生成二维码增加mode参数web端调整

This commit is contained in:
wkj 2025-09-23 18:24:38 +08:00
parent 0a359eb287
commit 7463494fce
14 changed files with 116 additions and 92 deletions

View File

@ -18,6 +18,7 @@ type IQrCodeProps = {
maskColor: string; maskColor: string;
maskTextColor: string; maskTextColor: string;
maskText: string; maskText: string;
mode: 'default' | 'simple';
}; };
export default function Render(props: WebComponentProps<EntityDict, keyof EntityDict, false, IQrCodeProps & { export default function Render(props: WebComponentProps<EntityDict, keyof EntityDict, false, IQrCodeProps & {
isBase64: boolean; isBase64: boolean;

View File

@ -6,7 +6,7 @@ import './web.less';
export default function Render(props) { export default function Render(props) {
const { data, methods } = props; const { data, methods } = props;
const { t } = methods; const { t } = methods;
const { filename = 'qrCode.png', expiresAt, tips, onDownload, onRefresh, size = 280, url, loading = false, disableDownload = false, disabled = false, isBase64, expired, expiresAtStr, color, bgColor, maskColor, maskTextColor, maskText, } = data; const { filename = 'qrCode.png', expiresAt, tips, onDownload, onRefresh, size = 280, url, loading = false, disableDownload = false, disabled = false, isBase64, expired, expiresAtStr, color, bgColor, maskColor, maskTextColor, maskText, mode, } = data;
const prefixCls = 'oak'; const prefixCls = 'oak';
let V; let V;
if (expiresAtStr) { if (expiresAtStr) {
@ -24,12 +24,10 @@ export default function Render(props) {
} }
} }
return (<div id="oakQrCode" className={`${prefixCls}-qrCodeBox`}> return (<div id="oakQrCode" className={`${prefixCls}-qrCodeBox`}>
<div className={`${prefixCls}-qrCodeBox_qrcode`} style={{ <div className={`${prefixCls}-qrCodeBox_qrcode`} style={mode === 'default' ? {
// width: size,
// height: size,
marginBottom: 16, marginBottom: 16,
marginTop: 16, marginTop: 16,
}}> } : {}}>
<Spin spinning={loading}> <Spin spinning={loading}>
{isBase64 ? (<img src={url} alt="qrCode" width={size} height={size}/>) : url ? (<QRCodeCanvas value={url} size={size} fgColor={color} bgColor={bgColor}/>) : null} {isBase64 ? (<img src={url} alt="qrCode" width={size} height={size}/>) : url ? (<QRCodeCanvas value={url} size={size} fgColor={color} bgColor={bgColor}/>) : null}
</Spin> </Spin>
@ -41,34 +39,39 @@ export default function Render(props) {
</div> : null} </div> : null}
</div> </div>
{V} {mode === 'default' ?
{tips} <>
{<Space className={`${prefixCls}-qrCodeBox_actions`}> {V}
{!!url && !disableDownload && !disabled && (<Button type="text" onClick={() => { {tips}
if (typeof onDownload === 'function') { {<Space className={`${prefixCls}-qrCodeBox_actions`}>
onDownload(url, filename); {!!url && !disableDownload && !disabled && (<Button type="text" onClick={() => {
return; if (typeof onDownload === 'function') {
} onDownload(url, filename);
const canvas = document return;
.getElementById('oakQrCode') }
?.querySelector('canvas'); const canvas = document
if (canvas) { .getElementById('oakQrCode')
const url = canvas.toDataURL(); ?.querySelector('canvas');
const a = document.createElement('a'); if (canvas) {
a.download = filename; const url = canvas.toDataURL();
a.href = url; const a = document.createElement('a');
document.body.appendChild(a); a.download = filename;
a.click(); a.href = url;
document.body.removeChild(a); document.body.appendChild(a);
} a.click();
}}> document.body.removeChild(a);
<DownloadOutlined className={`${prefixCls}-qrCodeBox_actions_downloadIcon`}/> }
</Button>)} }}>
{onRefresh && (<Button type="text" onClick={() => { <DownloadOutlined className={`${prefixCls}-qrCodeBox_actions_downloadIcon`}/>
onRefresh(); </Button>)}
}} size="small"> {onRefresh && (<Button type="text" onClick={() => {
<ReloadOutlined className={`${prefixCls}-qrCodeBox_actions_refreshIcon`}/> onRefresh();
</Button>)} }} size="small">
</Space>} <ReloadOutlined className={`${prefixCls}-qrCodeBox_actions_refreshIcon`}/>
</Button>)}
</Space>}
</>
: null}
</div>); </div>);
} }

View File

@ -7,5 +7,6 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
maskColor: string; maskColor: string;
maskText: string; maskText: string;
maskTextColor: string; maskTextColor: string;
mode: "default" | "simple";
}>) => React.ReactElement; }>) => React.ReactElement;
export default _default; export default _default;

