httputil.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // let BASE_Server = "http://127.0.0.1:8329"
  2. //let BASE_Server = "https://192.168.1.100:18080"
  3. let BASE_Server = "https://sookajs.top:18080"
  4. let app = getApp()
  5. // function send_post_login(url, data, successfun) {
  6. // wx.request({
  7. // url: BASE_Server_Login + url, //仅为示例,并非真实的接口地址
  8. // method: "POST",
  9. // header: {
  10. // 'content-type': 'application/json'
  11. // },
  12. // data: data,
  13. // success(res) {
  14. // successfun(res)
  15. // // var d = decodeURIComponent(decodeURIComponent(res.data.data))
  16. // // console.log("*****", d)
  17. // // var json = JSON.parse(d)
  18. // // successfun(json)
  19. // }
  20. // })
  21. // }
  22. //-----------------------------登录,获取token-----------------------------------
  23. function init_userInfo() {
  24. if (app.globalToken == null) {
  25. wx.getUserProfile({
  26. desc: 'desc',
  27. success: (res) => {
  28. getSysUserInfo(res.userInfo)
  29. },
  30. fail: res => {
  31. console.log(res)
  32. }
  33. })
  34. }
  35. }
  36. function getSysUserInfo(info) {
  37. console.log(2222)
  38. let that = this
  39. wx.login({
  40. success(res) {
  41. var code = res.code
  42. var data = {
  43. wxCode: code,
  44. wxNickName: info.nickName,
  45. wxAvatarUrl: info.avatarUrl
  46. }
  47. // http.send_post_login("/minapp/AppLoginController/appLogin",data)
  48. send_post("/auth/applogin", data, loginSuccess)
  49. },
  50. fail(res) {
  51. console.log("ffff", res)
  52. }
  53. })
  54. }
  55. function loginSuccess(res) {
  56. if (res.data.code != 200) {
  57. wx.showToast({
  58. title: res.data.msg != null ? res.data.msg : '',
  59. icon: "none"
  60. })
  61. } else {
  62. app.globalToken = res.data.data.access_token
  63. //登录成功,获取首页数据
  64. this.initIndexPage()
  65. }
  66. console.log("!!!!!", app.globalToken)
  67. }
  68. //------------------------------------------------------------------
  69. function send_post(url, data, successfun) {
  70. console.log("令牌:", app.globalToken)
  71. //如果令牌为空或过期,需要重新请求
  72. wx.request({
  73. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  74. method: "POST",
  75. header: {
  76. 'content-type': 'application/json',
  77. 'Authorization': 'Bearer ' + app.globalToken
  78. },
  79. data: data,
  80. success(res) {
  81. // var d = decodeURIComponent(decodeURIComponent(res.data.data))
  82. // var json = JSON.parse(d)
  83. successfun(res)
  84. }
  85. })
  86. }
  87. function post(url, data, successfun) {
  88. wx.request({
  89. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  90. method: "POST",
  91. header: {
  92. 'content-type': 'application/x-www-form-urlencoded',
  93. 'Authorization': 'Bearer ' + app.globalToken
  94. },
  95. data: data,
  96. success(res) {
  97. successfun(res.data)
  98. }
  99. })
  100. }
  101. function wxpost(url, data, successfun) {
  102. wx.request({
  103. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  104. method: "POST",
  105. header: {
  106. 'content-type': 'application/json',
  107. 'Authorization': 'Bearer ' + app.globalToken
  108. },
  109. data: data,
  110. success(res) {
  111. successfun(res.data)
  112. }
  113. })
  114. }
  115. function get(url, data, successfun) {
  116. wx.request({
  117. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  118. method: "Get",
  119. header: {
  120. 'content-type': 'application/x-www-form-urlencoded'
  121. },
  122. params: data,
  123. success(res) {
  124. successfun(res.data)
  125. }
  126. })
  127. }
  128. function send_postdecode(url, data, successfun) {
  129. wx.request({
  130. url: BASE_Server + url, //仅为示例,并非真实的接口地址
  131. method: "POST",
  132. header: {
  133. 'content-type': 'application/x-www-form-urlencoded'
  134. },
  135. data: data,
  136. success(res) {
  137. var json = JSON.parse(res.data)
  138. successfun(json)
  139. }
  140. })
  141. }
  142. function send_photo(data, successfun) {
  143. var that = this
  144. for (let i = 0; i < data.length; i++) {
  145. console.log("data长度=" + data.length)
  146. console.log(data)
  147. wx.uploadFile({
  148. url: BASE_Server + "/FileUpLoadController/upload.action", //仅为示例,非真实的接口地址
  149. filePath: data[i] + "",
  150. name: 'file',
  151. success: function (res) {
  152. var json = JSON.parse(res.data)
  153. var sss = JSON.parse(decodeURIComponent(decodeURIComponent(json.data)));
  154. wx.setStorageSync('filename' + (i + 1), sss.data.filename);
  155. successfun(sss)
  156. }
  157. })
  158. }
  159. }
  160. function send(data, successfun) {
  161. var that = this
  162. wx.uploadFile({
  163. url: BASE_Server + "/CarIDScanController/carIduploadGetNumber.action", //仅为示例,非真实的接口地址
  164. filePath: data[0] + "",
  165. name: 'file',
  166. success: function (res) {
  167. var json = JSON.parse(res.data)
  168. var sss = JSON.parse(decodeURIComponent(decodeURIComponent(json.data)));
  169. // wx.setStorageSync("carnumber", sss.data.carNumber)
  170. successfun(sss)
  171. },
  172. fail: function (res) {}
  173. })
  174. }
  175. module.exports = {
  176. BASE_Server: BASE_Server,
  177. send_post: send_post,
  178. send_photo: send_photo,
  179. send: send,
  180. post: post,
  181. wxpost: wxpost,
  182. get: get,
  183. send_postdecode: send_postdecode,
  184. // send_post_login,
  185. showLoading,
  186. hideLoading,
  187. }
  188. function showLoading() {
  189. wx.showLoading({
  190. title: '加载中...',
  191. mask: true,
  192. })
  193. }
  194. function hideLoading() {
  195. wx.hideLoading()
  196. }