|
@@ -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
|