jiazx0107
2026-02-08 e7ab049344b954b044fc474992c378fcbbeeba33
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
178
179
180
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
var layer;
var form;
var curCamera;
var firstQuantity;
var hisChart = null;   //曲线图
var listRecord;
var fileRecord;
var names = ['12-01', '12-02', '12-03', '12-04', '12-05', '12-06', '12-07'];
var data = [2560000, 2510000, 2540000, 2530000, 2490000, 2610000, 2570000];
 
layui.use(['layer'], function () {
    form = layui.form;
    layer = layui.layer;
 
    // 调色板切换事件
    document.querySelectorAll('.palette-item').forEach(item => {
        item.addEventListener('click', function () {
            document.querySelectorAll('.palette-item').forEach(i => {
                i.classList.remove('active');
            });
            this.classList.add('active');
            const paletteName = this.textContent.trim();
            layer.msg(`已切换至${paletteName}调色板`, {icon: 1, time: 1000});
        });
    });
 
 
    //选择摄像头后触发的事件
    const cameraSelect = document.getElementById('select-camera');
    cameraSelect.addEventListener('change', function () {
        const selectId = this.value;
 
        ajaxData(selectId);
    });
 
    // 初始化走势图
    initEcharts(names, data);
 
});
 
/**
 * 视频播放
 * @param selectId
 */
function ajaxData(selectId) {
    curCamera = null;
    //从列表中获取摄像头信息
    curCamera = listCamera.find(camera => camera.depotId === selectId);
    if (!curCamera) {
        layer.msg('没有获取到当前摄像头信息……', {icon: 1, time: 1200});
        return;
    }
 
    //获取视频
    video();
 
    //渲染走势图
    ajaxEcharts();
 
    //渲染记录
    ajaxListRecord();
}
 
/**
 * 请求图表信息
 */
function ajaxSnapImg() {
    if(!firstQuantity){
        renderSnapImg();
        return;
    }
    fileRecord = null;
    var data = {
        key: firstQuantity.batchId
    };
    $.ajax({
        type: 'POST',
        url: "/security/quantity-files",
        dataType: 'JSON',
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "0000") {
                renderSnapImg();
            } else {
                fileRecord = result.data;
                renderSnapImg();
            }
        },
        error: function (result) {
            renderSnapImg();
        }
    });
}
 
/**
 * 渲染抓图
 * @returns {null}
 */
function renderSnapImg() {
 
    if (!fileRecord) return null;
 
    if (fileRecord.length === 0) return null;
 
    var record = fileRecord[0];
    if (record) {
        $("#file-time1").text(record.createTime);
        $("#file-img1").attr("src", record.filePath);
    } else {
        $("#file-time1").text("----");
        $("#file-img1").attr("src", "/img/web/security/p-snap.jpg");
    }
 
    record = fileRecord[1];
    if (record) {
        $("#file-time2").text(record.createTime);
        $("#file-img2").attr("src", record.filePath);
    } else {
        $("#file-time2").text("----");
        $("#file-img2").attr("src", "/img/web/security/p-snap.jpg");
    }
 
    record = fileRecord[2];
    if (record) {
        $("#file-time3").text(record.createTime);
        $("#file-img3").attr("src", record.filePath);
    } else {
        $("#file-time3").text("----");
        $("#file-img3").attr("src", "/img/web/security/p-snap.jpg");
    }
 
    record = fileRecord[3];
    if (record) {
        $("#file-time4").text(record.createTime);
        $("#file-img4").attr("src", record.filePath);
    } else {
        $("#file-time4").text("----");
        $("#file-img4").attr("src", "/img/web/security/p-snap.jpg");
    }
}
 
/**
 * 请求图表信息
 */
function ajaxEcharts() {
    var data = {
        depotId: curCamera.depotId
    };
    $.ajax({
        type: 'POST',
        url: "/security/quantity-chart",
        dataType: 'JSON',
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "0000") {
                renderEcharts(null);
            } else {
                renderEcharts(result.data);
            }
        },
        error: function (result) {
            renderEcharts(null);
        }
    });
}
 
/**
 * 渲染图表
 * @param chartData
 */
function renderEcharts(chartData) {
    var chart = hisChart;
    if (chartData && chartData.xaxis.length > 0 && chartData.seriesData.length > 0) {
        chart.option.xAxis[0].data = chartData.xaxis;
        chart.option.series[0].data = chartData.seriesData;
        chart.chart.setOption(chart.option, true);
    } else {
        chart.option.xAxis[0].data = names;
        chart.option.series[0].data = data;
        chart.chart.setOption(chart.option, true);
    }
    hisChart = chart;
}
 
/**
 * 请求记录
 */
function ajaxListRecord() {
    firstQuantity = null;
    listRecord = null;
    var data = {
        depotId: curCamera.depotId
    };
    $.ajax({
        type: 'POST',
        url: "/security/quantity-list",
        dataType: 'JSON',
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "0000") {
                renderListRecord();
            } else {
                listRecord = result.data;
                renderListRecord();
            }
        },
        error: function (result) {
            renderListRecord();
        }
    });
}
 
/**
 * 渲染记录
 * @returns {null}
 */
