From 04b1a9cfde4049be9a38b9832d5289d4a192c883 Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期五, 15 五月 2026 16:29:33 +0800
Subject: [PATCH] 加班申请模块和审批流程公共组件

---
 src/store/modules/permission.js |  117 ++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 69 insertions(+), 48 deletions(-)

diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index 8a2b1a9..0b11d2e 100644
--- a/src/store/modules/permission.js
+++ b/src/store/modules/permission.js
@@ -1,9 +1,10 @@
 import auth from '@/plugins/auth'
 import router, { constantRoutes, dynamicRoutes } from '@/router'
 import { getRouters } from '@/api/menu'
-import Layout from '@/layout/index'
-import ParentView from '@/components/ParentView'
-import InnerLink from '@/layout/components/InnerLink'
+import Layout from '@/layout/index'
+import ParentView from '@/components/ParentView'
+import InnerLink from '@/layout/components/InnerLink'
+import useUserStore from '@/store/modules/user'
 
 // 鍖归厤views閲岄潰鎵�鏈夌殑.vue鏂囦欢
 const modules = import.meta.glob('./../../views/**/*.vue')
@@ -36,27 +37,62 @@
         return new Promise(resolve => {
           // 鍚戝悗绔姹傝矾鐢辨暟鎹�
           getRouters().then(res => {
-            const sdata = JSON.parse(JSON.stringify(res.data))
-            const rdata = JSON.parse(JSON.stringify(res.data))
-            const defaultData = JSON.parse(JSON.stringify(res.data))
+            const aiEnabled = Number(useUserStore().aiEnabled) === 1
+            const rawRoutes = filterAiFeatureRoutes(res.data, aiEnabled)
+            const sdata = JSON.parse(JSON.stringify(rawRoutes))
+            const rdata = JSON.parse(JSON.stringify(rawRoutes))
+            const defaultData = JSON.parse(JSON.stringify(rawRoutes))
             const sidebarRoutes = filterAsyncRouter(sdata)
             const rewriteRoutes = filterAsyncRouter(rdata, false, true)
-            const defaultRoutes = filterAsyncRouter(defaultData)
-            const asyncRoutes = filterDynamicRoutes(dynamicRoutes)
-            asyncRoutes.forEach(route => { router.addRoute(route) })
-            this.setRoutes(rewriteRoutes)
-            this.setSidebarRouters(constantRoutes.concat(sidebarRoutes))
-            this.setDefaultRoutes(sidebarRoutes)
-            this.setTopbarRoutes(defaultRoutes)
-            resolve(rewriteRoutes)
-          })
-        })
+            const defaultRoutes = filterAsyncRouter(defaultData)
+            const asyncRoutes = filterDynamicRoutes(dynamicRoutes)
+            asyncRoutes.forEach(route => { router.addRoute(route) })
+            this.setRoutes(rewriteRoutes)
+            const constantSidebarRoutes = filterAiFeatureRoutes(constantRoutes, aiEnabled)
+            // 灏嗚储鍔$鐞嗚矾鐢卞悎骞跺埌渚ц竟鏍�
+            this.setSidebarRouters(constantSidebarRoutes.concat(sidebarRoutes))
+            this.setDefaultRoutes(sidebarRoutes)
+            this.setTopbarRoutes(defaultRoutes)
+            resolve(rewriteRoutes)
+          })
+        })
       }
     }
   })
 
 // 閬嶅巻鍚庡彴浼犳潵鐨勮矾鐢卞瓧绗︿覆锛岃浆鎹负缁勪欢瀵硅薄
-function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
+function filterAiFeatureRoutes(routes = [], aiEnabled = false) {
+  if (aiEnabled) {
+    return routes
+  }
+  return routes.reduce((acc, route) => {
+    if (!route || isAiFeatureRoute(route)) {
+      return acc
+    }
+    const nextRoute = { ...route }
+    if (Array.isArray(nextRoute.children) && nextRoute.children.length > 0) {
+      nextRoute.children = filterAiFeatureRoutes(nextRoute.children, aiEnabled)
+    }
+    acc.push(nextRoute)
+    return acc
+  }, [])
+}
+
+function isAiFeatureRoute(route = {}) {
+  const path = String(route.path || '').toLowerCase()
+  const component = String(route.component || '').toLowerCase()
+  const name = String(route.name || '').toLowerCase()
+  const title = String(route?.meta?.title ?? route?.title ?? '')
+
+  return (
+    path.includes('chathome') ||
+    component.includes('chathome') ||
+    name.includes('chathome') ||
+    title.includes('AI')
+  )
+}
+
+function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
   return asyncRouterMap.filter(route => {
     if (type && route.children) {
       route.children = filterChildren(route.children)
@@ -83,36 +119,21 @@
   })
 }
 
-function filterChildren(childrenMap, lastRouter = false) {
+function filterChildren(childrenMap, lastRouter = false) {
   var children = []
-  childrenMap.forEach((el, index) => {
-    if (el.children && el.children.length) {
-      if (el.component === 'ParentView' && !lastRouter) {
-        el.children.forEach(c => {
-          c.path = el.path + '/' + c.path
-          if (c.children && c.children.length) {
-            children = children.concat(filterChildren(c.children, c))
-            return
-          }
-          children.push(c)
-        })
-        return
-      }
+  childrenMap.forEach(el => {
+    el.path = lastRouter ? lastRouter.path + '/' + el.path : el.path
+    if (el.children && el.children.length && el.component === 'ParentView') {
+      children = children.concat(filterChildren(el.children, el))
+    } else {
+      children.push(el)
     }
-    if (lastRouter) {
-      el.path = lastRouter.path + '/' + el.path
-      if (el.children && el.children.length) {
-        children = children.concat(filterChildren(el.children, el))
-        return
-      }
-    }
-    children = children.concat(el)
   })
-  return children
-}
-
-// 鍔ㄦ�佽矾鐢遍亶鍘嗭紝楠岃瘉鏄惁鍏峰鏉冮檺
-export function filterDynamicRoutes(routes) {
+  return children
+}
+
+// 鍔ㄦ�佽矾鐢遍亶鍘嗭紝楠岃瘉鏄惁鍏峰鏉冮檺
+export function filterDynamicRoutes(routes) {
   const res = []
   routes.forEach(route => {
     if (route.permissions) {
@@ -129,14 +150,14 @@
 }
 
 export const loadView = (view) => {
-  let res;
+  let res
   for (const path in modules) {
-    const dir = path.split('views/')[1].split('.vue')[0];
+    const dir = path.split('views/')[1].split('.vue')[0]
     if (dir === view) {
-      res = () => modules[path]();
+      res = () => modules[path]()
     }
   }
-  return res;
+  return res
 }
 
 export default usePermissionStore

--
Gitblit v1.9.3