index.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { OperationTabMenu } from '@/goServiceAPI/commonService/interface';
  2. import APP from '@/services';
  3. import { ref, unref } from 'vue';
  4. import { Router, useRouter } from 'vue-router';
  5. // 处理 动态路由
  6. function mateRouter(router: Router) {
  7. const menuList = APP.getRef('menus');
  8. const list = unref(menuList);
  9. const pathArr = router.currentRoute.value.fullPath.split('/')
  10. let result: OperationTabMenu[] = []
  11. if (pathArr.length > 1) {
  12. if (list.length && list[0].children && list[0].children.length) {
  13. const path = pathArr[1];
  14. for (let i = 0; i < list.length; i++) {
  15. for (let j = 0; j < list[i].children.length; j++) {
  16. if (path === list[i].children[j].code) {
  17. result = list[i].children[j].children
  18. break;
  19. }
  20. }
  21. }
  22. }
  23. }
  24. return result
  25. }
  26. export function handleMenu() {
  27. const router = useRouter();
  28. const list = ref<OperationTabMenu[]>([])
  29. // 获取动态路由
  30. function getMenuList() {
  31. list.value = mateRouter(router)
  32. }
  33. // 切换路由
  34. function selectMenu(item: any) {
  35. console.log('item', item);
  36. router.push({ name: item.code });
  37. }
  38. return { list, selectMenu, getMenuList };
  39. }