You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.4 KiB
101 lines
3.4 KiB
//app.js
|
|
const tdsdk = require('./libs/tdweapp.js')
|
|
App({
|
|
//----------------------------------------------globalData--------------------------------------
|
|
evn: 1,//0:开发环境,1:测试环境,2:生产环境
|
|
tmplIds: ['SUjEgwDopCv9xkkSZ4KbS0L7XbAiVQor6GmPg14K760'],
|
|
agentMsgIds: ['kG8DErWDpyzBHCFaLlSKYMF7xVy8UpgogCwV_WSNt10', 'lOQ8Gvyy_dTk68bYGpRVnVA0M7DsYYrV81Gd39GUPBA'],
|
|
version: 152,
|
|
xAppId: '470236309865238528',
|
|
nowLocation: null,
|
|
nowCity: null,
|
|
globalData: {
|
|
userInfo: null,
|
|
openId: null,
|
|
token: null,
|
|
isIos: false,
|
|
kg: 0
|
|
},
|
|
onLaunch: function(options) {
|
|
tdsdk.App.onLaunch(options)//包含sdk初始化,必须调用
|
|
},
|
|
onShow: function(options) {
|
|
tdsdk.App.onShow(options)
|
|
if (wx.canIUse('getUpdateManager')) {
|
|
const updateManager = wx.getUpdateManager()
|
|
updateManager.onCheckForUpdate(function (res) {
|
|
// 请求完新版本信息的回调
|
|
if (res.hasUpdate) {
|
|
updateManager.onUpdateReady(function () {
|
|
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
updateManager.applyUpdate()
|
|
})
|
|
updateManager.onUpdateFailed(function () {
|
|
// 新版本下载失败
|
|
wx.showModal({
|
|
title: '已有新版本',
|
|
content: '请您删除小程序,重新搜索进入',
|
|
})
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
wx.showModal({
|
|
title: '溫馨提示',
|
|
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
|
|
})
|
|
}
|
|
if(this.globalData.Custom){
|
|
return
|
|
}
|
|
wx.getSystemInfo({
|
|
success: e => {
|
|
this.globalData.isIos = this.checkIos(e)
|
|
this.globalData.dev = e.platform == 'devtools'
|
|
|
|
let custom = wx.getMenuButtonBoundingClientRect()
|
|
this.globalData.Custom = custom
|
|
// 顶部操作栏高度
|
|
this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight + (this.globalData.isIos ? 4 : 0)
|
|
let windowHeight = e.windowHeight * (750 / e.windowWidth)
|
|
this.globalData.customHeight = this.globalData.CustomBar * (750 / e.windowWidth)
|
|
let safeBottom = e.windowHeight - e.safeArea.bottom
|
|
if(safeBottom > e.windowHeight){
|
|
safeBottom = 34
|
|
}
|
|
this.globalData.safeBottom = safeBottom * (750 / e.windowWidth)
|
|
// 状态栏高度
|
|
this.globalData.StatusBar = e.statusBarHeight * (750 / e.windowWidth)
|
|
let statusBarHeight = this.globalData.CustomBar * (750 / e.windowWidth)
|
|
this.globalData.statusBarHeight = statusBarHeight
|
|
// fragmentHeight:指的是整个页面statusBarHeight以下的高度
|
|
this.globalData.fragmentHeight = windowHeight - statusBarHeight
|
|
this.globalData.safeFragmentHeight = windowHeight - statusBarHeight - this.globalData.safeBottom
|
|
this.globalData.windowWidth = e.windowWidth
|
|
this.resumeIndex()
|
|
}
|
|
})
|
|
},
|
|
checkIos: function (e) {
|
|
if ('ios' === e.platform) {
|
|
return true
|
|
}
|
|
if (e.system.startsWith('iOS')) {
|
|
return true
|
|
}
|
|
return false
|
|
},
|
|
resumeIndex: function(){
|
|
wx.onAppRoute(function (res) {
|
|
let pages = getCurrentPages()
|
|
let page = pages[pages.length - 1]
|
|
if(page && page.route == 'pages/index/index' && !page.data.inited){
|
|
// page.setHeightData()
|
|
}
|
|
})
|
|
},
|
|
onHide: function(){
|
|
tdsdk.App.onHide()
|
|
}
|
|
|
|
})
|