feat: 首页更新
This commit is contained in:
@@ -27,6 +27,7 @@ interface State {
|
||||
gamesTryPlayIds: number[];
|
||||
smallClassGames: Record<string, any>;
|
||||
gameBigClass: Record<string, any>;
|
||||
selectedCategory: string; // 当前选中的游戏分类
|
||||
}
|
||||
|
||||
// 操作
|
||||
@@ -38,6 +39,7 @@ interface Actions {
|
||||
setHomeHotGames: (data: Record<string, any>[]) => void;
|
||||
setSmallClassGame: (data: Record<string, any>) => void;
|
||||
setGameBigClass: (data: Record<string, any>) => void;
|
||||
setSelectedCategory: (categoryId: string) => void; // 设置选中的游戏分类
|
||||
// requestHomePageData: (data?: Record<string, any>) => Promise<any>;
|
||||
}
|
||||
|
||||
@@ -58,6 +60,7 @@ const useGameStore = create<State & Actions>()((set, get) => ({
|
||||
gamesTryPlayIds: [], // 试玩游戏id列表
|
||||
smallClassGames: {},
|
||||
gameBigClass: {},
|
||||
selectedCategory: '103', // 默认选中推荐分类
|
||||
|
||||
|
||||
// 保存首页数据
|
||||
@@ -157,6 +160,12 @@ const useGameStore = create<State & Actions>()((set, get) => ({
|
||||
[GameMainKeysEnum.BLOCK_THIRD]: groupByType?.[10] || [],
|
||||
} });
|
||||
},
|
||||
|
||||
setSelectedCategory: (categoryId: string) => {
|
||||
set({ selectedCategory: categoryId });
|
||||
// 保存到 session storage,页面刷新后仍然保留
|
||||
storageManager.session.setItem(STORAGE_KEYS.APP_ACTIVE_MAIN_MENU_TAB, categoryId);
|
||||
},
|
||||
}));
|
||||
|
||||
// 从 AsyncStorage 恢复状态的函数
|
||||
|
||||
@@ -8,7 +8,6 @@ export {
|
||||
useUser,
|
||||
useIsLoggedIn,
|
||||
useToken,
|
||||
useUserActions,
|
||||
restoreUserState,
|
||||
} from './userStore';
|
||||
export type { User } from './userStore';
|
||||
@@ -21,7 +20,6 @@ export {
|
||||
useNotificationsEnabled,
|
||||
useSoundEnabled,
|
||||
useHapticsEnabled,
|
||||
useSettingsActions,
|
||||
restoreSettingsState,
|
||||
} from './settingsStore';
|
||||
export type { Theme, Language } from './settingsStore';
|
||||
|
||||
@@ -10,7 +10,7 @@ import storageManager, { STORAGE_KEYS } from '@/utils/storageManager';
|
||||
/**
|
||||
* 主题类型
|
||||
*/
|
||||
export type Theme = 'light' | 'dark' | 'auto';
|
||||
export type Theme = 'light' | 'dark' | 'orange' | 'auto';
|
||||
|
||||
/**
|
||||
* 语言类型
|
||||
@@ -121,8 +121,7 @@ export const restoreSettingsState = async () => {
|
||||
try {
|
||||
const stored = await storageManager.local.getItem(STORAGE_KEYS.SETTINGS_STORE);
|
||||
if (stored) {
|
||||
const state = JSON.parse(stored);
|
||||
useSettingsStore.setState(state);
|
||||
useSettingsStore.setState(stored);
|
||||
if (__DEV__) {
|
||||
console.log('✅ Settings state restored from storage');
|
||||
}
|
||||
@@ -152,16 +151,3 @@ export const useSoundEnabled = () => useSettingsStore((state) => state.soundEnab
|
||||
// 获取触觉反馈状态
|
||||
export const useHapticsEnabled = () => useSettingsStore((state) => state.hapticsEnabled);
|
||||
|
||||
// 获取设置操作方法
|
||||
// 使用 useShallow 避免每次渲染都返回新对象
|
||||
export const useSettingsActions = () =>
|
||||
useSettingsStore(
|
||||
useShallow((state) => ({
|
||||
setTheme: state.setTheme,
|
||||
setLanguage: state.setLanguage,
|
||||
setNotificationsEnabled: state.setNotificationsEnabled,
|
||||
setSoundEnabled: state.setSoundEnabled,
|
||||
setHapticsEnabled: state.setHapticsEnabled,
|
||||
resetSettings: state.resetSettings,
|
||||
}))
|
||||
);
|
||||
|
||||
@@ -147,13 +147,13 @@ export const useToken = () => useUserStore((state) => state.token);
|
||||
|
||||
// 获取用户操作方法
|
||||
// 使用 useShallow 避免每次渲染都返回新对象
|
||||
export const useUserActions = () =>
|
||||
useUserStore(
|
||||
useShallow((state) => ({
|
||||
setUser: state.setUser,
|
||||
setToken: state.setToken,
|
||||
login: state.login,
|
||||
logout: state.logout,
|
||||
updateUser: state.updateUser,
|
||||
}))
|
||||
);
|
||||
// export const useUserActions = () =>
|
||||
// useUserStore(
|
||||
// useShallow((state) => ({
|
||||
// setUser: state.setUser,
|
||||
// setToken: state.setToken,
|
||||
// login: state.login,
|
||||
// logout: state.logout,
|
||||
// updateUser: state.updateUser,
|
||||
// }))
|
||||
// );
|
||||
|
||||
Reference in New Issue
Block a user