Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wanjj_1210
ant-design
提交
7843fda1
A
ant-design
项目概览
wanjj_1210
/
ant-design
与 Fork 源项目一致
从无法访问的项目Fork
通知
10
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
ant-design
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7843fda1
编写于
12月 28, 2015
作者:
A
afc163
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #759 from ant-design/fix-upload
fix: uploadList should under the controll of beforeUpload #757
上级
a3704c1d
5699e61f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
0 deletion
+43
-0
components/upload/demo/beforeUpload.md
components/upload/demo/beforeUpload.md
+30
-0
components/upload/index.jsx
components/upload/index.jsx
+12
-0
components/upload/index.md
components/upload/index.md
+1
-0
未找到文件。
components/upload/demo/beforeUpload.md
0 → 100644
浏览文件 @
7843fda1
# 限制用户上传的文件
-
order: 7
可以通过
`beforeUpload`
在文件上传之前进行干预,如限制用户只能上传 JPG 文件。
---
````
jsx
import
{
Upload
,
Button
,
Icon
,
message
}
from
'
antd
'
;
const
props
=
{
action
:
'
/upload.do
'
,
beforeUpload
:
function
(
file
)
{
const
isJPG
=
file
.
type
===
'
image/jpeg
'
;
if
(
!
isJPG
)
{
message
.
error
(
'
只能上传 JPG 文件哦!
'
);
}
return
isJPG
;
}
};
ReactDOM
.
render
(
<
Upload
{
...
props
}
>
<
Button
type
=
"ghost"
>
<
Icon
type
=
"upload"
/>
点击上传
</
Button
>
</
Upload
>
,
document
.
getElementById
(
'
components-upload-demo-beforeupload
'
));
````
components/upload/index.jsx
浏览文件 @
7843fda1
...
...
@@ -8,6 +8,10 @@ const prefixCls = 'ant-upload';
function
noop
()
{
}
function
T
()
{
return
true
;
}
// Fix IE file.status problem
// via coping a new Object
function
fileToObject
(
file
)
{
...
...
@@ -55,6 +59,8 @@ const AntUpload = React.createClass({
};
},
onStart
(
file
)
{
if
(
this
.
recentUploadStatus
===
false
)
return
;
let
targetItem
;
let
nextFileList
=
this
.
state
.
fileList
.
concat
();
if
(
file
.
length
>
0
)
{
...
...
@@ -142,6 +148,10 @@ const AntUpload = React.createClass({
targetItem
.
status
=
'
error
'
;
this
.
handleRemove
(
targetItem
);
},
beforeUpload
(
file
)
{
this
.
recentUploadStatus
=
this
.
props
.
beforeUpload
(
file
);
return
this
.
recentUploadStatus
;
},
handleRemove
(
file
)
{
let
fileList
=
this
.
removeFile
(
file
);
if
(
fileList
)
{
...
...
@@ -170,6 +180,7 @@ const AntUpload = React.createClass({
data
:
{},
accept
:
''
,
onChange
:
noop
,
beforeUpload
:
T
,
showUploadList
:
true
,
listType
:
'
text
'
,
// or pictrue
className
:
''
,
...
...
@@ -197,6 +208,7 @@ const AntUpload = React.createClass({
onError
:
this
.
onError
,
onProgress
:
this
.
onProgress
,
onSuccess
:
this
.
onSuccess
,
beforeUpload
:
this
.
beforeUpload
,
});
let
uploadList
;
if
(
this
.
props
.
showUploadList
)
{
...
...
components/upload/index.md
浏览文件 @
7843fda1
...
...
@@ -26,6 +26,7 @@
| showUploadList | 可选参数, 是否展示 uploadList, 默认开启 | Boolean | true |
| multiple | 可选参数, 是否支持多选文件,支持
`ie10+`
| Boolean | false |
| accept | 可选参数, 接受上传的文件类型, 详见 input accept Attribute | String | 无 |
| beforeUpload | 可选参数, 上传文件之前的钩子,参数为上传的文件,若返回
`false`
或者 Promise 则停止上传。
**注意:该方法不支持老 IE**
。 | Function | 无 |
| onChange | 可选参数, 上传文件改变时的状态,详见 onChange | Function | 无 |
| listType | 上传列表的内建样式,支持两种基本样式
`text`
or
`picture`
| String | 'text'|
| className | 自定义类名 | String | 无 |
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录