1
1
<template >
2
2
<Dialog v-model =" dialogVisible" :title =" dialogTitle" >
3
- <Form ref =" formRef" v-loading =" formLoading" :rules =" rules" :schema =" allSchemas.formSchema" />
3
+ <el-form
4
+ ref =" formRef"
5
+ v-loading =" formLoading"
6
+ :model =" formData"
7
+ :rules =" formRules"
8
+ label-width =" 150px"
9
+ >
10
+ <el-form-item label =" 邮箱" prop =" mail" >
11
+ <el-input v-model =" formData.mail" placeholder =" 请输入邮箱" />
12
+ </el-form-item >
13
+ <el-form-item label =" 用户名" prop =" username" >
14
+ <el-input v-model =" formData.username" placeholder =" 请输入用户名" />
15
+ </el-form-item >
16
+ <el-form-item label =" 密码" prop =" password" >
17
+ <el-input
18
+ v-model =" formData.password"
19
+ placeholder =" 请输入密码"
20
+ type =" password"
21
+ show-password
22
+ />
23
+ </el-form-item >
24
+ <el-form-item label =" SMTP 服务器域名" prop =" host" >
25
+ <el-input v-model =" formData.host" placeholder =" 请输入 SMTP 服务器域名" />
26
+ </el-form-item >
27
+ <el-form-item label =" SMTP 服务器端口" prop =" port" >
28
+ <el-input-number
29
+ v-model =" formData.port"
30
+ placeholder =" 请输入 SMTP 服务器端口"
31
+ :min =" 1"
32
+ :max =" 65535"
33
+ />
34
+ </el-form-item >
35
+ <el-form-item label =" 是否开启 SSL" >
36
+ <el-radio-group v-model =" formData.sslEnable" >
37
+ <el-radio
38
+ v-for =" dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
39
+ :key =" dict.value"
40
+ :value =" dict.value"
41
+ >
42
+ {{ dict.label }}
43
+ </el-radio >
44
+ </el-radio-group >
45
+ </el-form-item >
46
+ <el-form-item label =" 是否开启 STARTTLS" >
47
+ <el-radio-group v-model =" formData.starttlsEnable" >
48
+ <el-radio
49
+ v-for =" dict in getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)"
50
+ :key =" dict.value"
51
+ :value =" dict.value"
52
+ >
53
+ {{ dict.label }}
54
+ </el-radio >
55
+ </el-radio-group >
56
+ </el-form-item >
57
+ </el-form >
4
58
<template #footer >
5
59
<el-button :disabled =" formLoading" type =" primary" @click =" submitForm" >确 定</el-button >
6
60
<el-button @click =" dialogVisible = false" >取 消</el-button >
7
61
</template >
8
62
</Dialog >
9
63
</template >
10
64
<script lang="ts" setup>
65
+ import { DICT_TYPE , getBoolDictOptions } from ' @/utils/dict'
11
66
import * as MailAccountApi from ' @/api/system/mail/account'
12
- import { allSchemas , rules } from ' ./account.data'
13
67
14
68
defineOptions ({ name: ' SystemMailAccountForm' })
15
69
@@ -20,19 +74,41 @@ const dialogVisible = ref(false) // 弹窗的是否展示
20
74
const dialogTitle = ref (' ' ) // 弹窗的标题
21
75
const formLoading = ref (false ) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
22
76
const formType = ref (' ' ) // 表单的类型:create - 新增;update - 修改
77
+ const formData = ref ({
78
+ id: undefined ,
79
+ mail: ' ' ,
80
+ username: ' ' ,
81
+ password: ' ' ,
82
+ host: ' ' ,
83
+ port: 465 ,
84
+ sslEnable: true ,
85
+ starttlsEnable: false
86
+ })
87
+ const formRules = reactive ({
88
+ mail: [
89
+ { required: true , message: ' 邮箱不能为空' , trigger: ' blur' },
90
+ { type: ' email' , message: ' 请输入正确的邮箱格式' , trigger: [' blur' , ' change' ] }
91
+ ],
92
+ username: [{ required: true , message: ' 用户名不能为空' , trigger: ' blur' }],
93
+ password: [{ required: true , message: ' 密码不能为空' , trigger: ' blur' }],
94
+ host: [{ required: true , message: ' SMTP 服务器域名不能为空' , trigger: ' blur' }],
95
+ port: [{ required: true , message: ' SMTP 服务器端口不能为空' , trigger: ' blur' }],
96
+ sslEnable: [{ required: true , message: ' 是否开启 SSL 不能为空' , trigger: ' blur' }],
97
+ starttlsEnable: [{ required: true , message: ' 是否开启 STARTTLS 不能为空' , trigger: ' blur' }]
98
+ })
23
99
const formRef = ref () // 表单 Ref
24
100
25
101
/** 打开弹窗 */
26
102
const open = async (type : string , id ? : number ) => {
27
103
dialogVisible .value = true
28
104
dialogTitle .value = t (' action.' + type )
29
105
formType .value = type
106
+ resetForm ()
30
107
// 修改时,设置数据
31
108
if (id ) {
32
109
formLoading .value = true
33
110
try {
34
- const data = await MailAccountApi .getMailAccount (id )
35
- formRef .value .setValues (data )
111
+ formData .value = await MailAccountApi .getMailAccount (id )
36
112
} finally {
37
113
formLoading .value = false
38
114
}
@@ -45,12 +121,12 @@ const emit = defineEmits(['success']) // 定义 success 事件,用于操作成
45
121
const submitForm = async () => {
46
122
// 校验表单
47
123
if (! formRef ) return
48
- const valid = await formRef .value .getElFormRef (). validate ()
124
+ const valid = await formRef .value .validate ()
49
125
if (! valid ) return
50
126
// 提交请求
51
127
formLoading .value = true
52
128
try {
53
- const data = formRef .value . formModel as MailAccountApi .MailAccountVO
129
+ const data = formData .value as MailAccountApi .MailAccountVO
54
130
if (formType .value === ' create' ) {
55
131
await MailAccountApi .createMailAccount (data )
56
132
message .success (t (' common.createSuccess' ))
@@ -65,4 +141,19 @@ const submitForm = async () => {
65
141
formLoading .value = false
66
142
}
67
143
}
144
+
145
+ /** 重置表单 */
146
+ const resetForm = () => {
147
+ formData .value = {
148
+ id: undefined ,
149
+ mail: ' ' ,
150
+ username: ' ' ,
151
+ password: ' ' ,
152
+ host: ' ' ,
153
+ port: 465 ,
154
+ sslEnable: true ,
155
+ starttlsEnable: false
156
+ }
157
+ formRef .value ?.resetFields ()
158
+ }
68
159
</script >
0 commit comments