From c8ed9dc165c7a1bbb0f54e6f7330286de7d36690 Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Mon, 8 May 2023 17:48:34 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor:=20=E9=87=8D?= =?UTF-8?q?=E5=86=99token=E8=8E=B7=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/login/login.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/pages/login/login.js b/src/pages/login/login.js index 55b3e9ae..e782b051 100644 --- a/src/pages/login/login.js +++ b/src/pages/login/login.js @@ -16,10 +16,9 @@ export default class App extends Component { } componentWillMount() { - const tokenString = this.props.location.search; - const token = tokenString.substring(tokenString.indexOf('=') + 1); + const { token, head } = this.getQuery(this.props.location.search); /* 判断是否有token */ - if (tokenString && tokenString.indexOf('=') > -1) { + if (token) { this.onSubmit(token); return; } @@ -27,6 +26,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(() => {