From 50dc76548d6aa8c10528fc2f24622cd38c7047cf Mon Sep 17 00:00:00 2001
From: wkj <278599135@.com>
Date: Wed, 22 May 2024 16:24:01 +0800
Subject: [PATCH] =?UTF-8?q?redirectUri=20=E9=BB=98=E8=AE=A4=E6=8B=BC?=
=?UTF-8?q?=E6=8E=A5=E9=93=BE=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
es/components/user/login/index.js | 8 +++++---
es/components/user/login/web.js | 11 +++++++++--
src/components/user/login/index.ts | 8 +++++---
src/components/user/login/web.tsx | 15 +++++++++++++--
4 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/es/components/user/login/index.js b/es/components/user/login/index.js
index 90224e145..fd48729de 100644
--- a/es/components/user/login/index.js
+++ b/es/components/user/login/index.js
@@ -28,7 +28,7 @@ export default OakComponent({
onlyCaptcha: false,
onlyPassword: false,
disabled: '',
- redirectUri: '',
+ redirectUri: '/wechatUser/login',
url: '',
callback: undefined, // 登录成功回调,排除微信登录方式
},
@@ -68,14 +68,16 @@ export default OakComponent({
appId = config2?.appId;
isSupportWechatGrant = !!(isService && appId);
isSupportWechat = !!config2?.passport?.includes('wechat');
- isSupportWechatPublic = !!config2?.passport?.includes('wechatPublic'); //是否开启
+ isSupportWechatPublic =
+ !!config2?.passport?.includes('wechatPublic'); //是否开启
}
else if (appType === 'web') {
const config2 = config;
appId = config2?.wechat?.appId;
domain = config2?.wechat?.domain;
isSupportWechat = !!config2?.passport?.includes('wechat');
- isSupportWechatPublic = !!config2?.passport?.includes('wechatPublic'); //是否开启
+ isSupportWechatPublic =
+ !!config2?.passport?.includes('wechatPublic'); //是否开启
}
if (isSupportWechatGrant) {
loginMode = 1;
diff --git a/es/components/user/login/web.js b/es/components/user/login/web.js
index f58ef5dba..a5f939f54 100644
--- a/es/components/user/login/web.js
+++ b/es/components/user/login/web.js
@@ -20,6 +20,13 @@ export default function Render(props) {
const validCaptcha = isCaptcha(captcha);
const validPassword = isPassword(password);
const allowSubmit = validMobile && (validCaptcha || validPassword);
+ let redirectUri2 = redirectUri;
+ if (!(redirectUri.startsWith('https') || redirectUri.startsWith('http'))) {
+ const hostname = domain || window.location.hostname;
+ const port = window.location.port ? `:${window.location.port}` : '';
+ const path = redirectUri.startsWith('/') ? redirectUri : `/${redirectUri}`;
+ redirectUri2 = encodeURIComponent(`${window.location.protocol}//${hostname}${port}${path}`);
+ }
const LoginPassword = (
} placeholder={t('placeholder.Mobile')} onChange={(e) => {
@@ -132,7 +139,7 @@ export default function Render(props) {
[Style['loginbox-bd__grant']]: isSupportWechatGrant,
})}>
{isSupportWechatGrant ? (
-
+
) : (<>
{/* 因为在选择授权方式时,微信网站和微信公众号授权登录二者只存其一,所以这里可以按这个判断分开显示 */}
- {isSupportWechat && ()}
+ {isSupportWechat && ()}
{isSupportWechatPublic && ()}
>)}
diff --git a/src/components/user/login/index.ts b/src/components/user/login/index.ts
index af2d9e55f..42df02f49 100644
--- a/src/components/user/login/index.ts
+++ b/src/components/user/login/index.ts
@@ -31,7 +31,7 @@ export default OakComponent({
onlyCaptcha: false,
onlyPassword: false,
disabled: '',
- redirectUri: '', // 微信登录后的redirectUri,要指向wechatUser/login去处理
+ redirectUri: '/wechatUser/login', // 微信登录后的redirectUri,要指向wechatUser/login去处理
url: '', // 登录系统之后要返回的页面
callback: undefined as (() => void) | undefined, // 登录成功回调,排除微信登录方式
},
@@ -79,13 +79,15 @@ export default OakComponent({
appId = config2?.appId;
isSupportWechatGrant = !!(isService && appId);
isSupportWechat = !!config2?.passport?.includes('wechat');
- isSupportWechatPublic = !!config2?.passport?.includes('wechatPublic'); //是否开启
+ isSupportWechatPublic =
+ !!config2?.passport?.includes('wechatPublic'); //是否开启
} else if (appType === 'web') {
const config2 = config as WebConfig;
appId = config2?.wechat?.appId;
domain = config2?.wechat?.domain;
isSupportWechat = !!config2?.passport?.includes('wechat');
- isSupportWechatPublic = !!config2?.passport?.includes('wechatPublic'); //是否开启
+ isSupportWechatPublic =
+ !!config2?.passport?.includes('wechatPublic'); //是否开启
}
if (isSupportWechatGrant) {
diff --git a/src/components/user/login/web.tsx b/src/components/user/login/web.tsx
index 4ccfd2284..3db6916d6 100644
--- a/src/components/user/login/web.tsx
+++ b/src/components/user/login/web.tsx
@@ -85,6 +85,17 @@ export default function Render(
const validPassword = isPassword(password);
const allowSubmit = validMobile && (validCaptcha || validPassword);
+ let redirectUri2 = redirectUri;
+ if (!(redirectUri.startsWith('https') || redirectUri.startsWith('http'))) {
+ const hostname = domain || window.location.hostname;
+ const port = window.location.port ? `:${window.location.port}` : '';
+ const path = redirectUri.startsWith('/') ? redirectUri : `/${redirectUri}`;
+ redirectUri2 = encodeURIComponent(
+ `${window.location.protocol}//${hostname}${port}${path}`
+ );
+ }
+
+
const LoginPassword = (
@@ -282,7 +293,7 @@ export default function Render(
disableText={disabled}
appId={appId}
scope="snsapi_userinfo"
- redirectUri={redirectUri}
+ redirectUri={redirectUri2}
state={state}
/>
@@ -317,7 +328,7 @@ export default function Render(
disableText={disabled}
appId={appId}
scope="snsapi_login"
- redirectUri={redirectUri}
+ redirectUri={redirectUri2}
state={state}
/>
)}