3 changed files with 299 additions and 1 deletions
@ -0,0 +1,58 @@
|
||||
<template> |
||||
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit"> |
||||
<BasicForm @register="registerForm" /> |
||||
</BasicModal> |
||||
</template> |
||||
<script lang="ts" setup name="MailTemplateModel"> |
||||
import { ref, computed, unref } from 'vue' |
||||
import { BasicModal, useModalInner } from '@/components/Modal' |
||||
import { BasicForm, useForm } from '@/components/Form' |
||||
import { formSchema } from './template.data' |
||||
import { createMailTemplateApi, getMailTemplateApi, updateMailTemplateApi } from '@/api/system/mail/template' |
||||
|
||||
const emit = defineEmits(['success', 'register']) |
||||
const isUpdate = ref(true) |
||||
const rowId = ref() |
||||
|
||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ |
||||
labelWidth: 100, |
||||
baseColProps: { span: 24 }, |
||||
schemas: formSchema, |
||||
showActionButtonGroup: false, |
||||
actionColOptions: { |
||||
span: 23 |
||||
} |
||||
}) |
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
||||
resetFields() |
||||
setModalProps({ confirmLoading: false }) |
||||
isUpdate.value = !!data?.isUpdate |
||||
|
||||
if (unref(isUpdate)) { |
||||
const res = await getMailTemplateApi(data.record.id) |
||||
rowId.value = res.id |
||||
setFieldsValue({ |
||||
...res |
||||
}) |
||||
} |
||||
}) |
||||
|
||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增邮箱' : '编辑邮箱')) |
||||
|
||||
async function handleSubmit() { |
||||
try { |
||||
const values = await validate() |
||||
setModalProps({ confirmLoading: true }) |
||||
if (unref(isUpdate)) { |
||||
await updateMailTemplateApi(values) |
||||
} else { |
||||
await createMailTemplateApi(values) |
||||
} |
||||
closeModal() |
||||
emit('success') |
||||
} finally { |
||||
setModalProps({ confirmLoading: false }) |
||||
} |
||||
} |
||||
</script> |
@ -1,3 +1,81 @@
|
||||
<template> |
||||
<div>开发中</div> |
||||
<div> |
||||
<BasicTable @register="registerTable"> |
||||
<template #toolbar> |
||||
<a-button type="primary" @click="handleCreate"> 新增 </a-button> |
||||
</template> |
||||
<template #bodyCell="{ column, record }"> |
||||
<template v-if="column.key === 'action'"> |
||||
<TableAction |
||||
:actions="[ |
||||
{ |
||||
icon: 'clarity:note-edit-line', |
||||
label: '修改', |
||||
onClick: handleEdit.bind(null, record) |
||||
}, |
||||
{ |
||||
icon: 'ant-design:delete-outlined', |
||||
color: 'error', |
||||
label: '删除', |
||||
popConfirm: { |
||||
title: '是否确认删除', |
||||
placement: 'left', |
||||
confirm: handleDelete.bind(null, record) |
||||
} |
||||
} |
||||
]" |
||||
/> |
||||
</template> |
||||
</template> |
||||
</BasicTable> |
||||
<TemplateModel @register="registerModal" @success="reload()" /> |
||||
</div> |
||||
</template> |
||||
<script lang="ts" setup name="MailTemplate"> |
||||
import { BasicTable, useTable, TableAction } from '@/components/Table' |
||||
import { deleteMailTemplateApi, getMailTemplatePageApi } from '@/api/system/mail/template' |
||||
import { useModal } from '@/components/Modal' |
||||
import TemplateModel from './TemplateModel.vue' |
||||
import { columns, searchFormSchema } from './template.data' |
||||
import { useMessage } from '@/hooks/web/useMessage' |
||||
|
||||
const { createMessage } = useMessage() |
||||
const [registerModal, { openModal }] = useModal() |
||||
const [registerTable, { reload }] = useTable({ |
||||
title: '邮件模板列表', |
||||
api: getMailTemplatePageApi, |
||||
columns, |
||||
formConfig: { |
||||
labelWidth: 120, |
||||
schemas: searchFormSchema |
||||
}, |
||||
useSearchForm: true, |
||||
showTableSetting: true, |
||||
showIndexColumn: false, |
||||
actionColumn: { |
||||
width: 160, |
||||
title: '操作', |
||||
dataIndex: 'action', |
||||
fixed: 'right' |
||||
} |
||||
}) |
||||
|
||||
function handleCreate() { |
||||
openModal(true, { |
||||
isUpdate: false |
||||
}) |
||||
} |
||||
|
||||
function handleEdit(record: Recordable) { |
||||
openModal(true, { |
||||
record, |
||||
isUpdate: true |
||||
}) |
||||
} |
||||
|
||||
async function handleDelete(record: Recordable) { |
||||
await deleteMailTemplateApi(record.id) |
||||
createMessage.success('删除成功') |
||||
reload() |
||||
} |
||||
</script> |
||||
|
@ -0,0 +1,162 @@
|
||||
import { getSimpleMailAccountListApi } from '@/api/system/mail/account' |
||||
import { BasicColumn, FormSchema, useRender } from '@/components/Table' |
||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
||||
|
||||
export const columns: BasicColumn[] = [ |
||||
{ |
||||
title: '模板编码', |
||||
dataIndex: 'code', |
||||
width: 100 |
||||
}, |
||||
{ |
||||
title: '模板名称', |
||||
dataIndex: 'name', |
||||
width: 180 |
||||
}, |
||||
{ |
||||
title: '模板标题', |
||||
dataIndex: 'title', |
||||
width: 100 |
||||
}, |
||||
{ |
||||
title: '模板内容', |
||||
dataIndex: 'content', |
||||
width: 300 |
||||
}, |
||||
{ |
||||
title: '邮箱账号', |
||||
dataIndex: 'accountId', |
||||
width: 120 |
||||
}, |
||||
{ |
||||
title: '发送人名称', |
||||
dataIndex: 'nickname', |
||||
width: 100 |
||||
}, |
||||
{ |
||||
title: '开启状态', |
||||
dataIndex: 'status', |
||||
width: 180, |
||||
customRender: ({ text }) => { |
||||
return useRender.renderDict(text, DICT_TYPE.COMMON_STATUS) |
||||
} |
||||
}, |
||||
{ |
||||
title: '创建时间', |
||||
dataIndex: 'createTime', |
||||
width: 180, |
||||
customRender: ({ text }) => { |
||||
return useRender.renderDate(text) |
||||
} |
||||
} |
||||
] |
||||
|
||||
export const searchFormSchema: FormSchema[] = [ |
||||
{ |
||||
label: '模板名称', |
||||
field: 'name', |
||||
component: 'Input', |
||||
colProps: { span: 8 } |
||||
}, |
||||
{ |
||||
label: '模板编码', |
||||
field: 'code', |
||||
component: 'Input', |
||||
colProps: { span: 8 } |
||||
}, |
||||
{ |
||||
label: '邮箱账号', |
||||
field: 'accountId', |
||||
component: 'ApiSelect', |
||||
componentProps: { |
||||
api: () => getSimpleMailAccountListApi(), |
||||
fieldNames: { |
||||
label: 'mail', |
||||
key: 'id', |
||||
value: 'id' |
||||
} |
||||
}, |
||||
colProps: { span: 8 } |
||||
}, |
||||
{ |
||||
label: '开启状态', |
||||
field: 'status', |
||||
component: 'Select', |
||||
componentProps: { |
||||
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) |
||||
}, |
||||
colProps: { span: 8 } |
||||
}, |
||||
{ |
||||
label: '创建时间', |
||||
field: 'createTime', |
||||
component: 'RangePicker', |
||||
colProps: { span: 8 } |
||||
} |
||||
] |
||||
|
||||
export const formSchema: FormSchema[] = [ |
||||
{ |
||||
label: '编号', |
||||
field: 'id', |
||||
show: false, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '模板名称', |
||||
field: 'name', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '模板编码', |
||||
field: 'code', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '邮箱账号', |
||||
field: 'accountId', |
||||
required: true, |
||||
component: 'ApiSelect', |
||||
componentProps: { |
||||
api: () => getSimpleMailAccountListApi(), |
||||
fieldNames: { |
||||
label: 'mail', |
||||
key: 'id', |
||||
value: 'id' |
||||
} |
||||
} |
||||
}, |
||||
{ |
||||
label: '发送人名称', |
||||
field: 'nickname', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '模板标题', |
||||
field: 'title', |
||||
required: true, |
||||
component: 'Input' |
||||
}, |
||||
{ |
||||
label: '模板内容', |
||||
field: 'content', |
||||
component: 'InputTextArea' |
||||
}, |
||||
{ |
||||
label: '开启状态', |
||||
field: 'status', |
||||
component: 'Select', |
||||
defaultValue: 0, |
||||
componentProps: { |
||||
options: getIntDictOptions(DICT_TYPE.COMMON_STATUS) |
||||
} |
||||
}, |
||||
{ |
||||
label: '备注', |
||||
field: 'remark', |
||||
component: 'InputTextArea' |
||||
} |
||||
] |
Reference in new issue