Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
be58717
Update README.md
kooff88 Nov 6, 2017
1f8613c
TagGroup 动态添加数据 点击删除无法获取相应数据问题
Nov 6, 2017
149d7bf
Update README.md
kooff88 Nov 6, 2017
f1f1c98
冲突
Nov 10, 2017
5739555
Merge branch 'master' of github.com:uiw-react/uiw
Nov 11, 2017
56c3d87
input test
Nov 11, 2017
1aa8a44
Merge branch 'master' of github.com:uiw-react/uiw
Nov 13, 2017
9862313
合并
Nov 13, 2017
5493d0f
Merge remote-tracking branch 'wcj/master'
Nov 13, 2017
805968e
Merge branch 'master' of github.com:uiw-react/uiw
Nov 13, 2017
3ed100f
input test2
Nov 13, 2017
d9fcd94
Adding default value of porps size on module Avatar and some test cases.
Xing-He Nov 13, 2017
194b7c8
fix(affix): Fix bug where body.scrollTop is 0.
jaywcjlove Nov 13, 2017
7424a1a
Merge branch 'master' of github.com:uiw-react/uiw
Nov 14, 2017
f7ac4aa
InputNumber add defaultValue
Nov 14, 2017
f5c2f37
InputNumber test
Nov 14, 2017
87ce807
layout md text description wrong
Nov 15, 2017
f947e9e
Layout Row test
Nov 15, 2017
878fdd7
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 16, 2017
b86907c
Layout Col test
Nov 16, 2017
456f69a
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 17, 2017
3184bea
loading test
Nov 17, 2017
a0a55e0
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 20, 2017
c73eb93
Progress test
Nov 20, 2017
819c651
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 21, 2017
56e513c
test(Menu): Menu组件测试用例
Nov 21, 2017
7a6bc9c
test(Message):Message添加测试用例
Nov 22, 2017
f20d82e
Test(Modal): Add modal text case
Nov 23, 2017
7efa9cb
style(Modal):remove console
Nov 23, 2017
561037d
clean(Modal):merge conflict
Nov 24, 2017
26b76e1
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 24, 2017
a87b13d
Test(Table): Add table test
Nov 24, 2017
70776c5
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 25, 2017
bdd58a5
Test(Notification):Add notification test
Nov 27, 2017
17a0486
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 27, 2017
b2ec136
style(Notification):eslist test modify
Nov 28, 2017
8afe778
fix(Notification):test conflict
Nov 28, 2017
f8e8bfd
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 28, 2017
2f7c9b4
Test(Paging):Add paging test
Nov 28, 2017
d447c23
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 28, 2017
173f5b1
Merge branch 'master' of github.com:uiw-react/uiw into zp
Nov 29, 2017
7265bcb
Test(Card):Add card test
Nov 29, 2017
36dee98
Test(Select):Add select test
Nov 30, 2017
2df52c8
Merge branch 'master' of github.com:uiw-react/uiw into zp
Dec 1, 2017
30d8796
Test(Switch):Add switch test
Dec 1, 2017
ddc7439
Merge branch 'master' of github.com:uiw-react/uiw into zp
Dec 4, 2017
5f96b3a
Test(Slider):Add Slider test
Dec 4, 2017
4745cac
Merge branch 'master' of github.com:uiw-react/uiw into zp
Dec 5, 2017
98e246a
Test(Steps):Add steps test
Dec 5, 2017
15265af
Merge branch 'master' of github.com:uiw-react/uiw into zp
Dec 6, 2017
3777432
Test(Tag):Add tag test
Dec 6, 2017
ce51c19
Merge branch 'master' of github.com:uiw-react/uiw into zp
Dec 7, 2017
251b114
feat(Upload):Add Upload modal
Dec 7, 2017
b364df7
feat(Upload):Add Upload modal 未完
Dec 7, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/Routers.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import carousel from 'bundle-loader?lazy&name=carousel!./pages/carousel';
import loading from 'bundle-loader?lazy&name=loading!./pages/loading';
import transition from 'bundle-loader?lazy&name=transition!./pages/transition';
import timestamp from 'bundle-loader?lazy&name=timestamp!./pages/timestamp';
import upload from 'bundle-loader?lazy&name=upload!./pages/upload';
/* eslint import/no-webpack-loader-syntax: off */

