feat: support shared pet care tasks and smooth daily page return
ci-cd / verify (push) Successful in 2m18s
ci-cd / deploy (push) Skipped

This commit is contained in:
2026-10-05 20:20:05 +08:00
parent fbc1eda561
commit 3175936266
16 changed files with 196 additions and 119 deletions
+24
View File
@@ -6,6 +6,10 @@ function dateLabel() {
const now = new Date();
return `${now.getMonth() + 1}月${now.getDate()}日 周${"日一二三四五六"[now.getDay()]}`;
}
function accountKey() {
const state = getApp().globalData || {};
return (state.user && state.user.id) || state.token || "";
}
Page({
data: {
locationName: "当前位置",
@@ -23,13 +27,32 @@ Page({
phase: "auth",
error: "",
},
onLoad() {
const cached = getApp().homeSnapshot;
if (cached && cached.account === accountKey() && cached.date === localDate()) {
this.setData({ ...cached.data, ready: true, phase: "ready", loading: false });
}
},
onShow() {
this.applyEnvironment(environment.cached());
this.load();
},
onHide() {
this.rememberHome();
},
onUnload() {
this.rememberHome();
this.disposed = true;
},
rememberHome() {
if (!this.data.ready || !accountKey()) return;
const { pets, selected, tasks, undoneCount, walkCount, name } = this.data;
getApp().homeSnapshot = {
account: accountKey(),
date: localDate(),
data: { pets, selected, tasks, undoneCount, walkCount, name },
};
},
updateEnvironmentLabel() {
this.setData({
headerSubtitle:
@@ -112,6 +135,7 @@ Page({
ready: true,
phase: "ready",
});
this.rememberHome();
// Location permission and weather never hold up the first usable screen.
this.refreshEnvironment();
} catch (error) {
+1 -2
View File
@@ -3,7 +3,6 @@
"usingComponents": {
"tab-bar": "/components/tab-bar/index",
"pet-picker": "/components/pet-picker/index",
"startup-state": "/components/startup-state/index",
"home-skeleton": "/components/home-skeleton/index"
"startup-state": "/components/startup-state/index"
}
}
+3 -5
View File
@@ -1,8 +1,7 @@
<startup-state wx:if="{{phase==='auth' || phase==='auth-error'}}" error="{{error}}" bind:retry="load" />
<startup-state wx:if="{{!ready && (!error || phase==='auth-error')}}" error="{{error}}" bind:retry="load" />
<page-layout wx:else id="page-layout" title="{{locationName}}" subtitle="{{headerSubtitle}}" location="{{true}}" bind:locationtap="refreshEnvironment">
<view class="screen">
<home-skeleton wx:if="{{loading && !ready}}" />
<view wx:elif="{{!ready && error}}" class="card home-error">
<view wx:if="{{!ready && error}}" class="card home-error">
<app-icon kind="paw" size="54" />
<view class="error-title">暂时没能准备好首页</view>
<view class="muted">{{error}}</view>
@@ -10,7 +9,6 @@
</view>
<block wx:else>
<view wx:if="{{error}}" class="refresh-error"><text>更新失败,保留上次的日常记录</text><text class="link" bindtap="load">重试</text></view>
<view wx:elif="{{loading}}" class="refresh-hint">正在更新今天的小日常…</view>
<view class="hero">
<view class="hero-copy">
<text class="hero-small">今日的主角</text>
@@ -91,7 +89,7 @@
</view>
<view class="task-main">
<text class="task-name">{{item.title}}</text>
<text class="muted">{{item.time_of_day}} · {{item.completed?'已完成':taskBusyIds[0]===item.id?'正在记录…':'点击完成'}}</text>
<text class="muted">{{item.all_pets?'全部宠物 · ':''}}{{item.time_of_day}} · {{item.completed?'已完成':taskBusyIds[0]===item.id?'正在记录…':'点击完成'}}</text>
</view>
</view>
<view wx:if="{{!tasks.length}}" class="empty">
-6
View File
@@ -189,12 +189,6 @@
border-radius: 22rpx;
margin-bottom: 20rpx;
}
.refresh-hint {
text-align: center;
font-size: 22rpx;
color: #a48d7e;
margin-bottom: 20rpx;
}
.first-pet {
padding-top: 30rpx;
}