Files
JoyD/Claw/client/wechat_app/app.js

80 lines
1.8 KiB
JavaScript
Raw Normal View History

2026-03-16 15:47:55 +08:00
// 应用入口文件
App({
onLaunch: function () {
console.log('智控未来小程序启动')
// 初始化系统信息
this.globalData.systemInfo = wx.getSystemInfoSync()
// 检查更新
this.checkForUpdate()
// 初始化网络监听
this.initNetworkListener()
},
onShow: function () {
console.log('小程序显示')
},
onHide: function () {
console.log('小程序隐藏')
},
onError: function (msg) {
console.error('小程序错误:', msg)
},
// 检查更新
checkForUpdate: function() {
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
console.log('检查更新结果:', 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
})
})
}
},
// 初始化网络监听
initNetworkListener: function() {
wx.onNetworkStatusChange(function(res) {
console.log('网络状态变化:', res)
if (!res.isConnected) {
wx.showToast({
title: '网络已断开',
icon: 'none'
})
}
})
},
// 全局数据
globalData: {
userInfo: null,
systemInfo: null,
apiBase: 'https://pactgo.cn/api/v1',
websocketUrl: 'wss://pactgo.cn/ws/task',
version: '1.0.0'
}
})