From ccef719c06c3d6bdbccb966c5d74d0ad102ed6a8 Mon Sep 17 00:00:00 2001 From: xiangcongshuai Date: Mon, 11 Aug 2025 15:08:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E5=AD=97=E4=BA=BA=E7=9B=B4=E6=92=AD?= =?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 --- electron/dbHandler.js | 127 +- electron/main.js | 21 +- electron/preload.js | 4 +- index.html | 2 +- package-lock.json | 24534 ------------------ package.json | 1 - pnpm-lock.yaml | 1991 +- src/api/chat.ts | 2 +- src/assets/live/loading.gif | Bin 0 -> 1301572 bytes src/components/NavBar/index.vue | 4 +- src/types/electron-api.d.ts | 2 + src/utils/httpProxy.ts | 2 +- src/views/AiLive/components/GoodsManage.vue | 117 +- src/views/AiLive/index.vue | 32 +- src/views/DigitalHuman/list/index.vue | 36 +- src/views/Live/index.vue | 154 +- src/views/login/index.vue | 2 +- 17 files changed, 1285 insertions(+), 25746 deletions(-) delete mode 100644 package-lock.json create mode 100644 src/assets/live/loading.gif diff --git a/electron/dbHandler.js b/electron/dbHandler.js index 25e7f69..37f70a3 100644 --- a/electron/dbHandler.js +++ b/electron/dbHandler.js @@ -3,13 +3,13 @@ const path = require("path"); const { app } = require("electron"); const { spawn, exec } = require("child_process"); -// 进程引用管理 +// 锟斤拷锟斤拷锟斤拷锟矫癸拷锟斤拷 const processes = { LiveTalkingProcess: null, gptsovitsProcess: null, chatProcess: null }; -// 获取数据库路径 +// 锟斤拷取锟斤拷锟捷匡拷路锟斤拷 function getDatabasePath() { if (process.env.NODE_ENV === "development") { const dbPath = path.join(__dirname, "..", "..", "live_chat.db"); @@ -17,28 +17,28 @@ function getDatabasePath() { } else { const exePath = app.getPath("exe"); - // 获取win-unpacked文件夹路径 + // 锟斤拷取win-unpacked锟侥硷拷锟斤拷路锟斤拷 const winUnpackedDir = path.dirname(exePath); - // 获取win-unpacked的上级目录(与win-unpacked同级的目录) + // 锟斤拷取win-unpacked锟斤拷锟较硷拷目录锟斤拷锟斤拷win-unpacked同锟斤拷锟斤拷目录锟斤拷 const parentDir = path.dirname(winUnpackedDir); - // 构建live_chat.db的完整路径 + // 锟斤拷锟斤拷live_chat.db锟斤拷锟斤拷锟斤拷路锟斤拷 const dbPath = path.join(parentDir, "live_chat.db"); console.log("dbPath", dbPath); return dbPath; } } -// 更新配置值 +// 锟斤拷锟斤拷锟斤拷锟斤拷值 function updateConfig(tableName, key, value) { return new Promise((resolve, reject) => { const db = new sqlite3.Database(getDatabasePath(), err => { if (err) { - console.error("数据库连接错误:", err.message); + console.error("锟斤拷锟捷匡拷锟斤拷锟接达拷锟斤拷:", err.message); return reject(err); } }); - // 先尝试更新,如果影响行数为0则插入新记录 + // 锟饺筹拷锟皆革拷锟铰o拷锟斤拷锟接帮拷锟斤拷锟斤拷锟轿0锟斤拷锟斤拷锟斤拷录锟铰 db.run( `UPDATE ${tableName} SET value = ? WHERE key = ?`, [value, key], @@ -48,7 +48,7 @@ function updateConfig(tableName, key, value) { return reject(err); } - // 如果没有匹配的记录则插入 + // 锟斤拷锟矫伙拷锟狡ワ拷锟侥硷拷录锟斤拷锟斤拷锟 if (this.changes === 0) { db.run( `INSERT INTO ${tableName} (key, value) VALUES (?, ?)`, @@ -72,7 +72,7 @@ function updateConfig(tableName, key, value) { }); } -// 获取配置值 +// 锟斤拷取锟斤拷锟斤拷值 function getConfigValue(tableName, key) { return new Promise((resolve, reject) => { const db = new sqlite3.Database(getDatabasePath(), err => { @@ -92,12 +92,44 @@ function getConfigValue(tableName, key) { ); }); } -// 批量插入系统消息 +function getAllSystemMessages() { + return new Promise((resolve, reject) => { + // 杩炴帴鏁版嵁搴 + const db = new sqlite3.Database(getDatabasePath(), err => { + if (err) { + console.error("鏁版嵁搴撹繛鎺ラ敊璇:", err.message); + return reject(err); + } + console.log("鎴愬姛杩炴帴鍒版暟鎹簱"); + }); + + // 鎵ц鏌ヨ + const sql = "SELECT message FROM system_message"; + db.all(sql, [], (err, rows) => { + // 鍏抽棴鏁版嵁搴撹繛鎺 + db.close(closeErr => { + if (closeErr) { + console.error("鍏抽棴鏁版嵁搴撻敊璇:", closeErr.message); + return reject(closeErr); + } + }); + + if (err) { + console.error("鏌ヨ閿欒:", err.message); + return reject(err); + } + + // 鎻愬彇鎵鏈塵essage瀛楁 + const messages = rows.map(row => row.message); + resolve(messages); + }); + }); +} +// 锟斤拷锟斤拷锟斤拷锟斤拷系统锟斤拷息 const bulkInsertSystemMessages = messages => { - console.log("系统消息:", messages); return new Promise((resolve, reject) => { if (!Array.isArray(messages) || messages.length === 0) { - reject(new Error("请提供有效的消息数组")); + reject(new Error("锟斤拷锟结供锟斤拷效锟斤拷锟斤拷息锟斤拷锟斤拷")); return; } @@ -108,7 +140,7 @@ const bulkInsertSystemMessages = messages => { return; } - // 使用事务进行批量插入,提高性能 + // 使锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷耄拷锟斤拷锟斤拷锟斤拷 db.run("BEGIN TRANSACTION", err => { if (err) { reject(err); @@ -130,7 +162,7 @@ const bulkInsertSystemMessages = messages => { completed++; - // 所有消息都处理完毕 + // 锟斤拷锟斤拷锟斤拷息锟斤拷锟斤拷锟斤拷锟斤拷锟 if (completed === messages.length) { stmt.finalize(); @@ -162,7 +194,7 @@ const bulkInsertSystemMessages = messages => { } }); }; -// 清空系统消息表 +// 锟斤拷锟较低筹拷锟较拷锟 const clearSystemMessages = () => { return new Promise((resolve, reject) => { const db = new sqlite3.Database(getDatabasePath(), err => { @@ -171,7 +203,7 @@ const clearSystemMessages = () => { return; } - // 使用TRUNCATE-like操作清空表,同时重置自增ID + // 使锟斤拷TRUNCATE-like锟斤拷锟斤拷锟斤拷毡锟斤拷锟酵憋拷锟斤拷锟斤拷锟斤拷锟絀D db.run("DELETE FROM system_message", err => { if (err) { reject(err); @@ -179,7 +211,7 @@ const clearSystemMessages = () => { return; } - // 重置自增计数器(SQLite特定) + // 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷SQLite锟截讹拷锟斤拷 db.run( "DELETE FROM sqlite_sequence WHERE name = 'system_message'", err => { @@ -198,31 +230,31 @@ const clearSystemMessages = () => { function getProcessExePath(fileName, exeName) { let exePath; let exeFolder; - // 判断是否为开发环境 + // 锟叫讹拷锟角凤拷为锟斤拷锟斤拷锟斤拷锟斤拷 if (process.env.NODE_ENV === "development") { - // process.cwd() 通常指向项目根目录 + // process.cwd() 通锟斤拷指锟斤拷锟斤拷目锟斤拷目录 const projectRoot = process.cwd(); const parentDir = path.dirname(projectRoot); exePath = path.join(parentDir, fileName, exeName); exeFolder = path.join(parentDir, fileName); } else { - // 生产环境: 与win-unpacked同级目录下的LiveTalking文件夹 + // 锟斤拷锟斤拷锟斤拷锟斤拷: 锟斤拷win-unpacked同锟斤拷目录锟铰碉拷LiveTalking锟侥硷拷锟斤拷 exePath = app.getPath("exe"); - // 获取win-unpacked文件夹路径 + // 锟斤拷取win-unpacked锟侥硷拷锟斤拷路锟斤拷 const winUnpackedDir = path.dirname(exePath); - // 获取win-unpacked的上级目录 + // 锟斤拷取win-unpacked锟斤拷锟较硷拷目录 const parentDir = path.dirname(winUnpackedDir); exePath = path.join(parentDir, fileName, exeName); exeFolder = path.join(parentDir, fileName); } console.log("exePath", exePath); console.log("exeFolder", exeFolder); - // 标准化路径格式 + // 锟斤拷准锟斤拷路锟斤拷锟斤拷式 return { exePath, exeFolder }; } /** - * 启动LiveTalking.exe + * 锟斤拷锟斤拷LiveTalking.exe */ async function startProcess(fileName, exeName) { return new Promise(async (resolve, reject) => { @@ -232,38 +264,48 @@ async function startProcess(fileName, exeName) { return; } - // 获取程序路径 + // 锟斤拷取锟斤拷锟斤拷路锟斤拷 const obj = getProcessExePath(fileName, exeName); try { - // 启动进程时,通过wmic获取详细信息(仅Windows) - const newProcess = spawn("cmd.exe", ["/c", obj.exePath], { - // 直接运行bat,不使用start命令 - cwd: obj.exeFolder, - windowsVerbatimArguments: true, - windowsHide: false, - detached: false // 不分离,便于跟踪子进程 - }); + // 锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷通锟斤拷wmic锟斤拷取锟斤拷细锟斤拷息锟斤拷锟斤拷Windows锟斤拷 + // const newProcess = spawn("cmd.exe", ["/c", obj.exePath], { + // // 直锟斤拷锟斤拷锟斤拷bat锟斤拷锟斤拷使锟斤拷start锟斤拷锟斤拷 + // cwd: obj.exeFolder, + // windowsVerbatimArguments: true, + // windowsHide: false, + // detached: false // 锟斤拷锟斤拷锟诫,锟斤拷锟节革拷锟斤拷锟接斤拷锟斤拷 + // }); - // 记录进程ID(关键:保存实际PID) + const newProcess = spawn( + "cmd.exe", + ["/c", "start", '""', `"${obj.exePath}"`], + { + cwd: obj.exeFolder, + windowsVerbatimArguments: true, + windowsHide: false, + detached: true + } + ); + // 锟斤拷录锟斤拷锟斤拷ID锟斤拷锟截硷拷锟斤拷锟斤拷锟斤拷实锟斤拷PID锟斤拷 processes[processKey] = { process: newProcess, - pid: newProcess.pid // 保存PID用于后续终止 + pid: newProcess.pid // 锟斤拷锟斤拷PID锟斤拷锟节猴拷锟斤拷锟斤拷止 }; newProcess.on("error", err => { processes[processKey] = null; - reject(`启动失败: ${err.message}`); + reject(`锟斤拷锟斤拷失锟斤拷: ${err.message}`); }); console.log(`spawned with PID ${newProcess.pid}`); - resolve(`${fileName} 启动成功 (PID: ${newProcess.pid})`); + resolve(`${fileName} 锟斤拷锟斤拷锟缴癸拷 (PID: ${newProcess.pid})`); } catch (err) { - reject(`启动异常: ${err.message}`); + reject(`锟斤拷锟斤拷锟届常: ${err.message}`); } }); } -// 停止所有进程 +// 停止锟斤拷锟叫斤拷锟斤拷 async function stopAllProcesses() { try { - // 清空所有属性,变成空对象 + // 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷裕锟斤拷锟缴空讹拷锟斤拷 for (const key in processes) { if (processes[key]) { delete processes[key]; @@ -289,5 +331,6 @@ module.exports = { bulkInsertSystemMessages, clearSystemMessages, startProcess, - stopAllProcesses + stopAllProcesses, + getAllSystemMessages }; diff --git a/electron/main.js b/electron/main.js index 40fd3ab..dccf920 100644 --- a/electron/main.js +++ b/electron/main.js @@ -7,7 +7,9 @@ const { bulkInsertSystemMessages, stopProcess, startProcess, - stopAllProcesses + stopAllProcesses, + getAllSystemMessages, + clearSystemMessages } = require("./dbHandler"); // 娉ㄥ唽IPC閫氫俊澶勭悊 @@ -38,6 +40,15 @@ function registerIpcHandlers() { throw error; } }); + ipcMain.handle("clear-system-messages", async () => { + try { + return await clearSystemMessages(); + } catch (error) { + console.error("鍋滄澶辫触:", error); + throw error; + } + }); + ipcMain.handle("start-process", async (event, fileName, exeName) => { try { return await startProcess(fileName, exeName); @@ -62,6 +73,14 @@ function registerIpcHandlers() { throw error; } }); + ipcMain.handle("get-all-system-messages", async () => { + try { + return await getAllSystemMessages(); + } catch (error) { + console.error("鍋滄澶辫触:", error); + throw error; + } + }); } function createWindow() { const win = new BrowserWindow({ diff --git a/electron/preload.js b/electron/preload.js index 630d432..f9bbef1 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -16,5 +16,7 @@ contextBridge.exposeInMainWorld("electronAPI", { ipcRenderer.invoke("start-process", fileName, exeName), stopProcess: (fileName, exeName) => ipcRenderer.invoke("stop-process", fileName, exeName), - stopAllProcesses: () => ipcRenderer.invoke("stop-all-process") + stopAllProcesses: () => ipcRenderer.invoke("stop-all-process"), + clearSystemMessages: () => ipcRenderer.invoke("clear-system-messages"), + getAllSystemMessages: () => ipcRenderer.invoke("get-all-system-messages") }); diff --git a/index.html b/index.html index 684732a..e229083 100644 --- a/index.html +++ b/index.html @@ -7,7 +7,7 @@ - 鏅鸿兘灏忓姪鎵 + 鐩存挱鏁板瓧浜 @@ -16,7 +16,7 @@ onMounted(() => {});