优化首页返回定位与发布在线时间表单
移动端首页用列表缓存和内部滚动恢复浏览位置;发布页在线时间改为全天+起止时间单行布局。
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import {
|
||||
defaultHomeAnnouncements,
|
||||
defaultHomeBanners,
|
||||
type HomeBannerSlide,
|
||||
} from '@/features/listings/api/homeConfig'
|
||||
import {
|
||||
emptyListingPublishOptions,
|
||||
type ListingPublishOptions,
|
||||
} from '@/features/listings/api/listingOptions'
|
||||
import type { Listing } from '@/features/listings/api/listings'
|
||||
|
||||
export type MobileHomeRangeFilters = Record<string, { min: string; max: string }>
|
||||
|
||||
export function buildMobileHomeListSignature(input: {
|
||||
searchValue: string
|
||||
activeSort: string
|
||||
activeZone: string
|
||||
selectedFilters: Record<string, string[]>
|
||||
rangeFilters: MobileHomeRangeFilters
|
||||
}) {
|
||||
return JSON.stringify({
|
||||
keyword: input.searchValue.trim(),
|
||||
sort: input.activeSort,
|
||||
zone: input.activeZone,
|
||||
selected: input.selectedFilters,
|
||||
ranges: input.rangeFilters,
|
||||
})
|
||||
}
|
||||
|
||||
/** 移动端首页列表/配置/滚动缓存:与页面实例解耦,返回详情后可直接恢复 */
|
||||
export const useMobileHomeCacheStore = defineStore('mobileHomeCache', {
|
||||
state: () => ({
|
||||
/** 与当前 listings 数据对应的筛选签名;空字符串表示尚无可用快照 */
|
||||
listSignature: '',
|
||||
listings: [] as Listing[],
|
||||
totalListings: 0,
|
||||
zoneCounts: {} as Record<string, number>,
|
||||
/** 下一页页码(与 MobileHomeView.currentPage 语义一致) */
|
||||
currentPage: 1,
|
||||
hasMoreListings: true,
|
||||
/** 列表滚动容器 scrollTop */
|
||||
scrollTop: 0,
|
||||
announcements: [...defaultHomeAnnouncements] as string[],
|
||||
bannerSlides: defaultHomeBanners.map(slide => ({ ...slide })) as HomeBannerSlide[],
|
||||
publishOptions: { ...emptyListingPublishOptions } as ListingPublishOptions,
|
||||
homeConfigLoaded: false,
|
||||
}),
|
||||
getters: {
|
||||
hasListSnapshot(state): boolean {
|
||||
return state.listSignature !== ''
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
matchList(signature: string) {
|
||||
return this.listSignature !== '' && this.listSignature === signature
|
||||
},
|
||||
saveList(payload: {
|
||||
signature: string
|
||||
listings: Listing[]
|
||||
totalListings: number
|
||||
zoneCounts: Record<string, number>
|
||||
currentPage: number
|
||||
hasMoreListings: boolean
|
||||
}) {
|
||||
this.listSignature = payload.signature
|
||||
this.listings = payload.listings
|
||||
this.totalListings = payload.totalListings
|
||||
this.zoneCounts = payload.zoneCounts
|
||||
this.currentPage = payload.currentPage
|
||||
this.hasMoreListings = payload.hasMoreListings
|
||||
},
|
||||
saveScrollTop(top: number) {
|
||||
this.scrollTop = Math.max(0, top)
|
||||
},
|
||||
saveHomeConfig(payload: {
|
||||
announcements: string[]
|
||||
bannerSlides: HomeBannerSlide[]
|
||||
publishOptions: ListingPublishOptions
|
||||
}) {
|
||||
this.announcements = payload.announcements
|
||||
this.bannerSlides = payload.bannerSlides
|
||||
this.publishOptions = payload.publishOptions
|
||||
this.homeConfigLoaded = true
|
||||
},
|
||||
clearList() {
|
||||
this.listSignature = ''
|
||||
this.listings = []
|
||||
this.totalListings = 0
|
||||
this.zoneCounts = {}
|
||||
this.currentPage = 1
|
||||
this.hasMoreListings = true
|
||||
this.scrollTop = 0
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user