| 12345678910111213141516171819202122232425262728293031323334353637 |
- import { Dialog } from '@kankan/components/index'
- import { ui18n } from '@/lang'
- const cacheMap = new Map<any, Promise<any>>()
- export const useAlert = async (msg: any) => {
- if (cacheMap.has(msg)) {
- await cacheMap.get(msg)
- } else {
- const caches = Array.from(cacheMap.values())
- if (caches.length) {
- await Promise.all(caches)
- }
- if (typeof msg == 'string') {
- msg = {
- content: msg
- }
- }
- msg.title = msg.title || ui18n.t('sys.dialogTitle')
- msg.okText = msg.okText || ui18n.t('sys.enter')
- const promise = Dialog.alert(msg)
- cacheMap.set(msg, promise)
- await promise
- cacheMap.delete(msg)
- }
- }
- export const useConfirm = async (msg: any) => {
- if (typeof msg == 'string') {
- msg = {
- content: msg
- }
- }
- msg.title = msg.title || ui18n.t('sys.dialogTitle')
- msg.okText = msg.okText || ui18n.t('sys.enter')
- msg.noText = msg.noText || ui18n.t('sys.cancel')
- return Dialog.confirm(msg)
- }
|