View File

@ -76,5 +76,6 @@ export default OakComponent({
maskColor: 'rgba(255,255,255,0.96)', maskColor: 'rgba(255,255,255,0.96)',
maskText: '', maskText: '',
maskTextColor: 'rgba(0,0,0,0.88)', maskTextColor: 'rgba(0,0,0,0.88)',
mode: 'default',
}, },
}); });

View File

@ -7,7 +7,9 @@
<block wx:elif="{{url}}"> <block wx:elif="{{url}}">
<qrCode url="{{url}}" expiresAt="{{expiresAt}}" disableDownload="{{disableDownload}}" <qrCode url="{{url}}" expiresAt="{{expiresAt}}" disableDownload="{{disableDownload}}"
size="{{size}}" disabled="{{disabled}}" color="{{color}}" bgColor="{{bgColor}}" size="{{size}}" disabled="{{disabled}}" color="{{color}}" bgColor="{{bgColor}}"
maskColor="{{maskColor}}" maskText="{{maskText}}" maskTextColor="{{maskTextColor}}" /> maskColor="{{maskColor}}" maskText="{{maskText}}" maskTextColor="{{maskTextColor}}"
mode="{{mode}}"
/>
</block> </block>
<block wx:else> <block wx:else>
</block> </block>

View File

@ -12,4 +12,5 @@ export default function Render(props: WebComponentProps<EntityDict, 'userEntityG
maskColor: string; maskColor: string;
maskText: string; maskText: string;
maskTextColor: string; maskTextColor: string;
mode: 'default' | 'simple';
}, {}>): React.JSX.Element | null; }, {}>): React.JSX.Element | null;

View File

@ -2,12 +2,12 @@ import React from 'react';
import QrCode from '../../common/qrCode'; import QrCode from '../../common/qrCode';
import { DotLoading } from 'antd-mobile'; import { DotLoading } from 'antd-mobile';
export default function Render(props) { export default function Render(props) {
const { url, expiresAt, oakLoading, disableDownload, size, disabled, color, bgColor, maskColor, maskText, maskTextColor } = props.data; const { url, expiresAt, oakLoading, disableDownload, size, disabled, color, bgColor, maskColor, maskText, maskTextColor, mode } = props.data;
if (oakLoading) { if (oakLoading) {
return <DotLoading color="primary"/>; return <DotLoading color="primary"/>;
} }
if (url) { if (url) {
return (<QrCode url={url} expiresAt={expiresAt} disableDownload={disableDownload} size={size} disabled={disabled} color={color} bgColor={bgColor} maskColor={maskColor} maskText={maskText} maskTextColor={maskTextColor}/>); return (<QrCode url={url} expiresAt={expiresAt} disableDownload={disableDownload} size={size} disabled={disabled} color={color} bgColor={bgColor} maskColor={maskColor} maskText={maskText} maskTextColor={maskTextColor} mode={mode}/>);
} }
return null; return null;
} }

View File

