Commit 3db5f72c by wangshufen

修改readme文件

parent e5b7554b
启动 yarn start
打包 yarn build
测试服务器路径: /data/enable/CommonService/
北京服务器路径: /home/WebSite/CommonService/
其他的没做修改
\ No newline at end of file
......@@ -28,42 +28,33 @@ const request = axios.create({
},
});
function checkFetchToken() {
fetch('http://69.235.144.91:8048/yszh-login/auth/checkToken', {
method: 'GET',
headers: {
accessToken: token,
},
})
.then((res) => res.json())
.then((res) => {
console.log('fetch--res', res);
if (res.code === 200) {
//校验通过,存储token
token && localStorage.setItem('token', token);
} else {
alert('token校验失败,返回登录页');
// window.open('http://localhost:3000/#/login', '_self');
window.open('http://ysplatform.atelligence-ai.com/#/login', '_self');
}
})
.catch(function (err) {
console.log('err', err);
window.open('http://ysplatform.atelligence-ai.com/#/login', '_self');
});
// 封装同步Ajax请求
function checkAjaxToken() {
const token = getQueryString('token') || localStorage.getItem('token');
let xhr = new XMLHttpRequest();
xhr.open('GET', 'http://69.235.144.91:8048/yszh-login/auth/checkToken', false);
xhr.setRequestHeader('accessToken', token);
xhr.send(null);
console.log(xhr); //准备状态
if (xhr.status == 200 && JSON.parse(xhr.responseText).code == 200) {
// 获取响应结果
// console.log(xhr.responseText);
token && localStorage.setItem('token', token);
return true;
} else {
console.log('状态码:' + xhr.status + ',原因:' + xhr.responseText);
return false;
}
}
checkFetchToken();
checkAjaxToken();
//拦截器
request.interceptors.request.use((config) => {
// alert('拦截器..');
console.log('token---', '拦截器方法校验token');
console.log(config);
if (localStorage.getItem('token')) {
config.headers['accessToken'] = localStorage.getItem('token');
console.log('config',config);
if (checkAjaxToken()) {
return config;
} else {
console.log('token为空....');
console.log('token校验失败...');
window.open('http://ysplatform.atelligence-ai.com/#/login', '_self');
}
});
......
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