Browse Source

修改客户资料动态路由

huangbin 4 years ago
parent
commit
eddcc1d5c1

+ 3 - 3
src/router/index.ts

@@ -49,11 +49,11 @@ const routes: Array<RouteRecordRaw> = [
                 meta: {
                     requireAuth: true
                 },
-                redirect: to => { return { name: EnumType.CustomInfo.normal } },
+                redirect: to => { return { name: 'custom_info_normal' } },
                 children: [
                     {
                         path: '/custom_info/normal',
-                        name: EnumType.CustomInfo.normal,
+                        name: 'custom_info_normal',
                         component: () => import('@/views/information/custom/list/normal-use/index.vue'),
                         meta: {
                             requireAuth: true
@@ -61,7 +61,7 @@ const routes: Array<RouteRecordRaw> = [
                     },
                     {
                         path: '/custom_info/stop',
-                        name: EnumType.CustomInfo.stop,
+                        name: 'custom_info_disabled',
                         component: () => import('@/views/information/custom/list/stop-use/index.vue'),
                         meta: {
                             requireAuth: true

+ 39 - 1
src/setup/router/index.ts

@@ -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 };
 }

+ 10 - 16
src/views/information/custom/index.vue

@@ -2,30 +2,20 @@
   <!-- 客户信息 -->
   <div class="custom">
     <firstMenu :list="list"
-               :value="'value'"
+               :value="'title'"
                @selectMenu="selectMenu" />
     <router-view />
   </div>
 </template>
 
 <script lang="ts">
-import { defineComponent } from 'vue';
+import { defineComponent, ref } from 'vue';
 import firstMenu from '@/components/firstMenu/index.vue';
 import { useRouter } from 'vue-router';
 import { CustomInfo } from '@/enums/routerName';
-
-// 处理菜单
-function handleMenu() {
-    const router = useRouter();
-    const list = [
-        { key: CustomInfo.normal, value: '正常' },
-        { key: CustomInfo.stop, value: '停用' },
-    ];
-    function selectMenu(item: any) {
-        router.push({ name: item.key });
-    }
-    return { list, selectMenu };
-}
+import { initData } from '@/setup/methods/index';
+import { handleMenu } from '@/setup/router/index';
+import { OperationTabMenu } from '@/goServiceAPI/commonService/interface';
 
 export default defineComponent({
     name: 'custom',
@@ -33,7 +23,11 @@ export default defineComponent({
         firstMenu,
     },
     setup() {
-        const { list, selectMenu } = handleMenu();
+        const { list, selectMenu, getMenuList } = handleMenu();
+        initData(() => {
+            getMenuList();
+            console.log('list', list);
+        });
         return { list, selectMenu };
     },
 });

+ 5 - 0
src/views/information/custom/list/normal-use/index.vue

@@ -25,9 +25,14 @@ import filterCustomTable from '@/views/information/custom/compoments/filterTable
 import { getTableHead, ColumnType } from '@/services/bus/table';
 import { TableState, TableStateFilters } from 'ant-design-vue/es/table/interface';
 import { message } from 'ant-design-vue';
+import { useRouter } from 'vue-router';
 
 // 查询客户资料列表
 function getCustomList() {
+    const router = useRouter();
+    const pathArr = router.currentRoute.value.fullPath.split('/');
+    console.log('pathArr', pathArr);
+
     // 表格数据
     const customList = ref<QueryCustomInfoType[]>([]);
     // 表头数据

+ 2 - 0
src/views/information/warehouse-info/index.vue

@@ -13,6 +13,7 @@ import { defineComponent } from 'vue';
 import firstMenu from '@/components/firstMenu/index.vue';
 import { useRouter } from 'vue-router';
 import { WarehouseInfo } from '@/enums/routerName';
+import { initData } from '@/setup/methods/index';
 
 // 处理菜单
 function handleMenu() {
@@ -34,6 +35,7 @@ export default defineComponent({
     },
     setup() {
         const { list, selectMenu } = handleMenu();
+        initData(() => {});
         return { list, selectMenu };
     },
 });

+ 2 - 4
src/views/information/warehouse-info/list/normal-use/index.vue

@@ -71,7 +71,7 @@ function getWarehouseInfoList() {
     // 获取仓库信息
     const wareHouseInfoList = ref<ErmcpWareHouseInfo[]>([]);
     function actionQuery() {
-        const reqParam = { userid: getUserId(),  status: "1"};
+        const reqParam = { userid: getUserId(), status: '1' };
         QueryWareHouse(reqParam)
             .then((res) => {
                 wareHouseInfos.value = res.map((e, i) => {
@@ -82,9 +82,7 @@ function getWarehouseInfoList() {
             .catch((err) => message.error(err));
     }
     // 查询
-    function search(value: any) {
-        
-    }
+    function search(value: any) {}
 
     return { wareHouseInfos, actionQuery, columns, getColumns, search };
 }