From 2717813966ced88c6a1635663dd01b502158a1b8 Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期四, 05 十二月 2024 17:01:36 +0800
Subject: [PATCH] 1、路由信息存储与session 2、修改与脚手架的跳转对接方式

---
 src/views/data/plan/category/CategoryForm.vue |    6 +-
 src/views/system/menu/index.vue               |    5 +-
 src/store/modules/permission.ts               |    8 ++--
 src/views/system/appmenu/AppMenuForm.vue      |    6 +-
 src/views/system/appmenu/index.vue            |    6 ++-
 src/views/data/ind/category/CategoryForm.vue  |    6 +-
 src/store/modules/user.ts                     |   15 ++++++-
 src/layout/components/Logo/src/Logo.vue       |   11 +++--
 src/views/Home/Index.vue                      |   18 +++++----
 src/api/login/index.ts                        |    8 ++--
 .env.prod                                     |   20 ++++++---
 src/views/system/menu/MenuForm.vue            |    6 +-
 12 files changed, 69 insertions(+), 46 deletions(-)

diff --git a/.env.prod b/.env.prod
index 50729b1..567c520 100644
--- a/.env.prod
+++ b/.env.prod
@@ -1,15 +1,15 @@
-# 生产环境:只在打包时使用
+# 测试环境:只在打包时使用
 NODE_ENV=production
 
 VITE_DEV=false
 
 # 请求路径
-VITE_BASE_URL='http://localhost:48080'
+VITE_BASE_URL='http://10.88.4.131'
 
 # 文件上传类型:server - 后端上传, client - 前端直连上传,仅支持S3服务
 VITE_UPLOAD_TYPE=server
 # 上传路径
-VITE_UPLOAD_URL='http://localhost:48080/admin-api/infra/file/upload'
+VITE_UPLOAD_URL='http://10.88.4.131/admin-api/infra/file/upload'
 
 # 接口地址
 VITE_API_URL=/admin-api
@@ -24,10 +24,16 @@
 VITE_SOURCEMAP=false
 
 # 打包路径
-VITE_BASE_PATH=/
+VITE_BASE_PATH=/plat
+
+# 数据采集服务所在服务器,映射截图图片用
+VITE_VIDEO_CAMERA_DOMAIN='10.88.4.131'
 
 # 输出路径
-VITE_OUT_DIR=dist-prod
+VITE_OUT_DIR=dist
 
-# 商城H5会员端域名
-VITE_MALL_H5_DOMAIN='http://'
+# 公共静态文件路径
+VITE_STATIC_DIR=/plat/
+
+# 验证码的开关
+VITE_APP_CAPTCHA_ENABLE=false
diff --git a/src/api/login/index.ts b/src/api/login/index.ts
index e6d9f52..4b82a93 100644
--- a/src/api/login/index.ts
+++ b/src/api/login/index.ts
@@ -42,10 +42,10 @@
   return request.get({ url: '/system/auth/get-permission-info' })
 }
 
