restructure/src/components/Dialog/index.vue

55 lines
1.0 KiB
Vue
Raw Normal View History

2022-05-25 19:02:52 +08:00
<template>
<div />
</template>
2022-05-18 17:35:46 +08:00
<script setup>
2022-05-25 15:32:44 +08:00
import { isNullOrUndef } from '@/utils/is'
2022-05-18 17:35:46 +08:00
import { useDialog } from 'naive-ui'
2022-05-25 15:32:44 +08:00
const NDialog = useDialog()
class Dialog {
success(title, option) {
this.showDialog('success', { title, ...option })
}
warning(title, option) {
this.showDialog('warning', { title, ...option })
}
error(title, option) {
this.showDialog('error', { title, ...option })
}
showDialog(type = 'success', option) {
if (isNullOrUndef(option.title)) {
option.showIcon = false
}
NDialog[type]({
positiveText: 'OK',
closable: false,
...option
})
}
confirm(option = {}) {
this.showDialog(option.type || 'error', {
positiveText: '确定',
negativeText: '取消',
onPositiveClick: option.confirm,
onNegativeClick: option.cancel,
onMaskClick: option.cancel,
...option
})
}
}
window['$dialog'] = new Dialog()
Object.freeze(window.$dialog)
Object.defineProperty(window, '$dialog', {
configurable: false,
writable: false
})
2022-05-18 17:35:46 +08:00
</script>
2022-05-25 15:32:44 +08:00