fix: 添加邮箱出题页面事件
This commit is contained in:
45
src/components/Email/index.ts
Normal file
45
src/components/Email/index.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
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
|
||||
const data = { contentIn, content };
|
||||
|
||||
// 为了避免重复,可以先查找并更新,如果不存在再添加
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user