redirectUri 默认拼接链接

This commit is contained in:
wkj 2024-05-22 16:24:01 +08:00
parent 7661f5e13d
commit 50dc76548d
4 changed files with 32 additions and 10 deletions

View File

@ -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;

View File

@ -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 = (<Form colon={true}>
<Form.Item name="mobile">
<Input allowClear value={mobile} type="tel" size="large" maxLength={11} prefix={<MobileOutlined />} placeholder={t('placeholder.Mobile')} onChange={(e) => {
@ -132,7 +139,7 @@ export default function Render(props) {
[Style['loginbox-bd__grant']]: isSupportWechatGrant,
})}>
{isSupportWechatGrant ? (<div className={Style['loginbox-grant']}>
<WeChatLoginGrant disabled={!!disabled} disableText={disabled} appId={appId} scope="snsapi_userinfo" redirectUri={redirectUri} state={state}/>
<WeChatLoginGrant disabled={!!disabled} disableText={disabled} appId={appId} scope="snsapi_userinfo" redirectUri={redirectUri2} state={state}/>
</div>) : (<>
<div className={Style['loginbox-password']} style={{
display: loginMode === 1 ? 'block' : 'none',
@ -148,7 +155,7 @@ export default function Render(props) {
display: loginMode === 3 ? 'block' : 'none',
}}>
{/* 因为在选择授权方式时,微信网站和微信公众号授权登录二者只存其一,所以这里可以按这个判断分开显示 */}
{isSupportWechat && (<WeChatLoginQrCode disabled={!!disabled} disableText={disabled} appId={appId} scope="snsapi_login" redirectUri={redirectUri} state={state}/>)}
{isSupportWechat && (<WeChatLoginQrCode disabled={!!disabled} disableText={disabled} appId={appId} scope="snsapi_login" redirectUri={redirectUri2} state={state}/>)}
{isSupportWechatPublic && (<WechatLoginQrCodeForPublic type="login" oakPath="$login-wechatLogin/qrCode" oakAutoUnmount={true} url={state}/>)}
</div>
</>)}

View File

@ -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) {

View File

@ -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 = (
<Form colon={true}>
<Form.Item name="mobile">
@ -282,7 +293,7 @@ export default function Render(
disableText={disabled}
appId={appId}
scope="snsapi_userinfo"
redirectUri={redirectUri}
redirectUri={redirectUri2}
state={state}
/>
</div>
@ -317,7 +328,7 @@ export default function Render(
disableText={disabled}
appId={appId}
scope="snsapi_login"
redirectUri={redirectUri}
redirectUri={redirectUri2}
state={state}
/>
)}