From 8c72102e875a5f5ba18d699ca031b5de3df42a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E8=AF=9A?= Date: Thu, 1 Jan 2026 15:20:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=9C=A8=E4=BA=A4=E6=98=93=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=B8=AD=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .sql/init_categories.sql | 29 +++++++ Repository/TransactionRecordRepository.cs | 17 ++++ Web/src/components/Global/GlobalAddBill.vue | 14 ++-- Web/src/views/ClassificationEdit.vue | 79 ++++++++++++++++++- Web/src/views/EmailRecord.vue | 64 ++++++++------- .../TransactionCategoryController.cs | 4 + 6 files changed, 173 insertions(+), 34 deletions(-) create mode 100644 .sql/init_categories.sql diff --git a/.sql/init_categories.sql b/.sql/init_categories.sql new file mode 100644 index 0000000..f3254ae --- /dev/null +++ b/.sql/init_categories.sql @@ -0,0 +1,29 @@ +-- 支出分类 (Type = 0) +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10001, '2026-01-01 00:00:00', 'C餐饮美食', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10002, '2026-01-01 00:00:00', 'F服饰美容', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10003, '2026-01-01 00:00:00', 'S生活日用', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10004, '2026-01-01 00:00:00', 'G交通出行', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10005, '2026-01-01 00:00:00', 'X休闲娱乐', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10006, '2026-01-01 00:00:00', 'Y医疗保健', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10007, '2026-01-01 00:00:00', 'Z住房物业', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10008, '2026-01-01 00:00:00', 'S水电煤气', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10009, '2026-01-01 00:00:00', 'T通讯物流', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10010, '2026-01-01 00:00:00', 'S学习教育', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10011, '2026-01-01 00:00:00', 'R人情往来', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10012, '2026-01-01 00:00:00', 'Q其他支出', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10013, '2026-01-01 00:00:00', 'N奶茶咖啡', 0); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (10014, '2026-01-01 00:00:00', 'D钻石福袋', 0); + + +-- 收入分类 (Type = 1) +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (11001, '2026-01-01 00:00:00', 'G工资薪金', 1); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (11002, '2026-01-01 00:00:00', 'J奖金补贴', 1); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (11003, '2026-01-01 00:00:00', 'L理财收益', 1); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (11004, '2026-01-01 00:00:00', 'J兼职收入', 1); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (11005, '2026-01-01 00:00:00', 'L礼金收入', 1); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (11006, '2026-01-01 00:00:00', 'Q其他收入', 1); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (11007, '2026-01-01 00:00:00', 'X闲鱼收入', 1); +-- 不记收支分类 (Type = 2) +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (12001, '2026-01-01 00:00:00', 'Z转账给自己', 2); +INSERT INTO TransactionCategory (Id, CreateTime, Name, Type) VALUES (12002, '2026-01-01 00:00:00', 'Z转账到公共', 2); + diff --git a/Repository/TransactionRecordRepository.cs b/Repository/TransactionRecordRepository.cs index f0d803e..bc87c08 100644 --- a/Repository/TransactionRecordRepository.cs +++ b/Repository/TransactionRecordRepository.cs @@ -178,6 +178,15 @@ public interface ITransactionRecordRepository : IBaseRepository当前交易类型 /// 候选交易列表 Task> GetCandidatesForOffsetAsync(long currentId, decimal amount, TransactionType currentType); + + /// + /// 更新分类名称 + /// + /// 旧分类名称 + /// 新分类名称 + /// 交易类型 + /// 影响行数 + Task UpdateCategoryNameAsync(string oldName, string newName, TransactionType type); } public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository(freeSql), ITransactionRecordRepository @@ -661,6 +670,14 @@ public class TransactionRecordRepository(IFreeSql freeSql) : BaseRepository Math.Abs(Math.Abs(t.Amount) - absAmount)).ToList(); } + + public async Task UpdateCategoryNameAsync(string oldName, string newName, TransactionType type) + { + return await FreeSql.Update() + .Set(a => a.Classify, newName) + .Where(a => a.Classify == oldName && a.Type == type) + .ExecuteAffrowsAsync(); + } } /// diff --git a/Web/src/components/Global/GlobalAddBill.vue b/Web/src/components/Global/GlobalAddBill.vue index 709df66..222888d 100644 --- a/Web/src/components/Global/GlobalAddBill.vue +++ b/Web/src/components/Global/GlobalAddBill.vue @@ -13,10 +13,10 @@ > - + - + @@ -33,11 +33,15 @@ const emit = defineEmits(['success']) const showAddBill = ref(false) const activeTab = ref('one') +const componentKey = ref(0) const openAddBill = () => { showAddBill.value = true - // Reset to default tab if needed, or keep last used - // activeTab.value = 'one' + // 清理状态,默认选中一句话录账 + activeTab.value = 'one' + + // 清理子组件状态通过 key 强制重渲染 + componentKey.value++ } const handleSuccess = () => { @@ -50,7 +54,7 @@ const handleSuccess = () => {