Attachment.js
2.4 KB
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
import React,{PropTypes} from 'react';
import moment from 'moment';
import cx from 'classnames';
import s from './Attachment.scss';
import accessoryUtil from '../../utils/accessoryUtil';
import fileUtil from '../../utils/fileUtil';
export class Attachment extends React.Component {
constructor(props) {
super(props);
this.downloadFile = this.downloadFile.bind(this);
this.onRemove = this.onRemove.bind(this);
this.state={
}
}
static propTypes = {
attachment:PropTypes.object,
onDelete: PropTypes.func,
index: PropTypes.number,
readOnly:PropTypes.bool
}
componentDidMount(){
}
componentWillReceiveProps(nextProps){
}
componentWillUnmount() {
}
onRemove(){
const {index, onDelete, attachment} = this.props;
const self = this;
console.log(index);
if(attachment.status!='active'){
// fileUtil.deleteFile(attachment.file_id).
// then(res=>{
// console.log(res);
// }).
// catch(function(error){
// console.log(error);
// });
}
onDelete(index);
}
downloadFile(){
const {attachment} = this.props;
console.log(attachment);
const name=attachment.name;
const path = attachment.path+name;
fileUtil.downloadFile(attachment.bucket, path, name,attachment.file_id);
}
renderIcon(){
const {attachment:{type=''}}=this.props;
if(type=='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
return <i className={cx('kr_icon',s.file_icon)}></i>;
else if(type=='application/msword')
return <i className={cx('kr_icon',s.file_icon)}></i>;
else
return <i className={cx('kr_icon',s.file_icon)}></i>;
}
render(){
const {attachment, readOnly}=this.props, self=this;
return(
<div className={cx(s.file_wrap)}>
<div className={cx(s.actions)}>
<a onClick={this.downloadFile} className={cx('kr_icon','ts_icon','ts_icon_share',s.download)}></a>
{!readOnly&&<a className={cx('kr_icon','ts_icon','ts_icon_share',s.download)} onClick={this.onRemove}>
</a>}
</div>
{this.renderIcon()}
<div className={cx(s.contents)}>
<span className={cx(s.tiem)}>{moment(attachment.created_at).format('M月D日 H:mmA')}</span>
<div className={cx(s.title)}>{attachment.name}</div>
<span className={cx(s.type)}>{attachment.type}</span>
</div>
</div>
);
}
}
export default Attachment