wechatlogin 生成二维码

This commit is contained in:
Wang Kejun 2023-04-26 12:48:03 +08:00
parent c9659a7c8b
commit f5d64a6545
4 changed files with 30 additions and 9 deletions

View File

@ -78,7 +78,9 @@ exports.default = OakComponent({
switch (_d.label) { switch (_d.label) {
case 0: case 0:
wechatLoginId = this.state.wechatLoginId; wechatLoginId = this.state.wechatLoginId;
return [4 /*yield*/, this.features.cache.refresh('wechatLogin', { return [
4 /*yield*/,
this.features.cache.refresh('wechatLogin', {
data: { data: {
id: 1, id: 1,
userId: 1, userId: 1,
@ -103,7 +105,7 @@ exports.default = OakComponent({
applicationId: 1, applicationId: 1,
}, },
filter: { filter: {
entity: 'userEntityGrant', entity: 'wechatLogin',
}, },
indexFrom: 0, indexFrom: 0,
count: 1, count: 1,
@ -112,7 +114,8 @@ exports.default = OakComponent({
filter: { filter: {
id: wechatLoginId, id: wechatLoginId,
}, },
})]; }),
];
case 1: case 1:
_c = tslib_1.__read.apply(void 0, [(_d.sent()).data, 1]), wechatLogin = _c[0]; _c = tslib_1.__read.apply(void 0, [(_d.sent()).data, 1]), wechatLogin = _c[0];
qrCodeUrl = (_a = wechatLogin === null || wechatLogin === void 0 ? void 0 : wechatLogin.wechatQrCode$entity[0]) === null || _a === void 0 ? void 0 : _a.url; qrCodeUrl = (_a = wechatLogin === null || wechatLogin === void 0 ? void 0 : wechatLogin.wechatQrCode$entity[0]) === null || _a === void 0 ? void 0 : _a.url;

View File

@ -15,6 +15,7 @@ type IQrCodeProps = {
size?: number; size?: number;
url: string; url: string;
loading?: boolean; loading?: boolean;
disableDownload?: boolean;
}; };
@ -32,6 +33,7 @@ function QrCode(props: IQrCodeProps) {
size = 280, size = 280,
url, url,
loading = false, loading = false,
disableDownload = false,
} = props; } = props;
const prefixCls = 'oak'; const prefixCls = 'oak';
@ -81,7 +83,8 @@ function QrCode(props: IQrCodeProps) {
style={{ style={{
width: size, width: size,
height: size, height: size,
marginBottom: 10, marginBottom: 16,
marginTop: 16
}} }}
> >
{isBase64(url) ? ( {isBase64(url) ? (
@ -94,7 +97,7 @@ function QrCode(props: IQrCodeProps) {
{tips} {tips}
{ {
<Space className={`${prefixCls}-qrCodeBox_actions`}> <Space className={`${prefixCls}-qrCodeBox_actions`}>
{!!url && ( {!!url && !disableDownload && (
<Button <Button
type="text" type="text"
onClick={() => { onClick={() => {

View File

@ -18,17 +18,26 @@ export default OakComponent({
} }
}, },
}, },
data: {
loading: false,
},
properties: {
type: 'bind' as EntityDict['wechatLogin']['Schema']['type'],
},
methods: { methods: {
async createWechatLogin() { async createWechatLogin() {
const userId = this.features.token.getUserId(); const userId = this.features.token.getUserId();
const wechatLoginId = await generateNewIdAsync(); const wechatLoginId = await generateNewIdAsync();
const { type = 'bind' } = this.props;
await this.features.cache.operate('wechatLogin', { await this.features.cache.operate('wechatLogin', {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
action: 'create', action: 'create',
data: { data: {
id: wechatLoginId, id: wechatLoginId,
userId, userId,
type: 'bind', type,
expiresAt: Date.now() + Interval, expiresAt: Date.now() + Interval,
expired: false, expired: false,
qrCodeType: 'wechatPublic', qrCodeType: 'wechatPublic',
@ -73,7 +82,7 @@ export default OakComponent({
applicationId: 1, applicationId: 1,
}, },
filter: { filter: {
entity: 'userEntityGrant', entity: 'wechatLogin',
}, },
indexFrom: 0, indexFrom: 0,
count: 1, count: 1,

View File

@ -13,15 +13,21 @@ export default function Render(
{ {
wechatLoginId: string; wechatLoginId: string;
qrCodeUrl: string; qrCodeUrl: string;
loading: boolean;
}, },
{} {}
> >
) { ) {
const { oakFullpath, wechatLoginId, qrCodeUrl } = props.data; const { oakFullpath, qrCodeUrl, loading } = props.data;
return ( return (
<div> <div>
<QrCode url={qrCodeUrl} /> <QrCode
loading={loading}
url={qrCodeUrl}
disableDownload={true}
tips={<div></div>}
/>
</div> </div>
); );
} }