- 新增 addComment/getComments/getFollowList/followUser/getUser/updateProfile/updatePet/deletePet 云函数并完成部署 - 统一通过 app.globalData.navBarInfo 避让系统胶囊按钮(编辑资料/编辑宠物等页面保存按钮被遮挡问题) - 编辑资料页所在城市改为省份 picker 选择 - 修复"我的"页动态为空(getUserPosts 应传 openid 而非数据库 _id) - 重构编辑宠物页:品种改用 picker 滚轮(替代有数量上限的 actionSheet),标签改用 selectedTagSet 映射 + 自定义标签输入(5字以内、仅中英文/数字、最多8个) - 接通宠物保存/删除真实云函数调用并同步本地缓存 - 移除 feed 页对不存在的 getStories 云函数调用,修复模拟器卡死 - 移除 post 页对不存在的 wx.reverseGeocoder API 的调用 - 统一扩展 AppGlobalData 类型并修正所有 getApp 调用的泛型,解决 TS 报错
98 lines
2.5 KiB
TypeScript
98 lines
2.5 KiB
TypeScript
import { UserProfile, GeoPoint, AppGlobalData } from './types/index'
|
|
import { getCachedUser, login } from './utils/auth'
|
|
import { CLOUD_ENV, HEARTBEAT_INTERVAL_MS } from './utils/constants'
|
|
import { api } from './utils/api'
|
|
|
|
App<{ globalData: AppGlobalData }>({
|
|
globalData: {
|
|
userInfo: null,
|
|
isLoggedIn: false,
|
|
currentLocation: null,
|
|
_locationTimer: null,
|
|
navBarInfo: { statusBarHeight: 0, navbarHeight: 44, navbarPaddingRight: 0 },
|
|
},
|
|
|
|
onLaunch() {
|
|
wx.cloud.init({
|
|
env: CLOUD_ENV,
|
|
traceUser: true,
|
|
})
|
|
|
|
// 测量系统胶囊按钮位置,供所有页面共用
|
|
const sysInfo = wx.getSystemInfoSync()
|
|
const capsule = wx.getMenuButtonBoundingClientRect()
|
|
this.globalData.navBarInfo = {
|
|
statusBarHeight: sysInfo.statusBarHeight,
|
|
navbarHeight: (capsule.top - sysInfo.statusBarHeight) * 2 + capsule.height,
|
|
navbarPaddingRight: sysInfo.windowWidth - capsule.left,
|
|
}
|
|
|
|
const cached = getCachedUser()
|
|
if (cached) {
|
|
this.globalData.userInfo = cached
|
|
this.globalData.isLoggedIn = true
|
|
}
|
|
|
|
this._initLocation()
|
|
},
|
|
|
|
onShow() {
|
|
this._startLocationHeartbeat()
|
|
},
|
|
|
|
onHide() {
|
|
this._stopLocationHeartbeat()
|
|
},
|
|
|
|
async _initLogin() {
|
|
try {
|
|
const userInfo = await login()
|
|
this.globalData.userInfo = userInfo
|
|
this.globalData.isLoggedIn = true
|
|
} catch (e) {
|
|
console.error('Login failed', e)
|
|
}
|
|
},
|
|
|
|
_initLocation() {
|
|
wx.getLocation({
|
|
type: 'gcj02',
|
|
success: res => {
|
|
this.globalData.currentLocation = {
|
|
latitude: res.latitude,
|
|
longitude: res.longitude,
|
|
}
|
|
if (this.globalData.isLoggedIn) {
|
|
api.updateLocation(res.latitude, res.longitude).catch(() => {})
|
|
}
|
|
},
|
|
fail: () => {},
|
|
})
|
|
},
|
|
|
|
_startLocationHeartbeat() {
|
|
if (this.globalData._locationTimer) return
|
|
this.globalData._locationTimer = setInterval(() => {
|
|
if (!this.globalData.isLoggedIn) return
|
|
wx.getLocation({
|
|
type: 'gcj02',
|
|
success: res => {
|
|
this.globalData.currentLocation = {
|
|
latitude: res.latitude,
|
|
longitude: res.longitude,
|
|
}
|
|
api.updateLocation(res.latitude, res.longitude).catch(() => {})
|
|
},
|
|
fail: () => {},
|
|
})
|
|
}, HEARTBEAT_INTERVAL_MS)
|
|
},
|
|
|
|
_stopLocationHeartbeat() {
|
|
if (this.globalData._locationTimer) {
|
|
clearInterval(this.globalData._locationTimer)
|
|
this.globalData._locationTimer = null
|
|
}
|
|
},
|
|
})
|