-// 获取用应用户权限信息
-export const getUserAppInfo = (id: number) => {
-  return request.get({ url: '/system/auth/get-app-permission-info?id=' + id })
-}
+// // 获取用应用户权限信息
+// export const getUserAppInfo = (id: number) => {
+//   return request.get({ url: '/system/auth/get-app-permission-info?id=' + id })
+// }
 
 //获取登录验证码
 export const sendSmsCode = (data: SmsCodeVO) => {
diff --git a/src/layout/components/Logo/src/Logo.vue b/src/layout/components/Logo/src/Logo.vue
index 98b17c3..ef80370 100644
--- a/src/layout/components/Logo/src/Logo.vue
+++ b/src/layout/components/Logo/src/Logo.vue
@@ -7,8 +7,11 @@
 import {isRelogin} from "@/config/axios/service";
 import router from "@/router";
 import type {RouteRecordRaw} from "vue-router";
-import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
+import {CACHE_KEY, useCache, useSessionCache} from "@/hooks/web/useCache";
+import {getAccessToken} from "@/utils/auth";
+import {getInfo} from "@/api/login";
 const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 
 defineOptions({ name: 'Logo' })
 
@@ -68,11 +71,11 @@
 
 /** 刷新所有菜单权限 */
 const gotoHome = async () => {
-  const userStore = useUserStoreWithOut()
   const permissionStore = usePermissionStoreWithOut()
   isRelogin.show = true
-  wsCache.set(CACHE_KEY.USER, null)
-  await userStore.setUserInfoAction()
+  let userInfo = await getInfo()
+  wsCache.set(CACHE_KEY.USER, userInfo)
+  wsSessionCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
   isRelogin.show = false
   // 后端过滤菜单
   await permissionStore.generateRoutes()
diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts
index 5e3287a..12ddb45 100644
--- a/src/store/modules/permission.ts
+++ b/src/store/modules/permission.ts
@@ -3,9 +3,9 @@
 import { cloneDeep } from 'lodash-es'
 import remainingRouter from '@/router/modules/remaining'
 import { flatMultiLevelRoutes, generateRoute } from '@/utils/routerHelper'
-import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import {CACHE_KEY, useSessionCache} from '@/hooks/web/useCache'
 
-const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 
 export interface PermissionState {
   routers: AppRouteRecordRaw[]
@@ -35,8 +35,8 @@
       return new Promise<void>(async (resolve) => {
         // 获得菜单列表,它在登录的时候,setUserInfoAction 方法中已经进行获取
         let res: AppCustomRouteRecordRaw[] = []
-        if (wsCache.get(CACHE_KEY.ROLE_ROUTERS)) {
-          res = wsCache.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[]
+        if (wsSessionCache.get(CACHE_KEY.ROLE_ROUTERS)) {
+          res = wsSessionCache.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[]
         }
         const routerMap: AppRouteRecordRaw[] = generateRoute(res)
         // 动态路由,404一定要放到最后面
diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts
index 1e8ae63..e4c45fd 100644
--- a/src/store/modules/user.ts
+++ b/src/store/modules/user.ts
@@ -1,10 +1,17 @@
 import { store } from '@/store'
 import { defineStore } from 'pinia'
 import { getAccessToken, removeToken } from '@/utils/auth'
-import { CACHE_KEY, useCache, deleteUserCache } from '@/hooks/web/useCache'
+import {
+  CACHE_KEY,
+  useCache,
+  deleteUserCache,
+  useSessionCache,
+  deleteUserSessionCache
+} from '@/hooks/web/useCache'
 import { getInfo, loginOut } from '@/api/login'
 
 const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 
 interface UserVO {
   id: number
@@ -61,9 +68,10 @@
       this.roles = userInfo.roles
       this.user = userInfo.user
       this.isSetUser = true
-      console.log(userInfo.menus)
       wsCache.set(CACHE_KEY.USER, userInfo)
-      wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
+      if(!wsSessionCache.get(CACHE_KEY.ROLE_ROUTERS)) {
+        wsSessionCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
+      }
     },
     async setUserAvatarAction(avatar: string) {
       const userInfo = wsCache.get(CACHE_KEY.USER)
@@ -83,6 +91,7 @@
       await loginOut()
       removeToken()
       deleteUserCache() // 删除用户缓存
+      deleteUserSessionCache() //删除路由缓存
       this.resetState()
     },
     resetState() {
diff --git a/src/views/Home/Index.vue b/src/views/Home/Index.vue
index 738039c..e931277 100644
--- a/src/views/Home/Index.vue
+++ b/src/views/Home/Index.vue
@@ -25,12 +25,13 @@
 
 import * as AppApi from '@/api/system/app'
 import {Apps} from "@/views/Home/types";
-import {CACHE_KEY, useCache} from "@/hooks/web/useCache";
+import {CACHE_KEY, useCache, useSessionCache} from "@/hooks/web/useCache";
 
 
 defineOptions({name: 'Home'})
 
 const {wsCache} = useCache()
+const {wsSessionCache} = useSessionCache()
 
 const loading = ref(true)
 
@@ -44,9 +45,9 @@
 const getAppMenuList = async (id, appCode) => {
   const data = await AppApi.getAppMenuList(id)
   let userInfo = wsCache.get(CACHE_KEY.USER)
-  userInfo.menus = data
+  // userInfo.menus = data
   wsCache.set(CACHE_KEY.USER, userInfo)
-  wsCache.set(CACHE_KEY.ROLE_ROUTERS, data)
+  wsSessionCache.set(CACHE_KEY.ROLE_ROUTERS, data)
   window.location.href = '/plat/index'
 }
 
@@ -70,11 +71,12 @@
   if (type === 0) {
     await getAppMenuList(id, appCode)
   } else {
-    const data = await AppApi.getAppMenuList(id)
-    let userInfo = wsCache.get(CACHE_KEY.USER)
-    userInfo.menus = data
-    wsCache.set(CACHE_KEY.USER, userInfo)
-    wsCache.set(CACHE_KEY.ROLE_ROUTERS, data)
+    // const data = await AppApi.getAppMenuList(id)
+    // let userInfo = wsCache.get(CACHE_KEY.USER)
+    // userInfo.menus = data
+    // wsCache.set(CACHE_KEY.USER, userInfo)
+    // wsSessionCache.set(CACHE_KEY.ROLE_ROUTERS, data)
+    localStorage.setItem(appCode, id)
     window.open(item.appDomain + '/index', '_blank')
     // window.open('/plat/shasteel', '_blank')
     // window.location.href = '/plat/shasteel'
diff --git a/src/views/data/ind/category/CategoryForm.vue b/src/views/data/ind/category/CategoryForm.vue
index d4bd86c..40cd2fb 100644
--- a/src/views/data/ind/category/CategoryForm.vue
+++ b/src/views/data/ind/category/CategoryForm.vue
@@ -33,13 +33,13 @@
 <script lang="ts" setup>
   import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
   import * as CategoryApi from '@/api/data/ind/category'
-  import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+  import {CACHE_KEY, useSessionCache} from '@/hooks/web/useCache'
   import { CommonStatusEnum, SystemMenuTypeEnum } from '@/utils/constants'
   import { defaultProps, handleTree } from '@/utils/tree'
 
   defineOptions({ name: 'IndItemCategoryForm' })
 
-  const { wsCache } = useCache()
+  const { wsSessionCache } = useSessionCache()
   const { t } = useI18n() // 国际化
   const message = useMessage() // 消息弹窗
 
@@ -114,7 +114,7 @@
     } finally {
       formLoading.value = false
       // 清空,从而触发刷新
-      wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
+      wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS)
     }
   }
 
diff --git a/src/views/data/plan/category/CategoryForm.vue b/src/views/data/plan/category/CategoryForm.vue
index 5bbbaad..8fa7de0 100644
--- a/src/views/data/plan/category/CategoryForm.vue
+++ b/src/views/data/plan/category/CategoryForm.vue
@@ -33,13 +33,13 @@
 <script lang="ts" setup>
 import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
 import * as CategoryApi from '@/api/data/plan/category'
-import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import {CACHE_KEY, useCache, useSessionCache} from '@/hooks/web/useCache'
 import { CommonStatusEnum, SystemMenuTypeEnum } from '@/utils/constants'
 import { defaultProps, handleTree } from '@/utils/tree'
 
 defineOptions({ name: 'PlanItemCategoryForm' })
 
-const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 
@@ -114,7 +114,7 @@
   } finally {
     formLoading.value = false
     // 清空,从而触发刷新
-    wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
+    wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS)
   }
 }
 
diff --git a/src/views/system/appmenu/AppMenuForm.vue b/src/views/system/appmenu/AppMenuForm.vue
index 3a7ad72..f8545cf 100644
--- a/src/views/system/appmenu/AppMenuForm.vue
+++ b/src/views/system/appmenu/AppMenuForm.vue
@@ -115,13 +115,13 @@
 <script lang="ts" setup>
 import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
 import * as MenuApi from '@/api/system/menu'
-import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import {CACHE_KEY, useCache, useSessionCache} from '@/hooks/web/useCache'
 import { CommonStatusEnum, SystemAppMenuTypeEnum } from '@/utils/constants'
 import { defaultProps, handleTree } from '@/utils/tree'
 
 defineOptions({ name: 'SystemAppMenuForm' })
 
-const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 
@@ -214,7 +214,7 @@
   } finally {
     formLoading.value = false
     // 清空,从而触发刷新
-    wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
+    wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS)
   }
 }
 
