31468a37
Yang Xiaoxiao
source
|
1
2
3
4
5
6
7
8
9
10
11
|
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 = []
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
12
13
14
15
|
// 20200604该需求 需要翻页删所有数据【但!获得一张图片时间过久!超过10秒,所以加以下变量】
let querList0604_ = []
|
31468a37
Yang Xiaoxiao
source
|
16
17
18
19
20
|
class SearchAlarm extends React.Component {
constructor(props) {
super(props);
this.state={
startTime : '',
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
endTime : '',
currentPage: 1,
totalPage:1,
defaultPageSize:28,
data:[],
indeterminate: false,
checkAll: false,
checkedList: [],
previewVisible: false,
previewImage: '',
previewTitle: ''
|
31468a37
Yang Xiaoxiao
source
|
35
|
};
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
36
|
}
|
31468a37
Yang Xiaoxiao
source
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// 时间
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处:页面跳转、每页数据限制;阿里...
|
52
|
let that = this
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
53
54
55
56
57
58
59
|
that.setState({
data:[]
},function(){
that.queryImg()
})
|
31468a37
Yang Xiaoxiao
source
|
60
61
|
}
queryImg = () =>{
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
62
|
let that = this
|
31468a37
Yang Xiaoxiao
source
|
63
|
plainOptions = []
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
64
|
querList0604_ = []
|
31468a37
Yang Xiaoxiao
source
|
65
66
67
68
69
70
|
axios.post(global.constants.commonUrl+'/syImgMs/queryImg',
{
'request':'queryImg',
'reqInfo':{
'dateTimeS':this.state.startTime,
'dateTimeE':this.state.endTime,
|
51d94662
Yang Xiaoxiao
2处:页面跳转、每页数据限制;阿里...
|
71
|
'curPage':this.state.currentPage,
|
31468a37
Yang Xiaoxiao
source
|
72
73
74
75
76
|
'pageNum':this.state.defaultPageSize
}
})
.then(function (response) {
var resList = response['data']['resInfo']['imgList']
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
77
78
|
querList0604_ = response['data']['resInfo']['imgList']
|
31468a37
Yang Xiaoxiao
source
|
79
80
81
82
83
|
that.setState({
data:[],
indeterminate: false,
checkAll: false,
checkedList: [],
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
84
|
totalPage: response['data']['resInfo']['totalPages'],
|
31468a37
Yang Xiaoxiao
source
|
85
86
87
88
89
90
91
92
|
});
that.getImgData(resList,0)
})
.catch(function (error) {
//console.log(error);
});
}
getImgData = (resList, currI) =>{
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
93
94
|
console.log(querList0604_)
|
31468a37
Yang Xiaoxiao
source
|
95
|
var that = this
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
96
|
if(currI == resList.length)
|
31468a37
Yang Xiaoxiao
source
|
97
|
return;
|
31468a37
Yang Xiaoxiao
source
|
98
99
100
101
102
103
104
105
106
|
else{
axios.post(global.constants.commonUrl+'/syImgMs/getImgData',
{
'request':'getImgData',
'reqInfo':{
'imgId':resList[currI]['id']
}
})
.then(function (response) {
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
console.log(querList0604_)
console.log(response)
var nowData = response['data']['resInfo']
var stateData = that.state.data
//0604防止旧查询旧数据出现 需验证querList0604_ 此次得来的图片id应该在querList0604_中,querList0604_始终保持最新查询所得的数据列表
for(var i=0;i<querList0604_.length;i++){
if(querList0604_[i]['id'] == nowData['id']){
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)
break;
}
}
|
31468a37
Yang Xiaoxiao
source
|
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
178
179
180
181
182
183
184
185
186
|
})
.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处:页面跳转、每页数据限制;阿里...
|
187
|
let that = this
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
188
189
190
191
192
193
194
195
|
that.setState({
currentPage: page,
data:[]
},function(){
that.queryImg()
});
};
|
31468a37
Yang Xiaoxiao
source
|
196
197
198
199
200
201
202
203
204
205
|
// 图片放大
handleCancel = () => this.setState({ previewVisible: false });
handlePreview = (e) => {
this.setState({
previewImage: e.target.src,
previewVisible: true,
previewTitle: e.target.name,
});
|
31468a37
Yang Xiaoxiao
source
|
206
|
};
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
207
|
render() {
|
31468a37
Yang Xiaoxiao
source
|
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
|
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}
|
57ec2902
Yang Xiaoxiao
新:切页要求重新加载
|
256
257
258
|
src={
'data:image/' + item['ext'] + ';base64,'+ item['data']
}/>
|
31468a37
Yang Xiaoxiao
source
|
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
287
288
289
290
291
292
293
294
295
296
297
298
|
<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
|