C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.5 KiB

  1. let host = 'https://ciformall.youlane.cn/C'
  2. const postResquest = (url, token, message, postData, doSuccess, doFail) => {
  3. let body = { ...postData };
  4. if (message != "") {
  5. wx.showLoading({
  6. title: message,
  7. })
  8. }
  9. wx.request({
  10. //项目的真正接口,通过字符串拼接方式实现
  11. url: host + url,
  12. header: {
  13. "content-type": "application/json;charset=UTF-8",
  14. "token": token
  15. },
  16. data: body,
  17. method: 'POST',
  18. success: function (res) {
  19. //参数值为res.data,直接将返回的数据传入
  20. if (message != "") {
  21. wx.hideLoading()
  22. };
  23. doSuccess(res.data);
  24. },
  25. fail: function (res) {
  26. if (message != "") {
  27. wx.hideLoading()
  28. };
  29. wx.showToast({
  30. title: '网络错误',
  31. })
  32. },
  33. })
  34. }
  35. const getResquest = (url, token, message, getData, doSuccess, doFail) => {
  36. let body = { ...getData };
  37. if (message != "") {
  38. wx.showLoading({
  39. title: message,
  40. })
  41. }
  42. wx.request({
  43. url: host + url,
  44. header: {
  45. "content-type": "application/json;charset=UTF-8",
  46. "token": token
  47. },
  48. data: body,
  49. method: 'GET',
  50. success: function (res) {
  51. if (message != "") {
  52. wx.hideLoading()
  53. };
  54. doSuccess(res.data);
  55. },
  56. fail: function (res) {
  57. if (message != "") {
  58. wx.hideLoading()
  59. };
  60. wx.showToast({
  61. title: '网络错误',
  62. })
  63. },
  64. })
  65. }
  66. module.exports = {
  67. postResquest: postResquest,
  68. getResquest: getResquest
  69. }