Skip to content

Commit 92da7e3

Browse files
committed
fix: 使用ElDialog:destroy-on-close属性解决对话框重新加载
1 parent 813e7d2 commit 92da7e3

File tree

2 files changed

+7
-20
lines changed

2 files changed

+7
-20
lines changed

src/views/mp/autoReply/index.vue

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
</el-table>
141141

142142
<!-- 添加或修改自动回复的对话框 -->
143-
<el-dialog :title="title" v-model="showReplyFormDialog" width="800px" append-to-body>
143+
<el-dialog :title="title" v-model="showReplyFormDialog" width="800px" destroy-on-close>
144144
<el-form ref="formRef" :model="replyForm" :rules="rules" label-width="80px">
145145
<el-form-item label="消息类型" prop="requestMessageType" v-if="msgType === MsgType.Message">
146146
<el-select v-model="replyForm.requestMessageType" placeholder="请选择">
@@ -167,7 +167,7 @@
167167
<el-input v-model="replyForm.requestKeyword" placeholder="请输入内容" clearable />
168168
</el-form-item>
169169
<el-form-item label="回复消息">
170-
<WxReplySelect :objData="objData" v-if="hackResetWxReplySelect" />
170+
<WxReplySelect :objData="objData" />
171171
</el-form-item>
172172
</el-form>
173173
<template #footer>
@@ -195,7 +195,7 @@ const message = useMessage()
195195
const formRef = ref()
196196
197197
// 消息类型(Follow: 关注时回复;Message: 消息回复;Keyword: 关键词回复)
198-
// 作为tab.name
198+
// 作为tab.name,enum的数字不能随意修改,与api参数相关
199199
enum MsgType {
200200
Follow = 1,
201201
Message = 2,
@@ -277,9 +277,6 @@ const rules = {
277277
requestMatch: [{ required: true, message: '请求的关键字的匹配不能为空', trigger: 'blur' }]
278278
}
279279
280-
// 重置 WxReplySelect 组件,解决无法清除的问题
281-
const hackResetWxReplySelect = ref(false)
282-
283280
const onAccountChanged = (id?: number) => {
284281
queryParams.accountId = id
285282
getList()
@@ -314,7 +311,6 @@ const handleTabChange = (tabName: TabPaneName) => {
314311
/** 新增按钮操作 */
315312
const handleAdd = () => {
316313
reset()
317-
resetEditor()
318314
// 打开表单,并设置初始化
319315
objData.value = {
320316
type: 'text',
@@ -328,7 +324,6 @@ const handleAdd = () => {
328324
/** 修改按钮操作 */
329325
const handleUpdate = async (row: any) => {
330326
reset()
331-
resetEditor()
332327
333328
const data = await MpAutoReplyApi.getAutoReply(row.id)
334329
// 设置属性
@@ -386,7 +381,7 @@ const handleSubmit = async () => {
386381
}
387382
388383
showReplyFormDialog.value = false
389-
getList()
384+
await getList()
390385
}
391386
392387
// 表单重置
@@ -408,14 +403,6 @@ const cancel = () => {
408403
reset()
409404
}
410405
411-
// 表单 Editor 重置
412-
const resetEditor = () => {
413-
hackResetWxReplySelect.value = false // 销毁组件
414-
nextTick(() => {
415-
hackResetWxReplySelect.value = true // 重建组件
416-
})
417-
}
418-
419406
const handleDelete = async (row) => {
420407
await message.confirm('是否确认删除此数据?')
421408
await MpAutoReplyApi.deleteAutoReply(row.id)

src/views/mp/message/index.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,9 @@
190190
v-model="showMessageBox"
191191
@click="showMessageBox = true"
192192
width="50%"
193+
destroy-on-close
193194
>
194-
<template #footer>
195-
<WxMsg :user-id="userId" v-if="showMessageBox" />
196-
</template>
195+
<WxMsg :user-id="userId" />
197196
</el-dialog>
198197
</ContentWrap>
199198
</template>
@@ -262,6 +261,7 @@ const handleQuery = () => {
262261
263262
/** 重置按钮操作 */
264263
const resetQuery = async () => {
264+
// 暂存accountId,并在reset后恢复
265265
const accountId = queryParams.accountId
266266
queryFormRef.value?.resetFields()
267267
queryParams.accountId = accountId

0 commit comments

Comments
 (0)