租房小程序前端代码
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.

37 lines
1.1 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
6 months ago
10 months ago
  1. /**
  2. * 响应拦截
  3. * @param {Object} http
  4. */
  5. export const responseInterceptors = (vm) => {
  6. uni.$uv.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
  7. const data = response.data
  8. if (data.code == 200 || data.code == 905) {
  9. return Promise.resolve(data);
  10. }else if(data.code === 500 && (data.message == '操作失败,token非法无效!' || data.message == '操作失败,用户不存在!')){
  11. uni.removeStorageSync('token')
  12. uni.removeStorageSync('userInfo')
  13. uni.removeStorageSync('sessionKey')
  14. uni.navigateTo({
  15. url:"/pages/auth/index"
  16. })
  17. return;
  18. }else{
  19. uni.$uv.toast(data.message)
  20. return Promise.reject(data)
  21. }
  22. }, (response) => {
  23. const data = response.data
  24. console.info('responseresponse',data)
  25. if(data.code === 401){
  26. uni.removeStorageSync('token')
  27. uni.removeStorageSync('userInfo')
  28. uni.removeStorageSync('sessionKey')
  29. uni.navigateTo({
  30. url:"/pages/auth/index"
  31. })
  32. return;
  33. }
  34. return Promise.reject(response)
  35. })
  36. }