项目调整,培训计划变更
This commit is contained in:
parent
372890bc7a
commit
8f4387f5cc
@ -32,6 +32,7 @@
|
||||
"mockjs2": "1.0.8",
|
||||
"moment": "^2.24.0",
|
||||
"nprogress": "^0.2.0",
|
||||
"qs": "^6.10.3",
|
||||
"react-draft-wysiwyg": "^1.14.7",
|
||||
"store": "^2.0.12",
|
||||
"viser-vue": "^2.4.6",
|
||||
@ -76,4 +77,4 @@
|
||||
"webpack": "^4.44.2",
|
||||
"webpack-theme-color-replacer": "^1.3.12"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,90 +5,98 @@ import notification from 'ant-design-vue/es/notification'
|
||||
import { VueAxios } from './axios'
|
||||
import { ACCESS_TOKEN } from '@/store/mutation-types'
|
||||
import router from '../router'
|
||||
import qs from 'qs'
|
||||
|
||||
const SUCCESS_CODE = 200
|
||||
const INVALID_TOKEN_CODE = 401
|
||||
|
||||
const toast = (msg, description) => {
|
||||
notification.error({
|
||||
message: msg,
|
||||
description: description
|
||||
})
|
||||
notification.error({
|
||||
message: msg,
|
||||
description: description
|
||||
})
|
||||
}
|
||||
|
||||
// 创建 axios 实例
|
||||
const request = axios.create({
|
||||
// API 请求的默认前缀
|
||||
baseURL: process.env.VUE_APP_API_BASE_URL,
|
||||
timeout: 60000 // 请求超时时间
|
||||
// API 请求的默认前缀
|
||||
baseURL: process.env.VUE_APP_API_BASE_URL,
|
||||
timeout: 60000 // 请求超时时间
|
||||
})
|
||||
|
||||
// 异常拦截处理器
|
||||
const errorHandler = (error) => {
|
||||
if (error.response) {
|
||||
const data = error.response.data
|
||||
// 从 localstorage 获取 token
|
||||
const token = storage.get(ACCESS_TOKEN)
|
||||
if (error.response.status === 403) {
|
||||
toast('Forbidden:', data.msg)
|
||||
if (error.response) {
|
||||
const data = error.response.data
|
||||
// 从 localstorage 获取 token
|
||||
const token = storage.get(ACCESS_TOKEN)
|
||||
if (error.response.status === 403) {
|
||||
toast('Forbidden:', data.msg)
|
||||
}
|
||||
if (error.response.status === 401 && !(data.result && data.result.isLogin)) {
|
||||
toast('Unauthorized:', 'Authorization verification failed')
|
||||
if (token) {
|
||||
store.dispatch('Logout').then(() => {
|
||||
setTimeout(() => {
|
||||
window.location.reload()
|
||||
}, 1500)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
if (error.response.status === 401 && !(data.result && data.result.isLogin)) {
|
||||
toast('Unauthorized:', 'Authorization verification failed')
|
||||
if (token) {
|
||||
store.dispatch('Logout').then(() => {
|
||||
setTimeout(() => {
|
||||
window.location.reload()
|
||||
}, 1500)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
return Promise.reject(error)
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
// request interceptor
|
||||
request.interceptors.request.use(config => {
|
||||
const token = storage.get(ACCESS_TOKEN)
|
||||
// 由于登录接口待联调,token使用默认值
|
||||
// const token = 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjY0MjM0YmY0LTkxOWEtNDFkMS05MzZlLTMwZDU3NDhkYmVjZCJ9.J15_FhVqcm_GsNIS2BCEYf26sWQQ4pMSTedV5eKauZT8-f6480Mx1s5ZdqWdEOlORnkKSc5pUioCngbCopr9cQ'
|
||||
// 如果 token 存在,让每个请求携带自定义 token 请根据实际情况自行修改
|
||||
if (token) {
|
||||
config.headers[ACCESS_TOKEN] = token
|
||||
}
|
||||
if (config.method === 'post') {
|
||||
if (!config.data) {
|
||||
config.data = {}
|
||||
const token = storage.get(ACCESS_TOKEN)
|
||||
// 由于登录接口待联调,token使用默认值
|
||||
// const token = 'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjY0MjM0YmY0LTkxOWEtNDFkMS05MzZlLTMwZDU3NDhkYmVjZCJ9.J15_FhVqcm_GsNIS2BCEYf26sWQQ4pMSTedV5eKauZT8-f6480Mx1s5ZdqWdEOlORnkKSc5pUioCngbCopr9cQ'
|
||||
// 如果 token 存在,让每个请求携带自定义 token 请根据实际情况自行修改
|
||||
if (token) {
|
||||
config.headers[ACCESS_TOKEN] = token
|
||||
}
|
||||
}
|
||||
return config
|
||||
if (config.method === 'post') {
|
||||
if (!config.data) {
|
||||
config.data = {}
|
||||
}
|
||||
}
|
||||
// get方法传递数组的处理(重点代码)
|
||||
if (config.method === 'get') {
|
||||
config.paramsSerializer = function(params) {
|
||||
return qs.stringify(params, { arrayFormat: 'repeat' })
|
||||
}
|
||||
}
|
||||
|
||||
return config
|
||||
}, errorHandler)
|
||||
|
||||
// response interceptor
|
||||
request.interceptors.response.use((response) => {
|
||||
if (response.status === 200 && response.data.code === SUCCESS_CODE) {
|
||||
return Promise.resolve(response.data)
|
||||
} else if (response.data && response.data.code === INVALID_TOKEN_CODE) {
|
||||
toast(response.data.msg)
|
||||
store.dispatch('Logout').then(() => {
|
||||
router.push({ name: 'login' })
|
||||
})
|
||||
return Promise.reject(response)
|
||||
} else {
|
||||
if (response.data && response.data.msg) toast(response.data.msg)
|
||||
return Promise.reject(response)
|
||||
}
|
||||
if (response.status === 200 && response.data.code === SUCCESS_CODE) {
|
||||
return Promise.resolve(response.data)
|
||||
} else if (response.data && response.data.code === INVALID_TOKEN_CODE) {
|
||||
toast(response.data.msg)
|
||||
store.dispatch('Logout').then(() => {
|
||||
router.push({ name: 'login' })
|
||||
})
|
||||
return Promise.reject(response)
|
||||
} else {
|
||||