新增json-bigint库,防止后端返回id数过大导致精度丢失

This commit is contained in:
hr121 2025-07-18 18:06:03 +08:00
parent 5abfccd598
commit b37d26ad62
2 changed files with 13 additions and 1 deletions

View File

@ -46,6 +46,7 @@
"js-beautify": "^1.10.2", "js-beautify": "^1.10.2",
"js-cookie": "2.2.0", "js-cookie": "2.2.0",
"jsencrypt": "^3.0.0-rc.1", "jsencrypt": "^3.0.0-rc.1",
"json-bigint": "^1.0.0",
"jszip": "^3.7.1", "jszip": "^3.7.1",
"mavon-editor": "^2.9.1", "mavon-editor": "^2.9.1",
"normalize.css": "7.0.0", "normalize.css": "7.0.0",

View File

@ -5,11 +5,21 @@ import store from '../store'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import Config from '@/settings' import Config from '@/settings'
import Cookies from 'js-cookie' import Cookies from 'js-cookie'
import JSONbig from 'json-bigint'
// 创建axios实例 // 创建axios实例
const service = axios.create({ const service = axios.create({
baseURL: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_BASE_API : '/', // api 的 base_url baseURL: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_BASE_API : '/', // api 的 base_url
timeout: Config.timeout // 请求超时时间 timeout: Config.timeout, // 请求超时时间
transformResponse: [function(data) {
try {
// 使用json-bigint处理大数字
return JSONbig.parse(data)
} catch (err) {
// 如果转换失败,返回原始数据
return data
}
}]
}) })
// request拦截器 // request拦截器
@ -26,6 +36,7 @@ service.interceptors.request.use(
} }
) )
// response 拦截器 // response 拦截器
service.interceptors.response.use( service.interceptors.response.use(
response => { response => {