From f5c803e09e10af90988194aa4a2199f5085a50fb Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期四, 05 十二月 2024 16:58:40 +0800
Subject: [PATCH] 优化与平台的菜单对接,需要更新平台最新代码

---
 src/store/modules/user.ts |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts
index b386180..176152e 100644
--- a/src/store/modules/user.ts
+++ b/src/store/modules/user.ts
@@ -1,10 +1,18 @@
 import { store } from '@/store'
 import { defineStore } from 'pinia'
 import { getAccessToken, removeToken } from '@/utils/auth'
-import { CACHE_KEY, useCache, deleteUserCache } from '@/hooks/web/useCache'
-import { getInfo, loginOut } from '@/api/login'
+import {
+  CACHE_KEY,
+  useCache,
+  deleteUserCache,
+  useSessionCache,
+  deleteUserSessionCache
+} from '@/hooks/web/useCache'
+import {getAppInfo, getInfo, loginOut} from '@/api/login'
+import * as AppApi from '@/api/system/app'
 
 const { wsCache } = useCache()
+const { wsSessionCache } = useSessionCache()
 
 interface UserVO {
   id: number
@@ -53,16 +61,21 @@
         this.resetState()
         return null
       }
-      let userInfo = wsCache.get(CACHE_KEY.USER)
-      if (!userInfo) {
-        userInfo = await getInfo()
-      }
+      const userInfo = await getInfo()
+      const appInfo = await getAppInfo()
       this.permissions = userInfo.permissions
       this.roles = userInfo.roles
       this.user = userInfo.user
       this.isSetUser = true
       wsCache.set(CACHE_KEY.USER, userInfo)
-      wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
+      //如果localStorage中有应用code,说明是从平台点击应用跳转过来
+      const appId = localStorage.getItem(import.meta.env.VITE_APP_CODE)
+      if(appId) {
+        const data = await AppApi.getAppMenuList(appId)
+        wsSessionCache.set(CACHE_KEY.ROLE_ROUTERS, data)
+      } else {
+        wsSessionCache.set(CACHE_KEY.ROLE_ROUTERS, appInfo.menus)
+      }
     },
     async setUserAvatarAction(avatar: string) {
       const userInfo = wsCache.get(CACHE_KEY.USER)
@@ -82,6 +95,8 @@
       await loginOut()
       removeToken()
       deleteUserCache() // 删除用户缓存
+      deleteUserSessionCache()
+      localStorage.clear()
       this.resetState()
     },
     resetState() {

--
Gitblit v1.9.3