diff --git a/src/views/system/appmenu/index.vue b/src/views/system/appmenu/index.vue
index 66b4f35..ea3ef37 100644
--- a/src/views/system/appmenu/index.vue
+++ b/src/views/system/appmenu/index.vue
@@ -116,11 +116,12 @@
 import { handleTree } from '@/utils/tree'
 import * as MenuApi from '@/api/system/menu'
 import AppMenuForm from './AppMenuForm.vue'
-import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import {CACHE_KEY, useCache, useSessionCache} from '@/hooks/web/useCache'
 
 defineOptions({ name: 'SystemAppMenu' })
 
 const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 
@@ -190,7 +191,8 @@
     await message.confirm('即将更新缓存刷新浏览器!', '刷新菜单缓存')
     // 清空,从而触发刷新
     wsCache.delete(CACHE_KEY.USER)
-    wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
+    // wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
+    wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS)
     // 刷新浏览器
     location.reload()
   } catch {}
diff --git a/src/views/system/menu/MenuForm.vue b/src/views/system/menu/MenuForm.vue
index 2b4a90d..a5004d0 100644
--- a/src/views/system/menu/MenuForm.vue
+++ b/src/views/system/menu/MenuForm.vue
@@ -115,13 +115,13 @@
 <script lang="ts" setup>
 import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
 import * as MenuApi from '@/api/system/menu'
