From 06541a0ab0b35a735ee074f8f1ff15874ed9f08e Mon Sep 17 00:00:00 2001 From: wkj <278599135@.com> Date: Thu, 23 May 2024 01:02:24 +0800 Subject: [PATCH] =?UTF-8?q?wechatuser/login=20=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es/components/wechatUser/login/index.js | 36 +++++++++-------------- src/components/wechatUser/login/index.ts | 37 +++++++++--------------- 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/es/components/wechatUser/login/index.js b/es/components/wechatUser/login/index.js index 3079826d2..811bbedba 100644 --- a/es/components/wechatUser/login/index.js +++ b/es/components/wechatUser/login/index.js @@ -17,7 +17,6 @@ export default OakComponent({ this.setState({ loading: true, }); - const token = this.features.token.getToken(true); const url = window.location.href; const urlParse = new URL(url); //格式 xx?code=xx&state=/xx/xx?d=xx @@ -26,41 +25,32 @@ export default OakComponent({ const wechatLoginId = urlParse?.searchParams?.get('wechatLoginId'); if (!code) { this.setState({ - error: this.t('missingCodeParameter'), + error: '缺少code参数', loading: false, }); return; } - if (process.env.NODE_ENV === 'production' && - token?.ableState === 'enabled') { + try { + // web微信扫码跟公众号授权 + await this.features.token.loginWechat(code, { + wechatLoginId, + }); this.setState({ loading: false, }); this.go(state); } - else { - try { - // web微信扫码跟公众号授权 - await this.features.token.loginWechat(code, { - wechatLoginId, - }); - this.setState({ - loading: false, - }); - this.go(state); - } - catch (err) { - this.setState({ - error: this.t('weChatLoginFailed'), - loading: false, - }); - throw err; - } + catch (err) { + this.setState({ + error: '微信登录失败', + loading: false, + }); + throw err; } }, go(state) { if (!state) { - this.navigateBack(2); + this.navigateBack(); return; } this.redirectTo({ diff --git a/src/components/wechatUser/login/index.ts b/src/components/wechatUser/login/index.ts index 12baa8901..b2c75da42 100644 --- a/src/components/wechatUser/login/index.ts +++ b/src/components/wechatUser/login/index.ts @@ -18,7 +18,6 @@ export default OakComponent({ this.setState({ loading: true, }); - const token = this.features.token.getToken(true); const url = window.location.href; const urlParse = new URL(url); //格式 xx?code=xx&state=/xx/xx?d=xx @@ -27,42 +26,32 @@ export default OakComponent({ const wechatLoginId = urlParse?.searchParams?.get('wechatLoginId') as string; if (!code) { this.setState({ - error: this.t('missingCodeParameter'), + error: '缺少code参数', loading: false, }); return; } - if ( - process.env.NODE_ENV === 'production' && - token?.ableState === 'enabled' - ) { + try { + // web微信扫码跟公众号授权 + await this.features.token.loginWechat(code, { + wechatLoginId, + }); this.setState({ loading: false, }); this.go(state); - } else { - try { - // web微信扫码跟公众号授权 - await this.features.token.loginWechat(code, { - wechatLoginId, - }); - this.setState({ - loading: false, - }); - this.go(state); - } catch (err) { - this.setState({ - error: this.t('weChatLoginFailed'), - loading: false, - }); - throw err; - } + } catch (err) { + this.setState({ + error: '微信登录失败', + loading: false, + }); + throw err; } }, go(state?: string) { if (!state) { - this.navigateBack(2); + this.navigateBack(); return; } this.redirectTo({