提交 | 用户 | 时间
|
314507
|
1 |
<template> |
H |
2 |
<Dialog v-model="dialogVisible" :title="dialogTitle"> |
|
3 |
<Form ref="formRef" v-loading="formLoading" :rules="rules" :schema="allSchemas.formSchema" /> |
|
4 |
<template #footer> |
|
5 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
6 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
7 |
</template> |
|
8 |
</Dialog> |
|
9 |
</template> |
|
10 |
<script lang="ts" setup> |
|
11 |
import * as MailAccountApi from '@/api/system/mail/account' |
|
12 |
import { allSchemas, rules } from './account.data' |
|
13 |
|
|
14 |
defineOptions({ name: 'SystemMailAccountForm' }) |
|
15 |
|
|
16 |
const { t } = useI18n() // 国际化 |
|
17 |
const message = useMessage() // 消息弹窗 |
|
18 |
|
|
19 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
20 |
const dialogTitle = ref('') // 弹窗的标题 |
|
21 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
22 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
23 |
const formRef = ref() // 表单 Ref |
|
24 |
|
|
25 |
/** 打开弹窗 */ |
|
26 |
const open = async (type: string, id?: number) => { |
|
27 |
dialogVisible.value = true |
|
28 |
dialogTitle.value = t('action.' + type) |
|
29 |
formType.value = type |
|
30 |
// 修改时,设置数据 |
|
31 |
if (id) { |
|
32 |
formLoading.value = true |
|
33 |
try { |
|
34 |
const data = await MailAccountApi.getMailAccount(id) |
|
35 |
formRef.value.setValues(data) |
|
36 |
} finally { |
|
37 |
formLoading.value = false |
|
38 |
} |
|
39 |
} |
|
40 |
} |
|
41 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
42 |
|
|
43 |
/** 提交表单 */ |
|
44 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
45 |
const submitForm = async () => { |
|
46 |
// 校验表单 |
|
47 |
if (!formRef) return |
|
48 |
const valid = await formRef.value.getElFormRef().validate() |
|
49 |
if (!valid) return |
|
50 |
// 提交请求 |
|
51 |
formLoading.value = true |
|
52 |
try { |
|
53 |
const data = formRef.value.formModel as MailAccountApi.MailAccountVO |
|
54 |
if (formType.value === 'create') { |
|
55 |
await MailAccountApi.createMailAccount(data) |
|
56 |
message.success(t('common.createSuccess')) |
|
57 |
} else { |
|
58 |
await MailAccountApi.updateMailAccount(data) |
|
59 |
message.success(t('common.updateSuccess')) |
|
60 |
} |
|
61 |
dialogVisible.value = false |
|
62 |
// 发送操作成功的事件 |
|
63 |
emit('success') |
|
64 |
} finally { |
|
65 |
formLoading.value = false |
|
66 |
} |
|
67 |
} |
|
68 |
</script> |