Skip to content

Commit e3660e0

Browse files
committed
REVIEW 站内信模版的发送
1 parent 97f9560 commit e3660e0

File tree

4 files changed

+152
-128
lines changed

4 files changed

+152
-128
lines changed
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,40 @@
11
import request from '@/config/axios'
22

33
export interface NotifyTemplateVO {
4-
id: number | null
4+
id?: number
55
name: string
66
nickname: string
77
code: string
88
content: string
9-
type: number | null
9+
type: number
1010
params: string
11-
status: number | null
11+
status: number
1212
remark: string
1313
}
1414

15-
export interface NotifyTemplatePageReqVO extends PageParam {
16-
name?: string
17-
code?: string
18-
status?: number
19-
createTime?: Date[]
20-
}
21-
2215
export interface NotifySendReqVO {
2316
userId: number | null
2417
templateCode: string
2518
templateParams: Map<String, Object>
2619
}
2720

2821
// 查询站内信模板列表
29-
export const getNotifyTemplatePageApi = async (params: NotifyTemplatePageReqVO) => {
22+
export const getNotifyTemplatePage = async (params: PageParam) => {
3023
return await request.get({ url: '/system/notify-template/page', params })
3124
}
3225

3326
// 查询站内信模板详情
34-
export const getNotifyTemplateApi = async (id: number) => {
27+
export const getNotifyTemplate = async (id: number) => {
3528
return await request.get({ url: '/system/notify-template/get?id=' + id })
3629
}
3730

3831
// 新增站内信模板
39-
export const createNotifyTemplateApi = async (data: NotifyTemplateVO) => {
32+
export const createNotifyTemplate = async (data: NotifyTemplateVO) => {
4033
return await request.post({ url: '/system/notify-template/create', data })
4134
}
4235

4336
// 修改站内信模板
44-
export const updateNotifyTemplateApi = async (data: NotifyTemplateVO) => {
37+
export const updateNotifyTemplate = async (data: NotifyTemplateVO) => {
4538
return await request.put({ url: '/system/notify-template/update', data })
4639
}
4740

@@ -51,6 +44,6 @@ export const deleteNotifyTemplateApi = async (id: number) => {
5144
}
5245

5346
// 发送站内信
54-
export const sendNotifyApi = (data: NotifySendReqVO) => {
47+
export const sendNotify = (data: NotifySendReqVO) => {
5548
return request.post({ url: '/system/notify-template/send-notify', data })
5649
}

src/views/system/notify/template/NotifyTemplateForm.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_NOTIFY_TEMPLATE_TYPE)"
2626
:key="dict.value"
2727
:label="dict.label"
28-
:value="parseInt(dict.value)"
28+
:value="dict.value"
2929
/>
3030
</el-select>
3131
</el-form-item>
@@ -34,7 +34,7 @@
3434
<el-radio
3535
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
3636
:key="dict.value"
37-
:label="parseInt(dict.value as string)"
37+
:label="dict.value as string"
3838
>
3939
{{ dict.label }}
4040
</el-radio>
@@ -81,6 +81,7 @@ const formRules = reactive({
8181
})
8282
const formRef = ref() // 表单 Ref
8383
84+
/** 打开弹窗 */
8485
const open = async (type: string, id?: number) => {
8586
dialogVisible.value = true
8687
dialogTitle.value = type
@@ -90,7 +91,7 @@ const open = async (type: string, id?: number) => {
9091
if (id) {
9192
formLoading.value = true
9293
try {
93-
formData.value = await NotifyTemplateApi.getNotifyTemplateApi(id)
94+
formData.value = await NotifyTemplateApi.getNotifyTemplate(id)
9495
} finally {
9596
formLoading.value = false
9697
}
@@ -107,12 +108,12 @@ const submitForm = async () => {
107108
if (!valid) return
108109
formLoading.value = true
109110
try {
110-
const data = formData.value as NotifyTemplateApi.NotifyTemplateVO
111+
const data = formData.value as unknown as NotifyTemplateApi.NotifyTemplateVO
111112
if (formType.value === 'create') {
112-
await NotifyTemplateApi.createNotifyTemplateApi(data)
113+
await NotifyTemplateApi.createNotifyTemplate(data)
113114
message.success('新增成功')
114115
} else {
115-
await NotifyTemplateApi.updateNotifyTemplateApi(data)
116+
await NotifyTemplateApi.updateNotifyTemplate(data)
116117
message.success('修改成功')
117118
}
118119
dialogVisible.value = false
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<template>
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="userId">
19+
<el-select v-model="formData.userId" placeholder="请选择接收人">
20+
<el-option
21+
v-for="item in userOption"
22+
:key="item.id"
23+
:label="item.nickname"
24+
:value="item.id"
25+
/>
26+
</el-select>
27+
</el-form-item>
28+
<el-form-item
29+
v-for="param in formData.params"
30+
:key="param"
31+
:label="'参数 {' + param + '}'"
32+
:prop="'templateParams.' + param"
33+
>
34+
<el-input
35+
v-model="formData.templateParams[param]"
36+
:placeholder="'请输入 ' + param + ' 参数'"
37+
/>
38+
</el-form-item>
39+
</el-form>
40+
<template #footer>
41+
<el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
42+
<el-button @click="dialogVisible = false">取 消</el-button>
43+
</template>
44+
</Dialog>
45+
</template>
46+
<script lang="ts" name="SystemNotifyTemplateSendForm" setup>
47+
import * as SmsTemplateApi from '@/api/system/sms/smsTemplate'
48+
import * as UserApi from '@/api/system/user'
49+
import * as NotifyTemplateApi from '@/api/system/notify/template'
50+
const message = useMessage() // 消息弹窗
51+
52+
const dialogVisible = ref(false) // 弹窗的是否展示
53+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
54+
const formData = ref({
55+
content: '',
56+
params: {},
57+
userId: null,
58+
templateCode: '',
59+
templateParams: new Map()
60+
})
61+
const formRules = reactive({
62+
userId: [{ required: true, message: '用户编号不能为空', trigger: 'change' }],
63+
templateCode: [{ required: true, message: '模版编号不能为空', trigger: 'blur' }],
64+
templateParams: {}
65+
})
66+
const formRef = ref() // 表单 Ref
67+
const userOption = ref<UserApi.UserVO[]>([])
68+
69+
const open = async (id: number) => {
70+
dialogVisible.value = true
71+
resetForm()
72+
// 设置数据
73+
formLoading.value = true
74+
try {
75+
const data = await NotifyTemplateApi.getNotifyTemplate(id)
76+
// 设置动态表单
77+
formData.value.content = data.content
78+
formData.value.params = data.params
79+
formData.value.templateCode = data.code
80+
formData.value.templateParams = data.params.reduce((obj, item) => {
81+
obj[item] = '' // 给每个动态属性赋值,避免无法读取
82+
return obj
83+
}, {})
84+
formRules.templateParams = data.params.reduce((obj, item) => {
85+
obj[item] = { required: true, message: '参数 ' + item + ' 不能为空', trigger: 'blur' }
86+
return obj
87+
}, {})
88+
} finally {
89+
formLoading.value = false
90+
}
91+
// 加载用户列表
92+
userOption.value = await UserApi.getSimpleUserList()
93+
}
94+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
95+
96+
/** 提交表单 */
97+
const submitForm = async () => {
98+
// 校验表单
99+
if (!formRef) return
100+
const valid = await formRef.value.validate()
101+
if (!valid) return
102+
// 提交请求
103+
formLoading.value = true
104+
try {
105+
const data = formData.value as SmsTemplateApi.SendSmsReqVO
106+
const logId = await SmsTemplateApi.sendSms(data)
107+
if (logId) {
108+
message.success('提交发送成功!发送结果,见发送日志编号:' + logId)
109+
}
110+
dialogVisible.value = false
111+
} finally {
112+
formLoading.value = false
113+
}
114+
}
115+
116+
/** 重置表单 */
117+
const resetForm = () => {
118+
formData.value = {
119+
content: '',
120+
params: {},
121+
mobile: '',
122+
templateCode: '',
123+
templateParams: new Map()
124+
}
125+
formRef.value?.resetFields()
126+
}
127+
</script>

0 commit comments

Comments
 (0)