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:
48
miniprogram/pages/search/search.js
Normal file
48
miniprogram/pages/search/search.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const app = getApp();
|
||||
const svc = require('../../services/exercise');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 20,
|
||||
q: '',
|
||||
results: [],
|
||||
loading: false,
|
||||
searched: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.setData({ statusBarHeight: app.globalData.statusBarHeight || 20 });
|
||||
},
|
||||
|
||||
onInput(e) {
|
||||
const q = e.detail.value;
|
||||
this.setData({ q });
|
||||
this.debouncedSearch(q);
|
||||
},
|
||||
|
||||
debouncedSearch(q) {
|
||||
if (this._timer) clearTimeout(this._timer);
|
||||
this._timer = setTimeout(() => this.doSearch(q), 350);
|
||||
},
|
||||
|
||||
doSearch(q) {
|
||||
if (!q || !q.trim()) {
|
||||
this.setData({ results: [], searched: false, loading: false });
|
||||
return;
|
||||
}
|
||||
this.setData({ loading: true });
|
||||
svc.search(q.trim()).then((res) => {
|
||||
this.setData({
|
||||
results: (res && res.items) || [],
|
||||
searched: true,
|
||||
loading: false
|
||||
});
|
||||
}).catch(() => {
|
||||
this.setData({ searched: true, loading: false });
|
||||
});
|
||||
},
|
||||
|
||||
onExercise(e) {
|
||||
wx.navigateTo({ url: '/pages/detail/detail?id=' + encodeURIComponent(e.detail.id) });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user