Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
improve: upload添加onchange事件
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlq committed Oct 11, 2016
1 parent b2e01cf commit 7edd7f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 8 additions & 1 deletion site/src/scripts/components/impression/components/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) {
Expand All @@ -63,6 +69,7 @@ export default class Upload extends PureComponent {
}

reader.readAsDataURL(file);
onChange && onChange(event);
}
// 渲染
render() {
Expand Down
9 changes: 8 additions & 1 deletion src/scripts/components/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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) {
Expand All @@ -63,6 +69,7 @@ export default class Upload extends PureComponent {
}

reader.readAsDataURL(file);
onChange && onChange(event);
}
// 渲染
render() {
Expand Down

0 comments on commit 7edd7f5

Please sign in to comment.