From a7a0569ee1617cfcae34bcb96a4a97e1ab7f6177 Mon Sep 17 00:00:00 2001 From: zhangdi <1104545947@qq.com> Date: Mon, 18 May 2026 19:40:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.json | 10 +++-- src/background.js | 2 +- src/views/AutoMode.vue | 65 +++++++++++++++++++++++---------- src/views/ModeSelect.vue | 1 + src/views/config/configFile.vue | 3 ++ 5 files changed, 57 insertions(+), 24 deletions(-) diff --git a/config.json b/config.json index 4e68666..21bebb4 100644 --- a/config.json +++ b/config.json @@ -7,17 +7,19 @@ "path": "/mqtt", "reconnect_time": "6", "status_reporting_time": "6", - "topic": "6" + "topic": "6", + "updateFileName": "2" }, "device": { - "username": "12111", - "code": "Z139009/202402", + "username": "NkXDO8uDmvnSMV8BGT7Y", + "code": "fileTest1", "codeType": "dd", "reconnect_time": "3", "address": "http://10.1.19.52:9999", "filePathDisc": "D", "file_path": "ai", "no_report_path": "未上传记录", - "searchMode": "manual" + "searchMode": "auto", + "updateFileName": "2" } } \ No newline at end of file diff --git a/src/background.js b/src/background.js index 6146db8..f67cf7d 100644 --- a/src/background.js +++ b/src/background.js @@ -40,7 +40,7 @@ async function createWindow() { createProtocol('app') win.loadURL(`${winURL}` + '/#/') - win.webContents.openDevTools({ mode: 'right' }); + // win.webContents.openDevTools({ mode: 'right' }); win.once('ready-to-show', () => { win.setTitle('Utils-Hub'); // 设置窗口标题 win.show(); diff --git a/src/views/AutoMode.vue b/src/views/AutoMode.vue index 2bb089f..7ff3a9a 100644 --- a/src/views/AutoMode.vue +++ b/src/views/AutoMode.vue @@ -259,9 +259,9 @@ export default { }; console.log("🔥 准备插入新记录:", newRecord); - this.allSavedFileList.unshift(newRecord); - this.total = this.allSavedFileList.length; - this.updateCurrentPageData(); + // this.allSavedFileList.unshift(newRecord); + // this.total = this.allSavedFileList.length; + // this.updateCurrentPageData(); console.log("🔥 已插入列表,当前总数:", this.total); // 调用上传接口 @@ -333,24 +333,29 @@ export default { record.analysisDate = JSON.stringify(result.data); // 保存上传记录到本地 - await window.api.saveFileInfo([{ - deviceId: device.code, - orderNumber: file.fileName.replace(/\.[^/.]+$/, ""), - deviceModel: device.codeType, - fileName: file.fileName, - analysisDate: JSON.stringify(result.data), - type: "auto", - date: this.getCurrentDateTime(), - uploadType: "自动上传", - }]); + await window.api.saveFileInfo([ + { + deviceId: device.code, + orderNumber: file.fileName.replace(/\.[^/.]+$/, ""), + deviceModel: device.codeType, + fileName: file.fileName, + analysisDate: JSON.stringify(result.data), + type: "auto", + date: this.getCurrentDateTime(), + uploadType: "自动上传", + }, + ]); console.log("自动上传成功"); this.lastUploadStatus = { title: "上传成功", type: "success" }; + this.getSavedFileInfo(); } else { - // 🔥 更新列表中的记录状态为失败 record.uploading = false; - record.analysisDate = "上传失败: " + result.msg; - console.error("上传失败:", result.msg); - this.lastUploadStatus = { title: result.msg, type: "error" }; + + record.analysisDate = "上传失败: " + (result.msg || "上传异常"); + this.lastUploadStatus = { + title: result.msg || "上传异常", + type: "error", + }; } } catch (err) { // 🔥 更新列表中的记录状态为失败 @@ -373,10 +378,32 @@ export default { this.tableLoading = true; const res = await window.api.getSavedFileInfo(); if (res.success) { - // 只显示自动上传的记录 - this.allSavedFileList = res.data.filter( + // 1. 筛选出自动上传的记录 + const autoUploadRecords = res.data.filter( (item) => item.uploadType === "自动上传" ); + + // 2. 去重逻辑:根据 orderNumber 和 fileName 去重,保留最新的一条 + // 假设 res.data 已经是按时间倒序排列(最新的在前) + const uniqueMap = new Map(); + + autoUploadRecords.forEach(item => { + // 生成唯一键:订单号_文件名 + // 如果 orderNumber 可能为空,可以加个默认值防止 key 冲突,例如: (item.orderNumber || 'unknown') + '_' + item.fileName + const key = `${item.orderNumber}_${item.fileName}`; + + // 如果 Map 中不存在该 key,则存入。 + // 因为是从前向后遍历(最新 -> 最旧),所以第一次遇到的就是最新的,后续的重复项会被忽略 + if (!uniqueMap.has(key)) { + uniqueMap.set(key, item); + } + }); + + // 3. 将 Map 的值转换回数组 + // 注意:Map.values() 保持插入顺序,所以这里依然是按时间倒序 + this.allSavedFileList = Array.from(uniqueMap.values()); + + // 4. 更新总数和当前页数据 this.total = this.allSavedFileList.length; this.updateCurrentPageData(); console.log(`成功读取${this.total}条自动上传记录`); diff --git a/src/views/ModeSelect.vue b/src/views/ModeSelect.vue index 9169c1d..857c7e9 100644 --- a/src/views/ModeSelect.vue +++ b/src/views/ModeSelect.vue @@ -34,6 +34,7 @@ export default { // 🔥 如果配置为自动检索模式,直接执行自动模式 if (this.configData && this.configData.device && this.configData.device.searchMode === "auto") { console.log("配置检测:自动检索模式,直接启动"); + window.api.stopWatchFolder(); await this.selectMode('auto'); return; // 不再继续执行后续代码 } diff --git a/src/views/config/configFile.vue b/src/views/config/configFile.vue index 46c17ac..81da35d 100644 --- a/src/views/config/configFile.vue +++ b/src/views/config/configFile.vue @@ -130,6 +130,8 @@ export default { file_path: "检索目录", no_report_path: "未上报目录", searchMode: "auto", + + updateFileName:'2' }, mqttInfo: { address: "tcp://127.0.0.1:1883/", @@ -140,6 +142,7 @@ export default { reconnect_time: "10", status_reporting_time: "10", topic: 'v1/telemetry/device/v1"', + updateFileName:'2' }, configData: {}, };