mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
97 lines
3.1 KiB
TypeScript
97 lines
3.1 KiB
TypeScript
import type { TabBar } from '@uni-helper/vite-plugin-uni-pages'
|
||
|
||
type FgTabBarItem = TabBar['list'][0] & {
|
||
icon: string
|
||
iconType: 'uiLib' | 'unocss' | 'iconfont'
|
||
}
|
||
|
||
/**
|
||
* tabbar 选择的策略,更详细的介绍见 tabbar.md 文件
|
||
* 0: 'NO_TABBAR' `无 tabbar`
|
||
* 1: 'NATIVE_TABBAR' `完全原生 tabbar`
|
||
* 2: 'CUSTOM_TABBAR_WITH_CACHE' `有缓存自定义 tabbar`
|
||
* 3: 'CUSTOM_TABBAR_WITHOUT_CACHE' `无缓存自定义 tabbar`
|
||
*
|
||
* 温馨提示:本文件的任何代码更改了之后,都需要重新运行,否则 pages.json 不会更新导致错误
|
||
*/
|
||
export const TABBAR_MAP = {
|
||
NO_TABBAR: 0,
|
||
NATIVE_TABBAR: 1,
|
||
CUSTOM_TABBAR_WITH_CACHE: 2,
|
||
CUSTOM_TABBAR_WITHOUT_CACHE: 3,
|
||
}
|
||
// TODO:通过这里切换使用tabbar的策略
|
||
export const selectedTabbarStrategy = TABBAR_MAP.NATIVE_TABBAR
|
||
|
||
// selectedTabbarStrategy==NATIVE_TABBAR(1) 时,需要填 iconPath 和 selectedIconPath
|
||
// selectedTabbarStrategy==CUSTOM_TABBAR(2,3) 时,需要填 icon 和 iconType
|
||
// selectedTabbarStrategy==NO_TABBAR(0) 时,tabbarList 不生效
|
||
export const tabbarList: FgTabBarItem[] = [
|
||
{
|
||
iconPath: 'static/tabbar/robot.png',
|
||
selectedIconPath: 'static/tabbar/robot_activate.png',
|
||
pagePath: 'pages/index/index',
|
||
text: '首页',
|
||
icon: 'home',
|
||
// 选用 UI 框架自带的 icon 时,iconType 为 uiLib
|
||
iconType: 'uiLib',
|
||
},
|
||
{
|
||
iconPath: 'static/tabbar/device.png',
|
||
selectedIconPath: 'static/tabbar/device_activate.png',
|
||
pagePath: 'pages/device/index',
|
||
text: '设备管理',
|
||
icon: 'i-carbon-laptop',
|
||
// 注意 unocss 的图标需要在 页面上引入一下,或者配置到 unocss.config.ts 的 safelist 中
|
||
iconType: 'uiLib',
|
||
},
|
||
{
|
||
iconPath: 'static/tabbar/microphone.png',
|
||
selectedIconPath: 'static/tabbar/microphone_activate.png',
|
||
pagePath: 'pages/voiceprint/index',
|
||
text: '声纹识别',
|
||
icon: 'i-carbon-microphone-filled',
|
||
iconType: 'uiLib',
|
||
},
|
||
{
|
||
iconPath: 'static/tabbar/chat.png',
|
||
selectedIconPath: 'static/tabbar/chat_activate.png',
|
||
pagePath: 'pages/chat-history/index',
|
||
text: '聊天记录',
|
||
icon: 'i-carbon-chat-bot',
|
||
iconType: 'uiLib',
|
||
},
|
||
// {
|
||
// pagePath: 'pages/my/index',
|
||
// text: '我的',
|
||
// icon: '/static/logo.svg',
|
||
// iconType: 'local',
|
||
// },
|
||
// {
|
||
// pagePath: 'pages/mine/index',
|
||
// text: '我的',
|
||
// icon: 'iconfont icon-my',
|
||
// iconType: 'iconfont',
|
||
// },
|
||
]
|
||
|
||
// NATIVE_TABBAR(1) 和 CUSTOM_TABBAR_WITH_CACHE(2) 时,需要tabbar缓存
|
||
export const cacheTabbarEnable = selectedTabbarStrategy === TABBAR_MAP.NATIVE_TABBAR
|
||
|| selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE
|
||
|
||
const _tabbar: TabBar = {
|
||
// 只有微信小程序支持 custom。App 和 H5 不生效
|
||
custom: selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE,
|
||
color: '#e6e6e6',
|
||
selectedColor: '#667dea',
|
||
backgroundColor: '#fff',
|
||
borderStyle: 'black',
|
||
height: '50px',
|
||
fontSize: '10px',
|
||
iconWidth: '24px',
|
||
spacing: '3px',
|
||
list: tabbarList as unknown as TabBar['list'],
|
||
}
|
||
|
||
// 0和1 需要显示底部的tabbar的各种配置,以利用缓存
|
||
export const tabBar = cacheTabbarEnable ? _tabbar : undefined
|