417 lines
13 KiB
Dart
417 lines
13 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:qhd_prevention/customWidget/custom_alert_dialog.dart';
|
|
import 'package:qhd_prevention/customWidget/custom_button.dart';
|
|
import 'package:qhd_prevention/customWidget/toast_util.dart';
|
|
import 'package:qhd_prevention/http/ApiService.dart';
|
|
import 'package:qhd_prevention/pages/home/scan_page.dart';
|
|
import 'package:qhd_prevention/pages/home/userinfo_page.dart';
|
|
import 'package:qhd_prevention/pages/mine/face_ecognition_page.dart';
|
|
import 'package:qhd_prevention/pages/mine/mine_change_firm_page.dart';
|
|
import 'package:qhd_prevention/pages/mine/mine_feedback_page.dart';
|
|
import 'package:qhd_prevention/pages/mine/mine_set_pwd_page.dart';
|
|
import 'package:qhd_prevention/pages/mine/onboarding_full_page.dart';
|
|
import 'package:qhd_prevention/pages/user/full_userinfo_page.dart';
|
|
import 'package:qhd_prevention/pages/user/login_page.dart';
|
|
import 'package:qhd_prevention/services/SessionService.dart';
|
|
import 'package:qhd_prevention/tools/tools.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class MinePage extends StatefulWidget {
|
|
const MinePage({super.key});
|
|
|
|
@override
|
|
State<MinePage> createState() => MinePageState();
|
|
}
|
|
|
|
class MinePageState extends State<MinePage> {
|
|
// 设置项状态
|
|
bool notificationsEnabled = false;
|
|
bool passwordChanged = false;
|
|
bool updateAvailable = false;
|
|
bool logoutSelected = false;
|
|
bool faceAuthentication = false;
|
|
bool scanAuthentication = false;
|
|
|
|
String name = '登录/注册';
|
|
String phone = '';
|
|
|
|
void onRouteConfigLoaded() {
|
|
if (mounted) {
|
|
setState(() {
|
|
// _updateMenuVisibility();
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
name = SessionService.instance.name ?? "登录/注册";
|
|
phone = SessionService.instance.phone ?? "";
|
|
}
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final double headerHeight = 300.0;
|
|
final double overlap = 100.0;
|
|
return SizedBox(
|
|
height: MediaQuery.of(context).size.height,
|
|
child: Stack(
|
|
children: [
|
|
Positioned(
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
height: headerHeight,
|
|
child: _buildHeaderSection(),
|
|
),
|
|
Positioned.fill(
|
|
child: NotificationListener<OverscrollIndicatorNotification>(
|
|
onNotification: (overscroll) {
|
|
overscroll.disallowIndicator();
|
|
return false;
|
|
},
|
|
child: ListView(
|
|
padding: EdgeInsets.only(
|
|
top: headerHeight - overlap,
|
|
bottom: 24,
|
|
left: 0,
|
|
right: 0,
|
|
),
|
|
children: [
|
|
_buildSettingsList(),
|
|
|
|
SizedBox(height: 15),
|
|
|
|
Padding(
|
|
padding: EdgeInsetsGeometry.symmetric(horizontal: 15),
|
|
child: CustomButton(
|
|
text: '退出登录',
|
|
textStyle: TextStyle(fontSize: 16),
|
|
backgroundColor: Colors.blue,
|
|
// borderRadius: 15,
|
|
onPressed: () {
|
|
CustomAlertDialog.showConfirm(
|
|
context,
|
|
title: '确认退出',
|
|
content: '确定要退出当前账号吗',
|
|
onConfirm: () async {
|
|
// await AuthService.logout(); // ✅ 等待登出完成
|
|
// if (!mounted) return;
|
|
// 清除用户登录状态
|
|
await _clearUserSession();
|
|
Navigator.pushAndRemoveUntil(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => const LoginPage(),
|
|
),
|
|
(Route<dynamic> route) => false,
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeaderSection() {
|
|
return Stack(
|
|
alignment: const FractionalOffset(0.5, 0),
|
|
children: [
|
|
Padding(
|
|
padding: EdgeInsets.fromLTRB(0, 0, 0, 10),
|
|
child: Image.asset(
|
|
"assets/images/my_bg.png",
|
|
width: MediaQuery.of(context).size.width, // 获取屏幕宽度
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
|
|
Positioned(
|
|
top: 51,
|
|
child: Text(
|
|
"我的",
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
|
|
// 标语区域
|
|
_buildSloganSection(),
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<void> _logout() async {
|
|
|
|
LoadingDialogHelper.show();
|
|
|
|
/// 获取用户在职列表
|
|
final firmData = await BasicInfoApi.getJoinFirmList();
|
|
if (firmData['success'] == true) {
|
|
final firmList = firmData['data'];
|
|
LoadingDialogHelper.dismiss();
|
|
if (firmList.isNotEmpty) {
|
|
CustomAlertDialog.showAlert(
|
|
context,
|
|
title: '温馨提示',
|
|
content: '您目前还有入职信息无法直接注销。\n请先在“就职单位”页面中离职。',
|
|
);
|
|
} else {
|
|
CustomAlertDialog.showConfirm(
|
|
context,
|
|
title: '温馨提示',
|
|
content: '注销后您的所有信息将会被删除\n请确认是否注销。 ',
|
|
onConfirm: () async {
|
|
CustomAlertDialog.showInputWithCode(
|
|
context,
|
|
title: '手机号:${SessionService.instance.phone}',
|
|
onGetCode: () async {
|
|
LoadingDialogHelper.show();
|
|
final res = await BasicInfoApi.sendRegisterSms({
|
|
'phone': phone,
|
|
});
|
|
LoadingDialogHelper.dismiss();
|
|
return true;
|
|
},
|
|
onConfirm: (code) async {
|
|
LoadingDialogHelper.show();
|
|
Map data = {
|
|
'id' : SessionService.instance.accountId,
|
|
'phoneCode' : code,
|
|
};
|
|
await BasicInfoApi.logout(data).then((res) async {
|
|
LoadingDialogHelper.dismiss();
|
|
if (res['success'] == true) {
|
|
ToastUtil.showNormal(context, '账号已注销');
|
|
await SessionService.instance.clear(clearPrefs: true);
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (_) => const LoginPage()),
|
|
);
|
|
} else {
|
|
ToastUtil.showNormal(context, res['errMessage'] ?? '');
|
|
}
|
|
});
|
|
}
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} else {
|
|
LoadingDialogHelper.dismiss();
|
|
ToastUtil.showNormal(context, firmData['errMessage'] ?? '');
|
|
}
|
|
}
|
|
|
|
Widget _buildSloganSection() {
|
|
return Container(
|
|
margin: EdgeInsets.fromLTRB(0, 100, 0, 0),
|
|
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, // 水平居中
|
|
// crossAxisAlignment: CrossAxisAlignment.center, // 垂直居中(可选)
|
|
children: [
|
|
Row(
|
|
children: [
|
|
CircleAvatar(
|
|
backgroundImage: AssetImage("assets/images/my_bg.png"),
|
|
radius: 30,
|
|
),
|
|
const SizedBox(width: 16),
|
|
Text(
|
|
name,
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(width: 16),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSettingsList() {
|
|
return Container(
|
|
margin: const EdgeInsets.fromLTRB(20, 0, 20, 0),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
spreadRadius: 2,
|
|
blurRadius: 8,
|
|
offset: const Offset(0, 4),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildSettingItem(
|
|
title: "我的信息",
|
|
icon: "assets/images/ico9.png",
|
|
value: notificationsEnabled,
|
|
onChanged: (value) {
|
|
pushPage(
|
|
FullUserinfoPage(isEidt: false, isChooseFirm: true),
|
|
context,
|
|
);
|
|
},
|
|
),
|
|
|
|
_buildSettingItem(
|
|
title: "修改密码",
|
|
icon: "assets/images/ico16.png",
|
|
value: notificationsEnabled,
|
|
onChanged: (value) async {
|
|
await pushPage(MineSetPwdPage('0'), context);
|
|
},
|
|
),
|
|
_buildSettingItem(
|
|
title: "扫码入职",
|
|
icon: "assets/images/ico10.png",
|
|
value: scanAuthentication,
|
|
onChanged: (value) async {
|
|
final result = await pushPage(
|
|
ScanPage(type: ScanType.Onboarding),
|
|
context,
|
|
);
|
|
if (result == null) {
|
|
return;
|
|
}
|
|
pushPage(OnboardingFullPage(scanData: result), context);
|
|
},
|
|
),
|
|
|
|
_buildSettingItem(
|
|
title: "人脸认证",
|
|
icon: "assets/images/ico11.png",
|
|
value: faceAuthentication,
|
|
onChanged: (value) {
|
|
pushPage(
|
|
const FaceRecognitionPage(
|
|
studentId: '',
|
|
data: {},
|
|
mode: FaceMode.setUpdata,
|
|
),
|
|
context,
|
|
);
|
|
},
|
|
),
|
|
|
|
_buildSettingItem(
|
|
title: "证书信息",
|
|
icon: "assets/images/ico12.png",
|
|
value: passwordChanged,
|
|
onChanged: (value) => setState(() => passwordChanged = value!),
|
|
),
|
|
|
|
_buildSettingItem(
|
|
title: "问题反馈",
|
|
icon: "assets/images/ico13.png",
|
|
value: passwordChanged,
|
|
onChanged: (value) => setState(() => passwordChanged = value!),
|
|
),
|
|
|
|
// const Divider(height: 1, indent: 60),
|
|
_buildSettingItem(
|
|
title: "版本更新",
|
|
icon: "assets/images/ico14.png",
|
|
value: updateAvailable,
|
|
onChanged: (value) => setState(() => updateAvailable = value!),
|
|
),
|
|
|
|
_buildSettingItem(
|
|
title: "关于我们",
|
|
icon: "assets/images/ico15.png",
|
|
value: logoutSelected,
|
|
onChanged: (value) {
|
|
setState(() => logoutSelected = value!);
|
|
},
|
|
),
|
|
_buildSettingItem(
|
|
title: "切换账户",
|
|
icon: "assets/images/ico15.png",
|
|
value: logoutSelected,
|
|
onChanged: (value) {
|
|
pushPage(MineChangeFirmPage(), context);
|
|
},
|
|
),
|
|
_buildSettingItem(
|
|
title: "账户注销",
|
|
icon: "assets/images/ico15.png",
|
|
value: logoutSelected,
|
|
onChanged: (value) {
|
|
_logout();
|
|
},
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildSettingItem({
|
|
required String title,
|
|
required String icon,
|
|
required bool value,
|
|
required ValueChanged<bool?> onChanged,
|
|
}) {
|
|
return GestureDetector(
|
|
onTap: () async {
|
|
onChanged(value);
|
|
},
|
|
child: ListTile(
|
|
leading: Container(
|
|
width: 20,
|
|
height: 20,
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Image.asset(icon, fit: BoxFit.cover),
|
|
),
|
|
title: Text(
|
|
title,
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
|
),
|
|
|
|
trailing: Transform.scale(
|
|
scale: 1.2,
|
|
child: Icon(Icons.chevron_right),
|
|
// Image.asset(
|
|
// "assets/images/right.png",
|
|
// fit: BoxFit.cover,
|
|
// width: 15,
|
|
// height: 15,
|
|
// ),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<void> _clearUserSession() async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.remove('isLoggedIn'); // 清除登录状态
|
|
}
|
|
}
|