- miniprogram/config.js: BASE_URL 指向 http://192.227.237.8:3001 - 动作标题中文化(nameZh),搜索匹配 name/nameZh/nameEn - 新增计划/收藏/我的 等页面与组件 - 后端 Docker 化(Dockerfile/.dockerignore)与翻译脚本 - .gitignore 补充 .DS_Store
78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
const app = getApp();
|
|
const planSvc = require('../../services/plan');
|
|
const favSvc = require('../../services/favorite');
|
|
const auth = require('../../utils/auth');
|
|
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 20,
|
|
slug: '',
|
|
collection: null,
|
|
exercises: [],
|
|
total: 0,
|
|
loading: true,
|
|
favorited: false
|
|
},
|
|
|
|
onLoad(query) {
|
|
const slug = query.slug || '';
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20, slug });
|
|
this.load();
|
|
if (auth.isLogin()) {
|
|
favSvc.planStatus(slug).then((r) => {
|
|
this.setData({ favorited: !!(r && r.favorited) });
|
|
}).catch(() => {});
|
|
}
|
|
},
|
|
|
|
load() {
|
|
this.setData({ loading: true });
|
|
planSvc.officialExercises(this.data.slug, 1, 60).then((res) => {
|
|
this.setData({
|
|
collection: res.collection,
|
|
exercises: (res && res.items) || [],
|
|
total: (res && res.total) || 0,
|
|
loading: false
|
|
});
|
|
}).catch(() => {
|
|
this.setData({ loading: false });
|
|
});
|
|
},
|
|
|
|
// 收藏 / 取消收藏官方计划
|
|
onToggleFav() {
|
|
auth.ensureLogin().then(() => {
|
|
const slug = this.data.slug;
|
|
const wasFav = this.data.favorited;
|
|
const op = wasFav ? favSvc.removePlan(slug) : favSvc.addPlan(slug);
|
|
op.then(() => {
|
|
this.setData({ favorited: !wasFav });
|
|
wx.showToast({ title: wasFav ? '已取消收藏' : '已收藏', icon: 'none' });
|
|
}).catch(() => {});
|
|
}).catch(() => {});
|
|
},
|
|
|
|
// 导入到我的计划
|
|
onImport() {
|
|
auth.ensureLogin().then(() => {
|
|
wx.showLoading({ title: '导入中…', mask: true });
|
|
planSvc.importOfficial(this.data.slug).then(() => {
|
|
wx.hideLoading();
|
|
wx.showToast({ title: '已导入到我的计划', icon: 'success' });
|
|
setTimeout(() => {
|
|
wx.navigateTo({ url: '/pages/my-plans/my-plans' });
|
|
}, 600);
|
|
}).catch(() => {
|
|
wx.hideLoading();
|
|
});
|
|
}).catch(() => {});
|
|
},
|
|
|
|
onExercise(e) {
|
|
wx.navigateTo({
|
|
url: '/pages/detail/detail?from=collection&slug=' +
|
|
encodeURIComponent(this.data.slug) + '&id=' + encodeURIComponent(e.detail.id)
|
|
});
|
|
}
|
|
});
|