feat: rebuild pet app and backend around core care flows

This commit is contained in:
2026-10-01 13:11:30 +08:00
parent 51ead8f411
commit bfcf8788a4
321 changed files with 4918 additions and 25199 deletions
+31 -25
View File
@@ -1,28 +1,34 @@
const store = require('./utils/store.js');
App({
globalData: {
statusBarHeight: 20,
navBarHeight: 44,
menuRight: 10
},
globalData: { token: "", user: null },
onLaunch() {
// 启动即登录并加载宠物(失败不阻塞 UI,页面会各自重试)
store.ready().catch((e) => console.warn('[app] 启动登录失败:', e && e.message));
// 计算自定义导航栏所需的状态栏 / 胶囊尺寸
try {
const win = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync();
const menu = wx.getMenuButtonBoundingClientRect();
const statusBarHeight = win.statusBarHeight || 20;
// 导航栏高度 = 胶囊高度 + 上下等距间隙
const navBarHeight = (menu.top - statusBarHeight) * 2 + menu.height;
this.globalData.statusBarHeight = statusBarHeight;
this.globalData.navBarHeight = navBarHeight;
this.globalData.menuRight = win.windowWidth - menu.right;
this.globalData.menuHeight = menu.height;
this.globalData.menuTop = menu.top;
} catch (e) {
// 兜底
}
}
this.globalData.token = wx.getStorageSync("pet_token") || "";
},
async login() {
if (this.globalData.token) return this.globalData.token;
if (!this.loginPromise)
this.loginPromise = (async () => {
const { isSimulator } = require("./utils/config");
const { request } = require("./utils/api");
let data;
try {
const { code } = await wx.login();
data = await request("/auth/login", "POST", { code }, false);
} catch (error) {
if (!isSimulator) throw error;
data = await request(
"/auth/dev",
"POST",
{ key: "wechat-devtools", nickname: "本地铲屎官" },
false,
);
}
this.globalData.token = data.token;
this.globalData.user = data.user;
wx.setStorageSync("pet_token", data.token);
return data.token;
})().finally(() => {
this.loginPromise = null;
});
return this.loginPromise;
},
});