1,新建邮件模版(电子钥匙、密码)API对接及兼容短信模版
2,删除邮件模版API对接及对应逻辑处理 3,新增计算短信条数函数及更新布局
This commit is contained in:
parent
fe5b3089a3
commit
7d01b9a056
@ -15,7 +15,7 @@ class NewSMSTemplateLogic extends BaseGetXController {
|
|||||||
//获取默认模板-- 1:电子钥匙 2:密码
|
//获取默认模板-- 1:电子钥匙 2:密码
|
||||||
Future<void> getDefaultTemplate() async {
|
Future<void> getDefaultTemplate() async {
|
||||||
final NewSMSTemplateEntity entity = await ApiRepository.to
|
final NewSMSTemplateEntity entity = await ApiRepository.to
|
||||||
.getDefaultTemplate(type: state.currentTemplate.value.type ?? 0);
|
.getDefaultTemplate(type: state.templateType.value);
|
||||||
if (entity.errorCode!.codeIsSuccessful) {
|
if (entity.errorCode!.codeIsSuccessful) {
|
||||||
state.templateList.value = entity.dataList ?? <SMSTemplateData>[];
|
state.templateList.value = entity.dataList ?? <SMSTemplateData>[];
|
||||||
if (state.templateList.isNotEmpty) {
|
if (state.templateList.isNotEmpty) {
|
||||||
@ -59,9 +59,32 @@ class NewSMSTemplateLogic extends BaseGetXController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TextSpan> buildElectronicKeySpan({required bool isPreview}) {
|
// 更新短信条数的函数
|
||||||
final List<TextSpan> textSpans = <TextSpan>[];
|
void updateSmsCost(String template) {
|
||||||
|
state.smsCost.value = calculateSmsCost(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
int calculateSmsCost(String template) {
|
||||||
|
final int smsCount = template.length;
|
||||||
|
if (smsCount <= 70) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return (smsCount / 67).ceil();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//构建电子钥匙模板
|
||||||
|
List<TextSpan> buildElectronicKeySpan({required bool isPreview}) {
|
||||||
|
//短信模版
|
||||||
|
if (state.templateType.value == 1) {
|
||||||
|
return _buildSMSElectronicKey(isPreview);
|
||||||
|
} else {
|
||||||
|
return _buildEmailElectronicKey(isPreview);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TextSpan> _buildSMSElectronicKey(bool isPreview) {
|
||||||
|
final List<TextSpan> textSpans = <TextSpan>[];
|
||||||
// 如果是预览模式,添加预览模板的文本
|
// 如果是预览模式,添加预览模板的文本
|
||||||
if (isPreview) {
|
if (isPreview) {
|
||||||
textSpans.add(
|
textSpans.add(
|
||||||
@ -74,7 +97,7 @@ class NewSMSTemplateLogic extends BaseGetXController {
|
|||||||
// 将模板分割为文本片段
|
// 将模板分割为文本片段
|
||||||
final List<String> textFragments = state.currentTemplate.value.template
|
final List<String> textFragments = state.currentTemplate.value.template
|
||||||
?.split(RegularExpression.urlRegExp) ??
|
?.split(RegularExpression.urlRegExp) ??
|
||||||
[];
|
<String>[];
|
||||||
|
|
||||||
// 添加链接文本和普通文本到文本片段列表
|
// 添加链接文本和普通文本到文本片段列表
|
||||||
for (int i = 0; i < textFragments.length; i++) {
|
for (int i = 0; i < textFragments.length; i++) {
|
||||||
@ -115,7 +138,62 @@ class NewSMSTemplateLogic extends BaseGetXController {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return textSpans;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<TextSpan> _buildEmailElectronicKey(bool isPreview) {
|
||||||
|
final List<TextSpan> textSpans = <TextSpan>[];
|
||||||
|
|
||||||
|
//邮件模版
|
||||||
|
// 如果是预览模式,添加预览模板的文本
|
||||||
|
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<Match> 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;
|
return textSpans;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,64 +210,68 @@ class NewSMSTemplateLogic extends BaseGetXController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义匹配 ${} 包围的变量的正则表达式
|
//短信模版才需要加默认模版
|
||||||
final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}');
|
if (state.templateType == 1 ||
|
||||||
|
(state.templateType == 2 && isPreview == false)) {
|
||||||
|
// 定义匹配 ${} 包围的变量的正则表达式
|
||||||
|
final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}');
|
||||||
|
|
||||||
final String template = state.currentTemplate.value.template ?? '';
|
final String template = state.currentTemplate.value.template ?? '';
|
||||||
|
|
||||||
// 对模板进行处理
|
// 对模板进行处理
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
for (final Match match in variableRegExp.allMatches(template)) {
|
for (final Match match in variableRegExp.allMatches(template)) {
|
||||||
// 处理变量之前的文本
|
// 处理变量之前的文本
|
||||||
final String nonVariableText =
|
final String nonVariableText =
|
||||||
template.substring(startIndex, match.start);
|
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 replacedNonVariableText =
|
final String replacedRemainingText =
|
||||||
nonVariableText.replaceAllMapped(RegExp(r',|。'), (Match match) {
|
remainingText.replaceAllMapped(RegExp(r',|。'), (Match match) {
|
||||||
return '${match.group(0)}\n';
|
return '${match.group(0)}\n';
|
||||||
});
|
});
|
||||||
textSpans.add(
|
textSpans.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: replacedNonVariableText,
|
text: replacedRemainingText,
|
||||||
style: state.defaultStyle,
|
style: state.defaultStyle,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// 处理变量
|
// 在预览模式下,添加预览模板的文本
|
||||||
final String variableText = match.group(0) ?? '';
|
if (isPreview) {
|
||||||
textSpans.add(
|
textSpans.add(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: variableText,
|
text: '\n${state.templateTwoTf.text}',
|
||||||
style: state.highStyle,
|
style: state.defaultStyle,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
// 更新起始索引
|
|
||||||
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;
|
return textSpans;
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: AppColors.mainBackgroundColor,
|
backgroundColor: AppColors.mainBackgroundColor,
|
||||||
appBar: TitleAppBar(
|
appBar: TitleAppBar(
|
||||||
barTitle: state.templateType.value == 1 ? '新建短信模版'.tr : '新建邮件模版'.tr,
|
barTitle: state.templateType == 1 ? '新建短信模版'.tr : '新建邮件模版'.tr,
|
||||||
haveBack: true,
|
haveBack: true,
|
||||||
backgroundColor: AppColors.mainColor,
|
backgroundColor: AppColors.mainColor,
|
||||||
),
|
),
|
||||||
@ -109,18 +109,24 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
|
|||||||
height: 100,
|
height: 100,
|
||||||
child: _buildTextField(state.templateOneTf),
|
child: _buildTextField(state.templateOneTf),
|
||||||
),
|
),
|
||||||
Obx(() => _buildTemplateWithType(isPreview: false)),
|
Obx(() => Container(
|
||||||
|
width: 1.sw - 50.w,
|
||||||
|
margin: EdgeInsets.only(left: 25.w, right: 25.w),
|
||||||
|
child: _buildTemplateWithType(isPreview: false),
|
||||||
|
)),
|
||||||
SizedBox(height: 10.h),
|
SizedBox(height: 10.h),
|
||||||
Container(
|
Obx(() => Visibility(
|
||||||
margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h),
|
visible: state.templateType.value == 1,
|
||||||
height: 100,
|
child: Container(
|
||||||
child: Stack(
|
margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h),
|
||||||
alignment: Alignment.bottomRight,
|
height: 100,
|
||||||
children: <Widget>[
|
child: Stack(
|
||||||
_buildTextField(state.templateTwoTf),
|
alignment: Alignment.bottomRight,
|
||||||
],
|
children: <Widget>[
|
||||||
),
|
_buildTextField(state.templateTwoTf),
|
||||||
),
|
],
|
||||||
|
),
|
||||||
|
))),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -144,7 +150,9 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Obx(() => Container(
|
Obx(() => Container(
|
||||||
|
width: 1.sw - 50.w,
|
||||||
margin: EdgeInsets.only(left: 25.w, right: 25.w),
|
margin: EdgeInsets.only(left: 25.w, right: 25.w),
|
||||||
|
padding: EdgeInsets.only(left: 20.w, right: 20.w, top: 10.h),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: const Color(0xFFF5F5F5),
|
color: const Color(0xFFF5F5F5),
|
||||||
borderRadius: BorderRadius.circular(10.h),
|
borderRadius: BorderRadius.circular(10.h),
|
||||||
@ -158,7 +166,7 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
|
|||||||
bottom: 25.h,
|
bottom: 25.h,
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
'预计产生短信条数:2',
|
'预计产生短信条数:${state.smsCost.value}',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
fontSize: 20.sp,
|
fontSize: 20.sp,
|
||||||
@ -176,19 +184,12 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
|
|||||||
state.currentTemplate.value.template!.isEmpty) {
|
state.currentTemplate.value.template!.isEmpty) {
|
||||||
return const SizedBox.shrink(); // 如果为空,返回一个空的 SizedBox
|
return const SizedBox.shrink(); // 如果为空,返回一个空的 SizedBox
|
||||||
} else {
|
} else {
|
||||||
return Row(
|
return RichText(
|
||||||
children: <Widget>[
|
text: TextSpan(
|
||||||
Padding(
|
children: state.currentTemplate.value.typeName == '电子钥匙'
|
||||||
padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 10.h),
|
? logic.buildElectronicKeySpan(isPreview: isPreview)
|
||||||
child: Obx(() => RichText(
|
: logic.buildPasswordSpan(isPreview: isPreview),
|
||||||
text: TextSpan(
|
),
|
||||||
children: state.currentTemplate.value.typeName == '电子钥匙'
|
|
||||||
? logic.buildElectronicKeySpan(isPreview: isPreview)
|
|
||||||
: logic.buildPasswordSpan(isPreview: isPreview),
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,6 +214,7 @@ class _NewSMSTemplatePageState extends State<NewSMSTemplatePage> {
|
|||||||
onChanged: (String value) {
|
onChanged: (String value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
controller.text = value;
|
controller.text = value;
|
||||||
|
logic.updateSmsCost(value); // 更新短信条数
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -30,7 +30,8 @@ class NewSMSTemplateState {
|
|||||||
|
|
||||||
RxBool isVip = false.obs;
|
RxBool isVip = false.obs;
|
||||||
RxList<SMSTemplateData> templateList = <SMSTemplateData>[].obs;
|
RxList<SMSTemplateData> templateList = <SMSTemplateData>[].obs;
|
||||||
Rx<SMSTemplateData> currentTemplate = SMSTemplateData().obs;
|
Rx<SMSTemplateData> currentTemplate = SMSTemplateData().obs; //当前模板信息
|
||||||
RxBool isShowDate = false.obs;
|
RxBool isShowDate = false.obs; //是否显示日期
|
||||||
RxInt templateType = 0.obs;
|
RxInt templateType = 0.obs; //1:短信 2:邮件
|
||||||
|
RxInt smsCost = 0.obs; //短信条数
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,9 +12,8 @@ import '../../../../tools/baseGetXController.dart';
|
|||||||
class CustomSMSTemplateListLogic extends BaseGetXController {
|
class CustomSMSTemplateListLogic extends BaseGetXController {
|
||||||
CustomSMSTemplateListState state = CustomSMSTemplateListState();
|
CustomSMSTemplateListState state = CustomSMSTemplateListState();
|
||||||
|
|
||||||
//获取短信模板列表
|
// 获取短信模板列表
|
||||||
Future<void> getSMSTemplateListRequest({required bool isRefresh}) async {
|
Future<void> getSMSTemplateListRequest({required bool isRefresh}) async {
|
||||||
// 如果是下拉刷新,清空已有数据
|
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
state.smsTemplateList.clear();
|
state.smsTemplateList.clear();
|
||||||
pageNo = 1;
|
pageNo = 1;
|
||||||
@ -31,7 +30,7 @@ class CustomSMSTemplateListLogic extends BaseGetXController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除短信模版
|
// 删除短信模板
|
||||||
Future<void> deleteSMSTemplateRequest({required int id}) async {
|
Future<void> deleteSMSTemplateRequest({required int id}) async {
|
||||||
final LoginEntity entity =
|
final LoginEntity entity =
|
||||||
await ApiRepository.to.deleteTemplateInfo(id: id);
|
await ApiRepository.to.deleteTemplateInfo(id: id);
|
||||||
@ -42,131 +41,75 @@ class CustomSMSTemplateListLogic extends BaseGetXController {
|
|||||||
|
|
||||||
List<TextSpan> buildElectronicKeySpan(
|
List<TextSpan> buildElectronicKeySpan(
|
||||||
{required CustomSMSTemplateItem templateData}) {
|
{required CustomSMSTemplateItem templateData}) {
|
||||||
final List<TextSpan> textSpans = <TextSpan>[];
|
final List<TextSpan> textSpans = [];
|
||||||
|
_addTextSpan(textSpans, '${templateData.regards}\n', state.defaultStyle);
|
||||||
textSpans.add(
|
_buildTextSpansFromTemplate(
|
||||||
TextSpan(
|
textSpans, templateData.template, state.defaultStyle, state.highStyle);
|
||||||
text: '${templateData.regards}\n',
|
_addTextSpan(textSpans, '\n${templateData.tips}', state.defaultStyle);
|
||||||
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;
|
return textSpans;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<TextSpan> buildPasswordSpan(
|
List<TextSpan> buildPasswordSpan(
|
||||||
{required CustomSMSTemplateItem templateData}) {
|
{required CustomSMSTemplateItem templateData}) {
|
||||||
final List<TextSpan> textSpans = <TextSpan>[];
|
final List<TextSpan> textSpans = [];
|
||||||
|
_addTextSpan(textSpans, '${templateData.regards}\n', state.defaultStyle);
|
||||||
textSpans.add(
|
_buildPasswordTextSpans(
|
||||||
TextSpan(
|
textSpans, templateData.template, state.defaultStyle, state.highStyle);
|
||||||
text: '${templateData.regards}\n',
|
_addTextSpan(textSpans, '\n${templateData.tips}', state.defaultStyle);
|
||||||
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;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
onReady() async {
|
Future<void> onReady() async {
|
||||||
|
super.onReady();
|
||||||
var isVip = await Storage.getBool(saveIsVip);
|
var isVip = await Storage.getBool(saveIsVip);
|
||||||
state.isVip.value = isVip ?? false;
|
state.isVip.value = isVip ?? false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user