diff --git a/package.json b/package.json index 53758d8f1..a5dad381b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-impression", - "version": "0.5.0", + "version": "0.5.1", "author": "peter.shenlq", "description": "An enterprise-class UI design language and React-based implementation.", "main": "./lib/index.js", diff --git a/site/src/scripts/components/impression/components/Upload.js b/site/src/scripts/components/impression/components/Upload.js index 5e1d722bb..77839c68e 100644 --- a/site/src/scripts/components/impression/components/Upload.js +++ b/site/src/scripts/components/impression/components/Upload.js @@ -16,6 +16,7 @@ export default class Upload extends PureComponent { message: PropTypes.string, src: PropTypes.string, children: PropTypes.any, + onChange: PropTypes.func, } // 默认props static defaultProps = { @@ -42,16 +43,21 @@ export default class Upload extends PureComponent { * 设置文件名. */ fileChangeHandle = event => { + let { onChange } = this.props; + this.setState({ file: event.target.value, }); + + onChange && onChange(event); } /** * 图片预览处理. * @param {[Event]} event [事件] */ imagePreviewHandle = event => { - let file = event.target.files[0], + let { onChange } = this.props, + file = event.target.files[0], reader = new FileReader(); if (file) { @@ -63,6 +69,7 @@ export default class Upload extends PureComponent { } reader.readAsDataURL(file); + onChange && onChange(event); } // 渲染 render() { diff --git a/src/scripts/components/Upload.js b/src/scripts/components/Upload.js index 5e1d722bb..77839c68e 100644 --- a/src/scripts/components/Upload.js +++ b/src/scripts/components/Upload.js @@ -16,6 +16,7 @@ export default class Upload extends PureComponent { message: PropTypes.string, src: PropTypes.string, children: PropTypes.any, + onChange: PropTypes.func, } // 默认props static defaultProps = { @@ -42,16 +43,21 @@ export default class Upload extends PureComponent { * 设置文件名. */ fileChangeHandle = event => { + let { onChange } = this.props; + this.setState({ file: event.target.value, }); + + onChange && onChange(event); } /** * 图片预览处理. * @param {[Event]} event [事件] */ imagePreviewHandle = event => { - let file = event.target.files[0], + let { onChange } = this.props, + file = event.target.files[0], reader = new FileReader(); if (file) { @@ -63,6 +69,7 @@ export default class Upload extends PureComponent { } reader.readAsDataURL(file); + onChange && onChange(event); } // 渲染 render() {