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:
@@ -1,25 +1,19 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { request } from '@/utils/request'
|
||||
import * as api from '@/api/budget'
|
||||
import { getCurrentMonth } from '@/utils/format'
|
||||
|
||||
export interface Budget {
|
||||
id: number
|
||||
amount: number
|
||||
month: string
|
||||
}
|
||||
// 重新导出类型以保持向后兼容
|
||||
export type Budget = api.Budget
|
||||
|
||||
export const useBudgetStore = defineStore('budget', () => {
|
||||
const budget = ref<Budget | null>(null)
|
||||
const budget = ref<api.Budget | null>(null)
|
||||
const loading = ref(false)
|
||||
|
||||
async function fetchBudget(month?: string) {
|
||||
loading.value = true
|
||||
try {
|
||||
budget.value = await request<Budget>({
|
||||
url: '/budget',
|
||||
data: { month: month || getCurrentMonth() }
|
||||
})
|
||||
budget.value = await api.getBudget(month || getCurrentMonth())
|
||||
} catch {
|
||||
budget.value = null
|
||||
} finally {
|
||||
@@ -28,11 +22,7 @@ export const useBudgetStore = defineStore('budget', () => {
|
||||
}
|
||||
|
||||
async function setBudget(amount: number, month?: string) {
|
||||
await request({
|
||||
url: '/budget',
|
||||
method: 'POST',
|
||||
data: { amount, month: month || getCurrentMonth() }
|
||||
})
|
||||
await api.setBudget(amount, month || getCurrentMonth())
|
||||
await fetchBudget(month)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user