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

243 lines
6.0 KiB
Dart

import 'dart:convert';
class NewSMSTemplateEntity {
NewSMSTemplateEntity({
this.errorCode,
this.description,
this.errorMsg,
this.dataList,
});
NewSMSTemplateEntity.fromJson(Map<String, dynamic> json) {
errorCode = json['errorCode'];
description = json['description'];
errorMsg = json['errorMsg'];
if (json['data'] != null) {
dataList = <LangData>[];
json['data'].forEach((v) {
dataList!.add(LangData.fromJson(v));
});
}
}
int? errorCode;
String? description;
String? errorMsg;
List<LangData>? dataList;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['errorCode'] = errorCode;
data['description'] = description;
data['errorMsg'] = errorMsg;
if (dataList != null) {
data['data'] = dataList!.map((v) => v.toJson()).toList();
}
return data;
}
}
class LangData {
LangData({
this.langType,
this.langName,
this.templates,
});
LangData.fromJson(Map<String, dynamic> json) {
langType = json['langType'];
langName = json['langName'];
if (json['templates'] != null) {
templates = <TemplateData>[];
json['templates'].forEach((v) {
templates!.add(TemplateData.fromJson(v));
});
}
}
int? langType;
String? langName;
List<TemplateData>? templates;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['langType'] = langType;
data['langName'] = langName;
if (templates != null) {
data['templates'] = templates!.map((v) => v.toJson()).toList();
}
return data;
}
}
class TemplateData {
TemplateData({
this.langType,
this.langName,
this.templateType,
this.templateName,
this.template,
this.templatePreviewCode,
});
TemplateData.fromJson(Map<String, dynamic> json) {
langType = json['langType'];
langName = json['langName'];
templateType = json['templateType'];
templateName = json['templateName'];
template = json['template'];
templatePreviewCode = json['templatePreviewCode'] != null
? jsonEncode(json['templatePreviewCode'])
: null;
}
int? langType;
String? langName;
int? templateType;
String? templateName;
String? template;
String? fixedKey;
String? templatePreviewCode; // Changed to String
String? regards = '';
String? tips = '';
int? id;
String? name;
int? channelType;
bool? isUpdate = false;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['langType'] = langType;
data['langName'] = langName;
data['templateType'] = templateType;
data['templateName'] = templateName;
data['template'] = template;
if (templatePreviewCode != null) {
data['templatePreviewCode'] = jsonDecode(templatePreviewCode!);
}
return data;
}
// New method to replace template variables with values from templatePreviewCode
String generatePreview() {
if (template == null || templatePreviewCode == null) {
return '';
}
// Decode the templatePreviewCode string back to a map
final Map<String, String> previewCodeMap =
Map<String, String>.from(jsonDecode(templatePreviewCode!));
String previewTemplate = template!;
previewCodeMap.forEach((String key, String value) {
previewTemplate = previewTemplate.replaceAll(
key, value + (value.length > 2 ? '\n' : ''));
});
return previewTemplate;
}
}
/*
class NewSMSTemplateEntity {
NewSMSTemplateEntity({
this.errorCode,
this.description,
this.errorMsg,
this.dataList,
});
NewSMSTemplateEntity.fromJson(Map<String, dynamic> json) {
errorCode = json['errorCode'];
description = json['description'];
errorMsg = json['errorMsg'];
if (json['data'] != null) {
dataList = <SMSTemplateData>[];
json['data'].forEach((v) {
dataList!.add(SMSTemplateData.fromJson(v));
});
}
}
int? errorCode;
String? description;
String? errorMsg;
List<SMSTemplateData>? dataList;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['errorCode'] = errorCode;
data['description'] = description;
data['errorMsg'] = errorMsg;
if (dataList != null) {
data['data'] = dataList!.map((v) => v.toJson()).toList();
}
return data;
}
}
class SMSTemplateData {
SMSTemplateData({
this.contentType,
this.typeName,
this.template,
this.fixedKey,
this.templatePreviewCode,
});
SMSTemplateData.fromJson(Map<String, dynamic> json) {
contentType = json['content_type'];
typeName = json['typeName'];
template = json['template'];
fixedKey = json['fixed_key'];
templatePreviewCode = json['template_preview_code'] != null
? jsonEncode(json['template_preview_code'])
: null;
}
int? contentType;
String? typeName;
String? template;
String? fixedKey;
String? templatePreviewCode; // Changed to String
String? regards = '';
String? tips = '';
int? id;
String? name;
int? type;
bool? isUpdate = false;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['content_type'] = contentType;
data['typeName'] = typeName;
data['template'] = template;
data['fixed_key'] = fixedKey;
if (templatePreviewCode != null) {
data['template_preview_code'] = jsonDecode(templatePreviewCode!);
}
return data;
}
// New method to replace template variables with values from templatePreviewCode
String generatePreview() {
if (template == null || templatePreviewCode == null) {
return '';
}
// Decode the templatePreviewCode string back to a map
final Map<String, String> previewCodeMap =
Map<String, String>.from(jsonDecode(templatePreviewCode!));
String previewTemplate = template!;
previewCodeMap.forEach((String key, String value) {
previewTemplate = previewTemplate.replaceAll(
key, value + (value.length > 2 ? '\n' : ''));
});
return previewTemplate;
}
}
*/