Files
fitness-coach/miniprogram/components/navbar/index.js
wm 70ff806042 feat: 小程序连接服务器IP + 同步未提交开发
- miniprogram/config.js: BASE_URL 指向 http://192.227.237.8:3001
- 动作标题中文化(nameZh),搜索匹配 name/nameZh/nameEn
- 新增计划/收藏/我的 等页面与组件
- 后端 Docker 化(Dockerfile/.dockerignore)与翻译脚本
- .gitignore 补充 .DS_Store
2026-07-22 14:05:30 +08:00

45 lines
1.3 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.

const app = getApp();
Component({
properties: {
title: { type: String, value: '' },
showBack: { type: Boolean, value: false },
// 拦截返回:为 true 时点击返回仅触发 bind:back 事件,由页面自行处理(如未保存草稿确认)
interceptBack: { type: Boolean, value: false }
},
data: {
statusBarHeight: 20,
// 运行期根据页面栈动态决定:只有确实存在上一页时才显示返回键,
// 避免在底部 tab 根页(页面栈深度 = 1误显示返回键
canBack: false
},
lifetimes: {
attached() {
const h = (app.globalData && app.globalData.statusBarHeight) || 20;
const pages = getCurrentPages();
this.setData({
statusBarHeight: h,
canBack: pages.length > 1
});
}
},
methods: {
onBack() {
const pages = getCurrentPages();
// 页面要求自行处理返回逻辑(典型场景:编辑页有未保存内容需确认)
if (this.data.interceptBack) {
this.triggerEvent('back');
return;
}
if (pages.length > 1) {
wx.navigateBack({ delta: 1 });
} else {
// 兜底:确实没有上一页时回到首页(正常 tab 根页不会显示返回键,此为保险)
wx.reLaunch({ url: '/pages/index/index' });
}
}
}
});