const appUrl = "https://www.mang406.top/omp/api/wx/"; // const appUrl = "http://localhost:8081/omp/api/wx/"; let lock = false; App({ onLaunch: function () { }, Url: { // 登录 login: appUrl + "user/login.do", // 获取设备最新位置信息 getLatestLocation: appUrl + "device/getLatestDetail.do", // 获取用户设备集合 listBindDevices: appUrl + "device/listBindDevices.do", //修改默认设备 switchDefaultDevice: appUrl + "device/switchDefault.do", //添加用户设备绑定关系 bind: appUrl + "device/bind.do", //解绑 unbind: appUrl + "device/unbind.do", //修改绑定信息 updateBindInfo: appUrl + "device/updateBindInfo.do", //获取绑定信息 getBindInfo: appUrl + "device/getBindInfo.do", //获取音量设置 getVolume: appUrl + "setInfo/volume.do", //设置功能-音量 setVolume: appUrl + "set/volume.do", //获取联系人设置 getSos: appUrl + "setInfo/sos.do", //设置功能-联系人 setSos: appUrl + "set/sos.do", //设置功能-语音播报 setNews: appUrl + "set/news.do", //获取其他设置 getOther: appUrl + "setInfo/other.do", //设置功能-定位频率 setGpsRate: appUrl + "set/gpsRate.do", //设置功能-持续定位 setContinue: appUrl + "set/continue.do", }, /** * 发送Get请求 * showLoading 是否显示等待 */ Get: function (url, params, showLoading) { const that = this; if (showLoading) wx.showLoading(); return new Promise((resolve, reject) => { wx.request({ url: url, header: { "verify": "omp", "user": that.globalData.openId }, data: params, success: function (res) { that.success(url, resolve, res); wx.hideLoading(); }, fail: function () { wx.hideLoading(); console.log("网络异常:" + url); that.Modal.tips("网络异常") }, }) }) }, /** * 发送Post请求 */ Post: function (url, params) { const that = this; wx.showLoading(); return new Promise((resolve, reject) => { wx.request({ url: url, method: 'POST', header: { "user": that.globalData.openId, "Content-Type": "application/x-www-form-urlencoded", "verify": "omp" }, data: params, success: function (res) { that.success(url, resolve, res); wx.hideLoading(); }, fail: function () { wx.hideLoading(); console.log("网络异常:" + url); that.Modal.tips("网络异常") } }) }) }, /** * 请求成功回调函数 */ success: function (url, resolve, res) { console.log(url); console.log(res.data); console.log("-------------------------------------------------------"); //请求成功回调函数 switch (res.data.status) { case 200: //成功 resolve(res.data); break; case 300: //警告 this.Modal.tips(res.data.msg); break; case 500: //服务器异常 console.log(res) this.Modal.tips("服务器开小差了"); break; } }, /** * 弹出层 */ Modal: { tips: function (content) { wx.hideLoading(); wx.showToast({ icon: 'none', title: content, duration: 2500, }) }, }, /** * 静态数据 */ globalData: { openId: null, openNum: null, } })