第一版完成
This commit is contained in:
parent
e2b5844fec
commit
5acfcbdc38
@ -1,5 +1,5 @@
|
||||
// 确保所有导入都使用 ES 模块语法
|
||||
import { app, BrowserWindow, ipcMain } from "electron";
|
||||
import { app, BrowserWindow, ipcMain, dialog } from "electron";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import {
|
||||
@ -68,7 +68,9 @@ function createWindow() {
|
||||
}
|
||||
|
||||
mainWindow = new BrowserWindow({
|
||||
fullscreen: true,
|
||||
// 将fullscreen改为false,添加maximized: true
|
||||
fullscreen: false,
|
||||
maximized: true,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, "../electron/preload.js"),
|
||||
nodeIntegration: false,
|
||||
@ -83,6 +85,28 @@ function createWindow() {
|
||||
mainWindow.loadFile(path.join(__dirname, "../dist/index.html"));
|
||||
}
|
||||
|
||||
// 添加窗口关闭前的确认对话框
|
||||
mainWindow.on('close', (event) => {
|
||||
// 阻止默认关闭行为
|
||||
event.preventDefault();
|
||||
|
||||
// 显示确认对话框
|
||||
dialog.showMessageBox({
|
||||
type: 'warning',
|
||||
title: '关闭确认',
|
||||
message: '系统关闭后,已进行中的试卷将不会被保存,是否确认要关闭?',
|
||||
buttons: ['取消', '确认关闭'],
|
||||
defaultId: 0
|
||||
}).then((result) => {
|
||||
// 如果用户点击确认关闭
|
||||
if (result.response === 1) {
|
||||
// 允许窗口关闭
|
||||
mainWindow.destroy();
|
||||
}
|
||||
// 否则取消关闭
|
||||
});
|
||||
});
|
||||
|
||||
// 当窗口关闭时,清空引用
|
||||
mainWindow.on("closed", () => {
|
||||
mainWindow = null;
|
||||
@ -97,6 +121,9 @@ app.whenReady().then(() => {
|
||||
});
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
// 在所有窗口关闭后,清空主窗口引用
|
||||
mainWindow = null;
|
||||
// 对于非macOS平台,仍然需要退出应用
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
|
@ -205,15 +205,6 @@ export async function initExamIpc(ipcMain) {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("exam-fetch-last", async () => {
|
||||
try {
|
||||
return { success: true, data: await fetchLastExam() };
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch last exam:", error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("exam-fetch-by-id", async (event, id) => {
|
||||
try {
|
||||
return { success: true, data: await fetchExamById(id) };
|
||||
@ -223,15 +214,6 @@ export async function initExamIpc(ipcMain) {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("exam-update", async (event, { id, examData }) => {
|
||||
try {
|
||||
const result = await modifyExam(id, examData);
|
||||
return { success: result, data: { id, ...examData } };
|
||||
} catch (error) {
|
||||
console.error(`Failed to update exam ${id}:`, error);
|
||||
return { success: false, error: error.message };
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle("exam-delete", async (event, id) => {
|
||||
try {
|
||||
|
11
package.json
11
package.json
@ -13,7 +13,8 @@
|
||||
"build": "vite build",
|
||||
"preview": "vite preview",
|
||||
"electron:dev": "vite --mode electron",
|
||||
"electron:build": "vite build && electron-builder"
|
||||
"electron:build": "vite build && electron-builder",
|
||||
"electron:build:win": "vite build && electron-builder --win --x64"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.3.1",
|
||||
@ -58,11 +59,12 @@
|
||||
{
|
||||
"target": "nsis",
|
||||
"arch": [
|
||||
"ia32"
|
||||
"x64"
|
||||
]
|
||||
}
|
||||
],
|
||||
"icon": "public/favicon.ico"
|
||||
"icon": "public/favicon.ico",
|
||||
"artifactName": "${productName}-${version}-win64.${ext}"
|
||||
},
|
||||
"nsis": {
|
||||
"oneClick": false,
|
||||
@ -73,7 +75,8 @@
|
||||
"installerHeaderIcon": "public/favicon.ico",
|
||||
"createDesktopShortcut": true,
|
||||
"createStartMenuShortcut": true,
|
||||
"shortcutName": "电子考试系统"
|
||||
"shortcutName": "电子考试系统",
|
||||
"runAfterFinish": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,9 +9,11 @@
|
||||
<!-- 交卷结果卡片 -->
|
||||
<div class="bg-white rounded-4 shadow-lg p-4 w-100 max-w-2xl border-2 border-primary/20">
|
||||
<el-result icon="success" title="考试已完成" sub-title="您已成功提交试卷,感谢您的参与!">
|
||||
<!---
|
||||
<template #extra>
|
||||
<el-button type="primary" @click="goHome">返回首页</el-button>
|
||||
</template>
|
||||
-->
|
||||
</el-result>
|
||||
|
||||
<el-divider />
|
||||
|
Loading…
Reference in New Issue
Block a user