157 lines
7.2 KiB
JavaScript
157 lines
7.2 KiB
JavaScript
const batchInsert = {
|
||
template: `
|
||
<el-dialog title="批量添加1111" :visible.sync="visible" width="70%" top="50px" :close-on-click-modal="false">
|
||
<div style="display: flex;justify-content: space-between;align-items: center">
|
||
<p style="line-height: 24px;margin-bottom: 10px;color: #333;">1、题目的识别基于标题前的题型说明,放在标题的前面,格式为“<span>[题型]标题内容((描述))</span>“<br>2、题干与选项,及各选项之间需回车换行</p>
|
||
<el-button size="medium">清空文本</el-button>
|
||
<div>
|
||
{{errorMsg}}
|
||
</div>
|
||
</div>
|
||
|
||
<div style="display: flex;height: 60vh;max-height: 1000px;border: 1px solid #ccc;">
|
||
<div style="border-right: 1px solid #ccc;height: 100%;width: 50%;overflow: auto">
|
||
<textarea name="txtContentNew"
|
||
v-model="txt"
|
||
cols="20"
|
||
rows="2"
|
||
wrap="off"
|
||
style="height: 59vh;width: 100%;overflow: auto;border: none;padding: 20px 10px 10px;display:inline-block;line-height: 20px;outline: none;"
|
||
placeholder=""></textarea>
|
||
</div>
|
||
<div style="height: 100%;width: 50%;overflow: auto;padding: 20px 10px 10px">
|
||
<div v-for="(issue,index) in issues" :key="index" style="margin-bottom: 10px">
|
||
<div style="display: flex">
|
||
<div>{{index+1}}、{{issue.iname}}</div>
|
||
</div>
|
||
<div v-if="issue.wors">
|
||
<el-radio-group v-if="issue.iisdx">
|
||
<div v-for="wor in issue.wors" :key="wor.wtxt">
|
||
<el-radio :label="wor.wtxt">{{wor.wtxt}}</el-radio>
|
||
</div>
|
||
</el-radio-group>
|
||
<el-checkbox-group v-if="!issue.iisdx">
|
||
<el-radio :label="wor.wtxt" :key="wor.wtxt" v-for="wor in issue.wors">{{wor.wtxt}}</el-radio>
|
||
</el-checkbox-group>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div slot="footer" class="dialog-footer">
|
||
<el-button @click="visible = false">取 消</el-button>
|
||
<el-button type="primary" @click="confirm">确 定</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
`,
|
||
data() {
|
||
return {
|
||
visible: false,
|
||
txt: null,
|
||
errorMsg: null
|
||
}
|
||
},
|
||
computed: {
|
||
issues() {
|
||
if (!this.txt) {
|
||
return []
|
||
}
|
||
let errorMsg = ''
|
||
|
||
// 使用正则表达式分割文本为单独的问题
|
||
// const questionTexts = this.txt.split('\n').map(line => line.trim()).join(); // 每个问题之间用换行符分隔
|
||
const questionTexts = this.txt.split('\n').map(v => v.trim()).join('\n').split("\n\n")
|
||
// 初始化问题数组
|
||
const questions = [];
|
||
// 遍历每个问题文本
|
||
questionTexts.forEach((questionText, index) => {
|
||
debugger
|
||
// 提取问题编号和题干
|
||
const match = questionText.trim().split('\n').slice(0, 1).join('').match(/^(?:\d+\.|\d+、)?\s*(.*?)\s*\[(.*题)\]\s*(?:\((\d+)分\)|\((\d+)分\))?$/);
|
||
if (match) {
|
||
const questionContent = match[1].trim();
|
||
const questionType = match[2];
|
||
const scoreChinese = match[3];
|
||
const scoreEnglish = match[4];
|
||
const score = scoreChinese || scoreEnglish;
|
||
|
||
// 题型合法性校验
|
||
const validTypes = ['多选题', '单选题'];
|
||
if (!validTypes.includes(questionType)) {
|
||
console.warn('问题' + (index + 1) + '的题型不合法: ' + questionType);
|
||
errorMsg += '\n问题' + (index + 1) + '的题型不合法: ' + questionType;
|
||
return;
|
||
}
|
||
|
||
// 分数格式校验
|
||
if (score) {
|
||
const scoreNumber = parseInt(score, 10);
|
||
if (isNaN(scoreNumber)) {
|
||
console.warn('问题' + (index + 1) + '的分数格式无效: ' + score);
|
||
errorMsg += '\n问题' + (index + 1) + '的分数格式无效: ' + score;
|
||
return;
|
||
}
|
||
}
|
||
|
||
// 提取选项
|
||
const optionTexts = questionText.replaceAll(match.input, "").split('\n').slice(1).filter(line => line.trim()); // 假设选项从第二行开始
|
||
const options = [];
|
||
|
||
optionTexts.forEach(optionText => {
|
||
// 使用正则表达式提取选项名称和是否正确
|
||
const optionMatch = optionText.match(/^([A-Z])\.?(.+?)\((正确答案|错误答案)\)/);
|
||
if (optionMatch) {
|
||
const optionName = optionMatch[1] + optionMatch[2].trim();
|
||
const isCorrect = optionMatch[3] === '正确答案';
|
||
options.push({wtxt: optionName, correct: isCorrect});
|
||
} else {
|
||
options.push({wtxt: optionText.trim(), correct: false});
|
||
}
|
||
});
|
||
|
||
// 构建问题对象
|
||
const question = {
|
||
//是否必答
|
||
iisbd: true,
|
||
//单选还是多选
|
||
iisdx: questionType === '单选题',
|
||
//是否随机选项???
|
||
iisrandom: false,
|
||
//题干
|
||
iname: questionContent,
|
||
//排列方式 没用
|
||
iplfs: 1,
|
||
//提示
|
||
its: null,
|
||
//题型 (1 选择题 2 填空题 3 判断题)
|
||
itx: (questionType === '单选题' || questionType === '多选题') ? 1 : 3,
|
||
//分数
|
||
fraction: score,
|
||
//选项
|
||
wors: options
|
||
};
|
||
// 添加到问题数组中
|
||
questions.push(question);
|
||
}
|
||
});
|
||
this.errorMsg = errorMsg
|
||
console.log(questions)
|
||
return questions
|
||
}
|
||
},
|
||
methods: {
|
||
onOpen() {
|
||
debugger
|
||
this.txt = null
|
||
this.visible = true
|
||
},
|
||
async confirm() {
|
||
if (this.errorMsg) {
|
||
this.$message.warning('存在不合法的题目,请调整后再提交')
|
||
return
|
||
}
|
||
this.$emit('confirm', this.issues)
|
||
this.visible = false
|
||
},
|
||
}
|
||
}
|