feat: 评分标准 JSON 导入/导出
This commit is contained in:
@@ -283,6 +283,37 @@ export function setupIpc(win: BrowserWindow): void {
|
||||
return null
|
||||
})
|
||||
|
||||
ipcMain.handle('rubric:exportJson', async () => {
|
||||
const d = getDb()
|
||||
const rows: any[] = d.prepare('SELECT * FROM rubric ORDER BY sort_order').all()
|
||||
if (!rows.length) throw new Error('暂无评分标准可导出')
|
||||
const questions = rows.map(r => ({
|
||||
questionTitle: r.question_title,
|
||||
maxScore: r.max_score,
|
||||
referenceAnswer: r.reference_answer,
|
||||
rubric: r.rubric
|
||||
}))
|
||||
const result = await dialogBox.showSaveDialog({
|
||||
defaultPath: '评分标准.json',
|
||||
filters: [{ name: 'JSON', extensions: ['json'] }]
|
||||
})
|
||||
if (result.canceled || !result.filePath) return false
|
||||
fs.writeFileSync(result.filePath, JSON.stringify(questions, null, 2), 'utf-8')
|
||||
return true
|
||||
})
|
||||
|
||||
ipcMain.handle('rubric:importJson', async () => {
|
||||
const result = await dialogBox.showOpenDialog({
|
||||
properties: ['openFile'],
|
||||
filters: [{ name: 'JSON', extensions: ['json'] }]
|
||||
})
|
||||
if (result.canceled || result.filePaths.length === 0) return null
|
||||
const content = fs.readFileSync(result.filePaths[0], 'utf-8')
|
||||
const questions = JSON.parse(content)
|
||||
if (!Array.isArray(questions)) throw new Error('JSON 格式错误:应为数组')
|
||||
return { questions, currentIndex: 0 }
|
||||
})
|
||||
|
||||
// --- Grading data bridge (toolbar → result window) ---
|
||||
ipcMain.handle('grading:storeData', (_event, data: any) => {
|
||||
gradingPayload = data
|
||||
|
||||
@@ -50,7 +50,9 @@ contextBridge.exposeInMainWorld('electronAPI', {
|
||||
|
||||
rubric: {
|
||||
storeData: (data: any) => ipcRenderer.invoke('rubric:storeData', data),
|
||||
getData: () => ipcRenderer.invoke('rubric:getData')
|
||||
getData: () => ipcRenderer.invoke('rubric:getData'),
|
||||
exportJson: () => ipcRenderer.invoke('rubric:exportJson'),
|
||||
importJson: () => ipcRenderer.invoke('rubric:importJson')
|
||||
},
|
||||
|
||||
template: {
|
||||
|
||||
Reference in New Issue
Block a user