app.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. const appUrl = "https://www.mang406.top/omp/api/wx/";
  2. // const appUrl = "http://localhost:8081/omp/api/wx/";
  3. let lock = false;
  4. App({
  5. onLaunch: function () { },
  6. // 自定义页面跳转
  7. Route: {
  8. path: {
  9. my: "/pages/my/my",
  10. set: "/pages/set/set",
  11. uploadData: "/pages/set/uploadData/uploadData",
  12. contacts: "/pages/set/contacts/contacts",
  13. volume: "/pages/set/volume/volume",
  14. idioms: "/pages/set/idioms/idioms",
  15. broadcast: "/pages/set/broadcast/broadcast",
  16. manager: "/pages/device/manager/manager",
  17. addition: "/pages/device/addition/addition",
  18. index: "/pages/index/index",
  19. location: "/pages/location/location",
  20. track: "/pages/track/track",
  21. },
  22. //跳转页面
  23. routeTo: function (path, params) {
  24. let url = "";
  25. if (params === undefined) url = path;
  26. else {
  27. const arr = Object.keys(params);
  28. url += "?"
  29. for (let i = 0; i < arr.length; i++) {
  30. url = url + arr[i] + "=" + params[arr[i]] + "&";
  31. }
  32. url = url.substring(0, url.length - 1);
  33. }
  34. wx.navigateTo({
  35. url: url,
  36. })
  37. }
  38. },
  39. Url: {
  40. //登录
  41. login: appUrl + "user/login.do",
  42. // 获取设备位置信息
  43. getLocation: appUrl + "location/getLocation.do",
  44. // 获取设备位置信息-历史轨迹
  45. getLocationHistory: appUrl + "location/getHistory.do",
  46. //添加用户设备绑定关系
  47. bind: appUrl + "device/bind.do",
  48. //删除绑定关系
  49. unbind: appUrl + "device/unbind.do",
  50. // 修改设备名称
  51. modifyDeviceName: appUrl + "device/updateName.do",
  52. //获取设备集合
  53. getListByUserId: appUrl + "device/getListByUserId.do",
  54. //修改默认设备
  55. changeDefaultDevice: appUrl + "device/changeDefault.do",
  56. // 获取用户常用语
  57. getUserIdioms: appUrl + "idioms/getList.do",
  58. // 添加用户常用语
  59. addUserIdioms: appUrl + "idioms/save.do",
  60. // 删除用户常用语
  61. deleteUserIdioms: appUrl + "idioms/delById.do",
  62. //获取音量设置
  63. getVolume: appUrl + "setInfo/volume.do",
  64. //获取联系人设置
  65. getSos: appUrl + "setInfo/sos.do",
  66. //获取其他设置
  67. getOther: appUrl + "setInfo/other.do",
  68. //设置功能-音量
  69. setVolume: appUrl + "set/volume.do",
  70. //设置功能-自动接听
  71. setAutoAnswer: appUrl + "set/autoAnswer.do",
  72. //设置功能-持续定位
  73. setContinue: appUrl + "set/continue.do",
  74. //设置功能-联系人
  75. setSos: appUrl + "set/sos.do",
  76. //设置功能-定位频率
  77. setGpsRate: appUrl + "set/gpsRate.do",
  78. //设置功能-语音播报
  79. setNews: appUrl + "set/news.do",
  80. },
  81. /**
  82. * 发送Get请求
  83. * showLoading 是否显示等待
  84. */
  85. Get: function (url, params, showLoading) {
  86. const that = this;
  87. if (showLoading) wx.showLoading();
  88. return new Promise((resolve, reject) => {
  89. wx.request({
  90. url: url,
  91. header: {
  92. "user": that.globalData.openId
  93. },
  94. data: params,
  95. success: function (res) {
  96. console.log(url);
  97. console.log(res.data);
  98. console.log("-------------------------------------------------------")
  99. if (showLoading) wx.hideLoading();
  100. //请求成功回调函数
  101. switch (res.data.status) {
  102. case 200: //成功
  103. resolve(res.data);
  104. break;
  105. case 300: //警告
  106. that.Modal.tips(res.data.msg);
  107. break;
  108. case 500: //服务器异常
  109. that.Modal.tips("服务器开小差了");
  110. break;
  111. }
  112. },
  113. fail: function () { //失败
  114. console.log("网络异常:" + url);
  115. that.Modal.tips("网络异常")
  116. },
  117. })
  118. })
  119. },
  120. /**
  121. * 发送Post请求
  122. */
  123. Post: function (url, params) {
  124. const that = this;
  125. if (lock) {
  126. that.Modal.tips("您的请求太快了");
  127. return;
  128. } else {
  129. lock = true; //加锁
  130. }
  131. wx.showLoading();
  132. return new Promise((resolve, reject) => {
  133. wx.request({
  134. url: url,
  135. method: 'POST',
  136. header: {
  137. "user": that.globalData.openId,
  138. "Content-Type": "application/x-www-form-urlencoded",
  139. },
  140. data: params,
  141. success: function (res) {
  142. console.log(url);
  143. console.log(res.data);
  144. console.log("-------------------------------------------------------")
  145. wx.hideLoading();
  146. //请求成功回调函数
  147. switch (res.data.status) {
  148. case 200: //成功
  149. resolve(res.data);
  150. break;
  151. case 300: //警告
  152. that.Modal.tips(res.data.msg);
  153. break;
  154. case 500: //服务器异常
  155. console.log(res)
  156. that.Modal.tips("服务器开小差了");
  157. break;
  158. }
  159. },
  160. fail: function () { //失败
  161. console.log("网络异常:" + url);
  162. that.Modal.tips("网络异常")
  163. },
  164. complete: function () {
  165. lock = false; //解锁
  166. }
  167. })
  168. })
  169. },
  170. /**
  171. * 弹出层
  172. */
  173. Modal: {
  174. tips: function (content) {
  175. wx.hideLoading();
  176. wx.showToast({
  177. icon: 'none',
  178. title: content,
  179. duration: 2500,
  180. })
  181. },
  182. },
  183. /**
  184. * 静态数据
  185. */
  186. globalData: {
  187. openId: null,
  188. deviceList: null,
  189. },
  190. /**
  191. * 获取设备集合
  192. */
  193. getDeviceList: function () {
  194. return this.globalData.deviceList == null ? [] : this.globalData.deviceList;
  195. },
  196. /**
  197. * 获取当前设备的信息
  198. */
  199. getCurrentDevice: function () {
  200. return (this.globalData.deviceList == null || this.globalData.deviceList == []) ? null : this.globalData.deviceList[0];
  201. },
  202. })