fix
All checks were successful
Docker Build & Deploy / Build Docker Image (push) Successful in 19s
Docker Build & Deploy / Deploy to Production (push) Successful in 7s
Docker Build & Deploy / Cleanup Dangling Images (push) Successful in 1s
Docker Build & Deploy / WeChat Notification (push) Successful in 2s

This commit is contained in:
SunCheng
2026-02-04 19:23:07 +08:00
parent 15f0ba0993
commit 63aaaf39c5

View File

@@ -217,16 +217,73 @@ public class TransactionCategoryController(
return "分类不存在".Fail<string>(); return "分类不存在".Fail<string>();
} }
// 使用AI生成简洁的SVG图标 // 使用AI生成简洁、风格鲜明的SVG图标
var systemPrompt = @"你是一个SVG图标生成专家。请生成简洁、现代的单色SVG图标。 var systemPrompt = @"你是一个专业的SVG图标设计师。你的任务是为预算分类生成极简风格、视觉识别度高的SVG图标。
要求:
1. 只返回<svg>标签及其内容,不要其他说明文字
2. viewBox=""0 0 24 24""
3. 尺寸为24x24
4. 使用单色fill=""currentColor""
5. 简洁的设计,适合作为应用图标";
var userPrompt = $"为分类\"{category.Name}\"{(category.Type == TransactionType.Expense ? "" : category.Type == TransactionType.Income ? "" : "")}生成一个SVG图标"; ## 核心设计原则
1. **语义相关性**:图标必须直观反映分类本质。例如:
- 「餐饮」→ 餐具、碗筷或热腾腾的食物
- 「交通」→ 汽车、地铁或公交车
- 「购物」→ 购物袋或购物车
- 「娱乐」→ 电影票、游戏手柄或麦克风
- 「医疗」→ 十字架或药丸
- 「工资」→ 钱袋或上升箭头
2. **极简风格**
- 线条简洁流畅,避免复杂细节
- 使用几何图形和圆润的边角
- 2-4个主要形状元素即可
- 笔画粗细统一stroke-width: 2
3. **视觉识别**
- 轮廓清晰,一眼能认出是什么
- 避免抽象符号,优先具象图形
- 留白合理,图标不要过于密集
## 技术规范
- viewBox=""0 0 24 24""
- 尺寸为 24×24
- 使用单色fill=""currentColor"" 或 stroke=""currentColor""
- 优先使用 stroke描边而非 fill填充更显轻盈
- stroke-width=""2"" stroke-linecap=""round"" stroke-linejoin=""round""
- 只返回 <svg> 标签及其内容,不要其他说明
## 回退方案
如果该分类实在无法用具象图形表达(如「其他」「杂项」等),则生成包含该分类**首字**的文字图标:
```xml
<svg viewBox=""0 0 24 24"" fill=""none"" xmlns=""http://www.w3.org/2000/svg"">
<circle cx=""12"" cy=""12"" r=""10"" stroke=""currentColor"" stroke-width=""2""/>
<text x=""12"" y=""16"" font-size=""12"" font-weight=""bold"" text-anchor=""middle"" fill=""currentColor"">{首字}</text>
</svg>
```
## 示例
**好的图标**
- 「咖啡」→ 咖啡杯+热气
- 「房租」→ 房子外轮廓
- 「健身」→ 哑铃
**差的图标**
- 过于复杂的写实风格
- 无法识别的抽象符号
- 图形过小或过密";
var transactionTypeDesc = category.Type switch
{
TransactionType.Expense => "支出",
TransactionType.Income => "收入",
_ => "不计收支"
};
var userPrompt = $@"请为「{category.Name}」分类生成图标({transactionTypeDesc}类别)。
要求:
1. 分析这个分类的核心含义
2. 选择最具代表性的视觉元素
3. 用极简线条勾勒出图标(优先使用 stroke 描边风格)
4. 如果实在无法用图形表达,则生成包含「{(category.Name.Length > 0 ? category.Name[0] : '?')}」的文字图标
直接返回SVG代码无需解释。";
var svgContent = await openAiService.ChatAsync(systemPrompt, userPrompt, timeoutSeconds: 30); var svgContent = await openAiService.ChatAsync(systemPrompt, userPrompt, timeoutSeconds: 30);
if (string.IsNullOrWhiteSpace(svgContent)) if (string.IsNullOrWhiteSpace(svgContent))