Browse Source

fix: close confirm dialog when clicking cancel

Custom DialogPlugin onClose replaced the default hide path, so Cancel
resolved false but left the modal open. Hide on cancel/close and settle once.
main
xiaosi 2 weeks ago
parent
commit
1c7d5e8e51
  1. 20
      src/stores/modules/uiStore.js

20
src/stores/modules/uiStore.js

@ -13,6 +13,13 @@ export const useUiStore = defineStore('ui', () => {
checks = ['设备在线', '无活动告警', '指令互斥检查'] checks = ['设备在线', '无活动告警', '指令互斥检查']
) { ) {
return new Promise((resolve) => { return new Promise((resolve) => {
let settled = false
const settle = (value) => {
if (settled) return
settled = true
resolve(value)
}
const list = Array.isArray(checks) ? checks.filter(Boolean) : [] const list = Array.isArray(checks) ? checks.filter(Boolean) : []
const body = list.length const body = list.length
? () => ? () =>
@ -32,18 +39,23 @@ export const useUiStore = defineStore('ui', () => {
confirmBtn: '确认执行', confirmBtn: '确认执行',
cancelBtn: '取消', cancelBtn: '取消',
theme: 'warning', theme: 'warning',
destroyOnClose: true,
onConfirm: () => { onConfirm: () => {
dialog.hide() dialog.hide()
resolve(true)
settle(true)
}, },
// 自定义 onClose 会覆盖插件默认关窗;取消/关闭都必须自行 hide
onClose: () => { onClose: () => {
resolve(false)
dialog.hide()
settle(false)
}, },
onCloseBtnClick: () => { onCloseBtnClick: () => {
resolve(false)
dialog.hide()
settle(false)
}, },
onCancel: () => { onCancel: () => {
resolve(false)
dialog.hide()
settle(false)
}, },
}) })
}) })

Loading…
Cancel
Save