建材商城系统20241014
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.

79 lines
1.5 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. import Vue from 'vue'
  2. import utils from '../utils/utils.js'
  3. import store from '../store/store.js'
  4. function http(uri, data, callback, method = 'GET', showLoading, title) {
  5. if(showLoading){
  6. uni.showLoading({
  7. title: title || '加载中...'
  8. });
  9. }
  10. let reject, resolve;
  11. let promise = new Promise((res, rej) => {
  12. reject = rej
  13. resolve = res
  14. })
  15. uni.request({
  16. url: Vue.prototype.$config.baseUrl + uri,
  17. data,
  18. method: method,
  19. header: {
  20. 'X-Access-Token': uni.getStorageSync('token'),
  21. 'Content-Type' : 'application/x-www-form-urlencoded'
  22. },
  23. success: (res) => {
  24. // console.log(res,'res')
  25. if(showLoading){
  26. uni.hideLoading();
  27. }
  28. if(res.statusCode == 401 ||
  29. res.data.message == '操作失败,token非法无效!' ||
  30. res.data.message == '操作失败,用户不存在!'){
  31. store.state.userInfo = {}
  32. store.state.riceInfo = {}
  33. uni.removeStorageSync('token')
  34. utils.toLogin()
  35. }
  36. if(res.statusCode == 200 && res.data.code != 200
  37. && res.data.code != 902){
  38. uni.showToast({
  39. mask: true,
  40. duration: 1000,
  41. title: res.data.message,
  42. icon:'none'
  43. });
  44. }
  45. callback && callback(res.data)
  46. resolve(res.data)
  47. },
  48. fail: () => {
  49. reject('api fail')
  50. uni.showLoading({})
  51. setTimeout(()=>{
  52. uni.hideLoading()
  53. uni.showToast({icon:"none", title:"网络异常"})
  54. }, 3000)
  55. if(showLoading){
  56. uni.hideLoading();
  57. }
  58. }
  59. });
  60. return promise
  61. }
  62. export default {
  63. http: http,
  64. }