sunlupeng 1 yıl önce
ebeveyn
işleme
be8e05455a
2 değiştirilmiş dosya ile 96 ekleme ve 142 silme
  1. 14 5
      src/api/home.js
  2. 82 137
      src/components/AppList/index.vue

+ 14 - 5
src/api/home.js

@@ -2,8 +2,17 @@ import request from '@/utils/request'
 
 //获取所有一、二级菜单
 export function appList() {
-    return request({
-      url: '/system/menu/getPrimarySecondaryMenus',
-      method: 'get'
-    })
-  }
+  return request({
+    url: '/system/menu/getPrimarySecondaryMenus',
+    method: 'get'
+  })
+}
+
+//通过menuId查询本身及子级树 
+export function listPost(query) {
+  return request({
+    url: '/system/menu/getListByMenuId',
+    method: 'get',
+    params: query
+  })
+}

+ 82 - 137
src/components/AppList/index.vue

@@ -9,7 +9,7 @@
         </div>
         <el-tabs v-model="activeName" @tab-click="handleClick">
           <el-tab-pane v-for="item, index in appList" :label="item.name" :name="item.name" :key="index">
-            <div class="app-item" v-for="(childItem, index) in item.childrenMenus" :key="index" @click="handleSelect(childItem)"
+            <div class="app-item" v-for="(childItem, index) in item.children" :key="index" @click="handleSelect(childItem)"
               @mouseover="showContent = index" @mouseleave="showContent = null">
               <svg-icon :icon-class="childItem.icon" style="width: 40px;height: 40px" />
               {{ childItem.name }}
@@ -25,8 +25,7 @@
 </template>
 
 <script>
-import {appList} from "@/api/home";
-import { constantRoutes } from "@/router";
+import {appList,getListByMenuId} from "@/api/home";
 import router from '@/router'
 import store from '@/store'
 export default {
@@ -35,144 +34,87 @@ export default {
       activeName: 'OA',
       showContent: null,
       appList: [
-        {
-          name: 'OA',
-          childrenMenus: [
-            {
-              type: 1,
-              path: 'https://www.baidu.com/',
-              name: '自定义应用',
-              icon: 'zidingyi',
-            },
-            {
-              type: 3,
-              path: '/system/companyInfo',
-              name: '系统管理',
-              icon: 'chuchai',
-            },
-            {
-              type: 1,
-              path: '/oa/entry',
-              name: '入职审批',
-              icon: 'qingjia',
-            },
-            {
-              type: 2,
-              path: '/oa/turnJust',
-              name: '转正申请',
-              icon: 'chuchai',
-            },
-            {
-              type: 3,
-              path: '/oa/renewal',
-              name: '续签申请',
-              icon: 'chuchai',
-            },
-            {
-              type: 4,
-              path: '/oa/staffQuit',
-              name: '离职申请',
-              icon: 'chuchai',
-            },
+        // {
+        //   name: 'OA',
+        //   children: [
+        //     {
+        //       type: 1,
+        //       path: 'https://www.baidu.com/',
+        //       name: '自定义应用',
+        //       icon: 'zidingyi',
+        //     },
+        //     {
+        //       type: 3,
+        //       path: '/system/companyInfo',
+        //       name: '系统管理',
+        //       icon: 'chuchai',
+        //     },
+        //     {
+        //       type: 1,
+        //       path: '/oa/entry',
+        //       name: '入职审批',
+        //       icon: 'qingjia',
+        //     },
+        //     {
+        //       type: 2,
+        //       path: '/oa/turnJust',
+        //       name: '转正申请',
+        //       icon: 'chuchai',
+        //     },
+        //     {
+        //       type: 3,
+        //       path: '/oa/renewal',
+        //       name: '续签申请',
+        //       icon: 'chuchai',
+        //     },
+        //     {
+        //       type: 4,
+        //       path: '/oa/staffQuit',
+        //       name: '离职申请',
+        //       icon: 'chuchai',
+        //     },
            
-            {
-              type: 4,
-              path: '/meeting/list',
-              name: '会议室管理',
-              icon: 'chuchai',
-            },
-          ],
-        },
-        {
-          name: '人事',
-          childrenMenus: [],
+        //     {
+        //       type: 4,
+        //       path: '/meeting/list',
+        //       name: '会议室管理',
+        //       icon: 'chuchai',
+        //     },
+        //   ],
+        // },
+        // {
+        //   name: '人事',
+        //   children: [],
 
-        },
-        {
-          name: '财务',
-          childrenMenus: [],
+        // },
+        // {
+        //   name: '财务',
+        //   children: [],
 
-        },
-        {
-          name: 'CRM',
-          childrenMenus: [],
+        // },
+        // {
+        //   name: 'CRM',
+        //   children: [],
 
-        },
+        // },
       ]
     };
   },
