refactor:优化 mail 邮箱的实现
This commit is contained in:
@@ -21,24 +21,36 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||
fieldName: 'mail',
|
||||
label: '邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入邮箱',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'username',
|
||||
label: '用户名',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入用户名',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'password',
|
||||
label: '密码',
|
||||
component: 'InputPassword',
|
||||
componentProps: {
|
||||
placeholder: '请输入密码',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
fieldName: 'host',
|
||||
label: 'SMTP 服务器域名',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入 SMTP 服务器域名',
|
||||
},
|
||||
rules: 'required',
|
||||
},
|
||||
{
|
||||
@@ -46,6 +58,7 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||
label: 'SMTP 服务器端口',
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
placeholder: '请输入 SMTP 服务器端口',
|
||||
min: 0,
|
||||
max: 65_535,
|
||||
},
|
||||
@@ -77,6 +90,9 @@ export function useFormSchema(): VbenFormSchema[] {
|
||||
fieldName: 'remark',
|
||||
label: '备注',
|
||||
component: 'Textarea',
|
||||
componentProps: {
|
||||
placeholder: '请输入备注',
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
@@ -88,25 +104,25 @@ export function useGridFormSchema(): VbenFormSchema[] {
|
||||
fieldName: 'mail',
|
||||
label: '邮箱',
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入邮箱',
|
||||
clearable: true,
|
||||
}
|
||||
},
|
||||
{
|
||||
fieldName: 'username',
|
||||
label: '用户名',
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
fieldName: 'createTime',
|
||||
label: '创建时间',
|
||||
component: 'RangePicker',
|
||||
componentProps: {
|
||||
allowClear: true,
|
||||
},
|
||||
},
|
||||
placeholder: '请输入用户名',
|
||||
clearable: true,
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/** 列表的字段 */
|
||||
export function useGridColumns<T = SystemMailAccountApi.MailAccount>(
|
||||
export function useGridColumns<T = SystemMailAccountApi.SystemMailAccount>(
|
||||
onActionClick: OnActionClickFn<T>,
|
||||
): VxeTableGridOptions['columns'] {
|
||||
return [
|
||||
@@ -118,12 +134,12 @@ export function useGridColumns<T = SystemMailAccountApi.MailAccount>(
|
||||
{
|
||||
field: 'mail',
|
||||
title: '邮箱',
|
||||
minWidth: 120,
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'username',
|
||||
title: '用户名',
|
||||
minWidth: 120,
|
||||
minWidth: 160,
|
||||
},
|
||||
{
|
||||
field: 'host',
|
||||
@@ -133,7 +149,7 @@ export function useGridColumns<T = SystemMailAccountApi.MailAccount>(
|
||||
{
|
||||
field: 'port',
|
||||
title: 'SMTP 服务器端口',
|
||||
minWidth: 120,
|
||||
minWidth: 130,
|
||||
},
|
||||
{
|
||||
field: 'sslEnable',
|
||||
@@ -147,17 +163,12 @@ export function useGridColumns<T = SystemMailAccountApi.MailAccount>(
|
||||
{
|
||||
field: 'starttlsEnable',
|
||||
title: '是否开启 STARTTLS',
|
||||
minWidth: 120,
|
||||
minWidth: 145,
|
||||
cellRender: {
|
||||
name: 'CellDict',
|
||||
props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '备注',
|
||||
minWidth: 120,
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
title: '创建时间',
|
||||
@@ -167,7 +178,7 @@ export function useGridColumns<T = SystemMailAccountApi.MailAccount>(
|
||||
{
|
||||
field: 'operation',
|
||||
title: '操作',
|
||||
minWidth: 220,
|
||||
minWidth: 130,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
cellRender: {
|
||||
@@ -176,15 +187,7 @@ export function useGridColumns<T = SystemMailAccountApi.MailAccount>(
|
||||
nameTitle: '邮箱账号',
|
||||
onClick: onActionClick,
|
||||
},
|
||||
name: 'CellOperation',
|
||||
options: [
|
||||
'edit', // 默认的编辑按钮
|
||||
'delete', // 默认的删除按钮
|
||||
{
|
||||
code: 'test',
|
||||
text: '测试连接',
|
||||
},
|
||||
],
|
||||
name: 'CellOperation'
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
<script lang="ts" setup>
|
||||
import type {
|
||||
OnActionClickParams,
|
||||
VxeTableGridOptions,
|
||||
} from '#/adapter/vxe-table';
|
||||
import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter/vxe-table';
|
||||
import type { SystemMailAccountApi } from '#/api/system/mail/account';
|
||||
|
||||
import { Page, useVbenModal } from '@vben/common-ui';
|
||||
import { Plus } from '@vben/icons';
|
||||
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
deleteMailAccount,
|
||||
getMailAccountPage,
|
||||
testMailAccount,
|
||||
} from '#/api/system/mail/account';
|
||||
import { $t } from '#/locales';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import { deleteMailAccount, getMailAccountPage } from '#/api/system/mail/account';
|
||||
|
||||
import { useGridColumns, useGridFormSchema } from './data';
|
||||
import Form from './modules/form.vue';
|
||||
|
||||
const [FormModal, formModalApi] = useVbenModal({
|
||||
connectedComponent: Form,
|
||||
@@ -37,30 +29,12 @@ function onCreate() {
|
||||
}
|
||||
|
||||
/** 编辑邮箱账号 */
|
||||
function onEdit(row: SystemMailAccountApi.MailAccount) {
|
||||
function onEdit(row: SystemMailAccountApi.SystemMailAccount) {
|
||||
formModalApi.setData(row).open();
|
||||
}
|
||||
|
||||
/** 测试邮箱连接 */
|
||||
async function onTest(row: SystemMailAccountApi.MailAccount) {
|
||||
const hideLoading = message.loading({
|
||||
content: '正在测试邮箱连接...',
|
||||
duration: 0,
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
try {
|
||||
await testMailAccount(row.id as number);
|
||||
message.success({
|
||||
content: '邮箱连接测试成功',
|
||||
key: 'action_process_msg',
|
||||
});
|
||||
} finally {
|
||||
hideLoading();
|
||||
}
|
||||
}
|
||||
|
||||
/** 删除邮箱账号 */
|
||||
async function onDelete(row: SystemMailAccountApi.MailAccount) {
|
||||
async function onDelete(row: SystemMailAccountApi.SystemMailAccount) {
|
||||
const hideLoading = message.loading({
|
||||
content: $t('ui.actionMessage.deleting', [row.mail]),
|
||||
duration: 0,
|
||||
@@ -82,7 +56,7 @@ async function onDelete(row: SystemMailAccountApi.MailAccount) {
|
||||
function onActionClick({
|
||||
code,
|
||||
row,
|
||||
}: OnActionClickParams<SystemMailAccountApi.MailAccount>) {
|
||||
}: OnActionClickParams<SystemMailAccountApi.SystemMailAccount>) {
|
||||
switch (code) {
|
||||
case 'delete': {
|
||||
onDelete(row);
|
||||
@@ -92,10 +66,6 @@ function onActionClick({
|
||||
onEdit(row);
|
||||
break;
|
||||
}
|
||||
case 'test': {
|
||||
onTest(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,7 +95,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
refresh: { code: 'query' },
|
||||
search: true,
|
||||
},
|
||||
} as VxeTableGridOptions<SystemMailAccountApi.MailAccount>,
|
||||
} as VxeTableGridOptions<SystemMailAccountApi.SystemMailAccount>,
|
||||
});
|
||||
</script>
|
||||
<template>
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
<script lang="ts" setup>
|
||||
import type { SystemMailAccountApi } from '#/api/system/mail/account';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import {
|
||||
createMailAccount,
|
||||
getMailAccount,
|
||||
updateMailAccount,
|
||||
} from '#/api/system/mail/account';
|
||||
import { $t } from '#/locales';
|
||||
import { computed, ref } from 'vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createMailAccount, getMailAccount, updateMailAccount,} from '#/api/system/mail/account';
|
||||
|
||||
import { useFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<SystemMailAccountApi.MailAccount>();
|
||||
const formData = ref<SystemMailAccountApi.SystemMailAccount>();
|
||||
const getTitle = computed(() => {
|
||||
return formData.value?.id
|
||||
? $t('ui.actionTitle.edit', ['邮箱账号'])
|
||||
@@ -29,6 +23,9 @@ const [Form, formApi] = useVbenForm({
|
||||
layout: 'horizontal',
|
||||
schema: useFormSchema(),
|
||||
showDefaultActions: false,
|
||||
commonConfig: {
|
||||
labelWidth: 140
|
||||
}
|
||||
});
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
@@ -39,12 +36,9 @@ const [Modal, modalApi] = useVbenModal({
|
||||
}
|
||||
modalApi.lock();
|
||||
// 提交表单
|
||||
const data =
|
||||
(await formApi.getValues()) as SystemMailAccountApi.MailAccount;
|
||||
const data = (await formApi.getValues()) as SystemMailAccountApi.SystemMailAccount;
|
||||
try {
|
||||
await (formData.value?.id
|
||||
? updateMailAccount(data)
|
||||
: createMailAccount(data));
|
||||
await (formData.value?.id ? updateMailAccount(data) : createMailAccount(data));
|
||||
// 关闭并提示
|
||||
await modalApi.close();
|
||||
emit('success');
|
||||
@@ -61,7 +55,7 @@ const [Modal, modalApi] = useVbenModal({
|
||||
return;
|
||||
}
|
||||
// 加载数据
|
||||
const data = modalApi.getData<SystemMailAccountApi.MailAccount>();
|
||||
const data = modalApi.getData<SystemMailAccountApi.SystemMailAccount>();
|
||||
if (!data || !data.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user