jhwxapp/miniprogram/app.js

154 lines
4.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

//app.js
//全局分享
!function(){
var PageTmp = Page;
Page =function (pageConfig) {
// 设置全局默认分享
pageConfig = Object.assign({
//右上角分享功能
onShareAppMessage () {
return {
title: '智慧工地优管',//分享标题
path: '/pages/login/login',//分享用户点开后页面
success (res) {
console.log('分享成功!')
}
}
}
},pageConfig);
PageTmp(pageConfig);
};
}();
App({
globalData: {
category:'',
standard:'',
paramDeptId:'',
userProjectId:'',
appId: "wx9997d071b4996f23",
// 智慧工地后台接口访问域名
//reqUrl:'https://szgcwx.jhncidg.com',
reqUrl:'http://127.0.0.1:8091',
//uploadUrl:"https://szgcwx.jhncidg.com/wechat",
uploadUrl:'http://192.168.43.53:8091/wechat',
//御景路数字化集成管控平台接口访问域名
szhUrl:'https://szh.makalu.cc',
// szhUrl:'http://127.0.0.1:9004',
// szhUrl:'http://192.168.31.49:9004',
//劳务实名制平台接口访问域名
smzUrl:'https://smz.makalu.cc',
//安全智管平台接口访问域名
aqzgUrl:'https://aqzg.makalu.cc',
//地图相关参数
scale:'',
initialLon:'',
initialLat:'',
markers:[],
//页面跳转参数
type:'',
value1:'省',
value2:'市/区',
value3:'公司',
projectInfoList:[],
projectId:'',
projectName:'',
companyName:'',
deptId:'',
},
onLaunch: function () {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init({
// env 参数说明:
// env 参数决定接下来小程序发起的云开发调用wx.cloud.xxx会默认请求到哪个云环境的资源
// 此处请填入环境 ID, 环境 ID 可打开云控制台查看
// 如不填则使用默认环境(第一个创建的环境)
// env: 'my-env-id',
traceUser: true,
})
}
this.autoUpdate();
},
onLoad(){
},
//页面弹窗
toast: function (msg) {
wx.showToast({
title: msg,
icon: 'none',
duration: 1000,
mask: true
});
},
//版本自动更新
autoUpdate:function(){
var self = this
// 获取小程序更新机制兼容
if (wx.canIUse('getUpdateManager')) {
const updateManager = wx.getUpdateManager()
//1. 检查小程序是否有新版本发布
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
if (res.hasUpdate) {
//2. 小程序有新版本,则静默下载新版本,做好更新准备
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
//3. 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
} else if (res.cancel) {
//如果需要强制更新,则给出二次弹窗,如果不需要,则这里的代码都可以删掉了
wx.showModal({
title: '温馨提示~',
content: '本次更新可能会导致旧版本无法正常访问,请使用新版本',
success: function (res) {
self.autoUpdate()
//第二次提示后,强制更新
// if (res.confirm) {
// // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
// updateManager.applyUpdate()
// } else if (res.cancel) {
// //重新回到版本更新提示
// self.autoUpdate()
// }
}
})
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
wx.showModal({
title: '已经有新版本了哟~',
content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~',
})
})
}
})
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
}
})