46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { useEmailStore } from '@/store/modules/email'
|
||
|
||
/**
|
||
* 通用的邮件消息发送函数,用于将设置更改添加到全局状态
|
||
* @param pageName 设置页面的顶级标题, e.g., '邮件'
|
||
* @param description 更改项的具体描述, e.g., '界面语言'
|
||
* @param category 更改项的分类, e.g., 'common'
|
||
* @param key 更改项的唯一标识, e.g., 'language'
|
||
* @param value 更改项的值 (可以是 boolean, string, number 等)
|
||
*/
|
||
export function sendEmailMsg(pageName: string, description: string, category: string, key: string, value: any) {
|
||
const emailStore = useEmailStore()
|
||
|
||
let displayValue: string;
|
||
|
||
// 根据值的类型格式化显示文本
|
||
if (typeof value === 'boolean') {
|
||
displayValue = value ? '打开' : '关闭';
|
||
} else {
|
||
displayValue = value;
|
||
}
|
||
|
||
// 拼接 contentIn 字符串
|
||
const contentIn = `设置${pageName}${description}: ${displayValue}`
|
||
|
||
// 拼接 content 字符串
|
||
const content = `${category}@${key}@${value}`
|
||
|
||
// 创建数据对象并添加到 store(包含scoreRate权值字段,默认为空,由用户填写)
|
||
const data = { contentIn, content, scoreRate: '' };
|
||
|
||
// 为了避免重复,可以先查找并更新,如果不存在再添加
|
||
const existingIndex = emailStore.emailFormList.findIndex(item => item.content.startsWith(`${category}@${key}@`));
|
||
|
||
if (existingIndex !== -1) {
|
||
// 如果已存在,则替换
|
||
emailStore.emailFormList[existingIndex] = data;
|
||
} else {
|
||
// 如果不存在,则添加
|
||
emailStore.emailFormList.push(data);
|
||
}
|
||
|
||
console.log('Updated email settings data:', data);
|
||
console.log('Current email form list:', emailStore.emailFormList);
|
||
}
|