fix: 修复前端多个 bug

1. 版本号闪烁问题
   - 将版本信息缓存到 Pinia store,避免每次路由切换都重新请求
   - 添加加载占位符,版本为空时显示骨架屏

2. 管理员登录跳转问题
   - 管理员登录后现在正确跳转到 /admin/dashboard
   - 普通用户仍跳转到 /dashboard

3. Dashboard 页面空白报错
   - 修复 API 返回 null 时访问 .length 导致的 TypeError
   - 为 computed 属性添加可选链操作符保护
   - 为数据赋值添加空数组默认值
This commit is contained in:
shaw
2025-12-18 22:11:29 +08:00
parent 9b4fc42457
commit 145171464f
5 changed files with 112 additions and 45 deletions

View File

@@ -406,7 +406,7 @@ const lineOptions = computed(() => ({
// Model chart data
const modelChartData = computed(() => {
if (!modelStats.value.length) return null
if (!modelStats.value?.length) return null
const colors = [
'#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6',
@@ -425,7 +425,7 @@ const modelChartData = computed(() => {
// Trend chart data
const trendChartData = computed(() => {
if (!trendData.value.length) return null
if (!trendData.value?.length) return null
return {
labels: trendData.value.map(d => d.date),
@@ -460,7 +460,7 @@ const trendChartData = computed(() => {
// User trend chart data
const userTrendChartData = computed(() => {
if (!userTrend.value.length) return null
if (!userTrend.value?.length) return null
// Group by user
const userGroups = new Map<string, { name: string; data: Map<string, number> }>()