考试管理 题目数量校验
This commit is contained in:
parent
9e4576d30c
commit
491b28125b
@ -105,7 +105,7 @@ export default {
|
|||||||
selectScope: '请选择范围',
|
selectScope: '请选择范围',
|
||||||
questionNumbers: '题数',
|
questionNumbers: '题数',
|
||||||
allNumberTipOne: '此类型有',
|
allNumberTipOne: '此类型有',
|
||||||
allNumberTipTwo: '道题',
|
allNumberTipTwo: '题',
|
||||||
scorePerQuestion: '每题分值',
|
scorePerQuestion: '每题分值',
|
||||||
inputQuestionNumber: '请输入题数',
|
inputQuestionNumber: '请输入题数',
|
||||||
inputQuestionNumberError: '输入的题数大于0',
|
inputQuestionNumberError: '输入的题数大于0',
|
||||||
|
@ -39,7 +39,7 @@ export default {
|
|||||||
},
|
},
|
||||||
findState: {
|
findState: {
|
||||||
type: 'select',
|
type: 'select',
|
||||||
label: '分类:',
|
label: '状态:',
|
||||||
value: 1,
|
value: 1,
|
||||||
config: {
|
config: {
|
||||||
data: paperStateQueryArr.map((v, i) => ({ value: i + 1, label: v })),
|
data: paperStateQueryArr.map((v, i) => ({ value: i + 1, label: v })),
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
></el-option>
|
></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</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-select multiple v-model="form.tags" @change="getQuestionAmount">
|
||||||
<el-option v-for="label in labels" :key="label" :label="label" :value="label"></el-option>
|
<el-option v-for="label in labels" :key="label" :label="label" :value="label"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
@ -40,12 +40,12 @@
|
|||||||
<el-form-item label="题目数量" prop="amount">
|
<el-form-item label="题目数量" prop="amount">
|
||||||
<el-input-number
|
<el-input-number
|
||||||
v-model="form.amount"
|
v-model="form.amount"
|
||||||
:precision="0"
|
|
||||||
:min="0"
|
:min="0"
|
||||||
style="width: calc(100% - 280px); float: left; margin-right: 10px;"
|
style="width: calc(100% - 280px); float: left; margin-right: 10px;"
|
||||||
/>
|
/>
|
||||||
<span v-if="this.form.type === 1" style="width: 190px; float: left;">
|
<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>
|
</span>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('publish.scorePerQuestion')" prop="score">
|
<el-form-item :label="$t('publish.scorePerQuestion')" prop="score">
|
||||||
@ -64,7 +64,11 @@ import { getQuestionAmount } from '@/api/management/exam'
|
|||||||
import { getLabelList } from '@/api/questionBank'
|
import { getLabelList } from '@/api/questionBank'
|
||||||
export default {
|
export default {
|
||||||
name: 'EditRule',
|
name: 'EditRule',
|
||||||
props: {},
|
props: {
|
||||||
|
ruleList: {
|
||||||
|
type: Array,
|
||||||
|
},
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
types() {
|
types() {
|
||||||
return [{ value: 1, label: '理论题' }, { value: 2, label: '实训题' }]
|
return [{ value: 1, label: '理论题' }, { value: 2, label: '实训题' }]
|
||||||
@ -90,7 +94,7 @@ export default {
|
|||||||
message(new Error(this.$t('publish.inputQuestionNumberError')))
|
message(new Error(this.$t('publish.inputQuestionNumberError')))
|
||||||
} else if (!Number(value)) {
|
} else if (!Number(value)) {
|
||||||
message(new Error(this.$t('publish.inputValidNumber')))
|
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')))
|
message(new Error(this.$t('publish.inputNumberError')))
|
||||||
} else {
|
} else {
|
||||||
message()
|
message()
|
||||||
@ -115,6 +119,8 @@ export default {
|
|||||||
},
|
},
|
||||||
labels: [],
|
labels: [],
|
||||||
topicNum: 0,
|
topicNum: 0,
|
||||||
|
remainNum: 0,
|
||||||
|
index: -1,
|
||||||
dialogShow: false,
|
dialogShow: false,
|
||||||
rules: {
|
rules: {
|
||||||
type: [{ required: true, message: this.$t('publish.selectTestType'), trigger: 'change' }],
|
type: [{ required: true, message: this.$t('publish.selectTestType'), trigger: 'change' }],
|
||||||
@ -137,22 +143,42 @@ export default {
|
|||||||
this.$refs.form.resetFields()
|
this.$refs.form.resetFields()
|
||||||
if (detail) {
|
if (detail) {
|
||||||
this.isEditMode = true
|
this.isEditMode = true
|
||||||
|
this.index = detail.index
|
||||||
this.form = {
|
this.form = {
|
||||||
type: detail.type,
|
type: detail.type,
|
||||||
subtype: detail.subtype,
|
subtype: detail.subtype,
|
||||||
amount: detail.amount,
|
amount: detail.amount,
|
||||||
score: detail.score,
|
score: detail.score,
|
||||||
id: detail.id || '',
|
id: detail.id || '',
|
||||||
|
tags: detail.tags
|
||||||
}
|
}
|
||||||
this.topicNum = detail.topicNum
|
this.topicNum = detail.topicNum
|
||||||
|
this.remainNum = detail.remainNum
|
||||||
} else {
|
} else {
|
||||||
this.isEditMode = false
|
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) {
|
getQuestionAmount(e) {
|
||||||
if (!(this.form.type && this.form.subtype)) return
|
if (!(this.form.type && this.form.subtype)) return
|
||||||
if (this.form.type === 2) return //实训题暂不支持查询数量
|
if (this.form.type === 2) return //实训题暂不支持查询数量
|
||||||
|
// if (this.isDuplicated()) {
|
||||||
|
// this.$message.warning('与已有规则重复, 请重新选择')
|
||||||
|
// return
|
||||||
|
// }
|
||||||
const param = {
|
const param = {
|
||||||
orgId: this.$store.state.user.companyId,
|
orgId: this.$store.state.user.companyId,
|
||||||
groupType: this.form.type,
|
groupType: this.form.type,
|
||||||
@ -160,7 +186,37 @@ export default {
|
|||||||
tags: this.form.tags,
|
tags: this.form.tags,
|
||||||
}
|
}
|
||||||
getQuestionAmount(param).then(resp => {
|
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() {
|
clearSubtype() {
|
||||||
@ -169,7 +225,17 @@ export default {
|
|||||||
handleOk() {
|
handleOk() {
|
||||||
this.$refs['form'].validate(valid => {
|
this.$refs['form'].validate(valid => {
|
||||||
if (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()
|
this.handleCancel()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -19,23 +19,23 @@
|
|||||||
<span>{{ subtypes[scope.row.subtype] }}</span>
|
<span>{{ subtypes[scope.row.subtype] }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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 prop="score" :label="$t('publish.eachScore')" width="100" />
|
||||||
<el-table-column :label="$t('publish.totalScore')" width="90">
|
<el-table-column :label="$t('publish.totalScore')" width="90">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ Number(scope.row.amount) * Number(scope.row.score) }}</span>
|
<span>{{ Number(scope.row.amount) * Number(scope.row.score) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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="题库题数">
|
<el-table-column label="题库题数">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ scope.row.topicNum }}</span>
|
<span>{{ scope.row.topicNum }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="标签">
|
<el-table-column label="分类">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-tag v-for="tag in scope.row.tags" :key="tag">{{ tag }}</el-tag>
|
<el-tag v-for="tag in scope.row.tags" :key="tag">{{ tag }}</el-tag>
|
||||||
</template>
|
</template>
|
||||||
@ -47,7 +47,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
</el-table>
|
</el-table>
|
||||||
<edit-rule @submit="handleRuleSubmit" ref="addRule" />
|
<edit-rule @submit="handleRuleSubmit" :ruleList="ruleList" ref="addRule" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -105,6 +105,7 @@ export default {
|
|||||||
amount: formData.amount,
|
amount: formData.amount,
|
||||||
score: formData.score,
|
score: formData.score,
|
||||||
topicNum: formData.topicNum,
|
topicNum: formData.topicNum,
|
||||||
|
tags: formData.tags,
|
||||||
}
|
}
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
this.$set(this.ruleList, this.editingIndex, data)
|
this.$set(this.ruleList, this.editingIndex, data)
|
||||||
@ -116,7 +117,7 @@ export default {
|
|||||||
const index = data.$index
|
const index = data.$index
|
||||||
this.ruleList.splice(index, 1)
|
this.ruleList.splice(index, 1)
|
||||||
},
|
},
|
||||||
|
|
||||||
checkTotolScores() {
|
checkTotolScores() {
|
||||||
return this.currentTotalScore === this.examData.fullScore
|
return this.currentTotalScore === this.examData.fullScore
|
||||||
},
|
},
|
||||||
@ -124,7 +125,7 @@ export default {
|
|||||||
this.editingIndex = data.$index
|
this.editingIndex = data.$index
|
||||||
const list = JSON.stringify(data.row)
|
const list = JSON.stringify(data.row)
|
||||||
const detail = JSON.parse(list)
|
const detail = JSON.parse(list)
|
||||||
this.$refs.addRule.show(detail)
|
this.$refs.addRule.show({ ...detail, index: data.$index })
|
||||||
},
|
},
|
||||||
getSummaries({ columns, data }) {
|
getSummaries({ columns, data }) {
|
||||||
const sums = []
|
const sums = []
|
||||||
@ -142,9 +143,9 @@ export default {
|
|||||||
return prev
|
return prev
|
||||||
}
|
}
|
||||||
}, 0)
|
}, 0)
|
||||||
} else if (index === 4) {
|
} else if (index === 3) {
|
||||||
const values = data.map(item => Number(item.amount) * Number(item.score))
|
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)
|
const value = Number(curr)
|
||||||
if (!isNaN(value)) {
|
if (!isNaN(value)) {
|
||||||
return prev + curr
|
return prev + curr
|
||||||
|
Loading…
Reference in New Issue
Block a user