fix(core): 解决ID字段精度丢失和账户ID为空问题
- 在前端请求处理中添加convertIdsToString函数,将超过安全范围的数字转换为字符串 - 使用json-bigint库处理大数字序列化,防止精度丢失 - 在医嘱保存逻辑中确保accountId不为null,自动创建自费账户 - 添加IAccountService依赖注入支持账户操作 - 在产品转移详情DTO中添加@TableField注解标识非数据库字段
This commit is contained in:
@@ -11,6 +11,38 @@ import JSONBig from 'json-bigint'
|
||||
// 初始化json-bigint,配置大数字转字符串(关键:storeAsString: true)
|
||||
const jsonBig = JSONBig({ storeAsString: true })
|
||||
|
||||
// 🔧 Bug Fix #281: 转换所有ID字段为字符串,防止BigInt精度丢失
|
||||
const convertIdsToString = (obj) => {
|
||||
if (obj === null || obj === undefined) return obj
|
||||
|
||||
if (typeof obj === 'number' && obj > 9007199254740991) {
|
||||
// 如果是超过安全范围的数字,转为字符串
|
||||
return String(obj)
|
||||
}
|
||||
|
||||
if (typeof obj === 'object') {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(item => convertIdsToString(item))
|
||||
} else {
|
||||
const newObj = {}
|
||||
for (const key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
const value = obj[key]
|
||||
// 如果key以Id结尾或者是id,且值是数字,转为字符串
|
||||
if ((key === 'id' || key.endsWith('Id') || key.endsWith('ID')) && typeof value === 'number') {
|
||||
newObj[key] = String(value)
|
||||
} else {
|
||||
newObj[key] = convertIdsToString(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
return newObj
|
||||
}
|
||||
}
|
||||
|
||||
return obj
|
||||
}
|
||||
|
||||
let downloadLoadingInstance;
|
||||
// 是否显示重新登录
|
||||
export let isRelogin = { show: false };
|
||||
@@ -35,16 +67,23 @@ const service = axios.create({
|
||||
}
|
||||
}
|
||||
],
|
||||
// 可选:请求体序列化,无需额外处理,默认即可(保留也不影响)
|
||||
// 可选:请求体序列化,使用json-bigint处理大数字
|
||||
transformRequest: [
|
||||
function (data) {
|
||||
return JSON.stringify(data)
|
||||
if (!data) return data
|
||||
// 🔧 Bug Fix #281: 使用json-bigint序列化,保留大数字精度
|
||||
return jsonBig.stringify(data)
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
// request拦截器
|
||||
service.interceptors.request.use(config => {
|
||||
// 🔧 Bug Fix #281: 转换请求数据中的ID字段为字符串
|
||||
if (config.data && typeof config.data === 'object') {
|
||||
config.data = convertIdsToString(config.data)
|
||||
}
|
||||
|
||||
// 是否需要设置 token
|
||||
const isToken = (config.headers || {}).isToken === false
|
||||
// 是否需要防止数据重复提交
|
||||
@@ -62,10 +101,11 @@ service.interceptors.request.use(config => {
|
||||
if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
|
||||
const requestObj = {
|
||||
url: config.url,
|
||||
data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
|
||||
data: typeof config.data === 'object' ? jsonBig.stringify(config.data) : config.data,
|
||||
time: new Date().getTime()
|
||||
}
|
||||
const requestSize = Object.keys(JSON.stringify(requestObj)).length; // 请求数据大小
|
||||
// 🔧 Bug Fix #281: 使用json-bigint计算大小
|
||||
const requestSize = Object.keys(jsonBig.stringify(requestObj)).length; // 请求数据大小
|
||||
const limitSize = 5 * 1024 * 1024; // 限制存放数据5M
|
||||
if (requestSize >= limitSize) {
|
||||
console.warn(`[${config.url}]: ` + '请求数据大小超出允许的5M限制,无法进行防重复提交验证。')
|
||||
|
||||
Reference in New Issue
Block a user