feat: 添加二维码生成功能并简化架构

- 新增二维码生成服务层,支持自定义内容和配置
  - 移除 Platform 抽象层,简化为三层架构
  - 更新开发文档和架构说明
  - 添加前端二维码生成页面和状态管理
This commit is contained in:
2026-02-10 19:06:36 +08:00
parent 927eaa1e03
commit b2754bdad5
24 changed files with 1642 additions and 278 deletions

99
src/types/qrcode.ts Normal file
View File

@@ -0,0 +1,99 @@
/**
* 二维码生成相关类型定义
*/
/**
* 二维码配置
*/
export interface QrConfig {
/** 二维码内容 */
content: string;
/** 输出尺寸(像素) */
size: number;
/** 边距(模块数) */
margin: number;
/** 容错级别 */
errorCorrection: 'L' | 'M' | 'Q' | 'H';
}
/**
* 二维码样式(阶段 2 使用)
*/
export interface QrStyle {
/** 点形状 */
dotShape: 'square' | 'circle' | 'rounded';
/** 码眼形状 */
eyeShape: 'square' | 'circle' | 'rounded';
/** 前景色Hex 颜色代码) */
foregroundColor: string;
/** 背景色Hex 颜色代码) */
backgroundColor: string;
/** 是否使用渐变 */
isGradient: boolean;
/** 渐变颜色列表 */
gradientColors?: string[];
}
/**
* Logo 配置(阶段 2 使用)
*/
export interface LogoConfig {
/** Logo 文件路径 */
path: string;
/** 缩放比例 (0.1 - 0.3) */
scale: number;
/** 是否添加边框 */
hasBorder: boolean;
/** 边框宽度(像素) */
borderWidth: number;
}
/**
* 二维码生成结果
*/
export interface QrResult {
/** Base64 编码的图片数据(带 data URL 前缀) */
data: string;
/** 图片格式(如 "png" */
format: string;
}
/**
* Tauri 命令类型声明
*/
export type QrCodeCommands = {
/** 生成二维码预览 */
generate_qr_preview: (config: QrConfig) => Promise<QrResult>;
/** 生成二维码并保存到文件 */
generate_qr_file: (config: QrConfig, outputPath: string) => Promise<void>;
};
/**
* 默认二维码配置
*/
export const DEFAULT_QR_CONFIG: QrConfig = {
content: 'https://example.com',
size: 512,
margin: 4,
errorCorrection: 'M',
};
/**
* 容错级别选项
*/
export const ERROR_CORRECTION_OPTIONS = [
{ value: 'L', label: 'L (7%)', description: '低容错率' },
{ value: 'M', label: 'M (15%)', description: '中容错率(推荐)' },
{ value: 'Q', label: 'Q (25%)', description: '高容错率' },
{ value: 'H', label: 'H (30%)', description: '最高容错率' },
] as const;
/**
* 预设尺寸选项
*/
export const SIZE_PRESETS = [
{ value: 256, label: '小 (256px)' },
{ value: 512, label: '中 (512px)' },
{ value: 1024, label: '大 (1024px)' },
{ value: 2048, label: '超大 (2048px)' },
] as const;