@ -12,4 +12,5 @@ export default function Render(props: WebComponentProps<EntityDict, 'userEntityG
maskColor: string; maskColor: string;
maskText: string; maskText: string;
maskTextColor: string; maskTextColor: string;
mode: 'default' | 'simple';
}, {}>): React.JSX.Element | null; }, {}>): React.JSX.Element | null;

View File

@ -2,12 +2,12 @@ import React from 'react';
import QrCode from '../../common/qrCode'; import QrCode from '../../common/qrCode';
import { Spin } from 'antd'; import { Spin } from 'antd';
export default function Render(props) { export default function Render(props) {
const { url, expiresAt, oakLoading, disableDownload, size, disabled, color, bgColor, maskColor, maskText, maskTextColor } = props.data; const { url, expiresAt, oakLoading, disableDownload, size, disabled, color, bgColor, maskColor, maskText, maskTextColor, mode } = props.data;
if (oakLoading) { if (oakLoading) {
return <Spin />; return <Spin />;
} }
if (url) { if (url) {
return (<QrCode url={url} expiresAt={expiresAt} disableDownload={disableDownload} size={size} disabled={disabled} color={color} bgColor={bgColor} maskColor={maskColor} maskText={maskText} maskTextColor={maskTextColor}/>); return (<QrCode url={url} expiresAt={expiresAt} disableDownload={disableDownload} size={size} disabled={disabled} color={color} bgColor={bgColor} maskColor={maskColor} maskText={maskText} maskTextColor={maskTextColor} mode={mode}/>);
} }
return null; return null;
} }

View File

@ -23,6 +23,7 @@ type IQrCodeProps = {
maskColor: string; maskColor: string;
maskTextColor: string; maskTextColor: string;
maskText: string; maskText: string;
mode: 'default' | 'simple';
}; };
export default function Render( export default function Render(
@ -60,6 +61,7 @@ export default function Render(
maskColor, maskColor,
maskTextColor, maskTextColor,
maskText, maskText,
mode,
} = data; } = data;
const prefixCls = 'oak'; const prefixCls = 'oak';
let V; let V;
@ -85,12 +87,10 @@ export default function Render(
<div id="oakQrCode" className={`${prefixCls}-qrCodeBox`}> <div id="oakQrCode" className={`${prefixCls}-qrCodeBox`}>
<div <div
className={`${prefixCls}-qrCodeBox_qrcode`} className={`${prefixCls}-qrCodeBox_qrcode`}
style={{ style={mode === 'default' ? {
// width: size,
// height: size,
marginBottom: 16, marginBottom: 16,
marginTop: 16, marginTop: 16,
}} }: {}}
> >
<Spin spinning={loading}> <Spin spinning={loading}>
{isBase64 ? ( {isBase64 ? (
@ -112,54 +112,61 @@ export default function Render(
</div> : null} </div> : null}
</div> </div>
{V}
{tips}
{ {
<Space className={`${prefixCls}-qrCodeBox_actions`}> mode === 'default' ?
{!!url && !disableDownload && !disabled && ( <>
<Button {V}
type="text" {tips}
onClick={() => { {
if (typeof onDownload === 'function') { <Space className={`${prefixCls}-qrCodeBox_actions`}>
onDownload(url, filename); {!!url && !disableDownload && !disabled && (
return; <Button
} type="text"
const canvas = document onClick={() => {
.getElementById('oakQrCode') if (typeof onDownload === 'function') {
?.querySelector<HTMLCanvasElement>( onDownload(url, filename);
'canvas' return;
); }
if (canvas) { const canvas = document
const url = canvas.toDataURL(); .getElementById('oakQrCode')
const a = document.createElement('a'); ?.querySelector<HTMLCanvasElement>(
a.download = filename; 'canvas'
a.href = url; );
document.body.appendChild(a); if (canvas) {
a.click(); const url = canvas.toDataURL();
document.body.removeChild(a); const a = document.createElement('a');
} a.download = filename;
}} a.href = url;
> document.body.appendChild(a);
<DownloadOutlined a.click();
className={`${prefixCls}-qrCodeBox_actions_downloadIcon`} document.body.removeChild(a);
/> }
</Button> }}
)} >
{onRefresh && ( <DownloadOutlined
<Button className={`${prefixCls}-qrCodeBox_actions_downloadIcon`}
type="text" />
onClick={() => { </Button>
onRefresh(); )}
}} {onRefresh && (
size="small" <Button
> type="text"
<ReloadOutlined onClick={() => {
className={`${prefixCls}-qrCodeBox_actions_refreshIcon`} onRefresh();
/> }}
</Button> size="small"
)} >
</Space> <ReloadOutlined
className={`${prefixCls}-qrCodeBox_actions_refreshIcon`}
/>
</Button>
)}
</Space>
}
</>
: null
} }
</div> </div>
); );
} }

View File

@ -78,5 +78,6 @@ export default OakComponent({
maskColor: 'rgba(255,255,255,0.96)', maskColor: 'rgba(255,255,255,0.96)',
maskText: '', maskText: '',
maskTextColor: 'rgba(0,0,0,0.88)', maskTextColor: 'rgba(0,0,0,0.88)',
mode: 'default' as 'default' | 'simple',
}, },
}); });