-  computed: {
-    // 顶部显示菜单
-    topMenus() {
-      let topMenus = [];
-      this.routers.map((menu) => {
-        if (menu.hidden !== true) {
-          // 兼容顶部栏一级菜单内部跳转
-          if (menu.path === "/") {
-            topMenus.push(menu.children[0]);
-          } else {
-            topMenus.push(menu);
-          }
-        }
-      });
-      return topMenus;
-    },
-    // 所有的路由信息
-    routers() {
-      return this.$store.state.permission.topbarRouters;
-    },
-    // 设置子路由
-    childrenMenus() {
-      const childrenMenus = [];
-      this.routers.map((router) => {
-        for (let item in router.children) {
-          if (router.children[item].parentPath === undefined) {
-            if (router.path === "/") {
-              router.children[item].path = "/" + router.children[item].path;
-            } else {
-              if (!this.ishttp(router.children[item].path)) {
-                router.children[item].path = router.path + "/" + router.children[item].path;
-              }
-            }
-            router.children[item].parentPath = router.path;
-          }
-          childrenMenus.push(router.children[item]);
-        }
-      });
-      return constantRoutes.concat(childrenMenus);
-    },
-  },
   created(){
-    // this.getAppList();
+    this.getAppList();
   },
   methods: {
     getAppList() {
       appList().then(res => {
         let appDataList = [];
         res.data.map((item) => {
-          if (item.name != '其他') {
+          // if (item.name != '其他') {
             appDataList.push(item);
-          }
+          // }
         });
         this.appList = appDataList;
       })
     },
-    // 当前激活的路由
-    activeRoutes(key) {
-      debugger
-      const routes = []
-      if (this.childrenMenus && this.childrenMenus.length > 0) {
-        this.childrenMenus.map((item) => {
-          if (key === item.parentPath || (key === "index" && "" === item.path)) {
-            routes.push(item);
-          }
-        });
-      }
-      if (routes.length > 0) {
-        this.$store.commit("SET_SIDEBAR_ROUTERS", routes);
-      }
-      this.$router.push({ path: key });
-    },
     childMethod() {
       this.$parent.openAppList();
     },
@@ -183,6 +125,24 @@ export default {
     // 菜单选择事件
     handleSelect(item) {
       let key = item.path;
+      getListByMenuId({menuld:item.id}).then(response => {
+          let menuList =response.data;
+          localStorage.setItem("menus", JSON.stringify(menuList))
+          if (this.ishttp(key)) {
+            // http(s):// 路径新窗口打开
+            window.open(key, "_blank");
+          } else {
+            store.dispatch('GenerateRoutes', menuList).then(accessRoutes => {
+              console.log(accessRoutes);
+              // 根据 roles 权限生成可访问的路由表
+              router.addRoutes(accessRoutes) // 动态添加可访问路由表
+            })
+            setTimeout(() => {
+              this.$router.push({ path: key });
+            }, 200);
+          }
+        });
+      
       const menus = [
         {
           "id": 1254,
@@ -3124,21 +3084,6 @@ export default {
           ]
         }
       ]
-      localStorage.setItem("menus", JSON.stringify(menu))
-      if (this.ishttp(key)) {
-        // http(s):// 路径新窗口打开
-        window.open(key, "_blank");
-      } else {
-        store.dispatch('GenerateRoutes', menu).then(accessRoutes => {
-          console.log(accessRoutes);
-          // 根据 roles 权限生成可访问的路由表
-          router.addRoutes(accessRoutes) // 动态添加可访问路由表
-        })
-        setTimeout(() => {
-          this.$router.push({ path: key });
-        }, 200);
-      }
-
     },
     handleClick(tab, event) {
       console.log(tab, event);