Claw 项目完整结构提交
This commit is contained in:
80
Claw/client/wechat_app/app.js
Normal file
80
Claw/client/wechat_app/app.js
Normal file
@@ -0,0 +1,80 @@
|
||||
// 应用入口文件
|
||||
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'
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user