2 changed files with 104 additions and 101 deletions
-
122src/api/api.js
-
83src/api/request.js
@ -0,0 +1,83 @@ |
|||
//vxvdvdsvsdvvds3
|
|||
import router from "@/router" |
|||
import axios from "axios" |
|||
// import Promise from 'promise'
|
|||
import {yztoken} from "@/utlis/istoken" |
|||
import mm from "@/utlis/mm"; |
|||
|
|||
import { Message } from 'element-ui'; |
|||
const instance = axios.create({ |
|||
baseURL: mm.apiurl, |
|||
timeout:5000 |
|||
}); |
|||
|
|||
|
|||
//请求拦截
|
|||
instance.interceptors.request.use( |
|||
|
|||
function (config) { |
|||
yztoken() |
|||
let token = localStorage.getItem('token') |
|||
let tokentype = localStorage.getItem('tokentype') |
|||
config.headers['Access-Control-Allow-Origin'] = '*' |
|||
// config.headers.ContentType = 'application/x-www-form-urlencoded'
|
|||
config.headers.Authorization = `${tokentype} ${token}` |
|||
return config |
|||
}, |
|||
function (err) { |
|||
console.log('666') |
|||
return Promise.reject(err) |
|||
} |
|||
) |
|||
|
|||
//响应拦截
|
|||
instance.interceptors.response.use( |
|||
(res) => { |
|||
//console.log(res);
|
|||
if (res.data.code == 1) { |
|||
// const { data } = res;
|
|||
console.log(9527); |
|||
console.log(res); |
|||
return res.data |
|||
} else if (res.Code == -1) { |
|||
// console.log(res.data.message);
|
|||
// this.$message({
|
|||
// message: res.data.message,
|
|||
// type: 'warning'
|
|||
// });
|
|||
Message.error(res.Message); |
|||
} |
|||
}, |
|||
(err) => { |
|||
console.log(err); |
|||
if (response.data.code == -1) { |
|||
router.push({ path: '/login' }) |
|||
// this.$router.push({path:'/login'})
|
|||
// this.$message.success('状态失效')
|
|||
Message.error('状态失效请重新登录') |
|||
console.log('token失效返回登录'); |
|||
} |
|||
console.log(err); |
|||
return Promise.reject(err) |
|||
} |
|||
// function (response) {
|
|||
// console.log(response,10010)
|
|||
// const {data} = response
|
|||
// if (data.status == 401) {
|
|||
|
|||
// window.location.href = '#/login'
|
|||
// this.$message.error('状态失效');
|
|||
// }
|
|||
// return data
|
|||
// },
|
|||
// function (err) {
|
|||
// if (err.response.status === 401) {
|
|||
// window.location.href = '#/login'
|
|||
// this.$router.push({ path: '/login' })
|
|||
// this.$message.error('登录失效请重新登录');
|
|||
// }
|
|||
// return err
|
|||
// }
|
|||
) |
|||
|
|||
export default instance |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue