feat(worker-platform): 发布寄卖与我的寄卖界面支持停留状态与筛选持久化记忆
1. 在 WorkerConsignmentPage 中通过 localStorage 与 URL 查询参数实时双向同步 activeTab 与 recordFilter; 2. 打手在切换发布寄卖/我的寄卖或筛选状态后,刷新页面或切换路由返回时自动恢复上次停留界面; 3. 提交寄卖成功后自动切换并记住跳转到我的寄卖-待审核列表。
This commit is contained in:
@@ -74,6 +74,41 @@ const BRILLIANCE_OPTIONS = [
|
|||||||
type RecordFilter = 'all' | 'reviewing' | 'active' | 'finished'
|
type RecordFilter = 'all' | 'reviewing' | 'active' | 'finished'
|
||||||
|
|
||||||
const DEPOSIT_TIP_KEY = 'worker-consignment-deposit-tip-seen'
|
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 秒足够展示,不需要秒级跳动 */
|
/** 赠送冷却倒计时刷新间隔:30 秒足够展示,不需要秒级跳动 */
|
||||||
const COOLDOWN_TICK_MS = 30_000
|
const COOLDOWN_TICK_MS = 30_000
|
||||||
@@ -81,8 +116,36 @@ const COOLDOWN_TICK_MS = 30_000
|
|||||||
export default function WorkerConsignmentPage() {
|
export default function WorkerConsignmentPage() {
|
||||||
const isMobile = useIsMobile()
|
const isMobile = useIsMobile()
|
||||||
const { message, modal } = App.useApp()
|
const { message, modal } = App.useApp()
|
||||||
const [activeTab, setActiveTab] = useState<'publish' | 'records'>('publish')
|
const [activeTab, setActiveTabState] = useState<'publish' | 'records'>(getInitialActiveTab)
|
||||||
const [recordFilter, setRecordFilter] = useState<RecordFilter>('all')
|
const [recordFilter, setRecordFilterState] = useState<RecordFilter>(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<UploadedFile[]>([])
|
const [screenshots, setScreenshots] = useState<UploadedFile[]>([])
|
||||||
const [submitting, setSubmitting] = useState(false)
|
const [submitting, setSubmitting] = useState(false)
|
||||||
const [evidenceItem, setEvidenceItem] = useState<WorkerConsignmentRecord | null>(null)
|
const [evidenceItem, setEvidenceItem] = useState<WorkerConsignmentRecord | null>(null)
|
||||||
|
|||||||
Reference in New Issue
Block a user