auth-web/src/store/configuration/emailTemplate.ts

106 lines
2.7 KiB
TypeScript
Raw Normal View History

import { defineStore } from 'pinia';
2025-04-24 13:43:37 +08:00
import {
2025-04-26 10:25:12 +08:00
addEmailTemplate,
2025-04-24 13:43:37 +08:00
fetchDeleteEmailTemplate,
fetchUpdateEmailTemplate,
2025-04-26 10:25:12 +08:00
getEmailTemplatePage,
getEmailTypeList,
2025-04-24 13:43:37 +08:00
} from '@/api/v1/email/emailTemplate';
import { pageSizes } from '@/enums/baseConstant';
import { storeMessage } from '@/utils/message';
import { storePagination } from '@/store/useStorePagination';
2024-11-03 21:33:23 +08:00
import { fetchGetAllMailboxConfigurationUsers } from '@/api/v1/email/emailUsers';
/**
* Store
*/
export const useEmailTemplateStore = defineStore('emailTemplateStore', {
2025-04-24 13:43:37 +08:00
state() {
return {
// 邮件模板表列表
datalist: [],
// 邮件模板用户列表
emailUserList: [],
// 邮件类型枚举
allEmailTypes: [],
// 查询表单
form: {
// 模板名称
templateName: undefined,
// 主题
subject: undefined,
// 邮件内容
body: undefined,
// 邮件类型
type: undefined,
},
// 分页查询结果
pagination: {
currentPage: 1,
pageSize: 30,
total: 1,
pageSizes,
},
// 加载
loading: false,
};
},
getters: {
getMailboxConfigurationUser(state) {
const map = {};
state.emailUserList.forEach((user) => (map[user.value] = user.key));
return map;
},
},
actions: {
/** 获取邮件模板表 */
2025-04-26 10:25:12 +08:00
async fetchEmailTemplatePage() {
2025-04-24 13:43:37 +08:00
// 整理请求参数
const data = { ...this.pagination, ...this.form };
delete data.pageSizes;
delete data.total;
delete data.background;
2025-04-24 13:43:37 +08:00
// 获取邮件模板表列表
2025-04-26 10:25:12 +08:00
const result = await getEmailTemplatePage(data);
2025-04-24 13:43:37 +08:00
// 公共页面函数hook
const pagination = storePagination.bind(this);
return pagination(result);
},
2025-04-24 13:43:37 +08:00
/** 获取所有邮箱配置用户 */
async getAllMailboxConfigurationUsers() {
const result = await fetchGetAllMailboxConfigurationUsers();
if (result.code !== 200) return;
2024-10-14 16:00:14 +08:00
2025-04-24 13:43:37 +08:00
this.emailUserList = result.data;
},
2024-10-14 16:00:14 +08:00
2025-04-24 13:43:37 +08:00
/** 获取模板类型字段 */
2025-04-26 10:25:12 +08:00
async loadEmailTypeList() {
const result = await getEmailTypeList();
2025-04-24 13:43:37 +08:00
if (result.code !== 200) return;
this.allEmailTypes = result.data;
},
2025-04-24 13:43:37 +08:00
/** 添加邮件模板表 */
async addEmailTemplate(data: any) {
2025-04-26 10:25:12 +08:00
const result = await addEmailTemplate(data);
2025-04-24 13:43:37 +08:00
return storeMessage(result);
},
2025-04-24 13:43:37 +08:00
/** 修改邮件模板表 */
async updateEmailTemplate(data: any) {
const result = await fetchUpdateEmailTemplate(data);
return storeMessage(result);
},
2025-04-24 13:43:37 +08:00
/** 删除邮件模板表 */
async deleteEmailTemplate(data: any) {
const result = await fetchDeleteEmailTemplate(data);
return storeMessage(result);
},
},
});