175 lines
4.5 KiB
TypeScript
175 lines
4.5 KiB
TypeScript
import type { TabBar } from '@uni-helper/vite-plugin-uni-pages'
|
|
import type { CustomTabBarItem, NativeTabBarItem } from './types'
|
|
|
|
/**
|
|
* tabbar 选择的策略
|
|
* 0: 'NO_TABBAR' 无 tabbar
|
|
* 1: 'NATIVE_TABBAR' 完全原生 tabbar
|
|
* 2: 'CUSTOM_TABBAR_WITH_CACHE' 有缓存自定义 tabbar
|
|
* 3: 'CUSTOM_TABBAR_WITHOUT_CACHE' 无缓存自定义 tabbar
|
|
*/
|
|
export const TABBAR_STRATEGY_MAP = {
|
|
NO_TABBAR: 0,
|
|
NATIVE_TABBAR: 1,
|
|
CUSTOM_TABBAR_WITH_CACHE: 2,
|
|
CUSTOM_TABBAR_WITHOUT_CACHE: 3,
|
|
}
|
|
|
|
export const selectedTabbarStrategy = TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITH_CACHE
|
|
|
|
// 原生 tabbar 配置(备用)
|
|
export const nativeTabbarList: NativeTabBarItem[] = [
|
|
{
|
|
iconPath: 'static/tabbar/home.png',
|
|
selectedIconPath: 'static/tabbar/homeHL.png',
|
|
pagePath: 'pages/index/index',
|
|
text: '首页',
|
|
},
|
|
{
|
|
iconPath: 'static/tabbar/personal.png',
|
|
selectedIconPath: 'static/tabbar/personalHL.png',
|
|
pagePath: 'pages/me/me',
|
|
text: '我的',
|
|
},
|
|
]
|
|
|
|
// ==================== 用户端 Tabbar 配置 ====================
|
|
export const userTabbarList: CustomTabBarItem[] = [
|
|
{
|
|
text: '首页',
|
|
pagePath: 'pages/index/index',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-home',
|
|
},
|
|
{
|
|
pagePath: 'pages/sort/index',
|
|
text: '分类',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-view-mode-2',
|
|
},
|
|
{
|
|
pagePath: 'pages/goods/cart',
|
|
text: '购物车',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-shopping-cart',
|
|
},
|
|
{
|
|
pagePath: 'pages/me/me',
|
|
text: '我的',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-user',
|
|
},
|
|
]
|
|
|
|
// ==================== 商家端 Tabbar 配置 ====================
|
|
export const merchantTabbarList: CustomTabBarItem[] = [
|
|
{
|
|
text: '工作台',
|
|
pagePath: 'pagesMerchant/dashboard/index',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-dashboard',
|
|
},
|
|
{
|
|
pagePath: 'pagesMerchant/order/list',
|
|
text: '订单',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-document',
|
|
},
|
|
{
|
|
pagePath: 'pagesMerchant/goods/list',
|
|
text: '商品',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-product',
|
|
},
|
|
{
|
|
pagePath: 'pagesMerchant/finance/index',
|
|
text: '财务',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-wallet',
|
|
},
|
|
{
|
|
pagePath: 'pagesMerchant/me/index',
|
|
text: '我的',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-user',
|
|
},
|
|
]
|
|
|
|
// ==================== 银行端 Tabbar 配置 ====================
|
|
export const bankTabbarList: CustomTabBarItem[] = [
|
|
{
|
|
text: '工作台',
|
|
pagePath: 'pagesBank/dashboard/index',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-analytics',
|
|
},
|
|
{
|
|
pagePath: 'pagesBank/audit/list',
|
|
text: '审核',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-task-approved',
|
|
},
|
|
{
|
|
pagePath: 'pagesBank/customer/list',
|
|
text: '客户',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-group',
|
|
},
|
|
{
|
|
pagePath: 'pagesBank/me/index',
|
|
text: '我的',
|
|
iconType: 'unocss',
|
|
icon: 'i-carbon-user',
|
|
},
|
|
]
|
|
|
|
// 根据客户端类型获取对应的 tabbar 配置
|
|
export type ClientTypeKey = 'user' | 'merchant' | 'bank'
|
|
export function getTabbarListByClientType(clientType: ClientTypeKey): CustomTabBarItem[] {
|
|
const tabbarMap: Record<ClientTypeKey, CustomTabBarItem[]> = {
|
|
user: userTabbarList,
|
|
merchant: merchantTabbarList,
|
|
bank: bankTabbarList,
|
|
}
|
|
return tabbarMap[clientType] || userTabbarList
|
|
}
|
|
|
|
// 默认使用用户端配置
|
|
export const customTabbarList: CustomTabBarItem[] = userTabbarList
|
|
|
|
/**
|
|
* 是否启用 tabbar 缓存
|
|
*/
|
|
export const tabbarCacheEnable
|
|
= [TABBAR_STRATEGY_MAP.NATIVE_TABBAR, TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITH_CACHE].includes(selectedTabbarStrategy)
|
|
|
|
/**
|
|
* 是否启用自定义 tabbar
|
|
*/
|
|
export const customTabbarEnable
|
|
= [TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITH_CACHE, TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITHOUT_CACHE].includes(selectedTabbarStrategy)
|
|
|
|
/**
|
|
* 是否需要隐藏原生 tabbar
|
|
*/
|
|
export const needHideNativeTabbar = selectedTabbarStrategy === TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITH_CACHE
|
|
|
|
const _tabbarList = customTabbarEnable ? customTabbarList.map(item => ({ text: item.text, pagePath: item.pagePath })) : nativeTabbarList
|
|
export const tabbarList = customTabbarEnable ? customTabbarList : nativeTabbarList
|
|
|
|
const _tabbar: TabBar = {
|
|
custom: selectedTabbarStrategy === TABBAR_STRATEGY_MAP.CUSTOM_TABBAR_WITH_CACHE,
|
|
color: '#999999',
|
|
selectedColor: '#018d71',
|
|
backgroundColor: '#F8F8F8',
|
|
borderStyle: 'black',
|
|
height: '50px',
|
|
fontSize: '10px',
|
|
iconWidth: '24px',
|
|
spacing: '3px',
|
|
list: _tabbarList as unknown as TabBar['list'],
|
|
}
|
|
|
|
export const tabBar = tabbarCacheEnable ? _tabbar : undefined
|
|
|