This commit is contained in:
zyronon
2023-11-30 14:02:20 +08:00
parent 5a3f4445dc
commit c0eef7768d
8 changed files with 153 additions and 182 deletions

View File

@@ -1,65 +1,64 @@
import {createApp} from 'vue'
import {createVNode, render} from 'vue'
import Dialog, {ModalProps} from "@/components/dialog/Dialog.vue";
import {AppContext, Component, ComponentPublicInstance, createVNode, getCurrentInstance, render, VNode} from 'vue';
export class MessageBox {
static confirm(
content: string,
title: string,
onOk: () => any = () => void 0,
onCancel: () => any = () => void 0,
onClose: () => any = () => void 0,
config: ModalProps = {}
) {
let container = document.createElement('div')
const close = () => {
render(null, container);
container.remove()
onClose?.()
}
const vNode = createVNode(Dialog, {
title,
content,
onCancel: onCancel,
confirm: onOk,
onClose: close,
footer: true,
...config
});
// const appContext = getCurrentInstance()?.appContext;
// // 补丁Component中获取当前组件树的provides
// if (appContext) {
// const currentProvides = (getCurrentInstance() as any)?.provides;
// Reflect.set(appContext, 'provides', {...appContext.provides, ...currentProvides});
// }
// vNode.appContext = appContext;
render(vNode, container);
document.body.append(container)
static confirm(
content: string,
title: string,
onOk: () => any = () => void 0,
onCancel: () => any = () => void 0,
onClose: () => any = () => void 0,
config: ModalProps = {}
) {
let container = document.createElement('div')
const close = () => {
render(null, container);
container.remove()
onClose?.()
}
static notice(
content: string,
title: string,
) {
let container = document.createElement('div')
let tempOnCancel = () => {
render(null, container);
container.remove()
}
const vNode = createVNode(Dialog, {
title,
content,
onCancel: tempOnCancel,
});
// const appContext = getCurrentInstance()?.appContext;
// // 补丁Component中获取当前组件树的provides
// if (appContext) {
// const currentProvides = (getCurrentInstance() as any)?.provides;
// Reflect.set(appContext, 'provides', {...appContext.provides, ...currentProvides});
// }
// vNode.appContext = appContext;
render(vNode, container);
document.body.append(container)
const vNode = createVNode(Dialog, {
title,
content,
onCancel: onCancel,
confirm: onOk,
onClose: close,
footer: true,
...config
});
// const appContext = getCurrentInstance()?.appContext;
// // 补丁Component中获取当前组件树的provides
// if (appContext) {
// const currentProvides = (getCurrentInstance() as any)?.provides;
// Reflect.set(appContext, 'provides', {...appContext.provides, ...currentProvides});
// }
// vNode.appContext = appContext;
render(vNode, container);
document.body.append(container)
}
static notice(
content: string,
title: string,
) {
let container = document.createElement('div')
let tempOnCancel = () => {
render(null, container);
container.remove()
}
const vNode = createVNode(Dialog, {
title,
content,
onCancel: tempOnCancel,
});
// const appContext = getCurrentInstance()?.appContext;
// // 补丁Component中获取当前组件树的provides
// if (appContext) {
// const currentProvides = (getCurrentInstance() as any)?.provides;
// Reflect.set(appContext, 'provides', {...appContext.provides, ...currentProvides});
// }
// vNode.appContext = appContext;
render(vNode, container);
document.body.append(container)
}
}