u
This commit is contained in:
1 parent
6849579652
commit
d60be4a75b
24 files changed
+463
-179
No files matched your search
@@ -5,7 +5,7 @@ import { Stack, useRouter } from 'expo-router'
|
||||
import * as SplashScreen from 'expo-splash-screen'
|
||||
import { StatusBar } from 'expo-status-bar'
|
||||
import { RefreshCw } from 'lucide-react-native'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useEffect } from 'react'
|
||||
import EmptyState from '@/components/common/EmptyStatus'
|
||||
import { GluestackUIProvider } from '@/components/ui/gluestack-ui-provider'
|
||||
import { useUserStore } from '@/store/user'
|
||||
@@ -33,33 +33,23 @@ export function ErrorBoundary({ error, retry }: ErrorBoundaryProps) {
|
||||
|
||||
export default function RootLayout() {
|
||||
const router = useRouter()
|
||||
|
||||
const token = useUserStore(state => state.token)
|
||||
const userStore = useUserStore()
|
||||
|
||||
const [fontsLoaded] = useFonts({
|
||||
SpaceMono: require('@/static/fonts/SpaceMono-Regular.ttf'),
|
||||
})
|
||||
|
||||
const [storeLoaded, setStoreLoaded] = useState(false)
|
||||
|
||||
// 等待 store 恢复数据
|
||||
useEffect(() => {
|
||||
if (token !== undefined) {
|
||||
setStoreLoaded(true)
|
||||
}
|
||||
}, [token])
|
||||
|
||||
// splash screen 隐藏 & 登录跳转
|
||||
useEffect(() => {
|
||||
if (fontsLoaded && storeLoaded) {
|
||||
if (fontsLoaded) {
|
||||
SplashScreen.hideAsync()
|
||||
|
||||
// 如果没有 token,则跳转登录页
|
||||
if (token === null) {
|
||||
if (!userStore.isLoggedIn()) {
|
||||
router.replace('/auth')
|
||||
}
|
||||
}
|
||||
}, [fontsLoaded, storeLoaded, token])
|
||||
}, [fontsLoaded])
|
||||
|
||||
return (
|
||||
<GluestackUIProvider>
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import type { StepLayoutItem } from '@/components/custom/StepLayout'
|
||||
import { Slot } from 'expo-router'
|
||||
import { Slot, Stack, useRouter } from 'expo-router'
|
||||
import { Image, Text, View } from 'react-native'
|
||||
import { SafeAreaView } from 'react-native-safe-area-context'
|
||||
import StepLayout from '@/components/custom/StepLayout'
|
||||
import CustomTabbar from '@/components/custom/Tabbar'
|
||||
|
||||
const steps: StepLayoutItem[] = [
|
||||
{
|
||||
@@ -22,5 +25,6 @@ export default function AuthLayout() {
|
||||
<StepLayout steps={steps}>
|
||||
<Slot />
|
||||
</StepLayout>
|
||||
|
||||
)
|
||||
}
|
||||
@@ -36,17 +36,20 @@ export default function AuthLogin() {
|
||||
setForm(prev => ({ ...prev, [field]: value }))
|
||||
}
|
||||
const defaultLogin = () => {
|
||||
alovaInstance.Post('/auth/login/default', {
|
||||
alovaInstance.Post('/auth/test', {
|
||||
title: 'foo',
|
||||
body: 'bar',
|
||||
userId: 1,
|
||||
}).then((res) => {
|
||||
console.log(res)
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('成功返回:', res)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('请求失败或未授权:', err)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
<View className="flex flex-col items-center px-6 h-full">
|
||||
<Image
|
||||
source={require('@/static/images/logo.png')}
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function AuthRegister() {
|
||||
|
||||
return (
|
||||
<ScrollView ref={scrollRef} style={{ flex: 1 }}>
|
||||
<View className="flex flex-col items-center px-6">
|
||||
<View className="flex flex-col items-center px-6 bg-white ">
|
||||
<Image
|
||||
source={require('@/static/images/logo.png')}
|
||||
style={{ width: 120, height: 120 }}
|
||||
|
||||
Reference in new issue
Block a user