jhprjv2/ruoyi-ui-app/miniprogram/app.js

170 lines
5.0 KiB
JavaScript
Raw Normal View History

2024-09-08 15:55:07 +08:00
import {
getToken
} from '/utils/auth'
//全局分享
!function(){
var PageTmp = Page;
Page =function (pageConfig) {
// 设置全局默认分享
pageConfig = Object.assign({
//右上角分享功能
onShareAppMessage () {
return {
title: '智慧工地优管',//分享标题
path: '/pages/login/index',//分享用户点开后页面
success (res) {
console.log('分享成功!')
}
}
}
},pageConfig);
PageTmp(pageConfig);
};
}();
App({
globalData: {
category:'',
standard:'',
paramDeptId:'',
userProjectId:'',
2024-09-08 23:16:48 +08:00
appId: "wx46466c7828eede2b",
2024-09-08 15:55:07 +08:00
// 智慧工地后台接口访问域名
2024-09-08 23:16:48 +08:00
reqUrl:'https://xiangguan.sxyanzhu.com/jhapp',
2024-09-08 15:55:07 +08:00
//reqUrl:'http://127.0.0.1:8091',
2024-09-08 23:16:48 +08:00
uploadUrl:"https://xiangguan.sxyanzhu.com/jhapp/wechat",
2024-09-08 15:55:07 +08:00
//uploadUrl:'http://127.0.0.1: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();
if(!getToken()){
setTimeout(() => {
this.toast("请使用手机号码登录",1500);
}, 1000);
wx.redirectTo({
url: '/pages/login/index',
});
return false;
}
},
onLoad(){},
//页面弹窗
toast: function (msg) {
wx.showToast({
title: msg,
icon: 'none',
duration: 1000,
mask: true
});
},
initWxAuth:function(){
wx.redirectTo({
url: '../wx-auth/index',
})
},
//版本自动更新
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: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
}
})