|
|
@@ -6,7 +6,12 @@ import { resolveRoutePath } from '@/utils'
|
|
|
import { cloneDeep } from 'lodash-es'
|
|
|
import useSettingsStore from './settings'
|
|
|
import api from '@/api'
|
|
|
-
|
|
|
+import useUserStore from'@/store/modules/user.ts'
|
|
|
+import { asyncRoutes } from "@/router/routes"; // 请根据实际路径调整
|
|
|
+import {
|
|
|
+ preprocessRoutes,
|
|
|
+ convertToTreeData
|
|
|
+} from "@/utils/composables/routeUtils"; // 导入工具方法
|
|
|
|
|
|
const useRouteStore = defineStore(
|
|
|
// 唯一ID
|
|
|
@@ -161,10 +166,10 @@ const useRouteStore = defineStore(
|
|
|
default:
|
|
|
if (route.component) {
|
|
|
route.component = views[`../../views${route.component}.vue`]
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
else {
|
|
|
delete route.component
|
|
|
}
|
|
|
@@ -176,6 +181,34 @@ const useRouteStore = defineStore(
|
|
|
return route
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ function filterTreeByPerms(nestedArray: any, referenceArray: any) {
|
|
|
+ // 创建参考值的Set以便快速查找
|
|
|
+ const referenceSet = new Set(referenceArray.map((item: any) => item.permsId));
|
|
|
+ function filterRecursive(data: any) {
|
|
|
+ return data.reduce((result: any, item: any) => {
|
|
|
+ // 检查当前项是否在参考数组中
|
|
|
+ const isMatch = referenceSet.has(`${item.id}`);
|
|
|
+
|
|
|
+ // 深度复制当前项(保留原始数据)
|
|
|
+ const newItem = {...item};
|
|
|
+
|
|
|
+ // 递归处理子项
|
|
|
+ if (newItem.children && newItem.children.length) {
|
|
|
+ newItem.children = filterRecursive(newItem.children);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果当前项匹配或有匹配的子项,则保留
|
|
|
+ if (isMatch || (newItem.children && newItem.children.length)) {
|
|
|
+ result.push(newItem);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }, []);
|
|
|
+ }
|
|
|
+
|
|
|
+ return filterRecursive(nestedArray);
|
|
|
+ }
|
|
|
// 生成路由(后端获取)
|
|
|
async function generateRoutesAtBack() {
|
|
|
await api.menuApi.getTenantConfig({
|
|
|
@@ -183,10 +216,22 @@ const useRouteStore = defineStore(
|
|
|
}).then((res) => {
|
|
|
// console.log(JSON.parse(res.data.sysConfig))
|
|
|
// 设置 routes 数据
|
|
|
- routesRaw.value = converDeprecatedAttribute(formatBackRoutes(JSON.parse(res.data.sysConfig)) as any)
|
|
|
- // console.log(routesRaw.value,66666)
|
|
|
+ // const routes = (JSON.parse(res.data.sysConfig))
|
|
|
+ // const sysPerms = (JSON.parse(res.data.sysPerms))
|
|
|
+ const userInfo = JSON.parse(localStorage.getItem('userInfo'))
|
|
|
+ let routes = preprocessRoutes(asyncRoutes);
|
|
|
+ console.log(123123123, routes)
|
|
|
+ if(userInfo) {
|
|
|
+ let arr = []
|
|
|
+ arr = filterTreeByPerms(routes, userInfo.auths)
|
|
|
+ routesRaw.value = converDeprecatedAttribute(formatBackRoutes(arr) as any)
|
|
|
+ } else {
|
|
|
+ routesRaw.value = converDeprecatedAttribute(formatBackRoutes(JSON.parse(res.data.sysConfig)) as any)
|
|
|
+ }
|
|
|
isGenerate.value = true
|
|
|
- }).catch(() => {})
|
|
|
+ }).catch((e) => {
|
|
|
+ console.log(123, e)
|
|
|
+ })
|
|
|
}
|
|
|
// 生成路由(文件系统生成)
|
|
|
function generateRoutesAtFilesystem(asyncRoutes: RouteRecordRaw[]) {
|