diff --git a/es/components/common/qrCode/index.d.ts b/es/components/common/qrCode/index.d.ts
index 49ab81b73..2f75a6154 100644
--- a/es/components/common/qrCode/index.d.ts
+++ b/es/components/common/qrCode/index.d.ts
@@ -11,7 +11,7 @@ type IQrCodeProps = {
url: string;
loading?: boolean;
disableDownload?: boolean;
- successed?: boolean;
+ successful?: boolean;
type?: EntityDict['wechatLogin']['Schema']['type'];
};
declare function QrCode(props: IQrCodeProps): React.JSX.Element;
diff --git a/es/components/common/qrCode/index.js b/es/components/common/qrCode/index.js
index 7d0a17aeb..9d71db585 100644
--- a/es/components/common/qrCode/index.js
+++ b/es/components/common/qrCode/index.js
@@ -9,7 +9,7 @@ function isBase64(url) {
return /data:image\/[\w|\W]+(;base64,)[\w|\W]*/.test(url);
}
function QrCode(props) {
- const { filename = 'qrCode.png', expiresAt, tips, onDownload, onRefresh, size = 280, url, loading = false, disableDownload = false, successed, type, } = props;
+ const { filename = 'qrCode.png', expiresAt, tips, onDownload, onRefresh, size = 280, url, loading = false, disableDownload = false, successful, type, } = props;
const prefixCls = 'oak';
const features = useFeatures();
let V;
@@ -40,9 +40,11 @@ function QrCode(props) {
}
}
}
- if (successed) {
+ if (successful) {
return (
-
+
);
}
return (
diff --git a/es/components/common/weChatLoginQrCode/index.js b/es/components/common/weChatLoginQrCode/index.js
index e20eef54d..07b74f962 100644
--- a/es/components/common/weChatLoginQrCode/index.js
+++ b/es/components/common/weChatLoginQrCode/index.js
@@ -3,7 +3,7 @@ import { random } from 'oak-domain/lib/utils/string';
import classNames from 'classnames';
import './index.less';
function QrCode(props) {
- const { id = 'login_qr_container', appId, scope, redirectUri, state, style = '', href = '', dev = process.env.NODE_ENV === 'development', // 默认本地为true 发布时为false
+ const { id = 'login_qr_container', appId, scope, redirectUri, state, style = '', href = "data:text/css;base64,LmltcG93ZXJCb3ggLnFyY29kZSB7d2lkdGg6IDIwMHB4O30KLmltcG93ZXJCb3ggLnRpdGxlIHtkaXNwbGF5OiBub25lO30KLmltcG93ZXJCb3ggLmluZm8ge3dpZHRoOiAyMDBweDt9Ci5zdGF0dXNfaWNvbiB7ZGlzcGxheTogbm9uZX0KLmltcG93ZXJCb3ggLnN0YXR1cyB7dGV4dC1hbGlnbjogY2VudGVyO30gCg==", dev = process.env.NODE_ENV === 'development', // 默认本地为true 发布时为false
disabled = false, disableText, rootStyle, rootClassName, } = props;
const [code, setCode] = useState('');
useEffect(() => {
diff --git a/es/components/user/login/index.d.ts b/es/components/user/login/index.d.ts
index b0c093100..4b205fc98 100644
--- a/es/components/user/login/index.d.ts
+++ b/es/components/user/login/index.d.ts
@@ -3,5 +3,7 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
onlyPassword: boolean;
disabled: string;
redirectUri: string;
+ url: string;
+ callback: (() => void) | undefined;
}>) => React.ReactElement;
export default _default;
diff --git a/es/components/user/login/index.js b/es/components/user/login/index.js
index 20d814a87..90224e145 100644
--- a/es/components/user/login/index.js
+++ b/es/components/user/login/index.js
@@ -21,14 +21,16 @@ export default OakComponent({
lastSendAt: undefined,
isSupportWechat: false,
isSupportWechatPublic: false,
- isSupportGrant: false,
+ isSupportWechatGrant: false,
domain: undefined,
},
properties: {
onlyCaptcha: false,
onlyPassword: false,
disabled: '',
- redirectUri: '', // 微信登录后的redirectUri,要指向wechatUser/login去处理
+ redirectUri: '',
+ url: '',
+ callback: undefined, // 登录成功回调,排除微信登录方式
},
formData({ features, props }) {
const { lastSendAt } = this.state;
@@ -51,21 +53,20 @@ export default OakComponent({
lifetimes: {
async ready() {
const application = this.features.application.getApplication();
- let loginMode = await this.load(LOGIN_MODE) || 2;
+ let loginMode = (await this.load(LOGIN_MODE)) || 2;
const lastSendAt = await this.load(SEND_KEY);
const appType = application?.type;
const config = application?.config;
let appId;
- let domain; //网站扫码 授权回调域
- let isSupportScan = false; //是否支持微信扫码登录
+ let domain; //网站扫码授权回调域
let isSupportWechat = false; // 微信扫码网站登录
let isSupportWechatPublic = false; // 微信扫码公众号登录
- let isSupportGrant = false; // 是否支持微信公众号授权登录
+ let isSupportWechatGrant = false; // 微信公众号授权登录
if (appType === 'wechatPublic') {
const config2 = config;
const isService = config2?.isService; //是否服务号 服务号才能授权登录
appId = config2?.appId;
- isSupportGrant = !!(isService && appId);
+ isSupportWechatGrant = !!(isService && appId);
isSupportWechat = !!config2?.passport?.includes('wechat');
isSupportWechatPublic = !!config2?.passport?.includes('wechatPublic'); //是否开启
}
@@ -76,7 +77,7 @@ export default OakComponent({
isSupportWechat = !!config2?.passport?.includes('wechat');
isSupportWechatPublic = !!config2?.passport?.includes('wechatPublic'); //是否开启
}
- if (isSupportGrant) {
+ if (isSupportWechatGrant) {
loginMode = 1;
}
else if (this.props.onlyPassword) {
@@ -86,6 +87,7 @@ export default OakComponent({
loginMode = 2;
}
else {
+ const isSupportScan = isSupportWechat || isSupportWechatPublic;
loginMode = loginMode === 3 && !isSupportScan ? 2 : loginMode;
}
this.setState({
@@ -94,10 +96,10 @@ export default OakComponent({
lastSendAt,
isSupportWechat,
isSupportWechatPublic,
- isSupportGrant,
+ isSupportWechatGrant,
domain,
}, () => this.reRender());
- }
+ },
},
methods: {
async sendCaptcha(mobile) {
@@ -122,6 +124,7 @@ export default OakComponent({
}
},
async loginByMobile(mobile, password, captcha) {
+ const { url, callback } = this.props;
try {
this.setState({
loading: true,
@@ -130,6 +133,16 @@ export default OakComponent({
this.setState({
loading: false,
});
+ if (callback) {
+ callback();
+ return;
+ }
+ if (url) {
+ this.redirectTo({
+ url,
+ });
+ return;
+ }
}
catch (err) {
this.setState({
diff --git a/es/components/user/login/web.d.ts b/es/components/user/login/web.d.ts
index f51cc7af9..2c774c06f 100644
--- a/es/components/user/login/web.d.ts
+++ b/es/components/user/login/web.d.ts
@@ -11,7 +11,7 @@ export default function Render(props: WebComponentProps {
const newOptions = [];
- if (isSupportGrant) {
+ if (isSupportWechatGrant) {
newOptions.push({
label: 'WeChatLoginByGrant',
value: 1,
@@ -107,13 +107,13 @@ export default function Render(props) {
useEffect(() => {
getOptions();
}, [
- isSupportGrant,
+ isSupportWechatGrant,
onlyPassword,
onlyCaptcha,
isSupportWechat,
isSupportWechatPublic,
]);
- // 构建微信扫码所需state参数,url存在,扫码后重定向url,否则返回上一页
+ // 构建微信扫码所需state参数,url存在扫码后重定向url,否则返回上一页
let state = '';
if (url) {
state = encodeURIComponent(decodeURIComponent(url));
@@ -129,9 +129,9 @@ export default function Render(props) {
)}
- {isSupportGrant ? (
+ {isSupportWechatGrant ? (
) : (<>
- {/* 因为在选择授权方式时,微信网站和微信公众号授权登录二者只存其一,
- 所以这里可以按这个判断分开显示 */}
- {isSupportWechat && ()}
+ {/* 因为在选择授权方式时,微信网站和微信公众号授权登录二者只存其一,所以这里可以按这个判断分开显示 */}
+ {isSupportWechat && ()}
{isSupportWechatPublic && ()}
>)}
diff --git a/es/components/wechatLogin/qrCode/index.js b/es/components/wechatLogin/qrCode/index.js
index dfe5637e0..8be6739c2 100644
--- a/es/components/wechatLogin/qrCode/index.js
+++ b/es/components/wechatLogin/qrCode/index.js
@@ -3,7 +3,6 @@ export default OakComponent({
isList: false,
lifetimes: {
async attached() {
- const { type } = this.props;
this.createWechatLogin();
this.createTimer = setInterval(() => {
this.createWechatLogin();
@@ -24,7 +23,7 @@ export default OakComponent({
data: {
intervalId: '',
loading: false,
- successed: false,
+ successful: false,
},
properties: {
type: 'bind',
@@ -133,7 +132,7 @@ export default OakComponent({
});
const { successed, type } = wechatLogin;
this.setState({
- successed,
+ successful: successed,
type,
}, async () => {
// 未登录的情况下才走这里
diff --git a/es/components/wechatLogin/qrCode/web.d.ts b/es/components/wechatLogin/qrCode/web.d.ts
index a0df5debc..f993d92cb 100644
--- a/es/components/wechatLogin/qrCode/web.d.ts
+++ b/es/components/wechatLogin/qrCode/web.d.ts
@@ -5,6 +5,6 @@ export default function Render(props: WebComponentProps
): React.JSX.Element;
diff --git a/es/components/wechatLogin/qrCode/web.js b/es/components/wechatLogin/qrCode/web.js
index 19d211f41..740ab7521 100644
--- a/es/components/wechatLogin/qrCode/web.js
+++ b/es/components/wechatLogin/qrCode/web.js
@@ -1,8 +1,8 @@
import React from 'react';
import QrCode from '../../../components/common/qrCode';
export default function Render(props) {
- const { oakFullpath, qrCodeUrl, loading, successed, type } = props.data;
+ const { oakFullpath, qrCodeUrl, loading, successful, type } = props.data;
return (
- 微信扫一扫
} successed={successed} type={type}/>
+ 微信扫一扫} successful={successful} type={type}/>
);
}
diff --git a/src/components/common/qrCode/index.tsx b/src/components/common/qrCode/index.tsx
index f7ad0e8b4..b9cb32ae9 100644
--- a/src/components/common/qrCode/index.tsx
+++ b/src/components/common/qrCode/index.tsx
@@ -18,7 +18,7 @@ type IQrCodeProps = {
url: string;
loading?: boolean;
disableDownload?: boolean;
- successed?: boolean;
+ successful?: boolean;
type?: EntityDict['wechatLogin']['Schema']['type'];
};
@@ -38,7 +38,7 @@ function QrCode(props: IQrCodeProps) {
url,
loading = false,
disableDownload = false,
- successed,
+ successful,
type,
} = props;
const prefixCls = 'oak';
@@ -79,15 +79,23 @@ function QrCode(props: IQrCodeProps) {
}
}
- if (successed) {
+ if (successful) {
return (
- )
+ );
}
return (
diff --git a/src/components/common/weChatLoginQrCode/index.tsx b/src/components/common/weChatLoginQrCode/index.tsx
index cc48212fc..4788e1e7d 100644
--- a/src/components/common/weChatLoginQrCode/index.tsx
+++ b/src/components/common/weChatLoginQrCode/index.tsx
@@ -26,7 +26,7 @@ function QrCode(props: QrCodeProps) {
redirectUri,
state,
style = '',
- href = '',
+ href = "data:text/css;base64,LmltcG93ZXJCb3ggLnFyY29kZSB7d2lkdGg6IDIwMHB4O30KLmltcG93ZXJCb3ggLnRpdGxlIHtkaXNwbGF5OiBub25lO30KLmltcG93ZXJCb3ggLmluZm8ge3dpZHRoOiAyMDBweDt9Ci5zdGF0dXNfaWNvbiB7ZGlzcGxheTogbm9uZX0KLmltcG93ZXJCb3ggLnN0YXR1cyB7dGV4dC1hbGlnbjogY2VudGVyO30gCg==",
dev = process.env.NODE_ENV === 'development', // 默认本地为true 发布时为false
disabled = false,
disableText,
diff --git a/src/components/user/login/index.ts b/src/components/user/login/index.ts
index 6dfb543ed..af2d9e55f 100644
--- a/src/components/user/login/index.ts
+++ b/src/components/user/login/index.ts
@@ -24,14 +24,16 @@ export default OakComponent({
lastSendAt: undefined as undefined | number,
isSupportWechat: false,
isSupportWechatPublic: false,
- isSupportGrant: false,
+ isSupportWechatGrant: false,
domain: undefined as string | undefined,
},
properties: {
onlyCaptcha: false,
onlyPassword: false,
disabled: '',
- redirectUri: '', // 微信登录后的redirectUri,要指向wechatUser/login去处理
+ redirectUri: '', // 微信登录后的redirectUri,要指向wechatUser/login去处理
+ url: '', // 登录系统之后要返回的页面
+ callback: undefined as (() => void) | undefined, // 登录成功回调,排除微信登录方式
},
formData({ features, props }) {
const { lastSendAt } = this.state;
@@ -61,57 +63,63 @@ export default OakComponent({
async ready() {
const application = this.features.application.getApplication();
- let loginMode = await this.load(LOGIN_MODE) || 2;
+ let loginMode = (await this.load(LOGIN_MODE)) || 2;
const lastSendAt = await this.load(SEND_KEY);
const appType = application?.type as AppType;
const config = application?.config;
let appId;
- let domain; //网站扫码 授权回调域
- let isSupportScan = false; //是否支持微信扫码登录
+ let domain; //网站扫码授权回调域
let isSupportWechat = false; // 微信扫码网站登录
let isSupportWechatPublic = false; // 微信扫码公众号登录
- let isSupportGrant = false; // 是否支持微信公众号授权登录
+ let isSupportWechatGrant = false; // 微信公众号授权登录
if (appType === 'wechatPublic') {
const config2 = config as WechatPublicConfig;
const isService = config2?.isService; //是否服务号 服务号才能授权登录
appId = config2?.appId;
- isSupportGrant = !!(isService && 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 (isSupportGrant) {
+ if (isSupportWechatGrant) {
loginMode = 1;
} else if (this.props.onlyPassword) {
loginMode = 1;
} else if (this.props.onlyCaptcha) {
loginMode = 2;
} else {
+ const isSupportScan = isSupportWechat || isSupportWechatPublic;
loginMode = loginMode === 3 && !isSupportScan ? 2 : loginMode;
}
- this.setState({
- loginMode,
- appId,
- lastSendAt,
- isSupportWechat,
- isSupportWechatPublic,
- isSupportGrant,
- domain,
- }, () => this.reRender());
- }
+ this.setState(
+ {
+ loginMode,
+ appId,
+ lastSendAt,
+ isSupportWechat,
+ isSupportWechatPublic,
+ isSupportWechatGrant,
+ domain,
+ },
+ () => this.reRender()
+ );
+ },
},
methods: {
async sendCaptcha(mobile: string) {
try {
- const result = await this.features.token.sendCaptcha(mobile, 'login');
+ const result = await this.features.token.sendCaptcha(
+ mobile,
+ 'login'
+ );
// 显示返回消息
this.setMessage({
type: 'success',
@@ -119,9 +127,12 @@ export default OakComponent({
});
const lastSendAt = Date.now();
await this.save(SEND_KEY, lastSendAt);
- this.setState({
- lastSendAt,
- }, () => this.reRender());
+ this.setState(
+ {
+ lastSendAt,
+ },
+ () => this.reRender()
+ );
} catch (err) {
this.setMessage({
type: 'error',
@@ -134,6 +145,7 @@ export default OakComponent({
password?: string,
captcha?: string
) {
+ const { url, callback } = this.props;
try {
this.setState({
loading: true,
@@ -141,11 +153,21 @@ export default OakComponent({
await this.features.token.loginByMobile(
mobile,
password,
- captcha,
+ captcha
);
this.setState({
loading: false,
});
+ if (callback) {
+ callback();
+ return;
+ }
+ if (url) {
+ this.redirectTo({
+ url,
+ });
+ return;
+ }
} catch (err) {
this.setState({
loading: false,
diff --git a/src/components/user/login/web.tsx b/src/components/user/login/web.tsx
index 5e5e2b0a7..4ccfd2284 100644
--- a/src/components/user/login/web.tsx
+++ b/src/components/user/login/web.tsx
@@ -40,7 +40,7 @@ export default function Render(
width: string;
isSupportWechat: boolean;
isSupportWechatPublic: boolean;
- isSupportGrant: boolean;
+ isSupportWechatGrant: boolean;
domain?: string;
disabled?: string;
redirectUri: string;
@@ -69,7 +69,7 @@ export default function Render(
domain,
isSupportWechat,
isSupportWechatPublic,
- isSupportGrant,
+ isSupportWechatGrant,
disabled,
redirectUri,
url,
@@ -195,7 +195,7 @@ export default function Render(
const getOptions = () => {
const newOptions: Option[] = [];
- if (isSupportGrant) {
+ if (isSupportWechatGrant) {
newOptions.push({
label: 'WeChatLoginByGrant',
value: 1,
@@ -236,14 +236,14 @@ export default function Render(
useEffect(() => {
getOptions();
}, [
- isSupportGrant,
+ isSupportWechatGrant,
onlyPassword,
onlyCaptcha,
isSupportWechat,
isSupportWechatPublic,
]);
- // 构建微信扫码所需state参数,url存在,扫码后重定向url,否则返回上一页
+ // 构建微信扫码所需state参数,url存在扫码后重定向url,否则返回上一页
let state = '';
if (url) {
state = encodeURIComponent(decodeURIComponent(url));
@@ -272,10 +272,10 @@ export default function Render(
- {isSupportGrant ? (
+ {isSupportWechatGrant ? (
- {/* 因为在选择授权方式时,微信网站和微信公众号授权登录二者只存其一,
- 所以这里可以按这个判断分开显示 */}
+ {/* 因为在选择授权方式时,微信网站和微信公众号授权登录二者只存其一,所以这里可以按这个判断分开显示 */}
{isSupportWechat && (
)}
{isSupportWechatPublic && (
diff --git a/src/components/wechatLogin/qrCode/index.ts b/src/components/wechatLogin/qrCode/index.ts
index 5ab7365ec..22553c27c 100644
--- a/src/components/wechatLogin/qrCode/index.ts
+++ b/src/components/wechatLogin/qrCode/index.ts
@@ -1,5 +1,4 @@
import { EntityDict } from '../../../oak-app-domain';
-import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
const Interval = 2 * 60 * 1000;
@@ -7,7 +6,6 @@ export default OakComponent({
isList: false,
lifetimes: {
async attached() {
- const { type } = this.props;
this.createWechatLogin();
(this as any).createTimer = setInterval(() => {
this.createWechatLogin();
@@ -28,7 +26,7 @@ export default OakComponent({
data: {
intervalId: '',
loading: false,
- successed: false,
+ successful: false,
},
properties: {
type: 'bind' as EntityDict['wechatLogin']['Schema']['type'],
@@ -150,7 +148,7 @@ export default OakComponent({
const { successed, type } = wechatLogin;
this.setState(
{
- successed,
+ successful: successed,
type,
},
async () => {
diff --git a/src/components/wechatLogin/qrCode/web.tsx b/src/components/wechatLogin/qrCode/web.tsx
index efae50ada..1da78f77c 100644
--- a/src/components/wechatLogin/qrCode/web.tsx
+++ b/src/components/wechatLogin/qrCode/web.tsx
@@ -14,13 +14,13 @@ export default function Render(
wechatLoginId: string;
qrCodeUrl: string;
loading: boolean;
- successed: boolean;
- type: EntityDict['wechatLogin']['Schema']['type']
+ successful: boolean;
+ type: EntityDict['wechatLogin']['Schema']['type'];
},
{}
>
) {
- const { oakFullpath, qrCodeUrl, loading, successed, type } = props.data;
+ const { oakFullpath, qrCodeUrl, loading, successful, type } = props.data;
return (
@@ -29,7 +29,7 @@ export default function Render(
url={qrCodeUrl}
disableDownload={true}
tips={
微信扫一扫
}
- successed={successed}
+ successful={successful}
type={type}
/>