SanHQin пре 1 година
родитељ
комит
e665dc32b4

+ 84 - 0
src/components/pages/testStudent/view/component/gap.vue

@@ -64,6 +64,7 @@ export default {
             option: {
                 1: { name: '问答题' },
             },
+						userid:this.$route.query.userid,
             checkJson: undefined
         }
     },
@@ -114,6 +115,89 @@ export default {
                 this.checkJson.score2 = this.checkJson.score
             }
         },
+				autoFill(){
+					let params = {
+        	  uid: this.userid,
+        	 	tit: this.checkJson.title,
+        	}
+      		this.ajax
+      		  .get(this.$store.state.api + "selectTestCourseAutoFillType3", params)
+      		  .then((res) => {
+							let result = res.data[0];
+							if(result.length == 0)return;
+							let answerArr = [];
+							result.forEach(i=>{
+								let answer = {updateAt:"",answer:"",sum:1};
+								let courseJson = i.courseJson?JSON.parse(i.courseJson):[];
+								courseJson = this.JSONSetting(courseJson)
+								console.log("👇👇")
+								console.log(courseJson)
+								let thisAnswer = courseJson.find(i=>(i.type == 3 && i.json.title == this.checkJson.title));
+								if(thisAnswer){
+								  answer.updateAt = i.update_at?i.update_at:i.create_at;
+									answer.answer = thisAnswer.json.answer2;
+								}
+								let repeatIndex = answerArr.findIndex(i=>i.answer == answer.answer);
+								if(repeatIndex != -1){
+								  let oldAnswer = answerArr[repeatIndex];
+									if(new Date(oldAnswer.updateAt)>=new Date(answer.updateAt)){
+										oldAnswer.updateAt = answer.updateAt;
+									}
+									oldAnswer.sum += 1;
+									answerArr[repeatIndex] = oldAnswer;
+								}else{
+									answerArr.push(answer);
+								}
+							})
+							// 先通过数量排序
+							answerArr.sort((a,b)=>b.sum-a.sum);
+							if(answerArr.length>0&&answerArr[0].sum == answerArr[answerArr.length-1].sum ){//次数都一样就通过时间来排序
+								answerArr.sort((a,b)=>new Date(b.updateAt)-new Date(a.updateAt));
+								this.checkJson.answer2 = answerArr[0].answer;
+							}else{
+								//提取次数最多的
+								let maxAnswer = answerArr.filter(i=>i.sum == answerArr[0].sum);
+								if(maxAnswer.length>0){
+								  //再通过时间来排序
+									maxAnswer.sort((a,b)=>new Date(b.updateAt)-new Date(a.updateAt));
+									this.checkJson.answer2 = maxAnswer[0].answer;
+								}
+							}
+      		  })
+      		  .catch((err) => {
+      		    this.$message.error("网络不佳");
+      		    console.error(err);
+      		  });
+				},
+				JSONSetting(json) {
+    		  let _json = json
+    		  let array = []
+    		  _json.filter((item) => {
+    		    if (item.array) {
+    		      item.array = item.array.filter((item2) => {
+    		        if (item2.ttype == 1 && item2.json) {
+    		          array.push(item2)
+    		        }
+    		        if (item2.array) {
+    		          item2.array = item2.array.filter((item3) => {
+    		            if (item3.ttype == 1 && item3.json) {
+    		              array.push(item3)
+    		            }
+    		            return item3;
+    		          });
+    		        }
+    		        return item2;
+    		      });
+    		    }
+    		    if (item.ttype == 1 && item.json) {
+    		      array.push(item)
+    		    }
+    		    console.log(item.array);
+    		    return item;
+    		  });
+    		  console.log(array);
+    		  return array;
+    		},
     },
     mounted() {
         this.checkJson = this.cJson ? this.depthCopy(this.cJson) : undefined

+ 11 - 5
src/components/pages/testStudent/view/component/topic.vue

@@ -15,7 +15,7 @@
           <div v-if="item.ttype == 1" class="answerBox">
             <choiceV :tindex="index" :cJson.sync="item.json" :checktype="checktype" v-if="item.type == 1" :see="see"
               :isTeacher="isTeacher"></choiceV>
-            <gapV :tindex="index" :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 3" :see="see"
+            <gapV ref="gapVRef" :tindex="index" :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 3" :see="see"
               :isTeacher="isTeacher"></gapV>
             <fileV :tindex="index" :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 5" :see="see"
               :isTeacher="isTeacher"></fileV>
@@ -31,7 +31,7 @@
             <div v-if="item2.ttype == 1" class="answerBox">
               <choiceV :tindex="index2" :cJson.sync="item2.json" :checktype="checktype" v-if="item2.type == 1"
                 :see="see" :isTeacher="isTeacher"></choiceV>
-              <gapV :tindex="index2" :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 3"
+              <gapV ref="gapVRef" :tindex="index2" :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 3"
                 :see="see" :isTeacher="isTeacher"></gapV>
               <fileV :tindex="index2" :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 5"
                 :see="see" :isTeacher="isTeacher"></fileV>
@@ -51,7 +51,7 @@
           <div v-if="item.ttype == 1" class="answerBox">
             <choiceV :tindex="index" :cJson.sync="item.json" :checktype="checktype" v-if="item.type == 1" :see="see"
               :isTeacher="isTeacher"></choiceV>
-            <gapV :tindex="index" :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 3" :see="see"
+            <gapV ref="gapVRef" :tindex="index" :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 3" :see="see"
               :isTeacher="isTeacher"></gapV>
             <fileV :tindex="index" :cJson.sync="item.json" :checktype="checktype" v-else-if="item.type == 5" :see="see"
               :isTeacher="isTeacher"></fileV>
@@ -67,7 +67,7 @@
             <div v-if="item2.ttype == 1" class="answerBox">
               <choiceV :tindex="index2" :cJson.sync="item2.json" :checktype="checktype" v-if="item2.type == 1"
                 :see="see" :isTeacher="isTeacher"></choiceV>
-              <gapV :tindex="index2" :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 3"
+              <gapV ref="gapVRef" :tindex="index2" :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 3"
                 :see="see" :isTeacher="isTeacher"></gapV>
               <fileV :tindex="index2" :cJson.sync="item2.json" :checktype="checktype" v-else-if="item2.type == 5"
                 :see="see" :isTeacher="isTeacher"></fileV>
@@ -296,7 +296,13 @@ export default {
     },
     publish2(){
       this.$emit('publish2')
-    }
+    },
+		autoFillGapV(){
+			// console.log(this.$refs["gapVRef"])
+			this.$refs["gapVRef"].forEach(i=>{
+				i.autoFill();
+			})
+		}
   },
   mounted() {
     this.checkArray = this.setJson(this.depthCopy(this.cJson));

+ 23 - 1
src/components/pages/testStudent/view/preview.vue

@@ -37,6 +37,7 @@
         <div class="step_box">
           <div class="edit_top">
             <div class="op_btn">
+							<el-button type="primary" size="small" @click="autoFill" v-if="showAutoFillBtn">智能填写</el-button>
               <el-button type="primary" size="small" @click="refresh" v-if="isReset">刷新</el-button>
               <el-button type="primary" size="small" @click="reset">重置</el-button>
               <el-button type="primary" size="small" @click="save" v-if="type != 3">保存</el-button>
@@ -82,6 +83,12 @@ export default {
       gcourseid: this.$route.query.courseid
     }
   },
+	computed:{
+		showAutoFillBtn(){
+			let _json = this.JSONSetting(this.cJson)
+			return _json.filter(i=>i.type==3).length>0;
+		}
+	},
   methods: {
     retrunCourse() {
       this
@@ -604,7 +611,22 @@ export default {
         .catch(err => {
           console.error(err);
         });
-    }
+    },
+		autoFill(){
+			this
+        .$confirm("这将覆盖原有的内容,是否继续?", "提示", {
+          confirmButtonText: "确定",
+          cancelButtonText: "取消",
+          type: "warning",
+        })
+        .then(() => {
+					console.log(this.$refs['topicVue'])
+          this.$refs['topicVue'].autoFillGapV();
+        })
+        .catch(() => {
+
+        });
+		}
   },
   mounted() {
     this.getData();