171 lines
4.8 KiB
JavaScript
171 lines
4.8 KiB
JavaScript
//app.js
|
||
var initial_url = 'https://app.gter.net/tenement';
|
||
var __ = require('./utils/miucms.js');
|
||
App({
|
||
randomString(n) {
|
||
let str = 'abcdefghijklmnopqrstuvwxyz9876543210';
|
||
let tmp = '',
|
||
i = 0,
|
||
l = str.length;
|
||
for (i = 0; i < n; i++) {
|
||
tmp += str.charAt(Math.floor(Math.random() * l));
|
||
}
|
||
return tmp;
|
||
},
|
||
|
||
autoUpdate: function () {
|
||
var self = this
|
||
// 获取小程序更新机制兼容
|
||
if (wx.canIUse('getUpdateManager')) {
|
||
const updateManager = wx.getUpdateManager()
|
||
updateManager.onCheckForUpdate(function (res) {
|
||
if (res.hasUpdate) {
|
||
wx.showModal({
|
||
title: '更新提示',
|
||
content: '检测到新版本,是否下载新版本并重启小程序?',
|
||
success: function (res) {
|
||
if (res.confirm) {
|
||
self.downLoadAndUpdate(updateManager)
|
||
} else if (res.cancel) {
|
||
wx.showModal({
|
||
title: '温馨提示',
|
||
content: '本次版本更新涉及到新的功能添加,旧版本无法正常访问',
|
||
showCancel: false,
|
||
confirmText: "确定更新",
|
||
success: function (res) {
|
||
if (res.confirm) {
|
||
//下载新版本,并重新应用
|
||
self.downLoadAndUpdate(updateManager)
|
||
}
|
||
}
|
||
})
|
||
}
|
||
}
|
||
})
|
||
}
|
||
})
|
||
} else {
|
||
wx.showModal({
|
||
title: '提示',
|
||
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。',
|
||
})
|
||
}
|
||
},
|
||
downLoadAndUpdate: function (updateManager) {
|
||
var self = this
|
||
wx.showLoading();
|
||
updateManager.onUpdateReady(function () {
|
||
wx.hideLoading()
|
||
updateManager.applyUpdate()
|
||
})
|
||
updateManager.onUpdateFailed(function () {
|
||
wx.hideLoading()
|
||
// 新的版本下载失败
|
||
wx.showModal({
|
||
title: '已经有新版本了哟~',
|
||
content: '新版本已经上线,请您删除当前小程序,重新搜索打开',
|
||
})
|
||
})
|
||
},
|
||
onLaunch: function (options) {
|
||
this.globalData.options = options;
|
||
|
||
__.initial(this)
|
||
console.log('__')
|
||
if (wx.getEnterOptionsSync().query && wx.getEnterOptionsSync().query.scancode_time) {
|
||
this.globalData.scancode_time = wx.getEnterOptionsSync().query.scancode_time
|
||
}
|
||
if (wx.getUserProfile) {
|
||
this.globalData.canIUseGetUserProfile = true;
|
||
}
|
||
|
||
|
||
try {
|
||
this.computeNavigateBarHeight();
|
||
} catch (e) {
|
||
// 获取系统信息失败
|
||
this.setData({
|
||
windowHeight: 812,
|
||
totalTopHeight: 68,
|
||
statusBarHeight: 20,
|
||
titleBarHeight: 48,
|
||
titleWidth: 87
|
||
});
|
||
}
|
||
this.autoUpdate()
|
||
},
|
||
onShow() {
|
||
|
||
|
||
},
|
||
computeNavigateBarHeight: function () {
|
||
console.log('computeNavigateBarHeightcomputeNavigateBarHeightcomputeNavigateBarHeight')
|
||
var systemInfo = wx.getSystemInfoSync();
|
||
var data = wx.getMenuButtonBoundingClientRect()
|
||
let totalTopHeight = data.bottom;
|
||
let windowHeight = systemInfo.windowHeight,
|
||
statusBarHeight = data.top;
|
||
this.globalData.screen_data = {
|
||
windowHeight: windowHeight,
|
||
totalTopHeight: totalTopHeight + 6,
|
||
statusBarHeight: statusBarHeight,
|
||
titleBarHeight: data.height,
|
||
titleWidth: data.widthinitial,
|
||
bottomLift: systemInfo.screenHeight - systemInfo.safeArea.bottom
|
||
}
|
||
},
|
||
onShow: function (options) {
|
||
// console.log('onShow', options)
|
||
this.globalData.source = options.path || '';
|
||
|
||
|
||
},
|
||
onHide: function () {
|
||
|
||
},
|
||
onError: function () {
|
||
// 这里回调错误信息
|
||
console.log('onError')
|
||
},
|
||
// get: function () {
|
||
// return this.globalData.config;
|
||
// },
|
||
return_data: function (res) {
|
||
var json = res.data;
|
||
var data = typeof res.data == 'string' ? JSON.parse(res.data) : res.data;
|
||
return data;
|
||
},
|
||
globalData: {
|
||
baseURL: "https://app.gter.net",
|
||
token: null,
|
||
title: null,
|
||
session: null,
|
||
code: null,
|
||
user: {},
|
||
userInfo: {},
|
||
options: {},
|
||
config: {},
|
||
notice: {},
|
||
source: '',
|
||
header: {
|
||
'content-type': 'application/json',
|
||
'Accept': 'application/json, text/plain',
|
||
'Cookie': 'miucms_session=' + wx.getStorageSync('Authorization'),
|
||
'Authorization': wx.getStorageSync('Authorization') || ''
|
||
},
|
||
new_reply: false,
|
||
// 寄托租房独有字段
|
||
choose: {},
|
||
kw: '',
|
||
status: 0,
|
||
screen_data: {},
|
||
StudentapartmentNew: null,
|
||
isUserAuthorization: 0, //用户点击授权:0:未知,1:未授权,2:已授权
|
||
listTab: {},
|
||
canIUseGetUserProfile: false,
|
||
scancode_time: "",
|
||
irentCouponBig: true,
|
||
unreadMessagesState: false,
|
||
firstWxParseImgLoaddState: false
|
||
}
|
||
}) |