feat: 首页更新
This commit is contained in:
@@ -27,7 +27,8 @@ interface State {
|
||||
gamesTryPlayIds: number[];
|
||||
smallClassGames: Record<string, any>;
|
||||
gameBigClass: Record<string, any>;
|
||||
selectedCategory: string; // 当前选中的游戏分类
|
||||
activeMainMenuTab: string; // 当前选中的主菜单分类
|
||||
activeSubMenuTab: string; // 当前选中的子菜单分类
|
||||
}
|
||||
|
||||
// 操作
|
||||
@@ -39,7 +40,9 @@ interface Actions {
|
||||
setHomeHotGames: (data: Record<string, any>[]) => void;
|
||||
setSmallClassGame: (data: Record<string, any>) => void;
|
||||
setGameBigClass: (data: Record<string, any>) => void;
|
||||
setSelectedCategory: (categoryId: string) => void; // 设置选中的游戏分类
|
||||
setActiveMenuTabs: (mainMenuKey: string, subMenuKey: string) => void; // 设置选中的游戏分类
|
||||
setActiveMainMenuTab: (mainMenuKey: string) => void; // 设置选中的主菜单分类
|
||||
setActiveSubMenuTab: (subMenuKey: string) => void; // 设置选中的子菜单分类
|
||||
// requestHomePageData: (data?: Record<string, any>) => Promise<any>;
|
||||
}
|
||||
|
||||
@@ -60,8 +63,8 @@ const useGameStore = create<State & Actions>()((set, get) => ({
|
||||
gamesTryPlayIds: [], // 试玩游戏id列表
|
||||
smallClassGames: {},
|
||||
gameBigClass: {},
|
||||
selectedCategory: '103', // 默认选中推荐分类
|
||||
|
||||
activeMainMenuTab: '103', // 默认选中推荐分类
|
||||
activeSubMenuTab: '', // 默认无子菜单选中
|
||||
|
||||
// 保存首页数据
|
||||
setHomePageData: (data: any) => {
|
||||
@@ -74,7 +77,10 @@ const useGameStore = create<State & Actions>()((set, get) => ({
|
||||
const appLoginPop = data.appLoginPop || false;
|
||||
|
||||
// 菜单排序
|
||||
const menuSort = filter(data.version_type, item => item.sort_v !== 0 && item.state == 1).sort((a, b) => {
|
||||
const menuSort = filter(
|
||||
data.version_type,
|
||||
(item) => item.sort_v !== 0 && item.state == 1
|
||||
).sort((a, b) => {
|
||||
return b.sort_v - a.sort_v;
|
||||
});
|
||||
console.log(menuSort, 'menuSort 1');
|
||||
@@ -131,7 +137,9 @@ const useGameStore = create<State & Actions>()((set, get) => ({
|
||||
setGamesTry: (list: Record<string, any>[]) => {
|
||||
set({ gamesTry: list || [] });
|
||||
storageManager.session.setItem(STORAGE_KEYS.GAME_TRY, list);
|
||||
const gamesTryPlayIds = concat(...map(list, item => map(item.subList, subItem => Number(subItem.play_id))));
|
||||
const gamesTryPlayIds = concat(
|
||||
...map(list, (item) => map(item.subList, (subItem) => Number(subItem.play_id)))
|
||||
);
|
||||
set({ gamesTryPlayIds });
|
||||
},
|
||||
|
||||
@@ -140,17 +148,21 @@ const useGameStore = create<State & Actions>()((set, get) => ({
|
||||
},
|
||||
|
||||
setSmallClassGame: (data: Record<string, any>) => {
|
||||
set({ smallClassGames: {
|
||||
set({
|
||||
smallClassGames: {
|
||||
[GameMainKeysEnum.HOT_ELECTRONIC]: data?.[2] || [],
|
||||
[GameMainKeysEnum.HOT_FISHING]: data?.[3] || [],
|
||||
[GameMainKeysEnum.HOT_CHESS]: data?.[5] || [],
|
||||
[GameMainKeysEnum.HOT_BLOCK_THIRD]: data?.[8] || [],
|
||||
} });
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
setGameBigClass: (data: Record<string, any>) => {
|
||||
const groupByType = cloneDeep(groupBy(data, item => item.big_type));
|
||||
set({ gameBigClass: {
|
||||
const groupByType = cloneDeep(groupBy(data, (item) => item.big_type));
|
||||
console.log(groupByType, 'groupByType');
|
||||
set({
|
||||
gameBigClass: {
|
||||
[GameMainKeysEnum.CHESS]: groupByType?.[1] || [],
|
||||
[GameMainKeysEnum.ELECTRONIC]: groupByType?.[2] || [],
|
||||
[GameMainKeysEnum.FISHING]: groupByType?.[3] || [],
|
||||
@@ -158,13 +170,27 @@ const useGameStore = create<State & Actions>()((set, get) => ({
|
||||
[GameMainKeysEnum.SPORTS]: groupByType?.[5] || [],
|
||||
[GameMainKeysEnum.LOTTERY]: groupByType?.[7] || [],
|
||||
[GameMainKeysEnum.BLOCK_THIRD]: groupByType?.[10] || [],
|
||||
} });
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
setSelectedCategory: (categoryId: string) => {
|
||||
set({ selectedCategory: categoryId });
|
||||
setActiveMenuTabs: (mainMenuKey: string, subMenuKey: string) => {
|
||||
set({ activeMainMenuTab: mainMenuKey, activeSubMenuTab: subMenuKey });
|
||||
// 保存到 session storage,页面刷新后仍然保留
|
||||
storageManager.session.setItem(STORAGE_KEYS.APP_ACTIVE_MAIN_MENU_TAB, categoryId);
|
||||
storageManager.session.setItem(STORAGE_KEYS.APP_ACTIVE_MAIN_MENU_TAB, mainMenuKey);
|
||||
storageManager.session.setItem(STORAGE_KEYS.APP_ACTIVE_SUB_MENU_TAB, subMenuKey);
|
||||
},
|
||||
|
||||
setActiveMainMenuTab: (mainMenuKey: string) => {
|
||||
set({ activeMainMenuTab: mainMenuKey });
|
||||
// 保存到 session storage,页面刷新后仍然保留
|
||||
storageManager.session.setItem(STORAGE_KEYS.APP_ACTIVE_MAIN_MENU_TAB, mainMenuKey);
|
||||
},
|
||||
|
||||
setActiveSubMenuTab: (subMenuKey: string) => {
|
||||
set({ activeSubMenuTab: subMenuKey });
|
||||
// 保存到 session storage,页面刷新后仍然保留
|
||||
storageManager.session.setItem(STORAGE_KEYS.APP_ACTIVE_SUB_MENU_TAB, subMenuKey);
|
||||
},
|
||||
}));
|
||||
|
||||
|
||||
@@ -3,13 +3,7 @@
|
||||
*/
|
||||
|
||||
// User Store
|
||||
export {
|
||||
useUserStore,
|
||||
useUser,
|
||||
useIsLoggedIn,
|
||||
useToken,
|
||||
restoreUserState,
|
||||
} from './userStore';
|
||||
export { useUserStore, useUser, useIsLoggedIn, useToken, restoreUserState } from './userStore';
|
||||
export type { User } from './userStore';
|
||||
|
||||
// Settings Store
|
||||
@@ -25,14 +19,10 @@ export {
|
||||
export type { Theme, Language } from './settingsStore';
|
||||
|
||||
// Tenant Store
|
||||
export {
|
||||
default as useTenantStore,
|
||||
restoreTenantState,
|
||||
} from './tenantStore';
|
||||
export { default as useTenantStore, restoreTenantState } from './tenantStore';
|
||||
|
||||
// Game Store
|
||||
export {
|
||||
default as useGameStore,
|
||||
restoreGameState,
|
||||
} from './gameStore';
|
||||
export { default as useGameStore, restoreGameState } from './gameStore';
|
||||
|
||||
// Msg Store
|
||||
export { default as useMsgStore, restoreMsgState } from './msgStore';
|
||||
|
||||
@@ -16,6 +16,9 @@ interface State {
|
||||
notices: Record<string, any>[];
|
||||
homeBanner: Record<string, any>[];
|
||||
mineBanner: Record<string, any>[];
|
||||
unreadMessage: number;
|
||||
unreadFeedback: number;
|
||||
unreadMyMessage: number;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -34,6 +37,9 @@ const useMsgStore = create<State & Actions>()((set, get) => ({
|
||||
notices: [],
|
||||
homeBanner: [],
|
||||
mineBanner: [],
|
||||
unreadMessage: 0, // 未读收件箱
|
||||
unreadFeedback: 0, // 未读问题反馈
|
||||
unreadMyMessage: 0, // 未读我的消息
|
||||
|
||||
// actions
|
||||
setNotices: (list: Record<string, any>[]) => {
|
||||
@@ -54,6 +60,9 @@ const useMsgStore = create<State & Actions>()((set, get) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
export const useUnreadMessageTotal = () =>
|
||||
useMsgStore((state) => state.unreadMessage + state.unreadFeedback + state.unreadMyMessage);
|
||||
|
||||
// 从 AsyncStorage 恢复状态的函数
|
||||
export const restoreMsgState = async () => {
|
||||
try {
|
||||
|
||||
@@ -150,4 +150,3 @@ export const useSoundEnabled = () => useSettingsStore((state) => state.soundEnab
|
||||
|
||||
// 获取触觉反馈状态
|
||||
export const useHapticsEnabled = () => useSettingsStore((state) => state.hapticsEnabled);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { create } from 'zustand';
|
||||
// import { useShallow } from 'zustand/react/shallow';
|
||||
import storageManager, { STORAGE_KEYS } from '@/utils/storageManager';
|
||||
import { tenantService } from '@/services';
|
||||
|
||||
import { get, find } from 'lodash-es';
|
||||
|
||||
/**
|
||||
* 租户信息接口
|
||||
@@ -16,7 +16,8 @@ export interface Tenant {
|
||||
tid: number;
|
||||
proxy: number;
|
||||
create_time: string;
|
||||
domain_addr: string
|
||||
domain_addr: string;
|
||||
logo_manage: Record<string, any>[];
|
||||
}
|
||||
|
||||
// 状态
|
||||
@@ -26,10 +27,9 @@ interface State {
|
||||
|
||||
// 操作
|
||||
interface Actions {
|
||||
setTenantInfo: (data: Record<string, any>) => void;
|
||||
setTenantInfo: (data: Tenant) => void;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 租户状态 Store
|
||||
*/
|
||||
@@ -37,7 +37,6 @@ const useTenantStore = create<State & Actions>()((set, get) => ({
|
||||
// 初始状态
|
||||
tenantInfo: null,
|
||||
|
||||
|
||||
// 设置租户信息(通用方法,包含持久化逻辑)
|
||||
setTenantInfo: (data: any) => {
|
||||
set({ tenantInfo: data });
|
||||
@@ -71,11 +70,30 @@ export const restoreTenantState = async () => {
|
||||
* 选择器 Hooks(优化性能,避免不必要的重渲染)
|
||||
*/
|
||||
|
||||
// 获取用户信息
|
||||
// 获取 store state 租户信息
|
||||
export const useTenantInfo = () => useTenantStore((state) => state.tenantInfo);
|
||||
|
||||
// 租户数据是否加载完成
|
||||
export const useTenantLoad = () => useTenantStore((state) => !!state.tenantInfo?.tid || !!state.tenantInfo?.create_time);
|
||||
export const useTenantLoad = () =>
|
||||
useTenantStore((state) => !!state.tenantInfo?.tid || !!state.tenantInfo?.create_time);
|
||||
|
||||
// 获取 logo
|
||||
export const useLogo = (): string =>
|
||||
useTenantStore((state) => {
|
||||
return get(
|
||||
find(state.tenantInfo?.logo_manage, (item) => item.message_id === 29 && item.pic_addr),
|
||||
'pic_addr'
|
||||
);
|
||||
});
|
||||
|
||||
// 获取 download logo
|
||||
export const useDownloadLogo = (): string =>
|
||||
useTenantStore((state) => {
|
||||
return get(
|
||||
find(state.tenantInfo?.logo_manage, (item) => item.message_id === 34 && item.pic_addr),
|
||||
'pic_addr'
|
||||
);
|
||||
});
|
||||
|
||||
// 获取租户信息
|
||||
export const requestTenantInfo = async (): Promise<Tenant> => {
|
||||
|
||||
Reference in New Issue
Block a user