|
|
|
@ -134,7 +134,8 @@ |
|
|
|
|
@update="e => updateSort(e, item)"> |
|
|
|
|
<div v-for="(ques, j) in item.examQuestions" :key="j" class="ques-item"> |
|
|
|
|
<el-checkbox v-model="ques.check"></el-checkbox> |
|
|
|
|
<div :class="['ques-info', { disabled: !ques.status, del: ques.isDel, repeat: ques.isRepeat }]"> |
|
|
|
|
{{ ques.repeat }} |
|
|
|
|
<div :class="['ques-info', { disabled: !ques.status, del: ques.isDel, repeat: ques.repeat }]"> |
|
|
|
|
<div class="top-line"> |
|
|
|
|
<div class="labels"> |
|
|
|
|
<span class="label">{{ j + 1 }} / {{ item.examQuestions.length }}</span> |
|
|
|
@ -189,25 +190,27 @@ |
|
|
|
|
<Manual :visible.sync="manualVisible" :questionType.sync="curType.questionType" /> |
|
|
|
|
<Auto :visible.sync="autoVisible" /> |
|
|
|
|
<Detail :visible.sync="quesVisible" :row.sync="curRow" :detailType.sync="detailType" @updateQues="updateQues" /> |
|
|
|
|
<RepeatQues :visible.sync="repeatVisible" :list.sync="repeatQues" /> |
|
|
|
|
</div> |
|
|
|
|
</template> |
|
|
|
|
<script> |
|
|
|
|
import Setting from '@/setting' |
|
|
|
|
import Util from '@/libs/util' |
|
|
|
|
import dayjs from 'dayjs' |
|
|
|
|
import Decimal from 'decimal.js' |
|
|
|
|
import Draggable from 'vuedraggable' |
|
|
|
|
import UeditorPlus from '@/components/ueditorPlus' |
|
|
|
|
import Breadcrumb from '@/components/breadcrumb' |
|
|
|
|
import QuesConst from '@/const/ques' |
|
|
|
|
import TestPaperConst from '@/const/testPaper' |
|
|
|
|
import Template from './template' |
|
|
|
|
import Manual from './manual' |
|
|
|
|
import Auto from './auto' |
|
|
|
|
import RepeatQues from './repeatQues' |
|
|
|
|
import Detail from '@/pages/ques/detail' |
|
|
|
|
import Setting from '@/setting' |
|
|
|
|
import Util from '@/libs/util' |
|
|
|
|
import dayjs from 'dayjs' |
|
|
|
|
import QuesConst from '@/const/ques' |
|
|
|
|
import TestPaperConst from '@/const/testPaper' |
|
|
|
|
import Decimal from 'decimal.js' |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
components: { UeditorPlus, Breadcrumb, Template, Manual, Auto, Detail, Draggable }, |
|
|
|
|
components: { UeditorPlus, Breadcrumb, Template, Manual, Auto, RepeatQues, Detail, Draggable }, |
|
|
|
|
data () { |
|
|
|
|
return { |
|
|
|
|
crumbs: [], |
|
|
|
@ -325,6 +328,7 @@ export default { |
|
|
|
|
repeatVisible: false, |
|
|
|
|
repeatQues: [], |
|
|
|
|
tempForm: {}, |
|
|
|
|
submiting: false, |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
computed: { |
|
|
|
@ -338,60 +342,6 @@ export default { |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
mounted () { |
|
|
|
|
function distributeScores (objects, totalScore) { |
|
|
|
|
const numObjects = objects.length; |
|
|
|
|
|
|
|
|
|
// 如果总分数小于数组长度,每个对象只能分配到一部分分数 |
|
|
|
|
const baseScore = totalScore / numObjects; |
|
|
|
|
const hasFraction = baseScore % 1 !== 0; // 判断是否有小数部分 |
|
|
|
|
|
|
|
|
|
// 分配整数部分 |
|
|
|
|
for (let i = 0; i < numObjects; i++) { |
|
|
|
|
objects[i].score = Math.floor(baseScore); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 如果有小数部分,计算小数部分的总和 |
|
|
|
|
let fractionalPartSum = 0; |
|
|
|
|
if (hasFraction) { |
|
|
|
|
for (let i = 0; i < numObjects; i++) { |
|
|
|
|
fractionalPartSum += baseScore % 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 分配小数部分 |
|
|
|
|
let remainingObjects = numObjects; |
|
|
|
|
while (fractionalPartSum > 0) { |
|
|
|
|
objects[--remainingObjects].score += 1; |
|
|
|
|
fractionalPartSum -= 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 如果总分数不足以给每个对象分配至少一分 |
|
|
|
|
if (totalScore < numObjects) { |
|
|
|
|
// 计算每个对象应该获得的小数部分 |
|
|
|
|
const fractionalDistribution = Math.ceil(fractionalPartSum); |
|
|
|
|
for (let i = 0; i < fractionalDistribution; i++) { |
|
|
|
|
objects[i].score += 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return objects; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 示例 |
|
|
|
|
const objects = [ |
|
|
|
|
{ id: 1 }, |
|
|
|
|
{ id: 2 }, |
|
|
|
|
{ id: 3 }, |
|
|
|
|
{ id: 4 } |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
const totalScore = 3; // 总分数小于数组长度 |
|
|
|
|
|
|
|
|
|
const result = distributeScores(objects, totalScore); |
|
|
|
|
console.log(result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.crumbs = [ |
|
|
|
|
{ |
|
|
|
|
name: '试卷管理', |
|
|
|
@ -473,8 +423,8 @@ export default { |
|
|
|
|
|
|
|
|
|
// 大纲题型选择回调 |
|
|
|
|
questionTypeChange (row) { |
|
|
|
|
// 如果大题名称还是默认的名字(即5个题型的名字),那么修改了题型后需要同步修改大题名称,用户自定义了大题名称,则不修改 |
|
|
|
|
if (this.questionTypes.find(e => e.name === row.outlineName)) row.outlineName = this.questionTypes.find(e => e.id === row.questionType).name |
|
|
|
|
// 如果大题名称为空,或者还是默认的名字(即5个题型的名字),那么修改了题型后需要同步修改大题名称,用户自定义了大题名称,则不修改 |
|
|
|
|
if (!row.outlineName || this.questionTypes.find(e => e.name === row.outlineName)) row.outlineName = this.questionTypes.find(e => e.id === row.questionType).name |
|
|
|
|
}, |
|
|
|
|
// 试卷大纲添加行 |
|
|
|
|
addLine (i) { |
|
|
|
@ -552,7 +502,7 @@ export default { |
|
|
|
|
data.avgValueList.map((e, i) => { |
|
|
|
|
// scores里有-1则不用循环 |
|
|
|
|
if (!e.scores.includes(-1)) { |
|
|
|
|
const stem = document.querySelector(`#stem` + e.questionId) |
|
|
|
|
const stem = document.querySelector(`#stem` + e.questionVersionId) |
|
|
|
|
if (stem) { |
|
|
|
|
const inputs = stem.querySelectorAll('.fill-input') |
|
|
|
|
if (inputs) { |
|
|
|
@ -695,21 +645,37 @@ export default { |
|
|
|
|
}, |
|
|
|
|
// 检查重复试题 |
|
|
|
|
hasRepeatQues (list) { |
|
|
|
|
const result = list.filter(e => { |
|
|
|
|
if (e.questionType !== 'fill_blank' && e.questionType !== 'essay') { |
|
|
|
|
// 选择和判断题则判断题型+题干+选项内容 |
|
|
|
|
const opts = e.questionAnswerVersionsList |
|
|
|
|
// 判断每个选项的内容是否相同(拿第一个选项的内容作基准) |
|
|
|
|
const first = opts[0].optionText |
|
|
|
|
const someOpt = opts.every(n => n.optionText === first) |
|
|
|
|
|
|
|
|
|
return e.questionType === e.questionType && e.stem === e.stem && someOpt |
|
|
|
|
} else { |
|
|
|
|
// 填空/问答:题干+题型一样即重复 |
|
|
|
|
return (e.questionType === e.questionType && e.stem === e.stem) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
list.forEach(e => { |
|
|
|
|
list.forEach(n => { |
|
|
|
|
if (e.questionVersionId !== n.questionVersionId && !e.repeat) { |
|
|
|
|
// 选择和判断题则判断题型+题干+选项内容 |
|
|
|
|
if (e.questionType !== 'fill_blank' && e.questionType !== 'essay') { |
|
|
|
|
// 判断每个选项的内容是否相同 |
|
|
|
|
const opts = e.questionAnswerVersionsList |
|
|
|
|
let diff = 0 |
|
|
|
|
for (const j in opts) { |
|
|
|
|
// debugger |
|
|
|
|
if (!n.questionAnswerVersionsList[j] || n.questionAnswerVersionsList[j].optionText !== opts[j].optionText) { |
|
|
|
|
diff = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.questionType === n.questionType && e.stem === n.stem && !diff) { |
|
|
|
|
e.repeat = true |
|
|
|
|
n.repeat = true |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
// 填空/问答:题干+题型一样即重复 |
|
|
|
|
if (e.questionType === n.questionType && e.stem === n.stem) { |
|
|
|
|
e.repeat = true |
|
|
|
|
n.repeat = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
const result = list.filter(e => e.repeat) |
|
|
|
|
// 如果有重复的试题,则弹框显示这些试题 |
|
|
|
|
if (result.length) { |
|
|
|
|
this.repeatVisible = true |
|
|
|
@ -737,13 +703,12 @@ export default { |
|
|
|
|
try { |
|
|
|
|
await this.$post(this.api.saveExamPaper, this.tempForm) |
|
|
|
|
Util.successMsg('保存成功') |
|
|
|
|
this.submiting = false |
|
|
|
|
this.back() |
|
|
|
|
} catch (e) { |
|
|
|
|
} finally { |
|
|
|
|
this.submiting = false |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 提交 |
|
|
|
|
// 提交验证及处理数据 |
|
|
|
|
async validForm (status) { |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
const { isCopy } = this // 复制 |
|
|
|
@ -819,11 +784,16 @@ export default { |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
e.examQuestions.map((n, j) => { |
|
|
|
|
n.outlineName = e.outlineName |
|
|
|
|
n.paperIndex = i |
|
|
|
|
n.quesIndex = j |
|
|
|
|
n.repeat = false |
|
|
|
|
}) |
|
|
|
|
allQues.push(...e.examQuestions) |
|
|
|
|
} |
|
|
|
|
if (invalid) return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.submiting = true |
|
|
|
|
|
|
|
|
|
form.particularYear = +(dayjs(form.particularYear).format('YYYY')) |
|
|
|
@ -877,8 +847,7 @@ export default { |
|
|
|
|
if (isCopy) form.paperId = '' |
|
|
|
|
this.tempForm = form |
|
|
|
|
|
|
|
|
|
// debugger |
|
|
|
|
// if (this.hasRepeatQues(allQues)) return false |
|
|
|
|
if (this.hasRepeatQues(allQues)) return false |
|
|
|
|
this.saveTestPaper() |
|
|
|
|
}, |
|
|
|
|
// 预览 |
|
|
|
@ -982,8 +951,11 @@ export default { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
&.repeat { |
|
|
|
|
border-color: #ff962a; |
|
|
|
|
|
|
|
|
|
&:after { |
|
|
|
|
content: '存在重复题'; |
|
|
|
|
background-color: #ff962a; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|