useLoginDialog.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { createApp, h } from "vue";
  2. import LoginDialog from "@/components/LoginDialog.vue";
  3. export function openLoginDialog(
  4. options: {
  5. onLogin?: (data: { username: string; password: string }) => void;
  6. onRegister?: () => void;
  7. onForgot?: () => void;
  8. onClose?: () => void;
  9. } = {}
  10. ) {
  11. const container = document.createElement("div");
  12. document.body.appendChild(container);
  13. const app = createApp({
  14. render() {
  15. return h(LoginDialog, {
  16. onLogin: (data: any) => {
  17. options.onLogin?.(data);
  18. app.unmount();
  19. document.body.removeChild(container);
  20. },
  21. onRegister: () => {
  22. options.onRegister?.();
  23. app.unmount();
  24. document.body.removeChild(container);
  25. },
  26. onForgot: () => {
  27. options.onForgot?.();
  28. },
  29. onClose: () => {
  30. options.onClose?.();
  31. app.unmount();
  32. document.body.removeChild(container);
  33. },
  34. ref: "dialog",
  35. });
  36. },
  37. mounted() {
  38. this.$refs.dialog.open();
  39. },
  40. });
  41. app.mount(container);
  42. }