Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

文件上传的onSuccess方法会将后端返回的String类型数字转为Number造成精度丢失 #7780

Closed
1 task done
imdap opened this issue Aug 10, 2024 · 1 comment

Comments

@imdap
Copy link

imdap commented Aug 10, 2024

  • I have searched the issues of this repository and believe that this is not a duplicate.

Version

4.2.3

Environment

windows11 node20 antdv4.2.3

Reproduction link

https://www.antdv.com/components/upload-cn#customrequest-%E6%80%8E%E4%B9%88%E4%BD%BF%E7%94%A8%EF%BC%9F

Steps to reproduce

使用自定义上传customRequest并且调用onSuccess方法 传入字符串(比如雪花ID)

async function customRequest(info: UploadRequestOption) {
info.onSucess('12345678901234567890')
}

What is expected?

不被转换为Number 实际应该为String

What is actually happening?

字符串被转换为Number类型 如果超过js安全数会丢失精度
源码位置:https://github.com/vueComponent/ant-design-vue/blob/main/components/upload/Upload.tsx#L198

const onSuccess = (response: any, file: FileType, xhr: any) => {
try {
if (typeof response === 'string') {
response = JSON.parse(response);
}
} catch (e) {
/* do nothing */
}
...省略
};

传入为string会走JSON.parse逻辑 会将String转为Number

8cec35f555713af3e26ad5567b7c10f

比如后端返回为雪花ID 超过js安全数会造成丢失精度问题

@cc-hearts
Copy link
Contributor

业务层的数据精度应该由业务层自行处理

@imdap imdap closed this as completed Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants