This commit is contained in:
oneao committed 2026-01-26 22:31:12 +08:00
1 parent 5a79414319
commit 8663cb2e3d
28 files changed
+744 -756

No files matched your search

+1 -3
View File
@@ -26,21 +26,19 @@ export const useAppStore = create<AppState>((set, get) => ({
const moneyCategoryStore = useMoneyCategoryStore.getState()
const spaceStore = useSpaceStore.getState()
// 未登录:跳转到登录页,但认为初始化已完成(允许 UI 继续渲染)
if (!userStore.isLoggedIn()) {
navStore.navigateToAuth()
set({ ready: true })
return
}
// 登录状态:执行完整初始化流程
try {
// 分类初始化
await moneyCategoryStore.init()
// 获取空间信息
const res = await getUserSpaceApi()
spaceStore.setUserSpace(res.data)
spaceStore.setUserSpace(res.data)
}
catch (err) {
console.error('app init error:', err)
+39 -11
View File
@@ -1,21 +1,49 @@
import type { icons } from 'lucide-react-native'
import AsyncStorage from '@react-native-async-storage/async-storage'
import { router } from 'expo-router'
// store/navigation.ts
import { create } from 'zustand'
import { createJSONStorage, persist } from 'zustand/middleware'
export interface NavItem {
label: string
path: string
icon: keyof typeof icons
}
interface NavState {
navMenus: NavItem[]
pathname: string
setPathname: (p: string) => void
navigateToAuth: () => void
setNavMenus: (menus: NavItem[]) => void
}
export const useNavStore = create<NavState>(set => ({
pathname: '/',
setPathname: (p: string) => set({ pathname: p }),
navigateToAuth: () => {
const pathname = useNavStore.getState().pathname
const DEFAULT_NAV_MENUS: NavItem[] = [
{ label: '记账', path: '/money', icon: 'CircleDollarSign' },
{ label: '恋爱记', path: '/love', icon: 'Heart' },
{ label: '聊天', path: '/chat', icon: 'MessageCircle' },
{ label: '个人中心', path: '/user', icon: 'CircleUserRound' },
]
if (!pathname.startsWith('/auth')) {
router.replace('/auth')
}
},
}))
export const useNavStore = create<NavState>()(
persist(
(set, get) => ({
pathname: '/',
navMenus: DEFAULT_NAV_MENUS,
setPathname: (p: string) => set({ pathname: p }),
navigateToAuth: () => {
const pathname = useNavStore.getState().pathname
if (!pathname.startsWith('/auth')) {
router.replace('/auth')
}
},
setNavMenus: navMenus => set({ navMenus }),
}),
{
name: 'nav-storage',
storage: createJSONStorage(() => AsyncStorage),
},
),
)