Files
frontend-miniapp/src/utils/guideTopTabs.ts

42 lines
1.2 KiB
TypeScript

export type GuideTopTab = 'guide' | 'explain'
export const GUIDE_LOCATION_PREVIEW_STORAGE_KEY = 'museum-guide:last-location-preview-url'
export const GUIDE_TOP_TABS: Array<{ id: GuideTopTab; label: string }> = [
{ id: 'guide', label: '馆内' },
{ id: 'explain', label: '讲解' }
]
export const isGuideTopTab = (value: unknown): value is GuideTopTab => {
return value === 'guide' || value === 'explain'
}
export const guideTopTabUrl = (tab: GuideTopTab) => `/pages/index/index?tab=${tab}`
export const saveLastGuideLocationPreviewUrl = (url: string) => {
if (typeof window === 'undefined' || !url) return
window.sessionStorage.setItem(GUIDE_LOCATION_PREVIEW_STORAGE_KEY, url)
}
export const getLastGuideLocationPreviewUrl = () => {
if (typeof window === 'undefined') return ''
return window.sessionStorage.getItem(GUIDE_LOCATION_PREVIEW_STORAGE_KEY) || ''
}
export const navigateToGuideTopTab = (tab: GuideTopTab) => {
if (tab === 'guide') {
const lastLocationPreviewUrl = getLastGuideLocationPreviewUrl()
if (lastLocationPreviewUrl) {
uni.reLaunch({
url: lastLocationPreviewUrl
})
return
}
}
uni.reLaunch({
url: guideTopTabUrl(tab)
})
}