mirror of
https://github.com/MCSManager/MCSManager.git
synced 2025-01-24 15:14:01 +08:00
Feat: add custom mount component
This commit is contained in:
parent
6abe0c37d0
commit
10020b59ad
34
frontend/src/hooks/useMountComponent.ts
Normal file
34
frontend/src/hooks/useMountComponent.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { createApp, type Component } from "vue";
|
||||
import { sleep } from "@/tools/commom";
|
||||
|
||||
export function useMountComponent() {
|
||||
let isOpen = false;
|
||||
const mount = <T>(component: Component) => {
|
||||
if (isOpen) return;
|
||||
isOpen = true;
|
||||
return new Promise<T>((resolve, reject) => {
|
||||
const div = document.createElement("div");
|
||||
document.body.appendChild(div);
|
||||
|
||||
const app = createApp(component, {
|
||||
async destroyComponent(delay = 0) {
|
||||
console.log(delay);
|
||||
|
||||
await sleep(delay);
|
||||
app.unmount();
|
||||
div.remove();
|
||||
isOpen = false;
|
||||
},
|
||||
emitResult(data: T) {
|
||||
isOpen = false;
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
app.mount(div);
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
mount
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user