Ver código fonte

单套连线拖拽bug修复

lvmax 2 meses atrás
pai
commit
bdd8f6d0b5
1 arquivos alterados com 68 adições e 71 exclusões
  1. 68 71
      pages/examPage/examStart.vue

+ 68 - 71
pages/examPage/examStart.vue

@@ -239,17 +239,17 @@
 							<view style="height: 600px;width: 800;background-color: #ffffff;">
 
 								<movable-area
-									:style="`height: 500px;width: 700px;background-color: #8c8c8c;margin: auto;background-image: url('${drag[this.scantron.sort].background.url}');background-size:${drag[this.scantron.sort].background.width}px ${drag[this.scantron.sort].background.height}px;background-repeat: no-repeat;`">
+									:style="`height: 500px;width: 700px;background-color: #8c8c8c;margin: auto;background-image: url('${drag[this.scantron.questionIndex].background.url}');background-size:${drag[this.scantron.questionIndex].background.width}px ${drag[this.scantron.questionIndex].background.height}px;background-repeat: no-repeat;`">
 									<!-- <rich-text :nodes="scantron.question.content"></rich-text> -->
 									<!-- <img v-if="drag.background.url!==''"  :style="`width:${drag.background.width} px;height:${drag.background.height} px;`"  :src="drag.background.url"/> -->
-									<template v-for="item in drag[this.scantron.sort].answer">
+									<template v-for="item in drag[this.scantron.questionIndex].answer">
 										<view
 											:style="`position: absolute;width: ${item.width}px;height: ${item.height}px;border:solid 1px black;left:${item.x}px;top:${item.y}px;`">
 
 										</view>
 									</template>
 
-									<template v-for="item in drag[this.scantron.sort].option">
+									<template v-for="item in drag[this.scantron.questionIndex].option">
 										<movable-view v-if="mbvShow" :id="item.id" :disabled="!disabledDrag"
 											:style="'width: '+item.width+'px;height: '+item.height+'px;background-color: '+item.backgroundColor+';'"
 											direction="all" :x="item.x" :y="item.y" @mousedown="onMousedown(item)"
