0.0.0
This commit is contained in:
62
miniprogram/pages/records/records.js
Normal file
62
miniprogram/pages/records/records.js
Normal file
@@ -0,0 +1,62 @@
|
||||
// pages/records/records — 6/6b 记录(Tab,含空状态)
|
||||
const { call } = require('../../utils/cloud.js');
|
||||
const store = require('../../utils/store.js');
|
||||
const { ACHIEVEMENTS, TOTAL } = require('../../utils/achievements.js');
|
||||
const { formatDurationCN, formatDistance, toDateStr } = require('../../utils/format.js');
|
||||
|
||||
Page({
|
||||
data: {
|
||||
isEmpty: false,
|
||||
dogName: '豆豆',
|
||||
primaryDogId: '',
|
||||
wall: [],
|
||||
unlockedCount: 0,
|
||||
total: TOTAL,
|
||||
walks: [],
|
||||
dogs: [],
|
||||
},
|
||||
|
||||
onShow() {
|
||||
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
|
||||
this.getTabBar().setData({ selected: 0, walkState: (store.getWalkSession() || {}).status || 'idle' });
|
||||
}
|
||||
this.load();
|
||||
},
|
||||
|
||||
async load() {
|
||||
const dogs = store.getState().dogs || [];
|
||||
const primaryDogId = store.getState().currentDogId || (dogs[0] && dogs[0]._id) || '';
|
||||
this.setData({ dogs, primaryDogId, dogName: (dogs[0] && dogs[0].name) || '狗狗' });
|
||||
|
||||
// 历史
|
||||
const hist = await call('getHistory', {});
|
||||
const walks = (hist.ok ? hist.data.walks : []).slice(0, 8).map((w) => ({
|
||||
_id: w._id,
|
||||
title: `${toDateStr(w.startAt)} · ${(w.dogNames || []).join('、')}`,
|
||||
sub: `${formatDurationCN(w.duration)} · ${formatDistance(w.distance)}`,
|
||||
isManual: w.isManual,
|
||||
}));
|
||||
|
||||
// 成就概览(取前 4,基于主狗解锁状态)
|
||||
let wall = ACHIEVEMENTS.slice(0, 4).map((a) => ({ key: a.key, name: a.name, unlocked: false }));
|
||||
let unlockedCount = 0;
|
||||
if (primaryDogId) {
|
||||
const dd = await call('getDogDetail', { dogId: primaryDogId });
|
||||
if (dd.ok) {
|
||||
const keys = new Set(dd.data.achievements.unlocked.map((u) => u.achievementKey));
|
||||
unlockedCount = dd.data.achievements.unlocked.length;
|
||||
wall = ACHIEVEMENTS.slice(0, 4).map((a) => ({ key: a.key, name: a.name, unlocked: keys.has(a.key) }));
|
||||
}
|
||||
}
|
||||
|
||||
this.setData({ isEmpty: walks.length === 0, walks, wall, unlockedCount });
|
||||
},
|
||||
|
||||
goAch() {
|
||||
const q = this.data.primaryDogId ? `?dogId=${this.data.primaryDogId}` : '';
|
||||
wx.navigateTo({ url: `/pages/achievements/achievements${q}` });
|
||||
},
|
||||
startWalk() { wx.navigateTo({ url: '/pages/walking/walking' }); },
|
||||
openAdd() { this.selectComponent('#addSheet').open(); },
|
||||
onSaved() { this.load(); },
|
||||
});
|
||||
Reference in New Issue
Block a user