提交 | 用户 | 时间
|
314507
|
1 |
<template> |
H |
2 |
<Dialog v-model="dialogVisible" title="测试发送" :max-height="500"> |
|
3 |
<el-form |
|
4 |
ref="formRef" |
|
5 |
v-loading="formLoading" |
|
6 |
:model="formData" |
|
7 |
:rules="formRules" |
|
8 |
label-width="140px" |
|
9 |
> |
|
10 |
<el-form-item label="模板内容" prop="content"> |
|
11 |
<el-input |
|
12 |
v-model="formData.content" |
|
13 |
placeholder="请输入模板内容" |
|
14 |
readonly |
|
15 |
type="textarea" |
|
16 |
/> |
|
17 |
</el-form-item> |
|
18 |
<el-form-item label="用户类型" prop="userType"> |
|
19 |
<el-radio-group v-model="formData.userType"> |
|
20 |
<el-radio |
|
21 |
v-for="dict in getIntDictOptions(DICT_TYPE.USER_TYPE)" |
|
22 |
:key="dict.value" |
|
23 |
:label="dict.value" |
|
24 |
> |
|
25 |
{{ dict.label }} |
|
26 |
</el-radio> |
|
27 |
</el-radio-group> |
|
28 |
</el-form-item> |
|
29 |
<el-form-item v-show="formData.userType === 1" label="接收人ID" prop="userId"> |
|
30 |
<el-input v-model="formData.userId" style="width: 160px" /> |
|
31 |
</el-form-item> |
|
32 |
<el-form-item v-show="formData.userType === 2" label="接收人" prop="userId"> |
|
33 |
<el-select v-model="formData.userId" placeholder="请选择接收人"> |
|
34 |
<el-option |
|
35 |
v-for="item in userOption" |
|
36 |
:key="item.id" |
|
37 |
:label="item.nickname" |
|
38 |
:value="item.id" |
|
39 |
/> |
|
40 |
</el-select> |
|
41 |
</el-form-item> |
|
42 |
<el-form-item |
|
43 |
v-for="param in formData.params" |
|
44 |
:key="param" |
|
45 |
:label="'参数 {' + param + '}'" |
|
46 |
:prop="'templateParams.' + param" |
|
47 |
> |
|
48 |
<el-input |
|
49 |
v-model="formData.templateParams[param]" |
|
50 |
:placeholder="'请输入 ' + param + ' 参数'" |
|
51 |
/> |
|
52 |
</el-form-item> |
|
53 |
</el-form> |
|
54 |
<template #footer> |
|
55 |
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button> |
|
56 |
<el-button @click="dialogVisible = false">取 消</el-button> |
|
57 |
</template> |
|
58 |
</Dialog> |
|
59 |
</template> |
|
60 |
<script lang="ts" setup> |
|
61 |
import * as UserApi from '@/api/system/user' |
|
62 |
import * as NotifyTemplateApi from '@/api/system/notify/template' |
|
63 |
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' |
|
64 |
|
|
65 |
defineOptions({ name: 'SystemNotifyTemplateSendForm' }) |
|
66 |
|
|
67 |
const message = useMessage() // 消息弹窗 |
|
68 |
|
|
69 |
const dialogVisible = ref(false) // 弹窗的是否展示 |
|
70 |
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 |
|
71 |
const formData = ref({ |
|
72 |
content: '', |
|
73 |
params: {}, |
|
74 |
userId: undefined, |
|
75 |
userType: 1, |
|
76 |
templateCode: '', |
|
77 |
templateParams: new Map() |
|
78 |
}) |
|
79 |
const formRules = reactive({ |
|
80 |
userId: [{ required: true, message: '用户编号不能为空', trigger: 'change' }], |
|
81 |
templateCode: [{ required: true, message: '模版编号不能为空', trigger: 'blur' }], |
|
82 |
templateParams: {} |
|
83 |
}) |
|
84 |
const formRef = ref() // 表单 Ref |
|
85 |
const userOption = ref<UserApi.UserVO[]>([]) |
|
86 |
|
|
87 |
const open = async (id: number) => { |
|
88 |
dialogVisible.value = true |
|
89 |
resetForm() |
|
90 |
// 设置数据 |
|
91 |
formLoading.value = true |
|
92 |
try { |
|
93 |
const data = await NotifyTemplateApi.getNotifyTemplate(id) |
|
94 |
// 设置动态表单 |
|
95 |
formData.value.content = data.content |
|
96 |
formData.value.params = data.params |
|
97 |
formData.value.templateCode = data.code |
|
98 |
formData.value.templateParams = data.params.reduce((obj, item) => { |
|
99 |
obj[item] = '' // 给每个动态属性赋值,避免无法读取 |
|
100 |
return obj |
|
101 |
}, {}) |
|
102 |
formRules.templateParams = data.params.reduce((obj, item) => { |
|
103 |
obj[item] = { required: true, message: '参数 ' + item + ' 不能为空', trigger: 'blur' } |
|
104 |
return obj |
|
105 |
}, {}) |
|
106 |
} finally { |
|
107 |
formLoading.value = false |
|
108 |
} |
|
109 |
// 加载用户列表 |
|
110 |
userOption.value = await UserApi.getSimpleUserList() |
|
111 |
} |
|
112 |
defineExpose({ open }) // 提供 open 方法,用于打开弹窗 |
|
113 |
|
|
114 |
/** 提交表单 */ |
|
115 |
const submitForm = async () => { |
|
116 |
// 校验表单 |
|
117 |
if (!formRef) return |
|
118 |
const valid = await formRef.value.validate() |
|
119 |
if (!valid) return |
|
120 |
// 提交请求 |
|
121 |
formLoading.value = true |
|
122 |
try { |
|
123 |
const data = formData.value as unknown as NotifyTemplateApi.NotifySendReqVO |
|
124 |
const logId = await NotifyTemplateApi.sendNotify(data) |
|
125 |
if (logId) { |
|
126 |
message.success('提交发送成功!发送结果,见发送日志编号:' + logId) |
|
127 |
} |
|
128 |
dialogVisible.value = false |
|
129 |
} finally { |
|
130 |
formLoading.value = false |
|
131 |
} |
|
132 |
} |
|
133 |
|
|
134 |
/** 重置表单 */ |
|
135 |
const resetForm = () => { |
|
136 |
formData.value = { |
|
137 |
content: '', |
|
138 |
params: {}, |
|
139 |
mobile: '', |
|
140 |
templateCode: '', |
|
141 |
templateParams: new Map(), |
|
142 |
userType: 1 |
|
143 |
} as any |
|
144 |
formRef.value?.resetFields() |
|
145 |
} |
|
146 |
</script> |