53
53
@on-delete =" onDelete"
54
54
/>
55
55
56
- <!-- 添加或修改自动回复的对话框 -->
57
- <!-- TODO @Dhb52 -->
58
- <el-dialog :title =" dialogTitle" v-model =" showFormDialog" width =" 800px" destroy-on-close >
59
- <el-form ref =" formRef" :model =" replyForm" :rules =" rules" label-width =" 80px" >
60
- <el-form-item label =" 消息类型" prop =" requestMessageType" v-if =" msgType === MsgType.Message" >
61
- <el-select v-model =" replyForm.requestMessageType" placeholder =" 请选择" >
62
- <template v-for =" dict in getDictOptions (DICT_TYPE .MP_MESSAGE_TYPE )" :key =" dict .value " >
63
- <el-option
64
- v-if =" RequestMessageTypes.includes(dict.value)"
65
- :label =" dict.label"
66
- :value =" dict.value"
67
- />
68
- </template >
69
- </el-select >
70
- </el-form-item >
71
- <el-form-item label =" 匹配类型" prop =" requestMatch" v-if =" msgType === MsgType.Keyword" >
72
- <el-select v-model =" replyForm.requestMatch" placeholder =" 请选择匹配类型" clearable >
73
- <el-option
74
- v-for =" dict in getIntDictOptions(DICT_TYPE.MP_AUTO_REPLY_REQUEST_MATCH)"
75
- :key =" dict.value"
76
- :label =" dict.label"
77
- :value =" dict.value"
78
- />
79
- </el-select >
80
- </el-form-item >
81
- <el-form-item label =" 关键词" prop =" requestKeyword" v-if =" msgType === MsgType.Keyword" >
82
- <el-input v-model =" replyForm.requestKeyword" placeholder =" 请输入内容" clearable />
83
- </el-form-item >
84
- <el-form-item label =" 回复消息" >
85
- <WxReplySelect v-model =" reply" />
86
- </el-form-item >
87
- </el-form >
56
+ <el-dialog
57
+ :title =" isCreating ? '新增自动回复' : '修改自动回复'"
58
+ v-model =" showDialog"
59
+ width =" 800px"
60
+ destroy-on-close
61
+ >
62
+ <ReplyForm v-model =" replyForm" v-model:reply =" reply" :msg-type =" msgType" ref =" formRef" />
88
63
<template #footer >
89
64
<el-button @click =" cancel" >取 消</el-button >
90
65
<el-button type =" primary" @click =" onSubmit" >确 定</el-button >
93
68
</ContentWrap >
94
69
</template >
95
70
<script setup lang="ts" name="MpAutoReply">
96
- import WxReplySelect , { type Reply , ReplyType } from ' @/views/mp/components/wx-reply'
71
+ import ReplyForm from ' @/views/mp/autoReply/components/ReplyForm.vue'
72
+ import { type Reply , ReplyType } from ' @/views/mp/components/wx-reply'
97
73
import WxAccountSelect from ' @/views/mp/components/wx-account-select'
98
74
import * as MpAutoReplyApi from ' @/api/mp/autoReply'
99
- import { DICT_TYPE , getDictOptions , getIntDictOptions } from ' @/utils/dict'
100
75
import { ContentWrap } from ' @/components/ContentWrap'
101
- import type { FormInstance , TabPaneName } from ' element-plus'
76
+ import type { TabPaneName } from ' element-plus'
102
77
import ReplyTable from ' ./components/ReplyTable.vue'
103
78
import { MsgType } from ' ./components/types'
104
79
const message = useMessage () // 消息
105
80
106
81
const accountId = ref (- 1 ) // 公众号ID
107
82
const msgType = ref <MsgType >(MsgType .Keyword ) // 消息类型
108
- const RequestMessageTypes = [' text' , ' image' , ' voice' , ' video' , ' shortvideo' , ' location' , ' link' ] // 允许选择的请求消息类型
109
83
const loading = ref (true ) // 遮罩层
110
84
const total = ref (0 ) // 总条数
111
85
const list = ref <any []>([]) // 自动回复列表
112
- const formRef = ref <FormInstance | null >(null ) // 表单 ref
86
+ const formRef = ref <InstanceType < typeof ReplyForm > | null >(null ) // 表单 ref
113
87
// 查询参数
114
88
const queryParams = reactive ({
115
89
pageNo: 1 ,
116
90
pageSize: 10 ,
117
91
accountId: accountId
118
92
})
119
93
120
- const dialogTitle = ref (' ' ) // 弹出层标题
121
- const showFormDialog = ref (false ) // 是否显示弹出层
94
+ const isCreating = ref (false ) // 是否新建(否则编辑)
95
+ const showDialog = ref (false ) // 是否显示弹出层
122
96
const replyForm = ref <any >({}) // 表单参数
123
97
// 回复消息
124
98
const reply = ref <Reply >({
125
99
type: ReplyType .Text ,
126
100
accountId: - 1
127
101
})
128
- // 表单校验
129
- const rules = {
130
- requestKeyword: [{ required: true , message: ' 请求的关键字不能为空' , trigger: ' blur' }],
131
- requestMatch: [{ required: true , message: ' 请求的关键字的匹配不能为空' , trigger: ' blur' }]
132
- }
133
102
134
103
/** 侦听账号变化 */
135
104
const onAccountChanged = (id : number ) => {
@@ -174,8 +143,8 @@ const onCreate = () => {
174
143
accountId: queryParams .accountId
175
144
}
176
145
177
- dialogTitle .value = ' 新增自动回复 '
178
- showFormDialog .value = true
146
+ isCreating .value = true
147
+ showDialog .value = true
179
148
}
180
149
181
150
/** 修改按钮操作 */
@@ -207,8 +176,8 @@ const onUpdate = async (id: number) => {
207
176
}
208
177
209
178
// 打开表单
210
- dialogTitle .value = ' 修改自动回复 '
211
- showFormDialog .value = true
179
+ isCreating .value = false
180
+ showDialog .value = true
212
181
}
213
182
214
183
/** 删除按钮操作 */
@@ -220,8 +189,7 @@ const onDelete = async (id: number) => {
220
189
}
221
190
222
191
const onSubmit = async () => {
223
- const valid = await formRef .value ?.validate ()
224
- if (! valid ) return
192
+ await formRef .value ?.validate ()
225
193
226
194
// 处理回复消息
227
195
const submitForm: any = { ... replyForm .value }
@@ -245,7 +213,7 @@ const onSubmit = async () => {
245
213
message .success (' 新增成功' )
246
214
}
247
215
248
- showFormDialog .value = false
216
+ showDialog .value = false
249
217
await getList ()
250
218
}
251
219
@@ -264,7 +232,7 @@ const reset = () => {
264
232
265
233
// 取消按钮
266
234
const cancel = () => {
267
- showFormDialog .value = false
235
+ showDialog .value = false
268
236
reset ()
269
237
}
270
238
</script >
0 commit comments