feat(tracking): pass question hash/text via history state and follow URL business date
Frontend CI / Frontend (push) Successful in 3m11s

Move question_hash and question_text out of the URL query into router
history state to keep tracking question links clean, and make the
tracking dashboard's business date follow the URL/today instead of the
previously persisted localStorage value.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-24 00:27:32 +08:00
parent 0d690371d2
commit 075e282c76
2 changed files with 22 additions and 13 deletions
@@ -30,8 +30,16 @@ const trackingToday = dayjs().format('YYYY-MM-DD')
const routeBrandId = computed(() => parsePositiveNumber(route.params.brandId))
const brandId = computed(() => companyStore.currentBrandId ?? routeBrandId.value)
const questionId = computed(() => parsePositiveNumber(route.params.questionId))
const questionHash = computed(() => normalizeQueryValue(route.query.question_hash))
const questionTitleFallback = computed(() => normalizeQueryValue(route.query.question_text))
const questionHash = computed(
() =>
normalizeHistoryStateValue(history.state?.tracking_question_hash) ||
normalizeQueryValue(route.query.question_hash),
)
const questionTitleFallback = computed(
() =>
normalizeHistoryStateValue(history.state?.tracking_question_text) ||
normalizeQueryValue(route.query.question_text),
)
const keywordId = computed(() => normalizeQueryValue(route.query.keyword_id))
const requestedPlatformId = computed(() => {
const platformId = normalizeMonitoringPlatformId(normalizeQueryValue(route.query.ai_platform_id))
@@ -1086,6 +1094,10 @@ function normalizeQueryValue(value: unknown): string {
return String(raw ?? '').trim()
}
function normalizeHistoryStateValue(value: unknown): string {
return typeof value === 'string' ? value.trim() : ''
}
function normalizeTrackingBusinessDate(value: unknown): string | null {
const normalized = normalizeQueryValue(value)
if (!normalized) {
+8 -11
View File
@@ -101,12 +101,12 @@ const allQuestionOptionValue = 'all'
const selectedQuestionId = useStorage<number | null>('tracking_selected_question', null)
const selectedPlatformId = useStorage<string>('tracking_selected_ai_platform_id', 'all')
const selectedBusinessDate = useStorage<string>('tracking_selected_business_date', trackingToday)
const selectedBusinessDate = ref<string>(
normalizeTrackingBusinessDate(route.query.business_date) ?? trackingToday,
)
const selectedCitationWindowDays = useStorage<number>('tracking_selected_citation_window_days', 7)
selectedPlatformId.value = normalizeMonitoringPlatformFilter(selectedPlatformId.value)
selectedBusinessDate.value =
normalizeTrackingBusinessDate(selectedBusinessDate.value) ?? trackingToday
selectedCitationWindowDays.value = normalizeCitationWindowDays(selectedCitationWindowDays.value)
const selectedQuestionSetOptionValue = computed<string | number>({
@@ -168,10 +168,7 @@ watch(selectedBrandId, (newId, oldId) => {
watch(
() => route.query.business_date,
(value) => {
const requestedBusinessDate = normalizeTrackingBusinessDate(value)
if (requestedBusinessDate) {
selectedBusinessDate.value = requestedBusinessDate
}
selectedBusinessDate.value = normalizeTrackingBusinessDate(value) ?? trackingToday
},
{ immediate: true },
)
@@ -636,13 +633,13 @@ function openQuestion(question: MonitoringHotQuestion): void {
questionId: String(question.question_id),
},
query: {
question_hash: question.question_hash,
question_text: question.question_text,
business_date: selectedBusinessDate.value,
date_from: selectedBusinessDate.value,
date_to: selectedBusinessDate.value,
...(selectedPlatformId.value !== 'all' ? { ai_platform_id: selectedPlatformId.value } : {}),
},
state: {
tracking_question_hash: question.question_hash,
tracking_question_text: question.question_text,
},
})
}