From 491b28125b2e586e6910077176ea82ba1817405c Mon Sep 17 00:00:00 2001 From: Yuan Date: Wed, 26 Oct 2022 09:39:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E8=AF=95=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E6=95=B0=E9=87=8F=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/i18n/langs/zh/publish.js | 2 +- src/views/organization/examManage/index.vue | 2 +- src/views/publish/examRule/draft/editRule.vue | 80 +++++++++++++++++-- src/views/publish/examRule/draft/rule.vue | 23 +++--- 4 files changed, 87 insertions(+), 20 deletions(-) diff --git a/src/i18n/langs/zh/publish.js b/src/i18n/langs/zh/publish.js index 55ad8fe50..0069d13de 100644 --- a/src/i18n/langs/zh/publish.js +++ b/src/i18n/langs/zh/publish.js @@ -105,7 +105,7 @@ export default { selectScope: '请选择范围', questionNumbers: '题数', allNumberTipOne: '此类型有', - allNumberTipTwo: '道题', + allNumberTipTwo: '题', scorePerQuestion: '每题分值', inputQuestionNumber: '请输入题数', inputQuestionNumberError: '输入的题数大于0', diff --git a/src/views/organization/examManage/index.vue b/src/views/organization/examManage/index.vue index 615cdc3f5..fa36b4c6f 100644 --- a/src/views/organization/examManage/index.vue +++ b/src/views/organization/examManage/index.vue @@ -39,7 +39,7 @@ export default { }, findState: { type: 'select', - label: '分类:', + label: '状态:', value: 1, config: { data: paperStateQueryArr.map((v, i) => ({ value: i + 1, label: v })), diff --git a/src/views/publish/examRule/draft/editRule.vue b/src/views/publish/examRule/draft/editRule.vue index b59252f1a..a7eb2fd55 100644 --- a/src/views/publish/examRule/draft/editRule.vue +++ b/src/views/publish/examRule/draft/editRule.vue @@ -32,7 +32,7 @@ > - + @@ -40,12 +40,12 @@ - {{ $t('publish.allNumberTipOne') }} {{ topicNum }} {{ $t('publish.allNumberTipTwo') }} + {{ $t('publish.allNumberTipOne') }} {{ topicNum }} {{ $t('publish.allNumberTipTwo') }}, 剩余 + {{ remainNum }}题 @@ -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() } }) diff --git a/src/views/publish/examRule/draft/rule.vue b/src/views/publish/examRule/draft/rule.vue index 42420626c..2be6e6f69 100644 --- a/src/views/publish/examRule/draft/rule.vue +++ b/src/views/publish/examRule/draft/rule.vue @@ -19,23 +19,23 @@ {{ subtypes[scope.row.subtype] }} - - - + + + - + @@ -47,7 +47,7 @@ - + @@ -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