Files
aiot-uniapp/src/tabbar/store.ts

33 lines
993 B
TypeScript
Raw Normal View History

import { tabbarList } from './config'
2024-05-11 11:32:34 +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,
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
},
setAutoCurIdx(path: string) {
const index = tabbarList.findIndex(item => item.pagePath === path)
// console.log('index:', index, path)
// console.log('tabbarList:', tabbarList)
if (index !== -1) {
this.setCurIdx(index)
}
else {
this.setCurIdx(0)
}
},
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
})