refactor: API 请求整合与 Bug 修复

前端重构:
- 新增 api/ 目录统一管理所有 API 请求
- 所有 stores 和 pages 改为使用 api 模块
- 修复日期格式化函数,支持 Date 对象和 ISO 字符串
- 修复 TransactionItem 使用 CategoryIcon 组件
- 优化 ChartWrapper 区分 H5 和小程序环境

后端修复:
- 修复 auth 中间件 PUBLIC_PATHS 缺少 demo-login
- 修复备份工具命令注入漏洞,改用 execFile
- 修复 stats 路由 type 参数验证
- 优化分类排序为批量 SQL 更新
- 合并迁移和删除为数据库事务原子操作
- 修复交易和统计日期返回格式
- 新增自动备份功能(启动时备份)
This commit is contained in:
2026-06-02 17:41:35 +08:00
parent d5e5655b88
commit db81ad8eb2
26 changed files with 908 additions and 258 deletions

View File

@@ -1,6 +1,6 @@
<script setup lang="ts">
import { onLaunch } from '@dcloudio/uni-app'
import { request } from '@/utils/request'
import { wxLogin, demoLogin } from '@/api/auth'
onLaunch(() => {
// #ifdef MP-WEIXIN
@@ -9,11 +9,7 @@ onLaunch(() => {
success: async (loginRes) => {
if (loginRes.code) {
try {
const data = await request<{ token: string; userId: number }>({
url: '/auth/login',
method: 'POST',
data: { code: loginRes.code }
})
const data = await wxLogin(loginRes.code)
uni.setStorageSync('xc:token', data.token)
uni.setStorageSync('xc:userId', data.userId)
console.log('[Auth] Login success')
@@ -29,10 +25,7 @@ onLaunch(() => {
const token = uni.getStorageSync('xc:token')
if (!token) {
// 同步等待 token避免页面首次请求因无 token 而 401
request<{ token: string; userId: number }>({
url: '/auth/demo-login',
method: 'POST'
}).then((data) => {
demoLogin().then((data) => {
uni.setStorageSync('xc:token', data.token)
uni.setStorageSync('xc:userId', data.userId)
console.log('[Auth] H5 demo login success')