jhwxapp/miniprogram/app.js

153 lines
4.1 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: {
paramDeptId:'',
userProjectId:'',
appId: "wxc44b5d588f599758",
// 智慧工地后台接口访问域名
// reqUrl:"http://wxw.ngrok.makalu.cc",
//reqUrl:'https://jaapplets.makalu.cc',
//reqUrl:'https://sxyanzhu.com/jhwxapp',
//reqUrl:'https://cf.makalu.cc',
reqUrl:'http://127.0.0.1:8091',
//御景路数字化集成管控平台接口访问域名
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.update();
},
onLoad(){
},
/**
* 获取用户openid
*/
getOPenId:function () {
wx.login({
success :res=>{
console.log(res)
wx.request({
url: this.globalData.reqUrl+'/weixin/userLogin/getOpenId',
data:{
"code": res.code,
"appId":"wxc44b5d588f599758",
},
success:(res)=>{
wx.setStorageSync('openId', res.data.openid)
}
})
}
})
},
//页面弹窗
toast: function (msg) {
wx.showToast({
title: msg,
icon: 'none',
duration: 2000,
mask: true
});
},
//版本更新
update(){
//使用更新对象之前判断是否可用
if (wx.canIUse('getUpdateManager')){
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate)//res.hasUpdate返回boolean类型
if (res.hasUpdate) {
updateManager.onUpdateReady(function () {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启当前应用?',
success(res) {
if (res.confirm) {
// 新的版本已经下载好调用applyUpdate应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
// 新版本下载失败时执行
updateManager.onUpdateFailed(function () {
wx.showModal({
title: '发现新版本',
content: '请删除当前小程序,重新搜索打开...',
})
})
}
})
}else{
//如果小程序需要在最新的微信版本体验,如下提示
wx.showModal({
title: '更新提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
}
})