From db81ad8eb2b0a3626b9540789ae755bf2962f9e5 Mon Sep 17 00:00:00 2001
From: wangxiaogang <1433729587@qq.com>
Date: Tue, 2 Jun 2026 17:41:35 +0800
Subject: [PATCH] =?UTF-8?q?refactor:=20API=20=E8=AF=B7=E6=B1=82=E6=95=B4?=
=?UTF-8?q?=E5=90=88=E4=B8=8E=20Bug=20=E4=BF=AE=E5=A4=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
前端重构:
- 新增 api/ 目录统一管理所有 API 请求
- 所有 stores 和 pages 改为使用 api 模块
- 修复日期格式化函数,支持 Date 对象和 ISO 字符串
- 修复 TransactionItem 使用 CategoryIcon 组件
- 优化 ChartWrapper 区分 H5 和小程序环境
后端修复:
- 修复 auth 中间件 PUBLIC_PATHS 缺少 demo-login
- 修复备份工具命令注入漏洞,改用 execFile
- 修复 stats 路由 type 参数验证
- 优化分类排序为批量 SQL 更新
- 合并迁移和删除为数据库事务原子操作
- 修复交易和统计日期返回格式
- 新增自动备份功能(启动时备份)
---
client/src/App.vue | 13 +-
client/src/api/auth.ts | 17 +
client/src/api/budget.ts | 18 +
client/src/api/category.ts | 52 +++
client/src/api/index.ts | 5 +
client/src/api/stats.ts | 40 ++
client/src/api/transaction.ts | 69 ++++
.../components/ChartWrapper/ChartWrapper.vue | 105 ++++--
.../TransactionItem/TransactionItem.vue | 27 +-
client/src/pages/category-manage/index.vue | 342 ++++++++++++++----
client/src/pages/index/index.vue | 4 +-
client/src/pages/profile/index.vue | 4 +-
client/src/pages/stats/index.vue | 16 +-
client/src/stores/budget.ts | 22 +-
client/src/stores/category.ts | 43 ++-
client/src/stores/stats.ts | 47 +--
client/src/stores/transaction.ts | 60 ++-
client/src/utils/format.ts | 27 +-
server/.env.example | 9 +
server/src/index.ts | 13 +-
server/src/middleware/auth.ts | 2 +-
server/src/routes/backup.ts | 29 ++
server/src/routes/category.ts | 87 +++++
server/src/routes/stats.ts | 9 +-
server/src/routes/transaction.ts | 6 +-
server/src/utils/backup.ts | 100 +++++
26 files changed, 908 insertions(+), 258 deletions(-)
create mode 100644 client/src/api/auth.ts
create mode 100644 client/src/api/budget.ts
create mode 100644 client/src/api/category.ts
create mode 100644 client/src/api/index.ts
create mode 100644 client/src/api/stats.ts
create mode 100644 client/src/api/transaction.ts
create mode 100644 server/src/routes/backup.ts
create mode 100644 server/src/utils/backup.ts
diff --git a/client/src/App.vue b/client/src/App.vue
index b512a29..60fb3b0 100644
--- a/client/src/App.vue
+++ b/client/src/App.vue
@@ -1,6 +1,6 @@
@@ -87,5 +133,6 @@ watch(() => props.chartData, () => {
.chart-canvas {
display: block;
+ width: 100%;
}
diff --git a/client/src/components/TransactionItem/TransactionItem.vue b/client/src/components/TransactionItem/TransactionItem.vue
index b5b8a44..ab56da3 100644
--- a/client/src/components/TransactionItem/TransactionItem.vue
+++ b/client/src/components/TransactionItem/TransactionItem.vue
@@ -8,9 +8,12 @@
@touchmove="!disableSwipe && onTouchMove($event)"
@touchend="!disableSwipe && onTouchEnd()"
>
-
- {{ item.category_name?.[0] || '?' }}
-
+
{{ item.note || item.category_name || '未分类' }}
{{ item.category_name || '未分类' }}{{ hideDate ? '' : ' · ' + formatDate(item.date) }}
@@ -27,6 +30,7 @@
import { ref } from 'vue'
import { formatAmount, formatDate } from '@/utils/format'
import Icon from '@/components/Icon/Icon.vue'
+import CategoryIcon from '@/components/CategoryIcon/CategoryIcon.vue'
withDefaults(defineProps<{
item: {
@@ -84,7 +88,7 @@ function onTouchEnd() {
.tx-item {
display: flex;
align-items: center;
- padding: 28rpx 0;
+ padding: 28rpx 24rpx;
gap: 24rpx;
border-radius: 20rpx;
transition: transform 0.2s ease;
@@ -117,21 +121,6 @@ function onTouchEnd() {
}
}
-.icon-wrap {
- width: 80rpx;
- height: 80rpx;
- border-radius: 24rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- flex-shrink: 0;
-}
-
-.icon-text {
- font-size: 36rpx;
- font-weight: 600;
-}
-
.info {
flex: 1;
min-width: 0;
diff --git a/client/src/pages/category-manage/index.vue b/client/src/pages/category-manage/index.vue
index 3072362..b975755 100644
--- a/client/src/pages/category-manage/index.vue
+++ b/client/src/pages/category-manage/index.vue
@@ -20,51 +20,129 @@
-
+
{{ cat.name }}
自定义
-
-
+
+
+
+
+
+
+
-
- 添加自定义分类
-
-
+
+
+ +
+
+
+
+
+
+ 添加自定义分类
+
+
+
+
+
+ 取消
+ 添加
+
-
-
+
+
+
+
+
+ 编辑分类
+
+
+
+
+
+ 取消
+ 确定
+
+
+
+
+
+
+
+ 迁移记录
+ 「{{ deletingCat?.name }}」下有 {{ migrateCount }} 条记录,请选择迁移到:
+
+
+
+ {{ cat.name }}
+
+
+
+ 取消
+ 确认迁移并删除
+
- 添加