fix: handleSave 增加 try-catch & 深拷贝去代理后再 IPC
This commit is contained in:
@@ -255,6 +255,7 @@ export function setupIpc(win: BrowserWindow): void {
|
||||
ipcMain.handle('rubric:storeData', (_event, data: any) => {
|
||||
const d = getDb()
|
||||
const questions = data?.questions || []
|
||||
log.info(`rubric:storeData: ${questions.length} questions`, JSON.stringify(questions.map((q: any) => ({ title: q.questionTitle, rubricLen: q.rubric?.length }))))
|
||||
if (questions.length === 0) return
|
||||
d.prepare('DELETE FROM rubric').run()
|
||||
const insert = d.prepare('INSERT INTO rubric (question_title, max_score, reference_answer, rubric, sort_order) VALUES (?, ?, ?, ?, ?)')
|
||||
@@ -267,6 +268,7 @@ export function setupIpc(win: BrowserWindow): void {
|
||||
ipcMain.handle('rubric:getData', () => {
|
||||
const d = getDb()
|
||||
const rows: any[] = d.prepare('SELECT * FROM rubric ORDER BY sort_order').all()
|
||||
log.info(`rubric:getData: ${rows.length} rows`)
|
||||
if (rows.length) {
|
||||
return {
|
||||
questions: rows.map(r => ({
|
||||
|
||||
@@ -84,13 +84,17 @@ function removeQuestion(idx: number) {
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
gradingStore.setQuestions(JSON.parse(JSON.stringify(questions.value)))
|
||||
await window.electronAPI?.rubric.storeData({
|
||||
questions: questions.value,
|
||||
currentIndex: 0
|
||||
})
|
||||
ElMessage.success('评分标准已应用')
|
||||
handleClose()
|
||||
try {
|
||||
gradingStore.setQuestions(JSON.parse(JSON.stringify(questions.value)))
|
||||
await window.electronAPI?.rubric.storeData({
|
||||
questions: JSON.parse(JSON.stringify(questions.value)),
|
||||
currentIndex: 0
|
||||
})
|
||||
ElMessage.success('评分标准已应用')
|
||||
handleClose()
|
||||
} catch (err) {
|
||||
ElMessage.error('保存失败:' + (err as Error).message)
|
||||
}
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
|
||||
Reference in New Issue
Block a user