-
Notifications
You must be signed in to change notification settings - Fork 24
/
FileList.js
178 lines (156 loc) · 4.48 KB
/
FileList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import FileItem from './FileItem';
import DefaultFileItem from './DefaultFileItem';
import util from './util';
import { Events, Status } from 'uploadcore';
import React from 'react';
import PropTypes from 'prop-types';
import Album from 'uxcore-album';
const { Photo } = Album;
export default class FileList extends React.Component {
static defaultProps = {
mode: 'mini',
showErrFile: true,
};
static propTypes = {
prefixCls: PropTypes.string,
locale: PropTypes.string,
mode: PropTypes.string,
isVisual: PropTypes.bool,
isOnlyImg: PropTypes.bool,
showErrFile: PropTypes.bool,
readOnly: PropTypes.bool,
disabled: PropTypes.bool,
onlineEdit: PropTypes.bool,
fileList: PropTypes.array,
core: PropTypes.any,
};
constructor(props) {
super(props);
this.core = props.core;
this.state = {
items: this.core.getStat().getFiles(),
};
}
componentDidMount() {
const flag = this.props.showErrFile;
const statchange = (stat) => {
let files = stat.getFiles();
if (!flag) {
files = files.filter(file => file.getStatus() != 64);
}
this.setState({
items: files,
});
};
this.core.on(Events.QUEUE_STAT_CHANGE, statchange);
this.stopListen = () => {
this.core.off(Events.QUEUE_STAT_CHANGE, statchange);
};
}
componentWillUnmount() {
if (this.stopListen) {
this.stopListen();
}
}
onShowFile(file, url, current) {
const { isOnlyImg, fileList, onShowFile } = this.props;
if (onShowFile) { // 自定义预览行为
onShowFile(file, url, current);
return;
}
if (isOnlyImg && url) {
const _fileList = fileList.map((item, index) => {
if (item.response) {
const { previewUrl } = util.getUrl(item.response);
return (<Photo
src={previewUrl}
key={index}
/>);
}
return null;
});
const shows = _fileList.filter(item => !!item);
Album.show({
photos: shows,
current,
showButton: true,
});
} else {
window.open(url);
}
}
onDownloadFile(file, url, current){
const { onDownloadFile } = this.props;
if(onDownloadFile){
onDownloadFile(file, url, current)
return;
}
window.open(url)
}
onEditFile(file, url, current) {
const { onEditFile } = this.props;
if (onEditFile) {
onEditFile(file, url, current);
return;
}
window.open(url);
}
renderDefaultFileItems() {
const arr = [];
const fileList = this.props.fileList || [];
fileList.forEach((file, index) => {
if (file.type !== 'delete') {
arr.push(
<DefaultFileItem
file={file}
prefixCls={this.props.prefixCls}
locale={this.props.locale}
key={index}
mode={this.props.mode}
isOnlyImg={this.props.isOnlyImg}
readOnly={this.props.readOnly}
disabled={this.props.disabled}
isVisual={this.props.isVisual}
onlineEdit={this.props.onlineEdit}
onShowFile={(currentFile, url) => { this.onShowFile(currentFile, url, index); }}
onDownloadFile={(currentFile, url) => { this.onDownloadFile(currentFile, url, index); }}
onEditFile={(currentFile, url) => { this.onEditFile(currentFile, url, index); }}
onCancel={this.props.removeFileFromList.bind(this)}
/>);
}
});
return arr;
}
renderFileItems() {
const arr = [];
this.state.items.forEach((file) => {
if ([Status.CANCELLED, Status.SUCCESS, Status.QUEUED].indexOf(file.status) === -1) {
arr.push(
<FileItem
prefixCls={this.props.prefixCls}
locale={this.props.locale}
key={file.id}
file={file}
mode={this.props.mode}
onlineEdit={this.props.onlineEdit}
isOnlyImg={this.props.isOnlyImg}
isVisual={this.props.isVisual}
interval={this.props.interval}
/>);
}
});
return arr;
}
render() {
const { prefixCls, mode, isVisual } = this.props;
return (
<div className={`${prefixCls}-filelist ${mode === 'nw' ? 'nwmode' : (mode === 'mini' ? 'minimode' : 'iconmode')}${isVisual ? ' filelist-visual' : ''}`}>
<div className="inner fn-clear">
{this.renderDefaultFileItems()}
{this.renderFileItems()}
{this.props.children}
</div>
</div>
);
}
}