Преглед изворни кода

Merge remote-tracking branch 'origin/main'

mjh пре 4 година
родитељ
комит
d928486521

+ 3 - 1
src/api/index.js

@@ -5,7 +5,8 @@ import {
     getTargetQuestionList,
     getStateQuestion,
     updateQuestion,
-    requestQuestion
+    requestQuestion,
+    getQuestionById
 } from "./question";
 
 import {getUserById,
@@ -26,6 +27,7 @@ const api = {
     getStateQuestion: getStateQuestion,
     updateQuestion: updateQuestion,
     requestQuestion: requestQuestion,
+    getQuestionById: getQuestionById,
 
     getUserById: getUserById,
 

+ 9 - 0
src/api/question.js

@@ -91,6 +91,15 @@ export function getStateQuestion(states, offset, pageSize) {
   });
 }
 
+/**
+ * 根据qid找到题目
+ * @param qid
+ * @returns {Promise<AxiosResponse<any>>}
+ */
+export function getQuestionById(qid){
+  return axios.get("/api/getQuestion/"+qid);
+}
+
 // /**
 //  * 上传题目列表到线上Bok
 //  * @param questions

+ 85 - 5
src/components/QuestionCard/UpdatingQuestionCard.vue

@@ -41,10 +41,10 @@
     <!--更新审核题目卡片的按钮-->
     <template v-slot:button>
       <el-col :span="1">
-        <el-button type="primary" icon="el-icon-check" circle @click="mockApproveQuestion"/>
+        <el-button type="primary" icon="el-icon-check" circle @click="approveQuestion"/>
       </el-col>
       <el-col :span="1">
-        <el-button type="danger" icon="el-icon-close" circle @click="mockDisapproveQuestion"/>
+        <el-button type="danger" icon="el-icon-close" circle @click="disapproveQuestion"/>
       </el-col>
     </template>
     <!--新旧题目题干不同-->
@@ -156,6 +156,7 @@ import PrimaryQuestionCard from "@/components/QuestionCard/PrimaryQuestionCard";
 import MarkdownText from "@/components/MarkdownText";
 import UpdateChoiceOption from "@/components/QuestionCard/AnswerDisplay/ChoiceDisplay/UpdatingChoiceDisplay";
 import {map} from "@/utils/knowledgeMapper";
