fix dashboard statistic and login guard warnings

This commit is contained in:
david
2026-07-29 16:45:17 +08:00
parent 94f6492d6e
commit a6fbb8da21
2 changed files with 15 additions and 8 deletions

View File

@@ -5,9 +5,14 @@ import { useUserStore } from '@/store';
import { isLogin } from '@/utils/auth'; import { isLogin } from '@/utils/auth';
export default function setupUserLoginInfoGuard(router: Router) { export default function setupUserLoginInfoGuard(router: Router) {
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, _from, next) => {
NProgress.start(); NProgress.start();
const userStore = useUserStore(); const userStore = useUserStore();
// 登录页不需要校验旧令牌,避免后端未启动或令牌过期时重复请求用户资料。
if (to.name === 'login') {
next();
return;
}
if (isLogin()) { if (isLogin()) {
if (userStore.role) { if (userStore.role) {
next(); next();
@@ -15,7 +20,7 @@ export default function setupUserLoginInfoGuard(router: Router) {
try { try {
await userStore.info(); await userStore.info();
next(); next();
} catch (error) { } catch {
await userStore.logout(); await userStore.logout();
next({ next({
name: 'login', name: 'login',
@@ -27,10 +32,6 @@ export default function setupUserLoginInfoGuard(router: Router) {
} }
} }
} else { } else {
if (to.name === 'login') {
next();
return;
}
next({ next({
name: 'login', name: 'login',
query: { query: {

View File

@@ -4,8 +4,14 @@
<a-grid :cols="{ xs: 1, sm: 2, lg: 4 }" :col-gap="16" :row-gap="16"> <a-grid :cols="{ xs: 1, sm: 2, lg: 4 }" :col-gap="16" :row-gap="16">
<a-grid-item v-for="item in cards" :key="item.key"> <a-grid-item v-for="item in cards" :key="item.key">
<a-card :bordered="false" class="metric-card"> <a-card :bordered="false" class="metric-card">
<a-statistic :title="item.label" :value="overview[item.key]" :precision="item.money ? 2 : 0" <a-statistic
:prefix="item.money ? '¥' : undefined" show-group-separator /> :title="item.label"
:value="overview[item.key]"
:precision="item.money ? 2 : 0"
show-group-separator
>
<template v-if="item.money" #prefix>¥</template>
</a-statistic>
<div class="metric-hint">{{ item.hint }}</div> <div class="metric-hint">{{ item.hint }}</div>
</a-card> </a-card>
</a-grid-item> </a-grid-item>