1) 新增 pages/plan-select(加入我的计划选择器,替换详情页 actionSheet) - 默认展示我全部计划(浏览,不再强制搜索),支持 最近创建/动作最多 排序 + 名称搜索 - 点选即把动作加入该计划并返回;无计划时引导新建 - 入口接在 detail 页「加入计划」(无 planId 时 navigate 至此) 2) 增强 pages/collection(官方训练计划) - 默认展示全部分级,新增 等级筛选 chips + 名称搜索(均用现有字段,不改后端) - 筛选/搜索纯前端,viewGroups 驱动渲染 3) 修复 plan-detail 从「添加动作」返回后列表不刷新(上轮已单独提交 7ff55a6) 4) app.json 注册 plan-select 页面
64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
const app = getApp();
|
|
const planSvc = require('../../services/plan');
|
|
|
|
// 官方训练计划浏览:默认展示全部分级,支持按等级筛选 + 名称搜索(均用现有字段)。
|
|
Page({
|
|
data: {
|
|
statusBarHeight: 20,
|
|
groups: [],
|
|
viewGroups: [],
|
|
levels: [{ value: 'all', label: '全部' }],
|
|
filterLevel: 'all',
|
|
keyword: '',
|
|
loading: true
|
|
},
|
|
|
|
onLoad() {
|
|
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20 });
|
|
this.load();
|
|
},
|
|
|
|
onShow() {
|
|
// 从详情返回(可能收藏/导入变化)时刷新
|
|
if (!this.data.loading && !this.data.keyword && this.data.filterLevel === 'all') this.load();
|
|
},
|
|
|
|
load() {
|
|
this.setData({ loading: true });
|
|
planSvc.officialGroups().then((res) => {
|
|
const groups = (res && res.groups) || [];
|
|
const levels = [{ value: 'all', label: '全部' }].concat(
|
|
groups.map((g) => ({ value: g.level, label: g.label }))
|
|
);
|
|
this.setData({ groups, levels, loading: false });
|
|
this.applyFilter();
|
|
}).catch(() => {
|
|
this.setData({ groups: [], viewGroups: [], levels: [{ value: 'all', label: '全部' }], loading: false });
|
|
});
|
|
},
|
|
|
|
applyFilter() {
|
|
const f = this.data.filterLevel;
|
|
const k = (this.data.keyword || '').trim().toLowerCase();
|
|
let groups = (this.data.groups || []).slice();
|
|
if (f !== 'all') groups = groups.filter((g) => g.level === f);
|
|
if (k) {
|
|
groups = groups
|
|
.map((g) => ({
|
|
...g,
|
|
plans: (g.plans || []).filter((p) => (p.name || '').toLowerCase().includes(k))
|
|
}))
|
|
.filter((g) => (g.plans || []).length);
|
|
}
|
|
this.setData({ viewGroups: groups });
|
|
},
|
|
|
|
onFilter(e) {
|
|
this.setData({ filterLevel: e.detail.value }, () => this.applyFilter());
|
|
},
|
|
|
|
onSearch(e) {
|
|
this.setData({ keyword: e.detail.value }, () => this.applyFilter());
|
|
}
|
|
});
|