- 删除未使用的空组件目录、死代码导出(clearAuth/calcDistance/COLORS/ AVATAR_GRADIENTS/Message/TabBarItem/deletePost/uploadImage/getFileURL/ _initLogin),确保程序仍可正常运行 - 新增 8 个云函数并补全对应页面逻辑:getMessages/sendMessage(私信聊天)、 getHotTopics/searchPosts/searchUsers(搜索)、getStory(故事,复用 posts 集合)、getNotifications/markAllRead(基于点赞评论聚合的通知系统) - 在 cloudbaserc.json 中注册全部新云函数,并通过 --deployMode zip 完成部署 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
88 lines
2.2 KiB
TypeScript
88 lines
2.2 KiB
TypeScript
import { AppGlobalData } from './types/index'
|
|
import { getCachedUser } 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()
|
|
},
|
|
|
|
_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
|
|
}
|
|
},
|
|
})
|