Ship a health-management BMI home for review, keep the nomad hub as hub, and let admin switch platforms.tt.homeVariant live with track/ntfy; fix tt config fetch to api.nomadro.cn/api/config. Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
/**
|
||
* 抖音启动页:默认 BMI(过审);homeVariant=hub 时跳正式门户
|
||
* 每次 onShow 强制拉配置,后台切换首页可近实时生效
|
||
*/
|
||
import { useEffect, useState } from 'react'
|
||
import Taro, { useDidShow } from '@tarojs/taro'
|
||
import {
|
||
getCachedRemoteConfig,
|
||
loadRemoteConfig,
|
||
} from '@/services/remoteConfig'
|
||
import {
|
||
resolveTtHomeVariantFromConfig,
|
||
type NomadroRemoteConfig,
|
||
} from '@/data/remoteConfig.defaults'
|
||
import { useNomadroTheme } from '@/utils/h5Theme'
|
||
import BmiHome from './BmiHome'
|
||
|
||
const HUB_PATH = '/pages/hub/index'
|
||
|
||
export default function IndexPage() {
|
||
const [config, setConfig] = useState<NomadroRemoteConfig>(() => getCachedRemoteConfig())
|
||
const [ready, setReady] = useState(false)
|
||
const theme = useNomadroTheme()
|
||
|
||
async function syncVariant(force = false) {
|
||
const r = await loadRemoteConfig(force)
|
||
setConfig(r.config)
|
||
if (resolveTtHomeVariantFromConfig(r.config) === 'hub') {
|
||
Taro.reLaunch({ url: HUB_PATH })
|
||
return false
|
||
}
|
||
setReady(true)
|
||
return true
|
||
}
|
||
|
||
useEffect(() => {
|
||
let cancelled = false
|
||
syncVariant(true).then((ok) => {
|
||
if (cancelled || !ok) return
|
||
})
|
||
if (resolveTtHomeVariantFromConfig(getCachedRemoteConfig()) !== 'hub') {
|
||
setReady(true)
|
||
}
|
||
return () => {
|
||
cancelled = true
|
||
}
|
||
}, [])
|
||
|
||
useDidShow(() => {
|
||
void syncVariant(true)
|
||
})
|
||
|
||
if (!ready) return null
|
||
return <BmiHome config={config} theme={theme} />
|
||
}
|