2024-06-04 14:44:04 +08:00
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2024-06-05 11:02:26 +08:00
|
|
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
2024-06-04 14:44:04 +08:00
|
|
|
|
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/tools/regularExpression.dart';
|
|
|
|
|
|
import 'package:star_lock/tools/storage.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../../../network/api_repository.dart';
|
|
|
|
|
|
import '../../../../tools/baseGetXController.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class CustomSMSTemplateListLogic extends BaseGetXController {
|
|
|
|
|
|
CustomSMSTemplateListState state = CustomSMSTemplateListState();
|
|
|
|
|
|
|
|
|
|
|
|
//获取短信模板列表
|
2024-06-05 11:02:26 +08:00
|
|
|
|
Future<void> getSMSTemplateListRequest({required bool isRefresh}) async {
|
|
|
|
|
|
// 如果是下拉刷新,清空已有数据
|
|
|
|
|
|
if (isRefresh) {
|
|
|
|
|
|
state.smsTemplateList.clear();
|
|
|
|
|
|
pageNo = 1;
|
|
|
|
|
|
}
|
2024-06-04 14:44:04 +08:00
|
|
|
|
final CustomSMSTemplateListEntity entity = await ApiRepository.to
|
2024-06-05 11:02:26 +08:00
|
|
|
|
.getSMSTemplateList(
|
2024-06-05 18:24:59 +08:00
|
|
|
|
type: state.type.value,
|
|
|
|
|
|
pageNo: pageNo,
|
|
|
|
|
|
pageSize: int.parse(pageSize));
|
2024-06-04 14:44:04 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
state.smsTemplateList.value =
|
|
|
|
|
|
entity.data?.list ?? <CustomSMSTemplateItem>[];
|
|
|
|
|
|
state.smsTemplateList.refresh();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-05 11:02:26 +08:00
|
|
|
|
//删除短信模版
|
|
|
|
|
|
Future<void> deleteSMSTemplateRequest({required int id}) async {
|
|
|
|
|
|
final LoginEntity entity =
|
|
|
|
|
|
await ApiRepository.to.deleteTemplateInfo(id: id);
|
|
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
getSMSTemplateListRequest(isRefresh: true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-04 14:44:04 +08:00
|
|
|
|
List<TextSpan> buildElectronicKeySpan(
|
|
|
|
|
|
{required CustomSMSTemplateItem templateData}) {
|
|
|
|
|
|
final List<TextSpan> textSpans = <TextSpan>[];
|
|
|
|
|
|
|
|
|
|
|
|
textSpans.add(
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
text: '${templateData.regards}\n',
|
|
|
|
|
|
style: state.defaultStyle,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
// 将模板分割为文本片段
|
|
|
|
|
|
final List<String> textFragments =
|
|
|
|
|
|
templateData.template?.split(RegularExpression.urlRegExp) ?? [];
|
|
|
|
|
|
|
|
|
|
|
|
// 添加链接文本和普通文本到文本片段列表
|
|
|
|
|
|
for (int i = 0; i < textFragments.length; i++) {
|
|
|
|
|
|
final String textFragment = textFragments[i];
|
|
|
|
|
|
// 添加普通文本
|
|
|
|
|
|
textSpans.add(
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
text: textFragment,
|
|
|
|
|
|
style: state.defaultStyle,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
// 如果不是最后一个文本片段,则添加换行符
|
|
|
|
|
|
if (i < textFragments.length - 1) {
|
|
|
|
|
|
textSpans.add(
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
text: '\n',
|
|
|
|
|
|
style: state.defaultStyle,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
// 添加链接文本
|
|
|
|
|
|
textSpans.add(
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
text: RegularExpression.urlRegExp
|
|
|
|
|
|
.stringMatch(templateData.template!) ??
|
|
|
|
|
|
'',
|
|
|
|
|
|
style: state.highStyle,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
textSpans.add(
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
text: '\n${templateData.tips}',
|
|
|
|
|
|
style: state.defaultStyle,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return textSpans;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
List<TextSpan> buildPasswordSpan(
|
|
|
|
|
|
{required CustomSMSTemplateItem templateData}) {
|
|
|
|
|
|
final List<TextSpan> textSpans = <TextSpan>[];
|
|
|
|
|
|
|
|
|
|
|
|
textSpans.add(
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
text: '${templateData.regards}\n',
|
|
|
|
|
|
style: state.defaultStyle,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// 定义匹配 ${} 包围的变量的正则表达式
|
|
|
|
|
|
final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}');
|
|
|
|
|
|
|
|
|
|
|
|
final String template = templateData.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';
|
|
|
|
|
|
});
|
|
|
|
|
|
textSpans.add(
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
text: replacedNonVariableText,
|
|
|
|
|
|
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,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
textSpans.add(
|
|
|
|
|
|
TextSpan(
|
|
|
|
|
|
text: '\n${templateData.tips}',
|
|
|
|
|
|
style: state.defaultStyle,
|
|
|
|
|
|
),
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
return textSpans;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
onReady() async {
|
|
|
|
|
|
var isVip = await Storage.getBool(saveIsVip);
|
|
|
|
|
|
state.isVip.value = isVip ?? false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|