|
|
|
@ -2,7 +2,7 @@ |
|
|
|
* 自定义 TabBar - 中间凸起样式 |
|
|
|
* 自定义 TabBar - 中间凸起样式 |
|
|
|
* 参考:https://developer.aliyun.com/article/1228635
|
|
|
|
* 参考:https://developer.aliyun.com/article/1228635
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
import { CoverView, CoverImage } from '@tarojs/components' |
|
|
|
import { View, Image } from '@tarojs/components' |
|
|
|
import Taro from '@tarojs/taro' |
|
|
|
import Taro from '@tarojs/taro' |
|
|
|
import { observer } from 'mobx-react' |
|
|
|
import { observer } from 'mobx-react' |
|
|
|
import { TAB_BAR_CONFIG } from '../constants/config' |
|
|
|
import { TAB_BAR_CONFIG } from '../constants/config' |
|
|
|
@ -40,7 +40,7 @@ const TAB_BAR_ITEMS = [ |
|
|
|
const CustomTabBar = observer(() => { |
|
|
|
const CustomTabBar = observer(() => { |
|
|
|
const pages = Taro.getCurrentPages() |
|
|
|
const pages = Taro.getCurrentPages() |
|
|
|
const currentPage = pages[pages.length - 1] |
|
|
|
const currentPage = pages[pages.length - 1] |
|
|
|
const currentPath = '/' + currentPage.route |
|
|
|
const currentPath = currentPage ? '/' + currentPage.route : '/pages/index/index' |
|
|
|
|
|
|
|
|
|
|
|
const handleTabClick = (path: string) => { |
|
|
|
const handleTabClick = (path: string) => { |
|
|
|
if (path === currentPath) return |
|
|
|
if (path === currentPath) return |
|
|
|
@ -55,7 +55,7 @@ const CustomTabBar = observer(() => { |
|
|
|
|
|
|
|
|
|
|
|
// 获取图标
|
|
|
|
// 获取图标
|
|
|
|
const getIcon = (path: string, isActive: boolean) => { |
|
|
|
const getIcon = (path: string, isActive: boolean) => { |
|
|
|
const icons = TAB_ICONS[path] |
|
|
|
const icons = TAB_ICONS[path as keyof typeof TAB_ICONS] |
|
|
|
if (!icons) return homeIcon |
|
|
|
if (!icons) return homeIcon |
|
|
|
return isActive ? icons.active : icons.normal |
|
|
|
return isActive ? icons.active : icons.normal |
|
|
|
} |
|
|
|
} |
|
|
|
@ -66,50 +66,50 @@ const CustomTabBar = observer(() => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<CoverView className="custom-tab-bar"> |
|
|
|
<View className="custom-tab-bar"> |
|
|
|
{/* 背景白色层 */} |
|
|
|
{/* 背景深色层 */} |
|
|
|
<CoverView className="tab-bar-bg" /> |
|
|
|
<View className="tab-bar-bg" /> |
|
|
|
|
|
|
|
|
|
|
|
{/* 中间凸起的圆形背景 */} |
|
|
|
{/* 中间凸起的圆形背景 */} |
|
|
|
{/* <CoverView className="tab-bar-center-bg" /> */} |
|
|
|
<View className="tab-bar-center-bg" /> |
|
|
|
|
|
|
|
|
|
|
|
{/* TabBar 项目 */} |
|
|
|
{/* TabBar 项目 */} |
|
|
|
<CoverView className="tab-bar-content"> |
|
|
|
<View className="tab-bar-content"> |
|
|
|
{TAB_BAR_ITEMS.map((item, index) => { |
|
|
|
{TAB_BAR_ITEMS.map((item, index) => { |
|
|
|
const isActive = currentPath === item.path |
|
|
|
const isActive = currentPath === item.path |
|
|
|
const isCenter = 'isCenter' in item && item.isCenter |
|
|
|
const isCenter = 'isCenter' in item && item.isCenter |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<CoverView |
|
|
|
<View |
|
|
|
key={item.path} |
|
|
|
key={item.path} |
|
|
|
className={`tab-item ${isActive ? 'active' : ''} ${isCenter ? 'center' : ''}`} |
|
|
|
className={`tab-item ${isActive ? 'active' : ''} ${isCenter ? 'center' : ''}`} |
|
|
|
onClick={() => handleTabClick(item.path)} |
|
|
|
onClick={() => handleTabClick(item.path)} |
|
|
|
> |
|
|
|
> |
|
|
|
{isCenter ? ( |
|
|
|
{isCenter ? ( |
|
|
|
// 中间扫码按钮 - 凸起样式
|
|
|
|
// 中间扫码按钮 - 凸起样式
|
|
|
|
<CoverView className="scan-wrapper"> |
|
|
|
<View className="scan-wrapper"> |
|
|
|
<CoverView className="scan-button"> |
|
|
|
<View className="scan-button"> |
|
|
|
<CoverImage |
|
|
|
<Image |
|
|
|
className="scan-icon" |
|
|
|
className="scan-icon" |
|
|
|
src={scanIcon} |
|
|
|
src={scanIcon} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</CoverView> |
|
|
|
</View> |
|
|
|
</CoverView> |
|
|
|
</View> |
|
|
|
) : ( |
|
|
|
) : ( |
|
|
|
// 普通 Tab 项
|
|
|
|
// 普通 Tab 项
|
|
|
|
<CoverView className="tab-content"> |
|
|
|
<View className="tab-content"> |
|
|
|
<CoverImage |
|
|
|
<Image |
|
|
|
className="tab-icon" |
|
|
|
className="tab-icon" |
|
|
|
src={getIcon(item.path, isActive)} |
|
|
|
src={getIcon(item.path, isActive)} |
|
|
|
/> |
|
|
|
/> |
|
|
|
<CoverView className="tab-text">{item.text}</CoverView> |
|
|
|
<View className="tab-text">{item.text}</View> |
|
|
|
</CoverView> |
|
|
|
</View> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</CoverView> |
|
|
|
</View> |
|
|
|
) |
|
|
|
) |
|
|
|
})} |
|
|
|
})} |
|
|
|
</CoverView> |
|
|
|
</View> |
|
|
|
</CoverView> |
|
|
|
</View> |
|
|
|
) |
|
|
|
) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|