diff --git a/package-lock.json b/package-lock.json index db37d38..e8056be 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4217,6 +4217,11 @@ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" }, + "decimal.js": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.4.3.tgz", + "integrity": "sha512-VBBaLc1MgL5XpzgIP7ny5Z6Nx3UrRkIViUkPUdtl9aya5amy3De1gsUUSB1g3+3sExYNjCAsAznmukyxCb1GRA==" + }, "decode-uri-component": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", diff --git a/package.json b/package.json index 29336db..7ba9c5b 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "axios": "^0.18.0", "babel-polyfill": "^6.26.0", "dayjs": "^1.11.12", + "decimal.js": "^10.4.3", "echarts": "^4.8.0", "element-theme": "^2.0.1", "element-ui": "^2.13.0", diff --git a/src/pages/quesBank/index.vue b/src/pages/quesBank/index.vue index a1cf76d..86bd8e4 100644 --- a/src/pages/quesBank/index.vue +++ b/src/pages/quesBank/index.vue @@ -232,7 +232,7 @@ export default { }, // 排序回调 sortChange (column) { - if (column.prop === 'questionNumOrderBy') this.filter.questionNumOrderBy = column.order ? column.order === 'ascending' ? 'asc' : 'desc' : '' + if (column.prop === 'questionsNum') this.filter.questionNumOrderBy = column.order ? column.order === 'ascending' ? 'asc' : 'desc' : '' if (column.prop === 'createTime') this.filter.timeOrderBy = column.order ? column.order === 'ascending' ? 'asc' : 'desc' : '' this.getList() }, diff --git a/src/pages/testPaper/detail/auto.vue b/src/pages/testPaper/detail/auto.vue index f176704..a42d8de 100644 --- a/src/pages/testPaper/detail/auto.vue +++ b/src/pages/testPaper/detail/auto.vue @@ -121,7 +121,7 @@ import Util from '@/libs/util' import QuesConst from '@/const/ques' import TestPaperConst from '@/const/testPaper' import _ from 'lodash' -// import Decimal from 'decimal.js' +import Decimal from 'decimal.js' export default { props: ['visible'], data () { @@ -221,7 +221,7 @@ export default { const ques = this.checked.find(e => e.quesBank.id === checkQues.id) // 已选中的题库数组里有该题库,则往该题库的知识点数组里 if (ques) { - const i = ques.knowledges.findIndex(e => e === data.id) + const i = ques.knowledges.findIndex(e => e.id === data.id) if (checked && i === -1) { ques.knowledges.push(data) } else if (!checked && i >= 0) { @@ -250,14 +250,22 @@ export default { closeOnClickModal: false, }) this.checked = [] + // this.$nextTick(() => { + // this.$refs.knowledge.setCheckedKeys([]) + // }) } catch (e) { } }, // 删除题库 delQuesBank (i) { - this.checked.splice(i, 1) + const k = this.$refs.knowledge + this.checked[i].knowledges.map(e => { + k.setChecked(e.id, false, true) + }) + // this.checked.splice(i, 1) }, // 删除知识点 delKnowledge (i, j, item) { + this.$refs.knowledge.setChecked(item.knowledges[j].id, false) item.knowledges.splice(j, 1) item.knowledges.length || this.checked.splice(i, 1) // 知识点清空了则把该题库删除 }, @@ -282,33 +290,23 @@ export default { // 遍历题型数组 list.forEach(e => { const total = e.questionNum - const nums = { - basicDifficulty: 0, - normalDifficulty: 0, - hardDifficulty: 0, - veryHardDifficulty: 0, - } - - // 初始化题目数量 - for (let i = 0; i < 4; i++) { - nums[names[i]] = 0 - } // 初始分配题目数量 - let totalWeight = total * target + let totalWeight = Decimal(total).mul(Decimal(target)).toNumber() const maxCount = Math.ceil(total / 4) for (let i = 0; i < 4; i++) { - console.log("🚀 ~ calculateQuestionNumbers ~ totalWeight:", totalWeight) if (totalWeight > 0) { - const random = Math.floor(Math.random() * (maxCount)) + 1 + const random = Math.floor(Math.random() * maxCount) + 1 const weight = difficultyWeights[i] - totalWeight -= weight * random - e[names[i]] = totalWeight > 0 ? random : 0 + totalWeight = Decimal(totalWeight).sub(Decimal(weight * random)).toNumber() + this.$set(e, names[i], totalWeight > 0 ? random : 0) + // e[names[i]] = totalWeight > 0 ? random : 0 } } - // e.nums = nums - }); + console.log("🚀 ~ calculateQuestionNumbers ~ totalWeight:", totalWeight) + + }) return list }, @@ -365,7 +363,6 @@ export default { let invalid = 0 let hasQues = 0 list.map((e, i) => { - console.log("🚀 ~ submit ~ e:", e) if (e.questionNum !== res.list[i].questions.length) invalid = 1 if (e.examQuestions.length) hasQues = 1 }) diff --git a/src/pages/testPaper/detail/index.vue b/src/pages/testPaper/detail/index.vue index 552c11d..13574e1 100644 --- a/src/pages/testPaper/detail/index.vue +++ b/src/pages/testPaper/detail/index.vue @@ -120,11 +120,18 @@
(