From 3d73201f0830320c703cfb3d36b47976eb3d94e7 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期四, 11 五月 2023 17:34:21 +0800
Subject: [PATCH] 1.生产进度报表提交

---
 src/store/modules/permission.js |  209 ++++++++++++++++-----------------------------------
 1 files changed, 67 insertions(+), 142 deletions(-)

diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index 8e7e811..706fed9 100644
--- a/src/store/modules/permission.js
+++ b/src/store/modules/permission.js
@@ -1,5 +1,6 @@
-import { commonRoutes } from '@/router'
+import { asyncRoutes, asyncRoutesCloud, commonRoutes } from '@/router'
 import Layout from '@/layout'
+import { getCookie } from '@/utils/auth'
 
 // 鍒ゆ柇鏄惁鏈夋潈闄�
 function hasPermission(roles, route) {
@@ -13,52 +14,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,106 +97,23 @@
 }
 
 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: '/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: 'yhqd',
-              name: 'yhqd',
-              component: '/jcsz/yhqd',
-              meta: { title: '鐢ㄦ埛娓呭崟', icon: '' }
-            },
-            {
-              path: 'jsqd',
-              name: 'jsqd',
-              component: '/jcsz/jsqd',
-              meta: { title: '瑙掕壊娓呭崟', icon: '' }
-            },
-            {
-              path: 'wldw',
-              name: 'wldw',
-              component: '/jcsz/wldw',
-              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)
-      console.log(asyncRoutes, 1)
+      // const newRoutes = getAsyncRoutes(asyncRoutes, menu)
+      let newRoutes
+      if (getCookie('cloud')) {
+        const arr = menu.map(i => i.code)
+        newRoutes = asyncRoutesCloud.filter(i => {
+          if (arr.includes(i.code)) {
+            return i
+          }
+        })
+        newRoutes.push({ path: '*', redirect: '/404', hidden: true })
+      } else {
+        newRoutes = getAsyncRoutes(asyncRoutes, menu)
+      }
+      commit('SET_ROUTES', newRoutes)
+      resolve(newRoutes)
     })
   }
 }

--
Gitblit v1.9.3