提交 | 用户 | 时间
|
820397
|
1 |
<template> |
H |
2 |
<Dialog v-model="dialogVisible" :title="dialogTitle"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="130px" |
|
9 |
> |
|
10 |
<el-form-item label="短信签名" prop="signature"> |
|
11 |
<el-input v-model="formData.signature" placeholder="请输入短信签名" /> |
|
12 |
</el-form-item> |
|
13 |
<el-form-item label="渠道编码" prop="code"> |
|
14 |
<el-select v-model="formData.code" clearable placeholder="请选择渠道编码"> |
|
15 |
<el-option |
|
16 |
v-for="dict in getStrDictOptions(DICT_TYPE.SYSTEM_SMS_CHANNEL_CODE)" |
|
17 |
:key="dict.value" |
|
18 |
:label="dict.label" |
|
19 |
:value="dict.value" |
|
20 |
/> |
|
21 |
</el-select> |
|
22 |
</el-form-item> |
|
23 |
<el-form-item label="启用状态"> |
|
24 |
<el-radio-group v-model="formData.status"> |
|
25 |
<el-radio |
|
26 |
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)" |
|
27 |
:key="dict.value" |
|
28 |
:label="dict.value" |
|
29 |
> |
|
30 |
{{ dict.label }} |
|
31 |
</el-radio> |
|
32 |
</el-radio-group> |
|
33 |
</el-form-item> |
|
34 |
<el-form-item label="备注" prop="remark"> |
|
35 |
<el-input v-model="formData.remark" placeholder="请输入备注" /> |
|
36 |
</el-form-item> |
|
37 |
<el-form-item label="短信 API 的账号" prop="apiKey"> |
|
38 |
<el-input v-model="formData.apiKey" placeholder="请输入短信 API 的账号" /> |
|
39 |
</el-form-item> |
|
40 |
<el-form-item label="短信 API 的密钥" prop="apiSecret"> |
|
41 |
<el-input v-model="formData.apiSecret" placeholder="请输入短信 API 的密钥" /> |
|
42 |
</el-form-item> |
|
43 |
<el-form-item label="短信发送回调 URL" prop="callbackUrl"> |
|
44 |
<el-input v-model="formData.callbackUrl" placeholder="请输入短信发送回调 URL" /> |
|
45 |
</el-form-item> |
|
46 |
</el-form> |
|
47 |
<template #footer> |
|
48 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
49 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
50 |
</template> |
|
51 |
</Dialog> |
|
52 |
</template> |
|
53 |
<script lang="ts" setup> |
|
54 |
import { DICT_TYPE, getIntDictOptions, getStrDictOptions } from '@/utils/dict' |
|
55 |
import * as SmsChannelApi from '@/api/system/sms/smsChannel' |
|
56 |
import { CommonStatusEnum } from '@/utils/constants' |
|
57 |
|
|
58 |
defineOptions({ name: 'SystemSmsChannelForm' }) |
|
59 |
|
|
60 |
const { t } = useI18n() // 国际化 |
|
61 |
const message = useMessage() // 消息弹窗 |
|
62 |
|
|
63 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
64 |
const dialogTitle = ref('') // 弹窗的标题 |
|
65 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
66 |
const formType = ref('') // 表单的类型:create - 新增;update - 修改 |
|
67 |
const formData = ref({ |
|
68 |
id: undefined, |
|
69 |
signature: '', |
|
70 |
code: '', |
|
71 |
status: CommonStatusEnum.ENABLE, |
|
72 |
remark: '', |
|
73 |
apiKey: '', |
|
74 |
apiSecret: '', |
|
75 |
callbackUrl: '' |
|
76 |
}) |
|
77 |
const formRules = reactive({ |
|
78 |
signature: [{ required: true, message: '短信签名不能为空', trigger: 'blur' }], |
|
79 |
code: [{ required: true, message: '渠道编码不能为空', trigger: 'blur' }], |
|
80 |
status: [{ required: true, message: '启用状态不能为空', trigger: 'blur' }], |
|
81 |
apiKey: [{ required: true, message: '短信 API 的账号不能为空', trigger: 'blur' }] |
|
82 |
}) |
|
83 |
const formRef = ref() // 表单 Ref |
|
84 |
|
|
85 |
/** 打开弹窗 */ |
|
86 |
const open = async (type: string, id?: number) => { |
|
87 |
dialogVisible.value = true |
|
88 |
dialogTitle.value = t('action.' + type) |
|
89 |
formType.value = type |
|
90 |
resetForm() |
|
91 |
// 修改时,设置数据 |
|
92 |
if (id) { |
|
93 |
formLoading.value = true |
|
94 |
try { |
|
95 |
formData.value = await SmsChannelApi.getSmsChannel(id) |
|
96 |
console.log(formData) |
|
97 |
} finally { |
|
98 |
formLoading.value = false |
|
99 |
} |
|
100 |
} |
|
101 |
} |
|
102 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
103 |
|
|
104 |
/** 提交表单 */ |
|
105 |
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 |
|
106 |
const submitForm = async () => { |
|
107 |
// 校验表单 |
|
108 |
if (!formRef) return |
|
109 |
const valid = await formRef.value.validate() |
|
110 |
if (!valid) return |
|
111 |
// 提交请求 |
|
112 |
formLoading.value = true |
|
113 |
try { |
|
114 |
const data = formData.value as unknown as SmsChannelApi.SmsChannelVO |
|
115 |
if (formType.value === 'create') { |
|
116 |
await SmsChannelApi.createSmsChannel(data) |
|
117 |
message.success(t('common.createSuccess')) |
|
118 |
} else { |
|
119 |
await SmsChannelApi.updateSmsChannel(data) |
|
120 |
message.success(t('common.updateSuccess')) |
|
121 |
} |
|
122 |
dialogVisible.value = false |
|
123 |
// 发送操作成功的事件 |
|
124 |
emit('success') |
|
125 |
} finally { |
|
126 |
formLoading.value = false |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
/** 重置表单 */ |
|
131 |
const resetForm = () => { |
|
132 |
formData.value = { |
|
133 |
id: undefined, |
|
134 |
signature: '', |
|
135 |
code: '', |
|
136 |
status: CommonStatusEnum.ENABLE, |
|
137 |
remark: '', |
|
138 |
apiKey: '', |
|
139 |
apiSecret: '', |
|
140 |
callbackUrl: '' |
|
141 |
} |
|
142 |
formRef.value?.resetFields() |
|
143 |
} |
|
144 |
</script> |