Vue3 重构:邮件模版的新增和修改操作

pull/34/MERGE
YunaiV 2023-03-18 10:39:19 +08:00
parent 4d03e46142
commit ba327cd8ae
5 changed files with 98 additions and 28 deletions

View File

@ -13,14 +13,6 @@ export interface MailTemplateVO {
remark: string remark: string
} }
export interface MailTemplatePageReqVO extends PageParam {
name?: string
code?: string
accountId?: number
status?: number
createTime?: Date[]
}
export interface MailSendReqVO { export interface MailSendReqVO {
mail: string mail: string
templateCode: string templateCode: string
@ -28,31 +20,31 @@ export interface MailSendReqVO {
} }
// 查询邮件模版列表 // 查询邮件模版列表
export const getMailTemplatePageApi = async (params: MailTemplatePageReqVO) => { export const getMailTemplatePage = async (params: PageParam) => {
return await request.get({ url: '/system/mail-template/page', params }) return await request.get({ url: '/system/mail-template/page', params })
} }
// 查询邮件模版详情 // 查询邮件模版详情
export const getMailTemplateApi = async (id: number) => { export const getMailTemplate = async (id: number) => {
return await request.get({ url: '/system/mail-template/get?id=' + id }) return await request.get({ url: '/system/mail-template/get?id=' + id })
} }
// 新增邮件模版 // 新增邮件模版
export const createMailTemplateApi = async (data: MailTemplateVO) => { export const createMailTemplate = async (data: MailTemplateVO) => {
return await request.post({ url: '/system/mail-template/create', data }) return await request.post({ url: '/system/mail-template/create', data })
} }
// 修改邮件模版 // 修改邮件模版
export const updateMailTemplateApi = async (data: MailTemplateVO) => { export const updateMailTemplate = async (data: MailTemplateVO) => {
return await request.put({ url: '/system/mail-template/update', data }) return await request.put({ url: '/system/mail-template/update', data })
} }
// 删除邮件模版 // 删除邮件模版
export const deleteMailTemplateApi = async (id: number) => { export const deleteMailTemplate = async (id: number) => {
return await request.delete({ url: '/system/mail-template/delete?id=' + id }) return await request.delete({ url: '/system/mail-template/delete?id=' + id })
} }
// 发送邮件 // 发送邮件
export const sendMailApi = (data: MailSendReqVO) => { export const sendMail = (data: MailSendReqVO) => {
return request.post({ url: '/system/mail-template/send-mail', data }) return request.post({ url: '/system/mail-template/send-mail', data })
} }

View File

@ -25,7 +25,6 @@ const openModal = async (type: string, id?: number) => {
modelVisible.value = true modelVisible.value = true
modelTitle.value = t('action.' + type) modelTitle.value = t('action.' + type)
formType.value = type formType.value = type
// resetForm()
// //
if (id) { if (id) {
formLoading.value = true formLoading.value = true

View File

@ -0,0 +1,66 @@
<template>
<Dialog :title="modelTitle" v-model="modelVisible" :scroll="true" :width="800" :max-height="500">
<Form ref="formRef" :schema="allSchemas.formSchema" :rules="rules" v-loading="formLoading" />
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="modelVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import * as MailTemplateApi from '@/api/system/mail/template'
import { rules, allSchemas } from './template.data'
const { t } = useI18n() //
const message = useMessage() //
const modelVisible = ref(false) //
const modelTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formRef = ref() // Ref
/** 打开弹窗 */
const openModal = async (type: string, id?: number) => {
modelVisible.value = true
modelTitle.value = t('action.' + type)
formType.value = type
//
if (id) {
formLoading.value = true
try {
const data = await MailTemplateApi.getMailTemplate(id)
formRef.value.setValues(data)
} finally {
formLoading.value = false
}
}
}
defineExpose({ openModal }) // openModal
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
if (!formRef) return
const valid = await formRef.value.getElFormRef().validate()
if (!valid) return
//
formLoading.value = true
try {
const data = formRef.value.formModel as MailTemplateApi.MailTemplateVO
if (formType.value === 'create') {
await MailTemplateApi.createMailTemplate(data)
message.success(t('common.createSuccess'))
} else {
await MailTemplateApi.updateMailTemplate(data)
message.success(t('common.updateSuccess'))
}
modelVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
</script>

View File

@ -49,28 +49,28 @@
</content-wrap> </content-wrap>
<!-- 表单弹窗添加/修改 --> <!-- 表单弹窗添加/修改 -->
<!-- <mail-template-form ref="modalRef" @success="getList" />--> <mail-template-form ref="modalRef" @success="getList" />
</template> </template>
<script setup lang="ts" name="MailTemplate"> <script setup lang="ts" name="MailTemplate">
import { allSchemas } from './template.data' import { allSchemas } from './template.data'
import * as MailTemplateApi from '@/api/system/mail/template' import * as MailTemplateApi from '@/api/system/mail/template'
// import MailAccountForm from './form.vue' import MailTemplateForm from './form.vue'
// tableObject // tableObject
// tableMethods // tableMethods
// https://kailong110120130.gitee.io/vue-element-plus-admin-doc/components/table.html#usetable // https://kailong110120130.gitee.io/vue-element-plus-admin-doc/components/table.html#usetable
const { tableObject, tableMethods } = useTable({ const { tableObject, tableMethods } = useTable({
getListApi: MailTemplateApi.getMailTemplatePageApi, // getListApi: MailTemplateApi.getMailTemplatePage, //
delListApi: MailTemplateApi.deleteMailTemplateApi // delListApi: MailTemplateApi.deleteMailTemplate //
}) })
// //
const { getList, setSearchParams } = tableMethods const { getList, setSearchParams } = tableMethods
/** 添加/修改操作 */ /** 添加/修改操作 */
// const modalRef = ref() const modalRef = ref()
// const openModal = (type: string, id?: number) => { const openModal = (type: string, id?: number) => {
// modalRef.value.openModal(type, id) modalRef.value.openModal(type, id)
// } }
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = (id: number) => { const handleDelete = (id: number) => {

View File

@ -42,14 +42,14 @@ const crudSchemas = reactive<CrudSchema[]>([
span: 24 span: 24
}, },
componentProps: { componentProps: {
valueHtml: '' valueHtml: '',
height: 200
} }
} }
}, },
{ {
label: '邮箱账号', label: '邮箱账号',
field: 'accountId', field: 'accountId',
isSearch: true,
width: '200px', width: '200px',
formatter: (_: Recordable, __: TableColumn, cellValue: number) => { formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
return accounts.find((account) => account.id === cellValue)?.mail return accounts.find((account) => account.id === cellValue)?.mail
@ -57,9 +57,17 @@ const crudSchemas = reactive<CrudSchema[]>([
search: { search: {
show: true, show: true,
component: 'Select', component: 'Select',
api: () => { api: () => accounts,
return accounts componentProps: {
}, optionsAlias: {
labelField: 'mail',
valueField: 'id'
}
}
},
form: {
component: 'Select',
api: () => accounts,
componentProps: { componentProps: {
optionsAlias: { optionsAlias: {
labelField: 'mail', labelField: 'mail',
@ -104,6 +112,11 @@ const crudSchemas = reactive<CrudSchema[]>([
defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')] defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')]
} }
} }
},
{
label: '操作',
field: 'action',
isForm: false
} }
]) ])
export const { allSchemas } = useCrudSchemas(crudSchemas) export const { allSchemas } = useCrudSchemas(crudSchemas)