From db51c42664e7f707ce2aad542b6589edfd95a9c8 Mon Sep 17 00:00:00 2001 From: wyf <494641114@qq.com> Date: Fri, 5 Dec 2025 17:37:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B6=88=E6=81=AF=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/langs/en_US.json | 46 +- assets/langs/zh_CN.json | 47 +- assets/langs/zh_TW.json | 44 +- lib/common/color/appConstants.dart | 3 +- lib/common/util/MyUtils.dart | 2 +- .../home_page/DynamicReportDetailWidget.dart | 5 +- .../device/body_device_controller.dart | 85 +- lib/controller/login/login_controller.dart | 105 +- lib/controller/login/login_controller.g.dart | 6 +- .../common_message_setting_controller.dart | 2 + .../common_message_setting_controller.g.dart | 4 + .../message/message_setting_controller.dart | 12 +- lib/controller/user_info_controller.dart | 74 +- lib/main.dart | 3 +- lib/model/user_data.dart | 3 +- lib/model/user_data.g.dart | 4 +- lib/pages/common/selectDialog.dart | 252 ++- lib/pages/device/BodyDeviceWidget.dart | 26 +- .../device/component/MessageSetting.dart | 937 ++++++++--- .../component/MessageTypeComponent.dart | 256 +++ .../component/SingleMessageSetting.dart | 1251 +++++++++++++++ lib/pages/device/component/messageTool.dart | 1413 +++++++++++++++++ .../after/after_wifi_page_person.dart | 1 + .../device_bind/componnet/MessageSetting.dart | 1134 ++++++------- .../device_bind/componnet/bind_dialog.dart | 476 ++++-- lib/pages/login/other_login.dart | 7 +- lib/pages/login/th_bind_tel_page.dart | 51 + lib/pages/main_bottom/e_page.dart | 178 ++- lib/pages/main_bottom/home_page.dart | 55 +- lib/pages/main_bottom/message_page.dart | 4 +- lib/pages/main_bottom/mine_page.dart | 14 +- .../mh_page/CommonMessageSettingPage.dart | 4 +- lib/pages/mh_page/device/mht_people_info.dart | 2 +- .../user/controller/bind_tel_controller.dart | 1 + .../mh_page/user/page/edit_userinfo_page.dart | 2 + lib/pages/person/person_page.dart | 1 - lib/pages/person/select_time.dart | 335 ++++ lib/pages/setting/common_mesaage_setting.dart | 6 +- lib/pages/user/about_us_page.dart | 1 - lib/pages/user/update_user_email.dart | 657 ++++++++ lib/pages/user/update_user_page.dart | 355 ++++- lib/pages/user/update_user_tel.dart | 659 ++++++++ lib/pages/user/wx_unbind_dialog.dart | 29 + lib/routers/routers.dart | 17 +- 44 files changed, 7510 insertions(+), 1059 deletions(-) create mode 100644 lib/pages/device/component/MessageTypeComponent.dart create mode 100644 lib/pages/device/component/SingleMessageSetting.dart create mode 100644 lib/pages/device/component/messageTool.dart create mode 100644 lib/pages/user/update_user_email.dart create mode 100644 lib/pages/user/update_user_tel.dart create mode 100644 lib/pages/user/wx_unbind_dialog.dart diff --git a/assets/langs/en_US.json b/assets/langs/en_US.json index 8fe65c1..4ecbc77 100644 --- a/assets/langs/en_US.json +++ b/assets/langs/en_US.json @@ -376,8 +376,8 @@ "入睡时间": "Sleep time", "睡眠时长": "Sleep duration", "起床时间": "Wake time", - "小时": "h", - "分钟": "m", + "小时": "hours", + "分钟": "minutes", "消息提醒设置": "Message notification settings", "APP消息": "APP messages", "APP消息介绍": "Open APP to view device messages", @@ -433,7 +433,7 @@ "年龄": "Age", "设备ID": "Device", "体重": "Weight", - "分": "", + "分": "m", "位置权限说明": "Location Permission Description", "获得位置信息,连接附近的蓝牙设备与推荐附近门店": "Obtain location information, connect to nearby Bluetooth devices, and recommend nearby stores", "蓝牙权限说明": "Bluetooth Permission Description", @@ -569,5 +569,43 @@ "选择城市": "Select City", "请选择城市": "Please select a city", "输入关键词": "Enter keywords", - "输入国家、省份或城市": "Enter country, province, or city" + "输入国家、省份或城市": "Enter country, province, or city", + "手机号码": "Phone number", + "邮箱": "email", + "微信": "WeChat", + "更换": "Change", + "换绑": "Rebind", + "绑定": "Bind", + "更换手机号码": "Change Phone Number", + "输入手机号码": "Enter Phone Number", + "请输验证码": "Please Enter Verification Code", + "请输入手机号": "Please Enter Phone Number", + "原手机号码": "Original Phone Number", + "更换邮箱": "Change Email", + "实时体征消息": "Real-time Vital Signs Messages", + "睡眠报告消息": "Sleep Report Messages", + "已开启": "Enabled", + "短信消息": "SMS Messages", + "短信消息介绍": "Customize this service to receive message alerts via SMS", + "电话语音提醒": "Voice Call Reminders", + "电话语音提醒介绍": "Customize this service to receive message alerts via phone calls", + "报警条件设置": "Alert Condition Settings", + "恢复默认": "Reset", + "心率小于": "Less Than", + "心率大于": "Greater Than", + "提醒类型": "type", + "全部通知": "All Notifications", + "离床时间大于": " Greater Than", + "未卧床时间大于": "Greater Than", + "未起床时间大于": "Greater Than", + "睡眠报告评分小于": "Less Than", + "呼吸小于": "Less Than", + "呼吸大于": "Greater Than", + "请先在设置里的消息通知打开APP消息配置": "Please enable APP message configuration in the Settings > Notifications first", + "间隔报警": "Interval Alert", + "分钟/次": "m/times", + "选择分数": "Select Score", + "离床时长": "Bed Exit Duration", + "已关闭": "Disabled", + "时": " h" } \ No newline at end of file diff --git a/assets/langs/zh_CN.json b/assets/langs/zh_CN.json index 3729553..2c71c46 100644 --- a/assets/langs/zh_CN.json +++ b/assets/langs/zh_CN.json @@ -377,7 +377,7 @@ "起床时间": "起床时间", "小时": "小时", "分钟": "分钟", - "消息提醒设置": "消息提醒设置", + "消息提醒设置": "消息设置", "APP消息": "APP消息", "APP消息介绍": "打开APP,可以查看该设备的消息内容", "通用APP消息介绍": "打开APP,可以查看消息内容", @@ -423,8 +423,8 @@ "退出": "退出", "完成": "完成", "时长": "时长:", - "继续": "继续", - "下次再说": "下次再说", + "继续": "继续流程", + "下次再说": "跳过", "发现": "发现!", "检测到": "检测到", "绑定流程未走完是否继续": "绑定流程未走完是否继续?", @@ -569,6 +569,43 @@ "选择城市": "选择城市", "请选择城市": "请选择城市", "输入关键词": "输入关键词", - "输入国家、省份或城市": "输入国家、省份或城市" - + "输入国家、省份或城市": "输入国家、省份或城市", + "手机号码": "手机号码", + "邮箱": "邮箱", + "微信": "微信", + "更换": "更换", + "换绑": "换绑", + "绑定": "绑定", + "更换手机号码": "更换手机号码", + "输入手机号码": "输入手机号码", + "请输验证码": "请输验证码", + "请输入手机号": "请输入手机号", + "原手机号码": "原手机号码", + "更换邮箱": "更换邮箱", + "实时体征消息": "实时体征消息", + "睡眠报告消息": "睡眠报告消息", + "已开启": "已开启", + "短信消息": "短信消息", + "短信消息介绍": "定制该服务可通过手机短信接收消息提醒", + "电话语音提醒": "电话语音提醒", + "电话语音提醒介绍": "定制该服务可通过手机通话接收消息提醒", + "报警条件设置": "报警条件设置", + "恢复默认": "恢复默认", + "心率小于": "心率小于", + "心率大于": "心率大于", + "提醒类型": "提醒类型", + "全部通知": "全部通知", + "离床时间大于": "离床时间大于", + "未卧床时间大于": "未卧床时间大于", + "未起床时间大于": "未起床时间大于", + "睡眠报告评分小于": "睡眠报告评分小于", + "呼吸小于": "呼吸小于", + "呼吸大于": "呼吸大于", + "请先在设置里的消息通知打开APP消息配置": "请先设置“我的”中的消息通知", + "间隔报警": "间隔报警", + "分钟/次": "分钟/次", + "选择分数": "选择分数", + "离床时长": "离床时长", + "已关闭": "已关闭", + "时": "时" } \ No newline at end of file diff --git a/assets/langs/zh_TW.json b/assets/langs/zh_TW.json index 7bab8ff..57112a0 100644 --- a/assets/langs/zh_TW.json +++ b/assets/langs/zh_TW.json @@ -511,8 +511,8 @@ "发现": "發現!", "检测到": "檢測到", "绑定流程未走完是否继续": "綁定流程未走完是否繼續?", - "继续": "繼續", - "下次再说": "下次再說", + "继续": "繼續流程", + "下次再说": "跳過", "请输入人员名称": "請輸入人員名稱", "可用wifi": "可用wifi", "一": "一", @@ -565,5 +565,43 @@ "选择城市": "選擇城市", "请选择城市": "請選擇城市", "输入关键词": "輸入關鍵詞", - "输入国家、省份或城市": "輸入國家、省份或城市" + "输入国家、省份或城市": "輸入國家、省份或城市", + "手机号码": "手機號碼", + "邮箱": "郵箱", + "微信": "微信", + "更换": "更換", + "换绑": "換綁", + "绑定": "綁定", + "更换手机号码": "更護手機號碼", + "输入手机号码": "輸入手機號碼", + "请输验证码": "請輸入驗證碼", + "请输入手机号": "請輸入手機號碼", + "原手机号码": "原手機號碼", + "更换邮箱": "更護郵箱", + "实时体征消息": "即時體徵訊息", + "睡眠报告消息": "睡眠報告訊息", + "已开启": "已開啟", + "短信消息": "簡訊訊息", + "短信消息介绍": "定制此服務可透過手機簡訊接收訊息提醒", + "电话语音提醒": "電話語音提醒", + "电话语音提醒介绍": "定制此服務可透過手機通話接收訊息提醒", + "报警条件设置": "警報條件設定", + "恢复默认": "恢復預設值", + "心率小于": "心率小於", + "心率大于": "心率大於", + "提醒类型": "提醒類型", + "全部通知": "全部通知", + "离床时间大于": "離床時間大於", + "未卧床时间大于": "未臥床時間大於", + "未起床时间大于": "未起床時間大於", + "睡眠报告评分小于": "睡眠報告評分小於", + "呼吸小于": "呼吸小於", + "呼吸大于": "呼吸大於", + "请先在设置里的消息通知打开APP消息配置": "請先設定「我的」中的訊息通知", + "间隔报警": "間隔警報", + "分钟/次": "分鐘/次", + "选择分数": "選擇分數", + "离床时长": "離床時長", + "已关闭": "已關閉", + "时": "時" } \ No newline at end of file diff --git a/lib/common/color/appConstants.dart b/lib/common/color/appConstants.dart index a99cd6d..681ce45 100644 --- a/lib/common/color/appConstants.dart +++ b/lib/common/color/appConstants.dart @@ -23,6 +23,7 @@ class AppConstants { double button_container_radius = 100.rpx; //按钮容器圆角 double text_padding_up_dowm_p = 5.rpx; //段落文字上下间距 + double text_padding = 10.rpx; //段落文字上下间距 double smaller_text_fontSize = 18.rpx; //普通文字字号 double small_text_fontSize = 20.rpx; //普通文字字号 @@ -63,7 +64,7 @@ class AppConstants { int wifi2 = -60; int wifi3 = -75; - static bool is_test_account = true; //是否测试账号 + static bool is_test_account = false; //是否测试账号 } //获取协议地址 diff --git a/lib/common/util/MyUtils.dart b/lib/common/util/MyUtils.dart index 8bec5e0..ba1b836 100644 --- a/lib/common/util/MyUtils.dart +++ b/lib/common/util/MyUtils.dart @@ -385,7 +385,7 @@ var closeIconWhite = GestureDetector( var returnIconButtom = returnIconButtomNew( onBack: () { // ⚡这里写你需要在返回前执行的逻辑 - Get.back(); + // Get.back(); }, ); diff --git a/lib/component/home_page/DynamicReportDetailWidget.dart b/lib/component/home_page/DynamicReportDetailWidget.dart index fb46dbf..1389d4f 100644 --- a/lib/component/home_page/DynamicReportDetailWidget.dart +++ b/lib/component/home_page/DynamicReportDetailWidget.dart @@ -77,7 +77,10 @@ class _DynamicReportDetailWidgetState extends State { SizedBox(height: 33.rpx), _buildSleepDateWidgets(), SizedBox(height: 20.rpx), - if (!AppConstants.is_test_account) _buildSleepDataModuleWidgets(), + if (!AppConstants.is_test_account) + Obx(() { + return _buildSleepDataModuleWidgets(); + }), ], ), ), diff --git a/lib/controller/device/body_device_controller.dart b/lib/controller/device/body_device_controller.dart index ae65ef5..7814d76 100644 --- a/lib/controller/device/body_device_controller.dart +++ b/lib/controller/device/body_device_controller.dart @@ -118,14 +118,82 @@ class BodyDeviceController extends GetControllerEx { return ApiResponse(code: -1, msg: "未知错误".tr); // Default return statement } - Future getDeviceList({String? key}) async { + // Future getDeviceList({String? key}) async { + // try { + // ApiResponse apiResponse = ApiResponse(code: -1, msg: "设备.设备列表请求失败".tr); + // String serviceAddress = ServiceConstant.service_address; + // String serviceName = ServiceConstant.server_service; + // String serviceApi = ServiceConstant.device_list; + // String queryUrl = + // "${serviceAddress}${serviceName}${serviceApi}?bindType=${model.type}${key != null ? '&key=$key' : ''}"; + // String? language = ""; + // if (AppConstants().ent_type == APPPackageType.MHT.code) { + // if (mhLanguageController.selectLanguage != null) { + // language = mhLanguageController.selectLanguage.value!.language_code; + // } + // } else { + // if (languageController.selectLanguage != null) { + // language = languageController.selectLanguage.value!.language_code; + // } + // } + // if (language != null && language.isNotEmpty) { + // if (queryUrl.contains("?")) { + // queryUrl += "&lang=$language"; + // } else { + // queryUrl += "?lang=$language"; + // } + // } + // var response = await EasyDartModule.dio.get(queryUrl); + // if (response != null) { + // var responseData = + // response.data is String ? jsonDecode(response.data) : response.data; + // ApiResponse res = + // ApiResponse.fromJson(responseData, (object) => object); + // MyUtils.formatResponse(res, "设备.设备列表请求成功".tr, "设备.设备列表请求失败".tr); + // if (res.code == HttpStatusCodes.ok) { + // // bindDeviceNum.value = res.total!; + // deviceList.value = res.data!; + // updateAll(); + // return res; + // } + // } else { + // return ApiResponse(code: -1, msg: "失败".tr); + // } + // return apiResponse; + // } catch (e) { + // EasyDartModule.logger.info("设备请求列表: $e"); + // DailyLogUtils.writeLog("设备请求列表: $e"); + // } + // return ApiResponse(code: -1, msg: "未知错误".tr); // Default return statement + // } + + Future getDeviceList( + {String? key, bool isAllDevice = false}) async { try { ApiResponse apiResponse = ApiResponse(code: -1, msg: "设备.设备列表请求失败".tr); String serviceAddress = ServiceConstant.service_address; String serviceName = ServiceConstant.server_service; String serviceApi = ServiceConstant.device_list; - String queryUrl = - "${serviceAddress}${serviceName}${serviceApi}?bindType=${model.type}${key != null ? '&key=$key' : ''}"; + + // 构建基础URL + String baseUrl = "${serviceAddress}${serviceName}${serviceApi}"; + + // 根据 isAllDevice 参数决定是否添加 bindType 参数 + String queryParams = ""; + if (!isAllDevice) { + queryParams = "?bindType=${model.type}"; + } + + // 添加 key 参数 + if (key != null) { + if (queryParams.isNotEmpty) { + queryParams += "&key=$key"; + } else { + queryParams = "?key=$key"; + } + } + + // 添加语言参数 String? language = ""; if (AppConstants().ent_type == APPPackageType.MHT.code) { if (mhLanguageController.selectLanguage != null) { @@ -136,13 +204,18 @@ class BodyDeviceController extends GetControllerEx { language = languageController.selectLanguage.value!.language_code; } } + if (language != null && language.isNotEmpty) { - if (queryUrl.contains("?")) { - queryUrl += "&lang=$language"; + if (queryParams.isNotEmpty) { + queryParams += "&lang=$language"; } else { - queryUrl += "?lang=$language"; + queryParams = "?lang=$language"; } } + + // 拼接完整URL + String queryUrl = baseUrl + queryParams; + var response = await EasyDartModule.dio.get(queryUrl); if (response != null) { var responseData = diff --git a/lib/controller/login/login_controller.dart b/lib/controller/login/login_controller.dart index d8acf00..8a1b935 100644 --- a/lib/controller/login/login_controller.dart +++ b/lib/controller/login/login_controller.dart @@ -43,6 +43,9 @@ class LoginModel { bool? register_agree = false; //是否同意协议 + String? updatePhone; //更新绑定手机号 + String? updateCode; //更新绑定验证码 + LoginModel(); static LoginModel fromJson(Map json) => @@ -61,8 +64,6 @@ class LoginController extends GetControllerEx { attr = GetModel(LoginModel()).obs; } - - //登录 Future login(BuildContext context) async { ApiResponse apiResponse = ApiResponse(code: -1, msg: "其他手机登录页.登录失败".tr); @@ -197,8 +198,78 @@ class LoginController extends GetControllerEx { } } - //微信登录 - Future wxLoginSendAuth(BuildContext context) async { + Future getUpdateTelCode(BuildContext context) async { + ApiResponse apiResponse = ApiResponse(code: -1, msg: "其他手机登录页.发送失败".tr); + try { + if (model.updatePhone == null || model.updatePhone!.isEmpty) { + apiResponse.msg = "其他手机登录页.请输入手机号".tr; + return apiResponse; + } + model.updatePhone = model.updatePhone!.trim(); + if (!MyUtils.isValidPhoneNumber(model.updatePhone!) && + !MyUtils.isValidEmail(model.updatePhone!)) { + apiResponse.msg = '其他手机登录页.不正确手机号'.tr; + return apiResponse; + } + String serviceAddress = ServiceConstant.service_address; + String serviceName = ServiceConstant.server_service; + String serviceApi = ServiceConstant.send_code; + String queryUrl = "${serviceAddress}${serviceName}${serviceApi}"; + String? language = ""; + if (AppConstants().ent_type == APPPackageType.MHT.code) { + if (mhLanguageController.selectLanguage != null) { + language = mhLanguageController.selectLanguage.value!.language_code; + } + } else { + if (languageController.selectLanguage != null) { + language = languageController.selectLanguage.value!.language_code; + } + } + if (language != null && language.isNotEmpty) { + if (queryUrl.contains("?")) { + queryUrl += "&lang=$language"; + } else { + queryUrl += "?lang=$language"; + } + } + var data = { + "userName": model.updatePhone, + "type": 5, + }; + if (AppConstants().ent_type == APPPackageType.HUANSHUI.code) { + data['code'] = "hzhskj"; + } + var response = + await EasyDartModule.dio.post(queryUrl, data: jsonEncode(data)); + if (response != null) { + var responseData = + response.data is String ? jsonDecode(response.data) : response.data; + ApiResponse res = + ApiResponse.fromJson(responseData, (object) => object); + if (res.code != HttpStatusCodes.ok) { + if (res.msg == null || res.msg!.isEmpty) { + res.msg = apiResponse.msg; + } + } else { + if (res.msg == null || res.msg!.isEmpty) { + res.msg = "其他手机登录页.发送成功".tr; + } + } + EasyDartModule.logger.info('msg:发送验证码成功'); + return res; + } else { + EasyDartModule.logger.error('msg:发送验证码失败:${response}'); + return ApiResponse(code: -1, msg: "失败".tr); + } + } catch (e) { + EasyDartModule.logger.error('msg:发送验证码失败:${e}'); + return ApiResponse(code: -1, msg: "失败".tr); + } + } + + //微信登录 auth 是否登录 + Future wxLoginSendAuth(BuildContext context, + {bool login = true}) async { /* 1、目前移动应用上微信登录只提供原生的登录方式,需要用户安装微信客户端才能配合使用。 2、对于Android应用,建议总是显示微信登录按钮,当用户手机没有安装微信客户端时,请引导用户下载安装微信客户端。 @@ -218,13 +289,14 @@ class LoginController extends GetControllerEx { .authBy( which: NormalAuth( scope: 'snsapi_userinfo', - state: 'wechat_sdk_theh_wxlogin', + state: 'wechat_sdk_theh_wxlogin' + + '${DateTime.now().millisecondsSinceEpoch}', )) .then((data) async { //返回true表示成功或者false表示失败,这边没有意义从login_controller页面构造函数监听中去处理 debugPrint('msg:$data'); EasyDartModule.logger.error('msg:$data'); - if (data) { + if (data && login) { //登陆成功 await dealBindProcess(); } @@ -253,18 +325,29 @@ class LoginController extends GetControllerEx { if (apiResponse.code == HttpStatusCodes.ok) { UserInfoController userInfoController = Get.find(); userInfoController.model.user = UserModel.fromJson(apiResponse.data); - if (userInfoController.model.user!.phone == null || - userInfoController.model.user!.phone!.isEmpty) { + if (apiResponse.data['test'] != null && + apiResponse.data['test'] == true) { + AppConstants.is_test_account = true; + } else { + AppConstants.is_test_account = false; + } + if ((userInfoController.model.user!.phone == null || + userInfoController.model.user!.phone!.isEmpty) && + (userInfoController.model.user!.email == null || + userInfoController.model.user!.email!.isEmpty)) { Map data = { 'img': "assets/img/bgNoImg.png", }; await Get.toNamed("/auth_bind_tel", arguments: data); } - if (userInfoController.model.user!.phone == null || - userInfoController.model.user!.phone!.isEmpty) { + if ((userInfoController.model.user!.phone == null || + userInfoController.model.user!.phone!.isEmpty) && + (userInfoController.model.user!.email == null || + userInfoController.model.user!.email!.isEmpty)) { userInfoController.model.login = 0; + } else { + userInfoController.model.login = 1; } - userInfoController.model.login = 1; String token = apiResponse.rawResponse.headers['token']!.first; EasyDartModule.dio.token = token; diff --git a/lib/controller/login/login_controller.g.dart b/lib/controller/login/login_controller.g.dart index 179e10a..7c52e49 100644 --- a/lib/controller/login/login_controller.g.dart +++ b/lib/controller/login/login_controller.g.dart @@ -17,7 +17,9 @@ LoginModel _$LoginModelFromJson(Map json) => LoginModel() ..forceLogin = (json['forceLogin'] as num?)?.toInt() ..isIos = json['isIos'] as bool? ..isWeChatNotInstalled = json['isWeChatNotInstalled'] as bool? - ..register_agree = json['register_agree'] as bool?; + ..register_agree = json['register_agree'] as bool? + ..updatePhone = json['updatePhone'] as String? + ..updateCode = json['updateCode'] as String?; Map _$LoginModelToJson(LoginModel instance) => { @@ -32,4 +34,6 @@ Map _$LoginModelToJson(LoginModel instance) => 'isIos': instance.isIos, 'isWeChatNotInstalled': instance.isWeChatNotInstalled, 'register_agree': instance.register_agree, + 'updatePhone': instance.updatePhone, + 'updateCode': instance.updateCode, }; diff --git a/lib/controller/message/common_message_setting_controller.dart b/lib/controller/message/common_message_setting_controller.dart index b5c0846..cecd7bf 100644 --- a/lib/controller/message/common_message_setting_controller.dart +++ b/lib/controller/message/common_message_setting_controller.dart @@ -10,6 +10,8 @@ class CommonMessageSettingModel { int? setting = 0; //总设置 0 关闭 1 开启 int? appSetting = 0; //app消息设置 int? serviceSetting = 0; //服务号消息 + int? telSetting = 0;//电话语音提醒 + int? smsSetting = 0;//短信提醒 int? tipSetting = 0; //设备放置说明 int? deviceUpgradeSetting = 0; //设备升级提示 int? deviceIssueSetting = 0; //设备故障提示 diff --git a/lib/controller/message/common_message_setting_controller.g.dart b/lib/controller/message/common_message_setting_controller.g.dart index 4c4b5ec..f67697f 100644 --- a/lib/controller/message/common_message_setting_controller.g.dart +++ b/lib/controller/message/common_message_setting_controller.g.dart @@ -12,6 +12,8 @@ CommonMessageSettingModel _$CommonMessageSettingModelFromJson( ..setting = (json['setting'] as num?)?.toInt() ..appSetting = (json['appSetting'] as num?)?.toInt() ..serviceSetting = (json['serviceSetting'] as num?)?.toInt() + ..telSetting = (json['telSetting'] as num?)?.toInt() + ..smsSetting = (json['smsSetting'] as num?)?.toInt() ..tipSetting = (json['tipSetting'] as num?)?.toInt() ..deviceUpgradeSetting = (json['deviceUpgradeSetting'] as num?)?.toInt() ..deviceIssueSetting = (json['deviceIssueSetting'] as num?)?.toInt() @@ -23,6 +25,8 @@ Map _$CommonMessageSettingModelToJson( 'setting': instance.setting, 'appSetting': instance.appSetting, 'serviceSetting': instance.serviceSetting, + 'telSetting': instance.telSetting, + 'smsSetting': instance.smsSetting, 'tipSetting': instance.tipSetting, 'deviceUpgradeSetting': instance.deviceUpgradeSetting, 'deviceIssueSetting': instance.deviceIssueSetting, diff --git a/lib/controller/message/message_setting_controller.dart b/lib/controller/message/message_setting_controller.dart index 19fa89a..890feae 100644 --- a/lib/controller/message/message_setting_controller.dart +++ b/lib/controller/message/message_setting_controller.dart @@ -5,9 +5,10 @@ part 'message_setting_controller.g.dart'; // 由json_serializable自动生成的 @JsonSerializable() class MessageSettingModel { - int? setting = 0;//总设置 0 关闭 1 开启 - int? appSetting = 0;//app消息设置 - int? serviceSetting = 0;//服务号消息 + int? setting = 0; //总设置 0 关闭 1 开启 + int? appSetting = 0; //app消息设置 + int? serviceSetting = 0; //服务号消息 + List device_type_setting = []; MessageSettingModel(); @@ -31,4 +32,9 @@ class MessageSettingController extends GetControllerEx { attr = GetModel(MessageSettingModel()).obs; } + RxMap messageType = RxMap(); + } + + + \ No newline at end of file diff --git a/lib/controller/user_info_controller.dart b/lib/controller/user_info_controller.dart index 30cf407..6babac7 100644 --- a/lib/controller/user_info_controller.dart +++ b/lib/controller/user_info_controller.dart @@ -1,7 +1,9 @@ import 'package:EasyDartModule/EasyDartModule.dart'; import 'package:dio/dio.dart' as dio; import 'package:ef/ef.dart'; +import 'package:flutter/material.dart'; import 'package:flutterflow_ui/flutterflow_ui.dart'; +import 'package:fluwx/fluwx.dart'; import 'package:get_storage/get_storage.dart'; import 'package:img_picker/img_picker.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -10,6 +12,8 @@ import 'package:vbvs_app/common/color/appConstants.dart'; import 'package:vbvs_app/common/color/app_uri_status.dart'; import 'package:vbvs_app/common/util/DailyLogUtils.dart'; import 'package:vbvs_app/common/util/MyUtils.dart'; +import 'package:vbvs_app/common/util/requestWithLog.dart'; +import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; import 'package:vbvs_app/controller/device/body_device_controller.dart'; import 'package:vbvs_app/controller/home/home_controller.dart'; import 'package:vbvs_app/controller/login/login_controller.dart'; @@ -67,6 +71,8 @@ class UserInfoController extends GetControllerEx { List device_bind_status = []; int device_bind_flag = 0; //0。未初始化 1.已初始化 int initLocationpermission = 0; //未初始化 + FluwxCancelable? fluwxCancelable; + final Fluwx fluwx = Fluwx(); Future uploadImg() async { EasyDartModule.logger.info("请求上传图片"); @@ -129,20 +135,29 @@ class UserInfoController extends GetControllerEx { } //更新用户信息 - Future updateData() async { + Future updateData({ + String? phone, + String? email, + String? code, + }) async { EasyDartModule.logger.info("更新用户资料"); DailyLogUtils.writeLog("更新用户资料"); try { + LoginController loginController = Get.find(); ApiResponse apiResponse = ApiResponse(code: -1, msg: "保存失败".tr); UserModel user = model.user!; if (user.tmpNickName == null || user.tmpNickName!.isEmpty) { apiResponse.msg = "昵称为空".tr; return apiResponse; } - // if (user.tmpNickName!.length >= 9) { - // apiResponse.msg = "最长字符为8个字".tr; - // return apiResponse; - // } + if ((phone != null && phone.isNotEmpty) || + (email != null && email.isNotEmpty)) { + if (loginController.model.updateCode == null || + loginController.model.updateCode!.isEmpty) { + apiResponse.msg = "请输验证码".tr; + return apiResponse; + } + } String serviceAddress = ServiceConstant.service_address; String serviceName = ServiceConstant.server_service; String serviceApi = ServiceConstant.user_info; @@ -168,8 +183,15 @@ class UserInfoController extends GetControllerEx { "nickName": user.tmpNickName, if (user.tmpHead != null && user.tmpHead!.isNotEmpty) "avatar": user.tmpHead, + if (phone != null && phone.isNotEmpty) "phone": phone, + if (email != null && email.isNotEmpty) "email": email, + if (loginController.model.updateCode != null && + loginController.model.updateCode!.isNotEmpty) + "verify": loginController.model.updateCode, + if (code != null && code.isNotEmpty) "wxCode": code, + if (code != null && code.isNotEmpty) "khCode": "theh", + "merge": true, }; - var response = await EasyDartModule.dio.put(queryUrl, data: jsonEncode(data)); if (apiResponse != null) { @@ -178,6 +200,10 @@ class UserInfoController extends GetControllerEx { ApiResponse res = ApiResponse.fromJson(responseData, (object) => object); MyUtils.formatResponse(res, "保存成功".tr, "保存失败".tr); + await getUserInfo(); + model.user!.tmpNickName = model.user!.nick_name; + model.user!.tmpHead = model.user!.avatar; + updateAll(); return res; } else { return ApiResponse(code: -1, msg: "服务器失败".tr); @@ -304,4 +330,40 @@ class UserInfoController extends GetControllerEx { return apiResponse; } + + //解除微信绑定 + unBindWx(BuildContext context) async { + String serviceAddress = ServiceConstant.service_address; + String serviceName = ServiceConstant.server_service; + String serviceApi = ServiceConstant.user_info; + String queryUrl = "${serviceAddress}${serviceName}${serviceApi}"; + try { + final data = { + "wxCode": "", + "khCode": "", + "merge": true, + }; + final res = await requestWithLog( + logTitle: "解除微信绑定", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + TopSlideNotification.show( + context, + text: res.msg!, + ); + }, + onFailure: (res) { + TopSlideNotification.show( + context, + text: res.msg!, + textColor: themeController.currentColor.sc9, + ); + }, + ); + } catch (e) { + ef.log("微信解绑失败-》$e"); + } + } } diff --git a/lib/main.dart b/lib/main.dart index 2dfa8f8..06c004c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -143,7 +143,8 @@ void initServiceAddress() { ServiceConstant.baseHost = "zhmht.swes.com.cn:27020"; } else if (AppConstants().ent_type == APPPackageType.TH.code) { // 太和 - ServiceConstant.baseHost = "vsbst-api.he-info.com"; + // ServiceConstant.baseHost = "vsbst-api.he-info.com"; + ServiceConstant.baseHost = "vsbs-test.he-info.cn"; } else { //默认 ServiceConstant.baseHost = "vsbst-api.he-info.com"; diff --git a/lib/model/user_data.dart b/lib/model/user_data.dart index 0c9afaa..f690125 100644 --- a/lib/model/user_data.dart +++ b/lib/model/user_data.dart @@ -17,7 +17,8 @@ class UserModel { int? created_at; String? email; bool? test; - bool? fac;//是否测试,可以全部升级 + bool? fac; //是否测试,可以全部升级 + bool? bindWx = false; UserModel(); static UserModel fromJson(Map json) => diff --git a/lib/model/user_data.g.dart b/lib/model/user_data.g.dart index 58703c0..ee7bace 100644 --- a/lib/model/user_data.g.dart +++ b/lib/model/user_data.g.dart @@ -20,7 +20,8 @@ UserModel _$UserModelFromJson(Map json) => UserModel() ..created_at = (json['created_at'] as num?)?.toInt() ..email = json['email'] as String? ..test = json['test'] as bool? - ..fac = json['fac'] as bool?; + ..fac = json['fac'] as bool? + ..bindWx = json['bindWx'] as bool?; Map _$UserModelToJson(UserModel instance) => { 'uid': instance.uid, @@ -37,4 +38,5 @@ Map _$UserModelToJson(UserModel instance) => { 'email': instance.email, 'test': instance.test, 'fac': instance.fac, + 'bindWx': instance.bindWx, }; diff --git a/lib/pages/common/selectDialog.dart b/lib/pages/common/selectDialog.dart index d204d6d..d580e8f 100644 --- a/lib/pages/common/selectDialog.dart +++ b/lib/pages/common/selectDialog.dart @@ -56,6 +56,66 @@ getOnePicker(BuildContext context, List arr, int checkIndex, ); } +// Widget getOnePickers( +// BuildContext context, +// List arr, +// RxInt selectedIndex, { +// String unit = '', +// bool looping = false, +// void Function(int)? onChanged, +// bool isMonthName = false, +// Key? pickerKey, +// }) { +// ThemeController themeController = Get.find(); +// final bool isEn = Get.locale?.languageCode.startsWith('en') ?? false; + +// return Obx(() { +// final dynamicKey = ValueKey('picker_${arr.length}_${selectedIndex.value}'); +// return CupertinoPicker.builder( +// key: pickerKey ?? dynamicKey, +// itemExtent: 90.rpx, +// useMagnifier: false, +// magnification: 1, +// diameterRatio: 1.3, +// squeeze: 1, +// scrollController: +// FixedExtentScrollController(initialItem: selectedIndex.value), +// selectionOverlay: Container(), +// onSelectedItemChanged: (int index) { +// selectedIndex.value = index; +// if (onChanged != null) onChanged(index); +// }, +// childCount: arr.length, +// itemBuilder: (context, index) { +// bool isSelected = index == selectedIndex.value; + +// // 处理显示文本 +// String displayText; +// if (isMonthName && isEn && arr[index] is int) { +// displayText = DateFormat.MMMM('en').format(DateTime(0, arr[index])); +// } else { +// // displayText = isEn ? "${arr[index]}" : "${arr[index]}$unit"; // 中文附带单位 +// displayText = "${arr[index]}$unit"; // 中文附带单位 +// } + +// return Center( +// child: Text( +// displayText, +// style: TextStyle( +// fontFamily: 'Readex Pro', +// color: isSelected +// ? themeController.currentColor.sc3 +// : const Color(0xFF9AA0B3), +// fontSize: 30.rpx, +// fontWeight: FontWeight.normal, +// ), +// ), +// ); +// }, +// ); +// }); +// } + Widget getOnePickers( BuildContext context, List arr, @@ -65,6 +125,9 @@ Widget getOnePickers( void Function(int)? onChanged, bool isMonthName = false, Key? pickerKey, + + /// ⭐ 新增:可选的自定义显示,但不影响旧用法 + String Function(dynamic value)? customDisplay, }) { ThemeController themeController = Get.find(); final bool isEn = Get.locale?.languageCode.startsWith('en') ?? false; @@ -89,13 +152,26 @@ Widget getOnePickers( itemBuilder: (context, index) { bool isSelected = index == selectedIndex.value; - // 处理显示文本 - String displayText; - if (isMonthName && isEn && arr[index] is int) { - displayText = DateFormat.MMMM('en').format(DateTime(0, arr[index])); - } else { - // displayText = isEn ? "${arr[index]}" : "${arr[index]}$unit"; // 中文附带单位 - displayText = "${arr[index]}$unit"; // 中文附带单位 + String value = arr[index].toString(); + String displayText = ""; + + // ⭐ 1. 优先使用自定义展示 + if (customDisplay != null) { + String? custom = customDisplay(arr[index]); + if (custom != null && custom.isNotEmpty) { + displayText = custom; + } + } + + // ⭐ 2. 若自定义没给或返回空,则使用你原本的逻辑 + if (displayText.isEmpty) { + if (isMonthName && isEn && arr[index] is int) { + // 英文月份 + displayText = DateFormat.MMMM('en').format(DateTime(0, arr[index])); + } else { + // 中文 + 单位(你原来的逻辑) + displayText = "$value$unit"; + } } return Center( @@ -1839,3 +1915,165 @@ DialogColorScheme _getDialogColors(int entType) { ); } } + +Future showTHDayTimeSelectionDialog( + BuildContext context, { + required List dayTimeArr, + Function(List)? checkChange, + String title = "选择时间", +}) { + ThemeController themeController = Get.find(); + + final List hours = List.generate(24, (i) => i); + final List minutes = List.generate(60, (i) => i); + + final RxInt hoursIndex = hours.indexOf(dayTimeArr[0]).obs; + final RxInt minutesIndex = minutes.indexOf(dayTimeArr[1]).obs; + + return showDialog( + context: context, + barrierDismissible: true, + builder: (BuildContext context) { + return Stack( + children: [ + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Material( + color: Colors.transparent, + child: Dialog( + backgroundColor: themeController.currentColor.sc17, // 修改:使用主题颜色 + insetPadding: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(0), + ), + child: Container( + width: double.infinity, + padding: EdgeInsets.fromLTRB(0.rpx, 0.rpx, 0.rpx, 90.rpx), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + // 顶部栏:取消 - 标题 - 确定 + Container( + padding: + EdgeInsets.fromLTRB(30.rpx, 0.rpx, 30.rpx, 0.rpx), + color: themeController.currentColor.sc5, // 修改:使用主题颜色 + height: 80.rpx, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: EdgeInsets.zero, + onTap: () => Navigator.of(context).pop(), + child: Container( + width: 110.rpx, + height: 60.rpx, + alignment: Alignment.center, + child: Text( + "取消".tr, + style: TextStyle( + fontSize: 30.rpx, + color: Colors.white, // 保持不变 + ), + ), + ), + ), + Text( + title.tr, + style: TextStyle( + fontFamily: 'Readex Pro', + color: themeController + .currentColor.sc3, // 修改:使用主题颜色 + fontSize: 30.rpx, + ), + ), + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: EdgeInsets.zero, + onTap: () { + checkChange?.call([ + hours[hoursIndex.value], + minutes[minutesIndex.value], + ]); + Get.back(); + }, + child: Container( + width: 110.rpx, + height: 60.rpx, + alignment: Alignment.center, + child: Text( + "确定".tr, + style: TextStyle( + fontSize: 30.rpx, + color: themeController + .currentColor.sc2, // 修改:使用主题颜色 + ), + ), + ), + ), + ], + ), + ), + SizedBox(height: 20.rpx), + Stack( + children: [ + Positioned.fill( + child: IgnorePointer( + child: Center( + child: Container( + height: 90.rpx, + margin: + EdgeInsets.symmetric(horizontal: 95.rpx), + decoration: BoxDecoration( + color: themeController + .currentColor.sc2, // 修改:使用主题颜色 + borderRadius: BorderRadius.circular(16.rpx), + ), + ), + ), + ), + ), + SizedBox( + height: 240.rpx, + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 95.rpx), + child: Row( + children: [ + Expanded( + child: getOnePickers( + context, + hours, + hoursIndex, + unit: "时".tr, + ), + ), + Expanded( + child: getOnePickers( + context, + minutes, + minutesIndex, + unit: "分".tr, + ), + ), + ], + ), + ), + ), + ], + ), + ], + ), + ), + ), + ), + ), + ], + ); + }, + ); +} diff --git a/lib/pages/device/BodyDeviceWidget.dart b/lib/pages/device/BodyDeviceWidget.dart index b2552b8..192e73b 100644 --- a/lib/pages/device/BodyDeviceWidget.dart +++ b/lib/pages/device/BodyDeviceWidget.dart @@ -188,10 +188,9 @@ class _BodyDevicePageState extends State { final targetPosition = index * (itemHeight + spacing); // 根据当前类型选择对应的ScrollController - final currentScrollController = - bodyDeviceController.model.type == 1 - ? _myDeviceScrollController - : _cloudDeviceScrollController; + final currentScrollController = bodyDeviceController.model.type == 1 + ? _myDeviceScrollController + : _cloudDeviceScrollController; if (currentScrollController.hasClients) { currentScrollController.animateTo( @@ -619,8 +618,11 @@ class _BodyDevicePageState extends State { children: [ // 我的e护页面 Obx(() { - final myDeviceList = bodyDeviceController.deviceList.value - .where((device) => device['type'] == 1 || device['bind_type'] == 1) + final myDeviceList = bodyDeviceController + .deviceList.value + .where((device) => + device['type'] == 1 || + device['bind_type'] == 1) .toList(); return myDeviceList.isEmpty ? NullDataWidget() @@ -643,8 +645,11 @@ class _BodyDevicePageState extends State { }), // 云关爱页面 Obx(() { - final cloudDeviceList = bodyDeviceController.deviceList.value - .where((device) => device['type'] == 2 || device['bind_type'] == 2) + final cloudDeviceList = bodyDeviceController + .deviceList.value + .where((device) => + device['type'] == 2 || + device['bind_type'] == 2) .toList(); return cloudDeviceList.isEmpty ? NullDataWidget() @@ -652,7 +657,8 @@ class _BodyDevicePageState extends State { padding: EdgeInsetsDirectional.fromSTEB( 30.rpx, 26.rpx, 30.rpx, 0), child: SingleChildScrollView( - controller: _cloudDeviceScrollController, + controller: + _cloudDeviceScrollController, child: Column( mainAxisSize: MainAxisSize.max, children: cloudDeviceList @@ -724,4 +730,4 @@ class _BodyDevicePageState extends State { ), ); } -} \ No newline at end of file +} diff --git a/lib/pages/device/component/MessageSetting.dart b/lib/pages/device/component/MessageSetting.dart index 0eb2bec..a3944e0 100644 --- a/lib/pages/device/component/MessageSetting.dart +++ b/lib/pages/device/component/MessageSetting.dart @@ -1,7 +1,9 @@ import 'dart:async'; +import 'package:EasyDartModule/EasyDartModule.dart' as edm; import 'package:ef/ef.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; import 'package:flutterflow_ui/flutterflow_ui.dart'; import 'package:vbvs_app/common/color/ServiceConstant.dart'; import 'package:vbvs_app/common/color/appConstants.dart'; @@ -9,11 +11,13 @@ import 'package:vbvs_app/common/util/FitTool.dart'; import 'package:vbvs_app/common/util/MyUtils.dart'; import 'package:vbvs_app/common/util/requestWithLog.dart'; import 'package:vbvs_app/component/base/GradientSwitch.dart'; +import 'package:vbvs_app/component/tool/ClickableContainer.dart'; import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; import 'package:vbvs_app/controller/message/common_message_setting_controller.dart'; import 'package:vbvs_app/controller/message/message_setting_controller.dart'; import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; +//消息总配置 class MessageSettingPage extends StatefulWidget { var data; MessageSettingPage({super.key, required this.data}); @@ -32,6 +36,9 @@ class _MessageSettingPageState extends State { super.initState(); _fetchCommonMessageSetting(); _fetchDeviceMessageSetting(); + _fetchMessageCommonConfig(); + //todo 查询用户自定义配置 + //todo 查询用户总配置 } Future _fetchCommonMessageSetting() async { @@ -41,9 +48,9 @@ class _MessageSettingPageState extends State { String type = "user_message_setting"; String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; requestWithLog( - logTitle: "查询用户消息配置", + logTitle: "查询用户消息配置1", method: MyHttpMethod.get, - queryUrl: queryUrl, + queryUrl: queryUrl, onSuccess: (res) { if (res.data == null || res.data.isEmpty) { var data = { @@ -54,6 +61,8 @@ class _MessageSettingPageState extends State { "tipSetting": 1, "deviceUpgradeSetting": 1, "deviceIssueSetting": 1, + "telSetting": 1, + "smsSetting": 1, }; requestWithLog( logTitle: "更新用户消息配置", @@ -62,11 +71,11 @@ class _MessageSettingPageState extends State { data: data, onSuccess: (res) { requestWithLog( - logTitle: "查询用户消息配置", + logTitle: "查询用户消息配置2", method: MyHttpMethod.get, queryUrl: queryUrl, onSuccess: (res) { - if (res.data != null && res.data.isNotEmpty) { + if (res.data != null) { var datalist = res.data; commonMessageSettingController.model.setting = datalist['setting']; @@ -80,12 +89,14 @@ class _MessageSettingPageState extends State { datalist['deviceUpgradeSetting']; commonMessageSettingController.model.deviceIssueSetting = datalist['deviceIssueSetting']; + commonMessageSettingController.model.telSetting = + datalist['telSetting']; + commonMessageSettingController.model.smsSetting = + datalist['smsSetting']; commonMessageSettingController.updateAll(); } }, ); - - // }, ); } else { @@ -101,6 +112,10 @@ class _MessageSettingPageState extends State { datalist['deviceUpgradeSetting']; commonMessageSettingController.model.deviceIssueSetting = datalist['deviceIssueSetting']; + commonMessageSettingController.model.telSetting = + datalist['telSetting']; + commonMessageSettingController.model.smsSetting = + datalist['smsSetting']; commonMessageSettingController.updateAll(); } }, @@ -118,11 +133,11 @@ class _MessageSettingPageState extends State { String type = "user_device_message_setting_$mac"; String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; requestWithLog( - logTitle: "查询用户消息配置", + logTitle: "查询用户消息配置3", method: MyHttpMethod.get, queryUrl: queryUrl, onSuccess: (res) { - if (res.data == null || res.data.isEmpty) { + if (res.data == null) { var data = { "type": type, "setting": 1, @@ -136,7 +151,7 @@ class _MessageSettingPageState extends State { data: data, onSuccess: (res) { requestWithLog( - logTitle: "查询用户消息配置", + logTitle: "查询用户消息配置4", method: MyHttpMethod.get, queryUrl: queryUrl, onSuccess: (res) { @@ -162,6 +177,11 @@ class _MessageSettingPageState extends State { messageSettingController.model.appSetting = datalist['appSetting']; messageSettingController.model.serviceSetting = datalist['serviceSetting']; + + if (datalist['device_type_setting'] != null) { + messageSettingController.model.device_type_setting = + datalist['device_type_setting']; + } messageSettingController.updateAll(); } }, @@ -326,241 +346,255 @@ class _MessageSettingPageState extends State { ), ), ), - Padding( - padding: EdgeInsetsDirectional.fromSTEB( - 30.rpx, 21.rpx, 30.rpx, 0), - child: Container( - decoration: BoxDecoration( - color: themeController.currentColor.sc5, - borderRadius: BorderRadius.circular( - AppConstants().normal_container_radius), + // Padding( + // padding: EdgeInsetsDirectional.fromSTEB( + // 30.rpx, 21.rpx, 30.rpx, 0), + // child: Container( + // decoration: BoxDecoration( + // color: themeController.currentColor.sc5, + // borderRadius: BorderRadius.circular( + // AppConstants().normal_container_radius), + // ), + // child: Padding( + // padding: EdgeInsetsDirectional.fromSTEB( + // 30.rpx, 40.rpx, 30.rpx, 54.rpx), + // child: Container( + // child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + // children: [ + // Row( + // mainAxisSize: MainAxisSize.max, + // mainAxisAlignment: + // MainAxisAlignment.spaceBetween, + // children: [ + // Expanded( + // child: Text( + // "APP消息".tr, + // style: TextStyle( + // color: themeController + // .currentColor.sc3, + // fontSize: AppConstants() + // .title_text_fontSize), + // ), + // ), + // Obx(() { + // return GradientSwitch( + // value: commonMessageSettingController + // .model.setting == + // 1 + // ? (messageSettingController + // .model.setting == + // 1 + // ? (messageSettingController + // .model + // .appSetting == + // 1 + // ? true + // : false) + // : false) + // : false, + // onChanged: (val) { + // if (commonMessageSettingController + // .model.setting == + // 0) { + // TopSlideNotification.show(context, + // text: + // "请先在设置里的消息通知打开全部消息配置".tr, + // textColor: themeController + // .currentColor.sc9); + // return; + // } + // if (messageSettingController + // .model.setting == + // 0) { + // TopSlideNotification.show(context, + // text: "请先打开消息提醒设置".tr, + // textColor: themeController + // .currentColor.sc9); + // return; + // } + // String serviceAddress = + // ServiceConstant.service_address; + // String serviceName = + // ServiceConstant.server_service; + // String serviceApi = + // ServiceConstant.user_setting; + // String mac = widget.data['mac']; + // String type = + // "user_device_message_setting_$mac"; + // String queryUrl = + // "${serviceAddress}${serviceName}${serviceApi}"; + // var data = { + // "type": type, + // "setting": + // messageSettingController + // .model.setting, + // "appSetting": val == true ? 1 : 0, + // "serviceSetting": + // messageSettingController + // .model.serviceSetting, + // }; + // requestWithLog( + // logTitle: "更新消息推送状态", + // method: MyHttpMethod.put, + // queryUrl: queryUrl, + // data: data, + // onSuccess: (res) { + // _fetchDeviceMessageSetting(); + // messageSettingController + // .updateAll(); + // }); + // }, + // activeGradient: LinearGradient( + // colors: [ + // themeController.currentColor.sc1, + // themeController.currentColor.sc2 + // ], + // ), + // activeThumbColor: Colors.white, + // inactiveThumbColor: + // stringToColor("#A2A4A9"), + // inactiveColor: + // stringToColor("#161B28"), + // ); + // }), + // ], + // ), + // Text( + // "APP消息介绍".tr, + // style: TextStyle( + // color: themeController.currentColor.sc4, + // fontSize: AppConstants() + // .normal_text_fontSize), + // ), + // Row( + // mainAxisSize: MainAxisSize.max, + // mainAxisAlignment: + // MainAxisAlignment.spaceBetween, + // children: [ + // Expanded( + // child: Text( + // "服务号消息".tr, + // style: TextStyle( + // color: themeController + // .currentColor.sc3, + // fontSize: AppConstants() + // .title_text_fontSize), + // ), + // ), + // Obx(() { + // return GradientSwitch( + // value: commonMessageSettingController + // .model.setting == + // 1 + // ? (messageSettingController + // .model.setting == + // 1 + // ? (messageSettingController + // .model + // .serviceSetting == + // 1 + // ? true + // : false) + // : false) + // : false, + // onChanged: (val) { + // if (commonMessageSettingController + // .model.setting == + // 0) { + // TopSlideNotification.show(context, + // text: + // "请先在设置里的消息通知打开全部消息配置".tr, + // textColor: themeController + // .currentColor.sc9); + // return; + // } + // if (messageSettingController + // .model.setting == + // 0) { + // TopSlideNotification.show(context, + // text: "请先打开消息提醒设置".tr, + // textColor: themeController + // .currentColor.sc9); + // return; + // } + // String serviceAddress = + // ServiceConstant.service_address; + // String serviceName = + // ServiceConstant.server_service; + // String serviceApi = + // ServiceConstant.user_setting; + // String mac = widget.data['mac']; + // String type = + // "user_device_message_setting_$mac"; + // String queryUrl = + // "${serviceAddress}${serviceName}${serviceApi}"; + // var data = { + // "type": type, + // "setting": + // messageSettingController + // .model.setting, + // "appSetting": + // messageSettingController + // .model.appSetting, + // "serviceSetting": + // val == true ? 1 : 0, + // }; + // requestWithLog( + // logTitle: "更新消息推送状态", + // method: MyHttpMethod.put, + // queryUrl: queryUrl, + // data: data, + // onSuccess: (res) { + // _fetchDeviceMessageSetting(); + // messageSettingController + // .updateAll(); + // }); + // }, + // activeGradient: LinearGradient( + // colors: [ + // themeController.currentColor.sc1, + // themeController.currentColor.sc2 + // ], + // ), + // activeThumbColor: Colors.white, + // inactiveThumbColor: + // stringToColor("#A2A4A9"), + // inactiveColor: + // stringToColor("#161B28"), + // ); + // }), + // ], + // ), + // Text( + // "服务号消息介绍".tr, + // style: TextStyle( + // color: themeController.currentColor.sc4, + // fontSize: AppConstants() + // .normal_text_fontSize), + // ), + // ].divide(SizedBox( + // height: 49.rpx, + // )), + // ), + // ), + // ), + // ), + // ), + Obx(() { + if (messageSettingController + .messageType.value.isEmpty) { + return Container(); + } + return Expanded( + child: SingleChildScrollView( + child: Column( + children: getMessageTypeList( + messageSettingController.messageType.value, + widget.data), ), - child: Padding( - padding: EdgeInsetsDirectional.fromSTEB( - 30.rpx, 40.rpx, 30.rpx, 54.rpx), - child: Container( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Text( - "APP消息".tr, - style: TextStyle( - color: themeController - .currentColor.sc3, - fontSize: AppConstants() - .title_text_fontSize), - ), - ), - Obx(() { - return GradientSwitch( - value: commonMessageSettingController - .model.setting == - 1 - ? (messageSettingController - .model.setting == - 1 - ? (messageSettingController - .model - .appSetting == - 1 - ? true - : false) - : false) - : false, - onChanged: (val) { - if (commonMessageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: - "请先在设置里的消息通知打开全部消息配置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - if (messageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: "请先打开消息提醒设置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - String serviceAddress = - ServiceConstant.service_address; - String serviceName = - ServiceConstant.server_service; - String serviceApi = - ServiceConstant.user_setting; - String mac = widget.data['mac']; - String type = - "user_device_message_setting_$mac"; - String queryUrl = - "${serviceAddress}${serviceName}${serviceApi}"; - var data = { - "type": type, - "setting": - messageSettingController - .model.setting, - "appSetting": val == true ? 1 : 0, - "serviceSetting": - messageSettingController - .model.serviceSetting, - }; - requestWithLog( - logTitle: "更新消息推送状态", - method: MyHttpMethod.put, - queryUrl: queryUrl, - data: data, - onSuccess: (res) { - _fetchDeviceMessageSetting(); - messageSettingController - .updateAll(); - }); - }, - activeGradient: LinearGradient( - colors: [ - themeController.currentColor.sc1, - themeController.currentColor.sc2 - ], - ), - activeThumbColor: Colors.white, - inactiveThumbColor: - stringToColor("#A2A4A9"), - inactiveColor: - stringToColor("#161B28"), - ); - }), - ], - ), - Text( - "APP消息介绍".tr, - style: TextStyle( - color: themeController.currentColor.sc4, - fontSize: AppConstants() - .normal_text_fontSize), - ), - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Text( - "服务号消息".tr, - style: TextStyle( - color: themeController - .currentColor.sc3, - fontSize: AppConstants() - .title_text_fontSize), - ), - ), - Obx(() { - return GradientSwitch( - value: commonMessageSettingController - .model.setting == - 1 - ? (messageSettingController - .model.setting == - 1 - ? (messageSettingController - .model - .serviceSetting == - 1 - ? true - : false) - : false) - : false, - onChanged: (val) { - if (commonMessageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: - "请先在设置里的消息通知打开全部消息配置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - if (messageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: "请先打开消息提醒设置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - String serviceAddress = - ServiceConstant.service_address; - String serviceName = - ServiceConstant.server_service; - String serviceApi = - ServiceConstant.user_setting; - String mac = widget.data['mac']; - String type = - "user_device_message_setting_$mac"; - String queryUrl = - "${serviceAddress}${serviceName}${serviceApi}"; - var data = { - "type": type, - "setting": - messageSettingController - .model.setting, - "appSetting": - messageSettingController - .model.appSetting, - "serviceSetting": - val == true ? 1 : 0, - }; - requestWithLog( - logTitle: "更新消息推送状态", - method: MyHttpMethod.put, - queryUrl: queryUrl, - data: data, - onSuccess: (res) { - _fetchDeviceMessageSetting(); - messageSettingController - .updateAll(); - }); - }, - activeGradient: LinearGradient( - colors: [ - themeController.currentColor.sc1, - themeController.currentColor.sc2 - ], - ), - activeThumbColor: Colors.white, - inactiveThumbColor: - stringToColor("#A2A4A9"), - inactiveColor: - stringToColor("#161B28"), - ); - }), - ], - ), - Text( - "服务号消息介绍".tr, - style: TextStyle( - color: themeController.currentColor.sc4, - fontSize: AppConstants() - .normal_text_fontSize), - ), - ].divide(SizedBox( - height: 49.rpx, - )), - ), - ), - ), - ), - ), + )); + }) ], ), ), @@ -571,4 +605,421 @@ class _MessageSettingPageState extends State { ), ); } + + void _fetchMessageCommonConfig() { + String serviceAddress = ServiceConstant.service_address; + String serviceName = ServiceConstant.server_service; + String serviceApi = ServiceConstant.user_setting; + String type = "alarmType"; + String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; + requestWithLog( + logTitle: "查询用户消息配置5", + method: MyHttpMethod.get, + queryUrl: queryUrl, + onSuccess: (res) { + if (res.data != null) { + messageSettingController.messageType.value = res.data; + ef.log("查询用户消息配置成功"); + messageSettingController.updateAll(); + } + }, + onFailure: (res) { + print(res); + }, + ); + } + + getMessageTypeList(Map data, Map deviceData) { + try { + List list = []; + if (data.containsKey("real") && data["real"] is List) { + // 首先添加容器装饰 + list.add( + SizedBox(height: 30.rpx), + ); + list.add( + Padding( + padding: EdgeInsets.fromLTRB(40.rpx, 0, 40.rpx, 0), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular( + AppConstants().normal_container_radius), + color: themeController.currentColor.sc17, + ), + child: Column( + children: [ + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 40.rpx, 40.rpx, 40.rpx, 20.rpx), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + "实时体征消息".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ], + ), + ), + // 动态生成每个数据项 + for (int i = 0; i < (data["real"] as List).length; i++) + if ((data["real"] as List)[i] is Map && + (data["real"] as List)[i].containsKey("name")) + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 40.rpx, + i == 0 ? 20.rpx : 0, // 第一个元素顶部有20.rpx间距 + 40.rpx, + i == (data["real"] as List).length - 1 + ? 20.rpx + : 0.rpx), + child: ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 0.rpx, 0.rpx, 0.rpx), + onTap: () async { + var item = (data["real"] as List)[i]; + item['device'] = deviceData; + Get.toNamed('/singleMessageSetting', + arguments: item); + }, + child: Container( + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 30.rpx, 0.rpx, 30.rpx), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + "${((data["real"] as List)[i]["name"] ?? "")}" + .tr, + style: TextStyle( + fontFamily: 'Inter', + color: + themeController.currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + Row( + mainAxisSize: MainAxisSize.max, + children: [ + // 可以根据需要显示其他数据 + Text( + "${getSwitchStatus((data["real"] as List)[i], widget.data)}" + .tr, // 这里可以显示其他信息,比如: (data["real"] as List)[i]["value"] ?? "" + style: TextStyle( + fontFamily: 'Inter', + color: getSwitchStatusValue( + (data["real"] as List)[i], + widget.data) == + 1 + ? themeController.currentColor.sc2 + : themeController + .currentColor.sc9, + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + ), + ), + ), + ], + ), + ), + ), + ); + } + if (data.containsKey("report")) { + list.add( + SizedBox(height: 30.rpx), + ); + list.add( + Padding( + padding: EdgeInsets.fromLTRB(40.rpx, 0, 40.rpx, 0), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular( + AppConstants().normal_container_radius), + color: themeController.currentColor.sc17, + ), + child: Column( + children: [ + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 40.rpx, 40.rpx, 40.rpx, 20.rpx), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text( + "睡眠报告消息".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ], + ), + ), + // 动态生成每个数据项 + for (int i = 0; i < (data["report"] as List).length; i++) + if ((data["report"] as List)[i] is Map && + (data["report"] as List)[i].containsKey("name")) + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 40.rpx, + i == 0 ? 20.rpx : 0, // 第一个元素顶部有20.rpx间距 + 40.rpx, + i == (data["report"] as List).length - 1 + ? 20.rpx + : 0.rpx), + child: ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 0.rpx, 0.rpx, 0.rpx), + onTap: () async { + var item = (data["report"] as List)[i]; + item['device'] = deviceData; + Get.toNamed( + '/singleMessageSetting', + arguments: item, + ); + }, + child: Container( + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 30.rpx, 0.rpx, 30.rpx), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + "${((data["report"] as List)[i]["name"] ?? "")}" + .tr, + style: TextStyle( + fontFamily: 'Inter', + color: + themeController.currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + Row( + mainAxisSize: MainAxisSize.max, + children: [ + // 可以根据需要显示其他数据 + Text( + "${getSwitchStatus((data["report"] as List)[i], widget.data)}" + .tr, // 这里可以显示其他信息,比如: (data["real"] as List)[i]["value"] ?? ""// 这里可以显示其他信息,比如: (data["real"] as List)[i]["value"] ?? "" + style: TextStyle( + fontFamily: 'Inter', + color: getSwitchStatusValue( + (data["report"] + as List)[i], + widget.data) == + 1 + ? themeController.currentColor.sc2 + : themeController + .currentColor.sc9, + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + ), + ), + ), + ], + ), + ), + ), + ); + } + if (list.length > 0) { + list = [ + ...list, // 使用 ... 展开原列表的所有元素 + SizedBox(height: 30.rpx), + ]; + } + + return list; + } catch (e) { + ef.log("$e"); + edm.EasyDartModule.logger.info("[websokcet数据]:解析消息类型失败-->$e"); + return [ + Container(), + ]; + } + } + + getSwitchStatus(config, device) { + String on = "已开启".tr; + String off = "已关闭".tr; + + try { + // 1. 检查通用消息设置 + if (commonMessageSettingController.model.setting == 0) { + return off; + } + + // 2. 检查通用消息的app和service设置 + if (commonMessageSettingController.model.appSetting == 0 && + commonMessageSettingController.model.serviceSetting == 0) { + return off; + } + + // 3. 检查设备消息总开关 + if (messageSettingController.model.setting == 0) { + return off; + } + + // 4. 获取当前配置的id + int id = config['id']; + + // 5. 从device_type_setting中查找对应id的配置 + List deviceTypeSettings = + messageSettingController.model.device_type_setting; + + if (deviceTypeSettings == null || deviceTypeSettings.isEmpty) { + return on; // 如果列表为空,返回on + } + + // 查找id匹配的配置 + var targetConfig; + for (var item in deviceTypeSettings) { + if (item is Map && item['id'] == id) { + targetConfig = item; + break; + } + } + + print("ID: $id, 找到配置: $targetConfig"); + + // 6. 如果找不到该配置,直接返回on(已开启) + if (targetConfig == null) { + return on; + } + + // 7. 根据配置中的setting字段返回相应状态 + if (targetConfig['setting'] == null) { + return on; // setting为空,默认返回on + } + + int settingValue = targetConfig['setting'] is int + ? targetConfig['setting'] + : int.tryParse(targetConfig['setting'].toString()) ?? 1; + + return settingValue == 1 ? on : off; + } catch (e) { + print("getSwitchStatus 错误: $e"); + return on; // 出错时默认返回已开启 + } + } + + // 返回开关状态数值 (1:开启, 0:关闭) + getSwitchStatusValue(config, device) { + try { + // 1. 检查通用消息设置 + if (commonMessageSettingController.model.setting == 0) { + return 0; + } + + // 2. 检查通用消息的app和service设置 + if (commonMessageSettingController.model.appSetting == 0 && + commonMessageSettingController.model.serviceSetting == 0) { + return 0; + } + + // 3. 检查设备消息总开关 + if (messageSettingController.model.setting == 0) { + return 0; + } + + // 4. 获取当前配置的id + int id = config['id']; + + // 5. 从device_type_setting中查找对应id的配置 + List deviceTypeSettings = + messageSettingController.model.device_type_setting; + + if (deviceTypeSettings == null || deviceTypeSettings.isEmpty) { + return 1; // 如果列表为空,返回1(默认开启) + } + + // 查找id匹配的配置 + var targetConfig; + for (var item in deviceTypeSettings) { + if (item is Map && item['id'] == id) { + targetConfig = item; + break; + } + } + + print("ID: $id, 找到配置: $targetConfig"); + + // 6. 如果找不到该配置,返回1(默认开启) + if (targetConfig == null) { + return 1; + } + + // 7. 根据配置中的setting字段返回相应数值 + if (targetConfig['setting'] == null) { + return 1; // setting为空,默认返回1 + } + + int settingValue = targetConfig['setting'] is int + ? targetConfig['setting'] + : int.tryParse(targetConfig['setting'].toString()) ?? 1; + + return settingValue == 1 ? 1 : 0; + } catch (e) { + print("getSwitchStatusValue 错误: $e"); + return 1; // 出错时默认返回1(开启) + } + } } diff --git a/lib/pages/device/component/MessageTypeComponent.dart b/lib/pages/device/component/MessageTypeComponent.dart new file mode 100644 index 0000000..2361c2a --- /dev/null +++ b/lib/pages/device/component/MessageTypeComponent.dart @@ -0,0 +1,256 @@ +import 'package:flutter/material.dart'; +import 'dart:convert'; + +class MessageTypeComponent extends StatelessWidget { + final Map config; + + const MessageTypeComponent({Key? key, required this.config}) : super(key: key); + + @override + Widget build(BuildContext context) { + final String name = config['name'] ?? '未命名'; + final String type = config['type'] ?? 'unknown'; + final List dataList = config['data'] ?? []; + + return Container( + margin: const EdgeInsets.all(12.0), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12.0), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.2), + blurRadius: 8.0, + offset: const Offset(0, 2), + ), + ], + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // 标题栏 + _buildHeader(name, type), + + // 分隔线 + const Divider(height: 1, color: Color(0xFFEEEEEE)), + + // 数据列表 + _buildDataList(dataList), + ], + ), + ); + } + + // 构建标题栏 + Widget _buildHeader(String name, String type) { + return Container( + padding: const EdgeInsets.all(16.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + name, + style: const TextStyle( + fontSize: 18.0, + fontWeight: FontWeight.bold, + color: Color(0xFF333333), + ), + ), + Container( + padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 4.0), + decoration: BoxDecoration( + color: _getTypeColor(type), + borderRadius: BorderRadius.circular(20.0), + ), + child: Text( + _getTypeText(type), + style: const TextStyle( + fontSize: 12.0, + color: Colors.white, + fontWeight: FontWeight.w500, + ), + ), + ), + ], + ), + ); + } + + // 构建数据列表 + Widget _buildDataList(List dataList) { + if (dataList.isEmpty) { + return const Padding( + padding: EdgeInsets.all(16.0), + child: Text( + '暂无数据', + style: TextStyle(color: Colors.grey), + ), + ); + } + + return ListView.separated( + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + padding: const EdgeInsets.symmetric(vertical: 8.0), + itemCount: dataList.length, + separatorBuilder: (context, index) => const Divider( + height: 1, + indent: 16.0, + endIndent: 16.0, + color: Color(0xFFF5F5F5), + ), + itemBuilder: (context, index) { + final Map item = dataList[index]; + return _buildDataItem(item); + }, + ); + } + + // 构建单个数据项 + Widget _buildDataItem(Map item) { + final String itemName = item['name']?.toString() ?? '未知'; + final int? id = item['id']; + + return Container( + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + // ID 标签 + if (id != null) + Container( + width: 24.0, + height: 24.0, + alignment: Alignment.center, + margin: const EdgeInsets.only(right: 12.0), + decoration: BoxDecoration( + color: const Color(0xFFE8F4FF), + borderRadius: BorderRadius.circular(12.0), + ), + child: Text( + id.toString().substring(id.toString().length - 2), + style: const TextStyle( + fontSize: 12.0, + color: Color(0xFF1890FF), + fontWeight: FontWeight.w500, + ), + ), + ), + + // 数据内容 + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + itemName, + style: const TextStyle( + fontSize: 16.0, + fontWeight: FontWeight.w500, + color: Color(0xFF333333), + ), + ), + + const SizedBox(height: 4.0), + + // 动态显示其他字段 + ..._buildExtraFields(item), + ], + ), + ), + ], + ), + ); + } + + // 构建额外字段显示 + List _buildExtraFields(Map item) { + final List fields = []; + + // 遍历所有字段,排除已经显示的 id 和 name + item.forEach((key, value) { + if (key != 'id' && key != 'name' && value != null) { + final String displayKey = _getDisplayKey(key); + final String displayValue = _formatValue(value); + + fields.add( + Padding( + padding: const EdgeInsets.only(top: 2.0), + child: Text.rich( + TextSpan( + children: [ + TextSpan( + text: '$displayKey:', + style: const TextStyle( + fontSize: 14.0, + color: Color(0xFF666666), + ), + ), + TextSpan( + text: displayValue, + style: const TextStyle( + fontSize: 14.0, + color: Color(0xFF1890FF), + fontWeight: FontWeight.w500, + ), + ), + ], + ), + ), + ), + ); + } + }); + + return fields; + } + + // 获取显示用的键名 + String _getDisplayKey(String key) { + final Map keyMap = { + 'min': '最小值', + 'max': '最大值', + 'interval': '间隔(秒)', + 'duration': '持续时间(秒)', + 'time': '时间', + }; + + return keyMap[key] ?? key; + } + + // 格式化值显示 + String _formatValue(dynamic value) { + if (value is int) { + // 如果是时间相关的秒数,转换为分钟显示 + if (value >= 60) { + return '${value ~/ 60}分钟${value % 60 != 0 ? '${value % 60}秒' : ''}'; + } + return value.toString(); + } + return value.toString(); + } + + // 根据类型获取颜色 + Color _getTypeColor(String type) { + switch (type) { + case 'instant': + return const Color(0xFF52C41A); + case 'sleep': + return const Color(0xFF1890FF); + default: + return Colors.grey; + } + } + + // 根据类型获取显示文本 + String _getTypeText(String type) { + switch (type) { + case 'instant': + return '实时'; + case 'sleep': + return '睡眠'; + default: + return '未知'; + } + } +} \ No newline at end of file diff --git a/lib/pages/device/component/SingleMessageSetting.dart b/lib/pages/device/component/SingleMessageSetting.dart new file mode 100644 index 0000000..b93a260 --- /dev/null +++ b/lib/pages/device/component/SingleMessageSetting.dart @@ -0,0 +1,1251 @@ +import 'dart:async'; + +import 'package:ef/ef.dart'; +import 'package:flutter/material.dart'; +import 'package:flutterflow_ui/flutterflow_ui.dart'; +import 'package:vbvs_app/common/color/ServiceConstant.dart'; +import 'package:vbvs_app/common/color/appConstants.dart'; +import 'package:vbvs_app/common/util/FitTool.dart'; +import 'package:vbvs_app/common/util/MyUtils.dart'; +import 'package:vbvs_app/common/util/requestWithLog.dart'; +import 'package:vbvs_app/component/base/GradientSwitch.dart'; +import 'package:vbvs_app/component/tool/ClickableContainer.dart'; +import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; +import 'package:vbvs_app/controller/message/common_message_setting_controller.dart'; +import 'package:vbvs_app/controller/message/message_setting_controller.dart'; +import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; +import 'package:vbvs_app/pages/device/component/messageTool.dart'; + +//消息总配置 +class SingleMessageSetting extends StatefulWidget { + var data; + SingleMessageSetting({ + super.key, + required this.data, + }); + + @override + State createState() => _MessageSettingPageState(); +} + +class _MessageSettingPageState extends State { + final ThemeController themeController = Get.find(); + MessageSettingController messageSettingController = Get.find(); + CommonMessageSettingController commonMessageSettingController = Get.find(); + + @override + void initState() { + super.initState(); + _fetchCommonMessageSetting(); + _fetchDeviceMessageSetting(); + _fetchMessageCommonConfig(); + //todo 查询用户自定义配置 + //todo 查询用户总配置 + } + + Future _fetchCommonMessageSetting() async { + String serviceAddress = ServiceConstant.service_address; + String serviceName = ServiceConstant.server_service; + String serviceApi = ServiceConstant.user_setting; + String type = "user_message_setting"; + String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; + requestWithLog( + logTitle: "查询用户消息配置6", + method: MyHttpMethod.get, + queryUrl: queryUrl, + onSuccess: (res) { + if (res.data == null || res.data.isEmpty) { + var data = { + "type": type, + "setting": 1, + "appSetting": 1, + "serviceSetting": 1, + "tipSetting": 1, + "deviceUpgradeSetting": 1, + "deviceIssueSetting": 1, + "telSetting": 1, + "smsSetting": 1, + }; + requestWithLog( + logTitle: "更新用户消息配置", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + requestWithLog( + logTitle: "查询用户消息配置7", + method: MyHttpMethod.get, + queryUrl: queryUrl, + onSuccess: (res) { + if (res.data != null && res.data.isNotEmpty) { + var datalist = res.data; + commonMessageSettingController.model.setting = + datalist['setting']; + commonMessageSettingController.model.appSetting = + datalist['appSetting']; + commonMessageSettingController.model.serviceSetting = + datalist['serviceSetting']; + commonMessageSettingController.model.tipSetting = + datalist['tipSetting']; + commonMessageSettingController.model.deviceUpgradeSetting = + datalist['deviceUpgradeSetting']; + commonMessageSettingController.model.deviceIssueSetting = + datalist['deviceIssueSetting']; + commonMessageSettingController.model.telSetting = + datalist['telSetting']; + commonMessageSettingController.model.smsSetting = + datalist['smsSetting']; + commonMessageSettingController.updateAll(); + } + }, + ); + + // + }, + ); + } else { + var datalist = res.data; + commonMessageSettingController.model.setting = datalist['setting']; + commonMessageSettingController.model.appSetting = + datalist['appSetting']; + commonMessageSettingController.model.serviceSetting = + datalist['serviceSetting']; + commonMessageSettingController.model.tipSetting = + datalist['tipSetting']; + commonMessageSettingController.model.deviceUpgradeSetting = + datalist['deviceUpgradeSetting']; + commonMessageSettingController.model.deviceIssueSetting = + datalist['deviceIssueSetting']; + commonMessageSettingController.model.telSetting = + datalist['telSetting']; + commonMessageSettingController.model.smsSetting = + datalist['smsSetting']; + commonMessageSettingController.updateAll(); + } + }, + onFailure: (res) { + print(res); + }, + ); + } + + Future _fetchDeviceMessageSetting() async { + String serviceAddress = ServiceConstant.service_address; + String serviceName = ServiceConstant.server_service; + String serviceApi = ServiceConstant.user_setting; + String mac = widget.data['device']['mac']; + String type = "user_device_message_setting_$mac"; + String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; + requestWithLog( + logTitle: "查询用户消息配置8", + method: MyHttpMethod.get, + queryUrl: queryUrl, + onSuccess: (res) { + if (res.data == null || res.data.isEmpty) { + var data = { + "type": type, + "setting": 1, + "appSetting": 1, + "serviceSetting": 1, + }; + requestWithLog( + logTitle: "更新用户消息配置", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + requestWithLog( + logTitle: "查询用户消息配置9", + method: MyHttpMethod.get, + queryUrl: queryUrl, + onSuccess: (res) { + if (res.data != null && res.data.isNotEmpty) { + var datalist = res.data; + messageSettingController.model.setting = + datalist['setting']; + messageSettingController.model.appSetting = + datalist['appSetting']; + messageSettingController.model.serviceSetting = + datalist['serviceSetting']; + messageSettingController.updateAll(); + } + }, + ); + + // + }, + ); + } else { + var datalist = res.data; + messageSettingController.model.setting = datalist['setting']; + messageSettingController.model.appSetting = datalist['appSetting']; + messageSettingController.model.serviceSetting = + datalist['serviceSetting']; + messageSettingController.updateAll(); + } + }, + onFailure: (res) { + print(res); + }, + ); + } + + @override + void dispose() { + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return LayoutBuilder( + builder: (context, bodysize) => GestureDetector( + child: Container( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/img/bgNoImg.png'), + fit: BoxFit.fill, + ), + ), + child: Scaffold( + backgroundColor: Colors.transparent, + appBar: AppBar( + backgroundColor: themeController.currentColor.sc17, + automaticallyImplyLeading: false, + iconTheme: IconThemeData( + color: themeController.currentColor.sc3, + ), + titleSpacing: 0, + title: Container( + width: double.infinity, + height: 180.rpx, + child: Stack( + alignment: Alignment.center, + children: [ + /// 居中标题 + Text( + '${widget.data['name']}'.tr, + style: TextStyle( + fontFamily: 'ReadexPro', + color: themeController.currentColor.sc3, + letterSpacing: 0, + fontSize: 30.rpx, + ), + ), + Positioned( + left: 0, + child: returnIconButtomAddCallback(() {}), + ), + ], + ), + ), + actions: [], + centerTitle: false, + ), + body: GestureDetector( + child: SafeArea( + top: true, + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0, 0.rpx, 0), + child: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Padding( + padding: + EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0), + child: Container( + width: double.infinity, + constraints: BoxConstraints( + minHeight: 90.rpx, + ), + decoration: BoxDecoration( + color: themeController.currentColor.sc5), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 30.rpx, 15.rpx, 30.rpx, 15.rpx), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + "全部消息".tr, + style: TextStyle( + color: + themeController.currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize), + ), + ), + Obx(() { + return GradientSwitch( + value: getAllMessageSwitch(widget.data), + onChanged: (val) { + if (commonMessageSettingController + .model.setting == + 0) { + TopSlideNotification.show(context, + text: "请先在设置里的消息通知打开全部消息配置".tr, + textColor: themeController + .currentColor.sc9); + return; + } + if (messageSettingController + .model.setting == + 0) { + TopSlideNotification.show(context, + text: "该设备消息提醒已关闭".tr, + textColor: themeController + .currentColor.sc9); + return; + } + String serviceAddress = + ServiceConstant.service_address; + String serviceName = + ServiceConstant.server_service; + String serviceApi = + ServiceConstant.user_setting; + String mac = + widget.data['device']['mac']; + String type = + "user_device_message_setting_$mac"; + String queryUrl = + "${serviceAddress}${serviceName}${serviceApi}"; + int targetId = widget.data['id']; + int configIndex = + messageSettingController + .model.device_type_setting + .indexWhere((item) => + item['id'] == targetId); + if (configIndex != -1) { + // 更新找到的配置项 + int newSetting = val ? 1 : 0; + messageSettingController + .model.device_type_setting[ + configIndex]['setting'] = + newSetting; + + // 根据 setting 的值更新 appSetting 和 serviceSetting + messageSettingController + .model.device_type_setting[ + configIndex]['appSetting'] = + newSetting; + messageSettingController + .model.device_type_setting[ + configIndex] + ['serviceSetting'] = newSetting; + } else { + messageSettingController + .model.device_type_setting + .add({ + "id": widget.data['id'], + "setting": val ? 1 : 0, + "max": widget.data['max'], + "appSetting": 1, + "serviceSetting": 1, + }); + } + var data = { + "type": type, + "setting": messageSettingController + .model.setting, + "device_type_setting": + messageSettingController + .model.device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + _fetchDeviceMessageSetting(); + messageSettingController + .updateAll(); + }); + }, + activeGradient: LinearGradient( + colors: [ + themeController.currentColor.sc1, + themeController.currentColor.sc2 + ], + ), + activeThumbColor: Colors.white, + inactiveThumbColor: + stringToColor("#A2A4A9"), + inactiveColor: stringToColor("#161B28"), + ); + }), + ], + ), + ), + ), + ), + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 30.rpx, 21.rpx, 30.rpx, 0), + child: Container( + decoration: BoxDecoration( + color: themeController.currentColor.sc5, + borderRadius: BorderRadius.circular( + AppConstants().normal_container_radius), + ), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 30.rpx, 40.rpx, 30.rpx, 54.rpx), + child: Container( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + "APP消息".tr, + style: TextStyle( + color: themeController + .currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize), + ), + ), + Obx(() { + return GradientSwitch( + value: getAPPMessageSwitch( + widget.data), + onChanged: (val) { + if (commonMessageSettingController + .model.setting == + 0) { + TopSlideNotification.show( + context, + text: "请先在设置里的消息通知打开全部消息配置" + .tr, + textColor: themeController + .currentColor.sc9); + return; + } + if (commonMessageSettingController + .model.appSetting == + 0) { + TopSlideNotification.show( + context, + text: "请先在设置里的消息通知打开APP消息配置" + .tr, + textColor: themeController + .currentColor.sc9); + return; + } + if (messageSettingController + .model.setting == + 0) { + TopSlideNotification.show( + context, + text: "请先打开消息提醒设置".tr, + textColor: themeController + .currentColor.sc9); + return; + } + String serviceAddress = + ServiceConstant + .service_address; + String serviceName = + ServiceConstant + .server_service; + String serviceApi = + ServiceConstant.user_setting; + String mac = + widget.data['device']['mac']; + String type = + "user_device_message_setting_$mac"; + String queryUrl = + "${serviceAddress}${serviceName}${serviceApi}"; + int targetId = widget.data['id']; + int configIndex = + messageSettingController + .model.device_type_setting + .indexWhere((item) => + item['id'] == + targetId); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController.model + .device_type_setting[ + configIndex][ + 'appSetting'] = val ? 1 : 0; + + // 获取当前的 serviceSetting 值 + int serviceSetting = + messageSettingController + .model + .device_type_setting[ + configIndex][ + 'serviceSetting'] ?? + 0; + + // 更新 setting 字段:只要有一个为1,setting就为1 + messageSettingController.model + .device_type_setting[ + configIndex] + ['setting'] = (val || + serviceSetting == 1) + ? 1 + : 0; + } else { + messageSettingController + .model.device_type_setting + .add({ + "id": widget.data['id'], + "setting": 1, + "max": widget.data['max'], + "appSetting": val, + "serviceSetting": 1, + }); + } + var data = { + "type": type, + "setting": + messageSettingController + .model.setting, + "device_type_setting": + messageSettingController + .model + .device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + _fetchDeviceMessageSetting(); + messageSettingController + .updateAll(); + }); + }, + activeGradient: LinearGradient( + colors: [ + themeController + .currentColor.sc1, + themeController.currentColor.sc2 + ], + ), + activeThumbColor: Colors.white, + inactiveThumbColor: + stringToColor("#A2A4A9"), + inactiveColor: + stringToColor("#161B28"), + ); + }), + ], + ), + Text( + "APP消息介绍".tr, + style: TextStyle( + color: + themeController.currentColor.sc4, + fontSize: AppConstants() + .normal_text_fontSize), + ), + // Row( + // mainAxisSize: MainAxisSize.max, + // mainAxisAlignment: + // MainAxisAlignment.spaceBetween, + // children: [ + // Expanded( + // child: Text( + // "短信消息".tr, + // style: TextStyle( + // color: themeController + // .currentColor.sc3, + // fontSize: AppConstants() + // .title_text_fontSize), + // ), + // ), + // Obx(() { + // return GradientSwitch( + // value: commonMessageSettingController + // .model.setting == + // 1 + // ? (messageSettingController + // .model.setting == + // 1 + // ? (messageSettingController + // .model + // .serviceSetting == + // 1 + // ? true + // : false) + // : false) + // : false, + // onChanged: (val) { + // if (commonMessageSettingController + // .model.setting == + // 0) { + // TopSlideNotification.show( + // context, + // text: "请先在设置里的消息通知打开全部消息配置" + // .tr, + // textColor: themeController + // .currentColor.sc9); + // return; + // } + // if (messageSettingController + // .model.setting == + // 0) { + // TopSlideNotification.show( + // context, + // text: "请先打开消息提醒设置".tr, + // textColor: themeController + // .currentColor.sc9); + // return; + // } + // String serviceAddress = + // ServiceConstant + // .service_address; + // String serviceName = + // ServiceConstant + // .server_service; + // String serviceApi = + // ServiceConstant.user_setting; + // String mac = widget.data['mac']; + // String type = + // "user_device_message_setting_$mac"; + // String queryUrl = + // "${serviceAddress}${serviceName}${serviceApi}"; + // var data = { + // "type": type, + // "setting": + // messageSettingController + // .model.setting, + // "appSetting": + // messageSettingController + // .model.appSetting, + // "serviceSetting": + // val == true ? 1 : 0, + // }; + // requestWithLog( + // logTitle: "更新消息推送状态", + // method: MyHttpMethod.put, + // queryUrl: queryUrl, + // data: data, + // onSuccess: (res) { + // _fetchDeviceMessageSetting(); + // messageSettingController + // .updateAll(); + // }); + // }, + // activeGradient: LinearGradient( + // colors: [ + // themeController + // .currentColor.sc1, + // themeController.currentColor.sc2 + // ], + // ), + // activeThumbColor: Colors.white, + // inactiveThumbColor: + // stringToColor("#A2A4A9"), + // inactiveColor: + // stringToColor("#161B28"), + // ); + // }), + // ], + // ), + // Text( + // "短信消息介绍".tr, + // style: TextStyle( + // color: + // themeController.currentColor.sc4, + // fontSize: AppConstants() + // .normal_text_fontSize), + // ), + // Row( + // mainAxisSize: MainAxisSize.max, + // mainAxisAlignment: + // MainAxisAlignment.spaceBetween, + // children: [ + // Expanded( + // child: Text( + // "电话语音提醒".tr, + // style: TextStyle( + // color: themeController + // .currentColor.sc3, + // fontSize: AppConstants() + // .title_text_fontSize), + // ), + // ), + // Obx(() { + // return GradientSwitch( + // value: commonMessageSettingController + // .model.setting == + // 1 + // ? (messageSettingController + // .model.setting == + // 1 + // ? (messageSettingController + // .model + // .serviceSetting == + // 1 + // ? true + // : false) + // : false) + // : false, + // onChanged: (val) { + // if (commonMessageSettingController + // .model.setting == + // 0) { + // TopSlideNotification.show( + // context, + // text: "请先在设置里的消息通知打开全部消息配置" + // .tr, + // textColor: themeController + // .currentColor.sc9); + // return; + // } + // if (messageSettingController + // .model.setting == + // 0) { + // TopSlideNotification.show( + // context, + // text: "请先打开消息提醒设置".tr, + // textColor: themeController + // .currentColor.sc9); + // return; + // } + // String serviceAddress = + // ServiceConstant + // .service_address; + // String serviceName = + // ServiceConstant + // .server_service; + // String serviceApi = + // ServiceConstant.user_setting; + // String mac = widget.data['mac']; + // String type = + // "user_device_message_setting_$mac"; + // String queryUrl = + // "${serviceAddress}${serviceName}${serviceApi}"; + // var data = { + // "type": type, + // "setting": + // messageSettingController + // .model.setting, + // "appSetting": + // messageSettingController + // .model.appSetting, + // "serviceSetting": + // val == true ? 1 : 0, + // }; + // requestWithLog( + // logTitle: "更新消息推送状态", + // method: MyHttpMethod.put, + // queryUrl: queryUrl, + // data: data, + // onSuccess: (res) { + // _fetchDeviceMessageSetting(); + // messageSettingController + // .updateAll(); + // }); + // }, + // activeGradient: LinearGradient( + // colors: [ + // themeController + // .currentColor.sc1, + // themeController.currentColor.sc2 + // ], + // ), + // activeThumbColor: Colors.white, + // inactiveThumbColor: + // stringToColor("#A2A4A9"), + // inactiveColor: + // stringToColor("#161B28"), + // ); + // }), + // ], + // ), + // Text( + // "电话语音提醒介绍".tr, + // style: TextStyle( + // color: + // themeController.currentColor.sc4, + // fontSize: AppConstants() + // .normal_text_fontSize), + // ), + + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + "服务号消息".tr, + style: TextStyle( + color: themeController + .currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize), + ), + ), + Obx(() { + return GradientSwitch( + value: getServiceMessageSwitch( + widget.data), + onChanged: (val) { + if (commonMessageSettingController + .model.setting == + 0) { + TopSlideNotification.show( + context, + text: "请先在设置里的消息通知打开全部消息配置" + .tr, + textColor: themeController + .currentColor.sc9); + return; + } + if (messageSettingController + .model.setting == + 0) { + TopSlideNotification.show( + context, + text: "请先打开消息提醒设置".tr, + textColor: themeController + .currentColor.sc9); + return; + } + String serviceAddress = + ServiceConstant + .service_address; + String serviceName = + ServiceConstant + .server_service; + String serviceApi = + ServiceConstant.user_setting; + String mac = + widget.data['device']['mac']; + String type = + "user_device_message_setting_$mac"; + String queryUrl = + "${serviceAddress}${serviceName}${serviceApi}"; + int targetId = widget.data['id']; + int configIndex = + messageSettingController + .model.device_type_setting + .indexWhere((item) => + item['id'] == + targetId); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController.model + .device_type_setting[ + configIndex] + ['serviceSetting'] = + val ? 1 : 0; + + // 获取当前的 appSetting 值 + int appSetting = + messageSettingController + .model + .device_type_setting[ + configIndex] + ['appSetting'] ?? + 0; + + // 更新 setting 字段 + // 只要 appSetting 或 serviceSetting 中有一个为1,setting就为1 + // 只有当两者都为0时,setting才为0 + messageSettingController.model + .device_type_setting[ + configIndex] + ['setting'] = (appSetting == + 1 || + val) + ? 1 + : 0; + } else { + messageSettingController + .model.device_type_setting + .add({ + "id": widget.data['id'], + "setting": 1, + "max": widget.data['max'], + "appSetting": 1, + "serviceSetting": val, + }); + } + var data = { + "type": type, + "setting": + messageSettingController + .model.setting, + "device_type_setting": + messageSettingController + .model + .device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + _fetchDeviceMessageSetting(); + messageSettingController + .updateAll(); + }); + }, + activeGradient: LinearGradient( + colors: [ + themeController + .currentColor.sc1, + themeController.currentColor.sc2 + ], + ), + activeThumbColor: Colors.white, + inactiveThumbColor: + stringToColor("#A2A4A9"), + inactiveColor: + stringToColor("#161B28"), + ); + }), + ], + ), + Text( + "服务号消息介绍".tr, + style: TextStyle( + color: + themeController.currentColor.sc4, + fontSize: AppConstants() + .normal_text_fontSize), + ), + ].divide(SizedBox( + height: 49.rpx, + )), + ), + ), + ), + ), + ), + Padding( + padding: + EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0), + child: Container( + width: double.infinity, + constraints: BoxConstraints( + minHeight: 90.rpx, + ), + decoration: BoxDecoration( + color: themeController.currentColor.sc5), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 30.rpx, 15.rpx, 30.rpx, 15.rpx), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Text( + "报警条件设置".tr, + style: TextStyle( + color: + themeController.currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize), + ), + ), + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: EdgeInsets.all( + AppConstants().text_padding), + onTap: () { + String serviceAddress = + ServiceConstant.service_address; + String serviceName = + ServiceConstant.server_service; + String serviceApi = + ServiceConstant.user_setting; + String mac = widget.data['device']['mac']; + String type = + "user_device_message_setting_$mac"; + String queryUrl = + "${serviceAddress}${serviceName}${serviceApi}"; + int targetId = widget.data['id']; + + Map? defaultConfig; + + defaultConfig = messageSettingController + .messageType['real'] + ?.firstWhere( + (item) => item['id'] == targetId, + orElse: () => null); + if (defaultConfig == null) { + defaultConfig = messageSettingController + .messageType['report'] + ?.firstWhere( + (item) => + item['id'] == targetId, + orElse: () => null); + } + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere( + (item) => item['id'] == targetId); + if (defaultConfig != null) { + if (configIndex != -1) { + // 更新找到的配置项 - 恢复所有默认字段 + // 创建一个新的 map,包含所有默认字段 + Map updatedConfig = { + ...defaultConfig, // 展开所有默认字段 + // 保留原有的配置开关,但恢复其他字段 + 'setting': messageSettingController + .model + .device_type_setting[ + configIndex]['setting'] ?? + 1, + 'appSetting': messageSettingController + .model + .device_type_setting[ + configIndex]['appSetting'] ?? + 1, + 'serviceSetting': + messageSettingController.model + .device_type_setting[ + configIndex] + ['serviceSetting'] ?? + 1, + }; + + // 替换原有的配置 + messageSettingController + .model.device_type_setting[ + configIndex] = updatedConfig; + } else { + // 如果不存在,创建一个新的配置项,使用默认值 + messageSettingController + .model.device_type_setting + .add({ + ...defaultConfig, // 展开所有默认字段 + 'setting': 1, + 'appSetting': 1, + 'serviceSetting': 1, + }); + } + + // 更新控制器,触发 UI 刷新 + messageSettingController.update(); + } + var data = { + "type": type, + "setting": messageSettingController + .model.setting, + "device_type_setting": + messageSettingController + .model.device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + _fetchDeviceMessageSetting(); + messageSettingController + .updateAll(); + }); + }, + child: Text( + "恢复默认".tr, + style: TextStyle( + color: + themeController.currentColor.sc2, + fontSize: AppConstants() + .middler_text_fontSize), + ), + ), + ], + ), + ), + ), + ), + Obx(() { + var aa = messageSettingController.messageType; + print("${aa}"); + return Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 30.rpx, 30.rpx, 30.rpx, 0), + child: getContentById(widget.data, context), + ); + }), + SizedBox( + height: 60.rpx, + ) + ], + ), + ), + ), + ), + ), + ), + ), + ), + ); + } + + void _fetchMessageCommonConfig() { + String serviceAddress = ServiceConstant.service_address; + String serviceName = ServiceConstant.server_service; + String serviceApi = ServiceConstant.user_setting; + String type = "alarmType"; + String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; + requestWithLog( + logTitle: "查询用户消息配置10", + method: MyHttpMethod.get, + queryUrl: queryUrl, + onSuccess: (res) { + if (res.data != null) { + messageSettingController.messageType.value = res.data; + ef.log("查询用户消息配置成功"); + messageSettingController.updateAll(); + } + }, + onFailure: (res) { + print(res); + }, + ); + } + + getAllMessageSwitch(data) { + int typeId = data['id']; + + // 全局开关判断 + if (commonMessageSettingController.model.setting == 0) { + return false; + } + if (messageSettingController.model.setting == 0) { + return false; + } + + // 获取设备类型配置 + if (messageSettingController.model.device_type_setting != null && + messageSettingController.model.device_type_setting.isNotEmpty) { + // 查找匹配 typeId 的配置 + var matchedConfig = + messageSettingController.model.device_type_setting.firstWhere( + (item) => item['id'] == typeId, + orElse: () => null, + ); + + // 如果找到匹配的配置 + if (matchedConfig != null) { + // 返回配置中的 switch 值,如果 switch 为 null 则默认 true + return matchedConfig['setting'] == null + ? true + : matchedConfig['setting'] == 1; + } else { + // 没有找到对应 typeId 的配置,返回 true(默认开启) + return true; + } + } else { + // device_type_setting 为空或 null,返回 true(默认开启) + return true; + } + } + + //APP消息设置 + getAPPMessageSwitch(data) { + int typeId = data['id']; + + // 全局开关判断 + if (commonMessageSettingController.model.setting == 0) { + return false; + } + if (commonMessageSettingController.model.appSetting == 0) { + return false; + } + if (messageSettingController.model.setting == 0) { + return false; + } + + // 获取设备类型配置 + if (messageSettingController.model.device_type_setting != null && + messageSettingController.model.device_type_setting.isNotEmpty) { + // 查找匹配 typeId 的配置 + var matchedConfig = + messageSettingController.model.device_type_setting.firstWhere( + (item) => item['id'] == typeId, + orElse: () => null, + ); + // 如果找到匹配的配置 + if (matchedConfig != null) { + // 返回配置中的 switch 值,如果 switch 为 null 则默认 true + if (matchedConfig['setting'] == null) { + return true; + } else { + if (matchedConfig['setting'] == 0) { + return false; + } else { + return matchedConfig['appSetting'] == 0 ? false : true; + } + } + } else { + // 没有找到对应 typeId 的配置,返回 true(默认开启) + return true; + } + } else { + // device_type_setting 为空或 null,返回 true(默认开启) + return true; + } + } + + //服务号消息 + getServiceMessageSwitch(data) { + int typeId = data['id']; + + // 全局开关判断 + if (commonMessageSettingController.model.setting == 0) { + return false; + } + if (commonMessageSettingController.model.serviceSetting == 0) { + return false; + } + if (messageSettingController.model.setting == 0) { + return false; + } + + // 获取设备类型配置 + if (messageSettingController.model.device_type_setting != null && + messageSettingController.model.device_type_setting.isNotEmpty) { + // 查找匹配 typeId 的配置 + var matchedConfig = + messageSettingController.model.device_type_setting.firstWhere( + (item) => item['id'] == typeId, + orElse: () => null, + ); + // 如果找到匹配的配置 + if (matchedConfig != null) { + // 返回配置中的 switch 值,如果 switch 为 null 则默认 true + if (matchedConfig['setting'] == null) { + return true; + } else { + if (matchedConfig['setting'] == 0) { + return false; + } else { + return matchedConfig['serviceSetting'] == 0 ? false : true; + } + } + } else { + // 没有找到对应 typeId 的配置,返回 true(默认开启) + return true; + } + } else { + // device_type_setting 为空或 null,返回 true(默认开启) + return true; + } + } +} diff --git a/lib/pages/device/component/messageTool.dart b/lib/pages/device/component/messageTool.dart new file mode 100644 index 0000000..e275a9a --- /dev/null +++ b/lib/pages/device/component/messageTool.dart @@ -0,0 +1,1413 @@ +import 'package:ef/ef.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:flutterflow_ui/flutterflow_ui.dart'; +import 'package:vbvs_app/common/color/ServiceConstant.dart'; +import 'package:vbvs_app/common/color/appConstants.dart'; +import 'package:vbvs_app/common/util/FitTool.dart'; +import 'package:vbvs_app/common/util/MyUtils.dart'; +import 'package:vbvs_app/common/util/requestWithLog.dart'; +import 'package:vbvs_app/component/tool/ClickableContainer.dart'; +import 'package:vbvs_app/controller/message/common_message_setting_controller.dart'; +import 'package:vbvs_app/controller/message/message_setting_controller.dart'; +import 'package:vbvs_app/pages/common/selectDialog.dart'; +import 'package:vbvs_app/pages/person/select_time.dart'; + +getContentById(data, BuildContext context) { + try { + String serviceAddress = ServiceConstant.service_address; + String serviceName = ServiceConstant.server_service; + String serviceApi = ServiceConstant.user_setting; + String mac = data['device']['mac']; + String type = "user_device_message_setting_$mac"; + String queryUrl = "${serviceAddress}${serviceName}${serviceApi}"; + CommonMessageSettingController commonMessageSettingController = Get.find(); + MessageSettingController messageSettingController = Get.find(); + int id = data['id']; + Map? userConfig = messageSettingController + .model.device_type_setting + .firstWhere((item) => item['id'] == id, orElse: () => null); + // 3. 如果没找到用户配置,再从 messageType 中查找默认配置 + Map? defaultConfig; + // 在 messageType 的 real 数组中查找 + defaultConfig = messageSettingController.messageType['real'] + ?.firstWhere((item) => item['id'] == id, orElse: () => null); + + // 如果在 real 中没找到,在 report 数组中查找 + if (defaultConfig == null) { + defaultConfig = messageSettingController.messageType['report'] + ?.firstWhere((item) => item['id'] == id, orElse: () => null); + } + if (id == 100001) { + //心率异常 + // 1. 优先从 device_type_setting 中查找用户配置 + int min = 40; // 默认值 + int max = 105; // 默认值 + int interval = 600; // 默认值 + // 2. 如果找到了用户配置,使用用户配置中的 max 值 + if (userConfig != null) { + print('找到用户配置: $userConfig'); + // 获取 max 值 + if (userConfig['max'] != null) { + max = userConfig['max'] is int + ? userConfig['max'] + : int.tryParse(userConfig['max'].toString()) ?? 60; + } + if (userConfig['min'] != null) { + min = userConfig['min'] is int + ? userConfig['min'] + : int.tryParse(userConfig['min'].toString()) ?? 60; + } + if (userConfig['interval'] != null) { + interval = userConfig['interval'] is int + ? userConfig['interval'] + : int.tryParse(userConfig['interval'].toString()) ?? 60; + } + } else { + // 如果找到了默认配置 + if (defaultConfig != null) { + print('找到默认配置: $defaultConfig'); + + // 获取 max 值 + if (defaultConfig['max'] != null) { + max = defaultConfig['max'] is int + ? defaultConfig['max'] + : int.tryParse(defaultConfig['max'].toString()) ?? 60; + } + if (defaultConfig['min'] != null) { + min = defaultConfig['min'] is int + ? defaultConfig['min'] + : int.tryParse(defaultConfig['min'].toString()) ?? 60; + } + if (defaultConfig['interval'] != null) { + interval = defaultConfig['interval'] is int + ? defaultConfig['interval'] + : int.tryParse(defaultConfig['interval'].toString()) ?? 60; + } + } else { + throw '未找到默认配置, 请检查配置文件'; + } + } + return Container( + decoration: BoxDecoration( + color: themeController.currentColor.sc5, + borderRadius: + BorderRadius.circular(AppConstants().normal_container_radius), + ), + child: Padding( + padding: + EdgeInsetsDirectional.fromSTEB(40.rpx, 20.rpx, 40.rpx, 20.rpx), + child: Column( + children: [ + /// --- 心率小于 --- + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 30.rpx), + onTap: () { + final currentScore = min; + final initialScore = currentScore != null + ? int.tryParse(currentScore.toString()) ?? 40 + : 40; + FocusScope.of(context).requestFocus(FocusNode()); + Future.delayed(const Duration(milliseconds: 250), () { + showScorePickerDialog( + context, + title: "心率小于".tr, + initialHeight: initialScore, + onConfirm: (int selectedScore) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController + .model.device_type_setting[configIndex] + ['min'] = selectedScore; // 根据你的业务逻辑,布尔值转成 1/0 + } else { + messageSettingController.model.device_type_setting + .add({ + "id": id, + "setting": 1, + "max": defaultConfig!['max'], + "min": selectedScore, + "interval": defaultConfig!['interval'], + "appSetting": 1, + "serviceSetting": 1, + }); + } + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": messageSettingController + .model.device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + // fetchDeviceMessageSetting(); + messageSettingController.updateAll(); + }); + }, + min: 10, + max: 140, + ); + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "心率小于".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + ), + ), + Row( + children: [ + Text( + "$min".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + + /// --- 心率大于 --- + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 30.rpx), + onTap: () { + final currentScore = max; + final initialScore = currentScore != null + ? int.tryParse(currentScore.toString()) ?? 105 + : 105; + FocusScope.of(context).requestFocus(FocusNode()); + Future.delayed(const Duration(milliseconds: 250), () { + showScorePickerDialog( + context, + title: "心率大于".tr, + initialHeight: initialScore, + onConfirm: (int selectedScore) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController + .model.device_type_setting[configIndex] + ['max'] = selectedScore; // 根据你的业务逻辑,布尔值转成 1/0 + } else { + messageSettingController.model.device_type_setting + .add({ + "id": id, + "setting": 1, + "max": selectedScore, + "min": defaultConfig!['min'], + "interval": defaultConfig!['interval'], + "appSetting": 1, + "serviceSetting": 1, + }); + } + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": messageSettingController + .model.device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + // fetchDeviceMessageSetting(); + messageSettingController.updateAll(); + }); + }, + min: 10, + max: 140, + ); + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "心率大于".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + ), + ), + Row( + children: [ + Text( + "$max".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + + /// --- 提醒类型 --- + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 30.rpx), + onTap: () { + final currentScore = interval; + final initialScore = currentScore != null + ? int.tryParse(currentScore.toString()) ?? 600 + : 600; + FocusScope.of(context).requestFocus(FocusNode()); + Future.delayed(const Duration(milliseconds: 250), () { + showIntervalPickerDialog( + unit: "分钟/次".tr, + context, + title: "提醒类型".tr, + onConfirm: (int selectedScore) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController + .model.device_type_setting[configIndex] + ['interval'] = + selectedScore; // 根据你的业务逻辑,布尔值转成 1/0 + } else { + messageSettingController.model.device_type_setting + .add({ + "id": id, + "setting": 1, + "max": defaultConfig!['max'], + "min": defaultConfig!['min'], + "interval": selectedScore, + "appSetting": 1, + "serviceSetting": 1, + }); + } + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": messageSettingController + .model.device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + // fetchDeviceMessageSetting(); + messageSettingController.updateAll(); + }); + }, + initialValue: initialScore, + options: [60, 300, 600], + ); + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "提醒类型".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + ), + ), + Row( + children: [ + Text( + "${getShowInternal(id, interval)}".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + ], + ), + ), + ); + } else if (id == 100002) { + // 呼吸异常 + + int min = 10; // 默认 + int max = 40; // 默认 + int interval = 600; // 默认 + + // 若有用户配置 + if (userConfig != null) { + if (userConfig['max'] != null) { + max = userConfig['max'] is int + ? userConfig['max'] + : int.tryParse(userConfig['max'].toString()) ?? max; + } + + if (userConfig['min'] != null) { + min = userConfig['min'] is int + ? userConfig['min'] + : int.tryParse(userConfig['min'].toString()) ?? min; + } + + if (userConfig['interval'] != null) { + interval = userConfig['interval'] is int + ? userConfig['interval'] + : int.tryParse(userConfig['interval'].toString()) ?? interval; + } + } + // 若无用户配置 → 用默认配置 + else if (defaultConfig != null) { + if (defaultConfig['max'] != null) { + max = defaultConfig['max'] is int + ? defaultConfig['max'] + : int.tryParse(defaultConfig['max'].toString()) ?? max; + } + + if (defaultConfig['min'] != null) { + min = defaultConfig['min'] is int + ? defaultConfig['min'] + : int.tryParse(defaultConfig['min'].toString()) ?? min; + } + + if (defaultConfig['interval'] != null) { + interval = defaultConfig['interval'] is int + ? defaultConfig['interval'] + : int.tryParse(defaultConfig['interval'].toString()) ?? interval; + } + } else { + throw '未找到默认配置,请检查配置文件'; + } + + return Container( + decoration: BoxDecoration( + color: themeController.currentColor.sc5, + borderRadius: + BorderRadius.circular(AppConstants().normal_container_radius), + ), + child: Padding( + padding: + EdgeInsetsDirectional.fromSTEB(40.rpx, 20.rpx, 40.rpx, 20.rpx), + child: Column( + children: [ + /// ---- 呼吸小于 ---- + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 30.rpx), + onTap: () { + final initialScore = min; + FocusScope.of(context).requestFocus(FocusNode()); + + Future.delayed(const Duration(milliseconds: 250), () { + showScorePickerDialog( + context, + title: "呼吸小于".tr, + initialHeight: initialScore, + min: 5, + max: 50, + onConfirm: (int selectedScore) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + + if (configIndex != -1) { + messageSettingController + .model.device_type_setting[configIndex] + ['min'] = selectedScore; + } else { + messageSettingController.model.device_type_setting + .add({ + "id": id, + "setting": 1, + "max": defaultConfig!['max'], + "min": selectedScore, + "interval": defaultConfig['interval'], + "appSetting": 1, + "serviceSetting": 1, + }); + } + + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": messageSettingController + .model.device_type_setting, + }; + + requestWithLog( + logTitle: "更新呼吸异常配置", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + messageSettingController.updateAll(); + }, + ); + }, + ); + }); + }, + child: _buildRow("呼吸小于", "$min"), + ), + + /// ---- 呼吸大于 ---- + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 30.rpx), + onTap: () { + final initialScore = max; + FocusScope.of(context).requestFocus(FocusNode()); + + Future.delayed(const Duration(milliseconds: 250), () { + showScorePickerDialog( + context, + title: "呼吸大于".tr, + initialHeight: initialScore, + min: 5, + max: 50, + onConfirm: (int selectedScore) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + + if (configIndex != -1) { + messageSettingController + .model.device_type_setting[configIndex] + ['max'] = selectedScore; + } else { + messageSettingController.model.device_type_setting + .add({ + "id": id, + "setting": 1, + "max": selectedScore, + "min": defaultConfig!['min'], + "interval": defaultConfig['interval'], + "appSetting": 1, + "serviceSetting": 1, + }); + } + + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": messageSettingController + .model.device_type_setting, + }; + + requestWithLog( + logTitle: "更新呼吸异常配置", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + messageSettingController.updateAll(); + }, + ); + }, + ); + }); + }, + child: _buildRow("呼吸大于", "$max"), + ), + + /// ---- 提醒类型 ---- + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 30.rpx), + onTap: () { + final initialScore = interval; + FocusScope.of(context).requestFocus(FocusNode()); + + Future.delayed(const Duration(milliseconds: 250), () { + showIntervalPickerDialog( + unit: "分钟/次".tr, + context, + title: "提醒类型".tr, + initialValue: initialScore, + options: [60, 300, 600], + onConfirm: (int selectedScore) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + + if (configIndex != -1) { + messageSettingController + .model.device_type_setting[configIndex] + ['interval'] = selectedScore; + } else { + messageSettingController.model.device_type_setting + .add({ + "id": id, + "setting": 1, + "max": defaultConfig!['max'], + "min": defaultConfig['min'], + "interval": selectedScore, + "appSetting": 1, + "serviceSetting": 1, + }); + } + + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": messageSettingController + .model.device_type_setting, + }; + + requestWithLog( + logTitle: "更新呼吸异常配置", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + messageSettingController.updateAll(); + }, + ); + }, + ); + }); + }, + child: _buildRow("提醒类型", "${getShowInternal(id, interval)}"), + ), + ], + ), + ), + ); + } else if (id == 100003) { + // 离床超时 + // 1. 优先从 device_type_setting 中查找用户配置 + int interval = 600; // 默认值 + int duration = 300; // 默认值 + + // 2. 如果找到了用户配置,使用用户配置中的值 + if (userConfig != null) { + print('找到用户配置: $userConfig'); + + // 获取 interval 值 + if (userConfig['interval'] != null) { + interval = userConfig['interval'] is int + ? userConfig['interval'] + : int.tryParse(userConfig['interval'].toString()) ?? 600; + } + + // 获取 duration 值 + if (userConfig['duration'] != null) { + duration = userConfig['duration'] is int + ? userConfig['duration'] + : int.tryParse(userConfig['duration'].toString()) ?? 300; + } + } else { + // 如果找到了默认配置 + if (defaultConfig != null) { + print('找到默认配置: $defaultConfig'); + + // 获取 interval 值 + if (defaultConfig['interval'] != null) { + interval = defaultConfig['interval'] is int + ? defaultConfig['interval'] + : int.tryParse(defaultConfig['interval'].toString()) ?? 600; + } + + // 获取 duration 值 + if (defaultConfig['duration'] != null) { + duration = defaultConfig['duration'] is int + ? defaultConfig['duration'] + : int.tryParse(defaultConfig['duration'].toString()) ?? 300; + } + } else { + throw '未找到默认配置, 请检查配置文件'; + } + } + + return Container( + decoration: BoxDecoration( + color: themeController.currentColor.sc5, + borderRadius: + BorderRadius.circular(AppConstants().normal_container_radius), + ), + child: Padding( + padding: + EdgeInsetsDirectional.fromSTEB(40.rpx, 20.rpx, 40.rpx, 20.rpx), + child: Column( + children: [ + /// --- 离床时长 --- + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 30.rpx), + onTap: () { + final currentDuration = duration; + final initialDuration = currentDuration != null + ? int.tryParse(currentDuration.toString()) ?? 300 + : 300; + FocusScope.of(context).requestFocus(FocusNode()); + Future.delayed(const Duration(milliseconds: 250), () { + showIntervalPickerDialog( + options: [60, 300, 600], + unit: "分钟".tr, + context, + title: "离床时长".tr, + initialValue: initialDuration, + onConfirm: (int selectedDuration) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController + .model.device_type_setting[configIndex] + ['duration'] = selectedDuration; + } else { + messageSettingController.model.device_type_setting + .add({ + "id": id, + "setting": 1, + "duration": selectedDuration, + "interval": defaultConfig?['interval'] ?? 600, + "appSetting": 1, + "serviceSetting": 1, + }); + } + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": messageSettingController + .model.device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + messageSettingController.updateAll(); + }); + }, + ); + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "离床时间大于".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + ), + ), + Row( + children: [ + Text( + "${formatDuration(duration)}".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + + /// --- 提醒类型 --- + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 30.rpx), + onTap: () { + final currentScore = interval; + final initialScore = currentScore != null + ? int.tryParse(currentScore.toString()) ?? 600 + : 600; + FocusScope.of(context).requestFocus(FocusNode()); + Future.delayed(const Duration(milliseconds: 250), () { + showIntervalPickerDialog( + unit: "分钟".tr, + context, + title: "提醒类型".tr, + onConfirm: (int selectedScore) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController + .model.device_type_setting[configIndex] + ['interval'] = selectedScore; + } else { + messageSettingController.model.device_type_setting + .add({ + "id": id, + "setting": 1, + "duration": defaultConfig?['duration'] ?? 300, + "interval": selectedScore, + "appSetting": 1, + "serviceSetting": 1, + }); + } + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": messageSettingController + .model.device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + messageSettingController.updateAll(); + }); + }, + initialValue: initialScore, + options: [60, 300, 600], + ); + }); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "提醒类型".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + ), + ), + Row( + children: [ + Text( + "${getShowInternal(id, interval)}".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + ], + ), + ), + ); + } else if (id == 100004) { + // 未卧床 + // 1. 优先从 device_type_setting 中查找用户配置 + String time = "23:00"; // 默认值 + // 2. 如果找到了用户配置,使用用户配置中的 time 值 + if (userConfig != null) { + print('找到用户配置: $userConfig'); + // 获取 time 值 + if (userConfig['time'] != null) { + time = userConfig['time'].toString(); + } + } else { + // 如果找到了默认配置 + if (defaultConfig != null) { + print('找到默认配置: $defaultConfig'); + + // 获取 time 值 + if (defaultConfig['time'] != null) { + time = defaultConfig['time'].toString(); + } + } else { + throw '未找到默认配置, 请检查配置文件'; + } + } + + // 将时间字符串转换为数组格式 [小时, 分钟] + List parseTimeToArray(String timeStr) { + try { + List parts = timeStr.split(':'); + if (parts.length >= 2) { + return [int.tryParse(parts[0]) ?? 23, int.tryParse(parts[1]) ?? 0]; + } + } catch (e) { + print('时间解析错误: $e'); + } + return [23, 0]; // 默认值 + } + + // 将数组格式转换为时间字符串 + String formatTimeFromArray(List timeArr) { + return "${timeArr[0].toString().padLeft(2, '0')}:${timeArr[1].toString().padLeft(2, '0')}"; + } + + // 初始化时间数组 + List currentTimeArr = parseTimeToArray(time); + + return Container( + decoration: BoxDecoration( + color: themeController.currentColor.sc5, + borderRadius: + BorderRadius.circular(AppConstants().normal_container_radius), + ), + child: Padding( + padding: + EdgeInsetsDirectional.fromSTEB(40.rpx, 20.rpx, 40.rpx, 20.rpx), + child: ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0.rpx), + onTap: () { + FocusScope.of(context).requestFocus(FocusNode()); + Future.delayed(const Duration(milliseconds: 250), () { + showTHDayTimeSelectionDialog( + context, + dayTimeArr: currentTimeArr, + title: "未卧床时间大于".tr, + checkChange: (List selectedTime) { + // 格式化时间为字符串 + String formattedTime = formatTimeFromArray(selectedTime); + + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController + .model.device_type_setting[configIndex]['time'] = + formattedTime; + } else { + messageSettingController.model.device_type_setting.add({ + "id": id, + "setting": 1, + "time": formattedTime, + "appSetting": 1, + "serviceSetting": 1, + }); + } + + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": + messageSettingController.model.device_type_setting, + }; + + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + messageSettingController.updateAll(); + }, + ); + }, + ); + }); + }, + child: Container( + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 30.rpx, 0.rpx, 30.rpx), + child: Column( + children: [ + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + "未卧床时间大于".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + time.tr, // 显示配置的时间 + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ].divide(SizedBox(height: 60.rpx)), + ), + ), + ), + ), + ), + ); + } else if (id == 100005) { + // 未起床 + // 1. 优先从 device_type_setting 中查找用户配置 + String time = "23:00"; // 默认值 + + // 2. 如果找到了用户配置,使用用户配置中的 time 值 + if (userConfig != null) { + print('找到用户配置: $userConfig'); + + // 获取 time 值 + if (userConfig['time'] != null) { + time = userConfig['time'].toString(); + } + } else { + // 如果找到了默认配置 + if (defaultConfig != null) { + print('找到默认配置: $defaultConfig'); + + // 获取 time 值 + if (defaultConfig['time'] != null) { + time = defaultConfig['time'].toString(); + } + } else { + throw '未找到默认配置, 请检查配置文件'; + } + } + + // 将时间字符串转换为数组格式 [小时, 分钟] + List parseTimeToArray(String timeStr) { + try { + List parts = timeStr.split(':'); + if (parts.length >= 2) { + return [int.tryParse(parts[0]) ?? 23, int.tryParse(parts[1]) ?? 0]; + } + } catch (e) { + print('时间解析错误: $e'); + } + return [23, 0]; // 默认值 + } + + // 将数组格式转换为时间字符串 + String formatTimeFromArray(List timeArr) { + return "${timeArr[0].toString().padLeft(2, '0')}:${timeArr[1].toString().padLeft(2, '0')}"; + } + + // 初始化时间数组 + List currentTimeArr = parseTimeToArray(time); + + return Container( + decoration: BoxDecoration( + color: themeController.currentColor.sc5, + borderRadius: + BorderRadius.circular(AppConstants().normal_container_radius), + ), + child: Padding( + padding: + EdgeInsetsDirectional.fromSTEB(40.rpx, 20.rpx, 40.rpx, 20.rpx), + child: ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0.rpx), + onTap: () { + FocusScope.of(context).requestFocus(FocusNode()); + Future.delayed(const Duration(milliseconds: 250), () { + showTHDayTimeSelectionDialog( + context, + dayTimeArr: currentTimeArr, + title: "未起床时间大于".tr, // 修改标题为"未起床时间大于" + checkChange: (List selectedTime) { + // 格式化时间为字符串 + String formattedTime = formatTimeFromArray(selectedTime); + + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController + .model.device_type_setting[configIndex]['time'] = + formattedTime; + } else { + messageSettingController.model.device_type_setting.add({ + "id": id, + "setting": 1, + "time": formattedTime, + "appSetting": 1, + "serviceSetting": 1, + }); + } + + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": + messageSettingController.model.device_type_setting, + }; + + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + messageSettingController.updateAll(); + }, + ); + }, + ); + }); + }, + child: Container( + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 30.rpx, 0.rpx, 30.rpx), + child: Column( + children: [ + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + "未起床时间大于".tr, // 修改为"未起床时间大于" + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + time.tr, // 显示配置的时间 + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ].divide(SizedBox(height: 60.rpx)), + ), + ), + ), + ), + ), + ); + } else if (id == 200001) { + // 1. 优先从 device_type_setting 中查找用户配置 + int score = 60; // 默认值 + // 2. 如果找到了用户配置,使用用户配置中的 max 值 + if (userConfig != null) { + print('找到用户配置: $userConfig'); + // 获取 max 值 + if (userConfig['max'] != null) { + score = userConfig['max'] is int + ? userConfig['max'] + : int.tryParse(userConfig['max'].toString()) ?? 60; + print('从用户配置获取睡眠得分阈值: $score'); + } + } else { + // 如果找到了默认配置 + if (defaultConfig != null) { + print('找到默认配置: $defaultConfig'); + + // 获取 max 值 + if (defaultConfig['max'] != null) { + score = defaultConfig['max'] is int + ? defaultConfig['max'] + : int.tryParse(defaultConfig['max'].toString()) ?? 60; + print('从默认配置获取睡眠得分阈值: $score'); + } + } else { + print('未找到 id 为 $id 的任何配置,使用默认值: $score'); + } + } + print('最终睡眠得分阈值: $score'); + // 这里可以继续使用 score 变量... + return Container( + decoration: BoxDecoration( + color: themeController.currentColor.sc5, + borderRadius: + BorderRadius.circular(AppConstants().normal_container_radius), + ), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 40.rpx, + 20.rpx, // 第一个元素顶部有20.rpx间距 + 40.rpx, + 20.rpx), + child: ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: themeController.currentColor.sc21, + padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0.rpx, 0.rpx, 0.rpx), + onTap: () async { + final currentScore = score; + final initialScore = currentScore != null + ? int.tryParse(currentScore.toString()) ?? 60 + : 60; + FocusScope.of(context).requestFocus(FocusNode()); + Future.delayed(const Duration(milliseconds: 250), () { + showScorePickerDialog( + unit: "分".tr, + context, + title: "选择分数".tr, + initialHeight: initialScore, + onConfirm: (int selectedScore) { + int configIndex = messageSettingController + .model.device_type_setting + .indexWhere((item) => item['id'] == id); + if (configIndex != -1) { + // 更新找到的配置项 + messageSettingController + .model.device_type_setting[configIndex]['max'] = + selectedScore; // 根据你的业务逻辑,布尔值转成 1/0 + } else { + messageSettingController.model.device_type_setting.add({ + "id": id, + "setting": 1, + "max": selectedScore, + "appSetting": 1, + "serviceSetting": 1, + }); + } + var data = { + "type": type, + "setting": messageSettingController.model.setting, + "device_type_setting": + messageSettingController.model.device_type_setting, + }; + requestWithLog( + logTitle: "更新消息推送状态", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) { + // fetchDeviceMessageSetting(); + messageSettingController.updateAll(); + }); + }, + ); + }); + }, + child: Container( + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 30.rpx, 0.rpx, 30.rpx), + child: Column( + children: [ + Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + // "${((data["report"] as List)[i]["name"] ?? "")}".tr, + "睡眠报告评分小于".tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + Row( + mainAxisSize: MainAxisSize.max, + children: [ + // 可以根据需要显示其他数据 + Text( + "${score}".tr + + "分".tr, // 这里可以显示其他信息,比如: (data["real"] as List)[i]["value"] ?? "" + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ].divide(SizedBox(height: 60.rpx)), + )), + ), + ), + ), + ); + } else { + return Container(); + } + } catch (e) { + ef.log("获取内容失败-->$e"); + return Container(); + } +} + +// 辅助函数:格式化持续时间(秒转分钟) +String formatDuration(int seconds) { + if (seconds < 60) { + return "${seconds}" + "秒".tr; + } else { + int minutes = seconds ~/ 60; + return "${minutes}" + "分钟".tr; + } +} + +Widget _buildRow(String title, String value) { + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + title.tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: AppConstants().title_text_fontSize, + ), + ), + Row( + children: [ + Text( + value.tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController.currentColor.sc3, + fontSize: 26.rpx, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15.rpx, + color: themeController.currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ); +} + +getShowInternal(int id, int interval) { + String str = ""; + if (id == 100001) { + String prefix = "间隔报警".tr; + // interval 秒 -> 转换成分钟 + int minutes = (interval / 60).round(); + str = "${prefix}(${minutes}" + "分钟/次".tr + ")"; + } + if (id == 100002) { + String prefix = "间隔报警".tr; + // interval 秒 -> 转换成分钟 + int minutes = (interval / 60).round(); + str = "${prefix}(${minutes}" + "分钟/次".tr + ")"; + } + if (id == 100003) { + String prefix = "间隔报警".tr; + // interval 秒 -> 转换成分钟 + int minutes = (interval / 60).round(); + str = "${prefix}(${minutes}" + "分钟".tr + ")"; + } + return str; +} diff --git a/lib/pages/device_bind/after/after_wifi_page_person.dart b/lib/pages/device_bind/after/after_wifi_page_person.dart index 082dffd..c178b0a 100644 --- a/lib/pages/device_bind/after/after_wifi_page_person.dart +++ b/lib/pages/device_bind/after/after_wifi_page_person.dart @@ -1145,4 +1145,5 @@ class _AfterWifiPagePersonState extends State { onFailure: (res) {}, ); } + } diff --git a/lib/pages/device_bind/componnet/MessageSetting.dart b/lib/pages/device_bind/componnet/MessageSetting.dart index 4b9845d..500386d 100644 --- a/lib/pages/device_bind/componnet/MessageSetting.dart +++ b/lib/pages/device_bind/componnet/MessageSetting.dart @@ -1,578 +1,578 @@ -import 'dart:async'; +// import 'dart:async'; -import 'package:ef/ef.dart'; -import 'package:flutter/material.dart'; -import 'package:flutterflow_ui/flutterflow_ui.dart'; -import 'package:vbvs_app/common/color/ServiceConstant.dart'; -import 'package:vbvs_app/common/color/appConstants.dart'; -import 'package:vbvs_app/common/util/FitTool.dart'; -import 'package:vbvs_app/common/util/MyUtils.dart'; -import 'package:vbvs_app/common/util/requestWithLog.dart'; -import 'package:vbvs_app/component/base/GradientSwitch.dart'; -import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; -import 'package:vbvs_app/controller/message/common_message_setting_controller.dart'; -import 'package:vbvs_app/controller/message/message_setting_controller.dart'; -import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; +// import 'package:ef/ef.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutterflow_ui/flutterflow_ui.dart'; +// import 'package:vbvs_app/common/color/ServiceConstant.dart'; +// import 'package:vbvs_app/common/color/appConstants.dart'; +// import 'package:vbvs_app/common/util/FitTool.dart'; +// import 'package:vbvs_app/common/util/MyUtils.dart'; +// import 'package:vbvs_app/common/util/requestWithLog.dart'; +// import 'package:vbvs_app/component/base/GradientSwitch.dart'; +// import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; +// import 'package:vbvs_app/controller/message/common_message_setting_controller.dart'; +// import 'package:vbvs_app/controller/message/message_setting_controller.dart'; +// import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; -class MessageSettingPage extends StatefulWidget { - var data; - MessageSettingPage({super.key, required this.data}); +// class MessageSettingPage extends StatefulWidget { +// var data; +// MessageSettingPage({super.key, required this.data}); - @override - State createState() => _MessageSettingPageState(); -} +// @override +// State createState() => _MessageSettingPageState(); +// } -class _MessageSettingPageState extends State { - final ThemeController themeController = Get.find(); - MessageSettingController messageSettingController = Get.find(); - CommonMessageSettingController commonMessageSettingController = Get.find(); +// class _MessageSettingPageState extends State { +// final ThemeController themeController = Get.find(); +// MessageSettingController messageSettingController = Get.find(); +// CommonMessageSettingController commonMessageSettingController = Get.find(); - @override - void initState() { - super.initState(); - _fetchCommonMessageSetting(); - _fetchDeviceMessageSetting(); - } +// @override +// void initState() { +// super.initState(); +// _fetchCommonMessageSetting(); +// _fetchDeviceMessageSetting(); +// } - Future _fetchCommonMessageSetting() async { - String serviceAddress = ServiceConstant.service_address; - String serviceName = ServiceConstant.server_service; - String serviceApi = ServiceConstant.user_setting; - String type = "user_message_setting"; - String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; - requestWithLog( - logTitle: "查询用户消息配置", - method: MyHttpMethod.get, - queryUrl: queryUrl, - onSuccess: (res) { - if (res.data == null || res.data.isEmpty) { - var data = { - "type": type, - "setting": 1, - "appSetting": 1, - "serviceSetting": 1, - "tipSetting": 1, - "deviceUpgradeSetting": 1, - "deviceIssueSetting": 1, - }; - requestWithLog( - logTitle: "更新用户消息配置", - method: MyHttpMethod.put, - queryUrl: queryUrl, - data: data, - onSuccess: (res) { - requestWithLog( - logTitle: "查询用户消息配置", - method: MyHttpMethod.get, - queryUrl: queryUrl, - onSuccess: (res) { - if (res.data != null && res.data.isNotEmpty) { - var datalist = res.data; - commonMessageSettingController.model.setting = - datalist['setting']; - commonMessageSettingController.model.appSetting = - datalist['appSetting']; - commonMessageSettingController.model.serviceSetting = - datalist['serviceSetting']; - commonMessageSettingController.model.tipSetting = - datalist['tipSetting']; - commonMessageSettingController.model.deviceUpgradeSetting = - datalist['deviceUpgradeSetting']; - commonMessageSettingController.model.deviceIssueSetting = - datalist['deviceIssueSetting']; - commonMessageSettingController.updateAll(); - } - }, - ); +// Future _fetchCommonMessageSetting() async { +// String serviceAddress = ServiceConstant.service_address; +// String serviceName = ServiceConstant.server_service; +// String serviceApi = ServiceConstant.user_setting; +// String type = "user_message_setting"; +// String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; +// requestWithLog( +// logTitle: "查询用户消息配置", +// method: MyHttpMethod.get, +// queryUrl: queryUrl, +// onSuccess: (res) { +// if (res.data == null || res.data.isEmpty) { +// var data = { +// "type": type, +// "setting": 1, +// "appSetting": 1, +// "serviceSetting": 1, +// "tipSetting": 1, +// "deviceUpgradeSetting": 1, +// "deviceIssueSetting": 1, +// }; +// requestWithLog( +// logTitle: "更新用户消息配置", +// method: MyHttpMethod.put, +// queryUrl: queryUrl, +// data: data, +// onSuccess: (res) { +// requestWithLog( +// logTitle: "查询用户消息配置", +// method: MyHttpMethod.get, +// queryUrl: queryUrl, +// onSuccess: (res) { +// if (res.data != null && res.data.isNotEmpty) { +// var datalist = res.data; +// commonMessageSettingController.model.setting = +// datalist['setting']; +// commonMessageSettingController.model.appSetting = +// datalist['appSetting']; +// commonMessageSettingController.model.serviceSetting = +// datalist['serviceSetting']; +// commonMessageSettingController.model.tipSetting = +// datalist['tipSetting']; +// commonMessageSettingController.model.deviceUpgradeSetting = +// datalist['deviceUpgradeSetting']; +// commonMessageSettingController.model.deviceIssueSetting = +// datalist['deviceIssueSetting']; +// commonMessageSettingController.updateAll(); +// } +// }, +// ); - // - }, - ); - } else { - var datalist = res.data; - commonMessageSettingController.model.setting = datalist['setting']; - commonMessageSettingController.model.appSetting = - datalist['appSetting']; - commonMessageSettingController.model.serviceSetting = - datalist['serviceSetting']; - commonMessageSettingController.model.tipSetting = - datalist['tipSetting']; - commonMessageSettingController.model.deviceUpgradeSetting = - datalist['deviceUpgradeSetting']; - commonMessageSettingController.model.deviceIssueSetting = - datalist['deviceIssueSetting']; - commonMessageSettingController.updateAll(); - } - }, - onFailure: (res) { - print(res); - }, - ); - } +// // +// }, +// ); +// } else { +// var datalist = res.data; +// commonMessageSettingController.model.setting = datalist['setting']; +// commonMessageSettingController.model.appSetting = +// datalist['appSetting']; +// commonMessageSettingController.model.serviceSetting = +// datalist['serviceSetting']; +// commonMessageSettingController.model.tipSetting = +// datalist['tipSetting']; +// commonMessageSettingController.model.deviceUpgradeSetting = +// datalist['deviceUpgradeSetting']; +// commonMessageSettingController.model.deviceIssueSetting = +// datalist['deviceIssueSetting']; +// commonMessageSettingController.updateAll(); +// } +// }, +// onFailure: (res) { +// print(res); +// }, +// ); +// } - Future _fetchDeviceMessageSetting() async { - String serviceAddress = ServiceConstant.service_address; - String serviceName = ServiceConstant.server_service; - String serviceApi = ServiceConstant.user_setting; - String mac = widget.data['mac']; - String type = "user_device_message_setting_$mac"; - String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; - requestWithLog( - logTitle: "查询用户消息配置", - method: MyHttpMethod.get, - queryUrl: queryUrl, - onSuccess: (res) { - if (res.data == null || res.data.isEmpty) { - var data = { - "type": type, - "setting": 1, - "appSetting": 1, - "serviceSetting": 1, - }; - requestWithLog( - logTitle: "更新用户消息配置", - method: MyHttpMethod.put, - queryUrl: queryUrl, - data: data, - onSuccess: (res) { - requestWithLog( - logTitle: "查询用户消息配置", - method: MyHttpMethod.get, - queryUrl: queryUrl, - onSuccess: (res) { - if (res.data != null && res.data.isNotEmpty) { - var datalist = res.data; - messageSettingController.model.setting = - datalist['setting']; - messageSettingController.model.appSetting = - datalist['appSetting']; - messageSettingController.model.serviceSetting = - datalist['serviceSetting']; - messageSettingController.updateAll(); - } - }, - ); +// Future _fetchDeviceMessageSetting() async { +// String serviceAddress = ServiceConstant.service_address; +// String serviceName = ServiceConstant.server_service; +// String serviceApi = ServiceConstant.user_setting; +// String mac = widget.data['mac']; +// String type = "user_device_message_setting_$mac"; +// String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; +// requestWithLog( +// logTitle: "查询用户消息配置", +// method: MyHttpMethod.get, +// queryUrl: queryUrl, +// onSuccess: (res) { +// if (res.data == null || res.data.isEmpty) { +// var data = { +// "type": type, +// "setting": 1, +// "appSetting": 1, +// "serviceSetting": 1, +// }; +// requestWithLog( +// logTitle: "更新用户消息配置", +// method: MyHttpMethod.put, +// queryUrl: queryUrl, +// data: data, +// onSuccess: (res) { +// requestWithLog( +// logTitle: "查询用户消息配置", +// method: MyHttpMethod.get, +// queryUrl: queryUrl, +// onSuccess: (res) { +// if (res.data != null && res.data.isNotEmpty) { +// var datalist = res.data; +// messageSettingController.model.setting = +// datalist['setting']; +// messageSettingController.model.appSetting = +// datalist['appSetting']; +// messageSettingController.model.serviceSetting = +// datalist['serviceSetting']; +// messageSettingController.updateAll(); +// } +// }, +// ); - // - }, - ); - } else { - var datalist = res.data; - messageSettingController.model.setting = datalist['setting']; - messageSettingController.model.appSetting = datalist['appSetting']; - messageSettingController.model.serviceSetting = - datalist['serviceSetting']; - messageSettingController.updateAll(); - } - }, - onFailure: (res) { - print(res); - }, - ); - } +// // +// }, +// ); +// } else { +// var datalist = res.data; +// messageSettingController.model.setting = datalist['setting']; +// messageSettingController.model.appSetting = datalist['appSetting']; +// messageSettingController.model.serviceSetting = +// datalist['serviceSetting']; +// messageSettingController.updateAll(); +// } +// }, +// onFailure: (res) { +// print(res); +// }, +// ); +// } - @override - void dispose() { - super.dispose(); - } +// @override +// void dispose() { +// super.dispose(); +// } - @override - Widget build(BuildContext context) { - return LayoutBuilder( - builder: (context, bodysize) => GestureDetector( - // onTap: () => FocusScope.of(context).unfocus(),, - child: Container( - decoration: BoxDecoration( - image: DecorationImage( - image: AssetImage('assets/img/bgNoImg.png'), - fit: BoxFit.fill, - ), - ), - child: Scaffold( - backgroundColor: Colors.transparent, - appBar: AppBar( - backgroundColor: themeController.currentColor.sc17, - automaticallyImplyLeading: false, - iconTheme: IconThemeData( - color: themeController.currentColor.sc3, - ), - titleSpacing: 0, - title: Container( - width: double.infinity, - height: 180.rpx, - child: Stack( - alignment: Alignment.center, - children: [ - /// 居中标题 - Text( - '消息设置'.tr, - style: TextStyle( - fontFamily: 'ReadexPro', - color: themeController.currentColor.sc3, - letterSpacing: 0, - fontSize: 30.rpx, - ), - ), - Positioned( - left: 0, - child: returnIconButtomAddCallback(() {}), - ), - ], - ), - ), - actions: [], - centerTitle: false, - ), - body: GestureDetector( - child: SafeArea( - top: true, - child: Padding( - padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0, 0.rpx, 0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Padding( - padding: - EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0), - child: Container( - width: double.infinity, - constraints: BoxConstraints( - minHeight: 90.rpx, - ), - decoration: BoxDecoration( - color: themeController.currentColor.sc5), - child: Padding( - padding: EdgeInsetsDirectional.fromSTEB( - 30.rpx, 15.rpx, 30.rpx, 15.rpx), - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Text( - "消息提醒设置".tr, - style: TextStyle( - color: themeController.currentColor.sc3, - fontSize: - AppConstants().title_text_fontSize), - ), - ), - Obx(() { - return GradientSwitch( - value: commonMessageSettingController - .model.setting == - 1 - ? (messageSettingController - .model.setting == - 1 - ? true - : false) - : false, - onChanged: (val) { - if (commonMessageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: "请先在设置里的消息通知打开全部消息配置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - String serviceAddress = - ServiceConstant.service_address; - String serviceName = - ServiceConstant.server_service; - String serviceApi = - ServiceConstant.user_setting; - String mac = widget.data['mac']; - String type = - "user_device_message_setting_$mac"; - String queryUrl = - "${serviceAddress}${serviceName}${serviceApi}"; - var data = { - "type": type, - "setting": val == true ? 1 : 0, - "appSetting": messageSettingController - .model.appSetting, - "serviceSetting": - messageSettingController - .model.serviceSetting, - }; - requestWithLog( - logTitle: "更新消息推送状态", - method: MyHttpMethod.put, - queryUrl: queryUrl, - data: data, - onSuccess: (res) { - _fetchDeviceMessageSetting(); - messageSettingController - .updateAll(); - }); - }, - activeGradient: LinearGradient( - colors: [ - themeController.currentColor.sc1, - themeController.currentColor.sc2 - ], - ), - activeThumbColor: Colors.white, - inactiveThumbColor: - stringToColor("#A2A4A9"), - inactiveColor: stringToColor("#161B28"), - ); - }), - ], - ), - ), - ), - ), - Padding( - padding: EdgeInsetsDirectional.fromSTEB( - 30.rpx, 21.rpx, 30.rpx, 0), - child: Container( - decoration: BoxDecoration( - color: themeController.currentColor.sc5, - borderRadius: BorderRadius.circular( - AppConstants().normal_container_radius), - ), - child: Padding( - padding: EdgeInsetsDirectional.fromSTEB( - 30.rpx, 40.rpx, 30.rpx, 54.rpx), - child: Container( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Text( - "APP消息".tr, - style: TextStyle( - color: themeController - .currentColor.sc3, - fontSize: AppConstants() - .title_text_fontSize), - ), - ), - Obx(() { - return GradientSwitch( - value: commonMessageSettingController - .model.setting == - 1 - ? (messageSettingController - .model.setting == - 1 - ? (messageSettingController - .model - .appSetting == - 1 - ? true - : false) - : false) - : false, - onChanged: (val) { - if (commonMessageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: - "请先在设置里的消息通知打开全部消息配置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - if (messageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: "请先打开消息提醒设置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - String serviceAddress = - ServiceConstant.service_address; - String serviceName = - ServiceConstant.server_service; - String serviceApi = - ServiceConstant.user_setting; - String mac = widget.data['mac']; - String type = - "user_device_message_setting_$mac"; - String queryUrl = - "${serviceAddress}${serviceName}${serviceApi}"; - var data = { - "type": type, - "setting": - messageSettingController - .model.setting, - "appSetting": val == true ? 1 : 0, - "serviceSetting": - messageSettingController - .model.serviceSetting, - }; - requestWithLog( - logTitle: "更新消息推送状态", - method: MyHttpMethod.put, - queryUrl: queryUrl, - data: data, - onSuccess: (res) { - _fetchDeviceMessageSetting(); - messageSettingController - .updateAll(); - }); - }, - activeGradient: LinearGradient( - colors: [ - themeController.currentColor.sc1, - themeController.currentColor.sc2 - ], - ), - activeThumbColor: Colors.white, - inactiveThumbColor: - stringToColor("#A2A4A9"), - inactiveColor: - stringToColor("#161B28"), - ); - }), - ], - ), - Text( - AppConstants().ent_type == 1 - ? "APP消息介绍".tr - : "打开“欢睡科技”APP,可以查看该设备的消息内容", - style: TextStyle( - color: themeController.currentColor.sc4, - fontSize: AppConstants() - .normal_text_fontSize), - ), - Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: - MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: Text( - "服务号消息".tr, - style: TextStyle( - color: themeController - .currentColor.sc3, - fontSize: AppConstants() - .title_text_fontSize), - ), - ), - Obx(() { - return GradientSwitch( - value: commonMessageSettingController - .model.setting == - 1 - ? (messageSettingController - .model.setting == - 1 - ? (messageSettingController - .model - .serviceSetting == - 1 - ? true - : false) - : false) - : false, - onChanged: (val) { - if (commonMessageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: - "请先在设置里的消息通知打开全部消息配置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - if (messageSettingController - .model.setting == - 0) { - TopSlideNotification.show(context, - text: "请先打开消息提醒设置".tr, - textColor: themeController - .currentColor.sc9); - return; - } - String serviceAddress = - ServiceConstant.service_address; - String serviceName = - ServiceConstant.server_service; - String serviceApi = - ServiceConstant.user_setting; - String mac = widget.data['mac']; - String type = - "user_device_message_setting_$mac"; - String queryUrl = - "${serviceAddress}${serviceName}${serviceApi}"; - var data = { - "type": type, - "setting": - messageSettingController - .model.setting, - "appSetting": - messageSettingController - .model.appSetting, - "serviceSetting": - val == true ? 1 : 0, - }; - requestWithLog( - logTitle: "更新消息推送状态", - method: MyHttpMethod.put, - queryUrl: queryUrl, - data: data, - onSuccess: (res) { - _fetchDeviceMessageSetting(); - messageSettingController - .updateAll(); - }); - }, - activeGradient: LinearGradient( - colors: [ - themeController.currentColor.sc1, - themeController.currentColor.sc2 - ], - ), - activeThumbColor: Colors.white, - inactiveThumbColor: - stringToColor("#A2A4A9"), - inactiveColor: - stringToColor("#161B28"), - ); - }), - ], - ), - Text( - AppConstants().ent_type == 1 - ? "服务号消息介绍".tr - : "无需打开“欢睡科技”APP,关注欢睡智能睡眠研究所服务号后,微信内即可接收该设备消息推送", - style: TextStyle( - color: themeController.currentColor.sc4, - fontSize: AppConstants() - .normal_text_fontSize), - ), - ].divide(SizedBox( - height: 49.rpx, - )), - ), - ), - ), - ), - ), - ], - ), - ), - ), - ), - ), - ), - ), - ); - } -} +// @override +// Widget build(BuildContext context) { +// return LayoutBuilder( +// builder: (context, bodysize) => GestureDetector( +// // onTap: () => FocusScope.of(context).unfocus(),, +// child: Container( +// decoration: BoxDecoration( +// image: DecorationImage( +// image: AssetImage('assets/img/bgNoImg.png'), +// fit: BoxFit.fill, +// ), +// ), +// child: Scaffold( +// backgroundColor: Colors.transparent, +// appBar: AppBar( +// backgroundColor: themeController.currentColor.sc17, +// automaticallyImplyLeading: false, +// iconTheme: IconThemeData( +// color: themeController.currentColor.sc3, +// ), +// titleSpacing: 0, +// title: Container( +// width: double.infinity, +// height: 180.rpx, +// child: Stack( +// alignment: Alignment.center, +// children: [ +// /// 居中标题 +// Text( +// '消息设置'.tr, +// style: TextStyle( +// fontFamily: 'ReadexPro', +// color: themeController.currentColor.sc3, +// letterSpacing: 0, +// fontSize: 30.rpx, +// ), +// ), +// Positioned( +// left: 0, +// child: returnIconButtomAddCallback(() {}), +// ), +// ], +// ), +// ), +// actions: [], +// centerTitle: false, +// ), +// body: GestureDetector( +// child: SafeArea( +// top: true, +// child: Padding( +// padding: EdgeInsetsDirectional.fromSTEB(0.rpx, 0, 0.rpx, 0), +// child: Column( +// mainAxisSize: MainAxisSize.min, +// children: [ +// Padding( +// padding: +// EdgeInsetsDirectional.fromSTEB(0, 30.rpx, 0, 0), +// child: Container( +// width: double.infinity, +// constraints: BoxConstraints( +// minHeight: 90.rpx, +// ), +// decoration: BoxDecoration( +// color: themeController.currentColor.sc5), +// child: Padding( +// padding: EdgeInsetsDirectional.fromSTEB( +// 30.rpx, 15.rpx, 30.rpx, 15.rpx), +// child: Row( +// mainAxisSize: MainAxisSize.max, +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Expanded( +// child: Text( +// "消息提醒设置".tr, +// style: TextStyle( +// color: themeController.currentColor.sc3, +// fontSize: +// AppConstants().title_text_fontSize), +// ), +// ), +// Obx(() { +// return GradientSwitch( +// value: commonMessageSettingController +// .model.setting == +// 1 +// ? (messageSettingController +// .model.setting == +// 1 +// ? true +// : false) +// : false, +// onChanged: (val) { +// if (commonMessageSettingController +// .model.setting == +// 0) { +// TopSlideNotification.show(context, +// text: "请先在设置里的消息通知打开全部消息配置".tr, +// textColor: themeController +// .currentColor.sc9); +// return; +// } +// String serviceAddress = +// ServiceConstant.service_address; +// String serviceName = +// ServiceConstant.server_service; +// String serviceApi = +// ServiceConstant.user_setting; +// String mac = widget.data['mac']; +// String type = +// "user_device_message_setting_$mac"; +// String queryUrl = +// "${serviceAddress}${serviceName}${serviceApi}"; +// var data = { +// "type": type, +// "setting": val == true ? 1 : 0, +// "appSetting": messageSettingController +// .model.appSetting, +// "serviceSetting": +// messageSettingController +// .model.serviceSetting, +// }; +// requestWithLog( +// logTitle: "更新消息推送状态", +// method: MyHttpMethod.put, +// queryUrl: queryUrl, +// data: data, +// onSuccess: (res) { +// _fetchDeviceMessageSetting(); +// messageSettingController +// .updateAll(); +// }); +// }, +// activeGradient: LinearGradient( +// colors: [ +// themeController.currentColor.sc1, +// themeController.currentColor.sc2 +// ], +// ), +// activeThumbColor: Colors.white, +// inactiveThumbColor: +// stringToColor("#A2A4A9"), +// inactiveColor: stringToColor("#161B28"), +// ); +// }), +// ], +// ), +// ), +// ), +// ), +// Padding( +// padding: EdgeInsetsDirectional.fromSTEB( +// 30.rpx, 21.rpx, 30.rpx, 0), +// child: Container( +// decoration: BoxDecoration( +// color: themeController.currentColor.sc5, +// borderRadius: BorderRadius.circular( +// AppConstants().normal_container_radius), +// ), +// child: Padding( +// padding: EdgeInsetsDirectional.fromSTEB( +// 30.rpx, 40.rpx, 30.rpx, 54.rpx), +// child: Container( +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// Row( +// mainAxisSize: MainAxisSize.max, +// mainAxisAlignment: +// MainAxisAlignment.spaceBetween, +// children: [ +// Expanded( +// child: Text( +// "APP消息".tr, +// style: TextStyle( +// color: themeController +// .currentColor.sc3, +// fontSize: AppConstants() +// .title_text_fontSize), +// ), +// ), +// Obx(() { +// return GradientSwitch( +// value: commonMessageSettingController +// .model.setting == +// 1 +// ? (messageSettingController +// .model.setting == +// 1 +// ? (messageSettingController +// .model +// .appSetting == +// 1 +// ? true +// : false) +// : false) +// : false, +// onChanged: (val) { +// if (commonMessageSettingController +// .model.setting == +// 0) { +// TopSlideNotification.show(context, +// text: +// "请先在设置里的消息通知打开全部消息配置".tr, +// textColor: themeController +// .currentColor.sc9); +// return; +// } +// if (messageSettingController +// .model.setting == +// 0) { +// TopSlideNotification.show(context, +// text: "请先打开消息提醒设置".tr, +// textColor: themeController +// .currentColor.sc9); +// return; +// } +// String serviceAddress = +// ServiceConstant.service_address; +// String serviceName = +// ServiceConstant.server_service; +// String serviceApi = +// ServiceConstant.user_setting; +// String mac = widget.data['mac']; +// String type = +// "user_device_message_setting_$mac"; +// String queryUrl = +// "${serviceAddress}${serviceName}${serviceApi}"; +// var data = { +// "type": type, +// "setting": +// messageSettingController +// .model.setting, +// "appSetting": val == true ? 1 : 0, +// "serviceSetting": +// messageSettingController +// .model.serviceSetting, +// }; +// requestWithLog( +// logTitle: "更新消息推送状态", +// method: MyHttpMethod.put, +// queryUrl: queryUrl, +// data: data, +// onSuccess: (res) { +// _fetchDeviceMessageSetting(); +// messageSettingController +// .updateAll(); +// }); +// }, +// activeGradient: LinearGradient( +// colors: [ +// themeController.currentColor.sc1, +// themeController.currentColor.sc2 +// ], +// ), +// activeThumbColor: Colors.white, +// inactiveThumbColor: +// stringToColor("#A2A4A9"), +// inactiveColor: +// stringToColor("#161B28"), +// ); +// }), +// ], +// ), +// Text( +// AppConstants().ent_type == 1 +// ? "APP消息介绍".tr +// : "打开“欢睡科技”APP,可以查看该设备的消息内容", +// style: TextStyle( +// color: themeController.currentColor.sc4, +// fontSize: AppConstants() +// .normal_text_fontSize), +// ), +// Row( +// mainAxisSize: MainAxisSize.max, +// mainAxisAlignment: +// MainAxisAlignment.spaceBetween, +// children: [ +// Expanded( +// child: Text( +// "服务号消息".tr, +// style: TextStyle( +// color: themeController +// .currentColor.sc3, +// fontSize: AppConstants() +// .title_text_fontSize), +// ), +// ), +// Obx(() { +// return GradientSwitch( +// value: commonMessageSettingController +// .model.setting == +// 1 +// ? (messageSettingController +// .model.setting == +// 1 +// ? (messageSettingController +// .model +// .serviceSetting == +// 1 +// ? true +// : false) +// : false) +// : false, +// onChanged: (val) { +// if (commonMessageSettingController +// .model.setting == +// 0) { +// TopSlideNotification.show(context, +// text: +// "请先在设置里的消息通知打开全部消息配置".tr, +// textColor: themeController +// .currentColor.sc9); +// return; +// } +// if (messageSettingController +// .model.setting == +// 0) { +// TopSlideNotification.show(context, +// text: "请先打开消息提醒设置".tr, +// textColor: themeController +// .currentColor.sc9); +// return; +// } +// String serviceAddress = +// ServiceConstant.service_address; +// String serviceName = +// ServiceConstant.server_service; +// String serviceApi = +// ServiceConstant.user_setting; +// String mac = widget.data['mac']; +// String type = +// "user_device_message_setting_$mac"; +// String queryUrl = +// "${serviceAddress}${serviceName}${serviceApi}"; +// var data = { +// "type": type, +// "setting": +// messageSettingController +// .model.setting, +// "appSetting": +// messageSettingController +// .model.appSetting, +// "serviceSetting": +// val == true ? 1 : 0, +// }; +// requestWithLog( +// logTitle: "更新消息推送状态", +// method: MyHttpMethod.put, +// queryUrl: queryUrl, +// data: data, +// onSuccess: (res) { +// _fetchDeviceMessageSetting(); +// messageSettingController +// .updateAll(); +// }); +// }, +// activeGradient: LinearGradient( +// colors: [ +// themeController.currentColor.sc1, +// themeController.currentColor.sc2 +// ], +// ), +// activeThumbColor: Colors.white, +// inactiveThumbColor: +// stringToColor("#A2A4A9"), +// inactiveColor: +// stringToColor("#161B28"), +// ); +// }), +// ], +// ), +// Text( +// AppConstants().ent_type == 1 +// ? "服务号消息介绍".tr +// : "无需打开“欢睡科技”APP,关注欢睡智能睡眠研究所服务号后,微信内即可接收该设备消息推送", +// style: TextStyle( +// color: themeController.currentColor.sc4, +// fontSize: AppConstants() +// .normal_text_fontSize), +// ), +// ].divide(SizedBox( +// height: 49.rpx, +// )), +// ), +// ), +// ), +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// ), +// ), +// ), +// ); +// } +// } diff --git a/lib/pages/device_bind/componnet/bind_dialog.dart b/lib/pages/device_bind/componnet/bind_dialog.dart index ae5847d..ff84e82 100644 --- a/lib/pages/device_bind/componnet/bind_dialog.dart +++ b/lib/pages/device_bind/componnet/bind_dialog.dart @@ -1001,132 +1001,400 @@ Future showTipDialog( ); } +// Future showUnBindTipDialog( +// BuildContext context, +// Widget widget, { +// Color? backgroundColor, +// VoidCallback? onConfirm, // “继续”按钮回调 +// VoidCallback? onCancel, // “下次再说”按钮回调 +// VoidCallback? onNoTip, // “下次再说”按钮回调 +// }) { +// ThemeController themeController = Get.find(); +// BlueteethBindController blueteethBindController = Get.find(); + +// return showDialog( +// context: context, +// barrierDismissible: true, +// barrierColor: Colors.black.withOpacity(0.5), +// builder: (BuildContext context) { +// return FrostedDialog( +// blurSigma: 3.0, +// child: Container( +// decoration: BoxDecoration( +// color: backgroundColor ?? themeController.currentColor.sc17, +// borderRadius: BorderRadius.circular(20.0), +// ), +// padding: EdgeInsetsDirectional.fromSTEB(64.rpx, 0, 64.rpx, 0), +// child: Container( +// width: double.infinity, +// constraints: BoxConstraints( +// maxHeight: MediaQuery.sizeOf(context).height * 0.656, +// ), +// child: Column( +// mainAxisSize: MainAxisSize.min, +// children: [ +// Align( +// alignment: AlignmentDirectional(0, 0), +// child: Padding( +// padding: EdgeInsetsDirectional.fromSTEB( +// 0.rpx, 93.rpx, 0, 30.rpx), +// child: widget, +// ), +// ), +// Padding( +// padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 10.rpx), +// child: CustomCard( +// borderRadius: AppConstants().button_container_radius, +// onTap: () { +// Get.back(); // 关闭对话框 +// if (onConfirm != null) { +// onConfirm(); // 调用确认回调 +// } +// }, +// colors: [ +// themeController.currentColor.sc1, +// themeController.currentColor.sc2, +// ], +// child: Container( +// width: MediaQuery.sizeOf(context).width, +// height: MediaQuery.sizeOf(context).height * 0.055, +// constraints: BoxConstraints( +// minWidth: 500.rpx, +// minHeight: 90.rpx, +// ), +// child: Row( +// mainAxisSize: MainAxisSize.max, +// mainAxisAlignment: MainAxisAlignment.center, +// children: [ +// Text( +// '继续'.tr, +// style: TextStyle( +// color: themeController.currentColor.sc3, +// fontFamily: 'Inter', +// fontSize: AppConstants().normal_text_fontSize, +// letterSpacing: 0.0, +// ), +// ), +// ].divide(SizedBox(width: 17.rpx)), +// ), +// ), +// ), +// ), +// Padding( +// padding: EdgeInsetsDirectional.fromSTEB(0, 19.rpx, 0, 60.rpx), +// child: CustomCard( +// borderRadius: AppConstants().button_container_radius, +// onTap: () { +// Get.back(); // 关闭对话框 +// if (onCancel != null) { +// onCancel(); // 调用取消回调 +// } +// }, +// colors: [Colors.transparent], +// child: Container( +// width: MediaQuery.sizeOf(context).width, +// height: MediaQuery.sizeOf(context).height * 0.055, +// decoration: BoxDecoration( +// border: Border.all( +// color: Colors.white, +// width: 0.5.rpx, +// ), +// borderRadius: BorderRadius.circular( +// AppConstants().button_container_radius), +// ), +// constraints: BoxConstraints( +// minWidth: 500.rpx, +// minHeight: 90.rpx, +// ), +// child: Row( +// mainAxisSize: MainAxisSize.max, +// mainAxisAlignment: MainAxisAlignment.center, +// children: [ +// Text( +// '下次再说'.tr, +// style: TextStyle( +// color: themeController.currentColor.sc3, +// fontFamily: 'Inter', +// fontSize: AppConstants().normal_text_fontSize, +// letterSpacing: 0.0, +// ), +// ), +// ].divide(SizedBox(width: 17.rpx)), +// ), +// ), +// ), +// ), +// Padding( +// padding: EdgeInsets.fromLTRB(0, 0, 0, 30.rpx), +// child: Container( +// width: double.infinity, +// child: Column( +// mainAxisSize: MainAxisSize.max, +// children: [ +// Container( +// width: double.infinity, +// child: Row( +// mainAxisSize: MainAxisSize.max, +// mainAxisAlignment: MainAxisAlignment.center, +// children: [ +// Theme( +// data: ThemeData( +// checkboxTheme: CheckboxThemeData( +// visualDensity: VisualDensity.compact, +// materialTapTargetSize: +// MaterialTapTargetSize.shrinkWrap, +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(64), +// ), +// ), +// unselectedWidgetColor: Color(0xFFD3D3D3), +// ), +// child: Obx( +// () => Checkbox( +// value: +// blueteethBindController.model.read == +// 1 +// ? false +// : true, +// onChanged: (newValue) async { +// blueteethBindController.model.read = +// newValue == true ? 0 : 1; +// blueteethBindController.updateAll(); +// }, +// side: BorderSide( +// width: 1.5, +// color: Colors.white, +// ), +// activeColor: stringToColor("#16C89F"), +// ), +// )), +// Text( +// '绑定引导.不再提示'.tr, +// style: TextStyle( +// fontFamily: 'Inter', +// fontSize: 26.rpx, +// letterSpacing: 0.0, +// color: themeController.currentColor.sc3, +// ), +// ), +// ].divide(SizedBox(width: 22.rpx)), +// ), +// ), +// ].divide(SizedBox(height: 42.rpx)), +// ), +// ), +// ) +// ], +// ), +// ), +// ), +// ); +// }, +// ); +// } + Future showUnBindTipDialog( BuildContext context, Widget widget, { Color? backgroundColor, VoidCallback? onConfirm, // “继续”按钮回调 VoidCallback? onCancel, // “下次再说”按钮回调 + bool initialNoTipValue = false, // 初始的"不再提示"值,从外部传入 + ValueChanged? onNoTipChanged, // "不再提示"值变化时的回调 }) { ThemeController themeController = Get.find(); - BlueteethBindController blueteethBindController = Get.find(); + // 移除原来的控制器依赖,使用传入的初始值 + // BlueteethBindController blueteethBindController = Get.find(); + + // 使用局部状态管理不再提示的值 + bool noTipValue = initialNoTipValue; return showDialog( context: context, barrierDismissible: true, barrierColor: Colors.black.withOpacity(0.5), builder: (BuildContext context) { - return FrostedDialog( - blurSigma: 3.0, - child: Container( - decoration: BoxDecoration( - color: backgroundColor ?? themeController.currentColor.sc17, - borderRadius: BorderRadius.circular(20.0), - ), - padding: EdgeInsetsDirectional.fromSTEB(64.rpx, 0, 64.rpx, 0), - child: Container( - width: double.infinity, - constraints: BoxConstraints( - maxHeight: MediaQuery.sizeOf(context).height * 0.656, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Align( - alignment: AlignmentDirectional(0, 0), - child: Padding( - padding: EdgeInsetsDirectional.fromSTEB( - 0.rpx, 93.rpx, 0, 30.rpx), - child: widget, - ), + // 使用StatefulBuilder来管理局部状态 + return StatefulBuilder( + builder: (context, setState) { + return FrostedDialog( + blurSigma: 3.0, + child: Container( + decoration: BoxDecoration( + color: backgroundColor ?? themeController.currentColor.sc17, + borderRadius: BorderRadius.circular(20.0), + ), + padding: EdgeInsetsDirectional.fromSTEB(64.rpx, 0, 64.rpx, 0), + child: Container( + width: double.infinity, + constraints: BoxConstraints( + maxHeight: MediaQuery.sizeOf(context).height * 0.656, ), - Padding( - padding: EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 10.rpx), - child: CustomCard( - borderRadius: AppConstants().button_container_radius, - onTap: () { - Get.back(); // 关闭对话框 - if (onConfirm != null) { - onConfirm(); // 调用确认回调 - } - }, - colors: [ - themeController.currentColor.sc1, - themeController.currentColor.sc2, - ], - child: Container( - width: MediaQuery.sizeOf(context).width, - height: MediaQuery.sizeOf(context).height * 0.055, - constraints: BoxConstraints( - minWidth: 500.rpx, - minHeight: 90.rpx, - ), - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - '继续'.tr, - style: TextStyle( - color: themeController.currentColor.sc3, - fontFamily: 'Inter', - fontSize: AppConstants().normal_text_fontSize, - letterSpacing: 0.0, - ), - ), - ].divide(SizedBox(width: 17.rpx)), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Align( + alignment: AlignmentDirectional(0, 0), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 93.rpx, 0, 30.rpx), + child: widget, ), ), - ), - ), - Padding( - padding: EdgeInsetsDirectional.fromSTEB(0, 19.rpx, 0, 60.rpx), - child: CustomCard( - borderRadius: AppConstants().button_container_radius, - onTap: () { - Get.back(); // 关闭对话框 - if (onCancel != null) { - onCancel(); // 调用取消回调 - } - }, - colors: [Colors.transparent], - child: Container( - width: MediaQuery.sizeOf(context).width, - height: MediaQuery.sizeOf(context).height * 0.055, - decoration: BoxDecoration( - border: Border.all( - color: Colors.white, - width: 0.5.rpx, + Padding( + padding: + EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 10.rpx), + child: CustomCard( + borderRadius: AppConstants().button_container_radius, + onTap: () { + Get.back(); // 关闭对话框 + if (onConfirm != null) { + onConfirm(); // 调用确认回调 + } + }, + colors: [ + themeController.currentColor.sc1, + themeController.currentColor.sc2, + ], + child: Container( + width: MediaQuery.sizeOf(context).width, + height: MediaQuery.sizeOf(context).height * 0.055, + constraints: BoxConstraints( + minWidth: 500.rpx, + minHeight: 90.rpx, + ), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + '继续'.tr, + style: TextStyle( + color: themeController.currentColor.sc3, + fontFamily: 'Inter', + fontSize: AppConstants().normal_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 17.rpx)), + ), ), - borderRadius: BorderRadius.circular( - AppConstants().button_container_radius), - ), - constraints: BoxConstraints( - minWidth: 500.rpx, - minHeight: 90.rpx, - ), - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - '下次再说'.tr, - style: TextStyle( - color: themeController.currentColor.sc3, - fontFamily: 'Inter', - fontSize: AppConstants().normal_text_fontSize, - letterSpacing: 0.0, - ), - ), - ].divide(SizedBox(width: 17.rpx)), ), ), - ), + Padding( + padding: + EdgeInsetsDirectional.fromSTEB(0, 19.rpx, 0, 60.rpx), + child: CustomCard( + borderRadius: AppConstants().button_container_radius, + onTap: () { + Get.back(); // 关闭对话框 + if (onCancel != null) { + onCancel(); // 调用取消回调 + } + }, + colors: [Colors.transparent], + child: Container( + width: MediaQuery.sizeOf(context).width, + height: MediaQuery.sizeOf(context).height * 0.055, + decoration: BoxDecoration( + border: Border.all( + color: Colors.white, + width: 0.5.rpx, + ), + borderRadius: BorderRadius.circular( + AppConstants().button_container_radius), + ), + constraints: BoxConstraints( + minWidth: 500.rpx, + minHeight: 90.rpx, + ), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + '下次再说'.tr, + style: TextStyle( + color: themeController.currentColor.sc3, + fontFamily: 'Inter', + fontSize: AppConstants().normal_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 17.rpx)), + ), + ), + ), + ), + Padding( + padding: EdgeInsets.fromLTRB(0, 0, 0, 30.rpx), + child: Container( + width: double.infinity, + child: Column( + mainAxisSize: MainAxisSize.max, + children: [ + Container( + width: double.infinity, + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Theme( + data: ThemeData( + checkboxTheme: CheckboxThemeData( + visualDensity: VisualDensity.compact, + materialTapTargetSize: + MaterialTapTargetSize.shrinkWrap, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(64), + ), + ), + unselectedWidgetColor: Color(0xFFD3D3D3), + ), + child: Checkbox( + value: noTipValue, + onChanged: (newValue) { + if (newValue != null) { + setState(() { + noTipValue = newValue; + }); + + // 回调新的值给外部 + if (onNoTipChanged != null) { + onNoTipChanged(noTipValue); + } + } + }, + side: BorderSide( + width: 1.5, + color: Colors.white, + ), + activeColor: stringToColor("#16C89F"), + ), + ), + Text( + '绑定引导.不再提示'.tr, + style: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController.currentColor.sc3, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + ), + ].divide(SizedBox(height: 42.rpx)), + ), + ), + ) + ], ), - ], + ), ), - ), - ), + ); + }, ); }, ); diff --git a/lib/pages/login/other_login.dart b/lib/pages/login/other_login.dart index 4d79588..ed8dd02 100644 --- a/lib/pages/login/other_login.dart +++ b/lib/pages/login/other_login.dart @@ -43,6 +43,7 @@ class _OtherLoginPageState extends State { void dispose() { _tapRecognizer2.dispose(); _tapRecognizer4.dispose(); + loginController.fluwxCancelable?.cancel(); super.dispose(); } @@ -104,7 +105,9 @@ class _OtherLoginPageState extends State { loginController.fluwxCancelable?.cancel(); // 登录成功移出网络检查监听 Checknetwork.subscription?.cancel(); - Get.offAndToNamed("/mianPageBottomChange"); + if (Get.currentRoute != '/mianPageBottomChange') { + Get.offAndToNamed("/mianPageBottomChange"); + } } // TODO 操作全部跳转页面前成功以后移除监听,防止重复监听,其他方式登录成功也需要移出监听 // fluwxCancelable?.cancel(); @@ -119,6 +122,7 @@ class _OtherLoginPageState extends State { } } }); + } @override @@ -625,6 +629,7 @@ class _OtherLoginPageState extends State { ), ), ), + Padding( padding: EdgeInsetsDirectional.fromSTEB(0, 26.rpx, 0, 0), diff --git a/lib/pages/login/th_bind_tel_page.dart b/lib/pages/login/th_bind_tel_page.dart index a5d7ed5..b5c0d03 100644 --- a/lib/pages/login/th_bind_tel_page.dart +++ b/lib/pages/login/th_bind_tel_page.dart @@ -64,6 +64,20 @@ class THBindTelWidget extends GetView { ), Positioned( left: 0.rpx, + // child: returnIconButtomNew(onBack: () { + // UserInfoController userInfoController = Get.find(); + // ApiResponse apiResponse = userInfoController.logOut(); + // TopSlideNotification.show( + // context, + // text: apiResponse.msg!, + // textColor: apiResponse.code == HttpStatusCodes.ok + // ? themeController.currentColor.sc2 + // : themeController.currentColor.sc9, + // ); + // if (apiResponse.code == HttpStatusCodes.ok) { + // Get.offAllNamed("/mianPageBottomChange"); + // } + // }), child: returnIconButtomNew(), ), ], @@ -163,6 +177,43 @@ class THBindTelWidget extends GetView { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 0, 0, 0), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + InkWell( + onTap: () async {}, + child: Container( + alignment: Alignment.center, + // constraints: BoxConstraints( + // minWidth: 150.rpx, + // ), + child: Text( + "+86", + style: TextStyle( + fontFamily: 'Readex Pro', + color: themeController + .currentColor.sc4, + fontSize: AppConstants() + .middler_text_fontSize, + letterSpacing: 0, + ), + ), + ), + ), + SizedBox( + height: 30.rpx, + child: VerticalDivider( + thickness: 2.rpx, + color: themeController + .currentColor.sc4, + ), + ), + ].divide(SizedBox(width: 10.rpx)), + ), + ), Expanded( child: Align( alignment: diff --git a/lib/pages/main_bottom/e_page.dart b/lib/pages/main_bottom/e_page.dart index 0632080..c7bd14c 100644 --- a/lib/pages/main_bottom/e_page.dart +++ b/lib/pages/main_bottom/e_page.dart @@ -135,12 +135,14 @@ class _EPageState extends State with AutomaticKeepAliveClientMixin { Widget _buildLoggedInContent() { return Obx(() { if (finalUri.isEmpty) { - return Center(child: CircularProgressIndicator( - strokeWidth: 2, - valueColor: AlwaysStoppedAnimation( - themeController.currentColor.sc1, - ), - ),); + return Center( + child: CircularProgressIndicator( + strokeWidth: 2, + valueColor: AlwaysStoppedAnimation( + themeController.currentColor.sc1, + ), + ), + ); } // 如果设备列表为空 @@ -166,7 +168,9 @@ class _EPageState extends State with AutomaticKeepAliveClientMixin { return Stack( children: [ InAppWebView( - initialUrlRequest: URLRequest(url: WebUri(finalUri.value+"?t=${DateTime.now().millisecondsSinceEpoch}")), + initialUrlRequest: URLRequest( + url: WebUri(finalUri.value + + "?t=${DateTime.now().millisecondsSinceEpoch}")), onLoadStart: (controller, url) { isPageLoading.value = true; }, @@ -178,12 +182,14 @@ class _EPageState extends State with AutomaticKeepAliveClientMixin { valueListenable: isPageLoading, builder: (context, isLoading, child) { return isLoading - ? Center(child:CircularProgressIndicator( + ? Center( + child: CircularProgressIndicator( strokeWidth: 2, valueColor: AlwaysStoppedAnimation( themeController.currentColor.sc1, ), - ),) + ), + ) : SizedBox.shrink(); }, ), @@ -212,55 +218,127 @@ class _EPageState extends State with AutomaticKeepAliveClientMixin { } Future getDeviceList() async { - BodyDeviceController bodyDeviceController = Get.find(); - ApiResponse apiResponse = await bodyDeviceController.getDeviceList(); + try { + BodyDeviceController bodyDeviceController = Get.find(); + ApiResponse apiResponse = + await bodyDeviceController.getDeviceList(isAllDevice: true); - if (apiResponse.code == HttpStatusCodes.ok) { - List rawList = apiResponse.data; + if (apiResponse.code == HttpStatusCodes.ok) { + List rawList = apiResponse.data; - // 提取 mac 和 person.name - List> newList = rawList.map((item) { - String mac = item['mac'] ?? ''; - String name = (item['person'] != null && - item['person']['name'] != null && - item['person']['name'].toString().trim().isNotEmpty) - ? item['person']['name'] + "_${mac}" - : '未命名'.tr + "_${mac}"; - return { - 'mac': mac, - 'name': name, - }; - }).toList(); + // 提取 mac 和 person.name + List> newList = rawList.map((item) { + String mac = item['mac'] ?? ''; + String name = (item['person'] != null && + item['person']['name'] != null && + item['person']['name'].toString().trim().isNotEmpty) + ? item['person']['name'] + "_${mac}" + : '未命名'.tr + "_${mac}"; + return { + 'mac': mac, + 'name': name, + }; + }).toList(); - deviceList.value = newList; + deviceList.value = newList; - // 拼接参数 person - if (deviceList.isNotEmpty) { - // JSON 编码整个 deviceList 对象数组 - String personParam = Uri.encodeComponent(jsonEncode(deviceList)); - finalUri.value = "${widget.sleepUri}?person=$personParam"; + // 拼接参数 person + if (deviceList.isNotEmpty) { + // JSON 编码整个 deviceList 对象数组 + String personParam = Uri.encodeComponent(jsonEncode(deviceList)); + finalUri.value = "${widget.sleepUri}?person=$personParam"; + } else { + finalUri.value = widget.sleepUri; + } + } + String? language = ""; + if (AppConstants().ent_type == APPPackageType.MHT.code) { + if (mhLanguageController.selectLanguage != null) { + language = mhLanguageController.selectLanguage.value!.language_code; + } } else { - finalUri.value = widget.sleepUri; + if (languageController.selectLanguage != null) { + language = languageController.selectLanguage.value!.language_code; + } } - } - String? language = ""; - if (AppConstants().ent_type == APPPackageType.MHT.code) { - if (mhLanguageController.selectLanguage != null) { - language = mhLanguageController.selectLanguage.value!.language_code; - } - } else { - if (languageController.selectLanguage != null) { - language = languageController.selectLanguage.value!.language_code; - } - } - if (language != null && language.isNotEmpty) { - if (finalUri.value.contains("?")) { - finalUri.value += "&lang=$language"; - } else { - finalUri.value += "?lang=$language"; + if (language != null && language.isNotEmpty) { + if (finalUri.value.contains("?")) { + finalUri.value += "&lang=$language"; + } else { + finalUri.value += "?lang=$language"; + } } + ef.log("msg"); + } catch (e) { + ef.log(e.toString()); } - ef.log("msg"); } + + // Future getDeviceList() async { + // try { + // BodyDeviceController bodyDeviceController = Get.find(); + // ApiResponse apiResponse = + // await bodyDeviceController.getDeviceList(isAllDevice: true); + + // // 调试:打印返回的数据结构 + // print('API响应数据: $apiResponse'); + // print('API响应数据类型: ${apiResponse.data.runtimeType}'); + // print('API响应数据内容: ${apiResponse.data}'); + + // if (apiResponse.code == HttpStatusCodes.ok) { + // List rawList = apiResponse.data; + + // // 调试:检查 rawList 的类型和内容 + // print('rawList 类型: ${rawList.runtimeType}'); + // print('rawList 长度: ${rawList.length}'); + // if (rawList.isNotEmpty) { + // print('rawList[0] 类型: ${rawList[0].runtimeType}'); + // print('rawList[0] 内容: ${rawList[0]}'); + // } + + // // 安全处理:确保每个元素都是 Map + // List> newList = + // rawList.whereType().map((item) { + // // 调试每个 item + // print('处理 item: $item'); + // print('item 类型: ${item.runtimeType}'); + + // String mac = (item['mac'] ?? '').toString(); + // String name = '未命名'.tr + "_${mac}"; + + // if (item['person'] != null && item['person'] is Map) { + // var person = item['person'] as Map; + // if (person['name'] != null && + // person['name'].toString().trim().isNotEmpty) { + // name = '${person['name']}_${mac}'; + // } + // } + + // return { + // 'mac': mac, + // 'name': name, + // }; + // }).toList(); + + // deviceList.value = newList; + + // // 拼接参数 person + // if (deviceList.isNotEmpty) { + // // JSON 编码整个 deviceList 对象数组 + // String personParam = Uri.encodeComponent(jsonEncode(deviceList)); + // finalUri.value = "${widget.sleepUri}?person=$personParam"; + // } else { + // finalUri.value = widget.sleepUri; + // } + // } + + // // ... 后续语言处理代码不变 + // } catch (e) { + // print('getDeviceList 错误详情: $e'); + // print('错误堆栈: ${e}'); + // ef.log(e.toString()); + // } + // } + } diff --git a/lib/pages/main_bottom/home_page.dart b/lib/pages/main_bottom/home_page.dart index 472ddc2..a59536e 100644 --- a/lib/pages/main_bottom/home_page.dart +++ b/lib/pages/main_bottom/home_page.dart @@ -1106,7 +1106,6 @@ class _HomePageState extends State { if (currentIndex >= device_bind_process.length) return; String code = device_bind_process[currentIndex]['mac']; - showUnBindTipDialog( context, Column( @@ -1145,6 +1144,7 @@ class _HomePageState extends State { ), ], ), + textAlign: TextAlign.center, // 添加这一行 ), ], ), @@ -1208,6 +1208,12 @@ class _HomePageState extends State { device_bind_process.removeAt(currentIndex); showNextDialog(); }, + onNoTipChanged: (value) { + updateDeviceTipStatus( + code, device_bind_process[currentIndex], value); + // device_bind_process.removeAt(currentIndex); + // showNextDialog(); + }, ); } @@ -1252,9 +1258,11 @@ class _HomePageState extends State { bool celibration = res.data['celibration']; bool person_info = res.data['person_info']; bool wifi = res.data['wifi']; - if (!celibration || !person_info || !wifi) { - res.data['device_info'] = element; - userInfoController.device_bind_status.add(res.data); + if (res.data['noTip'] == null || res.data['noTip'] == false) { + if (!celibration || !person_info || !wifi) { + res.data['device_info'] = element; + userInfoController.device_bind_status.add(res.data); + } } } } catch (e) { @@ -1267,4 +1275,43 @@ class _HomePageState extends State { print("查询设备绑定列表失败: $e"); } } + + void updateDeviceTipStatus(String mac, Map config, bool noTip) { + try { + String serviceAddress = ServiceConstant.service_address; + String serviceName = ServiceConstant.server_service; + String serviceApi = ServiceConstant.user_setting; + String type = "device_bind_status_$mac"; + String queryUrl = + "${serviceAddress}${serviceName}${serviceApi}?type=${type}"; + requestWithLog( + logTitle: "查询绑定流程", + method: MyHttpMethod.get, + queryUrl: queryUrl, + onSuccess: (res) { + print(res); + Map data = { + "type": type, + "mac": mac, + "wifi": res.data['wifi'], + "celibration": res.data['celibration'], + "person_info": res.data['person_info'], + "noTip": noTip, + "time": DateTime.now().millisecondsSinceEpoch, + }; + requestWithLog( + logTitle: "更新绑定流程", + method: MyHttpMethod.put, + queryUrl: queryUrl, + data: data, + onSuccess: (res) {}, + onFailure: (res) {}, + ); + }, + onFailure: (res) {}, + ); + } catch (e) { + ef.log("$e"); + } + } } diff --git a/lib/pages/main_bottom/message_page.dart b/lib/pages/main_bottom/message_page.dart index cb9c736..a31b9d6 100644 --- a/lib/pages/main_bottom/message_page.dart +++ b/lib/pages/main_bottom/message_page.dart @@ -37,7 +37,7 @@ class _MessagePageState extends State { // 监听切换语言 subscription = EventBus().on().listen((event) { - ef.log("切换语言事件通知:${event.language}"); + ef.log("切换语言事件通知:${event.language}"); _fetchMessageData(); }); _fetchMessageData(); @@ -255,7 +255,7 @@ class _MessagePageState extends State { 10.rpx, // 动态设置左侧位置 child: Container( width: lineWidth, - height: 4.rpx, + height: 5.rpx, decoration: BoxDecoration( color: themeController.currentColor.sc2, borderRadius: diff --git a/lib/pages/main_bottom/mine_page.dart b/lib/pages/main_bottom/mine_page.dart index 633e3fe..ab6561c 100644 --- a/lib/pages/main_bottom/mine_page.dart +++ b/lib/pages/main_bottom/mine_page.dart @@ -208,17 +208,17 @@ class _MinePageState extends State { final user = userInfoController .model.user!; - if (user.email != null && - user.email! - .isNotEmpty) { - return user.email!; - } else if (user.phone != - null && + if (user.phone != null && user.phone! .isNotEmpty) { return MyUtils .hidePhoneNumber( user.phone!); + } else if (user.email != + null && + user.email! + .isNotEmpty) { + return user.email!; } else { return "微信用户".tr; } @@ -690,7 +690,7 @@ class _MinePageState extends State { mainAxisSize: MainAxisSize.max, children: [ Text( - 'V1.0.2511.21', + 'V1.0.2512.03', style: TextStyle( fontFamily: 'Inter', // color: Color(0xFFD9E3EB), diff --git a/lib/pages/mh_page/CommonMessageSettingPage.dart b/lib/pages/mh_page/CommonMessageSettingPage.dart index 542379e..2101fde 100644 --- a/lib/pages/mh_page/CommonMessageSettingPage.dart +++ b/lib/pages/mh_page/CommonMessageSettingPage.dart @@ -41,7 +41,7 @@ class _CommonMessageSettingPageState String type = "user_message_setting"; String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; requestWithLog( - logTitle: "查询用户消息配置", + logTitle: "查询用户消息配置11", method: MyHttpMethod.get, queryUrl: queryUrl, onSuccess: (res) { @@ -62,7 +62,7 @@ class _CommonMessageSettingPageState data: data, onSuccess: (res) { requestWithLog( - logTitle: "查询用户消息配置", + logTitle: "查询用户消息配置12", method: MyHttpMethod.get, queryUrl: queryUrl, onSuccess: (res) { diff --git a/lib/pages/mh_page/device/mht_people_info.dart b/lib/pages/mh_page/device/mht_people_info.dart index 6c1cb65..2758290 100644 --- a/lib/pages/mh_page/device/mht_people_info.dart +++ b/lib/pages/mh_page/device/mht_people_info.dart @@ -400,7 +400,7 @@ class _MHTPeopleInfoPageState extends State { () { showHeightPickerDialog( context, - title: "选择身高".tr, + title: "选择分数".tr, initialHeight: int.tryParse( peopleList[index]['height'] ?? '170') ?? diff --git a/lib/pages/mh_page/user/controller/bind_tel_controller.dart b/lib/pages/mh_page/user/controller/bind_tel_controller.dart index 46dc3f1..3bc3915 100644 --- a/lib/pages/mh_page/user/controller/bind_tel_controller.dart +++ b/lib/pages/mh_page/user/controller/bind_tel_controller.dart @@ -164,6 +164,7 @@ class AuthBindTelController extends GetControllerEx { final data = { 'phone': model.phone, 'verify': model.code, + 'merge': true, }; var response = diff --git a/lib/pages/mh_page/user/page/edit_userinfo_page.dart b/lib/pages/mh_page/user/page/edit_userinfo_page.dart index 357207c..9a2fcde 100644 --- a/lib/pages/mh_page/user/page/edit_userinfo_page.dart +++ b/lib/pages/mh_page/user/page/edit_userinfo_page.dart @@ -442,6 +442,8 @@ class _UpdateUserPageState extends State { userInfoController.model.user!.tmpHead = null; userInfoController.model.user!.tmpNickName = null; await userInfoController.getUserInfo(); + userInfoController.model.user!.tmpNickName = userInfoController.model.user!.nick_name; + userInfoController.model.user!.tmpHead = userInfoController.model.user!.avatar; userInfoController.updateAll(); Get.back(); } diff --git a/lib/pages/person/person_page.dart b/lib/pages/person/person_page.dart index 884ed7a..230b5ba 100644 --- a/lib/pages/person/person_page.dart +++ b/lib/pages/person/person_page.dart @@ -447,7 +447,6 @@ class _EPageState extends State { currentHeight.toString()) ?? 170 : 170; - FocusScope.of(context) .requestFocus(FocusNode()); Future.delayed( diff --git a/lib/pages/person/select_time.dart b/lib/pages/person/select_time.dart index 5c0d9d3..1382e75 100644 --- a/lib/pages/person/select_time.dart +++ b/lib/pages/person/select_time.dart @@ -821,3 +821,338 @@ Future showWeightPickerDialog( ); } +Future showScorePickerDialog( + BuildContext context, { + required int initialHeight, + required Function(int selectedHeight) onConfirm, + String title = "选择分数", + String unit = "", // 单位(可选) + int min = 0, // ✅ 新增:最小值 + int max = 100, // ✅ 新增:最大值 +}) async { + /// 生成范围:min ~ max + List heights = List.generate(max - min + 1, (index) => min + index); + + /// 确保初始值在范围内 + if (initialHeight < min) initialHeight = min; + if (initialHeight > max) initialHeight = max; + + int selectedIndex = heights.indexOf(initialHeight); + final RxInt tempIndex = RxInt(selectedIndex); + + ThemeController themeController = Get.find(); + + await showDialog( + context: context, + barrierDismissible: true, + builder: (BuildContext context) { + return Stack( + children: [ + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Material( + color: Colors.transparent, + child: Dialog( + backgroundColor: themeController.currentColor.sc17, + insetPadding: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(0), + ), + child: Container( + padding: EdgeInsets.fromLTRB(0.rpx, 0.rpx, 0.rpx, 90.rpx), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + // ------- 顶部标题区域 ------- + Container( + padding: + EdgeInsets.fromLTRB(30.rpx, 0.rpx, 30.rpx, 0.rpx), + color: themeController.currentColor.sc5, + height: 80.rpx, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: EdgeInsets.only(top: 0), + onTap: () { + Get.back(); + }, + child: Container( + alignment: Alignment.center, + width: 110.rpx, + height: 60.rpx, + child: Text( + "取消".tr, + style: TextStyle( + fontSize: 30.rpx, + color: Colors.white, + ), + ), + ), + ), + Text( + title, + style: TextStyle( + fontFamily: 'Readex Pro', + color: themeController.currentColor.sc3, + fontSize: 30.rpx, + ), + ), + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: Colors.transparent, + padding: EdgeInsets.only(top: 0), + onTap: () { + onConfirm(heights[tempIndex.value]); + Get.back(); + }, + child: Container( + alignment: Alignment.center, + width: 110.rpx, + height: 60.rpx, + child: Text( + "确定".tr, + style: TextStyle( + fontSize: 30.rpx, + color: themeController.currentColor.sc2, + ), + ), + ), + ), + ], + ), + ), + + SizedBox(height: 20.rpx), + + // -------- 中间选择器 -------- + Stack( + children: [ + Positioned.fill( + child: IgnorePointer( + child: Center( + child: Container( + height: 90.rpx, + margin: + EdgeInsets.symmetric(horizontal: 95.rpx), + decoration: BoxDecoration( + color: themeController.currentColor.sc2, + borderRadius: BorderRadius.circular(16.rpx), + ), + ), + ), + ), + ), + SizedBox( + height: 240.rpx, + child: getOnePickers( + context, + heights, + tempIndex, + unit: unit, // 使用传入的单位 + ), + ), + ], + ), + ], + ), + ), + ), + ), + ), + ], + ); + }, + ); +} + +Future showIntervalPickerDialog( + BuildContext context, { + required int initialValue, + required Function(int selectedValue) onConfirm, + List options = const [], // ✅ 可选值数组(优先级最高) + int min = 0, // 若没有 options,则使用 min/max + int max = 100, + int type = 2, // 1=秒,2=分钟(默认),3=小时 + String unit = "分钟/次", + String title = "选择间隔", +}) async { + ThemeController themeController = Get.find(); + + /// ------------------------------------------ + /// 计算实际数据源:优先使用 options + /// ------------------------------------------ + List values; + if (options.isNotEmpty) { + values = [...options]; + } else { + values = List.generate(max - min + 1, (index) => min + index); + } + + /// ------------------------------------------ + /// 显示转换函数 + /// ------------------------------------------ + String formatValue(int raw) { + double result; + + switch (type) { + case 1: // 秒 + result = raw.toDouble(); + return "${result.toInt()}秒/次"; + + case 2: // 分钟 + result = raw / 60.0; + break; + + case 3: // 小时 + result = raw / 3600.0; + break; + + default: + result = raw.toDouble(); + } + + /// 去掉多余的小数,例如 1.0 → 1 + String text = + result % 1 == 0 ? result.toInt().toString() : result.toStringAsFixed(1); + + return "$text$unit"; + } + + /// ------------------------------------------ + /// 初始 index + /// ------------------------------------------ + int initialIndex = values.indexOf(initialValue); + if (initialIndex < 0) initialIndex = 0; + final RxInt tempIndex = RxInt(initialIndex); + await showDialog( + context: context, + barrierDismissible: true, + builder: (BuildContext context) { + return Stack( + children: [ + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Material( + color: Colors.transparent, + child: Dialog( + backgroundColor: themeController.currentColor.sc17, + insetPadding: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(0), + ), + child: Container( + padding: EdgeInsets.fromLTRB(0.rpx, 0.rpx, 0.rpx, 90.rpx), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + /// ---------------- 顶部标题 ---------------- + Container( + padding: + EdgeInsets.fromLTRB(30.rpx, 0.rpx, 30.rpx, 0.rpx), + color: themeController.currentColor.sc5, + height: 80.rpx, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: Colors.transparent, + onTap: () => Get.back(), + padding: EdgeInsets.all(0), + child: Container( + alignment: Alignment.center, + width: 110.rpx, + height: 60.rpx, + child: Text( + "取消".tr, + style: TextStyle( + fontSize: 30.rpx, + color: Colors.white, + ), + ), + ), + ), + Text( + title, + style: TextStyle( + fontFamily: 'Readex Pro', + color: themeController.currentColor.sc3, + fontSize: 30.rpx, + ), + ), + ClickableContainer( + backgroundColor: Colors.transparent, + highlightColor: Colors.transparent, + onTap: () { + onConfirm(values[tempIndex.value]); // 返回原始秒数 + Get.back(); + }, + padding: EdgeInsets.all(0), + child: Container( + alignment: Alignment.center, + width: 110.rpx, + height: 60.rpx, + child: Text( + "确定".tr, + style: TextStyle( + fontSize: 30.rpx, + color: themeController.currentColor.sc2, + ), + ), + ), + ), + ], + ), + ), + + SizedBox(height: 20.rpx), + + /// ---------------- 中间选择器 ---------------- + Stack( + children: [ + Positioned.fill( + child: IgnorePointer( + child: Center( + child: Container( + height: 90.rpx, + margin: + EdgeInsets.symmetric(horizontal: 95.rpx), + decoration: BoxDecoration( + color: themeController.currentColor.sc2, + borderRadius: BorderRadius.circular(16.rpx), + ), + ), + ), + ), + ), + SizedBox( + height: 240.rpx, + child: getOnePickers( + context, + values, + tempIndex, + + /// → 替换显示文本(核心) + customDisplay: (val) => formatValue(val), + ), + ), + ], + ), + ], + ), + ), + ), + ), + ), + ], + ); + }, + ); +} diff --git a/lib/pages/setting/common_mesaage_setting.dart b/lib/pages/setting/common_mesaage_setting.dart index 4b6b86c..4f57843 100644 --- a/lib/pages/setting/common_mesaage_setting.dart +++ b/lib/pages/setting/common_mesaage_setting.dart @@ -38,7 +38,7 @@ class _CommonMessageSettingPageState extends State { String type = "user_message_setting"; String queryUrl = "${serviceAddress}${serviceName}${serviceApi}?type=$type"; requestWithLog( - logTitle: "查询用户消息配置", + logTitle: "查询用户消息配置13", method: MyHttpMethod.get, queryUrl: queryUrl, onSuccess: (res) { @@ -59,7 +59,7 @@ class _CommonMessageSettingPageState extends State { data: data, onSuccess: (res) { requestWithLog( - logTitle: "查询用户消息配置", + logTitle: "查询用户消息配置14", method: MyHttpMethod.get, queryUrl: queryUrl, onSuccess: (res) { @@ -188,7 +188,7 @@ class _CommonMessageSettingPageState extends State { children: [ Expanded( child: Text( - "全部消息".tr, + "全部通知".tr, style: TextStyle( color: themeController.currentColor.sc3, diff --git a/lib/pages/user/about_us_page.dart b/lib/pages/user/about_us_page.dart index e4347d6..dd9e649 100644 --- a/lib/pages/user/about_us_page.dart +++ b/lib/pages/user/about_us_page.dart @@ -1,6 +1,5 @@ import 'package:ef/ef.dart'; import 'package:flutter/material.dart'; -import 'package:vbvs_app/common/color/appConstants.dart'; import 'package:vbvs_app/common/util/FitTool.dart'; import 'package:vbvs_app/common/util/MyUtils.dart'; import 'package:vbvs_app/component/tool/WebViewWidget.dart'; diff --git a/lib/pages/user/update_user_email.dart b/lib/pages/user/update_user_email.dart new file mode 100644 index 0000000..a46f572 --- /dev/null +++ b/lib/pages/user/update_user_email.dart @@ -0,0 +1,657 @@ +import 'package:EasyDartModule/EasyDartModule.dart' as edm; +import 'package:ef/ef.dart'; +import 'package:flutter/material.dart'; +import 'package:flutterflow_ui/flutterflow_ui.dart'; +import 'package:vbvs_app/common/color/appConstants.dart'; +import 'package:vbvs_app/common/color/app_uri_status.dart'; +import 'package:vbvs_app/common/util/DailyLogUtils.dart'; +import 'package:vbvs_app/common/util/FitTool.dart'; +import 'package:vbvs_app/common/util/MyUtils.dart'; +import 'package:vbvs_app/component/tool/CustomCard.dart'; +import 'package:vbvs_app/component/tool/NewTopSlideNotification.dart'; +import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; +import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart'; +import 'package:vbvs_app/controller/login/login_controller.dart'; +import 'package:vbvs_app/controller/main_bottom/global_controller.dart'; +import 'package:vbvs_app/controller/person/person_controller.dart'; +import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; +import 'package:vbvs_app/controller/time/countdown_controller.dart'; +import 'package:vbvs_app/controller/user_info_controller.dart'; +import 'package:vbvs_app/model/api_response.dart'; +import 'package:vbvs_app/model/user_data.dart'; + +class UpdateUserEmailPage extends StatefulWidget { + const UpdateUserEmailPage({super.key}); + + @override + State createState() => _UpdateUserEmailPageState(); +} + +class _UpdateUserEmailPageState extends State { + GlobalController globalController = Get.find(); + UserInfoController userInfoController = Get.find(); + BlueteethBindController blueteethBindController = Get.find(); + PersonController personController = Get.find(); + ThemeController themeController = Get.find(); + LoginController loginController = Get.find(); + + @override + void initState() { + super.initState(); + userInfoController.model.user!.tmpHead = null; + userInfoController.model.user!.tmpNickName = null; + userInfoController.model.user!.tmpHead = + userInfoController.model.user!.avatar; + userInfoController.model.user!.tmpNickName = + userInfoController.model.user!.nick_name; + loginController.model.updatePhone = null; + } + + @override + Widget build(BuildContext context) { + int login = userInfoController.model.login!; + return LayoutBuilder( + builder: (context, bodySize) => GestureDetector( + // onTap: () => FocusScope.of(context).unfocus(),, + child: Container( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/img/bgNoImg.png'), + fit: BoxFit.fill, + ), + ), + child: Scaffold( + backgroundColor: Colors.transparent, + appBar: AppBar( + backgroundColor: themeController.currentColor.sc17, + automaticallyImplyLeading: false, + iconTheme: IconThemeData( + color: themeController.currentColor.sc3, + ), + titleSpacing: 0, + title: Container( + width: double.infinity, + height: 180.rpx, + child: Stack( + alignment: Alignment.center, + children: [ + Text( + '更换邮箱'.tr, + style: TextStyle( + fontFamily: 'Readex Pro', + color: themeController.currentColor.sc3, + letterSpacing: 0, + fontSize: 30.rpx, + ), + ), + Positioned( + left: 0, + child: returnIconButtom, + ), + Positioned( + right: 20.rpx, + child: CustomCard( + borderRadius: 20.rpx, + onTap: () async { + if (loginController.model.updatePhone == null || + loginController.model.updatePhone == '') { + NewTopSlideNotification.show( + text: "请输入邮箱号", + textColor: themeController.currentColor.sc9, + ); + return; + } + ApiResponse apiResponse = + await userInfoController.updateData( + email: loginController.model.updatePhone); + TopSlideNotification.show( + context, + text: apiResponse.msg!, + textColor: apiResponse.code == HttpStatusCodes.ok + ? themeController.currentColor.sc2 + : themeController.currentColor.sc9, + ); + if (apiResponse.code == HttpStatusCodes.ok) { + userInfoController.model.user!.tmpHead = null; + userInfoController.model.user!.tmpNickName = null; + loginController.model.updatePhone = null; + await userInfoController.getUserInfo(); + userInfoController.model.user!.tmpNickName = userInfoController.model.user!.nick_name; + userInfoController.model.user!.tmpHead = userInfoController.model.user!.avatar; + userInfoController.updateAll(); + Get.back(); + } + }, + colors: [ + themeController.currentColor.sc1, + themeController.currentColor.sc2, + ], + child: Container( + width: 100.rpx, + height: 60.rpx, + alignment: Alignment.center, + padding: EdgeInsetsDirectional.fromSTEB( + 16.rpx, 0.rpx, 16.rpx, 0.rpx), + child: Text( + '修改资料页.保存'.tr, + style: TextStyle( + fontFamily: 'Inter Tight', + color: themeController.currentColor.sc3, + letterSpacing: 0.0, + ), + ), + ), + ), + ), + ], + ), + ), + actions: [], + centerTitle: false, + ), + body: SafeArea( + top: true, + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration(), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 30.rpx, 0.rpx, 30.rpx, 0.rpx), + child: Column( + mainAxisSize: MainAxisSize.max, + children: [ + Align( + alignment: AlignmentDirectional(-1, 0), + child: Padding( + padding: + EdgeInsetsDirectional.fromSTEB(0, 20.rpx, 0, 0), + child: Container( + alignment: Alignment.centerLeft, + width: double.infinity, + height: bodySize.maxHeight * 0.056, + constraints: BoxConstraints( + minHeight: 120.rpx, + ), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 60.rpx, 0, 35.rpx, 0), + child: Text( + "原邮箱号" + ":" + "${getHideEmail()}", + style: TextStyle( + color: themeController.currentColor.sc3, + fontSize: AppConstants().normal_text_fontSize, + ), + ), + ), + ), + ), + ), + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular( + AppConstants().normal_container_radius), + color: themeController.currentColor.sc17, + ), + child: Column( + children: [ + Align( + alignment: AlignmentDirectional(-1, 0), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0, 0.rpx, 0, 20.rpx), + child: Container( + width: double.infinity, + height: bodySize.maxHeight * 0.056, + decoration: BoxDecoration( + color: Colors.transparent, + borderRadius: BorderRadius.circular( + 0, + ), + ), + constraints: BoxConstraints( + minHeight: 90.rpx, + ), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 35.rpx, 0, 35.rpx, 0), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + // Padding( + // padding: EdgeInsetsDirectional.fromSTEB( + // 26.rpx, 0, 0, 0), + // child: Row( + // mainAxisSize: MainAxisSize.max, + // children: [ + // InkWell( + // onTap: () async {}, + // child: Container( + // alignment: Alignment.center, + // // constraints: BoxConstraints( + // // minWidth: 150.rpx, + // // ), + // child: Text( + // "+86", + // style: TextStyle( + // fontFamily: 'Readex Pro', + // color: themeController + // .currentColor.sc4, + // fontSize: AppConstants() + // .middler_text_fontSize, + // letterSpacing: 0, + // ), + // ), + // ), + // ), + // SizedBox( + // height: 30.rpx, + // child: VerticalDivider( + // thickness: 2.rpx, + // color: themeController + // .currentColor.sc4, + // ), + // ), + // ].divide(SizedBox(width: 10.rpx)), + // ), + // ), + + Expanded( + child: Container( + child: Align( + alignment: + AlignmentDirectional(-1, 0), + child: TextFormField( + onChanged: (value) { + loginController.model + .updatePhone = value; + }, + autofocus: false, + obscureText: false, + decoration: InputDecoration( + isDense: true, + labelStyle: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + hintText: '输入邮箱号码'.tr, + hintStyle: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController + .currentColor.sc4, + ), + enabledBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Color(0x00000000), + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + focusedBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Color(0x00000000), + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + errorBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red, + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + focusedErrorBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red, + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + filled: false, + fillColor: Colors.white, + ), + style: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController + .currentColor.sc3, + ), + cursorColor: themeController + .currentColor.sc3, + // validator: _model + // .textControllerValidator + // .asValidator(context), + ), + ), + ), + ), + ], + ), + ), + ), + ), + ), + Align( + alignment: AlignmentDirectional(-1, 0), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0, 0.rpx, 0, 0), + child: Container( + height: bodySize.maxHeight * 0.056, + width: double.infinity, + constraints: BoxConstraints( + minHeight: 90.rpx, + ), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 35.rpx, 0, 35.rpx, 0), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Container( + child: Align( + alignment: + AlignmentDirectional(-1, 0), + child: TextFormField( + onChanged: (value) { + loginController + .model.updateCode = value; + }, + autofocus: false, + obscureText: false, + decoration: InputDecoration( + isDense: true, + labelStyle: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + hintText: '其他手机登录页.输入验证码'.tr, + hintStyle: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController + .currentColor.sc4, + ), + enabledBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Color(0x00000000), + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + focusedBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Color(0x00000000), + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + errorBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red, + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + focusedErrorBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red, + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + filled: true, + fillColor: Colors.transparent, + ), + style: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController + .currentColor.sc3, + ), + cursorColor: themeController + .currentColor.sc3, + // validator: _model + // .textControllerValidator + // .asValidator(context), + ), + ), + ), + ), + Padding( + padding: + EdgeInsetsDirectional.fromSTEB( + 26.rpx, 0, 0, 0), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + SizedBox( + height: 30.rpx, + child: VerticalDivider( + thickness: 2.rpx, + color: themeController + .currentColor.sc7, + ), + ), + Obx(() { + final CountdownController + countdownController = + Get.find< + CountdownController>(); + return InkWell( + onTap: () async { + try { + DailyLogUtils.writeLog( + "点击获取验证码"); + if (countdownController + .countdown + .value != + 0) { + return; + } + ApiResponse apiResponse = + await loginController + .getUpdateTelCode( + context); + if (apiResponse.code != + HttpStatusCodes.ok) { + TopSlideNotification + .show( + context, + text: + apiResponse.msg!, + textColor: + themeController + .currentColor + .sc9, + ); + await DailyLogUtils + .writeLog( + "获取验证码成功,${apiResponse}"); + return; + } else { + TopSlideNotification + .show( + context, + text: + apiResponse.msg!, + textColor: + themeController + .currentColor + .sc2, + ); + await DailyLogUtils + .writeLog( + "获取验证码失败,${apiResponse}"); + } + countdownController + .countdown + .value == + 0 + ? countdownController + .startCountdown( + AppConstants + .code_time) + : null; + } catch (e) { + await DailyLogUtils + .writeLog( + "获取验证码异常,${e}"); + edm.EasyDartModule.logger + .info("获取验证码异常:${e}"); + } + }, + child: Container( + alignment: Alignment.center, + constraints: BoxConstraints( + minWidth: 150.rpx, + ), + child: Text( + countdownController + .countdown + .value == + 0 + ? '其他手机登录页.获取验证码'.tr + : '${countdownController.countdown.value}' + + "其他手机登录页.秒".tr, + style: TextStyle( + fontFamily: + 'Readex Pro', + color: themeController + .currentColor.sc2, + fontSize: AppConstants() + .middler_text_fontSize, + letterSpacing: 0, + ), + ), + ), + ); + }), + ].divide(SizedBox(width: 26.rpx)), + ), + ), + ], + ), + ), + ), + ), + ), + ], + ), + ), + ], + ), + ), + ), + ), + ), + ), + ), + ); + } + + Widget getImageWidget(BuildContext context) { + try { + UserInfoController controller = Get.find(); + var head = controller.model.user!.tmpHead; + return Container( + width: 200.rpx, + height: 200.rpx, + child: Container( + clipBehavior: Clip.antiAlias, + decoration: BoxDecoration( + shape: BoxShape.circle, + ), + child: head == null || head.isEmpty + ? Image.asset( + 'assets/img/avatar.png', + fit: BoxFit.cover, + ) + : Image.network( + head, + fit: BoxFit.cover, + ), + ), + ); + } catch (e) { + print(e); + } + return Container(); + } + + String getTextByUserInfo(String type) { + UserInfoController userInfoController = Get.find(); + UserModel userInfo = userInfoController.model.user!; + if (userInfo == null) { + return ""; + } + if (type == "phone") { + if (userInfo.phone == null || userInfo.phone!.isEmpty) { + return "更换".tr; + } else { + return "换绑".tr; + } + } + if (type == "email") { + if (userInfo.email == null || userInfo.email!.isEmpty) { + return "绑定".tr; + } else { + return "换绑".tr; + } + } + if (type == "wechat") { + if (userInfo.bindWx == null || userInfo.bindWx == false) { + return "绑定".tr; + } else { + return "解绑".tr; + } + } + return ""; + } + + getHideEmail() { + UserModel userModel = userInfoController.model.user!; + if (userModel.email == null || userModel.email == "") { + return "暂无".tr; + } + return userModel.email! + .replaceRange(3, userModel.email!.length - 3, "****"); + } +} diff --git a/lib/pages/user/update_user_page.dart b/lib/pages/user/update_user_page.dart index ea74671..b693816 100644 --- a/lib/pages/user/update_user_page.dart +++ b/lib/pages/user/update_user_page.dart @@ -3,9 +3,12 @@ import 'dart:io'; import 'package:EasyDartModule/EasyDartModule.dart' as edm; import 'package:ef/ef.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; import 'package:flutterflow_ui/flutterflow_ui.dart'; +import 'package:fluwx/fluwx.dart'; import 'package:vbvs_app/common/color/appConstants.dart'; import 'package:vbvs_app/common/color/app_uri_status.dart'; +import 'package:vbvs_app/common/util/CommonVariables.dart'; import 'package:vbvs_app/common/util/DailyLogUtils.dart'; import 'package:vbvs_app/common/util/FitTool.dart'; import 'package:vbvs_app/common/util/MyUtils.dart'; @@ -13,11 +16,14 @@ import 'package:vbvs_app/component/tool/ClickableContainer.dart'; import 'package:vbvs_app/component/tool/CustomCard.dart'; import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart'; +import 'package:vbvs_app/controller/login/login_controller.dart'; import 'package:vbvs_app/controller/main_bottom/global_controller.dart'; import 'package:vbvs_app/controller/person/person_controller.dart'; import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; import 'package:vbvs_app/controller/user_info_controller.dart'; import 'package:vbvs_app/model/api_response.dart'; +import 'package:vbvs_app/model/user_data.dart'; +import 'package:vbvs_app/pages/user/wx_unbind_dialog.dart'; class UpdateUserPage extends StatefulWidget { const UpdateUserPage({super.key}); @@ -42,6 +48,53 @@ class _UpdateUserPageState extends State { userInfoController.model.user!.avatar; userInfoController.model.user!.tmpNickName = userInfoController.model.user!.nick_name; + + Fluwx fluwx = userInfoController.fluwx; + userInfoController.fluwxCancelable = fluwx.addSubscriber((response) async { + if (response is WeChatAuthResponse) { + debugPrint('state :${response.state} \n code:${response.code}'); + int errCode = response.errCode ?? -9999; + if (errCode == 0) { + // TODO 微信登录成功 传递code给后台 再操作逻辑 + String code = response.code ?? ""; + //把微信登录返回的code传给后台,剩下的事就交给后台处理 + //首次未注册的用户引导去手机号填写页面 + //已注册的用户直接跳转首页 + if (CommonVariables.isNetWorkOn == false) { + TopSlideNotification.show(context, + text: "网络未连接,请开启设备网络后重试".tr, + textColor: themeController.currentColor.sc9); + // showToast("网络未连接,请开启设备网络后重试"); + return; + } + ApiResponse apiResponse = + await userInfoController.updateData(code: code); + TopSlideNotification.show( + context, + text: apiResponse.msg!, + textColor: apiResponse.code == HttpStatusCodes.ok + ? themeController.currentColor.sc2 + : themeController.currentColor.sc9, + ); + // TODO 操作全部跳转页面前成功以后移除监听,防止重复监听,其他方式登录成功也需要移出监听 + // fluwxCancelable?.cancel(); + } else if (errCode == -4) { + TopSlideNotification.show(context, + text: "用户拒绝授权".tr, textColor: themeController.currentColor.sc9); + // showToast("用户拒绝授权"); + } else if (errCode == -2) { + TopSlideNotification.show(context, + text: "用户取消授权".tr, textColor: themeController.currentColor.sc9); + // showToast("用户取消授权"); + } + } + }); + } + + @override + void dispose() { + userInfoController.fluwxCancelable?.cancel(); + super.dispose(); } @override @@ -103,6 +156,10 @@ class _UpdateUserPageState extends State { userInfoController.model.user!.tmpHead = null; userInfoController.model.user!.tmpNickName = null; await userInfoController.getUserInfo(); + userInfoController.model.user!.tmpNickName = + userInfoController.model.user!.nick_name; + userInfoController.model.user!.tmpHead = + userInfoController.model.user!.avatar; userInfoController.updateAll(); Get.back(); } @@ -142,13 +199,13 @@ class _UpdateUserPageState extends State { decoration: BoxDecoration(), child: Padding( padding: EdgeInsetsDirectional.fromSTEB( - 60.rpx, 0.rpx, 60.rpx, 0.rpx), + 0.rpx, 0.rpx, 0.rpx, 0.rpx), child: Column( mainAxisSize: MainAxisSize.max, children: [ Padding( padding: EdgeInsetsDirectional.fromSTEB( - 0.rpx, 76.rpx, 0.rpx, 0.rpx), + 60.rpx, 76.rpx, 60.rpx, 0.rpx), child: Container( width: MediaQuery.sizeOf(context).width * 0.213, height: MediaQuery.sizeOf(context).height * 0.098, @@ -158,6 +215,9 @@ class _UpdateUserPageState extends State { ), decoration: BoxDecoration(), child: Obx(() { + var aa = + userInfoController.model.user!.tmpNickName; + print(aa); return getImageWidget(context); })), ), @@ -165,7 +225,7 @@ class _UpdateUserPageState extends State { backgroundColor: Colors.transparent, highlightColor: themeController.currentColor.sc16, padding: EdgeInsetsDirectional.fromSTEB( - 0.rpx, 44.rpx, 0.rpx, 44.rpx), + 60.rpx, 44.rpx, 60.rpx, 44.rpx), borderRadius: 0, onTap: () async { edm.EasyDartModule.logger @@ -196,7 +256,7 @@ class _UpdateUserPageState extends State { ), Padding( padding: EdgeInsetsDirectional.fromSTEB( - 0.rpx, 79.rpx, 0.rpx, 0.rpx), + 60.rpx, 79.rpx, 60.rpx, 0.rpx), child: Container( width: double.infinity, decoration: BoxDecoration( @@ -310,6 +370,258 @@ class _UpdateUserPageState extends State { ), ), ), + SizedBox( + height: 100.rpx, + ), + Padding( + padding: EdgeInsets.fromLTRB(40.rpx, 0, 40.rpx, 0), + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular( + AppConstants().normal_container_radius), + color: themeController.currentColor.sc17, + ), + child: Column( + children: [ + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 20.rpx, 20.rpx, 20.rpx, 0.rpx), + child: ClickableContainer( + backgroundColor: Colors.transparent, // 容器背景色 + highlightColor: themeController + .currentColor.sc21, // 点击时的背景色 + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 0.rpx, 0.rpx, 0.rpx), + onTap: () async { + Get.toNamed('/updateUserTelPage'); + }, + child: Container( + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 20.rpx, 30.rpx, 20.rpx, 30.rpx), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + '手机号码'.tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController + .currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + getTextByUserInfo('phone'), + style: TextStyle( + fontFamily: 'Inter', + // color: Color(0xFFD9E3EB), + color: themeController + .currentColor.sc2, + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15 + .rpx, // 如果 SVG 中没有固定颜色,可以这样设置 + color: themeController + .currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + ), + ), + ), + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 40.rpx, 20.rpx, 40.rpx, 0.rpx), + child: ClickableContainer( + backgroundColor: Colors.transparent, // 容器背景色 + highlightColor: themeController + .currentColor.sc21, // 点击时的背景色 + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 0.rpx, 0.rpx, 0.rpx), + onTap: () async { + Get.toNamed('/updateUserEmailPage'); + }, + child: Container( + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 30.rpx, 0.rpx, 30.rpx), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + '邮箱'.tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController + .currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + getTextByUserInfo('email'), + style: TextStyle( + fontFamily: 'Inter', + // color: Color(0xFFD9E3EB), + color: themeController + .currentColor.sc2, + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + ), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15 + .rpx, // 如果 SVG 中没有固定颜色,可以这样设置 + color: themeController + .currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + ), + ), + ), + Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 40.rpx, 20.rpx, 40.rpx, 20.rpx), + child: ClickableContainer( + backgroundColor: Colors.transparent, // 容器背景色 + highlightColor: themeController + .currentColor.sc21, // 点击时的背景色 + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 0.rpx, 0.rpx, 0.rpx), + onTap: () async { + if (userInfoController.model.user!.bindWx == + null || + userInfoController.model.user!.bindWx == + false) { + //微信绑定 + LoginController loginController = + Get.find(); + await loginController.wxLoginSendAuth( + context, + login: false); + } else { + //取消微信绑定 + // LoginController loginController = + // Get.find(); + // await loginController.wxLoginSendAuth( + // context, + // login: false); + // TopSlideNotification.show(context, + // text: "暂不支持微信解绑授权".tr, + // textColor: + // themeController.currentColor.sc9); + // return; + showUnbindWxConfirmDialog(context); + } + }, + child: Container( + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0.rpx, 30.rpx, 0.rpx, 30.rpx), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Text( + '微信'.tr, + style: TextStyle( + fontFamily: 'Inter', + color: themeController + .currentColor.sc3, + fontSize: AppConstants() + .title_text_fontSize, + letterSpacing: 0.0, + ), + ), + ].divide(SizedBox(width: 22.rpx)), + ), + Row( + mainAxisSize: MainAxisSize.max, + children: [ + Obx(() { + var aa = userInfoController + .model.user!.tmpNickName; + print(aa); + return Text( + getTextByUserInfo('wechat'), + style: TextStyle( + fontFamily: 'Inter', + // color: Color(0xFFD9E3EB), + color: getTextByUserInfo( + 'wechat') == + "解绑".tr + ? themeController + .currentColor.sc4 + : themeController + .currentColor.sc2, + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + ); + }), + SvgPicture.asset( + 'assets/img/icon/arrow_right.svg', + width: 8.rpx, + height: 15 + .rpx, // 如果 SVG 中没有固定颜色,可以这样设置 + color: themeController + .currentColor.sc3, + ), + ].divide(SizedBox(width: 28.rpx)), + ), + ], + ), + ), + ), + ), + ), + ], + ), + ), + ), + ], ), ), @@ -334,9 +646,8 @@ class _UpdateUserPageState extends State { shape: BoxShape.circle, ), child: head == null || head.isEmpty - ? Image.asset( - 'assets/img/avatar.png', - fit: BoxFit.cover, + ? SvgPicture.asset( + "assets/img/avatar.svg", ) : Image.network( head, @@ -349,4 +660,34 @@ class _UpdateUserPageState extends State { } return Container(); } + + String getTextByUserInfo(String type) { + UserInfoController userInfoController = Get.find(); + UserModel userInfo = userInfoController.model.user!; + if (userInfo == null) { + return ""; + } + if (type == "phone") { + if (userInfo.phone == null || userInfo.phone!.isEmpty) { + return "更换".tr; + } else { + return "换绑".tr; + } + } + if (type == "email") { + if (userInfo.email == null || userInfo.email!.isEmpty) { + return "绑定".tr; + } else { + return "换绑".tr; + } + } + if (type == "wechat") { + if (userInfo.bindWx == null || userInfo.bindWx == false) { + return "绑定".tr; + } else { + return "解绑".tr; + } + } + return ""; + } } diff --git a/lib/pages/user/update_user_tel.dart b/lib/pages/user/update_user_tel.dart new file mode 100644 index 0000000..e6ad7aa --- /dev/null +++ b/lib/pages/user/update_user_tel.dart @@ -0,0 +1,659 @@ +import 'dart:io'; + +import 'package:EasyDartModule/EasyDartModule.dart' as edm; +import 'package:ef/ef.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:flutterflow_ui/flutterflow_ui.dart'; +import 'package:vbvs_app/common/color/appConstants.dart'; +import 'package:vbvs_app/common/color/app_uri_status.dart'; +import 'package:vbvs_app/common/util/DailyLogUtils.dart'; +import 'package:vbvs_app/common/util/FitTool.dart'; +import 'package:vbvs_app/common/util/MyUtils.dart'; +import 'package:vbvs_app/component/tool/ClickableContainer.dart'; +import 'package:vbvs_app/component/tool/CustomCard.dart'; +import 'package:vbvs_app/component/tool/NewTopSlideNotification.dart'; +import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; +import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart'; +import 'package:vbvs_app/controller/login/login_controller.dart'; +import 'package:vbvs_app/controller/main_bottom/global_controller.dart'; +import 'package:vbvs_app/controller/person/person_controller.dart'; +import 'package:vbvs_app/controller/theme_controller/ThemeController.dart'; +import 'package:vbvs_app/controller/time/countdown_controller.dart'; +import 'package:vbvs_app/controller/user_info_controller.dart'; +import 'package:vbvs_app/model/api_response.dart'; +import 'package:vbvs_app/model/user_data.dart'; + +class UpdateUserTelPage extends StatefulWidget { + const UpdateUserTelPage({super.key}); + + @override + State createState() => _UpdateUserTelPageState(); +} + +class _UpdateUserTelPageState extends State { + GlobalController globalController = Get.find(); + UserInfoController userInfoController = Get.find(); + BlueteethBindController blueteethBindController = Get.find(); + PersonController personController = Get.find(); + ThemeController themeController = Get.find(); + LoginController loginController = Get.find(); + + @override + void initState() { + super.initState(); + userInfoController.model.user!.tmpHead = null; + userInfoController.model.user!.tmpNickName = null; + userInfoController.model.user!.tmpHead = + userInfoController.model.user!.avatar; + userInfoController.model.user!.tmpNickName = + userInfoController.model.user!.nick_name; + loginController.model.updatePhone = null; + } + + @override + Widget build(BuildContext context) { + int login = userInfoController.model.login!; + return LayoutBuilder( + builder: (context, bodySize) => GestureDetector( + // onTap: () => FocusScope.of(context).unfocus(),, + child: Container( + decoration: BoxDecoration( + image: DecorationImage( + image: AssetImage('assets/img/bgNoImg.png'), + fit: BoxFit.fill, + ), + ), + child: Scaffold( + backgroundColor: Colors.transparent, + appBar: AppBar( + backgroundColor: themeController.currentColor.sc17, + automaticallyImplyLeading: false, + iconTheme: IconThemeData( + color: themeController.currentColor.sc3, + ), + titleSpacing: 0, + title: Container( + width: double.infinity, + height: 180.rpx, + child: Stack( + alignment: Alignment.center, + children: [ + Text( + '更换手机号码'.tr, + style: TextStyle( + fontFamily: 'Readex Pro', + color: themeController.currentColor.sc3, + letterSpacing: 0, + fontSize: 30.rpx, + ), + ), + Positioned( + left: 0, + child: returnIconButtom, + ), + Positioned( + right: 20.rpx, + child: CustomCard( + borderRadius: 20.rpx, + onTap: () async { + if (loginController.model.updatePhone == null || + loginController.model.updatePhone == '') { + NewTopSlideNotification.show( + text: "请输入手机号", + textColor: themeController.currentColor.sc9, + ); + return; + } + ApiResponse apiResponse = + await userInfoController.updateData( + phone: loginController.model.updatePhone); + TopSlideNotification.show( + context, + text: apiResponse.msg!, + textColor: apiResponse.code == HttpStatusCodes.ok + ? themeController.currentColor.sc2 + : themeController.currentColor.sc9, + ); + if (apiResponse.code == HttpStatusCodes.ok) { + userInfoController.model.user!.tmpHead = null; + userInfoController.model.user!.tmpNickName = null; + loginController.model.updatePhone = null; + await userInfoController.getUserInfo(); + userInfoController.model.user!.tmpNickName = + userInfoController.model.user!.nick_name; + userInfoController.model.user!.tmpHead = + userInfoController.model.user!.avatar; + userInfoController.updateAll(); + Get.back(); + } + }, + colors: [ + themeController.currentColor.sc1, + themeController.currentColor.sc2, + ], + child: Container( + width: 100.rpx, + height: 60.rpx, + alignment: Alignment.center, + padding: EdgeInsetsDirectional.fromSTEB( + 16.rpx, 0.rpx, 16.rpx, 0.rpx), + child: Text( + '修改资料页.保存'.tr, + style: TextStyle( + fontFamily: 'Inter Tight', + color: themeController.currentColor.sc3, + letterSpacing: 0.0, + ), + ), + ), + ), + ), + ], + ), + ), + actions: [], + centerTitle: false, + ), + body: SafeArea( + top: true, + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration(), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 30.rpx, 0.rpx, 30.rpx, 0.rpx), + child: Column( + mainAxisSize: MainAxisSize.max, + children: [ + Align( + alignment: AlignmentDirectional(-1, 0), + child: Padding( + padding: + EdgeInsetsDirectional.fromSTEB(0, 0.rpx, 0, 0), + child: Container( + alignment: Alignment.centerLeft, + width: double.infinity, + height: bodySize.maxHeight * 0.056, + constraints: BoxConstraints( + minHeight: 120.rpx, + ), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 60.rpx, 0, 35.rpx, 0), + child: Text( + "原手机号码" + ":" + "${getHidePhone()}", + style: TextStyle( + color: themeController.currentColor.sc3, + fontSize: AppConstants().normal_text_fontSize, + ), + ), + ), + ), + ), + ), + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular( + AppConstants().normal_container_radius), + color: themeController.currentColor.sc17, + ), + child: Column( + children: [ + Align( + alignment: AlignmentDirectional(-1, 0), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0, 20.rpx, 0, 0), + child: Container( + width: double.infinity, + height: bodySize.maxHeight * 0.056, + decoration: BoxDecoration( + color: Colors.transparent, + ), + constraints: BoxConstraints( + minHeight: 90.rpx, + ), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 35.rpx, 0, 35.rpx, 0), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: + EdgeInsetsDirectional.fromSTEB( + 26.rpx, 0, 0, 0), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + InkWell( + onTap: () async {}, + child: Container( + alignment: Alignment.center, + // constraints: BoxConstraints( + // minWidth: 150.rpx, + // ), + child: Text( + "+86", + style: TextStyle( + fontFamily: 'Readex Pro', + color: themeController + .currentColor.sc4, + fontSize: AppConstants() + .middler_text_fontSize, + letterSpacing: 0, + ), + ), + ), + ), + SizedBox( + height: 30.rpx, + child: VerticalDivider( + thickness: 2.rpx, + color: themeController + .currentColor.sc4, + ), + ), + ].divide(SizedBox(width: 10.rpx)), + ), + ), + Expanded( + child: Container( + child: Align( + alignment: + AlignmentDirectional(-1, 0), + child: TextFormField( + onChanged: (value) { + loginController.model + .updatePhone = value; + }, + autofocus: false, + obscureText: false, + decoration: InputDecoration( + isDense: true, + labelStyle: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + hintText: '输入手机号码'.tr, + hintStyle: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController + .currentColor.sc4, + ), + enabledBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Color(0x00000000), + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + focusedBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Color(0x00000000), + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + errorBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red, + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + focusedErrorBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red, + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + filled: false, + fillColor: Colors.white, + ), + style: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController + .currentColor.sc3, + ), + cursorColor: themeController + .currentColor.sc3, + // validator: _model + // .textControllerValidator + // .asValidator(context), + ), + ), + ), + ), + ], + ), + ), + ), + ), + ), + Align( + alignment: AlignmentDirectional(-1, 0), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 0, 26.rpx, 0, 20.rpx), + child: Container( + height: bodySize.maxHeight * 0.056, + width: double.infinity, + constraints: BoxConstraints( + minHeight: 90.rpx, + ), + child: Padding( + padding: EdgeInsetsDirectional.fromSTEB( + 35.rpx, 0, 35.rpx, 0), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Container( + child: Align( + alignment: + AlignmentDirectional(-1, 0), + child: TextFormField( + onChanged: (value) { + loginController + .model.updateCode = value; + }, + autofocus: false, + obscureText: false, + decoration: InputDecoration( + isDense: true, + labelStyle: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + ), + hintText: '其他手机登录页.输入验证码'.tr, + hintStyle: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController + .currentColor.sc4, + ), + enabledBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Color(0x00000000), + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + focusedBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Color(0x00000000), + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + errorBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red, + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + focusedErrorBorder: + OutlineInputBorder( + borderSide: BorderSide( + color: Colors.red, + width: 1.rpx, + ), + borderRadius: + BorderRadius.circular( + 8.rpx), + ), + filled: true, + fillColor: Colors.transparent, + ), + style: TextStyle( + fontFamily: 'Inter', + fontSize: 26.rpx, + letterSpacing: 0.0, + color: themeController + .currentColor.sc3, + ), + cursorColor: themeController + .currentColor.sc3, + // validator: _model + // .textControllerValidator + // .asValidator(context), + ), + ), + ), + ), + Padding( + padding: + EdgeInsetsDirectional.fromSTEB( + 26.rpx, 0, 0, 0), + child: Row( + mainAxisSize: MainAxisSize.max, + children: [ + SizedBox( + height: 30.rpx, + child: VerticalDivider( + thickness: 2.rpx, + color: themeController + .currentColor.sc7, + ), + ), + Obx(() { + final CountdownController + countdownController = + Get.find< + CountdownController>(); + return InkWell( + onTap: () async { + try { + DailyLogUtils.writeLog( + "点击获取验证码"); + if (countdownController + .countdown + .value != + 0) { + return; + } + ApiResponse apiResponse = + await loginController + .getUpdateTelCode( + context); + if (apiResponse.code != + HttpStatusCodes.ok) { + TopSlideNotification + .show( + context, + text: + apiResponse.msg!, + textColor: + themeController + .currentColor + .sc9, + ); + await DailyLogUtils + .writeLog( + "获取验证码成功,${apiResponse}"); + return; + } else { + TopSlideNotification + .show( + context, + text: + apiResponse.msg!, + textColor: + themeController + .currentColor + .sc2, + ); + await DailyLogUtils + .writeLog( + "获取验证码失败,${apiResponse}"); + } + countdownController + .countdown + .value == + 0 + ? countdownController + .startCountdown( + AppConstants + .code_time) + : null; + } catch (e) { + await DailyLogUtils + .writeLog( + "获取验证码异常,${e}"); + edm.EasyDartModule.logger + .info("获取验证码异常:${e}"); + } + }, + child: Container( + alignment: Alignment.center, + constraints: BoxConstraints( + minWidth: 150.rpx, + ), + child: Text( + countdownController + .countdown + .value == + 0 + ? '其他手机登录页.获取验证码'.tr + : '${countdownController.countdown.value}' + + "其他手机登录页.秒".tr, + style: TextStyle( + fontFamily: + 'Readex Pro', + color: themeController + .currentColor.sc2, + fontSize: AppConstants() + .middler_text_fontSize, + letterSpacing: 0, + ), + ), + ), + ); + }), + ].divide(SizedBox(width: 26.rpx)), + ), + ), + ], + ), + ), + ), + ), + ), + ], + ), + ), + ], + ), + ), + ), + ), + ), + ), + ), + ); + } + + Widget getImageWidget(BuildContext context) { + try { + UserInfoController controller = Get.find(); + var head = controller.model.user!.tmpHead; + return Container( + width: 200.rpx, + height: 200.rpx, + child: Container( + clipBehavior: Clip.antiAlias, + decoration: BoxDecoration( + shape: BoxShape.circle, + ), + child: head == null || head.isEmpty + ? Image.asset( + 'assets/img/avatar.png', + fit: BoxFit.cover, + ) + : Image.network( + head, + fit: BoxFit.cover, + ), + ), + ); + } catch (e) { + print(e); + } + return Container(); + } + + String getTextByUserInfo(String type) { + UserInfoController userInfoController = Get.find(); + UserModel userInfo = userInfoController.model.user!; + if (userInfo == null) { + return ""; + } + if (type == "phone") { + if (userInfo.phone == null || userInfo.phone!.isEmpty) { + return "更换".tr; + } else { + return "换绑".tr; + } + } + if (type == "email") { + if (userInfo.email == null || userInfo.email!.isEmpty) { + return "绑定".tr; + } else { + return "换绑".tr; + } + } + if (type == "wechat") { + if (userInfo.bindWx == null || userInfo.bindWx == false) { + return "绑定".tr; + } else { + return "解绑".tr; + } + } + return ""; + } + + getHidePhone() { + UserModel userModel = userInfoController.model.user!; + if (userModel.phone == null || userModel.phone == "") { + return "暂无".tr; + } + return "${userModel.phone!.substring(0, 3)}****${userModel.phone!.substring(7, 11)}"; + } +} diff --git a/lib/pages/user/wx_unbind_dialog.dart b/lib/pages/user/wx_unbind_dialog.dart new file mode 100644 index 0000000..f313929 --- /dev/null +++ b/lib/pages/user/wx_unbind_dialog.dart @@ -0,0 +1,29 @@ +import 'package:ef/ef.dart'; +import 'package:flutter/material.dart'; +import 'package:vbvs_app/common/color/app_uri_status.dart'; +import 'package:vbvs_app/common/util/MyUtils.dart'; +import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; +import 'package:vbvs_app/controller/user_info_controller.dart'; +import 'package:vbvs_app/model/api_response.dart'; +import 'package:vbvs_app/pages/device_bind/componnet/bind_dialog.dart'; + +void showUnbindWxConfirmDialog(BuildContext context) { + showConfirmDialog( + context, + Container(), + "是否确认解绑".tr, + onConfirm: () async { + UserInfoController userInfoController = Get.find(); + ApiResponse apiResponse = + await userInfoController.updateData(code: "unBind"); + TopSlideNotification.show( + context, + text: apiResponse.msg!, + textColor: apiResponse.code == HttpStatusCodes.ok + ? themeController.currentColor.sc2 + : themeController.currentColor.sc9, + ); + }, + onCancel: () {}, + ); +} diff --git a/lib/routers/routers.dart b/lib/routers/routers.dart index 8e99852..220887b 100644 --- a/lib/routers/routers.dart +++ b/lib/routers/routers.dart @@ -5,6 +5,7 @@ import 'package:vbvs_app/component/tool/TopSlideNotification.dart'; import 'package:vbvs_app/controller/user_info_controller.dart'; import 'package:vbvs_app/pages/device/BodyDeviceWidget.dart'; import 'package:vbvs_app/pages/device/component/MessageSetting.dart'; +import 'package:vbvs_app/pages/device/component/SingleMessageSetting.dart'; import 'package:vbvs_app/pages/device/device_detail.dart'; import 'package:vbvs_app/pages/device/instant_body_page.dart'; import 'package:vbvs_app/pages/device/message_review_page.dart'; @@ -50,7 +51,9 @@ import 'package:vbvs_app/pages/sleep_report/sleep_report_page.dart'; import 'package:vbvs_app/pages/user/about_us_page.dart'; import 'package:vbvs_app/pages/user/privacy_scheme_page.dart'; import 'package:vbvs_app/pages/user/setting_page.dart'; +import 'package:vbvs_app/pages/user/update_user_email.dart'; import 'package:vbvs_app/pages/user/update_user_page.dart'; +import 'package:vbvs_app/pages/user/update_user_tel.dart'; import 'package:vbvs_app/pages/user/user_scheme_page.dart'; var routes = { @@ -94,7 +97,9 @@ var routes = { "/applyRepairPage": (contxt) => ApplyRepairPage(), "/languageSetting": (contxt) => LanguageSetting(), "/themeSetting": (contxt) => ThemeSetting(), - "/helpPage": (contxt, {arguments}) => HelpPage( url: arguments,), + "/helpPage": (contxt, {arguments}) => HelpPage( + url: arguments, + ), "/followPage": (contxt) => FollowPage(), "/repairListPage": (contxt) => RepairListPage(), "/newSleepReportPage": (contxt, {arguments}) => @@ -122,6 +127,11 @@ var routes = { UserPrivacyNewPage(sleepUri: arguments), "/privacyPolicyPageNew": (contxt, {arguments}) => PrivacyPolicyNewPage(sleepUri: arguments), + "/updateUserTelPage": (contxt) => UpdateUserTelPage(), + "/updateUserEmailPage": (contxt) => UpdateUserEmailPage(), + "/singleMessageSetting": (context, {arguments}) => + SingleMessageSetting( + data: arguments), }; var onGenerateRoute = (RouteSettings settings) { @@ -141,9 +151,8 @@ var onGenerateRoute = (RouteSettings settings) { settings.name != "/userSchemePage" && settings.name != "/privacyPage" && settings.name != "/userPolicyPageNew" && - settings.name != "/privacyPolicyPageNew"&& - settings.name != "/auth_bind_tel" - ) { + settings.name != "/privacyPolicyPageNew" && + settings.name != "/auth_bind_tel") { TopSlideNotification.show( Get.context!, text: "必须登录提示".tr,