diff --git a/JY-Salon-Front/src/utils/storage.ts b/JY-Salon-Front/src/utils/storage.ts index c61b0755..20546800 100644 --- a/JY-Salon-Front/src/utils/storage.ts +++ b/JY-Salon-Front/src/utils/storage.ts @@ -17,14 +17,34 @@ export const removeStorage = (key: string): void => { const PLANNING_REFRESH_KEY = 'planningNeedRefresh' -export const markPlanningRefresh = (): void => { - window.localStorage.setItem(PLANNING_REFRESH_KEY, '1') +export interface PlanningRefreshTarget { + date?: string + artistId?: string } -export const consumePlanningRefresh = (): boolean => { - const marked = window.localStorage.getItem(PLANNING_REFRESH_KEY) === '1' - if (marked) { - window.localStorage.removeItem(PLANNING_REFRESH_KEY) +export const markPlanningRefresh = (target?: PlanningRefreshTarget): void => { + const payload = { + date: target?.date || '', + artistId: target?.artistId || '' + } + window.localStorage.setItem(PLANNING_REFRESH_KEY, JSON.stringify(payload)) +} + +export const consumePlanningRefresh = (): PlanningRefreshTarget | null => { + const raw = window.localStorage.getItem(PLANNING_REFRESH_KEY) + if (!raw) { + return null + } + window.localStorage.removeItem(PLANNING_REFRESH_KEY) + if (raw === '1') { + return {} + } + const parsed = JSON.parse(raw) as PlanningRefreshTarget + if (parsed === null || typeof parsed !== 'object') { + throw new Error('规划刷新标记格式不正确,无法读取 planningNeedRefresh') + } + return { + date: typeof parsed.date === 'string' ? parsed.date : '', + artistId: typeof parsed.artistId === 'string' ? parsed.artistId : '' } - return marked }