feat: 实现二维码高级渲染功能,支持自定义颜色、形状和 Logo 嵌入

This commit is contained in:
2026-02-10 19:59:32 +08:00
parent b2754bdad5
commit 825b650542
28 changed files with 1782 additions and 355 deletions

View File

@@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
///
/// 定义生成二维码所需的参数
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QrConfig {
/// 二维码内容
pub content: String,
@@ -15,12 +16,17 @@ pub struct QrConfig {
pub margin: u32,
/// 容错级别: "L", "M", "Q", "H"
pub error_correction: String,
/// 样式配置
pub style: Option<QrStyle>,
/// Logo 配置
pub logo: Option<LogoConfig>,
}
/// 二维码样式(阶段 2 使用)
/// 二维码样式
///
/// 定义二维码的视觉样式
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QrStyle {
/// 点形状: "square", "circle", "rounded"
pub dot_shape: String,
@@ -36,10 +42,24 @@ pub struct QrStyle {
pub gradient_colors: Option<Vec<String>>,
}
/// Logo 配置(阶段 2 使用)
impl Default for QrStyle {
fn default() -> Self {
Self {
dot_shape: "square".to_string(),
eye_shape: "square".to_string(),
foreground_color: "#000000".to_string(),
background_color: "#FFFFFF".to_string(),
is_gradient: false,
gradient_colors: None,
}
}
}
/// Logo 配置
///
/// 定义 Logo 的位置和样式
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct LogoConfig {
/// Logo 文件路径
pub path: String,
@@ -55,6 +75,7 @@ pub struct LogoConfig {
///
/// 包含生成的二维码图片数据
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct QrResult {
/// Base64 编码的图片数据
pub data: String,