mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-27 01:01:51 +08:00
fix: 修复从设置/AI对话页返回后时间筛选重置为全部的问题
添加模块级缓存 timeStateCache,按 sessionId 保存用户最后设置的 时间筛选状态。initialTimeState 优先级:URL 参数 > 缓存 > 默认值, timeRangeValue 变化时自动写入缓存,确保跨页面导航后状态得以恢复。 Made-with: Cursor
This commit is contained in:
@@ -9,6 +9,12 @@ import type { Ref } from 'vue'
|
||||
import type { RouteLocationNormalizedLoaded, Router } from 'vue-router'
|
||||
import type { TimeRangeValue, TimeSelectState, TimeSelectMode } from '@/components/common/TimeSelect.vue'
|
||||
|
||||
/**
|
||||
* 模块级缓存:按 sessionId 保存用户最后设置的时间筛选状态。
|
||||
* 解决从设置页/AI 对话等页面切回聊天分析页时时间筛选被重置的问题。
|
||||
*/
|
||||
const timeStateCache = new Map<string, Partial<TimeSelectState>>()
|
||||
|
||||
interface UseTimeSelectOptions {
|
||||
/** 当前激活的 Tab ref(用于 URL 同步) */
|
||||
activeTab: Ref<string>
|
||||
@@ -57,7 +63,10 @@ export function useTimeSelect(route: RouteLocationNormalizedLoaded, router: Rout
|
||||
return new Date(v.startTs * 1000).getFullYear()
|
||||
})
|
||||
|
||||
/** 从 URL query 构建 TimeSelect 初始状态;总览 Tab 默认「全部」,其余 Tab 默认「最近一年」 */
|
||||
/**
|
||||
* 从 URL query 构建 TimeSelect 初始状态。
|
||||
* 优先级:URL 参数 > 缓存(上次用户设置)> 默认值(总览 Tab「全部」,其余「最近一年」)
|
||||
*/
|
||||
const initialTimeState = computed<Partial<TimeSelectState>>(() => {
|
||||
const q = route.query
|
||||
const m = q.timeMode as TimeSelectMode | undefined
|
||||
@@ -72,6 +81,9 @@ export function useTimeSelect(route: RouteLocationNormalizedLoaded, router: Rout
|
||||
customEnd: (q.timeEnd as string) || undefined,
|
||||
}
|
||||
}
|
||||
if (currentSessionId.value && timeStateCache.has(currentSessionId.value)) {
|
||||
return timeStateCache.get(currentSessionId.value)!
|
||||
}
|
||||
return {
|
||||
mode: 'recent',
|
||||
recentDays: activeTab.value === 'overview' ? 0 : 365,
|
||||
@@ -108,6 +120,8 @@ export function useTimeSelect(route: RouteLocationNormalizedLoaded, router: Rout
|
||||
timeRangeValue,
|
||||
(val) => {
|
||||
if (!val || !currentSessionId.value) return
|
||||
// 缓存当前时间筛选状态,供从其他页面返回时恢复
|
||||
timeStateCache.set(currentSessionId.value, val.state)
|
||||
onTimeRangeChange?.()
|
||||
},
|
||||
{ immediate: true }
|
||||
|
||||
Reference in New Issue
Block a user