From 48c1de18235020edff108339ed1d12bade8a2b90 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期一, 08 十二月 2025 16:37:02 +0800
Subject: [PATCH] #

---
 src/main/webapp/static/js/deviceLogs/deviceLogs.js |  228 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 228 insertions(+), 0 deletions(-)

diff --git a/src/main/webapp/static/js/deviceLogs/deviceLogs.js b/src/main/webapp/static/js/deviceLogs/deviceLogs.js
new file mode 100644
index 0000000..31246f0
--- /dev/null
+++ b/src/main/webapp/static/js/deviceLogs/deviceLogs.js
@@ -0,0 +1,228 @@
+layui.use(['tree', 'layer', 'form', 'element'], function() {
+    var tree = layui.tree;
+    var $ = layui.jquery;
+    var layer = layui.layer;
+    var form = layui.form;
+    var element = layui.element;
+
+    var currentDay = null;
+
+    function buildMonthTree(data) {
+        var monthMap = {};
+        (data || []).forEach(function (y) {
+            (y.children || []).forEach(function (m) {
+                var month = m.title;
+                var arr = monthMap[month] || (monthMap[month] = []);
+                (m.children || []).forEach(function (d) {
+                    arr.push({ title: d.title, id: d.id });
+                });
+            });
+        });
+        var result = [];
+        Object.keys(monthMap).sort().forEach(function (month) {
+            result.push({ title: month + '鏈�', id: month, children: monthMap[month] });
+        });
+        return result;
+    }
+
+    function loadDateTree() {
+        $.ajax({
+            url: baseUrl + "/deviceLog/dates/auth",
+            headers: {'token': localStorage.getItem('token')},
+            method: 'GET',
+            beforeSend: function () {
+                layer.load(1, {shade: [0.1,'#fff']});
+            },
+            success: function (res) {
+                layer.closeAll('loading');
+                if (res.code === 200) {
+                    var monthTree = buildMonthTree(res.data);
+                    tree.render({
+                        elem: '#date-tree',
+                        id: 'dateTree',
+                        data: monthTree,
+                        click: function(obj){
+                            var node = obj.data;
+                            if (node.id && node.id.length === 8) {
+                                currentDay = node.id;
+                                $('#selected-day').val(currentDay);
+                                loadDevices(currentDay);
+                            }
+                        }
+                    });
+                } else if (res.code === 403) {
+                    top.location.href = baseUrl + "/";
+                } else {
+                    layer.msg(res.msg || '鍔犺浇鏃ユ湡澶辫触', {icon: 2});
+                }
+            }
+        });
+    }
+
+    function loadDevices(day) {
+        $('#device-list').html('');
+        $.ajax({
+            url: baseUrl + "/deviceLog/day/" + day + "/devices/auth",
+            headers: {'token': localStorage.getItem('token')},
+            method: 'GET',
+            beforeSend: function () {
+                layer.load(1, {shade: [0.1,'#fff']});
+            },
+            success: function (res) {
+                layer.closeAll('loading');
+                if (res.code === 200) {
+                    if (!res.data || res.data.length === 0) {
+                        $('#device-list').html('<div class="layui-text">褰撴棩鏈壘鍒拌澶囨棩蹇�</div>');
+                        return;
+                    }
+                    var html = '';
+                    res.data.forEach(function(item){
+                        var types = item.types || [];
+                        var typeBtns = '';
+                        types.forEach(function(t){
+                            typeBtns += '<button class="layui-btn layui-btn-xs" data-type="' + t + '" data-device-no="' + item.deviceNo + '">涓嬭浇(' + t + ')</button>';
+                        });
+                        html += '<div class="layui-col-xs12" style="margin-bottom:8px;">' +
+                            '<div class="layui-card">' +
+                            '<div class="layui-card-body">' +
+                            '<span>璁惧缂栧彿锛�<b>' + item.deviceNo + '</b></span>' +
+                            '<span style="margin-left:20px;">绫诲瀷锛�' + types.join(',') + '</span>' +
+                            '<span style="margin-left:20px;">鏂囦欢鏁帮細' + item.fileCount + '</span>' +
+                            '<span style="margin-left:20px;">' + typeBtns + '</span>' +
+                            '</div>' +
+                            '</div>' +
+                            '</div>';
+                    });
+                    $('#device-list').html(html);
+                } else if (res.code === 403) {
+                    top.location.href = baseUrl + "/";
+                } else {
+                    layer.msg(res.msg || '鍔犺浇璁惧澶辫触', {icon: 2});
+                }
+            }
+        });
+    }
+
+    function downloadDeviceLog(day, type, deviceNo) {
+        if (!day) {
+            layer.msg('璇峰厛閫夋嫨鏃ユ湡', {icon: 2});
+            return;
+        }
+        if (!type) {
+            layer.msg('璇烽�夋嫨璁惧绫诲瀷', {icon: 2});
+            return;
+        }
+        if (!deviceNo) {
+            layer.msg('璇疯緭鍏ヨ澶囩紪鍙�', {icon: 2});
+            return;
+        }
+        var offsetVal = parseInt($('#file-offset').val());
+        var limitVal = parseInt($('#file-limit').val());
+        var offset = isNaN(offsetVal) || offsetVal < 0 ? 0 : offsetVal;
+        var limit = isNaN(limitVal) || limitVal <= 0 ? 200 : limitVal;
+        $.ajax({
+            url: baseUrl + "/deviceLog/download/init/auth",
+            headers: {'token': localStorage.getItem('token')},
+            method: 'POST',
+            data: JSON.stringify({ day: day, type: type, deviceNo: deviceNo, offset: offset, limit: limit }),
+            dataType:'json',
+            contentType:'application/json;charset=UTF-8',
+            success: function (res) {
+                if (res.code !== 200) {
+                    layer.msg(res.msg || '鍒濆鍖栧け璐�', {icon: 2});
+                    return;
+                }
+                var pid = res.data.progressId;
+                var progressIndex = layer.open({
+                    type: 1,
+                    title: '涓嬭浇涓�',
+                    area: ['520px', '200px'],
+                    content: '<div style="padding:16px;">' +
+                        '<div class="layui-text" style="margin-bottom:15px;">鍘嬬缉鐢熸垚杩涘害</div>' +
+                        '<div class="layui-progress" lay-showPercent="true" lay-filter="buildProgress">' +
+                        '<div class="layui-progress-bar" style="width:0%"><span class="layui-progress-text">0%</span></div>' +
+                        '</div>' +
+                        '<div class="layui-text" style="margin:12px 0 15px;">涓嬭浇鎺ユ敹杩涘害</div>' +
+                        '<div class="layui-progress" lay-showPercent="true" lay-filter="receiveProgress">' +
+                        '<div class="layui-progress-bar" style="width:0%"><span class="layui-progress-text">0%</span></div>' +
+                        '</div>' +
+                        '</div>'
+                });
+                var timer = setInterval(function(){
+                    $.ajax({
+                        url: baseUrl + '/deviceLog/download/progress/auth',
+                        headers: {'token': localStorage.getItem('token')},
+                        method: 'GET',
+                        data: { id: pid },
+                        success: function (p) {
+                            if (p.code === 200) {
+                                var percent = p.data.percent || 0;
+                                element.progress('buildProgress', percent + '%');
+                                // 闅愯棌瀹炴椂澶у皬锛屼笉鏇存柊鏂囧瓧
+                            }
+                        }
+                    });
+                }, 500);
+
+                $.ajax({
+                    url: baseUrl + "/deviceLog/day/" + day + "/download/auth?type=" + encodeURIComponent(type) + "&deviceNo=" + encodeURIComponent(deviceNo) + "&offset=" + offset + "&limit=" + limit + "&progressId=" + encodeURIComponent(pid),
+                    headers: {'token': localStorage.getItem('token')},
+                    method: 'GET',
+                    xhrFields: { responseType: 'blob' },
+                    xhr: function(){
+                        var xhr = new window.XMLHttpRequest();
+                        xhr.onprogress = function(e){
+                            var percent = 0;
+                            if (e.lengthComputable && e.total > 0) {
+                                percent = Math.floor(e.loaded / e.total * 100);
+                                element.progress('receiveProgress', percent + '%');
+                            }
+                            // 闅愯棌瀹炴椂澶у皬锛屼笉鏇存柊鏂囧瓧
+                        };
+                        return xhr;
+                    },
+                    success: function (data, status, xhr) {
+                        var disposition = xhr.getResponseHeader('Content-Disposition') || '';
+                        var filename = type + '_' + deviceNo + '_' + day + '.zip';
+                        var match = /filename=(.+)/.exec(disposition);
+                        if (match && match[1]) {
+                            filename = decodeURIComponent(match[1]);
+                        }
+                        element.progress('buildProgress', '100%');
+                        element.progress('receiveProgress', '100%');
+                        var blob = new Blob([data], {type: 'application/zip'});
+                        var link = document.createElement('a');
+                        var url = window.URL.createObjectURL(blob);
+                        link.href = url;
+                        link.download = filename;
+                        document.body.appendChild(link);
+                        link.click();
+                        document.body.removeChild(link);
+                        window.URL.revokeObjectURL(url);
+                        clearInterval(timer);
+                        setTimeout(function(){ layer.close(progressIndex); }, 300);
+                    },
+                    error: function () {
+                        clearInterval(timer);
+                        layer.close(progressIndex);
+                        layer.msg('涓嬭浇澶辫触鎴栨湭鎵惧埌鏃ュ織', {icon: 2});
+                    }
+                });
+            }
+        });
+    }
+
+    $(document).on('click', '#download-btn', function () {
+        downloadDeviceLog(currentDay, $('#device-type-input').val(), $('#device-no-input').val());
+    });
+
+    $(document).on('click', '#device-list .layui-btn', function () {
+        var deviceNo = $(this).attr('data-device-no');
+        var type = $(this).attr('data-type');
+        downloadDeviceLog(currentDay, type, deviceNo);
+    });
+
+    loadDateTree();
+    limit();
+});
+

--
Gitblit v1.9.1