index.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { defineComponent, onMounted, ref, watch, watchEffect } from 'vue';
  2. import { useRouter, RouterView, useRoute } from 'vue-router';
  3. import Menus from '@/layout/ManagementLayout/Menus';
  4. import {
  5. PATH_LINK_NAV_BAR_MENU,
  6. PATH_LINK_NAV_BAR_MENU_DICT,
  7. } from '@/constants/constants';
  8. import './index.scss';
  9. import { useCommonStore } from '@/store';
  10. export default defineComponent({
  11. name: 'ManagementLayout',
  12. setup() {
  13. const router = useRouter();
  14. const route = useRoute();
  15. const currentRoute = router.currentRoute.value.path;
  16. const paths = Object.keys(PATH_LINK_NAV_BAR_MENU);
  17. const currentKey = ref(paths.find((p) => currentRoute.includes(p)));
  18. const store = useCommonStore();
  19. const handleRedirect = async (path: string) => {
  20. let item = '1';
  21. for (const menu of PATH_LINK_NAV_BAR_MENU_DICT) {
  22. if (path === menu.path) {
  23. await store.getGlobalDict(menu.dict);
  24. item = store.globalDict[menu.dict]?.[0]?.dictValue ?? '';
  25. item && router.replace(`${menu.path}/${menu.subpath}/${item}`);
  26. }
  27. }
  28. };
  29. onMounted(() => {
  30. PATH_LINK_NAV_BAR_MENU_DICT.forEach((i) => {
  31. store.getGlobalDict(i.dict);
  32. });
  33. handleRedirect(route.path);
  34. });
  35. watchEffect(() => {
  36. handleRedirect(route.path);
  37. });
  38. watch(
  39. () => route.path,
  40. (next) => {
  41. currentKey.value = paths.find((p) => next.includes(p));
  42. },
  43. );
  44. return () => (
  45. <div class="management-container">
  46. <Menus
  47. type={
  48. (currentKey.value as keyof typeof PATH_LINK_NAV_BAR_MENU) ??
  49. 'incident-management'
  50. }
  51. />
  52. <div class="main-content">
  53. <RouterView />
  54. </div>
  55. </div>
  56. );
  57. },
  58. });