考试管理 题目数量校验

This commit is contained in:
Yuan 2022-10-26 09:39:00 +08:00
parent 9e4576d30c
commit 491b28125b
4 changed files with 87 additions and 20 deletions

View File

@ -105,7 +105,7 @@ export default {
selectScope: '请选择范围',
questionNumbers: '题数',
allNumberTipOne: '此类型有',
allNumberTipTwo: '题',
allNumberTipTwo: '题',
scorePerQuestion: '每题分值',
inputQuestionNumber: '请输入题数',
inputQuestionNumberError: '输入的题数大于0',

View File

@ -39,7 +39,7 @@ export default {
},
findState: {
type: 'select',
label: '分类:',
label: '状态:',
value: 1,
config: {
data: paperStateQueryArr.map((v, i) => ({ value: i + 1, label: v })),

View File

@ -32,7 +32,7 @@
></el-option>
</el-select>
</el-form-item>
<el-form-item label="标签" prop="tags">
<el-form-item label="分类" prop="tags">
<el-select multiple v-model="form.tags" @change="getQuestionAmount">
<el-option v-for="label in labels" :key="label" :label="label" :value="label"></el-option>
</el-select>
@ -40,12 +40,12 @@
<el-form-item label="题目数量" prop="amount">
<el-input-number
v-model="form.amount"
:precision="0"
:min="0"
style="width: calc(100% - 280px); float: left; margin-right: 10px;"
/>
<span v-if="this.form.type === 1" style="width: 190px; float: left;">
{{ $t('publish.allNumberTipOne') }} {{ topicNum }} {{ $t('publish.allNumberTipTwo') }}
{{ $t('publish.allNumberTipOne') }} {{ topicNum }} {{ $t('publish.allNumberTipTwo') }}, 剩余
{{ remainNum }}
</span>
</el-form-item>
<el-form-item :label="$t('publish.scorePerQuestion')" prop="score">
@ -64,7 +64,11 @@ import { getQuestionAmount } from '@/api/management/exam'
import { getLabelList } from '@/api/questionBank'
export default {
name: 'EditRule',
props: {},
props: {
ruleList: {
type: Array,
},
},
computed: {
types() {
return [{ value: 1, label: '理论题' }, { value: 2, label: '实训题' }]
@ -90,7 +94,7 @@ export default {
message(new Error(this.$t('publish.inputQuestionNumberError')))
} else if (!Number(value)) {
message(new Error(this.$t('publish.inputValidNumber')))
} else if (Number(value) > this.topicNum && this.form.type === 1) {
} else if (Number(value) > this.remainNum && this.form.type === 1) {
message(new Error(this.$t('publish.inputNumberError')))
} else {
message()
@ -115,6 +119,8 @@ export default {
},
labels: [],
topicNum: 0,
remainNum: 0,
index: -1,
dialogShow: false,
rules: {
type: [{ required: true, message: this.$t('publish.selectTestType'), trigger: 'change' }],
@ -137,22 +143,42 @@ export default {
this.$refs.form.resetFields()
if (detail) {
this.isEditMode = true
this.index = detail.index
this.form = {
type: detail.type,
subtype: detail.subtype,
amount: detail.amount,
score: detail.score,
id: detail.id || '',
tags: detail.tags
}
this.topicNum = detail.topicNum
this.remainNum = detail.remainNum
} else {
this.isEditMode = false
this.remainNum = 0
}
})
},
isDuplicated() {
const isDuplicated =
this.ruleList.length > 0 &&
this.ruleList.some(
rule =>
rule.type === this.form.type &&
rule.subtype === this.form.subtype &&
rule.tags.length === this.form.tags.length &&
rule.tags.every(tag => this.form.tags.includes(tag))
)
return isDuplicated
},
getQuestionAmount(e) {
if (!(this.form.type && this.form.subtype)) return
if (this.form.type === 2) return //
// if (this.isDuplicated()) {
// this.$message.warning(', ')
// return
// }
const param = {
orgId: this.$store.state.user.companyId,
groupType: this.form.type,
@ -160,7 +186,37 @@ export default {
tags: this.form.tags,
}
getQuestionAmount(param).then(resp => {
this.topicNum = resp.data
const num = resp.data
this.topicNum = num
const { type, subtype, tags } = this.form
if (this.ruleList.length > 0) {
const smallerRangeRules = this.ruleList.filter(
(rule, i) =>
rule.type === type &&
rule.subtype === subtype &&
rule.tags.length >= tags.length &&
(tags.every(tag => rule.tags.includes(tag)) || tags.length === 0) &&
(this.isEditMode ? this.index !== i : true) //
)
//()
const amount1 = smallerRangeRules.reduce((prev, curr) => prev + curr.amount, 0)
const largerRangeRules = this.ruleList.filter(
(rule, i) =>
rule.type === type &&
rule.subtype === subtype &&
rule.tags.length < tags.length &&
(rule.tags.every(tag => tags.includes(tag)) || rule.tags.length === 0) &&
(this.isEditMode ? this.index !== i : true)
)
//
const amount2 = largerRangeRules.reduce(
(prev, curr) => (curr.topicNum - curr.amount < prev ? curr.topicNum - curr.amount : prev),
num
)
this.remainNum = amount2 - amount1
} else {
this.remainNum = num
}
})
},
clearSubtype() {
@ -169,7 +225,17 @@ export default {
handleOk() {
this.$refs['form'].validate(valid => {
if (valid) {
this.$emit('submit', { ...this.form, topicNum: this.topicNum }, this.isEditMode)
if (this.ruleList.length > 0 && !this.isEditMode) {
if (this.isDuplicated()) {
this.$message.warning('与已有规则重复, 请重新选择')
return
}
}
this.$emit(
'submit',
{ ...this.form, topicNum: this.topicNum, remainNum: this.remainNum },
this.isEditMode
)
this.handleCancel()
}
})

View File

@ -19,23 +19,23 @@
<span>{{ subtypes[scope.row.subtype] }}</span>
</template>
</el-table-column>
<el-table-column prop="amount" label="题目数量" width="100">
<template slot-scope="scope">
<span>{{ scope.row.amount }}</span>
</template>
</el-table-column>
<el-table-column prop="score" :label="$t('publish.eachScore')" width="100" />
<el-table-column :label="$t('publish.totalScore')" width="90">
<template slot-scope="scope">
<span>{{ Number(scope.row.amount) * Number(scope.row.score) }}</span>
</template>
</el-table-column>
<el-table-column prop="amount" label="题目数量" width="100">
<template slot-scope="scope">
<span>{{ scope.row.amount }}</span>
</template>
</el-table-column>
<el-table-column label="题库题数">
<template slot-scope="scope">
<span>{{ scope.row.topicNum }}</span>
</template>
</el-table-column>
<el-table-column label="标签">
<el-table-column label="分类">
<template slot-scope="scope">
<el-tag v-for="tag in scope.row.tags" :key="tag">{{ tag }}</el-tag>
</template>
@ -47,7 +47,7 @@
</template>
</el-table-column>
</el-table>
<edit-rule @submit="handleRuleSubmit" ref="addRule" />
<edit-rule @submit="handleRuleSubmit" :ruleList="ruleList" ref="addRule" />
</div>
</template>
@ -105,6 +105,7 @@ export default {
amount: formData.amount,
score: formData.score,
topicNum: formData.topicNum,
tags: formData.tags,
}
if (isEdit) {
this.$set(this.ruleList, this.editingIndex, data)
@ -116,7 +117,7 @@ export default {
const index = data.$index
this.ruleList.splice(index, 1)
},
checkTotolScores() {
return this.currentTotalScore === this.examData.fullScore
},
@ -124,7 +125,7 @@ export default {
this.editingIndex = data.$index
const list = JSON.stringify(data.row)
const detail = JSON.parse(list)
this.$refs.addRule.show(detail)
this.$refs.addRule.show({ ...detail, index: data.$index })
},
getSummaries({ columns, data }) {
const sums = []
@ -142,9 +143,9 @@ export default {
return prev
}
}, 0)
} else if (index === 4) {
} else if (index === 3) {
const values = data.map(item => Number(item.amount) * Number(item.score))
this.currentTotalScore = sums[4] = values.reduce((prev, curr) => {
this.currentTotalScore = sums[3] = values.reduce((prev, curr) => {
const value = Number(curr)
if (!isNaN(value)) {
return prev + curr