This commit is contained in:
parent
5e8c4b2813
commit
497f74b73d
10
src/App.tsx
10
src/App.tsx
|
|
@ -5,29 +5,27 @@ import PayPage from './pages/PayPage.tsx'
|
|||
import PayResultPage from './pages/PayResultPage.tsx'
|
||||
import Twins from './pages/Twins.tsx'
|
||||
import PlaceholderPage from './components/PlaceholderPage.tsx'
|
||||
import { getPackage } from './api/user.ts'
|
||||
|
||||
// http://localhost:5173?token=c3f52a99-c519-427a-af05-364c5f3e59cc
|
||||
// ?package=com.btys.btwx
|
||||
function App() {
|
||||
const [isConfigReady, setIsConfigReady] = useState(false)
|
||||
const [searchParams] = useSearchParams()
|
||||
const navigate = useNavigate()
|
||||
const [initialToken] = useState(() => searchParams.get('token'))
|
||||
const [initialPackage] = useState(() => searchParams.get('package'))
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true
|
||||
|
||||
async function initConfig() {
|
||||
if (initialPackage) {
|
||||
window.localStorage.setItem('package', initialPackage || '')
|
||||
}
|
||||
if (initialToken) {
|
||||
window.localStorage.setItem('token', initialToken || '')
|
||||
} else if (!window.localStorage.getItem('token')) {
|
||||
navigate('/twins', { replace: true })
|
||||
}
|
||||
|
||||
await getPackage()
|
||||
|
||||
if (isMounted) {
|
||||
setIsConfigReady(true)
|
||||
}
|
||||
|
|
@ -38,7 +36,7 @@ function App() {
|
|||
return () => {
|
||||
isMounted = false
|
||||
}
|
||||
}, [initialPackage, initialToken, navigate])
|
||||
}, [initialToken, navigate])
|
||||
|
||||
if (!isConfigReady) {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,6 @@ export function getService() {
|
|||
return get<ApiResponse<ServiceConfig>>('/api/weixin/service')
|
||||
}
|
||||
|
||||
export function getPackage({ package_name }: { package_name: string }) {
|
||||
return get<ApiResponse<PackageInfo>>('/api/package', { package_name })
|
||||
export function getPackage() {
|
||||
return get<ApiResponse<PackageInfo>>('/api/package')
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue