|
|
@@ -1,4 +1,42 @@
|
|
|
+import { OperationTabMenu } from '@/goServiceAPI/commonService/interface';
|
|
|
+import APP from '@/services';
|
|
|
+import { ref, unref } from 'vue';
|
|
|
+import { Router, useRouter } from 'vue-router';
|
|
|
|
|
|
-export function mateRouter() {
|
|
|
+// 处理 动态路由
|
|
|
+function mateRouter(router: Router) {
|
|
|
+ const menuList = APP.getRef('menus');
|
|
|
+ const list = unref(menuList);
|
|
|
+ const pathArr = router.currentRoute.value.fullPath.split('/')
|
|
|
+ let result: OperationTabMenu[] = []
|
|
|
+ if (pathArr.length > 1) {
|
|
|
+ if (list.length && list[0].children && list[0].children.length) {
|
|
|
+ const path = pathArr[1];
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ for (let j = 0; j < list[i].children.length; j++) {
|
|
|
+ if (path === list[i].children[j].code) {
|
|
|
+ result = list[i].children[j].children
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+}
|
|
|
|
|
|
+export function handleMenu() {
|
|
|
+ const router = useRouter();
|
|
|
+ const list = ref<OperationTabMenu[]>([])
|
|
|
+ // 获取动态路由
|
|
|
+ function getMenuList() {
|
|
|
+ list.value = mateRouter(router)
|
|
|
+ }
|
|
|
+ // 切换路由
|
|
|
+ function selectMenu(item: any) {
|
|
|
+ console.log('item', item);
|
|
|
+
|
|
|
+ router.push({ name: item.code });
|
|
|
+ }
|
|
|
+ return { list, selectMenu, getMenuList };
|
|
|
}
|