0.0.0
This commit is contained in:
59
miniprogram/pages/dog-detail/dog-detail.js
Normal file
59
miniprogram/pages/dog-detail/dog-detail.js
Normal file
@@ -0,0 +1,59 @@
|
||||
// pages/dog-detail/dog-detail — 4 狗狗主页
|
||||
// 累计只用 次数/公里/连续天数;成就墙露灰锁(docs/05 R8, R10)
|
||||
const { call } = require('../../utils/cloud.js');
|
||||
const { ACHIEVEMENTS, TOTAL } = require('../../utils/achievements.js');
|
||||
const { formatDurationCN, formatDistance, toDateStr } = require('../../utils/format.js');
|
||||
|
||||
const GENDER_TEXT = { male: '公', female: '母' };
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
dog: null,
|
||||
stats: null,
|
||||
metaText: '',
|
||||
wall: [],
|
||||
unlockedCount: 0,
|
||||
total: TOTAL,
|
||||
recent: [],
|
||||
},
|
||||
|
||||
onLoad(o) { this.dogId = o.id; },
|
||||
onShow() { if (this.dogId) this.load(); },
|
||||
|
||||
async load() {
|
||||
const res = await call('getDogDetail', { dogId: this.dogId });
|
||||
if (!res.ok) return;
|
||||
const { dog, achievements, recentWalks } = res.data;
|
||||
|
||||
const metaParts = [dog.breed];
|
||||
if (dog.ageText) metaParts.push(dog.ageText);
|
||||
if (GENDER_TEXT[dog.gender]) metaParts.push(GENDER_TEXT[dog.gender]);
|
||||
|
||||
const unlockedKeys = new Set(achievements.unlocked.map((u) => u.achievementKey));
|
||||
const wall = ACHIEVEMENTS.map((a) => ({
|
||||
key: a.key, name: a.name, unlocked: unlockedKeys.has(a.key),
|
||||
}));
|
||||
|
||||
const recent = recentWalks.map((w) => ({
|
||||
_id: w._id,
|
||||
title: `${toDateStr(w.startAt)}${w.isManual ? ' · 补记' : ''}`,
|
||||
sub: `${formatDurationCN(w.duration)} · ${formatDistance(w.distance)}` +
|
||||
(w.dogSteps != null ? ` · ${w.dogSteps}狗步` : ''),
|
||||
}));
|
||||
|
||||
this.setData({
|
||||
loading: false,
|
||||
dog,
|
||||
stats: dog.stats || {},
|
||||
metaText: metaParts.join(' · '),
|
||||
wall,
|
||||
unlockedCount: achievements.unlocked.length,
|
||||
total: achievements.total,
|
||||
recent,
|
||||
});
|
||||
},
|
||||
|
||||
goEdit() { wx.navigateTo({ url: `/pages/dog-edit/dog-edit?id=${this.dogId}` }); },
|
||||
goAchievements() { wx.navigateTo({ url: `/pages/achievements/achievements?dogId=${this.dogId}` }); },
|
||||
});
|
||||
Reference in New Issue
Block a user