|
|
|
@ -310,6 +310,11 @@ export default { |
|
|
|
|
detailType: '', |
|
|
|
|
|
|
|
|
|
difficultSelected: false, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
repeatVisible: false, |
|
|
|
|
repeatQues: [], |
|
|
|
|
tempForm: {}, |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
computed: { |
|
|
|
@ -671,137 +676,186 @@ export default { |
|
|
|
|
item.examQuestions.splice(i, 1) |
|
|
|
|
this.calcDifficult() |
|
|
|
|
}, |
|
|
|
|
// 检查重复试题 |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 如果有重复的试题,则弹框显示这些试题 |
|
|
|
|
if (result.length) { |
|
|
|
|
this.repeatVisible = true |
|
|
|
|
this.repeatQues = result |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
return false |
|
|
|
|
}, |
|
|
|
|
// 提交 |
|
|
|
|
submit (status) { |
|
|
|
|
if (status) { |
|
|
|
|
// 草稿只需判断名字有没有填 |
|
|
|
|
if (!this.form.name) return Util.warningMsg('请输入试卷名称') |
|
|
|
|
this.validForm(status) |
|
|
|
|
} else { |
|
|
|
|
this.$refs.form.validate(async (valid) => { |
|
|
|
|
if (valid) { |
|
|
|
|
this.validForm(status) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 保存发送请求 |
|
|
|
|
async saveTestPaper () { |
|
|
|
|
try { |
|
|
|
|
await this.$post(this.api.saveExamPaper, this.tempForm) |
|
|
|
|
Util.successMsg('保存成功') |
|
|
|
|
this.submiting = false |
|
|
|
|
this.back() |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
// 提交 |
|
|
|
|
async submit (status) { |
|
|
|
|
async validForm (status) { |
|
|
|
|
if (this.submiting) return false |
|
|
|
|
this.$refs.form.validate(async (valid) => { |
|
|
|
|
if (valid) { |
|
|
|
|
const { isCopy } = this // 复制 |
|
|
|
|
const form = _.cloneDeep(this.form) |
|
|
|
|
if (isNaN(form.suggestTime) || form.suggestTime < 1 || form.suggestTime % 1) return Util.warningMsg('估计用时请输入正整数') |
|
|
|
|
const paper = form.paperOutline |
|
|
|
|
let invalid = 0 |
|
|
|
|
for (const i in paper) { |
|
|
|
|
const e = paper[i] |
|
|
|
|
if (!e.questionType) { |
|
|
|
|
Util.warningMsg('请选择题型') |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
if (!e.questionNum) { |
|
|
|
|
Util.warningMsg('请输入目标题数') |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
if (!e.targetScore) { |
|
|
|
|
Util.warningMsg('请输入目标分值') |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
const { isCopy } = this // 复制 |
|
|
|
|
const form = _.cloneDeep(this.form) |
|
|
|
|
const paper = form.paperOutline |
|
|
|
|
const allQues = [] |
|
|
|
|
|
|
|
|
|
// 发布才需要校验 |
|
|
|
|
if (!status) { |
|
|
|
|
if (isNaN(form.suggestTime) || form.suggestTime < 1 || form.suggestTime % 1) return Util.warningMsg('估计用时请输入正整数') |
|
|
|
|
let invalid = 0 |
|
|
|
|
for (const i in paper) { |
|
|
|
|
const e = paper[i] |
|
|
|
|
if (!e.questionType) { |
|
|
|
|
Util.warningMsg('请选择题型') |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
if (!e.questionNum) { |
|
|
|
|
Util.warningMsg('请输入目标题数') |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
if (!e.targetScore) { |
|
|
|
|
Util.warningMsg('请输入目标分值') |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const chineseNum = this.arabicToChinese(+i + 1) |
|
|
|
|
// 该大题里的小题总数需等于目标题数 |
|
|
|
|
if (+e.questionNum !== e.examQuestions.length) { |
|
|
|
|
Util.warningMsg(`第${chineseNum}大题的小题总数跟目标题数不一致,请重新修改`) |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
const chineseNum = this.arabicToChinese(+i + 1) |
|
|
|
|
// 该大题里的小题总数需等于目标题数 |
|
|
|
|
if (+e.questionNum !== e.examQuestions.length) { |
|
|
|
|
Util.warningMsg(`第${chineseNum}大题的小题总数跟目标题数不一致,请重新修改`) |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 填空题需要拿每个小空的分数计算 |
|
|
|
|
if (e.questionType === 'fill_blank') { |
|
|
|
|
let totalScore = 0 |
|
|
|
|
e.examQuestions.map(n => { |
|
|
|
|
const stem = document.querySelector(`#stem` + n.questionVersionId) |
|
|
|
|
if (stem) { |
|
|
|
|
const inputs = stem.querySelectorAll('.fill-input') |
|
|
|
|
if (inputs) { |
|
|
|
|
for (const e of inputs) { |
|
|
|
|
totalScore = Decimal(totalScore).add(e.value || 0).toNumber() |
|
|
|
|
} |
|
|
|
|
// 填空题需要拿每个小空的分数计算 |
|
|
|
|
if (e.questionType === 'fill_blank') { |
|
|
|
|
let totalScore = 0 |
|
|
|
|
e.examQuestions.map(n => { |
|
|
|
|
const stem = document.querySelector(`#stem` + n.questionVersionId) |
|
|
|
|
if (stem) { |
|
|
|
|
const inputs = stem.querySelectorAll('.fill-input') |
|
|
|
|
if (inputs) { |
|
|
|
|
for (const e of inputs) { |
|
|
|
|
totalScore = Decimal(totalScore).add(e.value || 0).toNumber() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if (+e.targetScore !== totalScore) { |
|
|
|
|
Util.warningMsg(`第${chineseNum}大题的小题总分跟目标分值不一致,请重新修改`) |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} else if (+e.targetScore !== e.examQuestions.reduce((e, j) => (e += +j.score), 0)) { |
|
|
|
|
// 该大题里的小题总分需等于目标分值 |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if (+e.targetScore !== totalScore) { |
|
|
|
|
Util.warningMsg(`第${chineseNum}大题的小题总分跟目标分值不一致,请重新修改`) |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
} else if (+e.targetScore !== e.examQuestions.reduce((e, j) => (e += +j.score), 0)) { |
|
|
|
|
// 该大题里的小题总分需等于目标分值 |
|
|
|
|
Util.warningMsg(`第${chineseNum}大题的小题总分跟目标分值不一致,请重新修改`) |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 试题里存在被禁用或者被删除的,不予提交 |
|
|
|
|
if (e.examQuestions.some(e => !e.status || e.isDel)) { |
|
|
|
|
Util.warningMsg(`当前试卷存在已被删除或已被禁用的试题,请进行相应调整 `) |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
// 试题里存在被禁用或者被删除的,不予提交 |
|
|
|
|
if (e.examQuestions.some(e => !e.status || e.isDel)) { |
|
|
|
|
Util.warningMsg(`当前试卷存在已被删除或已被禁用的试题,请进行相应调整 `) |
|
|
|
|
invalid = 1 |
|
|
|
|
break |
|
|
|
|
} |
|
|
|
|
if (invalid) return false |
|
|
|
|
allQues.push(...e.examQuestions) |
|
|
|
|
} |
|
|
|
|
if (invalid) return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.submiting = true |
|
|
|
|
form.particularYear = +(dayjs(form.particularYear).format('YYYY')) |
|
|
|
|
form.libraryId = this.libraryId |
|
|
|
|
form.questionCount = this.questionCount |
|
|
|
|
form.remarks = this.$refs.remarks.getUEContent() |
|
|
|
|
form.score = this.score |
|
|
|
|
form.status = status |
|
|
|
|
this.submiting = true |
|
|
|
|
|
|
|
|
|
paper.map(e => { |
|
|
|
|
// 复制不需要传id |
|
|
|
|
if (isCopy) { |
|
|
|
|
e.paperId = '' |
|
|
|
|
e.outlineId = '' |
|
|
|
|
} |
|
|
|
|
e.targetScore = +e.targetScore |
|
|
|
|
|
|
|
|
|
e.examQuestions = e.examQuestions.map((n, j) => { |
|
|
|
|
// 填空题的各个填空分数处理 |
|
|
|
|
if (n.questionType === 'fill_blank') { |
|
|
|
|
const stem = document.querySelector(`#stem` + n.questionVersionId) |
|
|
|
|
const scores = [] |
|
|
|
|
if (stem) { |
|
|
|
|
const inputs = stem.querySelectorAll('.fill-input') |
|
|
|
|
if (inputs) { |
|
|
|
|
for (const e of inputs) { |
|
|
|
|
scores.push(e.value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
form.particularYear = +(dayjs(form.particularYear).format('YYYY')) |
|
|
|
|
form.libraryId = this.libraryId |
|
|
|
|
form.questionCount = this.questionCount |
|
|
|
|
form.remarks = this.$refs.remarks.getUEContent() |
|
|
|
|
form.score = this.score |
|
|
|
|
form.status = status |
|
|
|
|
|
|
|
|
|
paper.map(e => { |
|
|
|
|
// 复制不需要传id |
|
|
|
|
if (isCopy) { |
|
|
|
|
e.paperId = '' |
|
|
|
|
e.outlineId = '' |
|
|
|
|
} |
|
|
|
|
e.targetScore = +e.targetScore |
|
|
|
|
|
|
|
|
|
e.examQuestions = e.examQuestions.map((n, j) => { |
|
|
|
|
// 填空题的各个填空分数处理 |
|
|
|
|
if (n.questionType === 'fill_blank') { |
|
|
|
|
const stem = document.querySelector(`#stem` + n.questionVersionId) |
|
|
|
|
const scores = [] |
|
|
|
|
if (stem) { |
|
|
|
|
const inputs = stem.querySelectorAll('.fill-input') |
|
|
|
|
if (inputs) { |
|
|
|
|
for (const e of inputs) { |
|
|
|
|
scores.push(e.value) |
|
|
|
|
} |
|
|
|
|
n.jsonText = JSON.stringify({ |
|
|
|
|
questionVersionId: n.questionVersionId, |
|
|
|
|
scores |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
questionVersionId: n.questionVersionId, |
|
|
|
|
serialNumber: n.serialNumber, |
|
|
|
|
score: +n.score, |
|
|
|
|
jsonText: n.jsonText, |
|
|
|
|
paperId: !isCopy && this.paperId || '', |
|
|
|
|
outlineId: !isCopy && e.outlineId || '', |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
n.jsonText = JSON.stringify({ |
|
|
|
|
questionVersionId: n.questionVersionId, |
|
|
|
|
scores |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
if (typeof form.classificationId === 'object') form.classificationId = form.classificationId[form.classificationId.length - 1] |
|
|
|
|
form.questionType = [...new Set(paper.map(e => e.questionType))].join('、') // 试题类型 |
|
|
|
|
form.createSource = 1 |
|
|
|
|
if (isCopy) form.paperId = '' |
|
|
|
|
// debugger |
|
|
|
|
try { |
|
|
|
|
await this.$post(this.api.saveExamPaper, form) |
|
|
|
|
Util.successMsg('保存成功') |
|
|
|
|
this.submiting = false |
|
|
|
|
this.back() |
|
|
|
|
} catch (e) { |
|
|
|
|
this.submiting = false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return { |
|
|
|
|
questionVersionId: n.questionVersionId, |
|
|
|
|
serialNumber: n.serialNumber, |
|
|
|
|
score: +n.score, |
|
|
|
|
jsonText: n.jsonText, |
|
|
|
|
paperId: !isCopy && this.paperId || '', |
|
|
|
|
outlineId: !isCopy && e.outlineId || '', |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
}) |
|
|
|
|
if (typeof form.classificationId === 'object') form.classificationId = form.classificationId[form.classificationId.length - 1] |
|
|
|
|
form.questionType = [...new Set(paper.map(e => e.questionType))].join('、') // 试题类型 |
|
|
|
|
form.createSource = 1 |
|
|
|
|
if (isCopy) form.paperId = '' |
|
|
|
|
this.tempForm = form |
|
|
|
|
|
|
|
|
|
// debugger |
|
|
|
|
// if (this.hasRepeatQues(allQues)) return false |
|
|
|
|
this.saveTestPaper() |
|
|
|
|
}, |
|
|
|
|
// 返回 |
|
|
|
|
back () { |
|
|
|
|