-import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import {CACHE_KEY, useCache, useSessionCache} from '@/hooks/web/useCache'
 import { CommonStatusEnum, SystemMenuTypeEnum } from '@/utils/constants'
 import { defaultProps, handleTree } from '@/utils/tree'
 
 defineOptions({ name: 'SystemMenuForm' })
 
-const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 
@@ -214,7 +214,7 @@
   } finally {
     formLoading.value = false
     // 清空,从而触发刷新
-    wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
+    wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS)
   }
 }
 
diff --git a/src/views/system/menu/index.vue b/src/views/system/menu/index.vue
index 4f280b5..a8fcc0e 100644
--- a/src/views/system/menu/index.vue
+++ b/src/views/system/menu/index.vue
@@ -125,11 +125,12 @@
 import { handleTree } from '@/utils/tree'
 import * as MenuApi from '@/api/system/menu'
 import MenuForm from './MenuForm.vue'
-import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
+import {CACHE_KEY, useCache, useSessionCache} from '@/hooks/web/useCache'
 
 defineOptions({ name: 'SystemMenu' })
 
 const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 const { t } = useI18n() // 国际化
 const message = useMessage() // 消息弹窗
 
@@ -186,7 +187,7 @@
     await message.confirm('即将更新缓存刷新浏览器!', '刷新菜单缓存')
     // 清空,从而触发刷新
     wsCache.delete(CACHE_KEY.USER)
-    wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
+    wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS)
     // 刷新浏览器
     location.reload()
   } catch {}

--
Gitblit v1.9.3