Skip to content

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

@imdap

Description

@imdap
  • 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安全数会造成丢失精度问题

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions