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:
@@ -3,10 +3,29 @@ export function formatAmount(fen: number): string {
|
||||
return '¥ ' + yuan.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
}
|
||||
|
||||
export function formatDate(date: string): string {
|
||||
// Parse YYYY-MM-DD as local time to avoid timezone off-by-one
|
||||
const parts = date.split('-').map(Number)
|
||||
const d = new Date(parts[0], parts[1] - 1, parts[2])
|
||||
export function formatDate(date: string | Date): string {
|
||||
if (!date) return ''
|
||||
|
||||
// 处理 Date 对象或 ISO 字符串
|
||||
let d: Date
|
||||
if (date instanceof Date) {
|
||||
d = date
|
||||
} else if (typeof date === 'string') {
|
||||
// 处理 YYYY-MM-DD 格式
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(date)) {
|
||||
const parts = date.split('-').map(Number)
|
||||
d = new Date(parts[0], parts[1] - 1, parts[2])
|
||||
} else {
|
||||
// 处理 ISO 字符串或其他格式
|
||||
d = new Date(date)
|
||||
}
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
|
||||
// 检查日期是否有效
|
||||
if (isNaN(d.getTime())) return ''
|
||||
|
||||
const now = new Date()
|
||||
// Reset time portion for accurate day diff
|
||||
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate())
|
||||
|
||||
Reference in New Issue
Block a user