From 2661f1cffa19d2f267561179127dce7c032f7071 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 06 五月 2026 15:29:49 +0800
Subject: [PATCH] feat(layout): 添加AI功能开关控制
---
src/store/modules/user.js | 53 ++++++++++++++------------
src/layout/index.vue | 5 ++
src/store/modules/permission.js | 48 ++++++++++++++++++++---
3 files changed, 73 insertions(+), 33 deletions(-)
diff --git a/src/layout/index.vue b/src/layout/index.vue
index a1bb724..03c13ba 100644
--- a/src/layout/index.vue
+++ b/src/layout/index.vue
@@ -16,7 +16,7 @@
<app-main />
<settings ref="settingRef" />
</div>
- <AIChatSidebar />
+ <AIChatSidebar v-if="aiEnabled" />
</div>
</template>
@@ -28,15 +28,18 @@
import defaultSettings from "@/settings";
import useAppStore from "@/store/modules/app";
+ import useUserStore from "@/store/modules/user";
import useSettingsStore from "@/store/modules/settings";
const settingsStore = useSettingsStore();
+ const userStore = useUserStore();
const theme = computed(() => settingsStore.theme);
const sideTheme = computed(() => settingsStore.sideTheme);
const sidebar = computed(() => useAppStore().sidebar);
const device = computed(() => useAppStore().device);
const needTagsView = computed(() => settingsStore.tagsView);
const fixedHeader = computed(() => settingsStore.fixedHeader);
+ const aiEnabled = computed(() => Number(userStore.aiEnabled) === 1);
const classObj = computed(() => ({
hideSidebar: !sidebar.value.opened,
diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index f7a7044..d3f0594 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,9 +37,11 @@
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)
@@ -57,7 +60,38 @@
})
// 閬嶅巻鍚庡彴浼犳潵鐨勮矾鐢卞瓧绗︿覆锛岃浆鎹负缁勪欢瀵硅薄
-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)
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index 4f3eab4..ea358d1 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -7,13 +7,14 @@
const useUserStore = defineStore(
'user',
{
- state: () => ({
- token: getToken(),
- id: '',
- name: '',
- avatar: '',
- roles: [],
- permissions: []
+ state: () => ({
+ token: getToken(),
+ id: '',
+ name: '',
+ avatar: '',
+ roles: [],
+ permissions: [],
+ aiEnabled: 0
}),
actions: {
// 鐧诲綍
@@ -58,29 +59,31 @@
this.id = user.userId
this.name = user.userName
this.avatar = avatar
- this.currentFactoryName = user.currentFactoryName
- this.nickName = user.nickName
- this.roleName = user.roles[0].roleName
- this.currentDeptId = user.tenantId
- this.currentLoginTime = this.getCurrentTime()
- resolve(res)
- }).catch(error => {
- reject(error)
- })
- })
+ this.currentFactoryName = user.currentFactoryName
+ this.nickName = user.nickName
+ this.roleName = user.roles[0].roleName
+ this.currentDeptId = user.tenantId
+ this.currentLoginTime = this.getCurrentTime()
+ this.aiEnabled = Number(res.aiEnabled) === 1 ? 1 : 0
+ resolve(res)
+ }).catch(error => {
+ reject(error)
+ })
+ })
},
// 閫�鍑虹郴缁�
logOut() {
return new Promise((resolve, reject) => {
logout(this.token).then(() => {
- this.token = ''
- this.roles = []
- this.permissions = []
- removeToken()
- resolve()
- }).catch(error => {
- reject(error)
- })
+ this.token = ''
+ this.roles = []
+ this.permissions = []
+ this.aiEnabled = 0
+ removeToken()
+ resolve()
+ }).catch(error => {
+ reject(error)
+ })
})
},
// 鐧诲綍鏍¢獙
--
Gitblit v1.9.3