新增更新模版信息接口对接且兼容新建模版逻辑

This commit is contained in:
Daisy 2024-06-04 18:09:38 +08:00
parent 088331a847
commit 2df1d2dacc
12 changed files with 138 additions and 147 deletions

View File

@ -357,10 +357,10 @@ abstract class Routers {
'/ValueAddedServicesHighFunctionPage'; // -
static const String valueAddedServicesBuyPage =
'/ValueAddedServicesBuyPage'; // -
static const String valueAddedServicesListSMSTemplatePage =
'/ValueAddedServicesListSMSTemplatePage'; // -
static const String valueAddedServicesAddSMSTemplatePage =
'/valueAddedServicesAddSMSTemplatePage'; // -
static const String customSMSTemplateListPage =
'/CustomSMSTemplateListPage'; // -
static const String newSMSTemplatePage =
'/NewSMSTemplatePage'; // -
static const String valueAddedServicesListEmailTemplatePage =
'/ValueAddedServicesListEmailTemplatePage'; // -
static const String valueAddedServicesAddEmailTemplatePage =
@ -867,11 +867,11 @@ abstract class AppRouters {
page: () => const ValueAddedServicesHighFunctionPage(),
),
GetPage<dynamic>(
name: Routers.valueAddedServicesListSMSTemplatePage,
name: Routers.customSMSTemplateListPage,
page: () => const CustomSMSTemplateListPage(),
),
GetPage<dynamic>(
name: Routers.valueAddedServicesAddSMSTemplatePage,
name: Routers.newSMSTemplatePage,
page: () => const NewSMSTemplatePage(),
),
GetPage<dynamic>(

View File

@ -24,7 +24,7 @@ class _ValueAddedServicesListEmailTemplatePageState
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.customMailTemplate!.tr,
barTitle: '自定义邮件模版'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Column(

View File

@ -112,8 +112,8 @@ class _ValueAddedServicesNoteAndEmailDetailPageState
GestureDetector(
onTap: () {
if (type == 1) {
Navigator.pushNamed(context,
Routers.valueAddedServicesListSMSTemplatePage);
Navigator.pushNamed(
context, Routers.customSMSTemplateListPage);
} else {
Navigator.pushNamed(context,
Routers.valueAddedServicesListEmailTemplatePage);
@ -130,9 +130,7 @@ class _ValueAddedServicesNoteAndEmailDetailPageState
height: 36.w,
),
Text(
(type == 1)
? '自定义短信模版'.tr
: TranslationLoader.lanKeys!.customMailTemplate!.tr,
(type == 1) ? '自定义短信模版'.tr : '自定义邮件模版'.tr,
style: TextStyle(fontSize: 24.sp),
),
],

View File

@ -30,22 +30,27 @@ class NewSMSTemplateEntity {
}
class SMSTemplateData {
SMSTemplateData({this.contentType, this.name, this.template, this.fixedKey});
SMSTemplateData(
{this.contentType, this.typeName, this.template, this.fixedKey});
SMSTemplateData.fromJson(Map<String, dynamic> json) {
contentType = json['content_type'];
name = json['name'];
typeName = json['typeName'];
template = json['template'];
fixedKey = json['fixed_key'];
}
int? contentType;
String? name;
String? typeName;
String? template;
String? fixedKey;
String? regards = '';
String? tips = '';
int? id;
String? name;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['content_type'] = contentType;
data['name'] = name;
data['typeName'] = typeName;
data['template'] = template;
data['fixed_key'] = fixedKey;
return data;

View File

@ -19,12 +19,11 @@ class NewSMSTemplateLogic extends BaseGetXController {
if (entity.errorCode!.codeIsSuccessful) {
state.templateList.value = entity.dataList ?? <SMSTemplateData>[];
if (state.templateList.isNotEmpty) {
state.templateTypeText.value = state.templateList[0].name ?? '';
// state.templateTypeText.value = state.templateList[0].name ?? '';
state.currentTemplate.value = state.templateList.firstWhere(
(SMSTemplateData element) =>
element.name == state.templateTypeText.value,
element.name == state.templateList[0].name,
);
state.templateTypeText.refresh();
state.currentTemplate.refresh();
}
}
@ -45,7 +44,19 @@ class NewSMSTemplateLogic extends BaseGetXController {
tips: state.templateTwoTf.text);
if (entity.errorCode!.codeIsSuccessful) {
showToast('添加成功');
Get.back();
Get.back(result: true);
}
}
Future<void> updateTemplateInfo() async {
final LoginEntity entity = await ApiRepository.to.updateTemplateInfo(
id: state.currentTemplate.value.id ?? 0,
name: state.templateNameTf.text,
regards: state.templateOneTf.text,
tips: state.templateTwoTf.text);
if (entity.errorCode!.codeIsSuccessful) {
showToast('修改成功');
Get.back(result: true);
}
}
@ -188,5 +199,9 @@ class NewSMSTemplateLogic extends BaseGetXController {
@override
Future<void> onReady() async {
super.onReady();
if (state.isUpdate.value == false) {
getDefaultTemplate();
}
}
}

View File

@ -23,12 +23,6 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
final NewSMSTemplateLogic logic = Get.put(NewSMSTemplateLogic());
final NewSMSTemplateState state = Get.find<NewSMSTemplateLogic>().state;
@override
void initState() {
super.initState();
logic.getDefaultTemplate();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -52,7 +46,11 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
child: SubmitBtn(
btnName: TranslationLoader.lanKeys!.save!.tr,
onClick: () {
logic.addSMSTemplate();
if (state.isUpdate.value == true) {
logic.updateTemplateInfo();
} else {
logic.addSMSTemplate();
}
},
),
),
@ -79,7 +77,7 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
Obx(
() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.type!.tr,
rightTitle: state.templateTypeText.value,
rightTitle: state.currentTemplate.value.typeName ?? '',
isHaveLine: false,
isHaveDirection: true,
action: _showSelectTemplateType,
@ -184,7 +182,7 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 10.h),
child: Obx(() => RichText(
text: TextSpan(
children: state.templateTypeText.value == '电子钥匙'
children: state.currentTemplate.value.typeName == '电子钥匙'
? logic.buildElectronicKeySpan(isPreview: isPreview)
: logic.buildPasswordSpan(isPreview: isPreview),
),
@ -213,7 +211,9 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
),
),
onChanged: (String value) {
controller.text = value;
setState(() {
controller.text = value;
});
},
);
}
@ -230,6 +230,7 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
controller: tfController,
autofocus: false,
textAlign: TextAlign.end,
style: TextStyle(fontSize: 22.sp),
decoration: InputDecoration(
contentPadding: const EdgeInsets.only(top: 12.0, bottom: 8.0),
hintText: tfStr,
@ -245,7 +246,7 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
void _showSelectTemplateType() {
final List<String> titleList = state.templateList
.map((SMSTemplateData template) => template.name ?? '')
.map((SMSTemplateData template) => template.typeName ?? '')
.toList();
ShowBottomSheetTool().showSingleRowPicker(
context,
@ -255,9 +256,8 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
sureTitle: TranslationLoader.lanKeys!.sure!.tr,
data: titleList,
clickCallBack: (int index, Object str) {
state.templateTypeText.value = str.toString();
state.templateTypeText.refresh();
state.currentTemplate.value = state.templateList[index];
state.currentTemplate.value.typeName = str.toString();
state.currentTemplate.refresh();
},
);

View File

@ -4,6 +4,18 @@ import 'package:get/get.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.dart';
class NewSMSTemplateState {
NewSMSTemplateState() {
if (Get.arguments != null) {
final Map map = Get.arguments;
currentTemplate.value = map['currentTemplate'];
currentTemplate.refresh();
isUpdate.value = true;
templateNameTf.text = currentTemplate.value.name ?? '';
templateOneTf.text = currentTemplate.value.regards ?? '';
templateTwoTf.text = currentTemplate.value.tips ?? '';
}
}
//
final TextStyle highStyle =
TextStyle(color: const Color(0xFFEEDFA8), fontSize: 20.sp);
@ -12,46 +24,15 @@ class NewSMSTemplateState {
final TextStyle defaultStyle =
TextStyle(color: Colors.black, fontSize: 20.sp);
//-
// late InlineSpan passwardSpan = TextSpan(children: <InlineSpan>[
// TextSpan(
// text:
// '${TranslationLoader.lanKeys!.hello!.tr}\n${TranslationLoader.lanKeys!.yourRoomIs!.tr}',
// style: defaultStyle),
// TextSpan(text: '201', style: highStyle),
// TextSpan(
// text: ' ${TranslationLoader.lanKeys!.theCodeToOpenTheDoorIs!.tr} ',
// style: defaultStyle),
// TextSpan(text: '332211\n', style: highStyle),
// TextSpan(
// text: '${TranslationLoader.lanKeys!.periodValidity!.tr} ',
// style: defaultStyle),
// TextSpan(text: '2021.12.11 12:00 - 2021.12.12 13:00。\n', style: highStyle),
// TextSpan(
// text: TranslationLoader.lanKeys!.templateTip1!.tr, style: defaultStyle),
// ]);
//-
// late InlineSpan electronicKeySpan = TextSpan(children: <InlineSpan>[
// TextSpan(
// text:
// '${TranslationLoader.lanKeys!.hello!.tr}\n${TranslationLoader.lanKeys!.templateTip2!.tr}',
// style: defaultStyle),
// TextSpan(text: 'https://abc.com/bcd\n', style: highStyle),
// TextSpan(
// text: '${TranslationLoader.lanKeys!.templateTip3!.tr}\n',
// style: defaultStyle),
// TextSpan(text: 'https://abc.com/bcd', style: highStyle),
// ]);
final TextEditingController templateOneTf = TextEditingController();
final TextEditingController templateTwoTf = TextEditingController();
final TextEditingController templateNameTf = TextEditingController();
RxBool isVip = false.obs;
RxList<SMSTemplateData> templateList = <SMSTemplateData>[].obs;
RxString templateTypeText = '电子钥匙'.tr.obs;
RxString templateContentText = ''.obs; //
// RxString templateTypeText = '电子钥匙'.tr.obs;
// RxString templateContentText = ''.obs; //
Rx<SMSTemplateData> currentTemplate = SMSTemplateData().obs;
RxBool isShowDate = false.obs;
RxBool isUpdate = false.obs;
}

View File

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart';
@ -53,9 +54,11 @@ class _CustomSMSTemplateListPageState extends State<CustomSMSTemplateListPage> {
margin: EdgeInsets.only(
left: 30.w, right: 30.w, top: 30.w, bottom: 30.w),
padding: EdgeInsets.only(top: 25.w, bottom: 25.w),
onClick: () {
Navigator.pushNamed(
context, Routers.valueAddedServicesAddSMSTemplatePage);
onClick: () async {
final result = await Get.toNamed(Routers.newSMSTemplatePage);
if (result != null) {
logic.getSMSTemplateListRequest();
}
}),
SizedBox(
height: 40.h,
@ -95,7 +98,6 @@ class _CustomSMSTemplateListPageState extends State<CustomSMSTemplateListPage> {
children: <Widget>[
SizedBox(
width: 1.sw - 15.w * 2 - 40.w * 2 - 140.w,
// margin: EdgeInsets.only(top:15.h, left: 15.w, right: 15.w, bottom: 15.h),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
@ -150,12 +152,24 @@ class _CustomSMSTemplateListPageState extends State<CustomSMSTemplateListPage> {
Widget _valueAddedServicesListSMSTemplateItem(
CustomSMSTemplateItem itemData) {
return GestureDetector(
onTap: () {
Navigator.pushNamed(
context, Routers.valueAddedServicesAddSMSTemplatePage);
onTap: () async {
final SMSTemplateData templateData = SMSTemplateData();
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 ? '电子钥匙' : '密码';
final result = await Get.toNamed(Routers.newSMSTemplatePage,
arguments: <String, SMSTemplateData>{
'currentTemplate': templateData
});
if (result != null) {
logic.getSMSTemplateListRequest();
}
},
child: Container(
// height: 100.h,
margin: EdgeInsets.only(left: 20.w, right: 20.w, top: 20.w),
decoration: BoxDecoration(
color: Colors.white,

View File

@ -1,9 +1,7 @@
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/translations/trans_lib.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart';
class CustomSMSTemplateListState {
//
@ -14,42 +12,6 @@ class CustomSMSTemplateListState {
final TextStyle defaultStyle =
TextStyle(color: Colors.black, fontSize: 20.sp);
// //-
// late InlineSpan passwardSpan = TextSpan(children: <InlineSpan>[
// TextSpan(
// text:
// '${TranslationLoader.lanKeys!.hello!.tr}\n${TranslationLoader.lanKeys!.yourRoomIs!.tr}',
// style: defaultStyle),
// TextSpan(text: '201', style: highStyle),
// TextSpan(
// text: ' ${TranslationLoader.lanKeys!.theCodeToOpenTheDoorIs!.tr} ',
// style: defaultStyle),
// TextSpan(text: '332211\n', style: highStyle),
// TextSpan(
// text: '${TranslationLoader.lanKeys!.periodValidity!.tr} ',
// style: defaultStyle),
// TextSpan(text: '2021.12.11 12:00 - 2021.12.12 13:00。\n', style: highStyle),
// TextSpan(
// text: TranslationLoader.lanKeys!.templateTip1!.tr, style: defaultStyle),
// ]);
// //-
// late InlineSpan electronicKeySpan = TextSpan(children: <InlineSpan>[
// TextSpan(
// text:
// '${TranslationLoader.lanKeys!.hello!.tr}\n${TranslationLoader.lanKeys!.templateTip2!.tr}',
// style: defaultStyle),
// TextSpan(text: 'https://abc.com/bcd\n', style: highStyle),
// TextSpan(
// text: '${TranslationLoader.lanKeys!.templateTip3!.tr}\n',
// style: defaultStyle),
// TextSpan(text: 'https://abc.com/bcd', style: highStyle),
// ]);
// final TextEditingController templateOneTf = TextEditingController();
// final TextEditingController templateTwoTf = TextEditingController();
// final TextEditingController templateNameTf = TextEditingController();
RxBool isVip = false.obs;
RxList smsTemplateList = [].obs;
RxList<CustomSMSTemplateItem> smsTemplateList = <CustomSMSTemplateItem>[].obs;
}

View File

@ -250,4 +250,5 @@ abstract class Api {
'/v2/service/getDefaultTemplate'; //
final String addSMSTemplateURL = '/v2/service/addSmsTemplate'; //
final String keydetail = ' /key/detail'; //
final String updateTemplateInfoURL = '/v2/service/update'; //
}

View File

@ -126,15 +126,12 @@ class ApiProvider extends BaseProvider {
'searchStr': searchStr
}));
Future<Response> electronicKey(
int lockId, int keyId
) =>
post(
keydetail.toUrl,
jsonEncode({
'lockId': lockId.toString(),
'keyId': keyId.toString(),
}));
Future<Response> electronicKey(int lockId, int keyId) => post(
keydetail.toUrl,
jsonEncode({
'lockId': lockId.toString(),
'keyId': keyId.toString(),
}));
Future<Response> sendElectronicKey(
int createUser,
@ -449,13 +446,12 @@ class ApiProvider extends BaseProvider {
'searchStr': searchStr
}));
Future<Response> passwordKey(int lockId, int keyboardPwdId,) =>
post(
passwordKeyDetailURL.toUrl,
jsonEncode({
'lockId': lockId,
'keyboardPwdId': keyboardPwdId
}));
Future<Response> passwordKey(
int lockId,
int keyboardPwdId,
) =>
post(passwordKeyDetailURL.toUrl,
jsonEncode({'lockId': lockId, 'keyboardPwdId': keyboardPwdId}));
Future<Response> resetPasswordKey(String lockId, String operatorUid) => post(
resetPasswordURL.toUrl,
@ -1116,17 +1112,15 @@ class ApiProvider extends BaseProvider {
}));
//
Future<Response> getFingerprintsData(
int fingerprintId) =>
post(
getFingerprintDetailURL.toUrl,
jsonEncode({
'fingerprintId': fingerprintId,
}));
Future<Response> getFingerprintsData(int fingerprintId) => post(
getFingerprintDetailURL.toUrl,
jsonEncode({
'fingerprintId': fingerprintId,
}));
//
Future<Response> getFingerprintsListData(
String lockId, String pageNo, String pageSize, String searchStr) =>
String lockId, String pageNo, String pageSize, String searchStr) =>
post(
getFingerprintListURL.toUrl,
jsonEncode({
@ -2204,6 +2198,19 @@ class ApiProvider extends BaseProvider {
}),
isUnShowLoading: true,
);
Future<Response<dynamic>> updateTemplateInfo(
int id, String name, String regards, String tips) =>
post(
updateTemplateInfoURL.toUrl,
jsonEncode(<String, dynamic>{
'id': id,
'name': name,
'regards': regards,
'tips': tips,
}),
isUnShowLoading: true,
);
}
extension ExtensionString on String {

View File

@ -174,10 +174,9 @@ class ApiRepository {
}
//
Future<ElectronicKeyEntity> electronicKey({
required int lockId,required int keyId
}) async {
final res = await apiProvider.electronicKey(lockId,keyId);
Future<ElectronicKeyEntity> electronicKey(
{required int lockId, required int keyId}) async {
final res = await apiProvider.electronicKey(lockId, keyId);
return ElectronicKeyEntity.fromJson(res.body);
}
@ -425,13 +424,11 @@ class ApiRepository {
}
//
Future<PasswordKeyEntity> passwordKey( int lockId,int keyboardPwdId) async {
final res = await apiProvider.passwordKey(
lockId, keyboardPwdId);
Future<PasswordKeyEntity> passwordKey(int lockId, int keyboardPwdId) async {
final res = await apiProvider.passwordKey(lockId, keyboardPwdId);
return PasswordKeyEntity.fromJson(res.body);
}
//
Future<PasswordKeyListEntity> resetPasswordKey(
String lockId, String operatorUid) async {
@ -2221,4 +2218,15 @@ class ApiRepository {
type, name, contentType, regards, tips, fixedKey);
return LoginEntity.fromJson(res.body);
}
//
Future<LoginEntity> updateTemplateInfo(
{required int id,
required String name,
required String regards,
required String tips}) async {
final Response<dynamic> res =
await apiProvider.updateTemplateInfo(id, name, regards, tips);
return LoginEntity.fromJson(res.body);
}
}