- miniprogram/config.js: BASE_URL 指向 http://192.227.237.8:3001 - 动作标题中文化(nameZh),搜索匹配 name/nameZh/nameEn - 新增计划/收藏/我的 等页面与组件 - 后端 Docker 化(Dockerfile/.dockerignore)与翻译脚本 - .gitignore 补充 .DS_Store
93 lines
2.5 KiB
JavaScript
93 lines
2.5 KiB
JavaScript
// 训练计划服务:我自己的计划 CRUD + 官方计划分级与导入。
|
|
const { request } = require('../utils/request');
|
|
|
|
function injectDisplayName(item) {
|
|
if (!item) return item;
|
|
item.displayName = item.nameZh || item.name || '';
|
|
return item;
|
|
}
|
|
|
|
function injectDisplayNames(list) {
|
|
if (!list || !Array.isArray(list)) return list || [];
|
|
return list.map(injectDisplayName);
|
|
}
|
|
|
|
function buildQuery(params) {
|
|
const qs = Object.keys(params || {})
|
|
.filter(k => params[k] !== '' && params[k] !== undefined && params[k] !== null)
|
|
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(params[k]))
|
|
.join('&');
|
|
return qs ? '?' + qs : '';
|
|
}
|
|
|
|
// 我自己的计划列表
|
|
function listMine() {
|
|
return request({ url: '/api/plans', method: 'GET' });
|
|
}
|
|
|
|
// 新建计划
|
|
function create(dto) {
|
|
return request({ url: '/api/plans', method: 'POST', data: dto });
|
|
}
|
|
|
|
// 计划详情
|
|
function get(id) {
|
|
return request({ url: '/api/plans/' + encodeURIComponent(id), method: 'GET' }).then((plan) => {
|
|
if (plan && plan.exercises) plan.exercises = injectDisplayNames(plan.exercises);
|
|
return plan;
|
|
});
|
|
}
|
|
|
|
// 更新计划元信息
|
|
function update(id, dto) {
|
|
return request({ url: '/api/plans/' + encodeURIComponent(id), method: 'PATCH', data: dto });
|
|
}
|
|
|
|
// 删除计划
|
|
function remove(id) {
|
|
return request({ url: '/api/plans/' + encodeURIComponent(id), method: 'DELETE' });
|
|
}
|
|
|
|
// 向计划添加动作(自动去重)
|
|
function addExercise(id, exerciseId) {
|
|
return request({ url: '/api/plans/' + encodeURIComponent(id) + '/exercises', method: 'POST', data: { exerciseId } });
|
|
}
|
|
|
|
// 从计划移除动作
|
|
function removeExercise(id, exerciseId) {
|
|
return request({ url: '/api/plans/' + encodeURIComponent(id) + '/exercises/' + encodeURIComponent(exerciseId), method: 'DELETE' });
|
|
}
|
|
|
|
// 导入官方计划为我的副本
|
|
function importOfficial(slug, name) {
|
|
return request({ url: '/api/plans/import', method: 'POST', data: { slug, name } });
|
|
}
|
|
|
|
// 官方计划分级分组
|
|
function officialGroups() {
|
|
return request({ url: '/api/plans/official', method: 'GET' });
|
|
}
|
|
|
|
// 官方计划下的动作(分页)
|
|
function officialExercises(slug, page = 1, pageSize = 30) {
|
|
return request({
|
|
url: '/api/plans/official/' + encodeURIComponent(slug) + '/exercises' + buildQuery({ page, pageSize })
|
|
}).then((res) => {
|
|
if (res && res.items) res.items = injectDisplayNames(res.items);
|
|
return res;
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
listMine,
|
|
create,
|
|
get,
|
|
update,
|
|
remove,
|
|
addExercise,
|
|
removeExercise,
|
|
importOfficial,
|
|
officialGroups,
|
|
officialExercises
|
|
};
|