Browse Source

feat: 题库页面显示refused状态的题目并可以修改为UPDATING状态

mjh 4 years ago
parent
commit
3104d3029f

+ 14 - 13
src/components/QuestionCard/PrimaryQuestionCard.vue

@@ -152,17 +152,17 @@
     </div>
   </el-card>
 
-  <el-drawer
-    title="更新题目"
-    :before-close="handleClose"
-    v-model="dialog"
-    direction="rtl"
-    custom-class="question-drawer"
-    ref="drawer"
-    size="35%"
-  >
-    <QuestionUpdater :question="questionVO" @closeDialog="closeDialog"/>
-  </el-drawer>
+<!--  <el-drawer-->
+<!--    title="更新题目"-->
+<!--    :before-close="handleClose"-->
+<!--    v-model="dialog"-->
+<!--    direction="rtl"-->
+<!--    custom-class="question-drawer"-->
+<!--    ref="drawer"-->
+<!--    size="35%"-->
+<!--  >-->
+<!--    <QuestionUpdater :question="questionVO" @closeDialog="closeDialog"/>-->
+<!--  </el-drawer>-->
 
 </template>
 
@@ -216,7 +216,7 @@ export default {
       }
     },
     updateQuestion() {
-      this.dialog = true;
+      this.$emit("update");
     },
     handleClose() {
       this.$confirm('此操作将丢失填写信息, 是否继续?', '提示', {
@@ -330,7 +330,8 @@ export default {
       }).catch(err1 => {
       console.log(err1);
     });
-  }
+  },
+  emits: ["update"],
 }
 </script>
 

+ 85 - 10
src/components/QuestionCreator/SingleQuestionCreator.vue