+import store from "@/store";
 
 export default {
   name: "UpdatingQuestionCard",
@@ -243,6 +244,48 @@ export default {
 
     // 审核通过更新的题目
     approveQuestion() {
+      const _this = this;
+      for (const key in this.oldQuestionVO) {
+        if(key !== 'id' && this.newQuestionVO[key] !== null){
+          _this.oldQuestionVO[key] = _this.newQuestionVO[key];
+        }
+      }
+      _this.oldQuestionVO.state = "APPROVED";
+      let record = {
+        userId: store.state.user.id,
+        operationType: "Approve",
+      }
+      _this.$api.updateQuestion(_this.oldQuestionVO)
+          .then(res => {
+            _this.$message({
+              type: 'success',
+              message: '修改审核通过!'
+            });
+            console.log("UpdatingQuestionCard-approve");
+            console.log(res);
+            record.questionId = res.data.result.id;
+            record.time = new Date();
+            // 审核通过,添加操作记录
+            _this.$api.createRecord(record)
+                .then(res1 => {
+                  console.log("Updating-approve-createRecord");
+                  console.log(res1);
+                }).catch(err1 => {
+              console.log(err1);
+            })
+          })
+          .catch(err => {
+            _this.$notify.error({
+              title: '错误',
+              message: '通过失败'
+            });
+            console.log(err);
+          });
+      _this.$api.deleteQuestionById(_this.newQuestionVO.id).then(res => {
+        console.log("中间状态题目删除成功");
+      }).catch(err => {
+        console.log(err);
+      })
     },
 
     mockApproveQuestion() {
@@ -255,6 +298,43 @@ export default {
 
     // 审核不通过更新的题目
     disapproveQuestion() {
+      const _this = this;
+      _this.oldQuestionVO.state = "APPROVED";
+      let record = {
+        userId: store.state.user.id,
+        operationType: "Refuse",
+      }
+      _this.$api.updateQuestion(_this.oldQuestionVO)
+          .then(res => {
+            _this.$message({
+              type: 'error',
+              message: '修改审核不通过!'
+            });
+            console.log("UpdatingQuestionCard-refuse");
+            console.log(res);
+            record.questionId = res.data.result.id;
+            record.time = new Date();
+            // 审核通过,添加操作记录
+            _this.$api.createRecord(record)
+                .then(res1 => {
+                  console.log("Updating-refuse-createRecord");
+                  console.log(res1);
+                }).catch(err1 => {
+              console.log(err1);
+            })
+          })
+          .catch(err => {
+            _this.$notify.error({
+              title: '错误',
+              message: '通过失败'
+            });
+            console.log(err);
+          });
+      _this.$api.deleteQuestionById(_this.newQuestionVO.id).then(res => {
+        console.log("中间状态题目删除成功");
+      }).catch(err => {
+        console.log(err);
+      })
     },
 
     mockDisapproveQuestion() {
@@ -276,7 +356,7 @@ export default {
 }
 
 .old-content {
-  text-align: center;
+  text-align: left;
   background: #feefea;
   color: #dc745a;
   border-color: #dc745a;
@@ -284,7 +364,7 @@ export default {
 }
 
 .new-content {
-  text-align: center;
+  text-align: left;
   background: #e8fdf4;
   color: #59a48d;
   border-color: #59a48d;
@@ -308,4 +388,4 @@ export default {
   margin-right: 1%;
   height: auto;
 }
-</style>
+</style>

+ 32 - 13
src/components/QuestionUpdater.vue

@@ -160,6 +160,7 @@
 
 <script>
     import store from "../store";
+    import {createQuestion} from "@/api/question";
 
     export default {
         name: "QuestionUpdater",
@@ -202,6 +203,7 @@
                     label: '难度5'
                 }],
                 chosenTags: ["Java", "软工系列", "Python", "Vue", "SpringBoot"],
+              old_question: String,
                 myknowledgeId: '',
             }
         },
@@ -210,43 +212,60 @@
                 this.$emit('closeDialog');
             },
             updateQuestion(){
+              const old_question = JSON.parse(this.old_question);
+              // console.log("old_question", old_question);
+              // console.log("question", this.question);
+              this.question.state = null;
                 this.question.lastModifiedTime = new Date();
                 let record = {
                     userId: store.state.user.id,
                     operationType: "Update",
                 }
-                this.$api.updateQuestion(this.question).then(res => {
+                delete this.question.id;
+                this.$api.createQuestion(this.question).then(res2 => {
+                  console.log("创建中间状态的题目", res2);
+                  const new_question = res2.data.result;
+                  old_question.remark = new_question.id;
+                  old_question.state = "UPDATING";
+                  this.$api.updateQuestion(old_question).then(res => {
                     this.$notify({
-                        title: '成功',
-                        message: '更新成功',
-                        type: 'success'
+                      title: '成功',
+                      message: '更新成功',
+                      type: 'success'
                     });
 
+                    console.log(res.data.result);
                     record.questionId = res.data.result.id;
                     record.time = new Date();
                     // 如果题目更新成功,那么添加操作记录
                     this.$api.createRecord(record)
                         .then(res1 => {
-                            console.log(res1);
+                          console.log("createRecord", res1);
                         }).catch(err1 => {
-                        console.log(err1);
+                      console.log(err1);
                     })
 
                     setTimeout(() => {
-                        this.$emit('closeDialog');
+                      this.$emit('closeDialog');
                     }, 1000);
-                }).catch(err => {
+                  }).catch(err => {
                     console.log(err);
                     this.$notify.error({
-                        title: '错误',
-                        message: '更新失败'
+                      title: '错误',
+                      message: '更新失败'
                     });
-                }).finally(() => {
-                    console.log('updateQuestion');
+                  })
+                }).catch(err2 => {
+                  console.log(err2);
                 })
 
+
+
             }
-        }
+        },
+      mounted() {
+          this.old_question = JSON.stringify(this.question);
+      }
     }
 </script>
 

+ 1 - 1
src/router/index.js

@@ -94,7 +94,7 @@ router.beforeEach((to, from , next) =>{
     store.commit('setToken', id_token);
     getUserInfo().then(({ data }) => {
       store.commit('setUser', data.result)
-      next()
+      next(to.path)
     }).catch(err => {
       console.log(err);
     })

+ 28 - 2
src/store/index.js

@@ -1,5 +1,7 @@
 import { createStore } from 'vuex'
 import bok from '@/store/bok'
+import {getUserInfo} from "../api/user";
+import {jumpToLogin} from "../api/axios.config";
 
 export default createStore({
   state: {
@@ -13,9 +15,18 @@ export default createStore({
     },
     setToken(state, token){
       state.token = token;
+      localStorage.setItem('token', token);
     },
     setUser(state, user){
       state.user = user;
+      localStorage.setItem('user', user);
+    },
+    logout(state){
+      state.token = null;
+      localStorage.removeItem('token');
+      state.user = null;
+      localStorage.removeItem('user');
+      jumpToLogin();
     }
   },
   actions: {
@@ -27,9 +38,24 @@ export default createStore({
   },
   getters: {
     showCount: state => {
-      return '苏的state:'+state.myCount;
+      return 'state:'+state.myCount;
+    },
+    isLogin: state => {
+      if(state.token){
+        return true;
+      }else if(localStorage.getItem('token')){
+        state.token = localStorage.getItem('token');
+        getUserInfo().then(({ data }) => {
+          state.user = data.result;
+        }).catch(err => {
+          console.log(err);
+          jumpToLogin();
+        })
+        return true;
+      }else{
+        return false;
+      }
     },
-    isLogin: state => Boolean(state.token),
 
   },
   modules: {

+ 78 - 53
src/views/Bok/Main/Check.vue

@@ -49,7 +49,7 @@
         <!--todo: 设计UpdateQuestionCard并且在这里应用-->
         <el-pagination
           @size-change="handleSizeChange"
-          @current-change="handleCurrentChange(updateCurrentPage, updateQuestionList, 'UPDATE')"
+          @current-change="handleCurrentChange(updateCurrentPage, updateQuestionList, 'UPDATING')"
           :current-page="updateCurrentPage"
           :page-sizes="[5, 10, 15, 20]"
           :page-size="pageSize"
@@ -67,9 +67,9 @@
         />
       </el-tab-pane>
 
-      <el-tab-pane label="审核失败" name="refused">
-        <!--todo: 设计RefuseQuestionCard并且在这里应用-->
-      </el-tab-pane>
+<!--      <el-tab-pane label="审核失败" name="refused">-->
+<!--        &lt;!&ndash;todo: 设计RefuseQuestionCard并且在这里应用&ndash;&gt;-->
+<!--      </el-tab-pane>-->
 
       <el-tab-pane label="删除审核" name="executing">
         <!--todo: 设计DeleteQuestionCard并且在这里应用-->
@@ -91,25 +91,25 @@
         />
       </el-tab-pane>
 
-      <el-tab-pane label="删除完成" name="deleted">
-        <!--todo: 设计DeleteQuestionCard并且在这里应用-->
-        <el-pagination
-          @size-change="handleSizeChange"
-          @current-change="handleCurrentChange(deleteCurrentPage, deleteQuestionList, 'DELETED')"
-          :current-page="deleteCurrentPage"
-          :page-sizes="[5, 10, 15, 20]"
-          :page-size="pageSize"
-          layout="total, sizes, prev, pager, next, jumper"
-          :total=deleteTotalNum
-          v-if="deleteQuestionList.length !== 0"
-        />
-        <deleted-question-card v-for="(item, index) in deleteQuestionList"
-                               :question-v-o="item"
-                               :key="item.id"
-                               :cur-num="index+(deleteCurrentPage-1)*pageSize"
-                               :total-num="deleteTotalNum"
-        />
-      </el-tab-pane>
+<!--      <el-tab-pane label="删除完成" name="deleted">-->
+<!--        &lt;!&ndash;todo: 设计DeleteQuestionCard并且在这里应用&ndash;&gt;-->
+<!--        <el-pagination-->
+<!--          @size-change="handleSizeChange"-->
+<!--          @current-change="handleCurrentChange(deleteCurrentPage, deleteQuestionList, 'DELETED')"-->
+<!--          :current-page="deleteCurrentPage"-->
+<!--          :page-sizes="[5, 10, 15, 20]"-->
+<!--          :page-size="pageSize"-->
+<!--          layout="total, sizes, prev, pager, next, jumper"-->
+<!--          :total=deleteTotalNum-->
+<!--          v-if="deleteQuestionList.length !== 0"-->
+<!--        />-->
+<!--        <deleted-question-card v-for="(item, index) in deleteQuestionList"-->
+<!--                               :question-v-o="item"-->
+<!--                               :key="item.id"-->
+<!--                               :cur-num="index+(deleteCurrentPage-1)*pageSize"-->
+<!--                               :total-num="deleteTotalNum"-->
+<!--        />-->
+<!--      </el-tab-pane>-->
     </el-tabs>
   </div>
 </template>
@@ -149,9 +149,9 @@ export default {
       createTotalNum: 0,
 
       // 审核失败题目列表
-      refuseQuestionList: [],
-      refuseCurrentPage: 1,
-      refuseTotalNum: 0,
+      // refuseQuestionList: [],
+      // refuseCurrentPage: 1,
+      // refuseTotalNum: 0,
 
       // 更新审核题目列表
       updateQuestionList: [],
@@ -164,9 +164,9 @@ export default {
       executeTotalNum: 0,
 
       // 删除完成题目列表
-      deleteQuestionList: [],
-      deleteCurrentPage: 1,
-      deleteTotalNum: 0,
+      // deleteQuestionList: [],
+      // deleteCurrentPage: 1,
+      // deleteTotalNum: 0,
     }
   },
   methods: {
@@ -199,7 +199,11 @@ export default {
         console.log(error);
       })
     },
-
+    async getQuestionById(id){
+      let res = await this.$api.getQuestionById(id)
+      console.log("test", res.data.result);
+      return res.data.result
+    },
     // 切换分页
     handleClick(tab, event) {
       const _this = this
@@ -238,23 +242,44 @@ export default {
           break;
         // 更新审核
         case "updating":
-          mockApi.mockGetUpdateQuestion().then().catch(err => {
-            _this.updateTotalNum = err.data.length;
-            _this.updateQuestionList = err.data
-          })
-          break;
+          _this.$api.getStateQuestion(tab.props.name.toUpperCase(), 0, this.pageSize)
+              .then(async res => {
+                console.log("getStateQuestion-UPDATING");
+                const update_list = res.data.result.content;
+                let updating_num = 0;
+                // console.log(update_list)
+                for (const updateListElement of update_list) {
+                  if (updateListElement.remark) {
+                    updating_num += 1;
+                    console.log(updateListElement);
+                    let item = {"oldQuestionVO": updateListElement};
+                    let newQuestionVO = await _this.getQuestionById(updateListElement.remark);
+                    item.newQuestionVO = newQuestionVO;
+                    this.updateQuestionList.push(item);
+                  }
+                }
+                this.updateTotalNum = updating_num;
+              }).catch(err => {
+              console.log(err);
+            })
+            break;
+          // mockApi.mockGetUpdateQuestion().then().catch(err => {
+          //   _this.updateTotalNum = err.data.length;
+          //   _this.updateQuestionList = err.data
+          // })
+          // break;
         // 审核失败
-        case "refused":
-          this.$api.getStateQuestion(tab.props.name.toUpperCase(), 0, this.pageSize)
-            .then(res => {
-              console.log("getStateQuestion-REFUSED");
-              console.log(res);
-              this.refuseQuestionList = res.data.result.content;
-              this.refuseTotalNum = res.data.result.totalElements;
-            }).catch(err => {
-            console.log(err);
-          })
-          break;
+        // case "refused":
+        //   this.$api.getStateQuestion(tab.props.name.toUpperCase(), 0, this.pageSize)
+        //     .then(res => {
+        //       console.log("getStateQuestion-REFUSED");
+        //       console.log(res);
+        //       this.refuseQuestionList = res.data.result.content;
+        //       this.refuseTotalNum = res.data.result.totalElements;
+        //     }).catch(err => {
+        //     console.log(err);
+        //   })
+        //   break;
         // 删除审核
         case "executing":
           mockApi.mockGetExecuteQuestion().then().catch(err => {
@@ -263,13 +288,13 @@ export default {
             _this.executeQuestionList = err.data
           })
           break;
-        case "deleted":
-          mockApi.mockGetExecuteQuestion().then().catch(err => {
-            console.log(err)
-            _this.deleteTotalNum = err.data.length;
-            _this.deleteQuestionList = err.data
-          })
-          break;
+        // case "deleted":
+        //   mockApi.mockGetExecuteQuestion().then().catch(err => {
+        //     console.log(err)
+        //     _this.deleteTotalNum = err.data.length;
+        //     _this.deleteQuestionList = err.data
+        //   })
+        //   break;
         default:
           break;
       }

+ 89 - 69
src/views/Bok/NavBar.vue

@@ -1,65 +1,71 @@
 <template>
-    <div class="navbar-wrapper">
-        <el-input placeholder="请输入内容" v-model="searchContent" size="mini" class="input-with-select"
-        v-if="$route.path!=='/search'" @keydown.enter="clickSearch">
-            <template #append>
-                <el-button icon="el-icon-search" @click="clickSearch"/>
-            </template>
-        </el-input>
-        <el-dropdown trigger="click" style="position: absolute;top: 0px;right: 0px">
-          <p style="position: absolute;top: 15px;left: -80px">{{$store.state.user.name}}</p>
-            <el-avatar shape="square" :size="30" :src="squareUrl"></el-avatar>
-            <template #dropdown>
-                <el-dropdown-menu>
-                    <el-dropdown-item>{{$store.state.user.name}}</el-dropdown-item>
-                    <el-dropdown-item>选项2</el-dropdown-item>
-                    <el-dropdown-item>选项3</el-dropdown-item>
-                    <el-dropdown-item>选项4</el-dropdown-item>
-                </el-dropdown-menu>
-            </template>
-        </el-dropdown>
-    </div>
+  <div class="navbar-wrapper">
+    <el-input placeholder="请输入内容" v-model="searchContent" size="mini" class="input-with-select"
+              v-if="$route.path!=='/search'" @keydown.enter="clickSearch">
+      <template #append>
+        <el-button icon="el-icon-search" @click="clickSearch"/>
+      </template>
+    </el-input>
+    <el-dropdown trigger="click" style="position: absolute;top: 0px;right: 0px">
+      <div class="user-wrap">
+        <span class="user-name">{{ $store.state.user.name }}</span>
+        <el-avatar shape="square" :size="30" :src="squareUrl"></el-avatar>
+      </div>
+      <template #dropdown>
+        <el-dropdown-menu>
+<!--          <el-dropdown-item>{{ $store.state.user.name }}</el-dropdown-item>-->
+          <el-dropdown-item @click="logout">
+            <i class="el-icon-switch-button"></i>
+            登出
+          </el-dropdown-item>
+        </el-dropdown-menu>
+      </template>
+    </el-dropdown>
+  </div>
 </template>
 
 <script>
 export default {
-    name: "NavBar",
-    data() {
-        return {
-            //
-            searchContent: "",
+  name: "NavBar",
+  data() {
+    return {
+      //
+      searchContent: "",
 
-            systemName: "bok",
-            squareUrl: "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png",
-        }
-    },
-    computed: {
-        path() {
-            const _this = this
-            let res = _this.$store.getters['bok/getPath'].split("/")
-            res[0] = _this.systemName
-            return res
-        }
-    },
-    mounted() {
-    },
-    methods: {
-        //
-        clickSearch(){
-            const _this = this
-            let content = _this.searchContent
-            _this.searchContent = ""
-            if(content!==""){
-                this.$router.replace({
-                    name: "Search",
-                    path:'/Search',
-                    params:{
-                        searchContent:content,
-                    }
-                })
-            }
-        },
+      systemName: "bok",
+      squareUrl: "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png",
+    }
+  },
+  computed: {
+    path() {
+      const _this = this
+      let res = _this.$store.getters['bok/getPath'].split("/")
+      res[0] = _this.systemName
+      return res
+    }
+  },
+  mounted() {
+  },
+  methods: {
+    //
+    clickSearch() {
+      const _this = this
+      let content = _this.searchContent
+      _this.searchContent = ""
+      if (content !== "") {
+        this.$router.replace({
+          name: "Search",
+          path: '/Search',
+          params: {
+            searchContent: content,
+          }
+        })
+      }
     },
+    logout() {
+      this.$store.commit('logout');
+    }
+  },
 }
 </script>
 
@@ -67,34 +73,48 @@ export default {
 @import "../../style/variables";
 
 .navbar-wrapper {
-    height: 50px;
-    box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
-    position: relative;
+  height: 50px;
+  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
+  position: relative;
 }
 
 .el-breadcrumb {
-    height: calc(100% - 30px);
-    padding: 15px;
-    font-size: 20px;
+  height: calc(100% - 30px);
+  padding: 15px;
+  font-size: 20px;
+}
+
+.user-wrap{
+  display: flex;
+  cursor: pointer;
+
+  .user-name{
+    margin-right: 16px;
+    padding-top: 18px;
+  }
+}
+
+.el-dropdown:hover{
+  cursor: pointer;
 }
 
 .el-avatar {
-    margin: 10px;
+  margin: 10px;
 }
 
 .el-avatar:hover {
-    cursor: pointer;
+  cursor: pointer;
 }
 
 .el-input {
-    position: absolute;
-    top: 11px;
-    left: 25%;
-    //height: 50%;
-    width: 50%;
+  position: absolute;
+  top: 11px;
+  left: 25%;
+  //height: 50%;
+  width: 50%;
 }
 
 .input-with-select .el-input-group__prepend {
-    background-color: #fff;
+  background-color: #fff;
 }
 </style>

+ 3 - 3
src/views/Bok/SideBar.vue

@@ -25,11 +25,11 @@
         <i class="el-icon-menu"></i>
         <template #title>知识点</template>
       </el-menu-item>
-      <el-menu-item index="knowledgeGraph">
+      <el-menu-item index="knowledgeGraph"  v-if="false">
         <i class="el-icon-connection"></i>
         <template #title>知识图谱</template>
       </el-menu-item>
-      <el-menu-item index="paper">
+      <el-menu-item index="paper"  v-if="false">
         <i class="el-icon-document"></i>
         <template #title>试卷袋</template>
       </el-menu-item>
@@ -37,7 +37,7 @@
         <i class="el-icon-circle-check"></i>
         <template #title>审核</template>
       </el-menu-item>
-      <el-menu-item index="setting">
+      <el-menu-item index="setting" v-if="false">
         <i class="el-icon-setting"></i>
         <template #title>设置</template>
       </el-menu-item>