mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-09-08 03:01:56 +08:00
mock error
This commit is contained in:
parent
6b9588eaa3
commit
76ec176fe4
@ -1,4 +1,4 @@
|
|||||||
build/*.js
|
build/*.js
|
||||||
config/*.js
|
|
||||||
src/assets
|
src/assets
|
||||||
public
|
public
|
||||||
|
dist
|
||||||
|
24
mock/user.js
24
mock/user.js
@ -30,9 +30,19 @@ export default [
|
|||||||
type: 'post',
|
type: 'post',
|
||||||
response: config => {
|
response: config => {
|
||||||
const { username } = config.body
|
const { username } = config.body
|
||||||
|
const token = tokens[username]
|
||||||
|
|
||||||
|
// mock error
|
||||||
|
if (!token) {
|
||||||
|
return {
|
||||||
|
code: 60204,
|
||||||
|
message: 'Account and password are incorrect.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 20000,
|
code: 20000,
|
||||||
data: tokens[username]
|
data: token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -43,9 +53,19 @@ export default [
|
|||||||
type: 'get',
|
type: 'get',
|
||||||
response: config => {
|
response: config => {
|
||||||
const { token } = config.query
|
const { token } = config.query
|
||||||
|
const info = users[token]
|
||||||
|
|
||||||
|
// mock error
|
||||||
|
if (!info) {
|
||||||
|
return {
|
||||||
|
code: 50008,
|
||||||
|
message: 'Login failed, unable to get user details.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
code: 20000,
|
code: 20000,
|
||||||
data: users[token]
|
data: info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { Message } from 'element-ui'
|
import { MessageBox, Message } from 'element-ui'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
import { getToken } from '@/utils/auth'
|
import { getToken } from '@/utils/auth'
|
||||||
|
|
||||||
@ -33,40 +33,39 @@ service.interceptors.response.use(
|
|||||||
* If you want to get information such as headers or status
|
* If you want to get information such as headers or status
|
||||||
* Please return response => response
|
* Please return response => response
|
||||||
*/
|
*/
|
||||||
response => response.data,
|
|
||||||
/**
|
/**
|
||||||
* 下面的注释为通过在response里,自定义code来标示请求状态
|
* 下面的注释为通过在response里,自定义code来标示请求状态
|
||||||
* 当code返回如下情况则说明权限有问题,登出并返回到登录页
|
* 当code返回如下情况则说明权限有问题,登出并返回到登录页
|
||||||
* 如想通过 xmlhttprequest 来状态码标识 逻辑可写在下面error中
|
* 如想通过 XMLHttpRequest 来状态码标识 逻辑可写在下面error中
|
||||||
* 以下代码均为样例,请结合自生需求加以修改,若不需要,则可删除
|
* 以下代码均为样例,请结合自生需求加以修改,若不需要,则可删除
|
||||||
*/
|
*/
|
||||||
// response => {
|
response => {
|
||||||
// const res = response.data
|
const res = response.data
|
||||||
// if (res.code !== 20000) {
|
if (res.code !== 20000) {
|
||||||
// Message({
|
Message({
|
||||||
// message: res.message,
|
message: res.message,
|
||||||
// type: 'error',
|
type: 'error',
|
||||||
// duration: 5 * 1000
|
duration: 5 * 1000
|
||||||
// })
|
})
|
||||||
// // 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了;
|
// 50008:非法的token; 50012:其他客户端登录了; 50014:Token 过期了;
|
||||||
// if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
|
if (res.code === 50008 || res.code === 50012 || res.code === 50014) {
|
||||||
// // 请自行在引入 MessageBox
|
// 请自行在引入 MessageBox
|
||||||
// // import { Message, MessageBox } from 'element-ui'
|
// import { Message, MessageBox } from 'element-ui'
|
||||||
// MessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
|
MessageBox.confirm('你已被登出,可以取消继续留在该页面,或者重新登录', '确定登出', {
|
||||||
// confirmButtonText: '重新登录',
|
confirmButtonText: '重新登录',
|
||||||
// cancelButtonText: '取消',
|
cancelButtonText: '取消',
|
||||||
// type: 'warning'
|
type: 'warning'
|
||||||
// }).then(() => {
|
}).then(() => {
|
||||||
// store.dispatch('user/resetToken').then(() => {
|
store.dispatch('user/resetToken').then(() => {
|
||||||
// location.reload() // 为了重新实例化vue-router对象 避免bug
|
location.reload() // 为了重新实例化vue-router对象 避免bug
|
||||||
// })
|
})
|
||||||
// })
|
})
|
||||||
// }
|
}
|
||||||
// return Promise.reject('error')
|
return Promise.reject('error')
|
||||||
// } else {
|
} else {
|
||||||
// return response.data
|
return res
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log('err' + error) // for debug
|
console.log('err' + error) // for debug
|
||||||
Message({
|
Message({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user