♻️ refactor: 重写token截取方法
This commit is contained in:
parent
6aa6886ba7
commit
ca07160d51
|
@ -18,14 +18,9 @@ export default class App extends Component {
|
|||
}
|
||||
|
||||
componentWillMount() {
|
||||
const tokenString = this.props.location.search;
|
||||
const token = tokenString.substring(
|
||||
tokenString.indexOf('=') + 1,
|
||||
tokenString.indexOf('&')
|
||||
);
|
||||
const head = tokenString.substring(tokenString.indexOf('&') + 6);
|
||||
const { token, head } = this.getQuery(this.props.location.search);
|
||||
/* 判断是否有token */
|
||||
if (tokenString && tokenString.indexOf('=') > -1) {
|
||||
if (token) {
|
||||
sessionStorage.setItem('authorization', token);
|
||||
this.onSubmit(token, head);
|
||||
return;
|
||||
|
@ -34,6 +29,15 @@ export default class App extends Component {
|
|||
this.toUnifiedLogin();
|
||||
}
|
||||
|
||||
/* 解析url参数 */
|
||||
getQuery = (url) =>
|
||||
(url.match(/([^?=&]+)(=([^&]*))/g) || []).reduce(
|
||||
(a, v) => (
|
||||
(a[v.slice(0, v.indexOf('='))] = v.slice(v.indexOf('=') + 1)), a
|
||||
),
|
||||
{}
|
||||
);
|
||||
|
||||
/* 跳转统一登录平台 */
|
||||
toUnifiedLogin() {
|
||||
setTimeout(() => {
|
||||
|
|
Loading…
Reference in New Issue