app.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. const webSocket = require('./utils/websocket.js');
  2. App({
  3. //设置全局请求URL
  4. globalData: {
  5. url: 'https://xiaochengxuapi.jrjyjrjy.com/v1/'
  6. },
  7. judge_Land() {
  8. <<<<<<< HEAD
  9. // try {
  10. // const value = wx.getStorageSync('wx_id')
  11. // if (value) {
  12. // // Do something with return value
  13. // }
  14. // } catch (e) {
  15. // // Do something when catch error
  16. // }
  17. =======
  18. // console.log(wx.getStorageSync('wx_id')) //已经授权 id
  19. // console.log(wx.getStorageSync('access_token')) //是否注册过
  20. try {
  21. const value = wx.getStorageSync('wx_id')
  22. if (value) {
  23. // Do something with return value
  24. }
  25. } catch (e) {
  26. // Do something when catch error
  27. }
  28. >>>>>>> 465e4a521529b4053bd5916de8135b481ec44d51
  29. try {
  30. if (wx.getStorageSync('access_token')) { //是否注册过
  31. wx.reLaunch({
  32. url: '/pages/index/index' //注册过 进入首页
  33. })
  34. } else if (wx.getStorageSync('wx_id')) { //是否授权
  35. // console.log(2);
  36. wx.reLaunch({
  37. url: '/pages/Landpage/Land/Land' //授权过 进入登陆页
  38. })
  39. } else {
  40. wx.reLaunch({
  41. url: '/pages/Jurisdiction/click_Jurisdiction/click_Jurisdiction' //未授权 进入授权页
  42. })
  43. }
  44. // const value = wx.getStorageSync('access_token')
  45. // if (value) {
  46. // // console.log(1234)
  47. // console.log(value);
  48. // // Do something with return value
  49. // }else{
  50. // wx.reLaunch({
  51. // url: '/pages/Landpage/Land/Land' //授权过 进入登陆页
  52. // })
  53. // }
  54. } catch (e) {
  55. // Do something when catch error
  56. }
  57. },
  58. onLoad: function (options) {
  59. webSocket.connectSocket();
  60. },
  61. onLaunch: function (options) {
  62. wx.showShareMenu();
  63. var _this = this;
  64. // 查看是否授权
  65. },
  66. // 提示框
  67. Tips(text) {
  68. wx.showToast({
  69. title: text,
  70. icon: 'none', // 不显示图标
  71. duration: 2500
  72. })
  73. },
  74. // 加载
  75. showLoading: function () {
  76. wx.showToast({
  77. title: '加载中',
  78. icon: 'loading'
  79. });
  80. },
  81. // 关闭加载
  82. cancelLoading: function () {
  83. wx.hideToast();
  84. },
  85. /**
  86. * 封装wx.request请求
  87. * url: 请求地址
  88. * data: 要传递的参数
  89. * callback: 请求成功回调函数
  90. * errFun: 请求失败回调函数
  91. **/
  92. postRequest(p_url, p_data, callback, errFun) {
  93. p_data.key = wx.getStorageSync('access_key');
  94. p_data.token = wx.getStorageSync('access_token');
  95. wx.request({
  96. url: this.globalData.url + p_url,
  97. method: 'POST',
  98. data: p_data,
  99. header: { 'Content-Type': 'application/x-www-form-urlencoded' },
  100. dataType: 'json',
  101. success: function (res) {
  102. if(res.data.code == "401"){
  103. wx.clearStorageSync();
  104. wx.reLaunch({
  105. url: '/pages/Landpage/Land/Land'
  106. });
  107. }
  108. return typeof callback == "function" && callback(res.data)
  109. },
  110. fail: function (err) {
  111. return typeof errFun == "function" && errFun(err.data)
  112. }
  113. })
  114. },
  115. getRequest(g_url, g_data, callback, errFun) {
  116. g_data.key = wx.getStorageSync('access_key');
  117. g_data.token = wx.getStorageSync('access_token');
  118. wx.request({
  119. url: this.globalData.url + g_url,
  120. method: 'GET',
  121. data: g_data,
  122. header: { 'Content-Type': 'application/x-www-form-urlencoded' },
  123. dataType: 'json',
  124. success: function (res) {
  125. return typeof callback == "function" && callback(res.data)
  126. },
  127. fail: function (err) {
  128. return typeof errFun == "function" && errFun(err.data)
  129. }
  130. })
  131. },
  132. // 图片方法
  133. Multigraph(dt_url, dt_filePath, callback) {
  134. wx.uploadFile({
  135. url: this.globalData.url + dt_url,
  136. filePath: dt_filePath,
  137. name: 'img',
  138. formData: {
  139. key: wx.getStorageSync('access_key'),
  140. token: wx.getStorageSync('access_token'),
  141. },
  142. success: function (res) {
  143. var data = JSON.parse(res.data);
  144. return typeof callback == "function" && callback(data)
  145. wx.showModal({
  146. title: '提示',
  147. content: '上传失败,请从新上传',
  148. showCancel: false,
  149. })
  150. }, fail: function (d) {
  151. wx.showModal({
  152. title: '提示',
  153. content: '上传失败',
  154. showCancel: false,
  155. })
  156. }
  157. })
  158. },
  159. getDistrict(latitude, longitude) {
  160. let _page = this;
  161. let keys = '3VTBZ-JEH6Q-M7D5I-GNPVS-3QWBH-QUFY3';
  162. wx.request({
  163. url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${keys}`,
  164. header: {
  165. 'Content-Type': 'application/json'
  166. },
  167. success: function (res) {
  168. console.log(res);
  169. if (res.data.status == 0) {
  170. console.log(res.data.result.address_component);
  171. _page.postRequest('trajectory/location/position', res.data.result.address_component)
  172. // // 省
  173. // let province = res.data.result.address_component.province;
  174. // // 市
  175. // let city = res.data.result.address_component.city;
  176. // // 区
  177. // let district = res.data.result.address_component.district;
  178. // console.log(province);
  179. }
  180. }
  181. })
  182. },
  183. Imsocket: function () {
  184. return webSocket;
  185. },
  186. UserId: function () {
  187. return wx.getStorageSync('access_token');
  188. },
  189. UserToken: function () {
  190. return wx.getStorageSync('access_user');
  191. }
  192. })
  193. getApp().judge_Land(); //判断登陆