第一版提交,答题功能OK,题库管理待完善

This commit is contained in:
2025-12-18 19:07:21 +08:00
parent e5600535be
commit ba252b2f56
93 changed files with 20431 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
import sqlite3 from 'sqlite3';
import path from 'path';
const dbPath = path.join(process.cwd(), 'data', 'survey.db');
const db = new sqlite3.Database(dbPath);
db.run("ALTER TABLE users ADD COLUMN password TEXT", (err) => {
if (err) {
if (err.message.includes("duplicate column name")) {
console.log("Column 'password' already exists.");
} else {
console.error("Error adding column:", err.message);
process.exit(1);
}
} else {
console.log("Successfully added 'password' column to users table.");
}
db.close();
});

23
scripts/reset-admin.ts Normal file
View File

@@ -0,0 +1,23 @@
import { SystemConfigModel } from '../api/models/systemConfig';
async function resetAdmin() {
console.log('正在重置管理员账号...');
try {
await SystemConfigModel.updateConfig('admin_user', {
username: 'Admin',
password: '123456'
});
console.log('管理员账号重置成功!');
console.log('账号: Admin');
console.log('密码: 123456');
} catch (error) {
console.error('重置失败:', error);
}
// 等待一小会儿确保数据库操作完成
setTimeout(() => {
process.exit(0);
}, 1000);
}
resetAdmin();

132
scripts/seed.ts Normal file
View File

@@ -0,0 +1,132 @@
import { QuestionModel } from '../api/models/question';
import { db } from '../api/database';
const questions = [
// 单选题 (Single Choice)
{
content: 'React 是由哪个公司维护的开源项目?',
type: 'single',
options: ['Google', 'Facebook (Meta)', 'Apple', 'Microsoft'],
answer: 'Facebook (Meta)',
score: 5
},
{
content: '在 React 中,用于管理组件内部状态的 Hook 是?',
type: 'single',
options: ['useEffect', 'useContext', 'useState', 'useReducer'],
answer: 'useState',
score: 5
},
{
content: 'TypeScript 是哪种语言的超集?',
type: 'single',
options: ['Java', 'C#', 'JavaScript', 'Python'],
answer: 'JavaScript',
score: 5
},
{
content: 'HTTP 协议中,表示请求成功的状态码是?',
type: 'single',
options: ['200', '404', '500', '302'],
answer: '200',
score: 5
},
{
content: 'CSS 中,用于设置元素背景颜色的属性是?',
type: 'single',
options: ['color', 'background-color', 'border-color', 'font-color'],
answer: 'background-color',
score: 5
},
// 多选题 (Multiple Choice)
{
content: '以下哪些是常见的前端构建工具?',
type: 'multiple',
options: ['Webpack', 'Vite', 'Maven', 'Rollup'],
answer: ['Webpack', 'Vite', 'Rollup'],
score: 10
},
{
content: '以下哪些属于 HTML5 的新特性?',
type: 'multiple',
options: ['Canvas', 'LocalStorage', 'Flexbox', 'Semantic Tags (语义化标签)'],
answer: ['Canvas', 'LocalStorage', 'Semantic Tags (语义化标签)'],
score: 10
},
{
content: 'React 的生命周期方法(类组件)包括哪些?',
type: 'multiple',
options: ['componentDidMount', 'componentDidUpdate', 'componentWillUnmount', 'useEffect'],
answer: ['componentDidMount', 'componentDidUpdate', 'componentWillUnmount'],
score: 10
},
{
content: '以下哪些是 JavaScript 的基本数据类型?',
type: 'multiple',
options: ['String', 'Number', 'Boolean', 'Object'],
answer: ['String', 'Number', 'Boolean'],
score: 10
},
// 判断题 (Judgment)
{
content: 'HTML 是一种编程语言。',
type: 'judgment',
answer: '错误',
score: 5
},
{
content: '在 JavaScript 中null === undefined 的结果是 true。',
type: 'judgment',
answer: '错误',
score: 5
},
{
content: 'React 组件必须返回一个根元素。',
type: 'judgment',
answer: '正确',
score: 5
},
{
content: 'localStorage 存储的数据没有过期时间。',
type: 'judgment',
answer: '正确',
score: 5
},
// 文字题 (Text)
{
content: '请简述什么是闭包Closure。',
type: 'text',
answer: '闭包是指有权访问另一个函数作用域中的变量的函数。',
score: 15
},
{
content: '请解释 GET 和 POST 请求的主要区别。',
type: 'text',
answer: 'GET主要用于获取数据参数在URL中POST主要用于提交数据参数在请求体中。',
score: 15
}
];
async function seed() {
console.log('开始生成测试题库...');
try {
// @ts-ignore
const result = await QuestionModel.createMany(questions);
console.log(`成功生成 ${result.success} 道题目`);
if (result.errors.length > 0) {
console.error('部分题目生成失败:', result.errors);
}
} catch (error) {
console.error('生成题库失败:', error);
}
// 等待一小会儿确保数据库操作完成
setTimeout(() => {
process.exit(0);
}, 1000);
}
seed();