fix: 调整加载个人信息逻辑
This commit is contained in:
@@ -27,7 +27,8 @@ import {
|
|||||||
type UserInfo,
|
type UserInfo,
|
||||||
userInfoKey,
|
userInfoKey,
|
||||||
removeToken,
|
removeToken,
|
||||||
getTokenInfo
|
getTokenInfo,
|
||||||
|
getUserInfo
|
||||||
} from "@/utils/auth";
|
} from "@/utils/auth";
|
||||||
|
|
||||||
/** 自动导入全部静态路由,无需再手动引入!匹配 src/router/modules 目录(任何嵌套级别)中具有 .ts 扩展名的所有文件,除了 remaining.ts 文件
|
/** 自动导入全部静态路由,无需再手动引入!匹配 src/router/modules 目录(任何嵌套级别)中具有 .ts 扩展名的所有文件,除了 remaining.ts 文件
|
||||||
@@ -129,6 +130,8 @@ router.beforeEach((to: ToRouteType, _from, next) => {
|
|||||||
whiteList.includes(to.fullPath) ? next(_from.fullPath) : next();
|
whiteList.includes(to.fullPath) ? next(_from.fullPath) : next();
|
||||||
}
|
}
|
||||||
const data = getTokenInfo();
|
const data = getTokenInfo();
|
||||||
|
/**获取个人信息 */
|
||||||
|
getUserInfo();
|
||||||
if (!data.isExpire) {
|
if (!data.isExpire) {
|
||||||
// 无权限跳转403页面
|
// 无权限跳转403页面
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { storageLocal } from "@pureadmin/utils";
|
import { storageLocal } from "@pureadmin/utils";
|
||||||
import { useUserStoreHook } from "@/store/modules/user";
|
import { useUserStoreHook } from "@/store/modules/user";
|
||||||
|
import { getUserInfoAPI } from "@/api/login";
|
||||||
|
|
||||||
export interface UserInfo {
|
export interface UserInfo {
|
||||||
/** 用户名 */
|
/** 用户名 */
|
||||||
@@ -114,3 +115,16 @@ export function getTokenInfo(): {
|
|||||||
export const hasAuth = (auth: string) => {
|
export const hasAuth = (auth: string) => {
|
||||||
return useUserStoreHook().permissions.includes(auth);
|
return useUserStoreHook().permissions.includes(auth);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**获取用户信息 */
|
||||||
|
export const getUserInfo = async () => {
|
||||||
|
const res = await getUserInfoAPI();
|
||||||
|
if (res.success) {
|
||||||
|
const user = storageLocal().getItem<object>(userInfoKey);
|
||||||
|
storageLocal().setItem(userInfoKey, {
|
||||||
|
...user,
|
||||||
|
...res.data
|
||||||
|
});
|
||||||
|
setUserInfo(res.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -34,8 +34,6 @@ import Check from "@iconify-icons/ep/check";
|
|||||||
import User from "@iconify-icons/ri/user-3-fill";
|
import User from "@iconify-icons/ri/user-3-fill";
|
||||||
import Info from "@iconify-icons/ri/information-line";
|
import Info from "@iconify-icons/ri/information-line";
|
||||||
import { GetCaptchaAPI } from "@/api/login";
|
import { GetCaptchaAPI } from "@/api/login";
|
||||||
import { getUserInfoAPI } from "@/api/login";
|
|
||||||
import { setUserInfo } from "@/utils/auth";
|
|
||||||
const Period = getConfig("Period");
|
const Period = getConfig("Period");
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
@@ -88,10 +86,6 @@ const onLogin = async (formEl: FormInstance | undefined) => {
|
|||||||
// 获取后端路由
|
// 获取后端路由
|
||||||
return initRouter().then(async () => {
|
return initRouter().then(async () => {
|
||||||
disabled.value = true;
|
disabled.value = true;
|
||||||
const res = await getUserInfoAPI();
|
|
||||||
if (res.success) {
|
|
||||||
setUserInfo(res.data);
|
|
||||||
}
|
|
||||||
router
|
router
|
||||||
.push(getTopMenu(true).path)
|
.push(getTopMenu(true).path)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
|||||||
10
src/views/monitor/cache/index.vue
vendored
10
src/views/monitor/cache/index.vue
vendored
@@ -121,6 +121,7 @@ import * as echarts from "echarts";
|
|||||||
import Monitor from "@iconify-icons/ep/monitor";
|
import Monitor from "@iconify-icons/ep/monitor";
|
||||||
import PieChart from "@iconify-icons/ep/pie-chart";
|
import PieChart from "@iconify-icons/ep/pie-chart";
|
||||||
import Odometer from "@iconify-icons/ep/odometer";
|
import Odometer from "@iconify-icons/ep/odometer";
|
||||||
|
import { onBeforeRouteLeave } from "vue-router";
|
||||||
|
|
||||||
const cache = reactive({
|
const cache = reactive({
|
||||||
commandStats: [] as { name: string; value: number }[],
|
commandStats: [] as { name: string; value: number }[],
|
||||||
@@ -240,13 +241,18 @@ const initUsedMemoryChart = () => {
|
|||||||
|
|
||||||
chart.setOption(option);
|
chart.setOption(option);
|
||||||
};
|
};
|
||||||
|
/**定时ID */
|
||||||
|
const timer = ref();
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await getCacheInfo();
|
await getCacheInfo();
|
||||||
setInterval(() => {
|
timer.value = setInterval(() => {
|
||||||
getCacheInfo();
|
getCacheInfo();
|
||||||
}, 60000);
|
}, 60000);
|
||||||
});
|
});
|
||||||
|
/**页面离开时清除定时器 */
|
||||||
|
onBeforeRouteLeave(() => {
|
||||||
|
clearInterval(timer.value);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
Reference in New Issue
Block a user