@@ -554,8 +554,8 @@
 			// 重置
 			restart() {
 				this.disabledDrag = true
-				this.drag[this.scantron.sort].answer = []
-				this.drag[this.scantron.sort].option = []
+				this.drag[this.scantron.questionIndex].answer = []
+				this.drag[this.scantron.questionIndex].option = []
 				let content = this.stringToHTML(this.scantron.question.content)
 				console.log(content);
 				for (var i = 0; i < content.children.length; i++) {
@@ -566,7 +566,7 @@
 					let thisBackgroundColor = content.children[i].style.backgroundColor
 					let thisInnerHTML = content.children[i].innerHTML
 					if (content.children[i].id.includes("option")) {
-						this.drag[this.scantron.sort].option.push({
+						this.drag[this.scantron.questionIndex].option.push({
 							id: content.children[i].id,
 							x: Number(thisLeft),
 							y: Number(thisTop),
@@ -585,7 +585,7 @@
 						})
 					}
 					if (content.children[i].id.includes("answer")) {
-						this.drag[this.scantron.sort].answer.push({
+						this.drag[this.scantron.questionIndex].answer.push({
 							id: content.children[i].id,
 							x: Number(thisLeft),
 							y: Number(thisTop),
@@ -602,15 +602,15 @@
 			},
 			// 上一题目
 			previousQuestion() {
-				if (this.scantron.sort > 1) {
-					this.radioScantron(this.scantron.sort - 1)
+				if (this.scantron.questionIndex > 1) {
+					this.radioScantron(this.scantron.questionIndex - 1)
 				}
 			},
 			// 下一题目
 			nextQuestion() {
-				if (this.scantron.sort < this.examObject.userExamQuestionList.length) {
-					// this.scantron = this.examObject.userExamQuestionList[this.scantron.sort]
-					this.radioScantron(this.scantron.sort + 1)
+				if (this.scantron.questionIndex < this.examObject.userExamQuestionList.length) {
+					// this.scantron = this.examObject.userExamQuestionList[this.scantron.questionIndex]
+					this.radioScantron(this.scantron.questionIndex + 1)
 				} else {
 					this.$refs.answerFinal.open()
 				}
@@ -651,11 +651,12 @@
 				if (this.scantron.questionType == 7) {
 					this.mbvShow = !this.mbvShow
 					this.disabledDrag = true
-					console.log(this.drag[this.scantron.questionIndex]);
-					if (this.drag[this.scantron.questionIndex] !== undefined) {
+					console.log(this.drag[8]);
+					console.log(this.scantron.questionIndex);
+					if (this.drag[Number(this.scantron.questionIndex)] !== undefined) {
 						setTimeout(() => {
-							for (var i = 0; i < this.drag[this.scantron.sort].option.length; i++) {
-								let drags = this.drag[this.scantron.sort].option[i]
+							for (var i = 0; i < this.drag[this.scantron.questionIndex].option.length; i++) {
+								let drags = this.drag[this.scantron.questionIndex].option[i]
 								console.log(document.getElementById(drags.id));
 								document.getElementById(drags.id).innerHTML = drags.innerHTML
 							}
@@ -675,7 +676,7 @@
 						let thisBackgroundColor = content.children[i].style.backgroundColor
 						let thisInnerHTML = content.children[i].innerHTML
 						if (content.children[i].id.includes("option")) {
-							this.drag[this.scantron.sort].option.push({
+							this.drag[this.scantron.questionIndex].option.push({
 								id: content.children[i].id,
 								x: Number(thisLeft),
 								y: Number(thisTop),
@@ -694,7 +695,7 @@
 							})
 						}
 						if (content.children[i].id.includes("answer")) {
-							this.drag[this.scantron.sort].answer.push({
+							this.drag[this.scantron.questionIndex].answer.push({
 								id: content.children[i].id,
 								x: Number(thisLeft),
 								y: Number(thisTop),
@@ -708,17 +709,17 @@
 							})
 						}
 						if (content.children[i].tagName === 'IMG') {
-							this.drag[this.scantron.sort].background.url = content.children[i].src
-							this.drag[this.scantron.sort].background.width = content.children[i].style.width.toString()
+							this.drag[this.scantron.questionIndex].background.url = content.children[i].src
+							this.drag[this.scantron.questionIndex].background.width = content.children[i].style.width.toString()
 								.replace("px", "")
-							this.drag[this.scantron.sort].background.height = content.children[i].style.height.toString()
+							this.drag[this.scantron.questionIndex].background.height = content.children[i].style.height.toString()
 								.replace("px", "")
 						}
 					}
-					console.log(this.drag[this.scantron.sort].option.length);
+					console.log(this.drag[this.scantron.questionIndex].option.length);
 					setTimeout(() => {
-						for (var i = 0; i < this.drag[this.scantron.sort].option.length; i++) {
-							let drags = this.drag[this.scantron.sort].option[i]
+						for (var i = 0; i < this.drag[this.scantron.questionIndex].option.length; i++) {
+							let drags = this.drag[this.scantron.questionIndex].option[i]
 							console.log(document.getElementById(drags.id));
 							document.getElementById(drags.id).innerHTML = drags.innerHTML
 						}
@@ -768,7 +769,8 @@
 											.offsetHeight / 2)
 										if (this.connectionInfo.length === this.connectionHtml.length &&
 											colId === 0) {
-											this.connectionContentALL[this.scantron.sort].push(this
+												
+											this.connectionContentALL[this.scantron.questionIndex].push(this
 												.connectionInfo)
 											this.radioAdd(this.connectionInfo, this
 												.connectionInfo[0].id.replace('option', '').split('-')[
@@ -776,21 +778,23 @@
 											this.connectionInfo = []
 
 										}
+										console.log(this.connectionContentALL);
+										console.log(this.scantron.questionIndex);
 										let arr = []
-										for (var i = 0; i < this.connectionContentALL[this.scantron.sort]
+										for (var i = 0; i < this.connectionContentALL[this.scantron.questionIndex]
 											.length; i++) {
-											let all = this.connectionContentALL[this.scantron.sort][i]
+											let all = this.connectionContentALL[this.scantron.questionIndex][i]
 											if (all[0].id !== id) {
-												arr.push(this.connectionContentALL[this.scantron.sort][i])
+												arr.push(this.connectionContentALL[this.scantron.questionIndex][i])
 											}
 										}
-										this.connectionContentALL[this.scantron.sort] = arr
+										this.connectionContentALL[this.scantron.questionIndex] = arr
 										let infoLength = this.connectionInfo.length
 										if (infoLength <= this.connectionHtml.length) {
 											if (infoLength !== 0) {
-												if (!this.isLine(id, this.scantron.sort)) {
+												if (!this.isLine(id, this.scantron.questionIndex)) {
 													this.messageToggle('error', "这个已经连过了")
-													this.drawLineWrite(this.scantron.sort)
+													this.drawLineWrite(this.scantron.questionIndex)
 													return
 												}
 												let last = this.connectionInfo[infoLength -
@@ -819,10 +823,9 @@
 															'-')[1]) === rowId &&
 														this.connectionInfo.length === this.connectionHtml
 														.length) {
-														this.connectionContentALL[this.scantron.sort].push(
+														this.connectionContentALL[this.scantron.questionIndex].push(
 															this.connectionInfo)
-														console.log(this.connectionContentALL[this.scantron
-															.sort]);
+														console.log(this.connectionContentALL[this.scantron.questionIndex]);
 														this.radioAdd(this.connectionInfo, this
 															.connectionInfo[0].id.replace('option', '')
 															.split('-')[1], this.scantron)
@@ -830,10 +833,9 @@
 													}
 												} else if (colId === this.connectionHtml.length - 1) {
 
-													this.connectionContentALL[this.scantron.sort].push(
+													this.connectionContentALL[this.scantron.questionIndex].push(
 														this.connectionInfo)
-													console.log(this.connectionContentALL[this.scantron
-														.sort]);
+													
 													this.radioAdd(this.connectionInfo, this
 														.connectionInfo[0].id.replace('option', '')
 														.split('-')[1], this.scantron)
@@ -858,7 +860,7 @@
 											}
 										}
 										this.shadowClean()
-										this.drawLineWrite(this.scantron.sort)
+										this.drawLineWrite(this.scantron.questionIndex)
 
 
 									})
@@ -978,16 +980,16 @@
 			tap(index, subX, subY) {
 				let x = subX
 				let y = subY
-				this.drag[this.scantron.sort].option[index].x = this.drag[this.scantron.sort].option[index].old.x
-				this.drag[this.scantron.sort].option[index].y = this.drag[this.scantron.sort].option[index].old.y
+				this.drag[this.scantron.questionIndex].option[index].x = this.drag[this.scantron.questionIndex].option[index].old.x
+				this.drag[this.scantron.questionIndex].option[index].y = this.drag[this.scantron.questionIndex].option[index].old.y
 				this.$nextTick(function() {
-					this.drag[this.scantron.sort].option[index].x = x
-					this.drag[this.scantron.sort].option[index].y = y
+					this.drag[this.scantron.questionIndex].option[index].x = x
+					this.drag[this.scantron.questionIndex].option[index].y = y
 				})
 			},
 			// 鼠标按下
 			onMousedown(item) {
-				console.log(this.drag[this.scantron.sort].option.length);
+				console.log(this.drag[this.scantron.questionIndex].option.length);
 				this.dragItem = item;
 			},
 			// 拖动监听
@@ -997,54 +999,50 @@
 				}
 
 				let index = -1
-				for (var j = 0; j < this.drag[this.scantron.sort].option.length; j++) {
-					let option = this.drag[this.scantron.sort].option[j]
+				for (var j = 0; j < this.drag[this.scantron.questionIndex].option.length; j++) {
+					let option = this.drag[this.scantron.questionIndex].option[j]
 					if (option.id === this.dragItem.id) {
 						index = j
 						break;
 					}
 
 				}
-				this.drag[this.scantron.sort].option[index].old.x = e.detail.x
-				this.drag[this.scantron.sort].option[index].old.y = e.detail.y
+				this.drag[this.scantron.questionIndex].option[index].old.x = e.detail.x
+				this.drag[this.scantron.questionIndex].option[index].old.y = e.detail.y
 				let asda = (event) => {
 					document.removeEventListener('mouseup', asda)
 					this.disabledDrag = false
 					let dragOne;
 					let bxs = true
 					// 处理鼠标抬起事件
-					for (var i = 0; i < this.drag[this.scantron.sort].answer.length; i++) {
-						let drag = this.drag[this.scantron.sort].answer[i]
+					for (var i = 0; i < this.drag[this.scantron.questionIndex].answer.length; i++) {
+						let drag = this.drag[this.scantron.questionIndex].answer[i]
 						let x = drag.x
 						let y = drag.y
 						if (
-							(Number(this.drag[this.scantron.sort].option[index].old.x) <= (Number(drag.x) + Number(
+							(Number(this.drag[this.scantron.questionIndex].option[index].old.x) <= (Number(drag.x) + Number(
 								drag
 								.width))) &&
-							(Number(this.drag[this.scantron.sort].option[index].old.x) + Number(this.drag[this
-									.scantron.sort].option[index]
+							(Number(this.drag[this.scantron.questionIndex].option[index].old.x) + Number(this.drag[this.scantron.questionIndex].option[index]
 								.width)) >= drag.x &&
-							(Number(this.drag[this.scantron.sort].option[index].old.y) <= (Number(drag.y) + Number(
+							(Number(this.drag[this.scantron.questionIndex].option[index].old.y) <= (Number(drag.y) + Number(
 								drag
 								.height))) &&
-							(Number(this.drag[this.scantron.sort].option[index].old.y) + Number(this.drag[this
-									.scantron.sort].option[index]
+							(Number(this.drag[this.scantron.questionIndex].option[index].old.y) + Number(this.drag[this.scantron.questionIndex].option[index]
 								.height)) >= drag.y
 						) {
-							for (var p = 0; p < this.drag[this.scantron.sort].answer.length; p++) {
-								if (this.drag[this.scantron.sort].answer[p].op !== undefined && this.drag[this
-										.scantron.sort].answer[p].op === index) {
-									this.drag[this.scantron.sort].answer[p].op = undefined
+							for (var p = 0; p < this.drag[this.scantron.questionIndex].answer.length; p++) {
+								if (this.drag[this.scantron.questionIndex].answer[p].op !== undefined && this.drag[this.scantron.questionIndex].answer[p].op === index) {
+									this.drag[this.scantron.questionIndex].answer[p].op = undefined
 								}
 							}
-							if (this.drag[this.scantron.sort].answer[i].op !== undefined) {
-								this.tap(this.drag[this.scantron.sort].answer[i].op, this.drag[this.scantron.sort]
-									.option[this.drag[this.scantron.sort].answer[i].op].old.ax, this.drag[this
-										.scantron.sort]
-									.option[this.drag[this.scantron.sort].answer[i].op].old.by);
-								this.drag[this.scantron.sort].answer[i].op = index
+							if (this.drag[this.scantron.questionIndex].answer[i].op !== undefined) {
+								this.tap(this.drag[this.scantron.questionIndex].answer[i].op, this.drag[this.scantron.questionIndex]
+									.option[this.drag[this.scantron.questionIndex].answer[i].op].old.ax, this.drag[this.scantron.questionIndex]
+									.option[this.drag[this.scantron.questionIndex].answer[i].op].old.by);
+								this.drag[this.scantron.questionIndex].answer[i].op = index
 							} else {
-								this.drag[this.scantron.sort].answer[i].op = index
+								this.drag[this.scantron.questionIndex].answer[i].op = index
 							}
 							this.tap(index, x, y);
 							dragOne = drag
@@ -1052,10 +1050,9 @@
 							break;
 						}
 					}
-					// console.log(this.drag[this.scantron.sort].option[index]);
+					// console.log(this.drag[this.scantron.questionIndex].option[index]);
 					if (bxs) {
-						this.tap(index, this.drag[this.scantron.sort].option[index].old.ax, this.drag[this.scantron
-							.sort].option[index].old.by);
+						this.tap(index, this.drag[this.scantron.questionIndex].option[index].old.ax, this.drag[this.scantron.questionIndex].option[index].old.by);
 					}
 					setTimeout(() => {
 						if (dragOne !== undefined) {
@@ -1065,8 +1062,8 @@
 					}, 700)
 				}
 
-				// if (this.drag[this.scantron.sort].option[index].b) {
-				// 	this.drag[this.scantron.sort].option[index].b = false
+				// if (this.drag[this.scantron.questionIndex].option[index].b) {
+				// 	this.drag[this.scantron.questionIndex].option[index].b = false
 				document.addEventListener('mouseup', asda);
 				// }