index.vue 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <!-- 💥 这里是一次性加载 LayoutComponents -->
  2. <template>
  3. <LayoutLockPage v-if="getIsLock" />
  4. <template v-else>
  5. <LayoutLoginPage v-if="getIsLogin" @login-success="funLoginSuccess" />
  6. <!-- <component :is="LayoutComponents[layout]" v-bind="lockEvents" /> -->
  7. <!-- <template v-if="!loadingBtn"> -->
  8. <LayoutClassic ref="LayoutClassicRef" v-bind="lockEvents" />
  9. <ThemeDrawer />
  10. <!-- </template> -->
  11. </template>
  12. </template>
  13. <script setup lang="ts" name="layout">
  14. import { computed, type Component, onBeforeMount, toRef, ref } from "vue";
  15. import { LayoutType } from "@/stores/interface";
  16. import { useGlobalStore } from "@/stores/modules/global";
  17. import ThemeDrawer from "./components/ThemeDrawer/index.vue";
  18. import LayoutVertical from "./LayoutVertical/index.vue";
  19. import LayoutClassic from "./LayoutClassic/index.vue";
  20. import LayoutTransverse from "./LayoutTransverse/index.vue";
  21. import LayoutColumns from "./LayoutColumns/index.vue";
  22. import { useLockPage } from "@/hooks/useLockPage";
  23. import { useLockStore } from "@/stores/modules/lock";
  24. import LayoutLockPage from "@/views/system/lock/index.vue";
  25. import LayoutLoginPage from "@/views/system/login/index.vue";
  26. import { createAppProviderContext } from "@/hooks/core/useAppContext";
  27. import { prefixCls } from "@/config/designSetting";
  28. import { useUserStore } from "@/stores/modules/user";
  29. import { loading } from "@/utils/loading";
  30. import { initDynamicRouter } from "@/routers/modules/dynamicRouter";
  31. import { useAuthStore } from "@/stores/modules/auth";
  32. import router from "@/routers";
  33. const LayoutComponents: Record<LayoutType, Component> = {
  34. vertical: LayoutVertical,
  35. classic: LayoutClassic,
  36. transverse: LayoutTransverse,
  37. columns: LayoutColumns
  38. };
  39. const LayoutClassicRef = ref();
  40. const authStore = useAuthStore();
  41. const globalStore = useGlobalStore();
  42. const layout = computed(() => globalStore.layout);
  43. const userStore = useUserStore();
  44. const lockStore = useLockStore();
  45. const lockEvents = useLockPage();
  46. const loadingBtn = ref(true);
  47. const getIsLock = computed(() => lockStore?.getLockInfo?.isLock ?? false);
  48. const getIsLogin = computed(() => lockStore?.getLockInfo?.isLogin ?? false);
  49. console.log("getIsLock :>> ", getIsLock);
  50. createAppProviderContext({ prefixCls: toRef(prefixCls), isMobile: toRef(false) });
  51. onBeforeMount(async () => {
  52. try {
  53. loadingBtn.value = true;
  54. loading.show("正在加载账号信息");
  55. // await userStore.getUserInfo();
  56. // 刷新动态路由
  57. await initDynamicRouter();
  58. console.log("authStore.authButtonList :>> ", authStore.authButtonList);
  59. // 获取常用菜单信息
  60. await authStore.getHomeLayout();
  61. globalStore.setGlobalState("isSuper", userStore.userInfo.usercode?.trim().toLocaleLowerCase() == "super");
  62. loadingBtn.value = false;
  63. loading.hide();
  64. } catch (error: any) {
  65. loading.hide();
  66. if (error.message && error.message.indexOf("timeout") !== -1) {
  67. let _fullPath = router.currentRoute.value.fullPath;
  68. let _redirectPath = _fullPath.replace(/&/g, "$and$");
  69. router.replace("/408" + "?redirect=" + _redirectPath);
  70. }
  71. }
  72. });
  73. /**
  74. * @description 登录成功后刷新页面
  75. */
  76. const funLoginSuccess = () => {
  77. LayoutClassicRef.value.refresh();
  78. };
  79. </script>
  80. <style scoped lang="scss">
  81. .layout {
  82. min-width: 730px;
  83. }
  84. </style>