12345678910111213141516171819202122232425262728293031323334353637383940 |
- /**
- * 响应拦截
- * @param {Object} http
- */
- module.exports = vm => {
- uni.$u.http.interceptors.response.use(
- response => {
- const data = response.data
- // 刷新token
- const authorization = response.headers?.authorization
- if (authorization) {
- vm.$store.dispatch('user/token', authorization)
- }
- if (data.code !== 0) {
- uni.showModal({
- title: '提示',
- content: data.message,
- showCancel: false
- })
- // 401 登录超时 402 需要登录
- if (data.status_code === 401 || data.status_code === 402) {
- /* uni.reLaunch({
- url: 'pages/index/index'
- })*/
- }
- return Promise.reject(data.message)
- }
- return data
- }, (error) => {
- console.error('-->error', error)
- // uni.showModal({
- // title: '提示',
- // content: error.message,
- // showCancel: false
- // })
- return Promise.reject(error)
- })
- }
|