From 7cd575009b7129a77e959daa0ca453e99bed0d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CDaisyWu=E2=80=9D?= <“18682150237@163.com”> Date: Tue, 9 Jul 2024 16:04:56 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E6=8E=A5=E5=85=A5=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9F=AD=E4=BF=A1=E3=80=81=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E6=A8=A1=E7=89=88API=E5=B9=B6=E4=BF=AE=E6=94=B9=E9=83=A8?= =?UTF-8?q?=E5=88=86=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=202=EF=BC=8C?= =?UTF-8?q?=E6=8E=A5=E5=85=A5=E6=9C=80=E6=96=B0=E8=8E=B7=E5=8F=96=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=A8=A1=E7=89=88API=E5=B9=B6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=80=BB=E8=BE=91=E4=BB=A3=E7=A0=81=203?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=BB=BA=E7=9F=AD=E4=BF=A1=E3=80=81=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E6=A8=A1=E7=89=88=E6=96=B0=E5=A2=9E=E5=9B=BD=E5=86=85?= =?UTF-8?q?=E3=80=81=E5=9B=BD=E9=99=85=E6=A8=A1=E7=89=88=E9=80=89=E6=8B=A9?= =?UTF-8?q?=204=EF=BC=8C=E9=87=8D=E6=9E=84=E6=96=B0=E5=BB=BA=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E3=80=81=E7=BC=96=E8=BE=91=E6=A8=A1=E7=89=88=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=BB=A3=E7=A0=81=205=EF=BC=8C=E6=A2=B3=E7=90=86?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E8=8E=B7=E5=8F=96=E5=B7=B2=E6=9C=89=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E5=88=97=E8=A1=A8API=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...eAddedServicesNoteAndEmailDetail_page.dart | 2 +- .../newSMSTemplate_entity.dart | 141 +++++++++++ .../newSMSTemplate_logic.dart | 238 +++++++----------- .../newSMSTemplate_page.dart | 77 ++++-- .../newSMSTemplate_state.dart | 11 +- .../customSMSTemplateList_entity.dart | 43 ++-- .../customSMSTemplateList_logic.dart | 2 +- .../customSMSTemplateList_page.dart | 21 +- .../customSMSTemplateList_state.dart | 4 +- lib/network/api.dart | 4 +- lib/network/api_provider.dart | 16 +- lib/network/api_repository.dart | 12 +- 12 files changed, 339 insertions(+), 232 deletions(-) diff --git a/lib/mine/valueAddedServices/valueAddedServicesNoteAndEmailDetail/valueAddedServicesNoteAndEmailDetail_page.dart b/lib/mine/valueAddedServices/valueAddedServicesNoteAndEmailDetail/valueAddedServicesNoteAndEmailDetail_page.dart index 77a59cc9..0cfea926 100755 --- a/lib/mine/valueAddedServices/valueAddedServicesNoteAndEmailDetail/valueAddedServicesNoteAndEmailDetail_page.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesNoteAndEmailDetail/valueAddedServicesNoteAndEmailDetail_page.dart @@ -114,7 +114,7 @@ class _ValueAddedServicesNoteAndEmailDetailPageState onTap: () { Navigator.pushNamed( context, Routers.customSMSTemplateListPage, - arguments: {'type': type}); + arguments: {'channelType': type}); }, child: Row( children: [ diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.dart index cce845be..4bdadf39 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.dart @@ -1,5 +1,145 @@ import 'dart:convert'; +class NewSMSTemplateEntity { + NewSMSTemplateEntity({ + this.errorCode, + this.description, + this.errorMsg, + this.dataList, + }); + + NewSMSTemplateEntity.fromJson(Map json) { + errorCode = json['errorCode']; + description = json['description']; + errorMsg = json['errorMsg']; + if (json['data'] != null) { + dataList = []; + json['data'].forEach((v) { + dataList!.add(LangData.fromJson(v)); + }); + } + } + + int? errorCode; + String? description; + String? errorMsg; + List? dataList; + + Map toJson() { + final Map data = {}; + data['errorCode'] = errorCode; + data['description'] = description; + data['errorMsg'] = errorMsg; + if (dataList != null) { + data['data'] = dataList!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class LangData { + LangData({ + this.langType, + this.langName, + this.templates, + }); + + LangData.fromJson(Map json) { + langType = json['langType']; + langName = json['langName']; + if (json['templates'] != null) { + templates = []; + json['templates'].forEach((v) { + templates!.add(TemplateData.fromJson(v)); + }); + } + } + + int? langType; + String? langName; + List? templates; + + Map toJson() { + final Map data = {}; + data['langType'] = langType; + data['langName'] = langName; + if (templates != null) { + data['templates'] = templates!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class TemplateData { + TemplateData({ + this.langType, + this.langName, + this.templateType, + this.templateName, + this.template, + this.templatePreviewCode, + }); + + TemplateData.fromJson(Map json) { + langType = json['langType']; + langName = json['langName']; + templateType = json['templateType']; + templateName = json['templateName']; + template = json['template']; + templatePreviewCode = json['templatePreviewCode'] != null + ? jsonEncode(json['templatePreviewCode']) + : null; + } + + int? langType; + String? langName; + int? templateType; + String? templateName; + String? template; + String? fixedKey; + String? templatePreviewCode; // Changed to String + String? regards = ''; + String? tips = ''; + int? id; + String? name; + int? channelType; + bool? isUpdate = false; + + Map toJson() { + final Map data = {}; + data['langType'] = langType; + data['langName'] = langName; + data['templateType'] = templateType; + data['templateName'] = templateName; + data['template'] = template; + if (templatePreviewCode != null) { + data['templatePreviewCode'] = jsonDecode(templatePreviewCode!); + } + return data; + } + + // New method to replace template variables with values from templatePreviewCode + String generatePreview() { + if (template == null || templatePreviewCode == null) { + return ''; + } + + // Decode the templatePreviewCode string back to a map + final Map previewCodeMap = + Map.from(jsonDecode(templatePreviewCode!)); + + String previewTemplate = template!; + previewCodeMap.forEach((String key, String value) { + previewTemplate = previewTemplate.replaceAll( + key, value + (value.length > 2 ? '\n' : '')); + }); + + return previewTemplate; + } +} + + +/* class NewSMSTemplateEntity { NewSMSTemplateEntity({ this.errorCode, @@ -99,3 +239,4 @@ class SMSTemplateData { return previewTemplate; } } +*/ diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart index 3c6d67ee..9a51d7f1 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart @@ -14,14 +14,19 @@ class NewSMSTemplateLogic extends BaseGetXController { //获取默认模板-- 1:电子钥匙 2:密码 Future getDefaultTemplate() async { - final NewSMSTemplateEntity entity = await ApiRepository.to - .getDefaultTemplate(type: state.templateType.value); + final NewSMSTemplateEntity entity = + await ApiRepository.to.getDefaultTemplate(); if (entity.errorCode!.codeIsSuccessful) { - state.templateList.value = entity.dataList ?? []; + state.langTemplateList.value = entity.dataList ?? []; + + state.templateList.value = + entity.dataList![state.selectedLangIndex.value].templates ?? + []; if (state.templateList.isNotEmpty) { state.currentTemplate.value = state.templateList.firstWhere( - (SMSTemplateData element) => - element.name == state.templateList[0].name, + (TemplateData element) => + element.name == + state.templateList[state.selectedTemplateIndex.value].name, ); state.currentTemplate.refresh(); } @@ -35,12 +40,13 @@ class NewSMSTemplateLogic extends BaseGetXController { return; } final LoginEntity entity = await ApiRepository.to.addTemplateService( - type: state.templateType.value, - name: state.templateNameTf.text, - fixedKey: state.currentTemplate.value.fixedKey ?? '', - contentType: state.currentTemplate.value.contentType ?? 0, - regards: state.templateOneTf.text, - tips: state.templateTwoTf.text); + channelType: state.channelType.value, + name: state.templateNameTf.text, + langType: state.currentTemplate.value.langType ?? 0, + regards: state.templateOneTf.text, + tips: state.templateTwoTf.text, + templateType: state.currentTemplate.value.templateType ?? 0, + ); if (entity.errorCode!.codeIsSuccessful) { showToast('添加成功'); Get.back(result: true); @@ -75,15 +81,6 @@ class NewSMSTemplateLogic extends BaseGetXController { //构建电子钥匙模板 List buildElectronicKeySpan({required bool isPreview}) { - //短信模版 - if (state.templateType.value == 1) { - return _buildSMSElectronicKey(isPreview); - } else { - return _buildEmailElectronicKey(isPreview); - } - } - - List _buildSMSElectronicKey(bool isPreview) { final List textSpans = []; // 如果是预览模式,添加预览模板的文本 if (isPreview) { @@ -110,6 +107,15 @@ class NewSMSTemplateLogic extends BaseGetXController { textSpans.addAll(_buildDefaultTemplate(isPreview)); } + if (isPreview) { + textSpans.add( + TextSpan( + text: '\n${state.templateTwoTf.text}\n', + style: state.defaultStyle, + ), + ); + } + return textSpans; } @@ -150,70 +156,6 @@ class NewSMSTemplateLogic extends BaseGetXController { } } - if (isPreview) { - textSpans.add( - TextSpan( - text: '\n${state.templateTwoTf.text}', - style: state.defaultStyle, - ), - ); - } - return textSpans; - } - - List _buildEmailElectronicKey(bool isPreview) { - final List textSpans = []; - - //邮件模版 - // 如果是预览模式,添加预览模板的文本 - if (isPreview) { - textSpans.add( - TextSpan( - text: '${state.templateOneTf.text}\n', - style: state.defaultStyle, - ), - ); - } else { - String template = state.currentTemplate.value.template ?? ''; - template = template.replaceAll(',', ',\n'); - - // 定义匹配 ${} 包围的变量的正则表达式 - final RegExp variableRegExp = RegExp(r'\{([^}]+)\}'); - final Iterable matches = variableRegExp.allMatches(template); - - int start = 0; - for (final Match match in matches) { - // 添加非变量文本 - if (match.start > start) { - textSpans.add( - TextSpan( - text: template.substring(start, match.start), - style: state.defaultStyle, - ), - ); - } - - // 添加变量文本 - textSpans.add( - TextSpan( - text: match.group(0), - style: state.highStyle, - ), - ); - - start = match.end; - } - - // 添加剩余的非变量文本 - if (start < template.length) { - textSpans.add( - TextSpan( - text: template.substring(start), - style: state.defaultStyle, - ), - ); - } - } return textSpans; } @@ -229,89 +171,85 @@ class NewSMSTemplateLogic extends BaseGetXController { ), ); } - //短信模版才需要加默认模版 - if ((state.templateType.value == 1) || - (state.templateType.value == 2 && isPreview == false)) { - if (isPreview) { - if (state.currentTemplate.value.generatePreview().isNotEmpty) { - textSpans.add( - TextSpan( - text: state.currentTemplate.value.generatePreview(), - style: state.defaultStyle, - ), - ); - - // 在预览模式下,添加预览模板的文本 - if (isPreview) { - textSpans.add( - TextSpan( - text: '\n${state.templateTwoTf.text}', - style: state.defaultStyle, - ), - ); - } - } - return textSpans; - } - // 定义匹配 ${} 包围的变量的正则表达式 - final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}'); - - final String template = state.currentTemplate.value.template ?? ''; - - // 对模板进行处理 - int startIndex = 0; - for (final Match match in variableRegExp.allMatches(template)) { - // 处理变量之前的文本 - final String nonVariableText = - template.substring(startIndex, match.start); - // 替换非变量文本中的字符 - final String replacedNonVariableText = - nonVariableText.replaceAllMapped(RegExp(r',|。'), (Match match) { - return '${match.group(0)}\n'; - }); + if (isPreview) { + if (state.currentTemplate.value.generatePreview().isNotEmpty) { textSpans.add( TextSpan( - text: replacedNonVariableText, + text: state.currentTemplate.value.generatePreview(), style: state.defaultStyle, ), ); - // 处理变量 - final String variableText = match.group(0) ?? ''; - textSpans.add( - TextSpan( - text: variableText, - style: state.highStyle, - ), - ); - - // 更新起始索引 - startIndex = match.end; + // 在预览模式下,添加预览模板的文本 + if (isPreview) { + textSpans.add( + TextSpan( + text: '\n${state.templateTwoTf.text}', + style: state.defaultStyle, + ), + ); + } } + return textSpans; + } - // 添加最后一个变量之后的文本 - final String remainingText = template.substring(startIndex); + // 定义匹配 ${} 包围的变量的正则表达式 + final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}'); + final String template = state.currentTemplate.value.template ?? ''; + + // 对模板进行处理 + int startIndex = 0; + for (final Match match in variableRegExp.allMatches(template)) { + // 处理变量之前的文本 + final String nonVariableText = + template.substring(startIndex, match.start); // 替换非变量文本中的字符 - final String replacedRemainingText = - remainingText.replaceAllMapped(RegExp(r',|。'), (Match match) { + final String replacedNonVariableText = + nonVariableText.replaceAllMapped(RegExp(r',|。'), (Match match) { return '${match.group(0)}\n'; }); textSpans.add( TextSpan( - text: replacedRemainingText, + text: replacedNonVariableText, style: state.defaultStyle, ), ); - // 在预览模式下,添加预览模板的文本 - if (isPreview) { - textSpans.add( - TextSpan( - text: '\n${state.templateTwoTf.text}', - style: state.defaultStyle, - ), - ); - } + // 处理变量 + final String variableText = match.group(0) ?? ''; + textSpans.add( + TextSpan( + text: variableText, + style: state.highStyle, + ), + ); + + // 更新起始索引 + startIndex = match.end; + } + + // 添加最后一个变量之后的文本 + final String remainingText = template.substring(startIndex); + // 替换非变量文本中的字符 + final String replacedRemainingText = + remainingText.replaceAllMapped(RegExp(r',|。'), (Match match) { + return '${match.group(0)}\n'; + }); + textSpans.add( + TextSpan( + text: replacedRemainingText, + style: state.defaultStyle, + ), + ); + + // 在预览模式下,添加预览模板的文本 + if (isPreview) { + textSpans.add( + TextSpan( + text: '\n${state.templateTwoTf.text}', + style: state.defaultStyle, + ), + ); } return textSpans; diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_page.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_page.dart index 965f3419..aabdeb3c 100755 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_page.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_page.dart @@ -30,10 +30,10 @@ class _NewSMSTemplatePageState extends State { backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: state.isUpdate.value == false - ? state.templateType.value == 1 + ? state.channelType.value == 1 ? '新建短信模版'.tr : '新建邮件模版'.tr - : state.templateType.value == 1 + : state.channelType.value == 1 ? '编辑短信模版'.tr : '编辑邮件模版'.tr, haveBack: true, @@ -84,12 +84,21 @@ class _NewSMSTemplatePageState extends State { Obx(() => state.isUpdate.value == false ? CommonItem( leftTitel: TranslationLoader.lanKeys!.type!.tr, - rightTitle: state.currentTemplate.value.typeName ?? '', - isHaveLine: false, + rightTitle: state.currentTemplate.value.templateName ?? '', + isHaveLine: true, isHaveDirection: true, action: _showSelectTemplateType, ) : Container()), + Obx(() => state.isUpdate.value == false + ? CommonItem( + leftTitel: '模版类型', + rightTitle: state.currentTemplate.value.langName ?? '', + isHaveLine: false, + isHaveDirection: true, + action: _showSelectLangType, + ) + : Container()), ], ); } @@ -123,18 +132,16 @@ class _NewSMSTemplatePageState extends State { child: _buildTemplateWithType(isPreview: false), )), SizedBox(height: 10.h), - Obx(() => Visibility( - visible: state.templateType.value == 1, - child: Container( - margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h), - height: 100, - child: Stack( - alignment: Alignment.bottomRight, - children: [ - _buildTextField(state.templateTwoTf), - ], - ), - ))), + Container( + margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h), + height: 100, + child: Stack( + alignment: Alignment.bottomRight, + children: [ + _buildTextField(state.templateTwoTf), + ], + ), + ) ], ), ); @@ -169,7 +176,7 @@ class _NewSMSTemplatePageState extends State { ), child: _buildTemplateWithType(isPreview: true), )), - if (state.templateType.value == 1) + if (state.channelType.value == 1) Padding( padding: EdgeInsets.only( left: 25.w, @@ -201,7 +208,7 @@ class _NewSMSTemplatePageState extends State { } else { return RichText( text: TextSpan( - children: state.currentTemplate.value.typeName == '电子钥匙' + children: state.currentTemplate.value.templateName == '电子钥匙' ? logic.buildElectronicKeySpan(isPreview: isPreview) : logic.buildPasswordSpan(isPreview: isPreview), ), @@ -228,8 +235,7 @@ class _NewSMSTemplatePageState extends State { ), onChanged: (String value) { setState(() { - controller.text = value; - logic.updateSmsCost(value); // 更新短信条数 + logic.updateSmsCost(controller.text); // 更新短信条数 }); }, ); @@ -269,7 +275,7 @@ class _NewSMSTemplatePageState extends State { void _showSelectTemplateType() { final List titleList = state.templateList - .map((SMSTemplateData template) => template.typeName ?? '') + .map((TemplateData template) => template.templateName ?? '') .toList(); ShowBottomSheetTool().showSingleRowPicker( context, @@ -279,8 +285,35 @@ class _NewSMSTemplatePageState extends State { sureTitle: TranslationLoader.lanKeys!.sure!.tr, data: titleList, clickCallBack: (int index, Object str) { + state.selectedTemplateIndex.value = index; state.currentTemplate.value = state.templateList[index]; - state.currentTemplate.value.typeName = str.toString(); + state.currentTemplate.value.templateName = str.toString(); + state.selectedTemplateIndex.refresh(); + state.currentTemplate.refresh(); + }, + ); + } + + void _showSelectLangType() { + // 提取 langName 列表 + final List langNames = state.langTemplateList + .map((LangData langData) => langData.langName ?? '') + .toList(); + + ShowBottomSheetTool().showSingleRowPicker( + context, + normalIndex: 0, + title: TranslationLoader.lanKeys!.type!.tr, + cancelTitle: TranslationLoader.lanKeys!.cancel!.tr, + sureTitle: TranslationLoader.lanKeys!.sure!.tr, + data: langNames, + clickCallBack: (int index, Object str) { + state.selectedLangIndex.value = index; + state.currentTemplate.value = state + .langTemplateList[state.selectedLangIndex.value] + .templates![state.selectedTemplateIndex.value]; + state.currentTemplate.value.langName = str.toString(); + state.selectedLangIndex.refresh(); state.currentTemplate.refresh(); }, ); diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart index daf04ccc..dc408ea5 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart @@ -12,7 +12,7 @@ class NewSMSTemplateState { templateNameTf.text = currentTemplate.value.name ?? ''; templateOneTf.text = currentTemplate.value.regards ?? ''; templateTwoTf.text = currentTemplate.value.tips ?? ''; - templateType.value = currentTemplate.value.type ?? 0; + channelType.value = currentTemplate.value.channelType ?? 0; isUpdate.value = map['isUpdate']; } } @@ -30,10 +30,13 @@ class NewSMSTemplateState { final TextEditingController templateNameTf = TextEditingController(); RxBool isVip = false.obs; - RxList templateList = [].obs; - Rx currentTemplate = SMSTemplateData().obs; //当前模板信息 + RxList templateList = [].obs; + Rx currentTemplate = TemplateData().obs; //当前模板信息 + RxList langTemplateList = [].obs; //语言模板列表 + RxInt selectedLangIndex = 0.obs; //选中的语言模板 + RxInt selectedTemplateIndex = 0.obs; //选中的模板 RxBool isShowDate = false.obs; //是否显示日期 - RxInt templateType = 0.obs; //1:短信 2:邮件 + RxInt channelType = 0.obs; //1:短信 2:邮件 RxInt smsCost = 0.obs; //短信条数 RxString preContent = ''.obs; //预览内容 RxBool isUpdate = false.obs; //是否是修改模板 diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart index 89e01d9d..bc1e5694 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart @@ -29,7 +29,7 @@ class CustomSMSTemplateListEntity { class CustomSMSTemplateListData { CustomSMSTemplateListData( - {this.type, + {this.channelType, this.list, this.pageNo, this.pageSize, @@ -37,7 +37,7 @@ class CustomSMSTemplateListData { this.total}); CustomSMSTemplateListData.fromJson(Map json) { - type = json['type']; + channelType = json['channelType']; if (json['list'] != null) { list = []; json['list'].forEach((v) { @@ -49,7 +49,7 @@ class CustomSMSTemplateListData { pages = json['pages']; total = json['total']; } - int? type; + int? channelType; List? list; int? pageNo; int? pageSize; @@ -58,7 +58,7 @@ class CustomSMSTemplateListData { Map toJson() { final Map data = {}; - data['type'] = type; + data['channelType'] = channelType; if (list != null) { data['list'] = list!.map((v) => v.toJson()).toList(); } @@ -73,58 +73,51 @@ class CustomSMSTemplateListData { class CustomSMSTemplateItem { CustomSMSTemplateItem( {this.id, - this.userId, - this.type, - this.contentType, + this.channelType, + this.templateType, this.name, this.regards, this.tips, - this.fixedKey, this.createdAt, this.updatedAt, - this.template, - this.fixedTemplate}); + this.langType, + this.template}); + CustomSMSTemplateItem.fromJson(Map json) { id = json['id']; - userId = json['user_id']; - type = json['type']; - contentType = json['content_type']; + channelType = json['channelType']; + templateType = json['templateType']; name = json['name']; regards = json['regards']; tips = json['tips']; - fixedKey = json['fixed_key']; createdAt = json['created_at']; updatedAt = json['updated_at']; + langType = json['langType']; template = json['template']; - fixedTemplate = json['fixed_template']; } int? id; - int? userId; - int? type; - int? contentType; + int? channelType; + int? templateType; String? name; String? regards; String? tips; - String? fixedKey; String? createdAt; String? updatedAt; + int? langType; String? template; - String? fixedTemplate; Map toJson() { final Map data = {}; data['id'] = id; - data['user_id'] = userId; - data['type'] = type; - data['content_type'] = contentType; + data['channelType'] = channelType; + data['templateType'] = templateType; data['name'] = name; data['regards'] = regards; data['tips'] = tips; - data['fixed_key'] = fixedKey; data['created_at'] = createdAt; data['updated_at'] = updatedAt; + data['langType'] = langType; data['template'] = template; - data['fixed_template'] = fixedTemplate; return data; } } diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart index a2b4da49..2d6ba6d1 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart @@ -20,7 +20,7 @@ class CustomSMSTemplateListLogic extends BaseGetXController { } final CustomSMSTemplateListEntity entity = await ApiRepository.to .getSMSTemplateList( - channelType: state.type.value, + channelType: state.channelType.value, pageNo: pageNo, pageSize: int.parse(pageSize)); if (entity.errorCode!.codeIsSuccessful) { diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_page.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_page.dart index ebea82b7..bc85004b 100755 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_page.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_page.dart @@ -42,7 +42,7 @@ class _CustomSMSTemplateListPageState extends State { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( - barTitle: state.type.value == 1 ? '自定义短信模版'.tr : '自定义邮件模版'.tr, + barTitle: state.channelType.value == 1 ? '自定义短信模版'.tr : '自定义邮件模版'.tr, haveBack: true, backgroundColor: AppColors.mainColor), body: EasyRefreshTool( @@ -66,11 +66,11 @@ class _CustomSMSTemplateListPageState extends State { left: 30.w, right: 30.w, top: 30.w, bottom: 30.w), padding: EdgeInsets.only(top: 25.w, bottom: 25.w), onClick: () async { - final SMSTemplateData templateData = SMSTemplateData(); - templateData.type = state.type.value; + final TemplateData templateData = TemplateData(); + templateData.channelType = state.channelType.value; templateData.isUpdate = false; - templateData.typeName = - templateData.contentType == 1 ? '电子钥匙' : '密码'; + templateData.templateName = + templateData.templateType == 1 ? '电子钥匙' : '密码'; final result = await Get.toNamed(Routers.newSMSTemplatePage, arguments: { 'currentTemplate': templateData, @@ -197,15 +197,16 @@ class _CustomSMSTemplateListPageState extends State { CustomSMSTemplateItem itemData) { return GestureDetector( onTap: () async { - final SMSTemplateData templateData = SMSTemplateData(); + final TemplateData templateData = TemplateData(); templateData.name = itemData.name; templateData.regards = itemData.regards; templateData.tips = itemData.tips; templateData.id = itemData.id; templateData.template = itemData.template; - templateData.contentType = itemData.contentType; - templateData.typeName = templateData.contentType == 1 ? '电子钥匙' : '密码'; - templateData.type = itemData.type; + templateData.templateType = itemData.templateType; + templateData.templateName = + templateData.templateName == 1 ? '电子钥匙' : '密码'; + templateData.channelType = itemData.channelType; templateData.isUpdate = true; final result = await Get.toNamed(Routers.newSMSTemplatePage, arguments: {'currentTemplate': templateData, 'isUpdate': true}); @@ -240,7 +241,7 @@ class _CustomSMSTemplateListPageState extends State { padding: EdgeInsets.only(left: 20.w, top: 20.h, bottom: 20.h), child: RichText( text: TextSpan( - children: itemData.contentType == 1 + children: itemData.templateType == 1 ? logic.buildElectronicKeySpan(templateData: itemData) : logic.buildPasswordSpan(templateData: itemData), ), diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart index 89f65961..ea4cf697 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart @@ -6,7 +6,7 @@ import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/ class CustomSMSTemplateListState { CustomSMSTemplateListState() { if (Get.arguments != null) { - type.value = Get.arguments['type']; + channelType.value = Get.arguments['channelType']; } } //高亮样式 @@ -19,5 +19,5 @@ class CustomSMSTemplateListState { RxBool isVip = false.obs; RxList smsTemplateList = [].obs; - RxInt type = 0.obs; + RxInt channelType = 0.obs; } diff --git a/lib/network/api.dart b/lib/network/api.dart index 92da7292..65b57f2c 100755 --- a/lib/network/api.dart +++ b/lib/network/api.dart @@ -243,9 +243,7 @@ abstract class Api { final String getNoticeTemplateURL = '/key/getNoticeTemplate'; //获取短信或者邮箱模板 final String appGetAppInfoURL = '/app/getAppInfo'; //获取APP基本信息 final String appGetFwVersionURL = '/app/getFwVersion'; //获取固件信息 - final String smsTemplateListURL = '/v2/service/listTemplate'; //获取短信模板列表 - final String emailTemplateListURL = - '/v2/service/listEmailTemplate'; //获取邮件模板列表 + final String haveTemplateListURL = '/v2/service/listTemplate'; //获取已添加模板列表 final String getDefaultTemplateURL = '/v2/service/getDefaultTemplate'; //获取默认模板 final String addTemplateServiceURL = '/v2/service/addTemplate'; //添加短信模板 diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index ecaa8e66..0c897578 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -2191,9 +2191,9 @@ class ApiProvider extends BaseProvider { ); // 获取默认模板 - Future> getDefaultTemplate(int type) => post( + Future> getDefaultTemplate() => post( getDefaultTemplateURL.toUrl, - jsonEncode({'type': type}), + jsonEncode({}), isUnShowLoading: true, ); @@ -2201,7 +2201,7 @@ class ApiProvider extends BaseProvider { Future> getSMSTemplateList( int channelType, int pageNo, int pageSize) => post( - smsTemplateListURL.toUrl, + haveTemplateListURL.toUrl, jsonEncode({ 'channelType': channelType, 'pageNo': pageNo, @@ -2211,17 +2211,17 @@ class ApiProvider extends BaseProvider { ); // 添加短信模板 - Future> addTemplateService(int type, String name, - int contentType, String regards, String tips, String fixedKey) => + Future> addTemplateService(int channelType, String name, + int langType, String regards, String tips, int templateType) => post( addTemplateServiceURL.toUrl, jsonEncode({ - 'type': type, + 'channelType': channelType, 'name': name, - 'content_type': contentType, + 'langType': langType, 'regards': regards, 'tips': tips, - 'fixed_key': fixedKey + 'templateType': templateType }), isUnShowLoading: true, ); diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index 877aeacd..31836cb6 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -2217,8 +2217,8 @@ class ApiRepository { } // 获取默认模板 - Future getDefaultTemplate({required int type}) async { - final Response res = await apiProvider.getDefaultTemplate(type); + Future getDefaultTemplate() async { + final Response res = await apiProvider.getDefaultTemplate(); return NewSMSTemplateEntity.fromJson(res.body); } @@ -2234,14 +2234,14 @@ class ApiRepository { // 添加短信模板 Future addTemplateService( - {required int type, + {required int channelType, required String name, - required int contentType, + required int langType, required String regards, required String tips, - required String fixedKey}) async { + required int templateType}) async { final Response res = await apiProvider.addTemplateService( - type, name, contentType, regards, tips, fixedKey); + channelType, name, langType, regards, tips, templateType); return LoginEntity.fromJson(res.body); }