From f3335e01ea71614db9fa6aedf1d35e1202c3b12f Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期四, 11 八月 2022 15:46:26 +0800
Subject: [PATCH] 修改登陆时传PC参数

---
 src/store/modules/permission.js |  207 +++++++++++++--------------------------------------
 1 files changed, 54 insertions(+), 153 deletions(-)

diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index c324d4d..216c241 100644
--- a/src/store/modules/permission.js
+++ b/src/store/modules/permission.js
@@ -1,4 +1,4 @@
-import { commonRoutes } from '@/router'
+import { asyncRoutes, commonRoutes } from '@/router'
 import Layout from '@/layout'
 
 // 鍒ゆ柇鏄惁鏈夋潈闄�
@@ -13,52 +13,59 @@
 /**
  * 鎶婂悗鍙拌繑鍥炶彍鍗曠粍瑁呮垚routes瑕佹眰鐨勬牸寮�
  * @param {*} routes
+ * @param {*} menu
  */
-export function getAsyncRoutes(routes) {
-  const res = []
-
-  routes.forEach(item => {
-    const newItem = {}
-    if (item.component) {
-      if (item.component === 'Layout') {
-        newItem.component = Layout
-        newItem.path = item.path
-        if (item.redirect) {
-          newItem.redirect = item.redirect
-        }
-        if (item.hidden === '0') {
-          newItem.hidden = false
-        }
-        if (item.hidden === '1') {
-          newItem.hidden = true
-        }
-        if (item.meta) {
-          newItem.meta = { title: item.meta.title, icon: item.meta.icon, affix: item.meta.affix === '1' }
-        }
-      } else {
-        newItem.path = item.path
-        if (item.name) {
-          newItem.name = item.name
-        }
-        if (item.hidden === '0') {
-          newItem.hidden = false
-        }
-        if (item.hidden === '1') {
-          newItem.hidden = true
-        }
-        newItem.component = (resolve) => require(['@/views' + `${item.component}`], resolve)
-        if (item.meta) {
-          newItem.meta = { title: item.meta.title, icon: item.meta.icon, affix: item.meta.affix === '1' }
-        }
+export function getAsyncRoutes(routes, menu) {
+  // menu  涓璮lag  "0" 琛ㄧず true  "1"琛ㄧずfalse
+  const menuCode = []// 灏嗗悗绔痗ode鍙栧嚭瀛樻垚鏁扮粍褰㈠紡
+  const menuNameAndCode = []// 灏嗗悗绔痗ode涓巒ame鍙栧嚭瀛樻垚鏁扮粍褰㈠紡
+  menu.forEach(item => {
+    if (item.flag === '0') {
+      menuCode.push(item.code)
+      menuNameAndCode.push({ code: item.code, name: item.name })
+      if (item.children && item.children.length > 0) {
+        item.children.forEach(it => {
+          if (it.flag === '0') {
+            menuCode.push(it.code)
+            menuNameAndCode.push({ code: it.code, name: it.name })
+          }
+        })
       }
     }
-
-    if (item.children && item.children.length) {
-      newItem.children = getAsyncRoutes(item.children)
-    }
-    res.push(newItem)
   })
-  return res
+
+  const newRoutes = [] // 鏂拌矾鐢�
+
+  routes.forEach(item => {
+    if (menuCode.includes(item.code) && item.children && item.children.length > 0) {
+      item.meta.title = menuNameAndCode.find(item2 => item2.code === item.code).name
+      const children = []
+      let flag = false// 鍒ゆ柇鏄惁鏈塩hildren瀛樿繘鍘�
+      item.children.forEach(it => {
+        if (menuCode.includes(it.code)) {
+          it.meta.title = menuNameAndCode.find(item2 => item2.code === it.code).name
+          children.push(it)
+          flag = true
+        }
+      })
+      if (flag) {
+        newRoutes.push({
+          alwaysShow: item.alwaysShow,
+          code: item.code,
+          name: item.name,
+          path: item.path,
+          redirect: item.redirect,
+          component: item.component,
+          children: children,
+          meta: item.meta
+        })
+      }
+    }
+  })
+
+  newRoutes.push({ path: '*', redirect: '/404', hidden: true })
+
+  return newRoutes
 }
 
 // 杩囨护鍑烘湁鏉冮檺鐨勮矾鐢�
@@ -89,117 +96,11 @@
 }
 
 const actions = {
-  generateRoutes({ commit }, info) {
+  generateRoutes({ commit }, menu) {
     return new Promise(resolve => {
-      // const accessedRoutes
-
-      // getMenuList().then(routes => {
-      //   const asyncRoutes = getAsyncRoutes(routes.data) // 瀵硅矾鐢辨牸寮忚繘琛屽鐞�
-      //   commit('SET_ROUTES', asyncRoutes)
-      //   resolve(asyncRoutes)
-      // })
-
-      // '0'浠h〃false,'1'浠h〃true
-      const routes = [
-        {
-          path: '/redirect',
-          component: 'Layout',
-          hidden: '1',
-          children: [
-            {
-              path: '/redirect/:path(.*)',
-              component: '/redirect/index'
-            }
-          ]
-        },
-        {
-          path: '/',
-          component: 'Layout',
-          redirect: '/index',
-          children: [{
-            path: 'index',
-            name: 'index',
-            component: '/xtsy/index',
-            meta: { title: '绯荤粺棣栭〉', icon: 'el-icon-house', affix: '1' }
-          }]
-        },
-        // {
-        //   path: '/',
-        //   component: 'Layout',
-        //   redirect: '/dashboard',
-        //   children: [{
-        //     path: 'dashboard',
-        //     name: 'Dashboard',
-        //     component: '/dashboard/index'
-        //   }]
-        // },
-        // {
-        //   path: '/xtsy',
-        //   component: 'Layout',
-        //   redirect: '/stxy/index',
-        //   children: [
-        //     {
-        //       path: 'index',
-        //       name: 'Form',
-        //       component: '/xtsy/index',
-        //       meta: { title: '绯荤粺棣栭〉', icon: 'form', affix: '1' }
-        //     }
-        //   ]
-        // },
-        {
-          path: '/jcsz',
-          component: 'Layout',
-          redirect: '/jcsz/zzjg',
-          name: 'jcsz',
-          meta: { title: '鍩虹璁剧疆', icon: 'el-icon-setting' },
-          children: [
-            {
-              path: 'zzjg',
-              name: 'Table',
-              component: '/jcsz/zzjg',
-              meta: { title: '缁勭粐鏋舵瀯', icon: '' }
-            },
-            {
-              path: 'rwgl',
-              name: 'rwgl',
-              component: '/jcsz/rwgl',
-              meta: { title: '浠诲姟绠$悊', icon: '' }
-            }
-          ]
-        },
-        {
-          path: '/zzmx',
-          component: 'Layout',
-          redirect: '/zzmx/gylx',
-          name: 'zzmx',
-          meta: { title: '鍒堕�犳ā鍨�', icon: 'el-icon-s-help' },
-          children: [
-            {
-              path: 'gylx',
-              name: 'gylx',
-              component: '/zzmx/gylx',
-              meta: { title: '鍏泭璺嚎', icon: '' }
-            },
-            {
-              path: 'jpgj',
-              name: 'jpgj',
-              component: '/zzmx/jpgj',
-              meta: { title: '鑺傛媿宸ヤ环', icon: '' }
-            },
-            {
-              path: 'test',
-              name: 'test',
-              component: '/zzmx/test',
-              meta: { title: '娴嬭瘯椤甸潰', icon: '' }
-            }
-          ]
-        }
-
-      ]
-      const asyncRoutes = getAsyncRoutes(routes)
-      asyncRoutes.push({ path: '*', redirect: '/404', hidden: true })
-      commit('SET_ROUTES', asyncRoutes)
-      resolve(asyncRoutes)
+      const newRoutes = getAsyncRoutes(asyncRoutes, menu)
+      commit('SET_ROUTES', newRoutes)
+      resolve(newRoutes)
     })
   }
 }

--
Gitblit v1.9.3