1 |
|
2 |
|
3 |
|
4 |
|
5 | import React, { Component } from 'react';
|
6 | import { Modal, Button, Icon, Upload, Message, Loading, Table, Popconfirm, ProgressBar } from 'tinper-bee';
|
7 | import PropTypes from 'prop-types';
|
8 |
|
9 | const propTypes = {
|
10 | title: PropTypes.string,
|
11 | multiple: PropTypes.bool,
|
12 | action: PropTypes.string,
|
13 | showUploadList: PropTypes.bool,
|
14 | accept: PropTypes.string,
|
15 | name: PropTypes.string,
|
16 | data: PropTypes.object,
|
17 | isView: PropTypes.bool
|
18 | };
|
19 |
|
20 | class AcUpload extends Component {
|
21 | constructor(props) {
|
22 | super(props);
|
23 | this.state = {
|
24 | show: false,
|
25 | historyData: props.defaultFileList
|
26 | }
|
27 | }
|
28 | componentWillReceiveProps = (newProps) => {
|
29 | this.setState({
|
30 | historyData: newProps.defaultFileList
|
31 | });
|
32 | }
|
33 | defaultFileListToList = (_list) => {
|
34 | let newData = [];
|
35 | if (Array.isArray(_list)) {
|
36 | for (let i = 0; i < _list.length; i++) {
|
37 | newData.push({
|
38 | uid: _list[i].fileName,
|
39 | name: _list[i].fileName,
|
40 | status: 'done',
|
41 | url: _list[i].accessAddress
|
42 | });
|
43 | }
|
44 | }
|
45 | return newData;
|
46 | }
|
47 |
|
48 |
|
49 | showModeHandler = (e) => {
|
50 | if (e) e.stopPropagation();
|
51 | this.setState({
|
52 | show: true
|
53 | });
|
54 | }
|
55 |
|
56 | hideModelHandler = () => {
|
57 | this.setState({
|
58 | show: false
|
59 | });
|
60 | }
|
61 | viewFileHandler = () => {
|
62 | this.setState({
|
63 | show: true
|
64 | });
|
65 | }
|
66 | render() {
|
67 | const uploadProps = {
|
68 | name: this.props.name,
|
69 | multiple: this.props.multiple,
|
70 | showUploadList: this.props.showUploadList,
|
71 | action: this.props.action,
|
72 | accept: this.props.accept,
|
73 | defaultFileList: this.defaultFileListToList(this.state.historyData),
|
74 | onChange: (msg) => {
|
75 | if (msg.file.status == 'done' && msg.file.response.status == 1) {
|
76 | this.props.onSuccess && this.props.onSuccess(msg.file.response.data);
|
77 | }
|
78 | if (msg.file.status == 'error') {
|
79 | this.props.onError && this.props.onError();
|
80 | }
|
81 | if (msg.file.status == 'uploading') {
|
82 | console.log('uploading');
|
83 | }
|
84 | if (msg.file.status == 'removed') {
|
85 | console.log(msg);
|
86 | this.props.onDelete && this.props.onDelete(msg.file);
|
87 | }
|
88 | }
|
89 | };
|
90 | return (
|
91 | <span className="ac-upload-wrap">
|
92 | <span onClick={this.showModeHandler}>
|
93 | {this.props.children}
|
94 | </span>
|
95 | <Modal
|
96 | dialogClassName="ac-upload-modal"
|
97 | backdrop={false}
|
98 | autoFocus={false}
|
99 | enforceFocus={false}
|
100 | show={this.state.show}
|
101 | onHide={this.hideModelHandler} >
|
102 | <Modal.Header
|
103 | closeButton>
|
104 | <Modal.Title>{this.props.title}</Modal.Title>
|
105 | </Modal.Header>
|
106 | <Modal.Body>
|
107 | <div className="ac-upload-wrap">
|
108 | <Upload {...uploadProps}>
|
109 | {!this.props.isView && <div className="opeat">
|
110 | <div className="svg-ready"></div>
|
111 | <div className="upload-tips">点击选择上传文件</div>
|
112 | </div>}
|
113 | </Upload>
|
114 | {this.props.isView && <div className="opeat">
|
115 | <div className="svg-no-pic"></div>
|
116 | <div style={{ "fontSize": "14px" }} className="upload-tips">暂无附件</div>
|
117 | </div>}
|
118 | </div>
|
119 | </Modal.Body>
|
120 | </Modal>
|
121 | </span>
|
122 | );
|
123 | }
|
124 | }
|
125 |
|
126 |
|
127 | AcUpload.propTypes = propTypes;
|
128 | AcUpload.defaultProps = {
|
129 | title: "文件上传",
|
130 | multiple: false,
|
131 | action: "/iuap_pap_quickstart/fileMananger/fastDfs/imgUpload",
|
132 | showUploadList: true,
|
133 | accept: "",
|
134 | name: "files[]",
|
135 | data: {},
|
136 | maxSize: 10240000000,
|
137 | defaultFileList: [],
|
138 | isView: false
|
139 | }
|
140 | export default AcUpload;
|