Files
Pet3/miniprogram/custom-tab-bar/index.js
2026-06-25 18:24:29 +08:00

46 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// custom-tab-bar — 三 Tab + 中央状态化「遛狗」FABdocs/04 §2
const store = require('../utils/store.js');
Component({
data: {
selected: 1, // 0=记录 1=我的
// walkState: idle | walking | paused —— 决定中央 FAB 颜色与文案
walkState: 'idle',
},
lifetimes: {
attached() {
this.syncWalkState();
},
},
pageLifetimes: {
show() {
this.syncWalkState();
},
},
methods: {
syncWalkState() {
const session = store.getWalkSession();
this.setData({ walkState: session ? session.status : 'idle' });
},
switchTab(e) {
const { path, index } = e.currentTarget.dataset;
this.setData({ selected: index });
wx.switchTab({ url: path });
},
// 中央「遛狗」按钮:进行中→回遛狗页;空闲→开始(单狗直进/多狗弹层)
onCenterTap() {
if (this.data.walkState !== 'idle') {
wx.navigateTo({ url: '/pages/walking/walking' });
return;
}
// TODO 阶段2单狗直接进 walking多狗触发 multi-dog-sheet
wx.navigateTo({ url: '/pages/walking/walking' });
},
},
});