浏览代码

clear data before tree query

abpcoder 4 月之前
父节点
当前提交
58a503dbf1
共有 1 个文件被更改,包括 17 次插入10 次删除
  1. 17 10
      src/views/questioncenter/components/smart-online.vue

+ 17 - 10
src/views/questioncenter/components/smart-online.vue

@@ -200,14 +200,21 @@ export default {
       // this.getTree()
     },
     handleQuery() {
+      this.cleanBeforeQuery()
       if (this.tabActive == 0) {
-        this.chapterList = []
         this.getTree()
       } else {
-        this.knowList = []
         this.getTreeByKnowledge()
       }
     },
+    cleanBeforeQuery() {
+      this.chapterTitle = ''
+      this.konwTitle = ''
+      this.knowList = []
+      this.chapterList = []
+      this.form.chapterId = ''
+      this.form.knowledgeId = ''
+    },
     httpDiagnosticRecords(pageNum) {
       diagnosticRecords({
         pageNum: pageNum,
@@ -235,8 +242,8 @@ export default {
             this.chapterTitle = res.data[0].name
             this.$refs.treeChapter.setCurrentKey(res.data[0].$treeNodeId)
             this.form.chapterId = res.data[0].id
+            this.getQueByChapter()
           }
-          this.getQueByChapter()
         })
       })
     },
@@ -246,9 +253,11 @@ export default {
         (res) => {
           this.knowTreeList = res.data
           this.$nextTick(() => {
-            this.konwTitle = res.data[0].name
-            this.form.knowledgeId = res.data[0].id
-            this.getQueByKnowledge()
+            if (res.data.length > 0) {
+              this.konwTitle = res.data[0].name
+              this.form.knowledgeId = res.data[0].id
+              this.getQueByKnowledge()
+            }
           })
         }
       )
@@ -265,6 +274,7 @@ export default {
     },
     // 根据章节来获取题目
     getQueByChapter() {
+      if (!this.form.chapterId) return
       getQuestionsNumByChapter({
         chapterId: this.form.chapterId,
         subjectId: this.queryParams.exeSubject,
@@ -276,6 +286,7 @@ export default {
     },
     // 根据知识点来获取题目
     getQueByKnowledge() {
+      if (!this.form.knowledgeId) return
       getQuestionsNumByKnowledge({
         knowledgeId: this.form.knowledgeId,
         subjectId: this.form.subjectId
@@ -285,20 +296,17 @@ export default {
       })
     },
     clickChapterNode(item) {
-      console.log(item)
       this.chapterTitle = item.name
       this.form.chapterId = item.id
       this.getQueByChapter()
     },
     clickKnowNode(item) {
-      console.log(item)
       this.form.knowledgeId = item.id
       this.konwTitle = item.name
       this.getQueByKnowledge()
     },
     // 做章节题目
     toChapterQue(item) {
-      console.log(item)
       this.$router.push({
         path: '/question-center/smartExercise/practice',
         query: {
@@ -310,7 +318,6 @@ export default {
     },
     // 做知识点题目
     toKnowQue(item) {
-      console.log(item)
       this.$router.push({
         path: '/question-center/smartExercise/practice',
         query: {