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

🐛[BUG]🐛[BUG] ProFormUploadButton组件 发送请求 是 list,应该需要string #8984

Closed
huasiyue opened this issue Jan 18, 2025 · 2 comments

Comments

@huasiyue
Copy link

提问前先看看:

https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md

🐛 bug 描述

ProFormUploadButton组件 发送请求 是 list,应该需要string

📷 复现步骤

前端请求json

{
  "id": "678914eedffc2e74c77ad233",
  "avatar": "678914e5dffc2e74c77ad21d",
  "createDate": "2025-01-16T14:17:18.414+00:00",
  "lastModifiedDate": "2025-01-16T14:17:18.414+00:00",
  "name": "4444",
  "portrait": [
    {
      "uid": "rc-upload-1737138388894-7",
      "lastModified": 1736482202038,
      "lastModifiedDate": "2025-01-10T04:10:02.038Z",
      "name": "zk.png",
      "originFileObj": {
        "uid": "rc-upload-1737138388894-7"
      },
      "percent": 100,
      "response": "678aa137ddf4300658100410",
      "size": 289107,
      "status": "done",
      "thumbUrl": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMg",
      "type": "image/png",
      "uid": "rc-upload-1737138388894-7",
      "xhr": {}
    }
  ]
}

相关代码

<ProFormUploadButton
      readonly={readonly}
      name="portrait"
      label={<FormattedMessage id={'portrait'} />}
      max={1}
      // initialValue={value}
      // valuePropName="file"
      listType='picture-card'
      accept='image/*'
      action={`${API_URL}/files/upload`}
      fieldProps={{
        headers: { 'labic-token': localStorage.getItem(TOKEN_KEY) || '' },
        maxCount: 1,
      }}
      onChange={(info) => {
        if (info.file.status === 'uploading') {
          return;
        }
        if (info.file.status === 'done') {
          if (info.file.response === 'Failed') {
            info.file.status = 'error'
            return
          }
        }

      }}
    />

🏞 期望结果

前端发送请求"portrait":678aa137ddf4300658100410

💻 复现代码

© 版本信息

  • ProComponents 版本: [e.g. "2.31.2"]
  • umi 版本
  • 浏览器环境
  • 开发环境 [e.g. windows]

🚑 其他信息

Copy link

以下的 Issues 可能会帮助到你 / The following issues may help you

@huasiyue
Copy link
Author

getValueFromEvent={(e) => {
                  if (Array.isArray(e?.fileList) && e.fileList[0]?.response) {
                    return e.fileList[0].response; // 提取 fileId
                  }
                  return initValue;
                }}

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

1 participant