feat: upload add crossOrigin

pull/5820/head
tangjinzhou 3 years ago
parent 8ad9317d11
commit 40a65d19da

@ -315,6 +315,7 @@ export default defineComponent({
typeof showUploadList === 'boolean' ? ({} as ShowUploadListInterface) : showUploadList; typeof showUploadList === 'boolean' ? ({} as ShowUploadListInterface) : showUploadList;
return showUploadList ? ( return showUploadList ? (
<UploadList <UploadList
prefixCls={prefixCls.value}
listType={props.listType} listType={props.listType}
items={mergedFileList.value} items={mergedFileList.value}
previewFile={previewFile} previewFile={previewFile}

@ -110,6 +110,7 @@ export default defineComponent({
src={file.thumbUrl || file.url} src={file.thumbUrl || file.url}
alt={file.name} alt={file.name}
class={`${prefixCls}-list-item-image`} class={`${prefixCls}-list-item-image`}
crossOrigin={file.crossOrigin}
/> />
) : ( ) : (
iconNode iconNode

@ -63,14 +63,15 @@ Uploading is the process of publishing information (web pages, text, pictures, v
Extends File with additional props. Extends File with additional props.
| Property | Description | Type | Default | | Property | Description | Type | Default | Version |
| --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| name | File name | string | - | | crossOrigin | CORS settings attributes | `'anonymous'` \| `'use-credentials'` \| `''` | - | 3.3.0 |
| percent | Upload progress percent | number | - | | name | File name | string | - | |
| status | Upload status. Show different style when configured | `error` \| `success` \| `done` \| `uploading` \| `removed` | - | | percent | Upload progress percent | number | - | |
| thumbUrl | Thumb image url | string | - | | status | Upload status. Show different style when configured | `error` \| `success` \| `done` \| `uploading` \| `removed` | - | |
| uid | unique id. Will auto generate when not provided | string | - | | thumbUrl | Thumb image url | string | - | |
| url | Download url | string | - | | uid | unique id. Will auto generate when not provided | string | - | |
| url | Download url | string | - | |
### change ### change
@ -125,3 +126,11 @@ See <https://github.com/react-component/upload#customrequest>.
### Why does `change` sometimes return File object and other times return { originFileObj: File }? ### Why does `change` sometimes return File object and other times return { originFileObj: File }?
For compatible case, we return File object when `beforeUpload` return `false`. It will merge to `{ originFileObj: File }` in next major version. Current version is compatible to get origin file by `info.file.originFileObj`. You can change this before major release. For compatible case, we return File object when `beforeUpload` return `false`. It will merge to `{ originFileObj: File }` in next major version. Current version is compatible to get origin file by `info.file.originFileObj`. You can change this before major release.
### Why sometime Chrome can not upload?
Chrome update will also break native upload. Please restart chrome to finish the upload work. Ref:
- [#32672](https://github.com/ant-design/ant-design/issues/32672)
- [#32913](https://github.com/ant-design/ant-design/issues/32913)
- [#33988](https://github.com/ant-design/ant-design/issues/33988)

@ -64,14 +64,15 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
继承自 File附带额外属性用于渲染。 继承自 File附带额外属性用于渲染。
| 参数 | 说明 | 类型 | 默认值 | | 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | | --- | --- | --- | --- | --- |
| name | 文件名 | string | - | | crossOrigin | CORS 属性设置 | `'anonymous'` \| `'use-credentials'` \| `''` | - | 3.3.0 |
| percent | 上传进度 | number | - | | name | 文件名 | string | - | - |
| status | 上传状态,不同状态展示颜色也会有所不同 | `error` \| `success` \| `done` \| `uploading` \| `removed` | - | | percent | 上传进度 | number | - | - |
| thumbUrl | 缩略图地址 | string | - | | status | 上传状态,不同状态展示颜色也会有所不同 | `error` \| `success` \| `done` \| `uploading` \| `removed` | - | - |
| uid | 唯一标识符,不设置时会自动生成 | string | - | | thumbUrl | 缩略图地址 | string | - | - |
| url | 下载地址 | string | - | | uid | 唯一标识符,不设置时会自动生成 | string | - | - |
| url | 下载地址 | string | - | - |
### change ### change
@ -126,3 +127,11 @@ cover: https://gw.alipayobjects.com/zos/alicdn/QaeBt_ZMg/Upload.svg
### `onChange` 为什么有时候返回 File 有时候返回 { originFileObj: File } ### `onChange` 为什么有时候返回 File 有时候返回 { originFileObj: File }
历史原因,在 `beforeUpload` 返回 `false` 时,会返回 File 对象。在下个大版本我们会统一返回 `{ originFileObj: File }` 对象。当前版本已经兼容所有场景下 `info.file.originFileObj` 获取原 File 写法。你可以提前切换。 历史原因,在 `beforeUpload` 返回 `false` 时,会返回 File 对象。在下个大版本我们会统一返回 `{ originFileObj: File }` 对象。当前版本已经兼容所有场景下 `info.file.originFileObj` 获取原 File 写法。你可以提前切换。
### 为何有时 Chrome 点击 Upload 无法弹出文件选择框?
与 antd 无关,原生上传也会失败。请重启 Chrome 浏览器,让其完成升级工作。相关 issue
- [#32672](https://github.com/ant-design/ant-design/issues/32672)
- [#32913](https://github.com/ant-design/ant-design/issues/32913)
- [#33988](https://github.com/ant-design/ant-design/issues/33988)

@ -27,6 +27,7 @@ export interface UploadFile<T = any> {
status?: UploadFileStatus; status?: UploadFileStatus;
percent?: number; percent?: number;
thumbUrl?: string; thumbUrl?: string;
crossOrigin?: HTMLImageElement['crossOrigin'];
originFileObj?: FileType; originFileObj?: FileType;
response?: T; response?: T;
error?: any; error?: any;
@ -49,7 +50,7 @@ export interface ShowUploadListInterface {
export interface UploadChangeParam<T = UploadFile> { export interface UploadChangeParam<T = UploadFile> {
// https://github.com/ant-design/ant-design/issues/14420 // https://github.com/ant-design/ant-design/issues/14420
file: T; file: T;
fileList: UploadFile[]; fileList: T[];
event?: { percent: number }; event?: { percent: number };
} }

@ -168,9 +168,11 @@
&-btn { &-btn {
opacity: 0; opacity: 0;
} }
&-btn.@{ant-prefix}-btn-sm { &-btn.@{ant-prefix}-btn-sm {
height: 20px; height: @line-height-base * @font-size-base;
line-height: 1; line-height: 1;
vertical-align: top;
} }
&.picture { &.picture {
@ -185,12 +187,16 @@
.@{iconfont-css-prefix} { .@{iconfont-css-prefix} {
color: @upload-actions-color; color: @upload-actions-color;
transition: all 0.3s;
}
&:hover .@{iconfont-css-prefix} {
color: @text-color;
} }
} }
&-info { &-info {
height: 100%; height: 100%;
padding: 0 4px;
transition: background-color 0.3s; transition: background-color 0.3s;
> span { > span {
@ -210,30 +216,10 @@
} }
} }
.@{iconfont-css-prefix}-close {
position: absolute;
top: 6px;
right: 4px;
color: @text-color-secondary;
font-size: 10px;
line-height: 0;
cursor: pointer;
opacity: 0;
transition: all 0.3s;
&:hover {
color: @text-color;
}
}
&:hover &-info { &:hover &-info {
background-color: @item-hover-bg; background-color: @item-hover-bg;
} }
&:hover .@{iconfont-css-prefix}-close {
opacity: 1;
}
&:hover &-card-actions-btn { &:hover &-card-actions-btn {
opacity: 1; opacity: 1;
} }
@ -369,14 +355,6 @@
margin-top: 0; margin-top: 0;
padding-left: 56px; padding-left: 56px;
} }
.@{iconfont-css-prefix}-close {
position: absolute;
top: 8px;
right: 8px;
line-height: 1;
opacity: 1;
}
} }
// ======================== Picture Card ======================== // ======================== Picture Card ========================
@ -389,10 +367,6 @@
vertical-align: top; vertical-align: top;
} }
&.@{upload-prefix-cls}-list::after {
display: none;
}
.@{upload-item} { .@{upload-item} {
height: 100%; height: 100%;
margin: 0; margin: 0;

@ -2,6 +2,7 @@ import '../../style/index.less';
import './index.less'; import './index.less';
// style dependencies // style dependencies
// deps-lint-skip: form
import '../../button/style'; import '../../button/style';
import '../../progress/style'; import '../../progress/style';
import '../../tooltip/style'; import '../../tooltip/style';

@ -72,13 +72,6 @@
} }
} }
.@{iconfont-css-prefix}-close {
.@{upload-prefix-cls}-list-rtl & {
right: auto;
left: 4px;
}
}
&-error &-card-actions { &-error &-card-actions {
.@{iconfont-css-prefix} { .@{iconfont-css-prefix} {
.@{upload-prefix-cls}-list-rtl & { .@{upload-prefix-cls}-list-rtl & {
@ -145,13 +138,6 @@
padding-left: 0; padding-left: 0;
} }
} }
.@{iconfont-css-prefix}-close {
.@{upload-prefix-cls}-list-rtl& {
right: auto;
left: 8px;
}
}
} }
&-picture-card { &-picture-card {

Loading…
Cancel
Save