2025-08-18 17:09:44 +08:00
|
|
|
|
import { tabbarList as _tabbarList } from './config'
|
|
|
|
|
|
|
|
|
|
|
|
// TODO 1/2: 中间的鼓包tabbarItem的开关
|
|
|
|
|
|
const BULGE_ENABLE = true
|
|
|
|
|
|
|
|
|
|
|
|
/** tabbarList 里面的 path 从 pages.config.ts 得到 */
|
|
|
|
|
|
const tabbarList = _tabbarList.map(item => ({ ...item, path: `/${item.pagePath}` }))
|
|
|
|
|
|
if (BULGE_ENABLE) {
|
|
|
|
|
|
if (tabbarList.length % 2 === 1) {
|
|
|
|
|
|
console.error('tabbar 数量必须是偶数,否则样式很奇怪!!')
|
|
|
|
|
|
}
|
|
|
|
|
|
tabbarList.splice(tabbarList.length / 2, 0, {
|
|
|
|
|
|
isBulge: true,
|
|
|
|
|
|
} as any)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export { tabbarList }
|
2025-08-15 16:41:03 +08:00
|
|
|
|
|
2024-05-11 11:32:34 +08:00
|
|
|
|
/**
|
2025-08-17 15:00:43 +08:00
|
|
|
|
* 自定义 tabbar 的状态管理,原生 tabbar 无需关注本文件
|
2024-05-11 11:32:34 +08:00
|
|
|
|
* tabbar 状态,增加 storageSync 保证刷新浏览器时在正确的 tabbar 页面
|
2024-05-28 11:33:15 +08:00
|
|
|
|
* 使用reactive简单状态,而不是 pinia 全局状态
|
2024-05-11 11:32:34 +08:00
|
|
|
|
*/
|
2024-05-11 09:36:26 +08:00
|
|
|
|
export const tabbarStore = reactive({
|
2024-05-11 11:36:44 +08:00
|
|
|
|
curIdx: uni.getStorageSync('app-tabbar-index') || 0,
|
2025-07-31 15:34:31 +08:00
|
|
|
|
prevIdx: uni.getStorageSync('app-tabbar-index') || 0,
|
2024-05-11 09:36:26 +08:00
|
|
|
|
setCurIdx(idx: number) {
|
|
|
|
|
|
this.curIdx = idx
|
2024-05-11 11:36:44 +08:00
|
|
|
|
uni.setStorageSync('app-tabbar-index', idx)
|
2024-05-11 09:36:26 +08:00
|
|
|
|
},
|
2025-08-13 20:15:08 +08:00
|
|
|
|
setAutoCurIdx(path: string) {
|
|
|
|
|
|
const index = tabbarList.findIndex(item => item.pagePath === path)
|
|
|
|
|
|
// console.log('index:', index, path)
|
|
|
|
|
|
// console.log('tabbarList:', tabbarList)
|
2025-08-18 17:09:44 +08:00
|
|
|
|
if (index === -1) {
|
|
|
|
|
|
this.setCurIdx(0)
|
2025-08-13 20:15:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2025-08-18 17:09:44 +08:00
|
|
|
|
this.setCurIdx(index)
|
2025-08-13 20:15:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-07-31 15:34:31 +08:00
|
|
|
|
restorePrevIdx() {
|
|
|
|
|
|
if (this.prevIdx === this.curIdx)
|
|
|
|
|
|
return
|
|
|
|
|
|
this.setCurIdx(this.prevIdx)
|
|
|
|
|
|
this.prevIdx = uni.getStorageSync('app-tabbar-index') || 0
|
|
|
|
|
|
},
|
2024-05-11 09:36:26 +08:00
|
|
|
|
})
|