Junjie
2026-04-16 424002744fa37f4483fef3e36633bd193481781a
src/main/webapp/static/js/deviceLogs/deviceLogs.js
@@ -67,6 +67,10 @@
        detailTab: 'logs',
        rawTab: 'wcs',
        systemLogType: 'info',
        systemLogRange: [],
        systemLogDialogVisible: false,
        downloadDialogVisible: false,
        buildProgress: 0,
        receiveProgress: 0,
@@ -292,6 +296,9 @@
        },
        canDownload: function () {
            return !!(this.selectedDay && this.selectedType && this.selectedDeviceNo);
        },
        canDownloadSystemLog: function () {
            return !!(this.selectedDay && this.systemLogType && this.systemLogRange && this.systemLogRange.length === 2 && this.systemLogRange[0] && this.systemLogRange[1]);
        },
        canPlay: function () {
            return !!(this.selectedDeviceSummary && this.timelineMeta.startTime && this.timelineMeta.endTime && this.sliderMax > 0);
@@ -1404,6 +1411,36 @@
        handleCurrentDeviceDownload: function () {
            this.doDownload(this.selectedDay, this.selectedType, this.selectedDeviceNo, this.selectedStationId);
        },
        openSystemLogDialog: function () {
            if (!this.selectedDay) {
                this.$message.warning('请先选择日志日期');
                return;
            }
            if (!this.systemLogRange || this.systemLogRange.length !== 2) {
                var start = this.formatDayText(this.selectedDay) + ' 00:00:00';
                var end = this.formatDayText(this.selectedDay) + ' 23:59:59';
                this.systemLogRange = [start, end];
            }
            this.systemLogDialogVisible = true;
        },
        handleSystemLogDownload: function () {
            if (!this.canDownloadSystemLog) {
                this.$message.warning('请选择日志类型和时间范围');
                return;
            }
            var startTime = this.systemLogRange[0];
            var endTime = this.systemLogRange[1];
            if (!startTime || !endTime) {
                this.$message.warning('请选择完整时间范围');
                return;
            }
            if (new Date(startTime).getTime() > new Date(endTime).getTime()) {
                this.$message.warning('开始时间不能晚于结束时间');
                return;
            }
            this.systemLogDialogVisible = false;
            this.doSystemLogDownload(this.systemLogType, startTime, endTime);
        },
        doDownload: function (day, type, deviceNo, stationId) {
            if (!day || !type || !deviceNo) {
                return;
@@ -1429,6 +1466,33 @@
                    var pid = res.data.progressId;
                    self.startDownloadProgress(pid);
                    self.performDownloadRequest(day, type, deviceNo, stationId, pid);
                },
                error: function () {
                    self.$message.error('初始化失败');
                }
            });
        },
        doSystemLogDownload: function (logType, startTime, endTime) {
            var self = this;
            $.ajax({
                url: baseUrl + '/deviceLog/system/download/init/auth',
                headers: { token: localStorage.getItem('token') },
                method: 'POST',
                data: JSON.stringify({
                    logType: logType,
                    startTime: startTime,
                    endTime: endTime
                }),
                dataType: 'json',
                contentType: 'application/json;charset=UTF-8',
                success: function (res) {
                    if (!res || res.code !== 200) {
                        self.$message.error((res && res.msg) || '初始化失败');
                        return;
                    }
                    var pid = res.data.progressId;
                    self.startDownloadProgress(pid);
                    self.performSystemLogDownloadRequest(logType, startTime, endTime, pid);
                },
                error: function () {
                    self.$message.error('初始化失败');
@@ -1465,8 +1529,19 @@
                query += '&stationId=' + encodeURIComponent(stationId);
            }
            query += '&progressId=' + encodeURIComponent(pid);
            this.performBlobDownload(baseUrl + '/deviceLog/day/' + day + '/download/auth' + query, type + '_' + deviceNo + '_' + day + '.zip', 'application/zip');
        },
        performSystemLogDownloadRequest: function (logType, startTime, endTime, pid) {
            var query = '?logType=' + encodeURIComponent(logType)
                + '&startTime=' + encodeURIComponent(startTime)
                + '&endTime=' + encodeURIComponent(endTime)
                + '&progressId=' + encodeURIComponent(pid);
            this.performBlobDownload(baseUrl + '/deviceLog/system/download/auth' + query, logType + '_system_logs.zip', 'application/zip');
        },
        performBlobDownload: function (url, fallbackFilename, mimeType) {
            var self = this;
            $.ajax({
                url: baseUrl + '/deviceLog/day/' + day + '/download/auth' + query,
                url: url,
                headers: { token: localStorage.getItem('token') },
                method: 'GET',
                xhrFields: { responseType: 'blob' },
@@ -1481,22 +1556,22 @@
                },
                success: function (data, status, xhr) {
                    var disposition = xhr.getResponseHeader('Content-Disposition') || '';
                    var filename = type + '_' + deviceNo + '_' + day + '.zip';
                    var filename = fallbackFilename;
                    var match = /filename=(.+)/.exec(disposition);
                    if (match && match[1]) {
                        filename = decodeURIComponent(match[1]);
                    }
                    self.buildProgress = 100;
                    self.receiveProgress = 100;
                    var blob = new Blob([data], { type: 'application/zip' });
                    var blob = new Blob([data], { type: mimeType || 'application/octet-stream' });
                    var link = document.createElement('a');
                    var url = window.URL.createObjectURL(blob);
                    link.href = url;
                    var objectUrl = window.URL.createObjectURL(blob);
                    link.href = objectUrl;
                    link.download = filename;
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                    window.URL.revokeObjectURL(url);
                    window.URL.revokeObjectURL(objectUrl);
                    if (self.downloadTimer) {
                        clearInterval(self.downloadTimer);
                        self.downloadTimer = null;