- backend: NestJS service with exercise/plan data - miniprogram: WeChat mini program client - exclude node_modules, dist, runtime data-store, local env
41 lines
1019 B
JavaScript
41 lines
1019 B
JavaScript
const app = getApp();
|
|
const svc = require('../../services/exercise');
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 20,
|
|
collections: [],
|
|
counts: {},
|
|
loading: true
|
|
},
|
|
|
|
onLoad() {
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20 });
|
|
this.load();
|
|
},
|
|
|
|
load() {
|
|
this.setData({ loading: true });
|
|
svc.listCollections().then((list) => {
|
|
const collections = list || [];
|
|
this.setData({ collections, loading: false });
|
|
// 异步获取每个训练组合的动作数量
|
|
collections.forEach(c => {
|
|
svc.getCollectionExercises(c.slug, { pageSize: 1 }).then((res) => {
|
|
const key = 'counts.' + c.slug;
|
|
this.setData({ [key]: (res && res.total) || 0 });
|
|
}).catch(() => {});
|
|
});
|
|
}).catch(() => {
|
|
this.setData({ loading: false });
|
|
});
|
|
},
|
|
|
|
onOpen(e) {
|
|
wx.navigateTo({
|
|
url: '/pages/collection-detail/collection-detail?slug=' +
|
|
encodeURIComponent(e.currentTarget.dataset.slug)
|
|
});
|
|
}
|
|
});
|