Commit 3d68bb63 by liang ce

router 判断

parent 22251945
...@@ -28,13 +28,18 @@ axios.interceptors.request.use((config) => { ...@@ -28,13 +28,18 @@ axios.interceptors.request.use((config) => {
}) })
// 配置请求返回的拦截器, // 配置请求返回的拦截器,
axios.interceptors.response.use(res => { axios.interceptors.response.use(res => {
// if (res.data.code === 0 || res.data.resultCode === 0) { // if (res.data.resultCode === 0) {
// store.dispatch('setSpinning', false) // return Promise.resolve(res)
return Promise.resolve(res) // } else {
// } else if (res.data.code === 40003 || res.data.resultCode === 40003) {
// message.error('权限不足')
// return Promise.reject() // 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 => { }, err => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log(err) console.log(err)
...@@ -75,22 +80,22 @@ axios.interceptors.response.use(res => { ...@@ -75,22 +80,22 @@ axios.interceptors.response.use(res => {
const $http = { const $http = {
post: (url, data) => { post: (url, data) => {
return new Promise((resolve, reject) => { 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 let postData = data === undefined ? '' : data
axios.post(`${BASE_URL}${url}`, postData, { axios.post(`${BASE_URL}${url}`, postData, {
headers: { headers: {
'Content-Type': 'application/json; charset=UTF-8' 'Content-Type': 'application/json; charset=UTF-8'
} }
}).then((res) => { }).then((res) => {
console.log(res.data, res.data.code, res.data.resultCode) return resolve(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)
}) })
}) })
}, },
...@@ -98,15 +103,7 @@ const $http = { ...@@ -98,15 +103,7 @@ const $http = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let getData = data === undefined ? '' : qs.stringify(data) let getData = data === undefined ? '' : qs.stringify(data)
axios.get(`${BASE_URL}${url}?${getData}`).then((res) => { axios.get(`${BASE_URL}${url}?${getData}`).then((res) => {
if (res.data.code === 0 || res.data.resultCode === 0) { return resolve(res)
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)
}) })
}) })
}, },
...@@ -114,15 +111,7 @@ const $http = { ...@@ -114,15 +111,7 @@ const $http = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let getData = data === undefined ? '' : qs.stringify(data) let getData = data === undefined ? '' : qs.stringify(data)
axios.delete(`${BASE_URL}${url}?${getData}`).then((res) => { axios.delete(`${BASE_URL}${url}?${getData}`).then((res) => {
if (res.data.code === 0 || res.data.resultCode === 0) { return resolve(res)
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)
}) })
}) })
} }
......
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