From 20c96f3dab1a3d9e10996a0580ef157293d45e06 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期五, 17 六月 2022 11:10:23 +0800
Subject: [PATCH] 修改路由匹配code  显示后端返回name值

---
 src/layout/components/Sidebar/index.vue |   70 +++++++++++++++--------
 src/router/index.js                     |   70 +++++++++++++++++++++-
 2 files changed, 110 insertions(+), 30 deletions(-)

diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue
index 4812b0f..857b930 100644
--- a/src/layout/components/Sidebar/index.vue
+++ b/src/layout/components/Sidebar/index.vue
@@ -25,7 +25,9 @@
       </el-menu>
     </el-scrollbar>
     <div style="position: absolute;bottom: 20px;left: 30px;">
-      <div><el-button type="text">鏂板嚡杩埗閫燰1.0.01</el-button></div>
+      <div>
+        <el-button type="text">鏂板嚡杩埗閫燰1.0.01</el-button>
+      </div>
     </div>
 
   </div>
@@ -49,7 +51,7 @@
   async created() {
     const { data: res } = await LoginMenu()
     this.routers = res
-    this.routers.unshift({ name: '绯荤粺棣栭〉' })
+    this.routers.unshift({ code: '1000', name: '绯荤粺璁剧疆' })
   },
   computed: {
     ...mapGetters([
@@ -57,14 +59,17 @@
       'sidebar'
     ]),
     routes() {
-      const newArr = []
+      const newCodeArr = []
+      const newCodeNameArr = []
       this.routers.forEach(item => {
-        if (item.name) {
-          newArr.push(item.name)
+        if (item.code) {
+          newCodeArr.push(item.code)
+          newCodeNameArr.push({ code: item.code, title: item.name })
           if (item.children) {
             item.children.forEach(it => {
-              if (it.name) {
-                newArr.push(it.name)
+              if (it.code) {
+                newCodeArr.push(it.code)
+                newCodeNameArr.push({ code: it.code, title: it.name })
               }
             })
           }
@@ -73,13 +78,23 @@
       const arr = this.$router.options.routes
       const arr2 = []
       arr.forEach((item, index) => {
-        if (newArr.includes(item.name) && item.children.length === 1) {
+        if (newCodeArr.includes(item.code) && item.children.length === 1) {
           arr2.push(item)
-        } else if (newArr.includes(item.name) && item.children.length > 1) {
+        } else if (newCodeArr.includes(item.code) && item.children.length > 1) {
+          newCodeNameArr.forEach(it1 => { // 鏇挎崲鎺ュ彛涓殑name涓鸿彍鍗曞悕绉�
+            if (it1.code === item.code) {
+              item.meta.title = it1.title
+            }
+          })
           const a = []
-          item.children.forEach((it, ind) => {
-            if (newArr.includes(it.name)) {
-              a.push(it)
+          item.children.forEach((it2, ind) => { // 閬嶅巻
+            if (newCodeArr.includes(it2.code)) {
+              newCodeNameArr.forEach(it1 => { // 鏇挎崲鎺ュ彛涓殑name涓鸿彍鍗曞悕绉�
+                if (it2.code === it1.code) {
+                  it2.meta.title = it1.title
+                }
+              })
+              a.push(it2)
             }
           })
           item.children = a
@@ -110,46 +125,51 @@
 }
 </script>
 <style lang="scss">
-$main_color :#42b983;
-.el-button--text, .el-button--text.is-disabled, .el-button--text.is-disabled:focus, .el-button--text.is-disabled:hover, .el-button--text:active{
-  color: white ;
-  font-size: 18px ;
+$main_color: #42b983;
+.el-button--text, .el-button--text.is-disabled, .el-button--text.is-disabled:focus, .el-button--text.is-disabled:hover, .el-button--text:active {
+  color: white;
+  font-size: 18px;
 }
+
 #app .sidebar-container .el-submenu .el-menu-item {
   background-color: transparent !important;
 }
 
-#app .sidebar-container .el-submenu .el-menu-item.is-active{
+#app .sidebar-container .el-submenu .el-menu-item.is-active {
   background: $main_color !important;
   color: #fff !important;
 }
-#app .sidebar-container .el-submenu .el-menu-item:hover{
+
+#app .sidebar-container .el-submenu .el-menu-item:hover {
   background: $main_color !important;
   //color: #fff !important;
 }
 
-.el-submenu__title{
+.el-submenu__title {
   font-weight: bolder;
 }
 
-.sub-el-icon::before{
+.sub-el-icon::before {
   color: $main_color;
 }
-.svg-icon{
+
+.svg-icon {
   color: $main_color;
 }
-.submenu-title-noDropdown{
+
+.submenu-title-noDropdown {
   font-weight: bolder;
 }
-.router-link-exact-active>.submenu-title-noDropdown{
+
+.router-link-exact-active > .submenu-title-noDropdown {
   color: $main_color !important;
 }
 
-.el-menu-item.is-active{
+.el-menu-item.is-active {
   color: $main_color !important;
 }
 
-.el-button--text:hover{
+.el-button--text:hover {
   color: #ffffff;
   cursor: default;
 }
diff --git a/src/router/index.js b/src/router/index.js
index 3e39da2..2d661e6 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -58,6 +58,7 @@
     component: Layout,
     redirect: '/index',
     name: '绯荤粺棣栭〉',
+    code: '1000',
     children: [{
       path: 'index',
       name: 'index',
@@ -70,31 +71,37 @@
     component: Layout,
     redirect: '/jcsz/zzjg',
     name: '鍩虹璁剧疆',
+    code: '1001',
     meta: { title: '鍩虹璁剧疆', icon: 'tree' },
     children: [
       {
         path: 'zzjg',
         name: '缁勭粐鏋舵瀯',
+        code: '1010',
         component: () => import('@/views/jcsz/zzjg'),
         meta: { title: '缁勭粐鏋舵瀯', icon: '' }
       }, {
-        path: 'jsqd',
-        name: '瑙掕壊娓呭崟',
-        component: () => import('@/views/jcsz/jsqd'),
-        meta: { title: '瑙掕壊娓呭崟', icon: '' }
-      }, {
         path: 'yhqd',
         name: '鐢ㄦ埛娓呭崟',
+        code: '1011',
         component: () => import('@/views/jcsz/yhqd'),
         meta: { title: '鐢ㄦ埛娓呭崟', icon: '' }
       }, {
+        path: 'jsqd',
+        name: '瑙掕壊娓呭崟',
+        code: '1012',
+        component: () => import('@/views/jcsz/jsqd'),
+        meta: { title: '瑙掕壊娓呭崟', icon: '' }
+      }, {
         path: 'wldw',
         name: '寰�鏉ュ崟浣�',
+        code: '1013',
         component: () => import('@/views/jcsz/wldw'),
         meta: { title: '寰�鏉ュ崟浣�', icon: '' }
       }, {
         path: 'adsz',
         name: '瀹夌伅璁剧疆',
+        code: '1014',
         component: () => import('@/views/jcsz/adsz'),
         meta: { title: '瀹夌伅璁剧疆', icon: '' }
       }
@@ -105,63 +112,74 @@
     component: Layout,
     redirect: '/sbgl/sblx',
     name: '璁惧绠$悊',
+    code: '1002',
     meta: { title: '璁惧绠$悊', icon: 'example' },
     children: [
       {
         path: 'sblx',
         name: '璁惧绫诲瀷',
+        code: '1020',
         component: () => import('@/views/sbgl/sblx'),
         meta: { title: '璁惧绫诲瀷', icon: '' }
       },
       {
         path: 'wxjl',
+        code: '1029',
         name: '缁翠慨璁板綍',
         component: () => import('@/views/sbgl/wxjl'),
         meta: { title: '缁翠慨璁板綍', icon: '' }
       }, {
         path: 'sbz',
         name: '璁惧缁�',
+        code: '1021',
         component: () => import('@/views/sbgl/sbz'),
         meta: { title: '璁惧缁�', icon: '' }
       }, {
         path: 'sbqd',
         name: '璁惧娓呭崟',
+        code: '1022',
         component: () => import('@/views/sbgl/sbqd'),
         meta: { title: '璁惧娓呭崟', icon: '' }
       },
       {
         path: 'djbz',
         name: '鐐规鏍囧噯',
+        code: '1023',
         component: () => import('@/views/sbgl/djbz'),
         meta: { title: '鐐规鏍囧噯', icon: '' }
       },
       {
         path: 'djbw',
         name: '鐐规閮ㄤ綅',
+        code: '1024',
         component: () => import('@/views/sbgl/djbw'),
         meta: { title: '鐐规閮ㄤ綅', icon: '' }
       },
       {
         path: 'bybz',
         name: '淇濆吇鏍囧噯',
+        code: '1025',
         component: () => import('@/views/sbgl/bybz'),
         meta: { title: '淇濆吇鏍囧噯', icon: '' }
       },
       {
         path: 'bybw',
         name: '淇濆吇閮ㄤ綅',
+        code: '1026',
         component: () => import('@/views/sbgl/bybw'),
         meta: { title: '淇濆吇閮ㄤ綅', icon: '' }
       },
       {
         path: 'djjl',
         name: '鐐规璁板綍',
+        code: '1027',
         component: () => import('@/views/sbgl/djjl'),
         meta: { title: '鐐规璁板綍', icon: '' }
       },
       {
         path: 'byjl',
         name: '淇濆吇璁板綍',
+        code: '1028',
         component: () => import('@/views/sbgl/byjl'),
         meta: { title: '淇濆吇璁板綍', icon: '' }
       }
@@ -172,61 +190,73 @@
     component: Layout,
     redirect: '/gzgl/gzlx',
     name: '宸ヨ绠$悊',
+    code: '1003',
     meta: { title: '宸ヨ绠$悊', icon: 'component' },
     children: [
       {
         path: 'gzlx',
         name: '宸ヨ绫诲瀷',
+        code: '1030',
         component: () => import('@/views/gzgl/gzlx'),
         meta: { title: '宸ヨ绫诲瀷', icon: '' }
       }, {
         path: 'sjxj',
         name: '涓婃満涓嬫満',
+        code: '1039',
         component: () => import('@/views/gzgl/sjxj'),
         meta: { title: '涓婃満涓嬫満', icon: '' }
       }, {
         path: 'ckrk',
         name: '鍑哄簱鍏ュ簱',
+        code: '1040',
         component: () => import('@/views/gzgl/ckrk'),
         meta: { title: '鍑哄簱鍏ュ簱', icon: '' }
       }, {
         path: 'gzqd',
         name: '宸ヨ娓呭崟',
+        code: '1031',
         component: () => import('@/views/gzgl/gzqd'),
         meta: { title: '宸ヨ娓呭崟', icon: '' }
       }, {
         path: 'djbz',
         name: '鐐规鏍囧噯',
+        code: '1032',
         component: () => import('@/views/gzgl/djbz'),
         meta: { title: '鐐规鏍囧噯', icon: '' }
       }, {
         path: 'djbw',
         name: '鐐规閮ㄤ綅',
+        code: '1033',
         component: () => import('@/views/gzgl/djbw'),
         meta: { title: '鐐规閮ㄤ綅', icon: '' }
       }, {
         path: 'bybz',
         name: '淇濆吇鏍囧噯',
+        code: '1034',
         component: () => import('@/views/gzgl/bybz'),
         meta: { title: '淇濆吇鏍囧噯', icon: '' }
       }, {
         path: 'bybw',
         name: '淇濆吇閮ㄤ綅',
+        code: '1035',
         component: () => import('@/views/gzgl/bybw'),
         meta: { title: '淇濆吇閮ㄤ綅', icon: '' }
       }, {
         path: 'djjl',
         name: '鐐规璁板綍',
+        code: '1036',
         component: () => import('@/views/gzgl/djjl'),
         meta: { title: '鐐规璁板綍', icon: '' }
       }, {
         path: 'byjl',
         name: '淇濆吇璁板綍',
+        code: '1037',
         component: () => import('@/views/gzgl/byjl'),
         meta: { title: '淇濆吇璁板綍', icon: '' }
       }, {
         path: 'gzwx',
         name: '宸ヨ缁翠慨',
+        code: '1038',
         component: () => import('@/views/gzgl/gzwx'),
         meta: { title: '宸ヨ缁翠慨', icon: '' }
       }
@@ -237,37 +267,44 @@
     component: Layout,
     redirect: '/wlgl/ckdy',
     name: '鐗╂枡绠$悊',
+    code: '1004',
     meta: { title: '鐗╂枡绠$悊', icon: 'table' },
     children: [
       {
         path: 'ckdy',
         name: '浠撳簱瀹氫箟',
+        code: '1050',
         component: () => import('@/views/wlgl/ckdy'),
         meta: { title: '浠撳簱瀹氫箟', icon: '' }
       },
       {
         path: 'kwdy',
         name: '搴撲綅瀹氫箟',
+        code: '1051',
         component: () => import('@/views/wlgl/kwdy'),
         meta: { title: '搴撲綅瀹氫箟', icon: '' }
       }, {
         path: 'rqlx',
         name: '瀹瑰櫒绫诲瀷',
+        code: '1052',
         component: () => import('@/views/wlgl/rqlx'),
         meta: { title: '瀹瑰櫒绫诲瀷', icon: '' }
       }, {
         path: 'rqqd',
         name: '瀹瑰櫒娓呭崟',
+        code: '1053',
         component: () => import('@/views/wlgl/rqqd'),
         meta: { title: '瀹瑰櫒娓呭崟', icon: '' }
       }, {
         path: 'crkjl',
         name: '鍑哄叆搴撹褰�',
+        code: '1054',
         component: () => import('@/views/wlgl/crkjl'),
         meta: { title: '鍑哄叆搴撹褰�', icon: '' }
       }, {
         path: 'kccx',
         name: '搴撳瓨鏌ヨ',
+        code: '1055',
         component: () => import('@/views/wlgl/kccx'),
         meta: { title: '搴撳瓨鏌ヨ', icon: '' }
       }
@@ -278,39 +315,46 @@
     component: Layout,
     redirect: '/zzmx/gylx',
     name: '鍒堕�犳ā鍨�',
+    code: '1005',
     meta: { title: '鍒堕�犳ā鍨�', icon: 'icu' },
     children: [
       {
         path: 'wllx',
         name: '鐗╂枡绫诲瀷',
+        code: '1060',
         component: () => import('@/views/zzmx/wllx'),
         meta: { title: '鐗╂枡绫诲瀷', icon: '' }
       },
       {
         path: 'chda',
         name: '瀛樿揣妗f',
+        code: '1061',
         component: () => import('@/views/zzmx/chda'),
         meta: { title: '瀛樿揣妗f', icon: '' }
       }, {
         path: 'wlqd',
         name: '鐗╂枡娓呭崟',
+        code: '1062',
         component: () => import('@/views/zzmx/wlqd'),
         meta: { title: '鐗╂枡娓呭崟', icon: '' }
       },
       {
         path: 'gylx',
         name: '宸ヨ壓璺嚎',
+        code: '1063',
         component: () => import('@/views/zzmx/gylx'),
         meta: { title: '宸ヨ壓璺嚎', icon: '' }
       }, {
         path: 'gxdy',
         name: '宸ュ簭瀹氫箟',
+        code: '1064',
         component: () => import('@/views/zzmx/gxdy'),
         meta: { title: '宸ュ簭瀹氫箟', icon: '' }
       },
       {
         path: 'jpgj',
         name: '鑺傛媿宸ヤ环',
+        code: '1065',
         component: () => import('@/views/zzmx/jpgj'),
         meta: { title: '鑺傛媿宸ヤ环', icon: '' }
       }
@@ -321,26 +365,31 @@
     component: Layout,
     redirect: '/scgl/scdd',
     name: '鐢熶骇绠$悊',
+    code: '1006',
     meta: { title: '鐢熶骇绠$悊', icon: 'production' },
     children: [
       {
         path: 'scdd',
         name: 'ERP鐢熶骇璁㈠崟',
+        code: '1070',
         component: () => import('@/views/scgl/scdd'),
         meta: { title: 'ERP鐢熶骇璁㈠崟', icon: '' }
       }, {
         path: 'gd',
         name: 'MES宸ュ崟',
+        code: '1071',
         component: () => import('@/views/scgl/gd'),
         meta: { title: 'MES宸ュ崟', icon: '' }
       }, {
         path: 'gdpg',
         name: '宸ュ崟娲惧伐',
+        code: '1072',
         component: () => import('@/views/scgl/gdpg'),
         meta: { title: '宸ュ崟娲惧伐', icon: '' }
       }, {
         path: 'sckbg',
         name: '鐢熶骇寮�鎶ュ伐',
+        code: '1073',
         component: () => import('@/views/scgl/sckbg'),
         meta: { title: '鐢熶骇寮�鎶ュ伐', icon: '' }
       }
@@ -351,31 +400,37 @@
     component: Layout,
     redirect: '/zlgl/zjbz',
     name: '璐ㄩ噺绠$悊',
+    code: '1007',
     meta: { title: '璐ㄩ噺绠$悊', icon: 'quality' },
     children: [
       {
         path: 'zjbz',
         name: '璐ㄦ鏍囧噯',
+        code: '1080',
         component: () => import('@/views/zlgl/zjbz'),
         meta: { title: '璐ㄦ鏍囧噯', icon: '' }
       }, {
         path: 'qxdy',
         name: '缂洪櫡瀹氫箟',
+        code: '1081',
         component: () => import('@/views/zlgl/qxdy'),
         meta: { title: '缂洪櫡瀹氫箟', icon: '' }
       }, {
         path: 'gxjy',
         name: '宸ュ簭妫�楠�',
+        code: '1082',
         component: () => import('@/views/zlgl/gxjy'),
         meta: { title: '宸ュ簭妫�楠�', icon: '' }
       }, {
         path: 'wljy',
         name: '鐗╂祦妫�楠�',
+        code: '1083',
         component: () => import('@/views/zlgl/wljy'),
         meta: { title: '鐗╂祦妫�楠�', icon: '' }
       }, {
         path: 'qxsj',
         name: '缂洪櫡缁熻',
+        code: '1084',
         component: () => import('@/views/zlgl/qxsj'),
         meta: { title: '缂洪櫡缁熻', icon: '' }
       }
@@ -386,26 +441,31 @@
     component: Layout,
     redirect: '/xtsz/bmgz',
     name: '绯荤粺璁剧疆',
+    code: '1009',
     meta: { title: '绯荤粺璁剧疆', icon: 'xtsz' },
     children: [
       {
         path: 'bmgz',
         name: '缂栫爜瑙勫垯',
+        code: '1101',
         component: () => import('@/views/xtsz/bmgz'),
         meta: { title: '缂栫爜瑙勫垯', icon: '' }
       }, {
         path: 'mmxg',
         name: '瀵嗙爜淇敼',
+        code: '1102',
         component: () => import('@/views/xtsz/mmxg'),
         meta: { title: '瀵嗙爜淇敼', icon: '' }
       }, {
         path: 'xtrz',
         name: '绯荤粺鏃ュ織',
+        code: '1103',
         component: () => import('@/views/xtsz/xtrz'),
         meta: { title: '绯荤粺鏃ュ織', icon: '' }
       }, {
         path: 'sc',
         name: 'SOP涓婁紶',
+        code: '1104',
         component: () => import('@/views/xtsz/sc'),
         meta: { title: 'SOP涓婁紶', icon: '' }
       }

--
Gitblit v1.9.3