tabbarList.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import type { TabBar } from '@uni-helper/vite-plugin-uni-pages'
  2. type FgTabBarItem = TabBar['list'][0] & {
  3. icon: string
  4. iconType: 'uiLib' | 'unocss' | 'iconfont'
  5. }
  6. /**
  7. * tabbar 选择的策略,更详细的介绍见 tabbar.md 文件
  8. * 0: 'NO_TABBAR' `无 tabbar`
  9. * 1: 'NATIVE_TABBAR' `完全原生 tabbar`
  10. * 2: 'CUSTOM_TABBAR_WITH_CACHE' `有缓存自定义 tabbar`
  11. * 3: 'CUSTOM_TABBAR_WITHOUT_CACHE' `无缓存自定义 tabbar`
  12. *
  13. * 温馨提示:本文件的任何代码更改了之后,都需要重新运行,否则 pages.json 不会更新导致错误
  14. */
  15. export const TABBAR_MAP = {
  16. NO_TABBAR: 0,
  17. NATIVE_TABBAR: 1,
  18. CUSTOM_TABBAR_WITH_CACHE: 2,
  19. CUSTOM_TABBAR_WITHOUT_CACHE: 3,
  20. }
  21. // TODO:通过这里切换使用tabbar的策略
  22. export const selectedTabbarStrategy = TABBAR_MAP.NATIVE_TABBAR
  23. // selectedTabbarStrategy==NATIVE_TABBAR(1) 时,需要填 iconPath 和 selectedIconPath
  24. // selectedTabbarStrategy==CUSTOM_TABBAR(2,3) 时,需要填 icon 和 iconType
  25. // selectedTabbarStrategy==NO_TABBAR(0) 时,tabbarList 不生效
  26. export const tabbarList: FgTabBarItem[] = [
  27. {
  28. iconPath: 'static/tabbar/home.png',
  29. selectedIconPath: 'static/tabbar/homeHL.png',
  30. pagePath: 'pages/index/index',
  31. text: '首页',
  32. icon: 'home',
  33. // 选用 UI 框架自带的 icon 时,iconType 为 uiLib
  34. iconType: 'uiLib',
  35. },
  36. {
  37. iconPath: 'static/tabbar/example.png',
  38. selectedIconPath: 'static/tabbar/exampleHL.png',
  39. pagePath: 'pages/about/about',
  40. text: '关于',
  41. icon: 'i-carbon-code',
  42. // 注意 unocss 的图标需要在 页面上引入一下,或者配置到 unocss.config.ts 的 safelist 中
  43. iconType: 'unocss',
  44. },
  45. // {
  46. // pagePath: 'pages/my/index',
  47. // text: '我的',
  48. // icon: '/static/logo.svg',
  49. // iconType: 'local',
  50. // },
  51. // {
  52. // pagePath: 'pages/mine/index',
  53. // text: '我的',
  54. // icon: 'iconfont icon-my',
  55. // iconType: 'iconfont',
  56. // },
  57. ]
  58. // NATIVE_TABBAR(1) 和 CUSTOM_TABBAR_WITH_CACHE(2) 时,需要tabbar缓存
  59. export const cacheTabbarEnable = selectedTabbarStrategy === TABBAR_MAP.NATIVE_TABBAR
  60. || selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE
  61. const _tabbar: TabBar = {
  62. // 只有微信小程序支持 custom。App 和 H5 不生效
  63. custom: selectedTabbarStrategy === TABBAR_MAP.CUSTOM_TABBAR_WITH_CACHE,
  64. color: '#999999',
  65. selectedColor: '#018d71',
  66. backgroundColor: '#F8F8F8',
  67. borderStyle: 'black',
  68. height: '50px',
  69. fontSize: '10px',
  70. iconWidth: '24px',
  71. spacing: '3px',
  72. list: tabbarList as unknown as TabBar['list'],
  73. }
  74. // 0和1 需要显示底部的tabbar的各种配置,以利用缓存
  75. export const tabBar = cacheTabbarEnable ? _tabbar : undefined