Skip to content

Commit b6b37cc

Browse files
gbinianzhenxiao.guo
andauthored
[upload]增加格式错误信息可配置 (#714)
Co-authored-by: zhenxiao.guo <zhenxiao.guo@shuyun.com>
1 parent 90e7c8d commit b6b37cc

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/components/upload/demos/picture.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default class UploadDemo extends React.Component {
2222
render() {
2323
const props = {
2424
accept: 'image/*',
25+
acceptErrorTip: '只能上传图片格式',
2526
labelText: 'Upload',
2627
action: '/upload',
2728
type: 'picture',

src/components/upload/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ class Upload extends Component {
228228
*/
229229
async handleBeforeUpload(file) {
230230
const {
231-
size, unit, accept, onBeforeUpload,
231+
size, unit, accept, onBeforeUpload, acceptErrorTip
232232
} = this.props;
233233

234234
let isSizeInvalidate;
@@ -251,7 +251,7 @@ class Upload extends Component {
251251
const fileNames = file.name.split('.') || [];
252252
const fileType = `.${fileNames[fileNames.length - 1]}`;
253253
if (!accept.includes(file.type) && !accept.includes(fileType)) {
254-
Message.error(`仅支持上传${accept}格式的文件`);
254+
Message.error(acceptErrorTip ? acceptErrorTip : `仅支持上传${accept}格式的文件`);
255255
this.ref.current.value = '';
256256
return false;
257257
}
@@ -492,6 +492,7 @@ Upload.propTypes = {
492492
className: PropTypes.string,
493493
unify: PropTypes.bool,
494494
params: PropTypes.object,
495+
acceptErrorTip: PropTypes.string,
495496
};
496497

497498
Upload.defaultProps = {

src/components/upload/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ group:
4747
| onRemove | 删除已上传列表的文件 | func | |
4848
| className | 外部控制样式 | string | |
4949
| params | FormData 中的额外参数 | object | {} |
50+
| acceptErrorTip | 格式校验失败的提示文案 | string | |
5051

5152
#### filelist 中的 File 对象
5253

0 commit comments

Comments
 (0)