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 }
|
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 }
|
* @param {Object} params - { pageNum, pageSize, shop_type }
|
||||||
@ -372,13 +384,15 @@ export function getShopList(params = {}) {
|
|||||||
uni.request({
|
uni.request({
|
||||||
url: url,
|
url: url,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
dataType: 'text',
|
||||||
header: {
|
header: {
|
||||||
'Authorization': 'Bearer ' + token
|
'Authorization': 'Bearer ' + token
|
||||||
},
|
},
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('【店铺列表】响应:', JSON.stringify(res.data))
|
var data = typeof res.data === 'string' ? safeJsonParse(res.data) : res.data
|
||||||
if (res.statusCode === 200 && res.data && res.data.code === 0) {
|
console.log('【店铺列表】响应:', JSON.stringify(data))
|
||||||
resolve(res.data.data)
|
if (res.statusCode === 200 && data && data.code === 0) {
|
||||||
|
resolve(data.data)
|
||||||
} else {
|
} else {
|
||||||
resolve({ list: [], total: 0 })
|
resolve({ list: [], total: 0 })
|
||||||
}
|
}
|
||||||
@ -404,16 +418,18 @@ export function getShopDetail(params = {}) {
|
|||||||
uni.request({
|
uni.request({
|
||||||
url: url,
|
url: url,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
dataType: 'text',
|
||||||
header: {
|
header: {
|
||||||
'Authorization': 'Bearer ' + token
|
'Authorization': 'Bearer ' + token
|
||||||
},
|
},
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
console.log('【上书详情】响应:', JSON.stringify(res.data))
|
var data = typeof res.data === 'string' ? safeJsonParse(res.data) : res.data
|
||||||
if (res.statusCode === 200 && res.data) {
|
console.log('【上书详情】响应:', JSON.stringify(data))
|
||||||
if (res.data.code === 200 && res.data.data) {
|
if (res.statusCode === 200 && data) {
|
||||||
resolve(res.data.data)
|
if (data.code === 200 && data.data) {
|
||||||
} else if (res.data.data) {
|
resolve(data.data)
|
||||||
resolve(res.data.data)
|
} else if (data.data) {
|
||||||
|
resolve(data.data)
|
||||||
} else {
|
} else {
|
||||||
resolve({ products: [], total: 0, page: 1, page_size: 10 })
|
resolve({ products: [], total: 0, page: 1, page_size: 10 })
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user