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