Bilibili-Evolved/src/core/dialog/index.ts
2023-02-04 22:53:11 +08:00

42 lines
1013 B
TypeScript

import { Executable, VueModule } from '../common-types'
import Dialog from './Dialog.vue'
export interface DialogInputs {
icon?: string
title?: string | Executable<VueModule>
zIndex?: number
content: string | Executable<VueModule>
contentProps?: Record<string, unknown>
}
export interface DialogInstance extends Required<DialogInputs> {
open: boolean
close(): Promise<void>
closeListeners: (() => void)[]
}
export const showDialog = (inputs: DialogInputs) => {
const { icon, title, zIndex, content, contentProps } = inputs
const dialogElement = new Dialog({
propsData: {
icon,
title,
zIndex,
content,
contentProps,
},
data: {
open: false,
closeListeners: [
() => {
dialogElement.$destroy()
dialogElement.$el.remove()
},
],
},
}).$mount() as Vue & DialogInstance
document.body.appendChild(dialogElement.$el)
setTimeout(() => {
dialogElement.open = true
})
return dialogElement
}