- 8 个页面 exercise-card 由 bind:tap 改为 catch:tap,拦截原生 tap 冒泡 避免一次点击被『自定义事件 + 原生冒泡』触发两次, 第二次 e.detail 无 id → navigateTo detail?id=undefined → 404 - 所有 onExercise 顶部加 id 守卫,无 id 直接 return - exercise-card 点击前校验 exercise.id,缺失不触发 - detail onLoad 的 id 为空时直接显示空态,不再发起错误请求
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
const app = getApp();
|
|
const favSvc = require('../../services/favorite');
|
|
const auth = require('../../utils/auth');
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 20,
|
|
list: [],
|
|
loading: true,
|
|
managing: false
|
|
},
|
|
|
|
onLoad() {
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20 });
|
|
},
|
|
|
|
onShow() {
|
|
if (auth.isLogin()) this.load();
|
|
else {
|
|
wx.showToast({ title: '请先登录', icon: 'none' });
|
|
setTimeout(() => wx.navigateBack(), 600);
|
|
}
|
|
},
|
|
|
|
load() {
|
|
this.setData({ loading: true });
|
|
favSvc.listExercises().then((list) => {
|
|
this.setData({ list: list || [], loading: false });
|
|
}).catch(() => {
|
|
this.setData({ list: [], loading: false });
|
|
});
|
|
},
|
|
|
|
onManage() {
|
|
this.setData({ managing: !this.data.managing });
|
|
},
|
|
|
|
onRemove(e) {
|
|
const id = e.currentTarget.dataset.id;
|
|
favSvc.removeExercise(id).then(() => {
|
|
const list = this.data.list.filter(i => i.id !== id);
|
|
this.setData({ list });
|
|
wx.showToast({ title: '已移除', icon: 'none' });
|
|
}).catch(() => {});
|
|
},
|
|
|
|
onExercise(e) {
|
|
if (!e || !e.detail || !e.detail.id) return;
|
|
if (this.data.managing) return;
|
|
wx.navigateTo({ url: '/pages/detail/detail?id=' + encodeURIComponent(e.detail.id) });
|
|
},
|
|
|
|
goRecommend() {
|
|
wx.navigateTo({ url: '/pages/recommend/recommend' });
|
|
}
|
|
});
|