123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- const appUrl = "https://www.mang406.top/omp/api/wx/";
- // const appUrl = "http://localhost:8081/omp/api/wx/";
- let lock = false;
- App({
- onLaunch: function () { },
- // 自定义页面跳转
- Route: {
- path: {
- my: "/pages/my/my",
- set: "/pages/set/set",
- uploadData: "/pages/set/uploadData/uploadData",
- contacts: "/pages/set/contacts/contacts",
- volume: "/pages/set/volume/volume",
- idioms: "/pages/set/idioms/idioms",
- broadcast: "/pages/set/broadcast/broadcast",
- manager: "/pages/device/manager/manager",
- addition: "/pages/device/addition/addition",
- index: "/pages/index/index",
- location: "/pages/location/location",
- track: "/pages/track/track",
- },
- //跳转页面
- routeTo: function (path, params) {
- let url = "";
- if (params === undefined) url = path;
- else {
- const arr = Object.keys(params);
- url += "?"
- for (let i = 0; i < arr.length; i++) {
- url = url + arr[i] + "=" + params[arr[i]] + "&";
- }
- url = url.substring(0, url.length - 1);
- }
- wx.navigateTo({
- url: url,
- })
- }
- },
- Url: {
- //登录
- login: appUrl + "user/login.do",
- // 获取设备位置信息
- getLocation: appUrl + "location/getLocation.do",
- // 获取设备位置信息-历史轨迹
- getLocationHistory: appUrl + "location/getHistory.do",
- //添加用户设备绑定关系
- bind: appUrl + "device/bind.do",
- //删除绑定关系
- unbind: appUrl + "device/unbind.do",
- // 修改设备名称
- modifyDeviceName: appUrl + "device/updateName.do",
- //获取设备集合
- getListByUserId: appUrl + "device/getListByUserId.do",
- //修改默认设备
- changeDefaultDevice: appUrl + "device/changeDefault.do",
- // 获取用户常用语
- getUserIdioms: appUrl + "idioms/getList.do",
- // 添加用户常用语
- addUserIdioms: appUrl + "idioms/save.do",
- // 删除用户常用语
- deleteUserIdioms: appUrl + "idioms/delById.do",
- //获取音量设置
- getVolume: appUrl + "setInfo/volume.do",
- //获取联系人设置
- getSos: appUrl + "setInfo/sos.do",
- //获取其他设置
- getOther: appUrl + "setInfo/other.do",
- //设置功能-音量
- setVolume: appUrl + "set/volume.do",
- //设置功能-自动接听
- setAutoAnswer: appUrl + "set/autoAnswer.do",
- //设置功能-持续定位
- setContinue: appUrl + "set/continue.do",
- //设置功能-联系人
- setSos: appUrl + "set/sos.do",
- //设置功能-定位频率
- setGpsRate: appUrl + "set/gpsRate.do",
- //设置功能-语音播报
- setNews: appUrl + "set/news.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: {
- "user": that.globalData.openId
- },
- data: params,
- success: function (res) {
- console.log(url);
- console.log(res.data);
- console.log("-------------------------------------------------------")
- if (showLoading) wx.hideLoading();
- //请求成功回调函数
- switch (res.data.status) {
- case 200: //成功
- resolve(res.data);
- break;
- case 300: //警告
- that.Modal.tips(res.data.msg);
- break;
- case 500: //服务器异常
- that.Modal.tips("服务器开小差了");
- break;
- }
- },
- fail: function () { //失败
- console.log("网络异常:" + url);
- that.Modal.tips("网络异常")
- },
- })
- })
- },
- /**
- * 发送Post请求
- */
- Post: function (url, params) {
- const that = this;
- if (lock) {
- that.Modal.tips("您的请求太快了");
- return;
- } else {
- lock = true; //加锁
- }
- 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",
- },
- data: params,
- success: function (res) {
- console.log(url);
- console.log(res.data);
- console.log("-------------------------------------------------------")
- wx.hideLoading();
- //请求成功回调函数
- switch (res.data.status) {
- case 200: //成功
- resolve(res.data);
- break;
- case 300: //警告
- that.Modal.tips(res.data.msg);
- break;
- case 500: //服务器异常
- console.log(res)
- that.Modal.tips("服务器开小差了");
- break;
- }
- },
- fail: function () { //失败
- console.log("网络异常:" + url);
- that.Modal.tips("网络异常")
- },
- complete: function () {
- lock = false; //解锁
- }
- })
- })
- },
- /**
- * 弹出层
- */
- Modal: {
- tips: function (content) {
- wx.hideLoading();
- wx.showToast({
- icon: 'none',
- title: content,
- duration: 2500,
- })
- },
- },
- /**
- * 静态数据
- */
- globalData: {
- openId: null,
- deviceList: null,
- },
- /**
- * 获取设备集合
- */
- getDeviceList: function () {
- return this.globalData.deviceList == null ? [] : this.globalData.deviceList;
- },
- /**
- * 获取当前设备的信息
- */
- getCurrentDevice: function () {
- return (this.globalData.deviceList == null || this.globalData.deviceList == []) ? null : this.globalData.deviceList[0];
- },
- })
|