Files
sundynix-pets/pets-fe/pages/share/share.js
T
Blizzard c72cf24f56
ci-cd / verify (push) Successful in 5s
ci-cd / deploy (push) Skipped
Complete core mini program flows
2026-10-04 09:26:58 +08:00

48 lines
1.1 KiB
JavaScript

const { request } = require("../../utils/api");
Page({
data: {
latitude: 31.23,
longitude: 121.47,
markers: [],
status: "加载中",
updated: "",
},
onLoad(options) {
this.token = options.token;
if (!this.token) this.setData({ status: "分享链接无效" });
},
onShow() {
if (!this.token) return;
this.load();
clearInterval(this.timer);
this.timer = setInterval(() => this.load(), 15000);
},
onHide() {
clearInterval(this.timer);
},
onUnload() {
clearInterval(this.timer);
},
async load() {
try {
const p = await request("/share/walk/" + this.token, "GET", null, false);
this.setData({
latitude: p.latitude,
longitude: p.longitude,
markers: [
{
id: 1,
latitude: p.latitude,
longitude: p.longitude,
title: "目前在这里",
},
],
status: p.status === "paused" ? "暂时停下休息" : "正在遛狗",
updated: new Date(p.recorded_at).toLocaleTimeString(),
});
} catch (e) {
this.setData({ status: "分享已结束或尚无位置" });
}
},
});