mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/fe-manage.git
synced 2025-12-10 19:36:46 +08:00
fix bug 用户中心接口调整
This commit is contained in:
22
src/App.vue
22
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,8 +93,8 @@ async function initDict(key) {
|
||||
store.commit("SET_DICT", {key, data: list});
|
||||
}
|
||||
|
||||
function getUserPermission(){
|
||||
request(USER_PERMISSION,{permissionType:'PAGE'}).then(res=>{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user