diff --git a/src/App.vue b/src/App.vue index 6ce19a10..6cdfd8ae 100644 --- a/src/App.vue +++ b/src/App.vue @@ -29,7 +29,7 @@ import zhCN from "ant-design-vue/es/locale/zh_CN"; import * as api1 from "@/api/index1"; import * as api2 from "@/api/index"; import {request} from "@/api/request"; -import {USER_PERMISSION} from "@/api/apis"; +import {USER_PERMISSION, VALIDATE_TOKEN} from "@/api/apis"; const store = useStore(); const isLogin = ref(false); @@ -37,7 +37,6 @@ const isLogin = ref(false); console.log("版本3.1.0------------"); - // 监听关闭浏览器 let time1 = ref(0); let time2 = ref(0); @@ -54,8 +53,7 @@ function beforeunloadHandler() { } function init() { - getUserInfo(); - getUserPermission(); + validateToken(); initDict("content_type"); //内容分类 initDict("project_level"); //项目级别 initDict("project_sys"); //培训分类 @@ -66,6 +64,17 @@ function init() { initDict("band"); //band } +async function validateToken() { + try{ + await request(VALIDATE_TOKEN) + await getUserInfo(); + await getUserPermission(); + }catch (e) { + console.log('token失效 跳转到登录页') + } + +} + function unloadHandler() { time2.value = new Date().getTime() - time1.value; if (time2.value <= 5) { @@ -84,9 +93,9 @@ async function initDict(key) { store.commit("SET_DICT", {key, data: list}); } -function getUserPermission(){ - request(USER_PERMISSION,{permissionType:'PAGE'}).then(res=>{ - store.commit("SET_PERMISSION", res.data?.map(s=>s.url)); +async function getUserPermission() { + return request(USER_PERMISSION, {permissionType: 'PAGE'}).then(res => { + store.commit("SET_PERMISSION", res.data?.map(s => s.url)); }) } @@ -109,6 +118,7 @@ const getDictList = (param) => api1.getDictTree({code: param,}).then((res) => re text-align: center !important; } } + .ant-table-tbody > tr:hover:not(.ant-table-expanded-row):not(.ant-table-row-selected) > td { background: #f6f9fd; } diff --git a/src/api/apis.js b/src/api/apis.js index 75887b62..7f1f7c7a 100644 --- a/src/api/apis.js +++ b/src/api/apis.js @@ -32,3 +32,5 @@ export const ORG_CHILD_LIST = "/admin/thirdApi/org/info"; export const AUDIENCE_LIST = "/admin/thirdApi/audience/userAudiences"; export const USER_PERMISSION = "/admin/thirdApi/permission/listByUser"; +export const VALIDATE_TOKEN = "/admin/thirdApi/validateToken"; +export const REFRESH_TOKEN = "/admin/thirdApi/refreshToken"; diff --git a/src/api/request.js b/src/api/request.js index a41c60eb..9798c01c 100644 --- a/src/api/request.js +++ b/src/api/request.js @@ -1,8 +1,9 @@ import {isRef, reactive, ref, toRefs, unref, watch, watchEffect} from "vue"; -import {getCookieForName, throttle} from "@/api/method"; +import {getCookieForName, setCookie, throttle} from "@/api/method"; import JSONBigInt from "json-bigint"; import router from "@/router"; import {message} from "ant-design-vue"; +import {REFRESH_TOKEN, VALIDATE_TOKEN} from "@/api/apis"; const JSONBigIntStr = JSONBigInt({ storeAsString: true }); @@ -405,13 +406,21 @@ export async function request(_url, params) { if (res.code === 0 || res.code === 200) { return res; } - if (res.code === 1000) { + if (res.code === 1000 || res.code === 1002) { (process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'alpine') ? router.push({path: 'login', query: { returnUrl: router.currentRoute.value.fullPath }}) : (window.location.href = process.env.VUE_APP_LOGIN_URL + encodeURIComponent(window.location.protocol + process.env.VUE_APP_BOE_API_URL + process.env.VUE_APP_BASE + router.currentRoute.value.fullPath)) localStorage.removeItem('refreshPage') return Promise.reject(res); + }else if(res.code=== 1001){ + request(REFRESH_TOKEN).then((res)=>{ + if(res.code===0 || res.code === 200){ + setCookie('token',res.data) + return request(_url, params) + } + }) } + //刷新token res.show ? message.error(res.msg):message.error('系统接口数据异常,请联系管理员'); return Promise.reject(res); });