Commit 3d68bb63 by liang ce

router 判断

parent 22251945
......@@ -28,13 +28,18 @@ axios.interceptors.request.use((config) => {
})
// 配置请求返回的拦截器,
axios.interceptors.response.use(res => {
// if (res.data.code === 0 || res.data.resultCode === 0) {
// store.dispatch('setSpinning', false)
return Promise.resolve(res)
// } else if (res.data.code === 40003 || res.data.resultCode === 40003) {
// message.error('权限不足')
// if (res.data.resultCode === 0) {
// return Promise.resolve(res)
// } else {
// return Promise.reject()
// }
if (res.data.code === 0 || res.data.resultCode === 0) {
store.dispatch('setSpinning', false)
return Promise.resolve(res)
} else if (res.data.code === 40003 || res.data.resultCode === 40003) {
message.error('权限不足')
return Promise.reject('1')
}
}, err => {
return new Promise((resolve, reject) => {
console.log(err)
......@@ -75,22 +80,22 @@ axios.interceptors.response.use(res => {
const $http = {
post: (url, data) => {
return new Promise((resolve, reject) => {
// let postData
// if (data === undefined) {
// postData = {
// orgId: localStorage.getItem('orgId')
// }
// } else {
// postData = data
// postData.orgId = localStorage.getItem('orgId')
// }
let postData = data === undefined ? '' : data
axios.post(`${BASE_URL}${url}`, postData, {
headers: {
'Content-Type': 'application/json; charset=UTF-8'
}
}).then((res) => {
console.log(res.data, res.data.code, res.data.resultCode)
if (res.data.code === 0 || res.data.resultCode === 0) {
store.dispatch('setSpinning', false)
return Promise.resolve(res)
} else if (res.data.code === 40003 || res.data.resultCode === 40003) {
message.error('权限不足')
return Promise.reject()
}
}).catch((err) => {
console.log(err)
return resolve(res)
})
})
},
......@@ -98,15 +103,7 @@ const $http = {
return new Promise((resolve, reject) => {
let getData = data === undefined ? '' : qs.stringify(data)
axios.get(`${BASE_URL}${url}?${getData}`).then((res) => {
if (res.data.code === 0 || res.data.resultCode === 0) {
store.dispatch('setSpinning', false)
return Promise.resolve(res)
} else if (res.data.code === 40003 || res.data.resultCode === 40003) {
message.error('权限不足')
return Promise.reject()
}
}).catch((err) => {
console.log(err)
return resolve(res)
})
})
},
......@@ -114,15 +111,7 @@ const $http = {
return new Promise((resolve, reject) => {
let getData = data === undefined ? '' : qs.stringify(data)
axios.delete(`${BASE_URL}${url}?${getData}`).then((res) => {
if (res.data.code === 0 || res.data.resultCode === 0) {
store.dispatch('setSpinning', false)
return Promise.resolve(res)
} else if (res.data.code === 40003 || res.data.resultCode === 40003) {
message.error('权限不足')
return Promise.reject()
}
}).catch((err) => {
console.log(err)
return resolve(res)
})
})
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment