1313 lines
74 KiB
Dart
1313 lines
74 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:ef/ef.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.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/NewTopSlideNotification.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<SingleMessageSetting> createState() => _MessageSettingPageState();
|
||
}
|
||
|
||
class _MessageSettingPageState extends State<SingleMessageSetting> {
|
||
final ThemeController themeController = Get.find();
|
||
MessageSettingController messageSettingController = Get.find();
|
||
CommonMessageSettingController commonMessageSettingController = Get.find();
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
_fetchCommonMessageSetting();
|
||
_fetchDeviceMessageSetting();
|
||
_fetchMessageCommonConfig();
|
||
//todo 查询用户自定义配置
|
||
//todo 查询用户总配置
|
||
}
|
||
|
||
Future<void> _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<void> _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 WillPopScope(
|
||
child: LayoutBuilder(
|
||
builder: (context, bodysize) => GestureDetector(
|
||
child: Container(
|
||
decoration: BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage(getBackgroundImageNoImage()),
|
||
fit: BoxFit.fill,
|
||
),
|
||
),
|
||
child: Scaffold(
|
||
backgroundColor: Colors.transparent,
|
||
appBar: AppBar(
|
||
systemOverlayStyle: SystemUiOverlayStyle(
|
||
statusBarColor: Colors.transparent, // 状态栏背景色
|
||
statusBarIconBrightness: Brightness.light, // 图标颜色(Android)
|
||
statusBarBrightness: Brightness.light, // 图标颜色(iOS)
|
||
),
|
||
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(() {
|
||
NewTopSlideNotification.show(text: "保存成功".tr);
|
||
}),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
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<String, dynamic>? 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<String, dynamic>
|
||
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,
|
||
)
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
onWillPop: () async {
|
||
NewTopSlideNotification.show(text: "保存成功".tr);
|
||
return true;
|
||
});
|
||
}
|
||
|
||
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;
|
||
}
|
||
}
|
||
}
|