“DaisyWu” 7cd575009b 1,接入最新添加短信、邮件模版API并修改部分逻辑代码
2,接入最新获取默认模版API并修改部分逻辑代码
3,新建短信、邮件模版新增国内、国际模版选择
4,重构新建模版、编辑模版模块代码
5,梳理最新获取已有模版列表API修改
2024-07-09 16:04:56 +08:00

121 lines
4.3 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:async';
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_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();
// 获取短信模板列表
Future<void> getSMSTemplateListRequest({required bool isRefresh}) async {
if (isRefresh) {
state.smsTemplateList.clear();
pageNo = 1;
}
final CustomSMSTemplateListEntity entity = await ApiRepository.to
.getSMSTemplateList(
channelType: state.channelType.value,
pageNo: pageNo,
pageSize: int.parse(pageSize));
if (entity.errorCode!.codeIsSuccessful) {
state.smsTemplateList.value =
entity.data?.list ?? <CustomSMSTemplateItem>[];
state.smsTemplateList.refresh();
}
}
// 删除短信模板
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(
{required CustomSMSTemplateItem templateData}) {
final List<TextSpan> textSpans = [];
_addTextSpan(textSpans, '${templateData.regards}\n', state.defaultStyle);
_buildTextSpansFromTemplate(
textSpans, templateData.template, state.defaultStyle, state.highStyle);
_addTextSpan(textSpans, '\n${templateData.tips}', state.defaultStyle);
return textSpans;
}
List<TextSpan> buildPasswordSpan(
{required CustomSMSTemplateItem templateData}) {
final List<TextSpan> textSpans = [];
_addTextSpan(textSpans, '${templateData.regards}\n', state.defaultStyle);
_buildPasswordTextSpans(
textSpans, templateData.template, state.defaultStyle, state.highStyle);
_addTextSpan(textSpans, '\n${templateData.tips}', state.defaultStyle);
return textSpans;
}
void _buildTextSpansFromTemplate(List<TextSpan> textSpans, String? template,
TextStyle defaultStyle, TextStyle highStyle) {
final List<String> textFragments =
template?.split(RegularExpression.urlRegExp) ?? [];
for (int i = 0; i < textFragments.length; i++) {
_addTextSpan(textSpans, textFragments[i], defaultStyle);
if (i < textFragments.length - 1) {
_addTextSpan(textSpans, '\n', defaultStyle);
_addTextSpan(
textSpans,
RegularExpression.urlRegExp.stringMatch(template!) ?? '',
highStyle);
}
}
}
void _buildPasswordTextSpans(List<TextSpan> textSpans, String? template,
TextStyle defaultStyle, TextStyle highStyle) {
final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}');
final String text = template ?? '';
int startIndex = 0;
for (final Match match in variableRegExp.allMatches(text)) {
_addTextSpan(
textSpans,
text
.substring(startIndex, match.start)
.replaceAllMapped(RegExp(r'|。'), (Match match) {
return '${match.group(0)}\n';
}),
defaultStyle);
_addTextSpan(textSpans, match.group(0) ?? '', highStyle);
startIndex = match.end;
}
_addTextSpan(
textSpans,
text.substring(startIndex).replaceAllMapped(RegExp(r'|。'),
(Match match) {
return '${match.group(0)}\n';
}),
defaultStyle);
}
void _addTextSpan(List<TextSpan> textSpans, String text, TextStyle style) {
textSpans.add(TextSpan(text: text, style: style));
}
Future<void> getVipStatus() async {
final bool? isVip = await Storage.getBool(saveIsVip);
state.isVip.value = isVip ?? false;
state.isVip.refresh();
}
@override
Future<void> onReady() async {
super.onReady();
}
}