wxapp/app.js
2025-04-21 22:59:44 +08:00

57 lines
1.5 KiB
JavaScript

App({
globalData: {
userInfo: null,
items: []
},
onLaunch: function() {
// 获取本地存储的物品数据
try {
const items = wx.getStorageSync('items') || []
this.globalData.items = items
} catch (e) {
console.error('获取本地存储失败:', e)
}
// 调试信息
if (wx.getSystemInfoSync) {
const systemInfo = wx.getSystemInfoSync()
console.log('系统信息:', systemInfo)
}
// 检查更新
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function(res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function() {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function(res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function() {
wx.showModal({
title: '更新提示',
content: '新版本下载失败,请检查网络设置',
showCancel: false
})
})
}
})
}
},
onError: function(err) {
console.error('小程序发生错误:', err)
},
onUnhandledRejection: function(err) {
console.error('未处理的 Promise 错误:', err)
}
})