环卫车小程序前端代码
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.

57 lines
1.4 KiB

5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. /**
  2. * 响应拦截
  3. * @param {Object} http
  4. */
  5. module.exports = (vm) => {
  6. // 响应拦截
  7. uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
  8. const data = response.data
  9. console.info('interceptorsresponse',data)
  10. if (data.code == 200) {
  11. return Promise.resolve(data);
  12. }else if(data.code === 401){
  13. uni.showToast({
  14. icon:"none",
  15. title:data.message
  16. })
  17. uni.removeStorageSync('token')
  18. uni.removeStorageSync('userInfo')
  19. uni.removeStorageSync('sessionKey')
  20. uni.navigateTo({
  21. url:"/pages/auth/index"
  22. })
  23. return;
  24. }else if(data.code === 500 && (data.message == '操作失败,token非法无效!' || data.message == '操作失败,用户不存在!')){
  25. uni.$u.toast(data.message)
  26. uni.showToast({
  27. icon:"none",
  28. title:data.message
  29. })
  30. uni.removeStorageSync('token')
  31. uni.removeStorageSync('userInfo')
  32. uni.removeStorageSync('sessionKey')
  33. uni.navigateTo({
  34. url:"/pages/auth/index"
  35. })
  36. return;
  37. }else{
  38. uni.showToast({
  39. icon:"none",
  40. title:data.message
  41. })
  42. return Promise.reject(data)
  43. }
  44. }, (response) => {
  45. const data = response.data
  46. console.info('responseresponse',data)
  47. if(data.code === 401){
  48. uni.removeStorageSync('token')
  49. uni.removeStorageSync('userInfo')
  50. uni.removeStorageSync('sessionKey')
  51. uni.navigateTo({
  52. url:"/pages/auth/index"
  53. })
  54. return;
  55. }
  56. return Promise.reject(response)
  57. })
  58. }