app.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. Url: {
  7. // 登录
  8. login: appUrl + "user/login.do",
  9. // 获取设备最新位置信息
  10. getLatestLocation: appUrl + "device/getLatestDetail.do",
  11. // 获取用户设备集合
  12. listBindDevices: appUrl + "device/listBindDevices.do",
  13. //修改默认设备
  14. switchDefaultDevice: appUrl + "device/switchDefault.do",
  15. //添加用户设备绑定关系
  16. bind: appUrl + "device/bind.do",
  17. //解绑
  18. unbind: appUrl + "device/unbind.do",
  19. //修改绑定信息
  20. updateBindInfo: appUrl + "device/updateBindInfo.do",
  21. //获取绑定信息
  22. getBindInfo: appUrl + "device/getBindInfo.do",
  23. //获取音量设置
  24. getVolume: appUrl + "setInfo/volume.do",
  25. //设置功能-音量
  26. setVolume: appUrl + "set/volume.do",
  27. //获取联系人设置
  28. getSos: appUrl + "setInfo/sos.do",
  29. //设置功能-联系人
  30. setSos: appUrl + "set/sos.do",
  31. //设置功能-语音播报
  32. setNews: appUrl + "set/news.do",
  33. //获取其他设置
  34. getOther: appUrl + "setInfo/other.do",
  35. //设置功能-定位频率
  36. setGpsRate: appUrl + "set/gpsRate.do",
  37. //设置功能-持续定位
  38. setContinue: appUrl + "set/continue.do",
  39. },
  40. /**
  41. * 发送Get请求
  42. * showLoading 是否显示等待
  43. */
  44. Get: function (url, params, showLoading) {
  45. const that = this;
  46. if (showLoading) wx.showLoading();
  47. return new Promise((resolve, reject) => {
  48. wx.request({
  49. url: url,
  50. header: {
  51. "verify": "omp",
  52. "user": that.globalData.openId
  53. },
  54. data: params,
  55. success: function (res) {
  56. that.success(url, resolve, res);
  57. wx.hideLoading();
  58. },
  59. fail: function () {
  60. wx.hideLoading();
  61. console.log("网络异常:" + url);
  62. that.Modal.tips("网络异常")
  63. },
  64. })
  65. })
  66. },
  67. /**
  68. * 发送Post请求
  69. */
  70. Post: function (url, params) {
  71. const that = this;
  72. wx.showLoading();
  73. return new Promise((resolve, reject) => {
  74. wx.request({
  75. url: url,
  76. method: 'POST',
  77. header: {
  78. "user": that.globalData.openId,
  79. "Content-Type": "application/x-www-form-urlencoded",
  80. "verify": "omp"
  81. },
  82. data: params,
  83. success: function (res) {
  84. that.success(url, resolve, res);
  85. wx.hideLoading();
  86. },
  87. fail: function () {
  88. wx.hideLoading();
  89. console.log("网络异常:" + url);
  90. that.Modal.tips("网络异常")
  91. }
  92. })
  93. })
  94. },
  95. /**
  96. * 请求成功回调函数
  97. */
  98. success: function (url, resolve, res) {
  99. console.log(url);
  100. console.log(res.data);
  101. console.log("-------------------------------------------------------");
  102. //请求成功回调函数
  103. switch (res.data.status) {
  104. case 200: //成功
  105. resolve(res.data);
  106. break;
  107. case 300: //警告
  108. this.Modal.tips(res.data.msg);
  109. break;
  110. case 500: //服务器异常
  111. console.log(res)
  112. this.Modal.tips("服务器开小差了");
  113. break;
  114. }
  115. },
  116. /**
  117. * 弹出层
  118. */
  119. Modal: {
  120. tips: function (content) {
  121. wx.hideLoading();
  122. wx.showToast({
  123. icon: 'none',
  124. title: content,
  125. duration: 2500,
  126. })
  127. },
  128. },
  129. /**
  130. * 静态数据
  131. */
  132. globalData: {
  133. openId: null,
  134. openNum: null,
  135. }
  136. })