refactor: 重构存储与接口适配,统一金额单位与会话管理

- 新增配置、存储、金额转换工具服务
- 按userId隔离本地缓存,替换旧设备级存储
- 统一移动端金额单位为万元,新增转换适配逻辑
- 重构认证与请求逻辑,支持真实后端会话
- 调整搜索、帮助、融资模块的模拟开关与数据适配
- 更新文档说明开发状态与配置规则
This commit is contained in:
hujun
2026-09-22 17:25:52 +08:00
parent 4a69357606
commit dcf12a4471
25 changed files with 1619 additions and 143 deletions
+30
View File
@@ -0,0 +1,30 @@
// 金额转换使用整数分,避免万元与元之间的浮点乘法误差。
export function wanAmountValid(value: string): boolean {
if (!/^[0-9]{1,5}([.][0-9]{1,6})?$/.test(value)) return false
return wanToCents(value) <= 99999999999
}
export function wanToCents(value: string): number {
const parts = value.split('.')
const fraction = parts.length > 1 ? parts[1] : ''
return parseInt(parts[0]) * 1000000 + parseInt((fraction + '000000').substring(0, 6))
}
export function wanToYuan(value: string): string {
if (!wanAmountValid(value)) throw new Error('金额范围为 0–99999.999999 万元,最多六位小数')
const cents = wanToCents(value)
const fraction = (cents % 100).toString()
return Math.floor(cents / 100).toString() + '.' + (fraction.length == 1 ? '0' + fraction : fraction)
}
export function yuanToWan(value: string): string {
if (value.length == 0) return ''
if (!/^[0-9]+([.][0-9]{1,2})?$/.test(value)) return value
const parts = value.split('.')
const fraction = parts.length > 1 ? parts[1] : ''
const digits = parts[0] + (fraction + '00').substring(0, 2)
const padded = '000000' + digits
const whole = parseInt(padded.substring(0, padded.length - 6)).toString()
const decimal = padded.substring(padded.length - 6).replace(/0+$/, '')
return whole + (decimal.length > 0 ? '.' + decimal : '')
}