const getLang = (key) => {
Expand Down Expand Up @@ -104,6 +105,7 @@ const routes = {
{ path: "/:lang/input-password", component: asyncComponent(inputPassword) },
{ path: "/:lang/time-picker", component: asyncComponent(timePicker) },
{ path: "/:lang/date-picker", component: asyncComponent(datePicker) },
{ path: "/:lang/upload", component: asyncComponent(upload) },
],
'Data Display': [
{ path: "/:lang/avatar", component: asyncComponent(Avatar) },
Expand Down
1 change: 1 addition & 0 deletions docs/locales/cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = {
'icon': 'Icon 图标',
'form': 'Form 表单',
'radio': 'Radio 单选框',
'upload': 'Upload 上传图片',
'recommendation': '精选开源组件',
'input': 'Input 输入框',
'input-number': 'InputNumber 数字输入框',
Expand Down
1 change: 1 addition & 0 deletions docs/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
'form': 'Form',
'radio': 'Radio',
'recommendation': 'Third-Party Libraries',
'upload': 'Upload',
'input': 'Input',
'input-number': 'InputNumber',
'input-password': 'InputPassword',
Expand Down
39 changes: 39 additions & 0 deletions docs/md/cn/upload.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Upload 标签
===

### 拖拽上传

可批量拖拽图片上传。

<!--DemoStart-->
```js
class Demo extends Component {
render() {
return (
<div>
<Upload.Dragger
onChange={(value1)=>{
console.log("value1::",value1)
}}
onRemove={(value2)=>{
console.log("value2::",value2)
}}
/>
</div>
)
}
}
```
<!--End-->



## API

### Upload.Dragger

| 参数 | 说明 | 类型 | 默认值 |
|--------- |-------- |---------- |-------- |
| onChange | 拖拽完成触发,可获取图片的base64编码以及二进制编码容器blob | function(value) | - |
| onRemove | 删除某张图片 | function(value) | - |
| disabled | 禁止点击按钮 | Boolean | `false` |
5 changes: 5 additions & 0 deletions docs/pages/upload/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Markdown from '../../libs/markdown/';

export default class Upload extends Markdown {

}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ export { default as Notification } from './notification/';
export { default as Carousel } from './carousel/';
export { default as Form } from './form/';
export { default as version } from './version';

export { default as Upload } from './upload';
9 changes: 9 additions & 0 deletions src/style/variables.less
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,15 @@
@carousel-dot-height: 3px;
@carousel-dot-active-width: 24px;

//== Upload 上传图片 ====

@upload-border-color: #bbb1b1;
@upload-bg-color: #f1ebeb;
@upload-button-border-color: #0fa120;
@upload-font-color: #cac0c0;
@upload-li-width: 120px;
@upload-li-height: 100px;

//== 定义屏幕宽度
//-----------------------

Expand Down
192 changes: 192 additions & 0 deletions src/upload/Dragger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import React from 'react';
import { Component, PropTypes } from '../utils/';
import Icon from '../icon';
import Button from '../button';
import './style/dragger.less';

export default class Dragger extends Component {
constructor(props) {
super(props);
this.state = {
files: [],
};
this.dragOverIndex = null;
this.onChange = this.onChange.bind(this);
this.renderPreview = this.renderPreview.bind(this);
this.onRemove = this.onRemove.bind(this);
}

// 改变图片位置
onChange(e) {
const items = e.target.files;
for (let i = 0; i < items.length; i += 1) {
this.scanFiles(items[i], this.listing);
}
}

// 删除图片
onRemove(index) {
const { files } = this.state;
const { onRemove } = this.props;
files.splice(index, 1);
this.setState({ files });
onRemove && onRemove(files);
}

// 图片base64与blob转换
dataURItoBlob(dataURI) {
const byteString = atob(dataURI.split(',')[1]);
const mimeString = dataURI
.split(',')[0]
.split(':')[1]
.split(';')[0];
const ab = new ArrayBuffer(byteString.length);
const ia = new Uint8Array(ab);
for (let i = 0; i < byteString.length; i += 1) {
ia[i] = byteString.charCodeAt(i);
}
return new Blob([ab], { type: mimeString });
}

handleChange(files) {
const { onChange } = this.props;
files.forEach((dt) => {
dt.blob = this.dataURItoBlob(dt.value);
});
onChange && onChange(files);
}

scanFiles(item) {
const reader = new FileReader();
reader.onloadend = (e) => {
const { files } = this.state;
files.push({
name: item.name,
value: e.target.result,
});
this.setState({ files });
this.handleChange(files);
};
reader.readAsDataURL(item);
}

componentDidMount() {
this.dragdropRef.addEventListener(
'dragover',
(event) => {
event.preventDefault();
},
false
);

this.dragdropRef.addEventListener(
'drop',
(event) => {
const items = event.dataTransfer.files;
event.preventDefault();
let length = items.length;
length = length > 4 ? 5 : length;
for (let i = 0; i < length; i += 1) {
this.scanFiles(items[i], this.listing);
}
},
false
);
}

renderPreview() {
return this.state.files.map((file, index) => {
return (
<li
key={`preview-key-${index}`}
data-index={index}
draggable
onDragEnd={() => {
const { files } = this.state;
if (this.dragOverIndex === null || this.dragOverIndex === index) return;
file = files[index];
files.splice(this.dragOverIndex, 0, file);
this.dragOverIndex < index
? files.splice(index + 1, 1)
: files.splice(index, 1);
this.dragOverIndex = null;
this.setState({ files });
this.handleChange(files);
}}
onDrop={(e) => {
const dataset = e.target.dataset || { dragOverIndex: null };
this.dragOverIndex = dataset.index;
}}
>
<div
data-index={index}
style={{ backgroundImage: `url(${file.value})` }}
/>
<p data-index={index}>
<span>{file.name}</span>
<Icon
type="delete"
onClick={() => {
this.onRemove(index);
}}
/>
</p>
</li>
);
});
}

render() {
const { prefixCls, className, disabled } = this.props;
const cls = this.classNames(`${prefixCls}`, className);
return (
<div className={cls}>
<div
className={`${prefixCls}-wrap`}
ref={(node) => {
this.dragdropRef = node;
}}
>
<Button
disabled={disabled}
size="small"
onClick={() => {
this.fileRef.click();
}}
>
<Icon type="cloud-upload" />拖拽或点击上传
</Button>
<input
type="file"
onChange={this.onChange}
ref={(node) => {
this.fileRef = node;
}}
/>
<p>只能上传png、gif、jpg格式图片,并不超过10M</p>
<ul
className={`${prefixCls}-list`}
ref={(node) => {
this.listing = node;
}}
>
{this.renderPreview()}
</ul>
</div>
</div>
);
}
}

Dragger.propTypes = {
prefixCls: PropTypes.string,
onChange: PropTypes.func,
onRemove: PropTypes.func,
disabled: PropTypes.bool,
};
Dragger.defaultProps = {
prefixCls: 'w-upload-dragger',
disabled: false,
onChange: () => {},
onRemove: () => {},
};
2 changes: 2 additions & 0 deletions src/upload/Upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@


6 changes: 6 additions & 0 deletions src/upload/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Upload from './Upload';
import Dragger from './Dragger';

Upload.Dragger = Dragger;

export default Upload;
Loading