feat: init fitness-coach (backend + miniprogram)
- backend: NestJS service with exercise/plan data - miniprogram: WeChat mini program client - exclude node_modules, dist, runtime data-store, local env
This commit is contained in:
89
miniprogram/pages/category/category.js
Normal file
89
miniprogram/pages/category/category.js
Normal file
@@ -0,0 +1,89 @@
|
||||
const app = getApp();
|
||||
const svc = require('../../services/exercise');
|
||||
|
||||
const DIM_MAP = {
|
||||
bodyPart: 'body-parts',
|
||||
equipment: 'equipment',
|
||||
target: 'targets',
|
||||
muscleGroup: 'muscle-groups',
|
||||
type: 'types'
|
||||
};
|
||||
|
||||
function labelForDim(d) {
|
||||
return ({
|
||||
bodyPart: '按部位',
|
||||
equipment: '按器械',
|
||||
target: '按目标',
|
||||
muscleGroup: '按肌群',
|
||||
type: '按类型'
|
||||
})[d] || '分类';
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 20,
|
||||
dimension: 'bodyPart',
|
||||
title: '分类',
|
||||
value: '',
|
||||
values: [],
|
||||
activeValue: '',
|
||||
exercises: [],
|
||||
loading: true,
|
||||
page: 1,
|
||||
pageSize: 20,
|
||||
total: 0
|
||||
},
|
||||
|
||||
onLoad(query) {
|
||||
const dimension = query.dimension || 'bodyPart';
|
||||
const value = query.value || '';
|
||||
const title = query.title || labelForDim(dimension);
|
||||
this.setData({
|
||||
statusBarHeight: app.globalData.statusBarHeight || 20,
|
||||
dimension,
|
||||
value,
|
||||
title
|
||||
});
|
||||
this.loadValues();
|
||||
},
|
||||
|
||||
loadValues() {
|
||||
this.setData({ loading: true });
|
||||
const key = DIM_MAP[this.data.dimension] || 'body-parts';
|
||||
svc.getCategories(key).then((items) => {
|
||||
this.setData({
|
||||
values: items || [],
|
||||
activeValue: this.data.value,
|
||||
loading: false
|
||||
});
|
||||
this.loadExercises();
|
||||
}).catch(() => {
|
||||
this.setData({ loading: false });
|
||||
});
|
||||
},
|
||||
|
||||
loadExercises() {
|
||||
this.setData({ loading: true });
|
||||
const params = { page: this.data.page, pageSize: this.data.pageSize };
|
||||
params[this.data.dimension] = this.data.activeValue;
|
||||
svc.listExercises(params).then((res) => {
|
||||
this.setData({
|
||||
exercises: (res && res.items) || [],
|
||||
total: (res && res.total) || 0,
|
||||
loading: false
|
||||
});
|
||||
}).catch(() => {
|
||||
this.setData({ loading: false });
|
||||
});
|
||||
},
|
||||
|
||||
onValue(e) {
|
||||
const value = e.detail.value;
|
||||
if (value === this.data.activeValue) return;
|
||||
this.setData({ activeValue: value, page: 1 }, () => this.loadExercises());
|
||||
},
|
||||
|
||||
onExercise(e) {
|
||||
wx.navigateTo({ url: '/pages/detail/detail?id=' + encodeURIComponent(e.detail.id) });
|
||||
}
|
||||
});
|
||||
9
miniprogram/pages/category/category.json
Normal file
9
miniprogram/pages/category/category.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"navigationStyle": "custom",
|
||||
"usingComponents": {
|
||||
"navbar": "/components/navbar/index",
|
||||
"chip": "/components/chip/index",
|
||||
"exercise-card": "/components/exercise-card/index",
|
||||
"bottom-nav": "/components/bottom-nav/index"
|
||||
}
|
||||
}
|
||||
29
miniprogram/pages/category/category.wxml
Normal file
29
miniprogram/pages/category/category.wxml
Normal file
@@ -0,0 +1,29 @@
|
||||
<view class="page">
|
||||
<navbar title="{{title}}" show-back />
|
||||
|
||||
<view class="section" style="padding-top: 8rpx;">
|
||||
<scroll-view wx:if="{{values.length}}" scroll-x class="filterbar">
|
||||
<chip
|
||||
wx:for="{{values}}"
|
||||
wx:key="value"
|
||||
label="{{item.label}}"
|
||||
value="{{item.value}}"
|
||||
active="{{activeValue === item.value}}"
|
||||
bind:tap="onValue" />
|
||||
<view class="filterbar__spacer"></view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="count muted" wx:if="{{!loading}}">共 {{total}} 个动作</view>
|
||||
|
||||
<view class="grid" wx:if="{{exercises.length}}">
|
||||
<view class="grid__item" wx:for="{{exercises}}" wx:key="id">
|
||||
<exercise-card exercise="{{item}}" bind:tap="onExercise" />
|
||||
</view>
|
||||
</view>
|
||||
<view wx:elif="{{!loading}}" class="empty">暂无数据</view>
|
||||
<view wx:else class="empty">加载中…</view>
|
||||
</view>
|
||||
|
||||
<view style="height: 160rpx;"></view>
|
||||
<bottom-nav active="category" />
|
||||
</view>
|
||||
8
miniprogram/pages/category/category.wxss
Normal file
8
miniprogram/pages/category/category.wxss
Normal file
@@ -0,0 +1,8 @@
|
||||
.page { min-height: 100vh; background: var(--bg-grad); }
|
||||
.filterbar { white-space: nowrap; padding: 8rpx 0 4rpx; }
|
||||
.filterbar chip { display: inline-block; margin-right: 16rpx; }
|
||||
.filterbar__spacer { display: inline-block; width: 4rpx; }
|
||||
.count { font-size: 24rpx; margin: 20rpx 0 8rpx; }
|
||||
.grid { display: flex; flex-wrap: wrap; gap: 18rpx; margin-top: 12rpx; }
|
||||
.grid__item { width: calc((100% - 18rpx) / 2); }
|
||||
.empty { color: var(--text-3); font-size: 26rpx; text-align: center; padding: 80rpx 0; }
|
||||
Reference in New Issue
Block a user