31468a37
Yang Xiaoxiao
source
|
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
|
import React from 'react';
import '../../css/style.css'
import '../../../config';
import axios from "axios"; //导入axios
import JSZip from 'jszip';
import saveAs from 'file-saver';
import { Row, Col, DatePicker, Checkbox, Pagination, Button, Modal } from 'antd';
const { RangePicker } = DatePicker;
let plainOptions = []
class SearchAlarm extends React.Component {
constructor(props) {
super(props);
this.state={
startTime : '',
endTime : '',
currentPage: 1,
totalPage:1,
defaultPageSize:28,
data:[],
indeterminate: false,
checkAll: false,
checkedList: [],
|
51d94662
Yang Xiaoxiao
2处:页面跳转、每页数据限制;阿里...
|
28
|
couldClick:true,
|
31468a37
Yang Xiaoxiao
source
|
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
previewVisible: false,
previewImage: '',
previewTitle: '',
};
}
// 时间
onTimeChange = (value,dateString) => {
let that = this;
this.setState({
startTime:dateString[0],
endTime:dateString[1]
},function(){
console.log(that.state.startTime)
console.log(that.state.endTime)
})
}
onOk = (value) => {
// 开始查询【日期选择】
|
51d94662
Yang Xiaoxiao
2处:页面跳转、每页数据限制;阿里...
|
50
51
52
53
54
55
|
let that = this
this.setState({
couldClick:false
},function(){
that.queryImg()
})
|
31468a37
Yang Xiaoxiao
source
|
56
57
58
59
60
61
62
63
64
65
|
}
queryImg = () =>{
let that = this
plainOptions = []
axios.post(global.constants.commonUrl+'/syImgMs/queryImg',
{
'request':'queryImg',
'reqInfo':{
'dateTimeS':this.state.startTime,
'dateTimeE':this.state.endTime,
|
51d94662
Yang Xiaoxiao
2处:页面跳转、每页数据限制;阿里...
|
66
|
'curPage':this.state.currentPage,
|
31468a37
Yang Xiaoxiao
source
|
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
'pageNum':this.state.defaultPageSize
}
})
.then(function (response) {
var resList = response['data']['resInfo']['imgList']
that.setState({
data:[],
indeterminate: false,
checkAll: false,
checkedList: [],
totalPage: response['data']['resInfo']['totalPages']
});
that.getImgData(resList,0)
})
.catch(function (error) {
//console.log(error);
});
}
getImgData = (resList, currI) =>{
var that = this
|
51d94662
Yang Xiaoxiao
2处:页面跳转、每页数据限制;阿里...
|
87
88
89
90
|
if(currI == resList.length){
that.setState({
couldClick:true
})
|
31468a37
Yang Xiaoxiao
source
|
91
|
return;
|
51d94662
Yang Xiaoxiao
2处:页面跳转、每页数据限制;阿里...
|
92
|
}
|
31468a37
Yang Xiaoxiao
source
|
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
|
else{
axios.post(global.constants.commonUrl+'/syImgMs/getImgData',
{
'request':'getImgData',
'reqInfo':{
'imgId':resList[currI]['id']
}
})
.then(function (response) {
var nowData = response['data']['resInfo']
var stateData = that.state.data
stateData.push({
'id': nowData['id'],
'name': nowData['name'],
'time': nowData['time'],
'ext': nowData['ext'],
'data': nowData['data']
})
that.setState({
data:stateData
});
plainOptions.push(nowData['id'])
that.getImgData(resList, currI+1)
})
.catch(function (error) {
//console.log(error);
});
}
}
// 下载
onCheckBoxChange = checkedList => {
this.setState({
checkedList,
indeterminate: !!checkedList.length && checkedList.length < plainOptions.length,
checkAll: checkedList.length === plainOptions.length,
});
};
onChange = checkedList => {
this.setState({
checkedList,
indeterminate: !!checkedList.length && checkedList.length < plainOptions.length,
checkAll: checkedList.length === plainOptions.length,
});
};
onCheckAllChange = e => {
let that = this
this.setState({
checkedList: e.target.checked ? plainOptions : [],
indeterminate: false,
checkAll: e.target.checked,
},function(){
console.log(that.state.checkedList)
});
};
clickBtn = e =>{
console.log(this.state.checkedList)
var checkedList = this.state.checkedList
var data = this.state.data
var zip = new JSZip();
for(var i=0;i<checkedList.length;i++){
for(var j=0;j<data.length;j++){
if(checkedList[i] == data[j]['id']){
var imgUrl = 'data:image/' + data[j]['ext'] + ';base64,'+ data[j]['data']
var img = zip.folder("images");
img.file(data[j]['name'], data[j]['data'], {base64: true});
break;
}
}
}
zip.generateAsync({type:"blob"})
.then(function(content) {
saveAs(content, "pictures.zip");
});
}
// 页码
onPageChange = page => {
// 更新新页数据 后端交互
|
51d94662
Yang Xiaoxiao
2处:页面跳转、每页数据限制;阿里...
|
173
174
175
176
177
178
179
180
|
let that = this
if(that.state.couldClick){
that.setState({
currentPage: page
},function(){
that.queryImg()
});
}
|
31468a37
Yang Xiaoxiao
source
|
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
};
// 图片放大
handleCancel = () => this.setState({ previewVisible: false });
handlePreview = (e) => {
this.setState({
previewImage: e.target.src,
previewVisible: true,
previewTitle: e.target.name,
});
};
render() {
let { data, currentPage, totalPage, defaultPageSize, previewVisible, previewImage, previewTitle } = this.state
let that = this
return (
<div style={{
width:'100%',
position:'relative'
}}>
<div style={{
padding:'20px 0',
}}>
<RangePicker
showTime={{ format: 'HH:mm' }}
format="YYYY-MM-DD HH:mm"
onChange={this.onTimeChange}
onOk={this.onOk}
/>
<Checkbox
indeterminate={this.state.indeterminate}
onChange={this.onCheckAllChange}
checked={this.state.checkAll}
style={{
margin:'0 20px',
color:'white'
}}
>
Check all
</Checkbox>
<Button type="primary" onClick={this.clickBtn} style={{
margin:'0 20px'
}}>downLoad</Button>
</div>
<div style={{
height:'calc(100% - 105px)',
top:'80px',
width:'calc(100% - 20px)',
margin:'0 10px'
}}>
{
data.length==0?null:
<Checkbox.Group style={{ width: '100%' }} onChange={that.onCheckBoxChange} value={this.state.checkedList}>
{
data.map((item)=>{
//console.log(item)
return <div key={item.id} style={{ width: 249, height:190, border:'1px solid rgba(255, 255, 255, 0.3)', margin:'10px', float:'left', position:'relative'}}>
<img style={{width:'100%', height:'140px'}}
onClick = {this.handlePreview}
name = {item.name}
src={
'data:image/' + item['ext'] + ';base64,'+ item['data']
}/>
<div style={{
height:'50px',
display:'flex',
flexDirection:'column',
color:'white',
justifyContent:'center',
alignItems:'center'
}}>
<span> 时间 </span>
<span> {item.time} </span>
</div>
<Checkbox style={{
position:'absolute',
top:'-8px',
right:'-8px'
}} value={item.id} defaultChecked ></Checkbox>
</div>
})
}
</Checkbox.Group>
}
</div>
<Pagination hideOnSinglePage={true} showTitle={false} current={currentPage} onChange={this.onPageChange} pageSize={defaultPageSize} total={totalPage*defaultPageSize} />
<Modal
visible={previewVisible}
title={previewTitle}
footer={null}
onCancel={this.handleCancel}
>
<img alt="example" style={{ width: '100%' }} src={previewImage} />
</Modal>
</div>
);
}
};
export default SearchAlarm
|