Browse Source

试卷配分问题

OnePsycho 3 years ago
parent
commit
3c16c29d4e

+ 8 - 0
TEAMModelOS/ClientApp/src/utils/public.js

@@ -178,6 +178,14 @@ export default {
 			.randomId() +
 			'-' + this.randomId() + this.randomId() + this.randomId())
 	},
+	
+	// 根据总分和数量求平均结果
+	doAverage(total,count,step){
+		let oneMaxScore = (Math.floor((total / (count * step))) * step);
+		let maxIndex = Math.floor((total - oneMaxScore * count) / step);
+		let tempArr = new Array(count).fill(oneMaxScore).map((item,index)=>index < maxIndex ? (item + step) : item);
+		return tempArr
+	},
 
 	// 正则判断是否为标准的URL格式
 	isURL(url) {

+ 1 - 1
TEAMModelOS/ClientApp/src/utils/sheetConfig.js

@@ -11,7 +11,7 @@ const ANCHORPROP = {
 };
 const SVG_BORDER_PROP = {
     x:15,
-    y:0,
+    y:10,
     width:PAPER_W - 15 * 2,
     height:PAPER_H - 140
 }

+ 85 - 72
TEAMModelOS/ClientApp/src/view/evaluation/components/BaseExerciseList.vue

@@ -550,6 +550,7 @@
 
 			/** 按照题型配分 */
 			onConfirmTypeScore() {
+				let step = 0.5
 				/** 重新计算剩余分配分数 */
 				this.surPlusScore = this.paperInfo.score - this.groupTypeList.reduce((p, e) => parseInt(p) + parseInt(e
 					.score), 0)
@@ -558,34 +559,37 @@
 				} else {
 					/* 按照题型配分后平均分配给每个子题 */
 					this.groupTypeList.forEach(item => {
+						let averageArr = this.$tools.doAverage(item.score,item.list.length,step)
 						item.list.forEach((exercise, exerciseIndex) => {
-							// 先找到原始列表里面的当前题目
+							exercise.score = averageArr[exerciseIndex]
 							let listItem = this.exerciseList.filter(item => item.id === exercise.id)[0]
-							// 先判断是否总分除以题目数量能否除尽
-							let remainder = item.score % item.list.length
-							// 如果可以整除 则直接计算
-							if (remainder === 0) {
-								exercise.score = item.score / item.list.length
-							} else {
-								// 如果不能整除 则前面所有取整 最后一题加上余数 即可完成配分
-								let integerScore = parseInt(item.score / item.list.length)
-								// let lastItem = exerciseIndex === item.list.length - 1
-								// exercise.score = lastItem ? integerScore + remainder : integerScore
-								exercise.score = exerciseIndex + 1 > remainder ? integerScore :
-									integerScore + 1
-							}
 							listItem.score = exercise.score
-
-							if (exercise.type === 'compose' && exercise.children && exercise.children
-								.length) {
+							// 先找到原始列表里面的当前题目
+							// // 先判断是否总分除以题目数量能否除尽
+							// let remainder = item.score % item.list.length
+							// // 如果可以整除 则直接计算
+							// if (remainder === 0) {
+							// 	exercise.score = item.score / 
+							// } else {
+							// 	// 如果不能整除 则前面所有取整 最后一题加上余数 即可完成配分
+							// 	let integerScore = parseInt(item.score / item.list.length)
+							// 	// let lastItem = exerciseIndex === item.list.length - 1
+							// 	// exercise.score = lastItem ? integerScore + remainder : integerScore
+							// 	exercise.score = exerciseIndex + 1 > remainder ? integerScore :
+							// 		integerScore + 1
+							// }
+
+							if (exercise.type === 'compose' && exercise.children && exercise.children.length) {
+								let childrenScoreArr = this.$tools.doAverage(exercise.score,exercise.children.length,step)
 								exercise.children.forEach((child, childIndex) => {
-									let remainder = exercise.score % exercise.children.length
-									let integerScore = parseInt(exercise.score / exercise.children
-										.length)
-									// let lastItem = childIndex === exercise.children.length - 1
-									// child.score = lastItem ? integerScore + remainder : integerScore
-									child.score = childIndex + 1 > remainder ? integerScore :
-										integerScore + 1
+									child.score =childrenScoreArr[childIndex]
+									// let remainder = exercise.score % exercise.children.length
+									// let integerScore = parseInt(exercise.score / exercise.children
+									// 	.length)
+									// // let lastItem = childIndex === exercise.children.length - 1
+									// // child.score = lastItem ? integerScore + remainder : integerScore
+									// child.score = childIndex + 1 > remainder ? integerScore :
+									// 	integerScore + 1
 								})
 							}
 
@@ -696,6 +700,59 @@
 				console.log(list)
 				console.log(this.noAnswerList)
 			})
+			
+			this.$EventBus.$off('getNewPaper')
+			this.$EventBus.$on('getNewPaper', newPaper => {
+				console.log(newPaper)
+				let isSave = Number(sessionStorage.getItem('isSave'))
+				console.log(isSave)
+				if (newPaper && !isSave) {
+					let that = this
+					this.groupList = [] // 题型排序的数据
+					this.orderList = [] //顺序排列的数据
+					this.exerciseList = []
+					this.paperInfo = newPaper
+					this.multipleRule = newPaper.multipleRule || 1 // 配分规则
+					if (newPaper.item.length) {
+						newPaper.item.forEach(i => {
+							if (!i.score) i.score = 0
+							// 如果有综合题 则将小题的分数进行累加作为综合题的分数
+							if(i.type === 'compose' && i.children.length){
+								i.score = i.children.reduce((a,b) => a + b.score , 0)
+							}
+						})
+						// 给顺序题目排序
+						this.orderList.push({
+							list: newPaper.item
+						})
+						/* 处理试卷内题目按照题型排序 */
+						this.typeList.forEach(item => {
+							this._.mapKeys(this._.groupBy(newPaper.item, 'type'), function(value, key) {
+								if (key === item) {
+									/* 按照题型排序,并且计算每种题型的总分 */
+									that.groupList.push({
+										type: key,
+										list: value,
+										score: value.reduce((p, e) => parseInt(p) + parseInt(e
+											.score), 0)
+									})
+									that.exerciseList = that.exerciseList.concat(value)
+								}
+							})
+						});
+					}
+					// 重新赋值
+					this.originData = this.exerciseList
+					this.groupTypeList = this.groupList
+					this.totalNum = newPaper.item.length
+					console.log('groupType', this.groupTypeList);
+					// 剩余可分配分数 更新
+					this.surPlusScore = newPaper.score - newPaper.item.reduce((p, e) => Number(p) + Number(e.score),
+					0);
+					this.$emit('scoreUpdate', this.surPlusScore)
+					this.pageScrollTo(0)
+				}
+			})
 		},
 		computed: {
 			listData() {
@@ -730,55 +787,11 @@
 		watch: {
 			paper: {
 				handler(newPaper) {
-					if (newPaper) {
-						console.log('C-BaseExerciseList-Paper', newPaper)
-						let that = this
-						this.groupList = [] // 题型排序的数据
-						this.orderList = [] //顺序排列的数据
-						this.exerciseList = []
-						this.paperInfo = newPaper
-						this.multipleRule = newPaper.multipleRule || 1 // 配分规则
-						if (newPaper.item.length) {
-							newPaper.item.forEach(i => {
-								if (!i.score) i.score = 0
-								// 如果有综合题 则将小题的分数进行累加作为综合题的分数
-								// if(i.type === 'compose' && i.children.length){
-								// 	i.score = i.children.reduce((a,b) => a + b.score , 0)
-								// }
-							})
-							// 给顺序题目排序
-							this.orderList.push({
-								list: newPaper.item
-							})
-							/* 处理试卷内题目按照题型排序 */
-							this.typeList.forEach(item => {
-								this._.mapKeys(this._.groupBy(newPaper.item, 'type'), function(value, key) {
-									if (key === item) {
-										/* 按照题型排序,并且计算每种题型的总分 */
-										that.groupList.push({
-											type: key,
-											list: value,
-											score: value.reduce((p, e) => parseInt(p) + parseInt(e
-												.score), 0)
-										})
-										that.exerciseList = that.exerciseList.concat(value)
-									}
-								})
-							});
-						}
-						// 重新赋值
-						this.originData = this.exerciseList
-						this.groupTypeList = this.groupList
-						this.totalNum = newPaper.item.length
-						console.log('groupType', this.groupTypeList);
-						// 剩余可分配分数 更新
-						this.surPlusScore = newPaper.score - newPaper.item.reduce((p, e) => Number(p) + Number(e.score),
-						0);
-						this.$emit('scoreUpdate', this.surPlusScore)
-						this.pageScrollTo(0)
-					}
+					console.log('C-BaseExerciseList-Paper', newPaper)
+					
 				},
-				deep: true
+				immediate:true
+				// deep: true
 			},
 			viewModel: {
 				handler(newValue) {

+ 15 - 12
TEAMModelOS/ClientApp/src/view/evaluation/index/CreatePaper.vue

@@ -348,18 +348,6 @@
 			getSelectedQuestion(data) {
 				console.log(data)
 				let arr = data.questions
-				// 拿到题目后 根据试卷总分给所有题目进行平均分配
-				let scoreArr = this.averageTotalScore(this.evaluationInfo.score, arr.length)
-				arr.forEach((i, index) => {
-					i.score = scoreArr[index] || 0
-					// 如果是综合题 则需要进行子题的分数平均分配
-					if(i.type === 'compose' && i.children.length){
-						let childrenScoreArr = this.averageTotalScore(i.score, i.children.length)
-						i.children.forEach((child,childIndex) => {
-							child.score = childrenScoreArr[childIndex]
-						})
-					}
-				})
 				// 如果是编辑试卷 则往原试卷添加不包含的新题目进入
 				if (this.isEditPaper) {
 					let list = this.evaluationInfo.item
@@ -369,6 +357,18 @@
 						}
 					})
 				} else {
+					// 拿到题目后 根据试卷总分给所有题目进行平均分配
+					let scoreArr = this.$tools.doAverage(this.evaluationInfo.score, arr.length, 0.5)
+					arr.forEach((i, index) => {
+						i.score = scoreArr[index] || 0
+						// 如果是综合题 则需要进行子题的分数平均分配
+						if(i.type === 'compose' && i.children.length){
+							let childrenScoreArr = this.$tools.doAverage(i.score, i.children.length, 0.5)
+							i.children.forEach((child,childIndex) => {
+								child.score = childrenScoreArr[childIndex]
+							})
+						}
+					})
 					this.evaluationInfo.item = arr
 				}
 			},
@@ -557,6 +557,7 @@
 								// 将当前的试题数据转化为BLOB内部的试题JSON格式
 								let removeItem = await this.$editorTools.doRemoveMideaHost(
 									exerciseItem)
+									// removeItem.score = 0
 								const itemJsonFile = await this.$evTools.createBlobItem(
 									removeItem)
 								const cosmosItem = await this.$evTools.createCosmosItem(
@@ -939,6 +940,7 @@
 				// let blobList = await this.getPaperFiles('paper/' + this.oldPaper.name)
 				// console.log(blobList)
 				// return
+				sessionStorage.setItem('isSave',1)
 				console.log('试卷数据', this.evaluationInfo)
 				this.isLoading = true
 				let multipleRule = this.$refs.testPaper.$refs.exList.multipleRule
@@ -1120,6 +1122,7 @@
 															tabName: 'paper'
 														}
 													})
+													sessionStorage.setItem('isSave',0)
 												// }).catch(err => {
 												// 	this.$Message.error(this.$t(
 												// 		'evaluation.newExercise.uploadErrorTip'

+ 5 - 2
TEAMModelOS/ClientApp/src/view/evaluation/index/TestPaper.vue

@@ -324,11 +324,14 @@
 		watch: {
 			paper: {
 				handler(newValue, oldValue) {
-					console.log('TestPaper组件接受的paper',newValue.name)
+					console.log('TestPaper组件接受的paper',newValue)
+					this.$nextTick(() => {
+						this.$EventBus.$emit('getNewPaper',newValue)
+					})
 					this.paperInfo = newValue
-					// localStorage.setItem('_paperInfo', JSON.stringify(newValue))
 					this.paperDiff = newValue.item ? this.handleDiffCalc(newValue.item) : 4
 				},
+				immediate:true,
 				deep: true
 			}
 		}

+ 1 - 1
TEAMModelOS/ClientApp/src/view/newsheet/BaseSvgBg.vue

@@ -25,7 +25,7 @@
 			},
 			sheetId: {
 				type: String,
-				default: "1591613",
+				default: "",
 			},
 			total: {
 				type: Number,

+ 1 - 0
TEAMModelOS/ClientApp/src/view/settings/Index.vue

@@ -91,6 +91,7 @@ export default {
         if (localStorage.getItem('cloudSetting')) {
             this.cloudSetting = JSON.parse(localStorage.getItem('cloudSetting'))
         }
+		
     },
     methods: {