BUG-01: recurring /sync next_date 更新逻辑错误(应用循环后的 next) BUG-02: bills onReachBottom loading 缺 .value BUG-03: group store switchToPersonal 缺少 await (3处) OPT-04: notification requireNotificationEditAuth 加 try-catch OPT-05: category 迁移源分类条件改为 is_custom=1 AND user_id=? OPT-06: user 旧头像删除加 try-catch + 日志 CODE-02: format.ts 跨年日期显示年份 CODE-05: notification isValidUrl 去掉相对路径允许
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
export function formatAmount(fen: number): string {
|
||
const yuan = (fen / 100).toFixed(2)
|
||
return '¥ ' + yuan.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||
}
|
||
|
||
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())
|
||
const target = new Date(d.getFullYear(), d.getMonth(), d.getDate())
|
||
const diff = Math.floor((today.getTime() - target.getTime()) / 86400000)
|
||
|
||
if (diff === 0) return '今天'
|
||
if (diff === 1) return '昨天'
|
||
if (diff === 2) return '前天'
|
||
|
||
// 跨年显示年份
|
||
const isCurrentYear = d.getFullYear() === now.getFullYear()
|
||
return isCurrentYear
|
||
? `${d.getMonth() + 1}月${d.getDate()}日`
|
||
: `${d.getFullYear()}年${d.getMonth() + 1}月${d.getDate()}日`
|
||
}
|
||
|
||
export function formatMonth(date: string): string {
|
||
const [year, month] = date.split('-')
|
||
return `${year}年${parseInt(month)}月`
|
||
}
|
||
|
||
/** 获取当前月份(UTC+8 时区,与服务端保持一致) */
|
||
export function getCurrentMonth(): string {
|
||
const d = new Date()
|
||
const offset = 8 * 60 * 60 * 1000
|
||
const local = new Date(d.getTime() + offset)
|
||
return local.toISOString().slice(0, 7)
|
||
}
|
||
|
||
export function formatAmountRaw(fen: number): string {
|
||
const yuan = (fen / 100).toFixed(2)
|
||
return yuan.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||
}
|
||
|