1,自定义SMS模版页面新增上拉加载下拉刷新

2,新增删除模版API对接及逻辑处理
This commit is contained in:
Daisy 2024-06-05 11:02:26 +08:00
parent 3035a53ff7
commit 5caa8a598f
6 changed files with 101 additions and 37 deletions

View File

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:star_lock/login/login/entity/LoginEntity.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart'; import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_entity.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart'; import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart';
import 'package:star_lock/tools/regularExpression.dart'; import 'package:star_lock/tools/regularExpression.dart';
@ -12,9 +13,15 @@ class CustomSMSTemplateListLogic extends BaseGetXController {
CustomSMSTemplateListState state = CustomSMSTemplateListState(); CustomSMSTemplateListState state = CustomSMSTemplateListState();
// //
Future<void> getSMSTemplateListRequest() async { Future<void> getSMSTemplateListRequest({required bool isRefresh}) async {
//
if (isRefresh) {
state.smsTemplateList.clear();
pageNo = 1;
}
final CustomSMSTemplateListEntity entity = await ApiRepository.to final CustomSMSTemplateListEntity entity = await ApiRepository.to
.getSMSTemplateList(type: 1, pageNo: 1, pageSize: 20); .getSMSTemplateList(
type: 1, pageNo: pageNo, pageSize: int.parse(pageSize));
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
state.smsTemplateList.value = state.smsTemplateList.value =
entity.data?.list ?? <CustomSMSTemplateItem>[]; entity.data?.list ?? <CustomSMSTemplateItem>[];
@ -22,6 +29,15 @@ class CustomSMSTemplateListLogic extends BaseGetXController {
} }
} }
//
Future<void> deleteSMSTemplateRequest({required int id}) async {
final LoginEntity entity =
await ApiRepository.to.deleteTemplateInfo(id: id);
if (entity.errorCode!.codeIsSuccessful) {
getSMSTemplateListRequest(isRefresh: true);
}
}
List<TextSpan> buildElectronicKeySpan( List<TextSpan> buildElectronicKeySpan(
{required CustomSMSTemplateItem templateData}) { {required CustomSMSTemplateItem templateData}) {
final List<TextSpan> textSpans = <TextSpan>[]; final List<TextSpan> textSpans = <TextSpan>[];

View File

@ -1,11 +1,14 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_entity.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_entity.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart'; import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart';
import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart'; import 'package:star_lock/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_state.dart';
import 'package:star_lock/tools/EasyRefreshTool.dart';
import 'package:star_lock/tools/noData.dart'; import 'package:star_lock/tools/noData.dart';
import 'package:star_lock/tools/showTipView.dart';
import '../../../../appRouters.dart'; import '../../../../appRouters.dart';
import '../../../../app_settings/app_colors.dart'; import '../../../../app_settings/app_colors.dart';
@ -30,7 +33,7 @@ class _CustomSMSTemplateListPageState extends State<CustomSMSTemplateListPage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
logic.getSMSTemplateListRequest(); logic.getSMSTemplateListRequest(isRefresh: true);
} }
@override @override
@ -41,29 +44,37 @@ class _CustomSMSTemplateListPageState extends State<CustomSMSTemplateListPage> {
barTitle: '自定义短信模版'.tr, barTitle: '自定义短信模版'.tr,
haveBack: true, haveBack: true,
backgroundColor: AppColors.mainColor), backgroundColor: AppColors.mainColor),
body: Column( body: EasyRefreshTool(
children: <Widget>[ onRefresh: () {
Obx(() => Visibility( logic.getSMSTemplateListRequest(isRefresh: true);
child: _topTipWidget(), },
visible: !state.isVip.value, onLoad: () {
)), logic.getSMSTemplateListRequest(isRefresh: false);
Expanded(child: Obx(buildMainUI)), },
SubmitBtn( child: Column(
btnName: TranslationLoader.lanKeys!.creatingANewTemplate!.tr, children: <Widget>[
borderRadius: 20.w, Obx(() => Visibility(
margin: EdgeInsets.only( child: _topTipWidget(),
left: 30.w, right: 30.w, top: 30.w, bottom: 30.w), visible: !state.isVip.value,
padding: EdgeInsets.only(top: 25.w, bottom: 25.w), )),
onClick: () async { Expanded(child: Obx(buildMainUI)),
final result = await Get.toNamed(Routers.newSMSTemplatePage); SubmitBtn(
if (result != null) { btnName: TranslationLoader.lanKeys!.creatingANewTemplate!.tr,
logic.getSMSTemplateListRequest(); borderRadius: 20.w,
} margin: EdgeInsets.only(
}), left: 30.w, right: 30.w, top: 30.w, bottom: 30.w),
SizedBox( padding: EdgeInsets.only(top: 25.w, bottom: 25.w),
height: 40.h, onClick: () async {
) final result = await Get.toNamed(Routers.newSMSTemplatePage);
], if (result != null) {
logic.getSMSTemplateListRequest(isRefresh: true);
}
}),
SizedBox(
height: 40.h,
)
],
),
), ),
); );
} }
@ -139,13 +150,36 @@ class _CustomSMSTemplateListPageState extends State<CustomSMSTemplateListPage> {
Widget buildMainUI() { Widget buildMainUI() {
return state.smsTemplateList.isNotEmpty return state.smsTemplateList.isNotEmpty
? ListView.builder( ? SlidableAutoCloseBehavior(
itemCount: state.smsTemplateList.length, child: ListView.builder(
itemBuilder: (BuildContext c, int index) { itemCount: state.smsTemplateList.length,
final CustomSMSTemplateItem itemData = itemBuilder: (BuildContext c, int index) {
state.smsTemplateList[index]; final CustomSMSTemplateItem itemData =
return _valueAddedServicesListSMSTemplateItem(itemData); state.smsTemplateList[index];
}) return Slidable(
key: ValueKey(itemData.id),
endActionPane: ActionPane(
extentRatio: 0.2,
motion: const ScrollMotion(),
children: <Widget>[
SlidableAction(
onPressed: (BuildContext context) {
ShowTipView()
.showIosTipWithContentDialog('是否删除?'.tr, () {
logic.deleteSMSTemplateRequest(
id: itemData.id ?? 0);
});
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
label: '删除'.tr,
padding: EdgeInsets.only(left: 5.w, right: 5.w),
),
],
),
child: _valueAddedServicesListSMSTemplateItem(itemData));
}),
)
: NoData(); : NoData();
} }
@ -166,7 +200,7 @@ class _CustomSMSTemplateListPageState extends State<CustomSMSTemplateListPage> {
'currentTemplate': templateData 'currentTemplate': templateData
}); });
if (result != null) { if (result != null) {
logic.getSMSTemplateListRequest(); logic.getSMSTemplateListRequest(isRefresh: true);
} }
}, },
child: Container( child: Container(

View File

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

View File

@ -2211,6 +2211,12 @@ class ApiProvider extends BaseProvider {
}), }),
isUnShowLoading: true, isUnShowLoading: true,
); );
Future<Response<dynamic>> deleteTemplateInfo(int id) => post(
deleteTemplateURL.toUrl,
jsonEncode(<String, dynamic>{'id': id}),
isUnShowLoading: true,
);
} }
extension ExtensionString on String { extension ExtensionString on String {

View File

@ -2229,4 +2229,10 @@ class ApiRepository {
await apiProvider.updateTemplateInfo(id, name, regards, tips); await apiProvider.updateTemplateInfo(id, name, regards, tips);
return LoginEntity.fromJson(res.body); return LoginEntity.fromJson(res.body);
} }
//
Future<LoginEntity> deleteTemplateInfo({required int id}) async {
final Response<dynamic> res = await apiProvider.deleteTemplateInfo(id);
return LoginEntity.fromJson(res.body);
}
} }

View File

@ -79,11 +79,11 @@ class ShowTipView {
content: Text(contentStr), content: Text(contentStr),
actions: <Widget>[ actions: <Widget>[
CupertinoDialogAction( CupertinoDialogAction(
child: Text(TranslationLoader.lanKeys!.cancel!.tr), child: Text('取消', style: TextStyle(color: AppColors.mainColor)),
onPressed: Get.back, onPressed: Get.back,
), ),
CupertinoDialogAction( CupertinoDialogAction(
child: Text(TranslationLoader.lanKeys!.sure!.tr), child: Text('确定', style: TextStyle(color: AppColors.mainColor)),
onPressed: () { onPressed: () {
Get.back(); Get.back();
sureClick(); sureClick();
@ -96,7 +96,8 @@ class ShowTipView {
} }
void showTFViewAlertDialog(TextEditingController controller, String title, void showTFViewAlertDialog(TextEditingController controller, String title,
String tipTitle, Function sureClick, {List<TextInputFormatter>? inputFormatters}) { String tipTitle, Function sureClick,
{List<TextInputFormatter>? inputFormatters}) {
// //
showDialog( showDialog(
context: Get.context!, context: Get.context!,