feat:更新协作信息

This commit is contained in:
leilei
2025-11-18 17:42:15 +08:00
parent ca93e91326
commit a894367dcc
22 changed files with 1085 additions and 458 deletions

View File

@@ -1,6 +1,6 @@
import Cookies from "js-cookie";
import router from '@/router';
const TokenKey = "token";
export function getToken() {
@@ -18,3 +18,54 @@ export function removeToken() {
return sessionStorage.removeItem(TokenKey);
}
//获取用户信息
export function getUserInfo() {
try {
const userData = sessionStorage.getItem("userData");
// 如果userData不存在执行未授权处理
if (!userData) {
handleUnauthorized();
return null;
}
// 尝试解析JSON数据
try {
const parsedData = JSON.parse(userData);
return parsedData;
} catch (parseError) {
console.error('用户数据格式错误无法解析JSON:', parseError);
// 数据格式错误也视为未登录
sessionStorage.removeItem("userData");
handleUnauthorized();
return null;
}
} catch (error) {
console.error('获取用户信息时发生错误:', error);
handleUnauthorized();
return null;
}
}
function handleUnauthorized() {
removeToken();
// 使用 nextTick 确保路由状态已更新
import('vue').then(({ nextTick }) => {
nextTick(() => {
const currentPath = router.currentRoute.value.fullPath;
if (router.currentRoute.value.path !== '/login') {
router.push({
path: '/login',
query: {
redirect: currentPath !== '/login' ? currentPath : undefined
}
});
} else {
window.location.reload();
}
});
});
}

View File

@@ -156,9 +156,10 @@ service.interceptors.response.use(
// if(currentPath == 'ConferencingRoom'){
// return Promise.resolve(responseData);
// }else{
return handleUnauthorized().then(() => {
return Promise.reject({ code: 401, message: '未授权' });
});
return handleUnauthorized()
// .then(() => {
// return Promise.reject({ code: 401, message: '未授权' });
// });
// }
case 500:
const serverErrorMsg = responseData.meta?.message || '服务器内部错误';
@@ -221,7 +222,7 @@ service.interceptors.response.use(
// });
// }
function handleUnauthorized() {
function handleUnauthorized() {
removeToken();
// 使用 nextTick 确保路由状态已更新

View File

@@ -716,3 +716,26 @@ export function removeDuplicate(arr) {
});
return newArr; // 返回一个新数组
}
export function createThrottle(func, delay){
let timeoutId;
let lastExecTime = 0;
return (...args) => {
const currentTime = Date.now();
// 立即执行第一次
if (currentTime - lastExecTime > delay) {
func.apply(this, args);
lastExecTime = currentTime;
} else {
// 清除之前的定时器,设置新的定时器
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
func.apply(this, args);
lastExecTime = Date.now();
}, delay);
}
};
};

View File

@@ -157,4 +157,4 @@ function isValidBox(x1, y1, x2, y2, imgWidth, imgHeight) {
x2 > x1 && y2 > y1 &&
x2 <= imgWidth && y2 <= imgHeight
);
}
}