.env | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/api/login/index.ts | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/config/axios/config.ts | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/hooks/web/useCache.ts | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/store/modules/permission.ts | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/store/modules/user.ts | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
types/env.d.ts | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
.env
@@ -16,22 +16,16 @@ # 接口地址 VITE_API_URL=/admin-api # 平台接口地址 VITE_PLAT_API_URL=/admin-api # 租户开关 VITE_APP_TENANT_ENABLE=true # 文档地址的开关 VITE_APP_DOCALERT_ENABLE=true # 默认账户密码 VITE_APP_DEFAULT_LOGIN_TENANT = iailab VITE_APP_DEFAULT_LOGIN_USERNAME = admin VITE_APP_DEFAULT_LOGIN_PASSWORD = admin123 VITE_TENANT_ID=174 VITE_APP_CODE=xmcsms ## 平台授权URL VITE_AUTH2_LOGIN_URL='http://172.16.8.100:48080/admin-api/system/oauth2/token' src/api/login/index.ts
@@ -41,6 +41,11 @@ return request.get({ url: plat_url + '/system/auth/get-permission-info' }) } // 获取应用菜单信息 export const getAppInfo = () => { return request.get({ url: plat_url + '/system/auth/get-app-permission-info' }) } // 获取验证图片以及 token export const getCode = (data) => { return request.postOriginal({ url: plat_url + '/system/captcha/get', data }) src/config/axios/config.ts
@@ -12,7 +12,7 @@ /** * 平台请求基础路径 */ plat_url: import.meta.env.VITE_PLAT_URL + import.meta.env.VITE_PLAT_API_URL, plat_url: import.meta.env.VITE_PLAT_URL + import.meta.env.VITE_API_URL, /** * 接口成功返回状态码 */ src/hooks/web/useCache.ts
@@ -37,3 +37,19 @@ wsCache.delete(CACHE_KEY.ROLE_ROUTERS) // 注意,不要清理 LoginForm 登录表单 } export const useSessionCache = (type: CacheType = 'sessionStorage') => { const wsSessionCache: WebStorageCache = new WebStorageCache({ storage: type }) return { wsSessionCache } } export const deleteUserSessionCache = () => { const { wsSessionCache } = useSessionCache() wsSessionCache.delete(CACHE_KEY.ROLE_ROUTERS) // 注意,不要清理 用户和 LoginForm 登录表单 } src/store/modules/permission.ts
@@ -3,10 +3,10 @@ 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' import Layout from "@/layout/Layout.vue"; const { wsCache } = useCache() const { wsSessionCache } = useSessionCache() export interface PermissionState { routers: AppRouteRecordRaw[] @@ -36,8 +36,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一定要放到最后面 @@ -53,7 +53,6 @@ } } ]) console.log(this.addRouters) // 渲染菜单的所有路由 this.routers = cloneDeep(remainingRouter).concat(routerMap) resolve() 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() { types/env.d.ts
@@ -14,9 +14,6 @@ readonly VITE_DEV: string readonly VITE_APP_CAPTCHA_ENABLE: string readonly VITE_APP_TENANT_ENABLE: string readonly VITE_APP_DEFAULT_LOGIN_TENANT: string readonly VITE_APP_DEFAULT_LOGIN_USERNAME: string readonly VITE_APP_DEFAULT_LOGIN_PASSWORD: string readonly VITE_APP_DOCALERT_ENABLE: string readonly VITE_BASE_URL: string readonly VITE_PLAT_URL: string @@ -32,6 +29,7 @@ readonly VITE_SOURCEMAP: string readonly VITE_OUT_DIR: string readonly VITE_TENANT_ID: string readonly VITE_APP_CODE: string } declare global {