3 changed files with 246 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="MailAccountModal"> |
||||||
|
import { ref, computed, unref } from 'vue' |
||||||
|
import { BasicModal, useModalInner } from '@/components/Modal' |
||||||
|
import { BasicForm, useForm } from '@/components/Form' |
||||||
|
import { formSchema } from './account.data' |
||||||
|
import { createMailAccountApi, getMailAccountApi, updateMailAccountApi } from '@/api/system/mail/account' |
||||||
|
|
||||||
|
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 getMailAccountApi(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 updateMailAccountApi(values) |
||||||
|
} else { |
||||||
|
await createMailAccountApi(values) |
||||||
|
} |
||||||
|
closeModal() |
||||||
|
emit('success') |
||||||
|
} finally { |
||||||
|
setModalProps({ confirmLoading: false }) |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
@ -0,0 +1,109 @@ |
|||||||
|
import { BasicColumn, FormSchema, useRender } from '@/components/Table' |
||||||
|
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
||||||
|
|
||||||
|
export const columns: BasicColumn[] = [ |
||||||
|
{ |
||||||
|
title: '编号', |
||||||
|
dataIndex: 'id', |
||||||
|
width: 100 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '邮箱', |
||||||
|
dataIndex: 'mail', |
||||||
|
width: 180 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '用户名', |
||||||
|
dataIndex: 'username', |
||||||
|
width: 100 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: 'SMTP 服务器域名', |
||||||
|
dataIndex: 'host', |
||||||
|
width: 120 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: 'SMTP 服务器端口', |
||||||
|
dataIndex: 'port', |
||||||
|
width: 120 |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '是否开启 SSL', |
||||||
|
dataIndex: 'sslEnable', |
||||||
|
width: 180, |
||||||
|
customRender: ({ text }) => { |
||||||
|
return useRender.renderDict(text, DICT_TYPE.INFRA_BOOLEAN_STRING) |
||||||
|
} |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '创建时间', |
||||||
|
dataIndex: 'createTime', |
||||||
|
width: 180, |
||||||
|
customRender: ({ text }) => { |
||||||
|
return useRender.renderDate(text) |
||||||
|
} |
||||||
|
} |
||||||
|
] |
||||||
|
|
||||||
|
export const searchFormSchema: FormSchema[] = [ |
||||||
|
{ |
||||||
|
label: '邮箱', |
||||||
|
field: 'mail', |
||||||
|
component: 'Input', |
||||||
|
colProps: { span: 8 } |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '用户名', |
||||||
|
field: 'username', |
||||||
|
component: 'Input', |
||||||
|
colProps: { span: 8 } |
||||||
|
} |
||||||
|
] |
||||||
|
|
||||||
|
export const formSchema: FormSchema[] = [ |
||||||
|
{ |
||||||
|
label: '编号', |
||||||
|
field: 'id', |
||||||
|
show: false, |
||||||
|
component: 'Input' |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '邮箱', |
||||||
|
field: 'mail', |
||||||
|
required: true, |
||||||
|
component: 'Input' |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '用户名', |
||||||
|
field: 'username', |
||||||
|
required: true, |
||||||
|
component: 'Input' |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '密码', |
||||||
|
field: 'password', |
||||||
|
required: true, |
||||||
|
component: 'InputPassword' |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: 'SMTP 服务器域名', |
||||||
|
field: 'host', |
||||||
|
required: true, |
||||||
|
component: 'Input' |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: 'SMTP 服务器端口', |
||||||
|
field: 'port', |
||||||
|
required: true, |
||||||
|
component: 'Input' |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '是否开启 SSL', |
||||||
|
field: 'sslEnable', |
||||||
|
component: 'Select', |
||||||
|
defaultValue: 0, |
||||||
|
componentProps: { |
||||||
|
options: getIntDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING) |
||||||
|
} |
||||||
|
} |
||||||
|
] |
@ -1,3 +1,81 @@ |
|||||||
<template> |
<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> |
||||||
|
<AccountModel @register="registerModal" @success="reload()" /> |
||||||
|
</div> |
||||||
</template> |
</template> |
||||||
|
<script lang="ts" setup name="MailAccount"> |
||||||
|
import { BasicTable, useTable, TableAction } from '@/components/Table' |
||||||
|
import { deleteMailAccountApi, getMailAccountPageApi } from '@/api/system/mail/account' |
||||||
|
import { useModal } from '@/components/Modal' |
||||||
|
import AccountModel from './AccountModel.vue' |
||||||
|
import { columns, searchFormSchema } from './account.data' |
||||||
|
import { useMessage } from '@/hooks/web/useMessage' |
||||||
|
|
||||||
|
const { createMessage } = useMessage() |
||||||
|
const [registerModal, { openModal }] = useModal() |
||||||
|
const [registerTable, { reload }] = useTable({ |
||||||
|
title: '邮件列表', |
||||||
|
api: getMailAccountPageApi, |
||||||
|
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 deleteMailAccountApi(record.id) |
||||||
|
createMessage.success('删除成功') |
||||||
|
reload() |
||||||
|
} |
||||||
|
</script> |
||||||
|
Reference in new issue