Files
pengchen-exam-vue/src/components/Email/index.ts

46 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-08-17 20:03:19 +08:00
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: '' };
2025-08-17 20:03:19 +08:00
// 为了避免重复,可以先查找并更新,如果不存在再添加
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);
}