12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- import axios from 'axios'
- import { MessageBox, Message } from 'element-ui'
- import store from '@/store'
- import { getToken } from '@/utils/auth'
- import qs from 'qs'
- import SYSTEM_EVN from '../../config/evn'
- const service = axios.create({
- baseURL: SYSTEM_EVN.BASE_URL
-
-
-
- })
- service.interceptors.request.use(
- config => {
- if (config.method === 'post' && config.url === '/auth/oauth/login?project=8030') {
- config.data = qs.stringify(config.data)
- config.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
- } else {
- config.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
- }
-
- if (store.getters.token) {
- config.headers['Authorization'] = 'bearer ' + getToken()
- }
- return config
- },
- error => {
-
- console.log(error)
- return Promise.reject(error)
- }
- )
- service.interceptors.response.use(
-
-
- response => {
- const res = response.data
-
- if (res.success) {
- return res
- } else {
- if (res.code !== 1) {
- Message({
- message: res.message || 'Error',
- type: 'error',
- duration: 5 * 1000
- })
-
- if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
-
- MessageBox.confirm('您已注销,您可以取消以停留在此页,或重新登录', '确认注销', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- store.dispatch('user/resetToken').then(() => {
- location.reload()
- })
- })
- }
- return Promise.reject(new Error(res.message || 'Error'))
- } else {
- return res
- }
- }
- },
- error => {
- console.log('err' + error)
- Message({
- message: error.message,
- type: 'error',
- duration: 3 * 1000
- })
- return Promise.reject(error)
- }
- )
- export default service
|