feat: support shared pet care tasks and smooth daily page return
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user