feat: update
This commit is contained in:
@ -1,14 +1,11 @@
|
||||
import { Tabbar } from '@taroify/core';
|
||||
import classNames from 'classnames';
|
||||
import { useCallback } from 'react';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
|
||||
import { APP_TAB_BAR_ID, RoleType, PageType, PageUrl } from '@/constants/app';
|
||||
import { ANCHOR_TAB_LIST, COMPANY_TAB_LIST, TabItemType } from '@/hooks/use-config';
|
||||
import useMessage from '@/hooks/use-message';
|
||||
import useRoleType from '@/hooks/user-role-type';
|
||||
import { changeHomePage } from '@/store/actions';
|
||||
import { selectHomePageType } from '@/store/selector';
|
||||
import { logWithPrefix } from '@/utils/common';
|
||||
import { switchTab } from '@/utils/route';
|
||||
|
||||
@ -16,6 +13,7 @@ import './index.less';
|
||||
|
||||
interface IProps {
|
||||
className?: string;
|
||||
type: PageType;
|
||||
}
|
||||
|
||||
const PREFIX = 'base-tab-bar';
|
||||
@ -40,25 +38,21 @@ const TabItem = (props: { item: TabItemType }) => {
|
||||
);
|
||||
};
|
||||
|
||||
function BaseTabBar(props: IProps) {
|
||||
const { className } = props;
|
||||
function BaseTabBar({ className, type }: IProps) {
|
||||
const roleType = useRoleType();
|
||||
const currentPage = useSelector(selectHomePageType);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const tabs = roleType === RoleType.Anchor ? ANCHOR_TAB_LIST : COMPANY_TAB_LIST;
|
||||
|
||||
const handleTabClick = useCallback(
|
||||
(value: PageType) => {
|
||||
if (value === currentPage) {
|
||||
if (value === type) {
|
||||
return;
|
||||
}
|
||||
dispatch(changeHomePage(value));
|
||||
const item = tabs.find((i: TabItemType) => i.type === value);
|
||||
log('tab bar changed', value, item?.pagePath);
|
||||
item && switchTab(item.pagePath as PageUrl);
|
||||
},
|
||||
[tabs, currentPage, dispatch]
|
||||
[tabs, type]
|
||||
);
|
||||
|
||||
// useEffect(() => {
|
||||
@ -72,14 +66,14 @@ function BaseTabBar(props: IProps) {
|
||||
|
||||
return (
|
||||
<div className={classNames(`${PREFIX}__wrapper`, className)} id={APP_TAB_BAR_ID}>
|
||||
<Tabbar className={PREFIX} defaultValue={currentPage}>
|
||||
<Tabbar className={PREFIX} value={type}>
|
||||
{tabs.map((item: TabItemType) => {
|
||||
return (
|
||||
<Tabbar.TabItem
|
||||
key={item.pagePath}
|
||||
value={item.type}
|
||||
onClick={() => handleTabClick(item.type)}
|
||||
className={classNames(`${PREFIX}__item`, { selected: item.type === currentPage })}
|
||||
className={classNames(`${PREFIX}__item`, { selected: item.type === type })}
|
||||
>
|
||||
<TabItem item={item} />
|
||||
</Tabbar.TabItem>
|
||||
|
||||
Reference in New Issue
Block a user