Files

133 lines
3.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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();