useLoginDialog.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. app.unmount();
  29. document.body.removeChild(container);
  30. },
  31. onClose: () => {
  32. options.onClose?.();
  33. app.unmount();
  34. document.body.removeChild(container);
  35. },
  36. ref: "loginDialog",
  37. });
  38. },
  39. mounted() {
  40. this.$refs.loginDialog.open();
  41. },
  42. });
  43. app.mount(container);
  44. }