浏览代码

fix: 首页菜单

zh 2 年之前
父节点
当前提交
28463d9b77
共有 2 个文件被更改,包括 63 次插入23 次删除
  1. 1 0
      src/permission.js
  2. 62 23
      src/views/dashboard.vue

+ 1 - 0
src/permission.js

@@ -84,6 +84,7 @@ function buildRoute(route, parentUrl = '') {
   var item = {}
   item.path = ~[3, 4].indexOf(type) ? fullUrl : parentUrl + url
   item.name = ~[3, 4].indexOf(type) ? fullUrl : parentUrl + url
+  item.type = type
   item.meta = {
     url,
     title: moduleName,

+ 62 - 23
src/views/dashboard.vue

@@ -5,7 +5,7 @@
         <div>
           <div class="main-title">
             <div class="title">常用菜单</div>
-            <div class="el-icon-setting" @click="dialogVisible = !dialogVisible" />
+            <div class="el-icon-setting" @click="getRouter(), (dialogVisible = !dialogVisible)" />
           </div>
           <div class="child">
             <el-row :gutter="20">
@@ -16,28 +16,26 @@
                 :span="4"
                 style="margin-top: 16px; padding: 3px 20px"
               >
-                <el-link class="link" :underline="false" @click="clickMenu(it.fullUrl)">{{ it.moduleName }}</el-link>
+                <el-link class="link" :underline="false" @click="clickMenu(it.path)">{{ it.meta.title }}</el-link>
               </el-col>
             </el-row>
           </div>
         </div>
-        <div v-for="(item, index) in menuList" :key="index" class="group">
-          <div v-if="item.moduleName != '首页'">
+        <div v-for="(item, index) in newMenuList" :key="index" class="group">
+          <div v-if="item.meta.title != '首页'">
             <div class="main-title">
-              <div class="title">{{ item.moduleName }}</div>
+              <div class="title">{{ item.meta.title }}</div>
             </div>
             <div v-if="item.children && item.children.length" class="child">
               <el-row :gutter="20">
                 <el-col v-for="(it, idx) in item.children" :key="idx" class="item" :span="4">
-                  <el-link class="link" :underline="false" @click="clickMenu(it.fullUrl)">{{ it.moduleName }}</el-link>
+                  <el-link class="link" :underline="false" @click="clickMenu(it.path)">{{ it.meta.title }}</el-link>
                 </el-col>
               </el-row>
             </div>
             <div v-else class="child">
               <div class="item">
-                <el-link class="link" :underline="false" @click="clickMenu(item.fullUrl)">{{
-                  item.moduleName
-                }}</el-link>
+                <el-link class="link" :underline="false" @click="clickMenu(item.path)">{{ item.meta.title }}</el-link>
               </div>
             </div>
           </div>
@@ -100,13 +98,6 @@ export default {
     popu
   },
   created() {
-    getRouter({
-      flag: 'index',
-      adminUserId: this.userid
-    }).then(res => {
-      this.menuList = res.data
-      console.log(res.data)
-    })
     this.getMenuList()
   },
   computed: {
@@ -136,20 +127,68 @@ export default {
       orderId: '',
       logisticsDetail: [],
       arrivalNoticeList: [],
-      specification: ''
+      specification: '',
+      newMenuList: []
     }
   },
 
   methods: {
+    getRouter() {
+      getRouter({
+        flag: 'index',
+        adminUserId: this.userid
+      }).then(res => {
+        this.menuList = res.data
+        this.getMenuList()
+      })
+    },
+    lista(list = [], cyd = []) {
+      var data = JSON.parse(JSON.stringify(list))
+      var cy = []
+      var l = []
+      for (var item of data) {
+        var { children, component, ...d } = item
+        if (d.type === 2 || d.type === 4) {
+          if (~cyd.indexOf(d.meta.moduleId)) {
+            cy.push(d)
+          }
+        }
+        const cpd = { ...d }
+        dg(children || [], cpd)
+        l.push(cpd)
+      }
+      function dg(ls, it) {
+        if (!it.children) {
+          it.children = []
+        }
+        for (const data2 of ls) {
+          var { children, component, ...d } = data2
+          if (d.type === 2 || d.type === 4) {
+            if (~cyd.indexOf(d.meta.moduleId)) {
+              console.log(d.meta.moduleId)
+
+              cy.push(d)
+            }
+            it.children.push(d)
+          } else if (children && children.length) {
+            dg(children, it)
+          }
+        }
+      }
+      return {
+        cy,
+        pp: l
+      }
+    },
     // 获取常用菜单列表
     getMenuList() {
       getMenuList().then(res => {
-        this.normsMenuList = res.data
-        if (this.normsMenuList.length) {
-          this.normsMenuList.forEach(k => {
-            this.checkList.push(k.moduleId)
-          })
-        }
+        this.checkList = res.data.map(k => k.moduleId)
+        console.log(global.antRouter, this.checkList)
+        const obj = this.lista(global.antRouter, this.checkList)
+        this.normsMenuList = obj.cy
+        console.log(this.normsMenuList)
+        this.newMenuList = obj.pp
       })
     },
     // 保存常用菜单