ModalManager.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <script setup lang="ts">
  2. import { defineAsyncComponent, shallowRef } from "vue";
  3. import { storeToRefs } from "pinia";
  4. import { useModalsStore } from "@/stores/modals";
  5. const modalsStore = useModalsStore();
  6. const { modals, activeModals } = storeToRefs(modalsStore);
  7. const useModalComponents = (map: { [key: string]: string }) => {
  8. const modalComponents: { [key: string]: string } = {};
  9. Object.entries(map).forEach(([mapKey, mapValue]) => {
  10. modalComponents[mapKey] = defineAsyncComponent(
  11. () => import(`./modals/${mapValue}.vue`)
  12. );
  13. });
  14. return modalComponents;
  15. };
  16. const modalComponents = shallowRef(
  17. useModalComponents({
  18. editUser: "EditUser",
  19. login: "Login",
  20. register: "Register",
  21. whatIsNew: "WhatIsNew",
  22. createStation: "CreateStation",
  23. editNews: "EditNews",
  24. manageStation: "ManageStation/index",
  25. editPlaylist: "EditPlaylist/index",
  26. createPlaylist: "CreatePlaylist",
  27. report: "Report",
  28. viewReport: "ViewReport",
  29. bulkActions: "BulkActions",
  30. viewApiRequest: "ViewApiRequest",
  31. viewPunishment: "ViewPunishment",
  32. removeAccount: "RemoveAccount",
  33. importAlbum: "ImportAlbum",
  34. confirm: "Confirm",
  35. editSong: "EditSong/index",
  36. viewYoutubeVideo: "ViewYoutubeVideo"
  37. })
  38. );
  39. </script>
  40. <template>
  41. <div>
  42. <div v-for="activeModalUuid in activeModals" :key="activeModalUuid">
  43. <component
  44. :is="modalComponents[modals[activeModalUuid]]"
  45. :modal-uuid="activeModalUuid"
  46. />
  47. </div>
  48. </div>
  49. </template>