import { TabBarType } from '../constants/tabbar' import IconFont from '@/components/iconfont/iconfont' type IconfontName = Parameters['0']['name'] type TabBarIndexMap = { [Property: number]: { id: number pagePath: string text: string iconPath: IconfontName selectedIconPath: IconfontName } } export enum TabBarIndex { INDEX = 1, SHOPPING = 2, ORDER = 3, USER = 4 } const INITIAL_STATE = { selectedId: TabBarIndex.INDEX, tabItem: [ { id: TabBarIndex.INDEX, pagePath: '/pages/index/index', text: '首页', iconPath: 'icon-shouye1', selectedIconPath: 'icon-shouye', }, { id: TabBarIndex.SHOPPING, pagePath: '/pages/shopping/index', text: '购物', iconPath: 'icon-gouwu1', selectedIconPath: 'icon-gouwu', }, { id: TabBarIndex.ORDER, pagePath: '/pages/order/index', text: '订单', iconPath: 'icon-dingdan1', selectedIconPath: 'icon-dingdan', }, { id: TabBarIndex.USER, pagePath: '/pages/user/index', text: '我的', iconPath: 'icon-gerenzhongxin1', selectedIconPath: 'icon-gerenzhongxin', }, ], } export type TabBarData = { selectedId: number tabItem?: TabBarIndexMap[number][] } export type TabBarAction = { type: TabBarType data: TabBarData } // TabBarReducer export default (state = INITIAL_STATE, action: TabBarAction) => { const { type, data } = action switch (type) { case TabBarType.SET_SELECTED: return { ...state, selectedId: data.selectedId, } default: return state } }