From 748140a0176b852cb8e82678fa452d5b7aa2e88d Mon Sep 17 00:00:00 2001 From: brianling Date: Thu, 16 Jul 2026 06:07:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=84=E5=88=86=E6=A0=87=E5=87=86?= =?UTF-8?q?=E6=8C=81=E4=B9=85=E5=8C=96=E5=88=B0=20SQLite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/ipc.ts | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/electron/main/ipc.ts b/electron/main/ipc.ts index 3cb79f0..9e721aa 100644 --- a/electron/main/ipc.ts +++ b/electron/main/ipc.ts @@ -58,6 +58,14 @@ function getDb() { max_score INTEGER, rubric TEXT )`).run() + db.prepare(`CREATE TABLE IF NOT EXISTS rubric ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + question_title TEXT NOT NULL DEFAULT '', + max_score REAL NOT NULL DEFAULT 100, + reference_answer TEXT NOT NULL DEFAULT '', + rubric TEXT NOT NULL DEFAULT '', + sort_order INTEGER NOT NULL DEFAULT 0 + )`).run() } return db } @@ -243,12 +251,36 @@ export function setupIpc(win: BrowserWindow): void { return { base64: buffer.toString('base64'), mime, filePath } }) - // --- Rubric data bridge (toolbar ↔ rubric window) --- + // --- Rubric data bridge (toolbar ↔ rubric window), persisted to DB --- ipcMain.handle('rubric:storeData', (_event, data: any) => { + const d = getDb() + d.prepare('DELETE FROM rubric').run() + const insert = d.prepare('INSERT INTO rubric (question_title, max_score, reference_answer, rubric, sort_order) VALUES (?, ?, ?, ?, ?)') + const questions = data?.questions || [] + for (let i = 0; i < questions.length; i++) { + const q = questions[i] + insert.run(q.questionTitle || '', q.maxScore ?? 100, q.referenceAnswer || '', q.rubric || '', i) + } rubricPayload = data }) - ipcMain.handle('rubric:getData', () => rubricPayload) + ipcMain.handle('rubric:getData', () => { + if (rubricPayload) return rubricPayload + const d = getDb() + const rows: any[] = d.prepare('SELECT * FROM rubric ORDER BY sort_order').all() + if (rows.length) { + return { + questions: rows.map(r => ({ + questionTitle: r.question_title, + maxScore: r.max_score, + referenceAnswer: r.reference_answer, + rubric: r.rubric + })), + currentIndex: 0 + } + } + return null + }) // --- Grading data bridge (toolbar → result window) --- ipcMain.handle('grading:storeData', (_event, data: any) => {