fix:前端 safeJsonParse 解决大整数精度丢失问题
This commit is contained in:
parent
2ad1316c92
commit
6bcfacd2d1
34
utils/api.js
34
utils/api.js
@ -360,6 +360,18 @@ function buildFormBodyWithImages(params, imageUrls, imageKey) {
|
||||
|
||||
export { buildFormBodyWithImages }
|
||||
|
||||
/**
|
||||
* 安全解析 JSON,将超出 JS 安全整数范围的数字转为字符串
|
||||
*/
|
||||
function safeJsonParse(text) {
|
||||
return JSON.parse(text, function(key, value) {
|
||||
if (typeof value === 'number' && !Number.isSafeInteger(value)) {
|
||||
return String(value)
|
||||
}
|
||||
return value
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取店铺列表(上书记录用)
|
||||
* @param {Object} params - { pageNum, pageSize, shop_type }
|
||||
@ -372,13 +384,15 @@ export function getShopList(params = {}) {
|
||||
uni.request({
|
||||
url: url,
|
||||
method: 'GET',
|
||||
dataType: 'text',
|
||||
header: {
|
||||
'Authorization': 'Bearer ' + token
|
||||
},
|
||||
success: (res) => {
|
||||
console.log('【店铺列表】响应:', JSON.stringify(res.data))
|
||||
if (res.statusCode === 200 && res.data && res.data.code === 0) {
|
||||
resolve(res.data.data)
|
||||
var data = typeof res.data === 'string' ? safeJsonParse(res.data) : res.data
|
||||
console.log('【店铺列表】响应:', JSON.stringify(data))
|
||||
if (res.statusCode === 200 && data && data.code === 0) {
|
||||
resolve(data.data)
|
||||
} else {
|
||||
resolve({ list: [], total: 0 })
|
||||
}
|
||||
@ -404,16 +418,18 @@ export function getShopDetail(params = {}) {
|
||||
uni.request({
|
||||
url: url,
|
||||
method: 'GET',
|
||||
dataType: 'text',
|
||||
header: {
|
||||
'Authorization': 'Bearer ' + token
|
||||
},
|
||||
success: (res) => {
|
||||
console.log('【上书详情】响应:', JSON.stringify(res.data))
|
||||
if (res.statusCode === 200 && res.data) {
|
||||
if (res.data.code === 200 && res.data.data) {
|
||||
resolve(res.data.data)
|
||||
} else if (res.data.data) {
|
||||
resolve(res.data.data)
|
||||
var data = typeof res.data === 'string' ? safeJsonParse(res.data) : res.data
|
||||
console.log('【上书详情】响应:', JSON.stringify(data))
|
||||
if (res.statusCode === 200 && data) {
|
||||
if (data.code === 200 && data.data) {
|
||||
resolve(data.data)
|
||||
} else if (data.data) {
|
||||
resolve(data.data)
|
||||
} else {
|
||||
resolve({ products: [], total: 0, page: 1, page_size: 10 })
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user