Commit 72f1dc61 by wangshufen

fixed:修改request.js token校验

parent a05cccab
...@@ -12,16 +12,16 @@ const menus = [ ...@@ -12,16 +12,16 @@ const menus = [
icon: 'search', icon: 'search',
key: '/Kinase', key: '/Kinase',
}, },
{ // {
title: 'PDB小分子搜索', // title: 'PDB小分子搜索',
icon: 'search', // icon: 'search',
key: '/MolecularSearch', // key: '/MolecularSearch',
}, // },
{ // {
title: '分子对接', // title: '分子对接',
icon: '', // icon: '',
key: '/dockingUploadDetails', // key: '/dockingUploadDetails',
}, // },
{ {
title: 'Drugbank', title: 'Drugbank',
icon: 'medicine-box', icon: 'medicine-box',
......
...@@ -684,7 +684,7 @@ export default class TargetDetails extends Component { ...@@ -684,7 +684,7 @@ export default class TargetDetails extends Component {
columns={columnsMutation} columns={columnsMutation}
/> />
</Panel> </Panel>
<Panel header="Drug & Clinical imformation" key="4"> <Panel header="Drug & Clinical information" key="4">
<Table <Table
bordered bordered
rowKey='item' rowKey='item'
......
import React, { Component } from 'react' import React, { Component } from 'react';
import { Pagination, message, Button, Tabs, Spin, Table, Tag, Typography } from 'antd' import { Pagination, message, Button, Tabs, Spin, Table, Tag, Typography } from 'antd';
import request from '../../../utils/request' import request from '../../../utils/request';
import './index.css' import './index.css';
import qs from 'qs' import qs from 'qs';
const { Title } = Typography const { Title } = Typography;
export default class IndicationDetails extends Component { export default class IndicationDetails extends Component {
state = { state = {
IndicationList: [], IndicationList: [],
smilesData: qs.parse(this.props.location.search.slice(1)), smilesData: qs.parse(this.props.location.search.slice(1)),
total_num: 0 total_num: 0,
};
componentDidMount() {
this.getDetails();
} }
componentDidMount () { getDetails() {
this.getDetails() this.setState({ loading: true });
} request
getDetails () { .post('/kinase/indication_search', this.state.smilesData)
this.setState({ loading: true }) .then((res) => {
request.post('/kinase/indication_search', this.state.smilesData) this.setState({ loading: false });
.then(res => {
this.setState({ loading: false })
if (res.data.code === 200) { if (res.data.code === 200) {
this.setState({ IndicationList: res.data.data }) this.setState({ IndicationList: res.data.data });
this.setState({ total_num: res.data.total_num }) this.setState({ total_num: res.data.total_num });
} else { } else {
message.error(res.data.msg) message.error(res.data.msg);
} }
}) })
.catch(err => { .catch((err) => {
console.error(err) console.error(err);
}) });
} }
onShowSizeChange = (current, pageSize) => { onShowSizeChange = (current, pageSize) => {
let smilesData = this.state.smilesData;
let smilesData = this.state.smilesData smilesData.page = current;
smilesData.page = current smilesData.page_size = pageSize;
smilesData.page_size = pageSize
this.setState({ this.setState({
smilesData smilesData,
}) });
this.getDetails() this.getDetails();
} };
onChange = (current, pageSize) => { onChange = (current, pageSize) => {
let smilesData = this.state.smilesData;
let smilesData = this.state.smilesData smilesData.page = current;
smilesData.page = current smilesData.page_size = pageSize;
smilesData.page_size = pageSize
this.setState({ this.setState({
smilesData smilesData,
}) });
this.getDetails() this.getDetails();
};
} getOne(e) {
getOne (e) { console.log(e);
console.log(e) const { dataid, datatype } = e;
const { dataid, datatype } = e
let data = { let data = {
dataid, dataid,
datatype datatype,
} };
this.props.history.push({ pathname: '/home/SearchDetails', search: qs.stringify(data) })
this.props.history.push({ pathname: '/kinase/SearchDetails', search: qs.stringify(data) });
} }
getOne2 (e) { getOne2(e) {
console.log(e) console.log(e);
const { dataid, datatype } = e const { dataid, datatype } = e;
let data = { let data = {
dataid, dataid,
datatype datatype,
} };
this.props.history.push({ pathname: '/home/TargetDetails', search: qs.stringify(data) })
this.props.history.push({ pathname: '/kinase/TargetDetails', search: qs.stringify(data) });
} }
getReferences = (e) => { getReferences = (e) => {
window.open(e) window.open(e);
} };
render () { render() {
const columns = [ const columns = [
{ {
title: 'indicationName', title: 'indicationName',
...@@ -111,13 +97,17 @@ export default class IndicationDetails extends Component { ...@@ -111,13 +97,17 @@ export default class IndicationDetails extends Component {
title: 'Drug', title: 'Drug',
dataIndex: 'Drug', dataIndex: 'Drug',
key: 'Drug', key: 'Drug',
render: Drug => ( render: (Drug) => (
<span> <span>
{ {
<Tag color="blue" onClick={() => { this.getOne(Drug) }} > <Tag
{(Drug.name)} color='blue'
onClick={() => {
this.getOne(Drug);
}}
>
{Drug.name}
</Tag> </Tag>
} }
</span> </span>
), ),
...@@ -150,42 +140,34 @@ export default class IndicationDetails extends Component { ...@@ -150,42 +140,34 @@ export default class IndicationDetails extends Component {
{ {
title: 'References', title: 'References',
dataIndex: 'References', dataIndex: 'References',
render: References => ( render: (References) => (
<span> <span>
{References.map(item => { {References.map((item) => {
return ( return (
<Tag color="blue" key={item} onClick={() => { this.getReferences(item) }} > <Tag
color='blue'
key={item}
onClick={() => {
this.getReferences(item);
}}
>
{item.toUpperCase()} {item.toUpperCase()}
</Tag> </Tag>
) );
})} })}
</span> </span>
), ),
}, },
] ];
const { IndicationList, total_num } = this.state const { IndicationList, total_num } = this.state;
return ( return (
<div className='IndicationDetails-div'> <div className='IndicationDetails-div'>
<Title>{IndicationList.name}</Title> <Title>{IndicationList.name}</Title>
<Table <Table bordered rowKey='item' dataSource={IndicationList} pagination={false} columns={columns} />
bordered
rowKey='item'
dataSource={IndicationList}
pagination={false}
columns={columns}
/>
<div className='bottom-div'> <div className='bottom-div'>
<Pagination <Pagination showSizeChanger onShowSizeChange={this.onShowSizeChange} onChange={this.onChange} total={total_num} />
showSizeChanger
onShowSizeChange={this.onShowSizeChange}
onChange={this.onChange}
total={total_num}
/>
</div> </div>
</div> </div>
) );
} }
} }
...@@ -1144,7 +1144,7 @@ export default class TargetDetails extends Component { ...@@ -1144,7 +1144,7 @@ export default class TargetDetails extends Component {
<Link href='#Sequence' title='Sequence' /> <Link href='#Sequence' title='Sequence' />
<Link href='#Structure' title='Structure' /> <Link href='#Structure' title='Structure' />
<Link href='#Mutation' title='Mutation' /> <Link href='#Mutation' title='Mutation' />
<Link href='#Drug' title='Drug & Clinical imformation' /> <Link href='#Drug' title='Drug & Clinical information' />
<Link href='#Bioassay' title='Bioassay' /> <Link href='#Bioassay' title='Bioassay' />
</Anchor> </Anchor>
</div> </div>
...@@ -1261,9 +1261,13 @@ export default class TargetDetails extends Component { ...@@ -1261,9 +1261,13 @@ export default class TargetDetails extends Component {
{/* {PanelList} */} {/* {PanelList} */}
<Collapse defaultActiveKey={['1', '2', '3', '4', '5', '6']} onChange={this.callback}> <Collapse defaultActiveKey={['1', '2', '3', '4', '5', '6']} onChange={this.callback}>
<Panel header='Sequence' key='1' id='Sequence'> <Panel header='Sequence' key='1' id='Sequence'>
<Button type='primary' onClick={this.alignmentEve}> <div>
alignment <Button type='primary' onClick={this.alignmentEve}>
</Button> alignment
</Button>
<div style={{ width: '90%', overflow: 'scroll' }}>{targetsDetail.SequenceStr}</div>
</div>
<div className='Sequence-div'> <div className='Sequence-div'>
{targetsDetail.Sequence && {targetsDetail.Sequence &&
targetsDetail.Sequence.map((item, index) => { targetsDetail.Sequence.map((item, index) => {
...@@ -1451,7 +1455,7 @@ export default class TargetDetails extends Component { ...@@ -1451,7 +1455,7 @@ export default class TargetDetails extends Component {
<Table bordered rowKey='item' dataSource={targetsDetail.MutationList} pagination={false} columns={columnsMutation} onChange={this.onChangeTable} /> <Table bordered rowKey='item' dataSource={targetsDetail.MutationList} pagination={false} columns={columnsMutation} onChange={this.onChangeTable} />
<Pagination showSizeChanger onShowSizeChange={this.onShowSizeChange} onChange={this.onChange} total={total_num} /> <Pagination showSizeChanger onShowSizeChange={this.onShowSizeChange} onChange={this.onChange} total={total_num} />
</Panel> </Panel>
<Panel header='Drug & Clinical imformation' key='4' id='Drug'> <Panel header='Drug & Clinical information' key='4' id='Drug'>
<Table bordered rowKey='item' dataSource={targetsDetail.DrugsInformation} pagination={false} expandedRowRender={expandedRowRender} columns={columnsDrug} /> <Table bordered rowKey='item' dataSource={targetsDetail.DrugsInformation} pagination={false} expandedRowRender={expandedRowRender} columns={columnsDrug} />
<Pagination showSizeChanger onShowSizeChange={this.onShowSizeChange3} onChange={this.onChange3} total={total_num3} /> <Pagination showSizeChanger onShowSizeChange={this.onShowSizeChange3} onChange={this.onChange3} total={total_num3} />
</Panel> </Panel>
......
...@@ -777,7 +777,7 @@ export default class TargetDetails extends Component { ...@@ -777,7 +777,7 @@ export default class TargetDetails extends Component {
})} })}
</Tabs> </Tabs>
</Panel> </Panel>
<Panel header="Drug&Clinical imformation" key="6"> <Panel header="Drug&Clinical information" key="6">
<Table <Table
bordered bordered
rowKey="item" rowKey="item"
......
...@@ -17,13 +17,54 @@ function disableF12() { ...@@ -17,13 +17,54 @@ function disableF12() {
} }
// disableF12(); // disableF12();
//对axios二次封装
const token = getQueryString('token');
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://69.235.144.91:3048/#/login', '_self');
}
})
.catch(function(err) {
console.log('err', err);
window.open('http://69.235.144.91:3048/#/login', '_self');
});
// request
// .get('http://69.235.144.91:8048/yszh-login/auth/checkToken')
// .then((res) => {
// console.log('--res', res);
// if (res.data.code === 200) {
// console.log('token 检验通过');
// return config;
// } else {
// console.log('token校验没通过 返回登录页');
// window.open('http://69.235.144.91:3048/#/login', '_self');
// }
// })
// .catch((err) => {
// console.log('token校验没通过 返回登录页');
// window.open('http://69.235.144.91:3048/#/login', '_self');
// console.log('err', err);
// });
}
checkFetchToken();
const baseURL = 'http://52.83.169.190:8002/'; //线上正式环境 const baseURL = 'http://52.83.169.190:8002/'; //线上正式环境
// const baseURL = 'http://69.235.144.91:8002/'; 测试环境 // const baseURL = 'http://69.235.144.91:8002/'; 测试环境
//对axios二次封装
// console.log('getQueryString', getQueryString('token'));
// console.log('localStorage', localStorage.getItem('token'));
const token = getQueryString('token') || localStorage.getItem('token');
const request = axios.create({ const request = axios.create({
baseURL, baseURL,
timeout: 15000, timeout: 15000,
...@@ -34,44 +75,16 @@ const request = axios.create({ ...@@ -34,44 +75,16 @@ const request = axios.create({
}, },
}); });
function checkToken(config) {
// alert(' 校验token111');
request
.get('http://69.235.144.91:8048/yszh-login/auth/checkToken')
.then((res) => {
console.log('--res', res);
if (res.data.code === 200) {
console.log('token 检验通过');
return config;
} else {
localStorage.removeItem('token');
// alert(' 失败');
console.log('token校验没通过 返回登录页');
// window.open('http://localhost:3000/#/login', '_self');
window.open('http://69.235.144.91:3048/#/login', '_self');
}
})
.catch((err) => {
localStorage.removeItem('token');
// alert(' 服务器报错');
console.log('token校验没通过 返回登录页');
window.open('http://69.235.144.91:3048/#/login', '_self');
console.log('err', err);
return false;
});
}
checkToken();
//拦截器 //拦截器
request.interceptors.request.use((config) => { request.interceptors.request.use((config) => {
// alert('拦截器..'); // alert('拦截器..');
console.log('token---', '拦截器方法校验token'); console.log('token---', '拦截器方法校验token');
console.log(config); console.log(config);
if (getQueryString('token') || localStorage.getItem('token')) { if (localStorage.getItem('token')) {
checkToken(config); config.headers['accessToken'] = localStorage.getItem('token');
return config;
} else { } else {
console.log('token为空....'); console.log('token为空....');
localStorage.removeItem('token');
window.open('http://69.235.144.91:3048/#/login', '_self'); window.open('http://69.235.144.91:3048/#/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