lsc 5 months ago
parent
commit
81bac424e5
2 changed files with 130 additions and 86 deletions
  1. 15 19
      src/components/pages/test/check/aiBoxRight.vue
  2. 115 67
      src/components/pages/test/check/index.vue

+ 15 - 19
src/components/pages/test/check/aiBoxRight.vue

@@ -562,25 +562,21 @@ export default {
     // },
     setJson(array){
       const getAnswer = (j) => {
-        switch (j.type) {
-          case 1:
-            return j.json.array
-              .filter((_, idx) => j.json.answer2.includes(idx))
-              .map(item => `${item.img}${item.option}`)
-              .join(',');
-          case 3:
-          case 6:
-          case 7:
-          case 8:
-          case 11:
-            return j.json.answer2.replace(/\n/g, ' '); // 去除回车
-          case 5:
-            if (!Array.isArray(j.json.file) || j.json.file.length === 0) {
-              return '无附件';
-            }
-            return j.json.file.map(file => `${file.name}(${file.url})`).join(',');
-          default:
-            return '';
+        if (j.type === 1) {
+          return j.json.array
+            .filter((_, idx) => j.json.answer2.includes(idx))
+            .map(item => `${item.img}${item.option}`)
+            .join(',');
+        } else if (j.type === 3 || j.type === 6 || j.type === 7 || j.type === 8 || j.type === 11) {
+          console.log(j.json);
+          return typeof j.json.answer2 === 'string' ? j.json.answer2.replace(/\n/g, ' ') : j.json.answer2;
+        } else if (j.type === 5) {
+          if (!Array.isArray(j.json.file) || j.json.file.length === 0) {
+            return '无附件';
+          }
+          return j.json.file.map(file => `${file.name}(${file.url})`).join(',');
+        } else {
+          return '';
         }
       };
 

+ 115 - 67
src/components/pages/test/check/index.vue

@@ -1327,36 +1327,63 @@ export default {
           let courseCount11 = []
           let testArray = []
           let array = []
+          let courseIds = []; // 初始化一个空数组来存储所有的courseId
           for (let i = 0; i < this.works.length; i++) {
             let cJson = this.setJSON(JSON.parse(JSON.stringify(JSON.parse(this.works[i].courseJson))))
             if (JSON.stringify(cJson) == JSON.stringify(chapters)) {
               let _json = this.JSONSetting(JSON.parse(JSON.stringify(JSON.parse(this.works[i].courseJson))))
 
               for (var ja = 0; ja < _json.length; ja++) {
-                let _json2 = _json[ja].json
+                let _json2 = _json[ja].json;
                 if (_json[ja].type == 6) {
-                  let _cjson = await this.getCourse(_json2.answer2)
-                  _json[ja].json.answer2 =  _cjson ? _cjson.title : ''
+                  let courseId = _json2.answer2;
+                  courseIds.push(courseId); // 将type为6的courseId添加到数组中
                 }
-                if(_json[ja].type == 11){
-                  let _answer = _json2.answer2
-                  _answer.length ? courseCount11 = courseCount11.concat(_answer) : ''
+                if (_json[ja].type == 11) {
+                  let _answer = _json2.answer2;
+                  _answer.length ? courseCount11 = courseCount11.concat(_answer) : '';
                   _json[ja].json.courseId = _answer ? _answer : [];
-                  let params = {
-                    cid:_answer.length ? _answer.join(",") : ''
-                  }
+                  courseIds = courseIds.concat(_answer); // 将type为11的courseId添加到数组中
+                }
+              }
+            }
+          }
+
+          // 将所有的courseId去重
+          courseIds = Array.from(new Set(courseIds));
+          // 使用一个数组来存储所有的courseId后,执行getCourseInfoTestAll
+          let courseTitles = {}; // 初始化一个空对象来存储所有的courseTitles
+          let params2 = [{
+            cid: courseIds.join(",")
+          }]
+
+          let data2 = await this.ajax.post(this.$store.state.api + 'getCourseInfoTestAll2', params2);
+          let result2 = data2.data[0];
+          result2.forEach(i => {
+            // _title.push(i.title);
+            courseTitles[i.courseId] = i.title;
+          });
+
+          for (let i = 0; i < this.works.length; i++) {
+            let cJson = this.setJSON(JSON.parse(JSON.stringify(JSON.parse(this.works[i].courseJson))))
+            if (JSON.stringify(cJson) == JSON.stringify(chapters)) {
+              let _json = this.JSONSetting(JSON.parse(JSON.stringify(JSON.parse(this.works[i].courseJson))))
 
-                  let data = await this.ajax.get(this.$store.state.api + 'getCourseInfoTestAll',params);
-                  let result = data.data[0]
+              _json.forEach(item => {
+                if (item.type == 11) {
+                  let cid = item.json.answer2
                   let _title = []
-                  // this.chapters.find(i=>i.type==6).nameFilters = result.map(r=>{return{text:r.title,value:r.courseId}})
-                  result.forEach(i=>{
-                    _title.push(i.title)
-                  })
-                  
-                  _json[ja].json.answer2 = _title.length ? _title.join(',') : '';
+                  for(var i = 0; i < cid.length; i++){
+                    _title.push(courseTitles[cid[i]])
+                  }
+                  item.json.answer2 = _title.length ? _title.join(",") : '';
                 }
-              }
+                if (item.type == 6) {
+                  let courseId = item.json.answer2;
+                  item.json.answer2 = courseTitles[courseId] || '';
+                }
+              });
+              // 更新对应的_json对象的answer2
               array.push({
                 courseid: this.works[i].courseid,
                 id: this.works[i].id,
@@ -1371,6 +1398,8 @@ export default {
             }
           }
 
+
+          let allCourseIds = [];
           for (var i = 0; i < this.chapters.length; i++) {
             let el = this.chapters[i]
             let topic = {
@@ -1382,6 +1411,7 @@ export default {
               choice: el.json ? el.json.array : '',
               array: [],
               answer: el.json ? el.json.answer : '',
+              answer2: '',
               count: 0,
               courses: el.json ? el.json.courses : [],
               small: el.json ? el.json.small : '',
@@ -1399,30 +1429,9 @@ export default {
             } else if (topic.type == 5) {
 
             } else if (topic.type == 6) {
-              let _answer = topic.courses
-              topic.array = _answer
-              topic.courseArray = [];
-							let params = {
-								cid:topic.array ? topic.array.join(",") : ''
-							}
-
-							let data = await this.ajax.get(this.$store.state.api + 'getCourseInfoTestAll',params);
-							let result = data.data[0]
-							// this.chapters.find(i=>i.type==6).nameFilters = result.map(r=>{return{text:r.title,value:r.courseId}})
-							result.forEach(i=>{
-								if(this.chapters.find(f=>f.type==6).nameFilters.find(c=>c.value==i.title)==undefined){
-									this.chapters.find(i=>i.type==6).nameFilters.push({text:i.title,value:i.title})
-								}
-							})
-							// this.chapters.find(i=>i.type==6).nameFilters = result.map(r=>{return{text:r.title,value:r.title}})
-							result.forEach(i=>i.update_at=new Date(i.update_at).toLocaleString('zh-CN', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit',hour12: false}).replace(/\//g,'-'))
-							topic.courseArray = result;
-              // topic.array.forEach(async i => {
-              //   let data = await this.getCourse(i)
-							// 	console.log(data.update_at)
-              //   data.update_at = new Date(data.update_at).toLocaleString('zh-CN', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit',hour12: false}).replace(/\//g,'-')
-              //   topic.courseArray.push(data)
-              // })
+              let _answer = topic.array
+
+              allCourseIds = allCourseIds.concat(_answer);
             } else if (topic.type == 7) {
               for (var t = parseInt(topic.small); t <= parseInt(topic.big); t++) {
                 topic.array.push({
@@ -1433,26 +1442,8 @@ export default {
             } else if (topic.type == 11) {
               const uniqueArray = courseCount11.filter((item, index) => courseCount11.indexOf(item) === index);
               let _answer = uniqueArray
-              topic.array = _answer
-              topic.courseArray = [];
-							let params = {
-								cid:topic.array ? topic.array.join(",") : ''
-							}
-
-							let data = await this.ajax.get(this.$store.state.api + 'getCourseInfoTestAll',params);
-							let result = data.data[0]
-							// this.chapters.find(i=>i.type==6).nameFilters = result.map(r=>{return{text:r.title,value:r.courseId}})
-							result.forEach(i=>{
-								if(this.chapters.find(f=>f.type==11).nameFilters.find(c=>c.value==i.title)==undefined){
-									this.chapters.find(i=>i.type==11).nameFilters.push({text:i.title,value:i.title})
-                  console.log(this.chapters);
-                  
-								}
-							})
-
-							result.forEach(i=>i.update_at=new Date(i.update_at).toLocaleString('zh-CN', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit',hour12: false}).replace(/\//g,'-'))
-							topic.courseArray = result;
-
+              
+              allCourseIds = allCourseIds.concat(_answer);
             }
             for (var j = 0; j < array.length; j++) {
               let el2 = array[j]
@@ -1483,8 +1474,7 @@ export default {
                 }
               } else if (topic.type == 5) {
                 let _answer = el2.array[i].json.file ? el2.array[i].json.file : []
-								console.log(el2)
-								let _user = {userid:el2.userid,username:el2.name}
+                let _user = {userid:el2.userid,username:el2.name}
                 for (var k = 0; k < _answer.length; k++) {
                   topic.array.push({..._answer[k],..._user})
                 }
@@ -1494,12 +1484,70 @@ export default {
                   topic.array[_answer].count++
                   topic.count++
                 }
+              }else if (topic.type == 6) {
+                if(el2.array[i].json.courses){
+                  let _answer = el2.array[i].json.courses.length ? el2.array[i].json.courses.join(",") : ''
+                  topic.answer2 = _answer
+                }
+              } else if (topic.type == 11) {
+                if(el2.array[i].json.answer2){
+                  let _answer = el2.array[i].json.answer2
+                  topic.answer2 = _answer
+                }
               }
             }
             console.log('topictopictopictopic',topic)
             testArray.push(topic)
             this.fileLoading.push({bool:false,count:0,load:0,progress:0})
           }
+
+          // 去重courseId
+          allCourseIds = Array.from(new Set(allCourseIds));
+
+          let params = [{
+            cid: allCourseIds.join(",")
+          }]
+
+          let data = await this.ajax.post(this.$store.state.api + 'getCourseInfoTestAll2',params);
+          let result = data.data[0]
+
+          for (var i = 0; i < this.chapters.length; i++) {
+            let el = this.chapters[i]
+            let topic = testArray[i]
+            if (topic.type == 6 || topic.type == 11) {
+              result.forEach(i=>{
+                i.update_at = new Date(i.update_at).toLocaleString('zh-CN', {year: 'numeric',month: '2-digit',day: '2-digit',hour: '2-digit',minute: '2-digit',second: '2-digit',hour12: false}).replace(/\//g,'-')
+              })
+              if(topic.type == 6){
+                result.forEach(i=>{
+                  if(this.chapters.find(f=>f.type==6).nameFilters.find(c=>c.value==i.title)==undefined && topic.answer2.includes(el.courseId)){
+                    this.chapters.find(i=>i.type==6).nameFilters.push({text:i.title,value:i.title})
+                  }
+                })
+              }else if(topic.type == 11){
+                result.forEach(i=>{
+                  if(this.chapters.find(f=>f.type==1).nameFilters.find(c=>c.value==i.title)==undefined && topic.answer2.includes(el.title)){
+                    this.chapters.find(i=>i.type==11).nameFilters.push({text:i.title,value:i.title})
+                  }
+                })
+              }
+
+              // this.chapters.find(i=>i.type==6 || i.type==11).nameFilters = result.map(r=>{return{text:r.title,value:r.courseId}})
+              if(topic.answer2.length){
+                let _answer = topic.answer2
+                topic.courseArray = result.filter(el => {
+                  if(topic.type == 11){
+                    return _answer.includes(el.title)
+                  }else if(topic.type == 6){
+                    return _answer.includes(el.courseId)
+                  }
+                });
+              }else{
+                topic.courseArray = []
+              }
+              // topic.courseArray = result
+            }
+          }
           this.testArray = testArray
           this.worksArray = array
           this.isLoading = false;
@@ -2009,11 +2057,11 @@ export default {
             let _answer = item.json.answer2
             _answer.length ? courseCount11 = courseCount11.concat(_answer) : ''
             _json[ja].json.courseId = _answer ? _answer : [];
-            let params = {
+            let params = [{
               cid:_answer.length ? _answer.join(",") : ''
-            }
+            }]
 
-            let data = await this.ajax.get(this.$store.state.api + 'getCourseInfoTestAll',params);
+            let data = await this.ajax.post(this.$store.state.api + 'getCourseInfoTestAll2',params);
             let result = data.data[0]
             let _title = []
             // this.chapters.find(i=>i.type==6).nameFilters = result.map(r=>{return{text:r.title,value:r.courseId}})