@@ -80,9 +80,16 @@ import {knowledgeData} from "@/utils/knowledgeData";
 export default {
   name: "SingleQuestionCreator",
   components: {},
+  props: {
+    target: {
+      type: String,
+      default: "create",
+    },
+  },
   data() {
     return {
       form: {
+        id: null,
         stem: "",
         type: 1,
         options: [
@@ -129,15 +136,32 @@ export default {
     async handleAckButtonClick() {
       if (this.checkFormCompletion()) {
         let questionVO = this.formatQuestionVO2backend();
-        let res = await this.$api.createQuestion(questionVO);
-        if (res.status === 200) {
-          this.$message({
-            message: '新建题目成功!',
-            type: 'success'
-          });
+        let res;
+        switch (this.target) {
+          case "create":
+            res = await this.$api.createQuestion(questionVO);
+            if (res.status === 200) {
+              this.$message({
+                message: '新建题目成功!',
+                type: 'success'
+              });
+            }
+            break;
+          case "update":
+            questionVO.state = "UPDATING";
+            delete questionVO.createdTime;
+            // todo 还没验证过
+            res = await this.$api.updateQuestion(questionVO);
+            if (res.status === 200) {
+              this.$message({
+                message: '更新题目成功!',
+                type: 'success'
+              });
+            }
+            break;
         }
-
       }
+      this.$emit("acknowledge");
     },
 
     checkFormCompletion() {
@@ -240,6 +264,7 @@ export default {
 
     initSingleQuestionCreator() {
       this.form = {
+        id: null,
         stem: "",
         type: 1,
         options: [
@@ -269,7 +294,7 @@ export default {
     formatQuestionVO2backend() {
       const savedUserId = this.$store.state.user.id;
       const checkedUserId = this.$store.state.user.id;
-      const createTime = new Date();
+      const createdTime = new Date();
       const lastModifiedTime = new Date();
       const state = "CHECKING";
 
@@ -306,17 +331,18 @@ export default {
       let tags = [this.form.tags];
 
       return {
+        id: this.form.id,
         stem: this.form.stem,
         type,
         options,
         answer: (this.form.type !== 2) ? this.form.answer : multi_answer,
         analysis: this.form.analysis,
-        difficulty: this.form.difficulty,
+        weight: this.form.difficulty,
         knowledgeId,
         tags,
         keyPoints: this.form.keyPoints,
         savedUserId,
-        createTime,
+        createdTime,
         lastModifiedTime,
         state
       };
@@ -330,8 +356,57 @@ export default {
         }
       }
     },
+
+    setForm(questionVO) {
+      let type;
+      switch (questionVO.type) {
+        case "choice":
+          type = 1;
+          break;
+        case "multiple_choice":
+          type = 2;
+          break;
+        case "blank":
+          type = 3;
+          break;
+        case "short_answer":
+          type = 4;
+          break;
+        case "code":
+          type = 5;
+          break;
+      }
+      let options = [];
+      for (let optionsKey in questionVO.options) {
+        options.push({
+          label: optionsKey,
+          content: questionVO.options[optionsKey],
+        })
+      }
+      let multi_answer = [];
+      if (type === 2) {
+        for (let i = 0; i < questionVO.answer.length; i++) {
+          multi_answer.push(questionVO.answer[i]);
+        }
+      }
+
+      this.form = {
+        id: questionVO.id,
+        stem: questionVO.stem,
+        type,
+        options,
+        answer: questionVO.answer,
+        multi_answer,
+        analysis: questionVO.analysis,
+        difficulty: questionVO.weight,
+        knowledgeId: questionVO.knowledgeId,
+        tags: questionVO.tags[0],
+        keyPoints: questionVO.keyPoints,
+      }
+    },
   },
   computed: {},
+  emits: ["acknowledge"],
 }
 </script>
 

+ 153 - 97
src/views/Bok/Main/QuestionRepository.vue

@@ -1,155 +1,210 @@
 <template>
   <h1>Question Repository</h1>
-
-  <div>
-    <el-button>新建题目</el-button>
-    <el-button @click="createQuestion">新建题目组</el-button>
-  </div>
-
-  <el-divider/>
-
-  <div>
-    <el-pagination @size-change="handleSizeChange"
-                   @current-change="handleCurrentChange"
-                   :current-page="currentPage"
-                   :page-sizes="[5, 10, 15, 20]"
-                   :page-size="pageSize"
-                   layout="total, sizes, prev, pager, next, jumper"
-                   :total=this.totalNum
-                   v-if="this.questionList.length !== 0"
-    />
-    <primary-question-card v-for="(item,index) in questionList"
-                           :key="item.id"
-                           :question-v-o="item"
-                           :total-num="totalNum"
-                           :cur-num="index+(currentPage-1)*pageSize"/>
-
-    <el-backtop :bottom="50">
-      <div style="height: 100%;width: 100%;background-color: #f2f5f6;box-shadow: 0 0 6px rgba(0,0,0, .12);line-height: 40px;">
-        UP
+  <el-tabs v-model="tabActiveName" @tab-click="handleTabClick" stretch>
+    <!--APPROVED-->
+    <el-tab-pane label="APPROVED" name="APPROVED">
+      <div>
+        <el-button>新建题目</el-button>
+        <!--        <el-button @click="createQuestion">新建题目组</el-button>-->
       </div>
-    </el-backtop>
-  </div>
-
+      <el-divider/>
+      <div>
+        <el-pagination @size-change="handleSizeChange"
+                       @current-change="handleCurrentChange"
+                       :current-page="currentPage"
+                       :page-sizes="[5, 10, 15, 20]"
+                       :page-size="pageSize"
+                       layout="total, sizes, prev, pager, next, jumper"
+                       :total=this.totalNum
+                       v-if="this.questionList.length !== 0"
+        />
+        <primary-question-card v-for="(item,index) in questionList"
+                               :key="item.id"
+                               :question-v-o="item"
+                               :total-num="totalNum"
+                               :cur-num="index+(currentPage-1)*pageSize"
+                               @update="handleQuestionUpdate(item)"/>
+        <el-backtop :bottom="50">
+          <div
+            style="height: 100%;width: 100%;background-color: #f2f5f6;box-shadow: 0 0 6px rgba(0,0,0, .12);line-height: 40px;">
+            UP
+          </div>
+        </el-backtop>
+      </div>
+    </el-tab-pane>
+    <!--REFUSED-->
+    <el-tab-pane label="REFUSED" name="REFUSED">
+      <div>
+        <el-pagination @size-change="handleSizeChange"
+                       @current-change="handleRefusedCurrentChange"
+                       :current-page="refusedCurrentPage"
+                       :page-sizes="[5, 10, 15, 20]"
+                       :page-size="pageSize"
+                       layout="total, sizes, prev, pager, next, jumper"
+                       :total=this.refusedTotalNum
+                       v-if="this.refusedQuestionList.length !== 0"
+        />
+        <primary-question-card v-for="(item,index) in refusedQuestionList"
+                               :key="item.id"
+                               :question-v-o="item"
+                               :total-num="refusedTotalNum"
+                               :cur-num="index+(refusedCurrentPage-1)*pageSize"
+                               @update="handleQuestionUpdate"/>
+        <el-backtop :bottom="50">
+          <div
+            style="height: 100%;width: 100%;background-color: #f2f5f6;box-shadow: 0 0 6px rgba(0,0,0, .12);line-height: 40px;">
+            UP
+          </div>
+        </el-backtop>
+      </div>
+    </el-tab-pane>
+  </el-tabs>
+  <!--修改框-->
   <el-drawer
-    title="新建题目"
+    title="更新题目"
     :before-close="handleClose"
     v-model="dialog"
     direction="rtl"
     custom-class="question-drawer"
     ref="drawer"
-    size="35%"
-  >
-    <QuestionCreater :dialog="dialog" @closeDialog="closeDialog"/>
-  </el-drawer>
-
-  <el-drawer
-    title="批量新建题目"
-    :before-close="handleClose"
-    v-model="dialog1"
-    direction="rtl"
-    custom-class="questionGroup-drawer"
-    ref="drawer"
-    size="35%"
-  >
-    <QuestionGroupCreater :dialog="dialog1" @closeDialog="closeDialog1"/>
+    size="35%">
+    <single-question-creator ref="QuestionUpdater"
+                             @acknowledge="handleQuestionCreatorAcknowledge"
+                             :target="creatorTarget"/>
   </el-drawer>
 </template>
 
 <script>
-import QuestionGroupCreater from "../../../components/QuestionGroupCreater.vue";
-import QuestionCreater from "@/components/QuestionCreater";
-import BriefQuestionCard from "../../../components/BriefQuestionCard.vue";
 import PrimaryQuestionCard from "@/components/QuestionCard/PrimaryQuestionCard";
+import SingleQuestionCreator from "@/components/QuestionCreator/SingleQuestionCreator";
 
 export default {
   name: "QuestionRepository",
   components: {
-    QuestionGroupCreater,
-    BriefQuestionCard,
+    SingleQuestionCreator,
     PrimaryQuestionCard,
-    QuestionCreater
   },
   data() {
     return {
-      info: null,
+      dialog: true,
+      pageSize: 20,
+
       questionList: [],
-      dialog: false,
-      dialog1: false,
       currentPage: 1,
-      pageSize: 20,
       totalNum: 0,
+
+      refusedQuestionList: [],
+      refusedCurrentPage: 1,
+      refusedTotalNum: 0,
+
+      tabActiveName: "APPROVED",
+
+      creatorTarget: "update",
     }
   },
   mounted() {
-    // console.log(this.questionList)
-
+    this.dialog = false;
     // 挂载时获取第一页题目列表
     let states = 'APPROVED';
     this.$api.getStateQuestion(states, 0, this.pageSize)
       .then(res => {
-        // console.log("QuestionRepository/index");
-        // console.log(res);
+        console.log(res);
         this.questionList = res.data.result.content;
         this.totalNum = res.data.result.totalElements;
-      }).catch(error => {
-      // console.log(error);
-    })
+      })
+      .catch(error => {
+        console.log(error);
+      })
   },
   computed: {},
   methods: {
-    createQuestion() {
-      this.dialog = true;
-    },
-
-    createQuestionByGruop() {
-      this.dialog1 = true;
-    },
+    // createQuestion() {
+    //   this.dialog = true;
+    // },
 
     handleClose(done) {
-      // if (this.loading) {
-      //   return;
-      // }
-      // this.$confirm('确定要提交表单吗?')
-      //   .then(_ => {
-      //     this.loading = true;
-          // this.timer = setTimeout(() => {
-          //   done();
-          //   // 动画关闭需要一定的时间
-          //   setTimeout(() => {
-          //     this.loading = false;
-          //   }, 400);
-          // }, 2000);
-        // })
-        // .catch(_ => {
-        // });
+      this.$confirm('确认关闭?')
+        .then(_ => {
+          done();
+        })
+        .catch(_ => {
+        });
     },
 
     closeDialog() {
       this.dialog = false;
     },
 
-    closeDialog1() {
-      this.dialog1 = false;
-    },
-
     handleSizeChange(val) {
       // console.log(`QuestionRepository/index-handleSizeChange 每页 ${val} 条`);
       this.pageSize = val;
     },
 
     handleCurrentChange(val) { // 当点击新的页面时才请求新的数据
-      // console.log(`QuestionRepository/index-handleCurrentChange 当前页: ${val}`);
       this.currentPage = val;
       let states = 'APPROVED';
       this.$api.getStateQuestion(states, val - 1, this.pageSize)
         .then(res => {
-          // console.log("handleCurrentChange-result");
-          // console.log(res);
+          console.log(res);
           this.questionList = res.data.result.content;
-        }).catch(error => {
-        // console.log(error);
-      })
+        })
+        .catch(error => {
+          console.log(error);
+        })
+    },
+
+    handleRefusedCurrentChange(val) { // 当点击新的页面时才请求新的数据
+      this.currentPage = val;
+      let states = 'REFUSED';
+      this.$api.getStateQuestion(states, val - 1, this.pageSize)
+        .then(res => {
+          console.log(res);
+          this.questionList = res.data.result.content;
+        })
+        .catch(error => {
+          console.log(error);
+        })
+    },
+
+    handleTabClick(tabItem) {
+      let state = tabItem.props.label;
+      switch (state) {
+        case "APPROVED":
+          this.$api.getStateQuestion(state, 0, this.pageSize)
+            .then(res => {
+              console.log(res);
+              this.questionList = res.data.result.content;
+              this.totalNum = res.data.result.totalElements;
+              this.currentPage = 1;
+            })
+            .catch(error => {
+              console.log(error);
+            });
+          break;
+        case "REFUSED":
+          this.$api.getStateQuestion(state, 0, this.pageSize)
+            .then(res => {
+              console.log(res);
+              this.refusedQuestionList = res.data.result.content;
+              this.refusedTotalNum = res.data.result.totalElements;
+              this.refusedCurrentPage = 1;
+            })
+            .catch(error => {
+              console.log(error);
+            })
+          break;
+        default:
+          break;
+      }
+    },
+
+    handleQuestionUpdate(item) {
+      this.dialog = true;
+      this.$refs.QuestionUpdater.setForm(item);
+    },
+
+    handleQuestionCreatorAcknowledge() {
+      this.dialog = false;
     },
   },
 }
@@ -162,9 +217,10 @@ export default {
 
 .el-drawer {
   overflow-y: auto;
+  padding: 0 20px;
 }
 
-.el-dialog{
+.el-dialog {
   margin: auto auto 15vh;
 }
 </style>