@@ -109,6 +116,8 @@
import Header from '../components/common/Header.vue'
import Footer from '../components/common/Footer.vue'
import { Message } from 'element-ui'
+// 导入Vuex store
+import store from '../store/index.js'
export default {
name: 'WelcomeView',
@@ -116,7 +125,7 @@ export default {
Header,
Footer
},
- data() {
+ data () {
return {
examineeIdCard: '', // 身份证号
examineeAdmissionTicket: '', // 准考证号
@@ -126,158 +135,179 @@ export default {
isLoading: false // 添加加载状态
}
},
- mounted() {
+ mounted () {
this.checkDatabaseStatus()
},
methods: {
- async checkDatabaseStatus() {
+ async checkDatabaseStatus () {
try {
- console.log('组件挂载 - 开始检查数据库初始化状态');
- const initialized = await window.electronAPI.checkDatabaseInitialized();
- console.log('组件挂载 - 数据库初始化状态检查完成:', initialized);
- this.isDatabaseInitialized = initialized;
+ console.log('组件挂载 - 开始检查数据库初始化状态')
+ const initialized = await window.electronAPI.checkDatabaseInitialized()
+ console.log('组件挂载 - 数据库初始化状态检查完成:', initialized)
+ this.isDatabaseInitialized = initialized
} catch (error) {
- console.error('检查数据库初始化状态失败:', error);
- Message.error('检查数据库初始化状态失败,请重试');
+ console.error('检查数据库初始化状态失败:', error)
+ Message.error('检查数据库初始化状态失败,请重试')
}
},
- async initializeDatabase() {
+ async initializeDatabase () {
try {
- console.log('初始化数据库 - 开始');
- this.isInitializing = true;
- Message.info('开始初始化数据库...');
+ console.log('初始化数据库 - 开始')
+ this.isInitializing = true
+ Message.info('开始初始化数据库...')
- const result = await window.electronAPI.initializeDatabase();
- console.log('初始化数据库 - 结果:', result);
+ const result = await window.electronAPI.initializeDatabase()
+ console.log('初始化数据库 - 结果:', result)
// 修复:同时处理布尔值true和带success属性的对象
if (result === true || (result && result.success)) {
- Message.success('数据库初始化成功!');
- console.log('初始化数据库 - 成功,更新初始化状态');
- this.isDatabaseInitialized = true;
+ Message.success('数据库初始化成功!')
+ console.log('初始化数据库 - 成功,更新初始化状态')
+ this.isDatabaseInitialized = true
} else {
- const errorMessage = result && result.error ? result.error : '未知错误';
- Message.error(`数据库初始化失败: ${errorMessage}`);
- console.error('初始化数据库 - 失败:', errorMessage);
+ const errorMessage = result && result.error ? result.error : '未知错误'
+ Message.error(`数据库初始化失败: ${errorMessage}`)
+ console.error('初始化数据库 - 失败:', errorMessage)
}
} catch (error) {
- console.error('数据库初始化失败:', error);
- Message.error(`数据库初始化失败: ${error.message || '未知错误'}`);
+ console.error('数据库初始化失败:', error)
+ Message.error(`数据库初始化失败: ${error.message || '未知错误'}`)
} finally {
- console.log('初始化数据库 - 结束');
- this.isInitializing = false;
+ console.log('初始化数据库 - 结束')
+ this.isInitializing = false
}
},
- async handleExamineeLogin() {
+ async handleExamineeLogin () {
console.log('考生登录 - 开始', {
examineeIdCard: this.examineeIdCard,
examineeAdmissionTicket: this.examineeAdmissionTicket
- });
+ })
// 清除首尾空格
- const idCard = this.examineeIdCard.trim();
- const admissionTicket = this.examineeAdmissionTicket.trim();
+ const idCard = this.examineeIdCard.trim()
+ const admissionTicket = this.examineeAdmissionTicket.trim()
// 前端验证
if (!idCard || !admissionTicket) {
- console.warn('考生登录 - 验证失败: 身份证号和准考证号不能为空');
- Message.error('请输入身份证号和准考证号');
- return;
+ console.warn('考生登录 - 验证失败: 身份证号和准考证号不能为空')
+ Message.error('请输入身份证号和准考证号')
+ return
}
// 设置加载状态
- this.isLoading = true;
+ this.isLoading = true
try {
- // 调用登录API
- const result = await window.electronAPI.userLogin(idCard, admissionTicket);
- console.log(result);
+ // 调用登录API - 使用正确的参数格式
+ const result = await window.electronAPI.userLogin({ idCard, admissionTicket })
+ console.log('考生登录 - 结果:', result)
if (result && result.id) {
- console.log('考生登录 - 成功', result);
- // 保存用户信息到store - 在Vue 2中通常使用Vuex
- if (this.$store && this.$store.commit) {
- this.$store.commit('setExaminee', result);
- }
- Message.success('登录成功');
+ console.log('考生登录 - 成功', result)
+ // 保存用户信息到store
+ this.$store.commit('setExaminee', result)
+ Message.success('登录成功')
// 跳转到考生首页
- this.$router.push('/examinee/home');
+ this.$router.push('/examinee/home')
} else {
- console.warn('考生登录 - 失败:', result);
- Message.error(result.error || '登录失败,请检查身份证号和准考证号');
+ console.warn('考生登录 - 失败:', result)
+ Message.error(result && result.error ? result.error : '登录失败,请检查身份证号和准考证号')
}
} catch (error) {
- console.error('考生登录 - 异常:', error);
- Message.error('登录失败,请重试');
+ console.error('考生登录 - 异常:', error)
+ Message.error(`登录失败: ${error.message || '未知错误'}`)
} finally {
// 无论成功失败,都关闭加载状态
- this.isLoading = false;
+ this.isLoading = false
}
},
- async handleAdminLogin() {
- console.log('管理员登录 - 开始', { passwordLength: this.adminPassword.length });
+ // 修改handleAdminLogin方法
+ async handleAdminLogin () {
+ console.log('管理员登录 - 开始', { passwordLength: this.adminPassword.length })
// 前端密码验证
- const passwordError = this.validateAdminPassword(this.adminPassword);
+ const passwordError = this.validateAdminPassword(this.adminPassword)
if (passwordError) {
- console.warn('管理员登录 - 验证失败:', passwordError);
- const errorElement = document.getElementById('admin-error-message');
+ console.warn('管理员登录 - 验证失败:', passwordError)
+ const errorElement = document.getElementById('admin-error-message')
if (errorElement) {
- errorElement.textContent = passwordError;
- errorElement.style.display = 'block';
+ errorElement.textContent = passwordError
+ errorElement.style.display = 'block'
}
- return;
+ return
}
// 清除之前的错误信息
- const errorElement = document.getElementById('admin-error-message');
+ const errorElement = document.getElementById('admin-error-message')
if (errorElement) {
- errorElement.style.display = 'none';
+ errorElement.style.display = 'none'
}
try {
- console.log('管理员登录 - 调用主进程登录方法');
+ console.log('管理员登录 - 调用主进程登录方法')
// 使用新的adminLogin方法
const result = await window.electronAPI.adminLogin({
username: 'admin',
password: this.adminPassword
- });
- console.log('管理员登录 - 登录结果:', result);
+ })
+ console.log('管理员登录 - 登录结果:', result)
if (result && result.success) {
- console.log('管理员登录 - 成功,跳转到管理首页');
- Message.success('登录成功');
- this.$router.push('/admin/home');
+ console.log('管理员登录 - 成功,更新store状态并跳转')
+ // 使用新的setAdmin mutation
+ this.$store.commit('setAdmin', { username: 'admin' })
+ Message.success('登录成功')
+ this.$router.push('/admin/home')
} else {
- const errorMessage = result && result.message ? result.message : '登录失败';
- console.warn('管理员登录 - 失败:', errorMessage);
- Message.error(errorMessage);
+ const errorMessage = result && result.message ? result.message : '登录失败'
+ console.warn('管理员登录 - 失败:', errorMessage)
+ Message.error(errorMessage)
}
} catch (error) {
- console.error('管理员登录 - 异常:', error);
- Message.error(`登录异常: ${error.message || '未知错误'}`);
+ console.error('管理员登录 - 异常:', error)
+ Message.error(`登录异常: ${error.message || '未知错误'}`)
}
},
- validateAdminPassword(password) {
+ validateAdminPassword (password) {
// 检查密码是否为空
if (!password) {
- return '请输入管理员密码';
+ return '请输入管理员密码'
}
// 检查密码长度
if (password.length < 4 || password.length > 32) {
- return '密码长度必须在4-32个字符之间';
+ return '密码长度必须在4-32个字符之间'
}
// 检查密码是否只包含英文大小写和数字
- const regex = /^[A-Za-z0-9]+$/;
+ const regex = /^[A-Za-z0-9]+$/
if (!regex.test(password)) {
- return '密码只能包含英文大小写字母和数字';
+ return '密码只能包含英文大小写字母和数字'
}
- return null;
- }
+ return null
+ },
+ // 修改exitExam方法
+ async exitExam () {
+ this.$confirm(
+ '确定要退出考试吗?',
+ '退出确认',
+ {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ type: 'warning'
+ }
+ ).then(() => {
+ // 完全清除store中的数据
+ this.$store.commit('clearUser')
+ // 重定向到欢迎页
+ this.$router.push('/')
+ }).catch(() => {
+ // 用户取消操作
+ console.log('用户取消退出')
+ })
+ },
}
}
@@ -311,9 +341,12 @@ export default {
.main-background {
background-image: url('../assets/bg.jpeg');
- background-size: 100% 100%; /* 拉伸背景图以填满容器 */
- background-position: center; /* 保持居中 */
- background-repeat: no-repeat; /* 避免重复 */
+ background-size: 100% 100%;
+ /* 拉伸背景图以填满容器 */
+ background-position: center;
+ /* 保持居中 */
+ background-repeat: no-repeat;
+ /* 避免重复 */
}
/* 适配移动设备 */
diff --git a/src/views/user/ExamineeHomeView.vue b/src/views/user/ExamineeHomeView.vue
new file mode 100644
index 0000000..fbdae80
--- /dev/null
+++ b/src/views/user/ExamineeHomeView.vue
@@ -0,0 +1,413 @@
+
+
+
+
+
+
+
+
考生信息
+
+
+
+
+
+
+
+ 姓名
+
+
+ {{ examinee && examinee.examinee_name }}
+
+
+
+
+
+ 身份证号
+
+
+ {{ formatIdCard(examinee && examinee.examinee_id_card) }}
+
+
+
+
+
+ 准考证号
+
+
+ {{ examinee && examinee.examinee_admission_ticket }}
+
+
+
+
+
考试信息
+
+
+
+
+
+
+
+ 考试时长
+
+
+ {{ lastExam && lastExam.exam_minutes }}分钟
+
+
+
+
+
+ 最短考试时长
+
+
+ {{ lastExam && lastExam.exam_minutes_min }}分钟
+
+
+
+
+
+ 考题数量
+
+
+ {{ totalQuestions }}
+
+
+
+
+
+ 考试总分
+
+
+ {{ totalScore }}
+
+
+
+
+
+
考试须知
+
+
+
+
+ 加载考试信息中...
+
+
+ 暂无考试须知
+
+
+
+ 返回
+ 开始考试
+
+
+
+
+
+
+
+
+
\ No newline at end of file