chore: freeze guide and explain update
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
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: '导览' },
|
||||
@@ -11,7 +12,29 @@ export const isGuideTopTab = (value: unknown): value is GuideTopTab => {
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
42
src/utils/publicUrl.ts
Normal file
42
src/utils/publicUrl.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
const SAME_SERVER_HOST = '1.92.206.90'
|
||||
const LEGACY_AUDIO_HOST = '47.120.48.148'
|
||||
|
||||
const isAbsoluteHttpUrl = (url: string) => /^https?:\/\//i.test(url)
|
||||
|
||||
export const normalizeSameOriginPublicUrl = (url: string | null | undefined) => {
|
||||
const value = url?.trim()
|
||||
if (!value || !isAbsoluteHttpUrl(value)) return value || ''
|
||||
|
||||
try {
|
||||
const parsed = new URL(value)
|
||||
const isSameServer = parsed.hostname === SAME_SERVER_HOST
|
||||
|
||||
if (
|
||||
isSameServer
|
||||
&& parsed.port === '9000'
|
||||
&& parsed.pathname.startsWith('/museum-assets/')
|
||||
) {
|
||||
return `${parsed.pathname}${parsed.search}${parsed.hash}`
|
||||
}
|
||||
|
||||
if (
|
||||
isSameServer
|
||||
&& parsed.port === '48080'
|
||||
&& parsed.pathname.startsWith('/yudao-server/')
|
||||
) {
|
||||
return `${parsed.pathname}${parsed.search}${parsed.hash}`
|
||||
}
|
||||
|
||||
if (
|
||||
parsed.hostname === LEGACY_AUDIO_HOST
|
||||
&& parsed.port === '19000'
|
||||
&& parsed.pathname.startsWith('/nhm/audio/')
|
||||
) {
|
||||
return `${parsed.pathname}${parsed.search}${parsed.hash}`
|
||||
}
|
||||
} catch {
|
||||
return value
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
Reference in New Issue
Block a user