View File

@ -7,7 +7,9 @@
<block wx:elif="{{url}}"> <block wx:elif="{{url}}">
<qrCode url="{{url}}" expiresAt="{{expiresAt}}" disableDownload="{{disableDownload}}" <qrCode url="{{url}}" expiresAt="{{expiresAt}}" disableDownload="{{disableDownload}}"
size="{{size}}" disabled="{{disabled}}" color="{{color}}" bgColor="{{bgColor}}" size="{{size}}" disabled="{{disabled}}" color="{{color}}" bgColor="{{bgColor}}"
maskColor="{{maskColor}}" maskText="{{maskText}}" maskTextColor="{{maskTextColor}}" /> maskColor="{{maskColor}}" maskText="{{maskText}}" maskTextColor="{{maskTextColor}}"
mode="{{mode}}"
/>
</block> </block>
<block wx:else> <block wx:else>
</block> </block>

View File

@ -20,11 +20,12 @@ export default function Render(
maskColor: string; maskColor: string;
maskText: string; maskText: string;
maskTextColor: string; maskTextColor: string;
mode: 'default' | 'simple';
}, },
{} {}
> >
) { ) {
const { url, expiresAt, oakLoading, disableDownload, size, disabled, color, bgColor, maskColor, maskText, maskTextColor } = props.data; const { url, expiresAt, oakLoading, disableDownload, size, disabled, color, bgColor, maskColor, maskText, maskTextColor, mode } = props.data;
if (oakLoading) { if (oakLoading) {
return <Spin />; return <Spin />;
} }
@ -41,6 +42,7 @@ export default function Render(
maskColor={maskColor} maskColor={maskColor}
maskText={maskText} maskText={maskText}
maskTextColor={maskTextColor} maskTextColor={maskTextColor}
mode={mode}
/> />
); );
} }

View File

@ -20,11 +20,12 @@ export default function Render(
maskColor: string; maskColor: string;
maskText: string; maskText: string;
maskTextColor: string; maskTextColor: string;
mode: 'default' | 'simple';
}, },
{} {}
> >
) { ) {
const { url, expiresAt, oakLoading, disableDownload, size, disabled, color, bgColor, maskColor, maskText, maskTextColor } = props.data; const { url, expiresAt, oakLoading, disableDownload, size, disabled, color, bgColor, maskColor, maskText, maskTextColor, mode } = props.data;
if (oakLoading) { if (oakLoading) {
return <DotLoading color="primary" />; return <DotLoading color="primary" />;
} }
@ -41,6 +42,7 @@ export default function Render(
maskColor={maskColor} maskColor={maskColor}
maskText={maskText} maskText={maskText}
maskTextColor={maskTextColor} maskTextColor={maskTextColor}
mode={mode}
/> />
); );
} }