3 changed files with 46 additions and 41 deletions
@ -1,33 +1,53 @@ |
|||
import { defineStore } from 'pinia' |
|||
import { ref } from 'vue' |
|||
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next' |
|||
import { h } from 'vue' |
|||
|
|||
export const useUiStore = defineStore('ui', () => { |
|||
const toastMsg = ref('') |
|||
const toastVisible = ref(false) |
|||
let toastTimer = null |
|||
function toast(message) { |
|||
toastMsg.value = message |
|||
toastVisible.value = true |
|||
clearTimeout(toastTimer) |
|||
toastTimer = setTimeout(() => { toastVisible.value = false }, 2200) |
|||
MessagePlugin.info({ content: String(message ?? ''), duration: 2200 }) |
|||
} |
|||
|
|||
const confirmVisible = ref(false) |
|||
const confirmTitle = ref('') |
|||
const confirmDesc = ref('') |
|||
const confirmChecks = ref([]) |
|||
let confirmResolve = null |
|||
function confirm(title, desc = '系统将校验设备状态和流程互斥条件,确认通过后提交本次操作。', checks = ['设备在线', '无活动告警', '指令互斥检查']) { |
|||
confirmTitle.value = title |
|||
confirmDesc.value = desc |
|||
confirmChecks.value = checks |
|||
confirmVisible.value = true |
|||
return new Promise((resolve) => { confirmResolve = resolve }) |
|||
} |
|||
function resolveConfirm(ok) { |
|||
confirmVisible.value = false |
|||
if (confirmResolve) { confirmResolve(ok); confirmResolve = null } |
|||
function confirm( |
|||
title, |
|||
desc = '系统将校验设备状态和流程互斥条件,确认通过后提交本次操作。', |
|||
checks = ['设备在线', '无活动告警', '指令互斥检查'] |
|||
) { |
|||
return new Promise((resolve) => { |
|||
const list = Array.isArray(checks) ? checks.filter(Boolean) : [] |
|||
const body = list.length |
|||
? () => |
|||
h('div', { class: 'ui-confirm-body' }, [ |
|||
h('p', desc), |
|||
h( |
|||
'div', |
|||
{ class: 'ui-confirm-checks' }, |
|||
list.map((item) => h('div', { class: 'ui-confirm-check' }, item)) |
|||
), |
|||
]) |
|||
: desc |
|||
|
|||
const dialog = DialogPlugin.confirm({ |
|||
header: title, |
|||
body, |
|||
confirmBtn: '确认执行', |
|||
cancelBtn: '取消', |
|||
theme: 'warning', |
|||
onConfirm: () => { |
|||
dialog.hide() |
|||
resolve(true) |
|||
}, |
|||
onClose: () => { |
|||
resolve(false) |
|||
}, |
|||
onCloseBtnClick: () => { |
|||
resolve(false) |
|||
}, |
|||
onCancel: () => { |
|||
resolve(false) |
|||
}, |
|||
}) |
|||
}) |
|||
} |
|||
|
|||
return { toastMsg, toastVisible, toast, confirmVisible, confirmTitle, confirmDesc, confirmChecks, confirm, resolveConfirm } |
|||
return { toast, confirm } |
|||
}) |
|||
|
|||
Loading…
Reference in new issue