app.js 3.4 KB

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