This commit is contained in:
2026-06-25 18:24:29 +08:00
commit a1190d7d9a
90 changed files with 5459 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
// pages/history/history — 5 遛狗历史 + 手动补记
const { call } = require('../../utils/cloud.js');
const store = require('../../utils/store.js');
const { formatDurationCN, formatDistance, toDateStr } = require('../../utils/format.js');
Page({
data: { groups: [], dogs: [] },
onShow() { this.load(); },
async load() {
const dogs = store.getState().dogs || [];
this.setData({ dogs });
const res = await call('getHistory', {});
if (!res.ok) return;
this.setData({ groups: this.groupByWeek(res.data.walks) });
},
// 本周 / 更早
groupByWeek(walks) {
const now = new Date();
const dow = now.getDay() || 7; // 周一=1
const weekStart = new Date(now.getFullYear(), now.getMonth(), now.getDate() - (dow - 1)).getTime();
const thisWeek = [];
const earlier = [];
walks.forEach((w) => {
const item = {
_id: w._id,
title: `${toDateStr(w.startAt)} · ${(w.dogNames || []).join('、')}`,
sub: `${formatDurationCN(w.duration)} · ${formatDistance(w.distance)}`,
isManual: w.isManual,
};
(w.startAt >= weekStart ? thisWeek : earlier).push(item);
});
const groups = [];
if (thisWeek.length) groups.push({ label: '本周', items: thisWeek });
if (earlier.length) groups.push({ label: '更早', items: earlier });
return groups;
},
openAdd() { this.selectComponent('#addSheet').open(); },
onSaved() { this.load(); },
});

View File

@@ -0,0 +1,6 @@
{
"usingComponents": {
"manual-add-sheet": "/components/manual-add-sheet/index"
},
"navigationBarTitleText": "遛狗历史"
}

View File

@@ -0,0 +1,23 @@
<view class="page">
<view class="top">
<text class="top-title">全部记录</text>
<text class="add-btn" bindtap="openAdd"> 补记</text>
</view>
<block wx:for="{{groups}}" wx:key="label">
<view class="group-label">{{item.label}}</view>
<view class="rows">
<view wx:for="{{item.items}}" wx:for-item="w" wx:key="_id" class="walk-row {{w.isManual?'manual':''}}">
<view class="wr-ico">{{w.isManual ? '✎' : '🐾'}}</view>
<view class="wr-body">
<view class="wr-title">{{w.title}}<text wx:if="{{w.isManual}}" class="tag">补记</text></view>
<view class="wr-sub">{{w.sub}}</view>
</view>
</view>
</view>
</block>
<view wx:if="{{!groups.length}}" class="empty">还没有遛狗记录</view>
<manual-add-sheet id="addSheet" dogs="{{dogs}}" bind:saved="onSaved" />
</view>

View File

@@ -0,0 +1,19 @@
.page { min-height: 100vh; padding: 24rpx 32rpx calc(48rpx + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 12rpx 0 20rpx; }
.top-title { font-size: 28rpx; font-weight: 600; }
.add-btn { font-size: 24rpx; color: var(--accent-deep); }
.group-label { font-size: 22rpx; color: var(--ink-2); padding: 16rpx 4rpx 10rpx; }
.rows { display: flex; flex-direction: column; gap: 16rpx; }
.walk-row { display: flex; align-items: center; gap: 18rpx; padding: 22rpx; background: var(--surface-2); border-radius: var(--radius-sm); }
.walk-row.manual { background: transparent; border: 1rpx dashed var(--line-2); }
.wr-ico { width: var(--icon-size); font-size: var(--icon-size); line-height: 1; text-align: center; }
.walk-row.manual .wr-ico { color: var(--accent-deep); }
.wr-body { flex: 1; }
.wr-title { font-size: 26rpx; }
.wr-sub { font-size: 22rpx; color: var(--ink-2); margin-top: 4rpx; }
.tag { font-size: 20rpx; color: var(--ink-2); background: var(--surface-2); border: 1rpx solid var(--line-2); border-radius: var(--radius-pill); padding: 2rpx 12rpx; margin-left: 12rpx; }
.empty { text-align: center; font-size: 24rpx; color: var(--ink-3); padding: 80rpx 0; }