function renderListRecord() {
 
    if (!listRecord) {
        //渲染抓拍图
        ajaxSnapImg();
        return null;
    }
 
    if (listRecord.length === 0) {
        //渲染抓拍图
        ajaxSnapImg();
        return null;
    }
 
    var record = listRecord[0];
    if (record) {
        firstQuantity = record;
        $("#record_title1").text("检测重量:" + record.weight + " KG");
        $("#record_time1").text(record.receiveDate);
        $("#record_content1").text(record.remark);
    } else {
        $("#record_title1").text("检测重量:---- KG");
        $("#record_time1").text("----");
        $("#record_content1").text("检测重量为---- KG,实际重量为---- KG,误差小于-%。");
    }
 
    record = listRecord[1];
    if (record) {
        $("#record_title2").text("检测重量:" + record.weight + " KG");
        $("#record_time2").text(record.receiveDate);
        $("#record_content2").text(record.remark);
    } else {
        $("#record_title2").text("检测重量:---- KG");
        $("#record_time2").text("----");
        $("#record_content2").text("检测重量为---- KG,实际重量为---- KG,误差小于-%。");
    }
 
    record = listRecord[2];
    if (record) {
        $("#record_title3").text("检测重量:" + record.weight + " KG");
        $("#record_time3").text(record.receiveDate);
        $("#record_content3").text(record.remark);
    } else {
        $("#record_title3").text("检测重量:---- KG");
        $("#record_time3").text("----");
        $("#record_content3").text("检测重量为---- KG,实际重量为---- KG,误差小于-%。");
    }
 
    record = listRecord[3];
    if (record) {
        $("#record_title4").text("检测重量:" + record.weight + " KG");
        $("#record_time4").text(record.receiveDate);
        $("#record_content4").text(record.remark);
    } else {
        $("#record_title4").text("检测重量:---- KG");
        $("#record_time4").text("----");
        $("#record_content4").text("检测重量为---- KG,实际重量为---- KG,误差小于-%。");
    }
 
    //渲染抓拍图
    ajaxSnapImg();
}
 
/**
 * 视频播放
 * @param
 */
function video() {
 
    var data = {
        id: curCamera.cameraSn,
        playType: curCamera.playType
    };
    $.ajax({
        type: 'POST',
        url: "/security/get-media",
        dataType: 'JSON',
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code != "SUCCESS") {
                layer.msg(result.msg, {icon: 1, time: 1200});
            } else {
                toPlay(result.playUrl);
            }
        },
        error: function (result) {
            layer.msg("未获取到播放信息!!", {icon: 1, time: 1200});
        }
    });
 
}
 
/**
 * 播放视频
 * @param url
 */
function toPlay(url) {
    var html = '';
    if (url) {
        html += '<iframe src="' + url + '" width="100%" height="100%" frameborder="0" allowfullscreen></iframe>';
    } else {
        html += '<img src="/img/web/security/p-snap.jpg">';
    }
    $("#divPlugin2").html(html);
}
 
/**
 * 启动开始检测
 */
function checkStart() {
    if (!curCamera) {
        shoTips("请先选择设备!");
        return;
    }
    layer.msg("开始执行……");
    var data = {
        'depotId': curCamera.depotId
    };
    $.ajax({
        type: "POST",
        url: "/security/check-single",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code == "ORDER_SUCCESS") {
                shoTips("命令发生成功,请等待终端返回结果……");
            } else {
                shoTips("命令发送失败:" + result.msg);
            }
        },
        error: function () {
            shoTips("检测出现异常,执行失败!");
        }
    });
}
 
/**
 * 停止检测
 */
function checkStop() {
    if (!curCamera) {
        shoTips("请先选择仓库!");
        return;
    }
    layer.msg("开始执行……");
    var data = {
        'depotId': curCamera.depotId
    };
    $.ajax({
        type: "POST",
        url: "/security/check-stop",
        dataType: "json",
        contentType: "application/json;charset=UTF-8",
        data: JSON.stringify(data),
        success: function (result) {
            if (result.code == "ORDER_SUCCESS") {
                shoTips("命令发生成功……");
            } else {
                shoTips("命令发送失败:" + result.msg);
            }
        },
        error: function () {
            shoTips("检测出现异常,执行失败!");
        }
    });
}
 
// 初始化ECharts温度走势图
function initEcharts(names, data) {
    // 初始化ECharts温度走势图
    var temperatureChartDom = document.getElementById('temperatureChart');
    var temperatureChart = echarts.init(temperatureChartDom);
 
    // 图表配置项
    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'cross',
                label: {
                    backgroundColor: '#6a7985'
                }
            }
        },
        legend: {
            data: ['数量 (KG)'],
            top: 0
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: [
            {
                type: 'category',
                boundaryGap: false,
                data: names
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: '数量 (KG)',
                min: 0,
                // max: 3000000,
                axisLabel: {
                    formatter: '{value} KG'
                }
            }
        ],
        series: [
            {
                name: '数量 (KG)',
                type: 'line',
                smooth: true,
                lineStyle: {
                    width: 2,
                    color: '#0f3460'
                },
                areaStyle: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        {offset: 0, color: 'rgba(15, 52, 96, 0.3)'},
                        {offset: 1, color: 'rgba(15, 52, 96, 0.05)'}
                    ])
                },
                data: data
            }
        ]
    };
    // 渲染图表
    option && temperatureChart.setOption(option);
    hisChart = {"chart": temperatureChart, "option": option};
 
    // 窗口大小变化时调整图表大小
    window.addEventListener('resize', function () {
        temperatureChart.resize();
    });
}
 
function shoTips(msg) {
    layer.msg(msg,
        {time: 3000, shift: 5, offset: "rb"},
        function () {
        });
}