feat: 添加二维码生成功能并简化架构
- 新增二维码生成服务层,支持自定义内容和配置 - 移除 Platform 抽象层,简化为三层架构 - 更新开发文档和架构说明 - 添加前端二维码生成页面和状态管理
This commit is contained in:
52
docs/快速参考.md
52
docs/快速参考.md
@@ -5,12 +5,10 @@
|
||||
```
|
||||
1. 定义 Models → src/models/new_feature.rs
|
||||
2. 实现 Utils → src/utils/new_algorithm.rs (可选)
|
||||
3. 定义 Platform → src/platforms/new_feature.rs
|
||||
4. 实现平台代码 → src/platforms/windows/new_feature_impl.rs
|
||||
5. 实现 Service → src/services/new_feature_service.rs
|
||||
6. 创建 Command → src/commands/new_feature_commands.rs
|
||||
7. 注册模块 → 更新 mod.rs 和 lib.rs
|
||||
8. 测试验证 → cargo check && cargo test
|
||||
3. 实现 Service → src/services/new_feature_service.rs
|
||||
4. 创建 Command → src/commands/new_feature_commands.rs
|
||||
5. 注册模块 → 更新 mod.rs 和 lib.rs
|
||||
6. 测试验证 → cargo check && cargo test
|
||||
```
|
||||
|
||||
## 📁 文件模板
|
||||
@@ -64,31 +62,13 @@ pub fn execute_feature(input: FeatureData) -> Result<Output, String> {
|
||||
}
|
||||
```
|
||||
|
||||
### 4. Platform Trait 模板
|
||||
|
||||
```rust
|
||||
// src/platforms/feature.rs
|
||||
use crate::error::AppResult;
|
||||
|
||||
/// Trait 说明
|
||||
pub trait FeatureAccessor {
|
||||
fn do_something(&self, param: &str) -> AppResult<String>;
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
pub type PlatformFeature = crate::platforms::windows::feature_impl::WindowsFeature;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub type PlatformFeature = crate::platforms::windows::feature_impl::DummyFeature;
|
||||
```
|
||||
|
||||
## ✅ 代码规范清单
|
||||
|
||||
### 命名规范
|
||||
- [ ] 模块文件: `snake_case`
|
||||
- [ ] 结构体: `PascalCase`
|
||||
- [ ] 函数: `snake_case`
|
||||
- [ ] Trait: `PascalCase` + 能力描述
|
||||
- [ ] Trait: `PascalCase` + 能力描述(可选)
|
||||
|
||||
### 文档规范
|
||||
- [ ] 所有公开 API 有 `///` 注释
|
||||
@@ -103,7 +83,7 @@ pub type PlatformFeature = crate::platforms::windows::feature_impl::DummyFeature
|
||||
- [ ] 使用中文错误消息
|
||||
- [ ] 参数验证在 Service 层
|
||||
- [ ] Command 层简洁(仅适配)
|
||||
- [ ] 使用 `#[cfg(windows)]` 条件编译
|
||||
- [ ] Service 层可直接调用 Windows API
|
||||
|
||||
## 🔧 常用命令
|
||||
|
||||
@@ -148,8 +128,6 @@ cargo doc --open
|
||||
```
|
||||
models/color.rs → ColorInfo, RgbInfo, HslInfo
|
||||
utils/color_conversion.rs → rgb_to_hsl()
|
||||
platforms/screen.rs → ScreenAccessor trait
|
||||
platforms/windows/screen_impl.rs → WindowsScreen
|
||||
services/color_service.rs → ColorService
|
||||
commands/color_commands.rs → pick_color_interactive
|
||||
lib.rs → 注册命令
|
||||
@@ -160,8 +138,6 @@ lib.rs → 注册命令
|
||||
```
|
||||
models/screenshot.rs → ScreenshotConfig, ScreenshotResult
|
||||
utils/image_utils.rs → (可选) 图像处理工具
|
||||
platforms/screenshot.rs → ScreenshotCapturer trait
|
||||
platforms/windows/screenshot_impl.rs → WindowsScreenshot
|
||||
services/screenshot_service.rs → ScreenshotService
|
||||
commands/screenshot_commands.rs → capture_screen
|
||||
lib.rs → 注册 capture_screen
|
||||
@@ -169,19 +145,7 @@ lib.rs → 注册 capture_screen
|
||||
|
||||
## ⚠️ 常见错误
|
||||
|
||||
### 错误 1: Trait 方法未找到
|
||||
```rust
|
||||
// ❌ 错误
|
||||
use crate::platforms::screen::PlatformScreen;
|
||||
PlatformScreen::get_pixel_color(x, y)?; // 找不到方法
|
||||
|
||||
// ✅ 正确
|
||||
use crate::platforms::screen::PlatformScreen;
|
||||
use crate::platforms::screen::ScreenAccessor; // 导入 trait
|
||||
PlatformScreen::get_pixel_color(x, y)?;
|
||||
```
|
||||
|
||||
### 错误 2: 类型不匹配
|
||||
### 错误 1: 类型不匹配
|
||||
```rust
|
||||
// ❌ 错误
|
||||
pub fn toggle_window(window: &WebviewWindow) { }
|
||||
@@ -190,7 +154,7 @@ pub fn toggle_window(window: &WebviewWindow) { }
|
||||
pub fn toggle_window(window: &Window) { }
|
||||
```
|
||||
|
||||
### 错误 3: 忘记注册命令
|
||||
### 错误 2: 忘记注册命令
|
||||
```rust
|
||||
// ❌ 错误:命令未注册,前端无法调用
|
||||
|
||||
|
||||
Reference in New Issue
Block a user