feat: 实现二维码高级渲染功能,支持自定义颜色、形状和 Logo 嵌入
This commit is contained in:
@@ -14,10 +14,14 @@ export interface QrConfig {
|
||||
margin: number;
|
||||
/** 容错级别 */
|
||||
errorCorrection: 'L' | 'M' | 'Q' | 'H';
|
||||
/** 样式配置 */
|
||||
style: QrStyle;
|
||||
/** Logo 配置 */
|
||||
logo?: LogoConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 二维码样式(阶段 2 使用)
|
||||
* 二维码样式
|
||||
*/
|
||||
export interface QrStyle {
|
||||
/** 点形状 */
|
||||
@@ -35,12 +39,12 @@ export interface QrStyle {
|
||||
}
|
||||
|
||||
/**
|
||||
* Logo 配置(阶段 2 使用)
|
||||
* Logo 配置
|
||||
*/
|
||||
export interface LogoConfig {
|
||||
/** Logo 文件路径 */
|
||||
path: string;
|
||||
/** 缩放比例 (0.1 - 0.3) */
|
||||
/** 缩放比例 (0.05 - 0.3) */
|
||||
scale: number;
|
||||
/** 是否添加边框 */
|
||||
hasBorder: boolean;
|
||||
@@ -68,6 +72,18 @@ export type QrCodeCommands = {
|
||||
generate_qr_file: (config: QrConfig, outputPath: string) => Promise<void>;
|
||||
};
|
||||
|
||||
/**
|
||||
* 默认样式配置
|
||||
*/
|
||||
export const DEFAULT_QR_STYLE: QrStyle = {
|
||||
dotShape: 'square',
|
||||
eyeShape: 'square',
|
||||
foregroundColor: '#000000',
|
||||
backgroundColor: '#FFFFFF',
|
||||
isGradient: false,
|
||||
gradientColors: undefined,
|
||||
};
|
||||
|
||||
/**
|
||||
* 默认二维码配置
|
||||
*/
|
||||
@@ -76,6 +92,7 @@ export const DEFAULT_QR_CONFIG: QrConfig = {
|
||||
size: 512,
|
||||
margin: 4,
|
||||
errorCorrection: 'M',
|
||||
style: DEFAULT_QR_STYLE,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -97,3 +114,57 @@ export const SIZE_PRESETS = [
|
||||
{ value: 1024, label: '大 (1024px)' },
|
||||
{ value: 2048, label: '超大 (2048px)' },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* 点形状选项
|
||||
*/
|
||||
export const DOT_SHAPE_OPTIONS = [
|
||||
{ value: 'square', label: '方块', icon: '⬜' },
|
||||
{ value: 'circle', label: '圆点', icon: '⚫' },
|
||||
{ value: 'rounded', label: '圆角', icon: '▢' },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* 码眼形状选项
|
||||
*/
|
||||
export const EYE_SHAPE_OPTIONS = [
|
||||
{ value: 'square', label: '方块', icon: '⬜' },
|
||||
{ value: 'circle', label: '圆点', icon: '⚫' },
|
||||
{ value: 'rounded', label: '圆角', icon: '▢' },
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* 预设颜色方案
|
||||
*/
|
||||
export const COLOR_PRESETS = [
|
||||
{
|
||||
name: '经典',
|
||||
foreground: '#000000',
|
||||
background: '#FFFFFF',
|
||||
},
|
||||
{
|
||||
name: '蓝白',
|
||||
foreground: '#1E40AF',
|
||||
background: '#DBEAFE',
|
||||
},
|
||||
{
|
||||
name: '红白',
|
||||
foreground: '#DC2626',
|
||||
background: '#FEE2E2',
|
||||
},
|
||||
{
|
||||
name: '绿白',
|
||||
foreground: '#059669',
|
||||
background: '#D1FAE5',
|
||||
},
|
||||
{
|
||||
name: '紫白',
|
||||
foreground: '#7C3AED',
|
||||
background: '#EDE9FE',
|
||||
},
|
||||
{
|
||||
name: '橙白',
|
||||
foreground: '#EA580C',
|
||||
background: '#FFEDD5',
|
||||
},
|
||||
] as const;
|
||||
|
||||
Reference in New Issue
Block a user