diff --git a/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx b/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx index a6d4c69f..c3649d93 100644 --- a/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx +++ b/apps/frontend/src/pages/worker/WorkerConsignmentPage.tsx @@ -74,6 +74,41 @@ const BRILLIANCE_OPTIONS = [ type RecordFilter = 'all' | 'reviewing' | 'active' | 'finished' const DEPOSIT_TIP_KEY = 'worker-consignment-deposit-tip-seen' +const ACTIVE_TAB_STORAGE_KEY = 'worker_consignment_active_tab' +const RECORD_FILTER_STORAGE_KEY = 'worker_consignment_record_filter' + +function getInitialActiveTab(): 'publish' | 'records' { + if (typeof window === 'undefined') return 'publish' + try { + const params = new URLSearchParams(window.location.search) + const tabParam = params.get('tab') + if (tabParam === 'records' || tabParam === 'publish') { + return tabParam + } + const saved = window.localStorage.getItem(ACTIVE_TAB_STORAGE_KEY) + return saved === 'records' ? 'records' : 'publish' + } catch { + return 'publish' + } +} + +function getInitialRecordFilter(): RecordFilter { + if (typeof window === 'undefined') return 'all' + try { + const params = new URLSearchParams(window.location.search) + const filterParam = params.get('filter') as RecordFilter | null + if (filterParam && ['all', 'reviewing', 'active', 'finished'].includes(filterParam)) { + return filterParam + } + const saved = window.localStorage.getItem(RECORD_FILTER_STORAGE_KEY) as RecordFilter | null + if (saved && ['all', 'reviewing', 'active', 'finished'].includes(saved)) { + return saved + } + } catch { + // ignore + } + return 'all' +} /** 赠送冷却倒计时刷新间隔:30 秒足够展示,不需要秒级跳动 */ const COOLDOWN_TICK_MS = 30_000 @@ -81,8 +116,36 @@ const COOLDOWN_TICK_MS = 30_000 export default function WorkerConsignmentPage() { const isMobile = useIsMobile() const { message, modal } = App.useApp() - const [activeTab, setActiveTab] = useState<'publish' | 'records'>('publish') - const [recordFilter, setRecordFilter] = useState('all') + const [activeTab, setActiveTabState] = useState<'publish' | 'records'>(getInitialActiveTab) + const [recordFilter, setRecordFilterState] = useState(getInitialRecordFilter) + + const setActiveTab = (tab: 'publish' | 'records') => { + setActiveTabState(tab) + if (typeof window !== 'undefined') { + try { + window.localStorage.setItem(ACTIVE_TAB_STORAGE_KEY, tab) + const url = new URL(window.location.href) + url.searchParams.set('tab', tab) + window.history.replaceState({}, '', url.toString()) + } catch { + // ignore + } + } + } + + const setRecordFilter = (filter: RecordFilter) => { + setRecordFilterState(filter) + if (typeof window !== 'undefined') { + try { + window.localStorage.setItem(RECORD_FILTER_STORAGE_KEY, filter) + const url = new URL(window.location.href) + url.searchParams.set('filter', filter) + window.history.replaceState({}, '', url.toString()) + } catch { + // ignore + } + } + } const [screenshots, setScreenshots] = useState([]) const [submitting, setSubmitting] = useState(false) const [evidenceItem, setEvidenceItem] = useState(null)