瀏覽代碼

修复页面刷新丢失数据bug

Johnson 7 年之前
父節點
當前提交
cace91fcfb

+ 23 - 5
mock/modules/assignment/index.js

@@ -42,6 +42,14 @@ router.route("/teacher/course/:courseId/code").get((req, res) => {
   });
 });
 
+//老师查看单个代码作业
+router.route("/teacher/:codeId").get((req, res) => {
+  res.send({
+    code: 0,
+    data: CodeSerializer()
+  });
+});
+
 //学生查看代码作业列表
 router.route("/student/course/:courseId/code").get((req, res) => {
   res.send({
@@ -132,6 +140,14 @@ router.route("/teacher/course/:courseId/document").get((req, res) => {
   });
 });
 
+//老师查看单个文档作业
+router.route("/teacher/document/:documentId").get((req, res) => {
+  res.send({
+    code: 0,
+    data: DocumentSerializer()
+  });
+});
+
 //学生查看文档作业列表
 router.route("/student/course/:courseId/document").get((req, res) => {
   res.send({
@@ -179,11 +195,13 @@ router.route("/student/document/:documentId/result").get((req, res) => {
   });
 });
 
-router.route("/teacher/document/:documentId/content").get((req, res) => {
-  res.send({
-    code: 0,
-    data: DocumentContentSerializer()
+router
+  .route("/teacher/document/result/:documentResultId/content")
+  .get((req, res) => {
+    res.send({
+      code: 0,
+      data: DocumentContentSerializer()
+    });
   });
-});
 
 module.exports = router;

+ 2 - 1
mock/serializers/assignment/DocumentResultSerializer.js

@@ -1,5 +1,6 @@
 const makeId = require("../../util/makeId");
 const groupSerializer = require("../course/GroupSerializer");
+const documentSerializer = require("../assignment/DocumentSerializer");
 /**
  * @description 文档作业成绩
  * @typedef {Object} DocumentResultSerializerType
@@ -18,7 +19,7 @@ const groupSerializer = require("../course/GroupSerializer");
 module.exports = () => {
   return {
     id: makeId(),
-    document: makeId(),
+    document: documentSerializer(),
     group: groupSerializer(),
     state: "互评中",
     result: "A",

+ 18 - 0
src/api/assignment.js

@@ -71,6 +71,15 @@ export const getCodeAssignmentListByTeacher = courseId => {
   return request(`${ASSIGNMENT_MODULE}/teacher/course/${courseId}/code`);
 };
 
+/**
+ * 老师查看单个代码作业
+ * @param codeId
+ * @returns {Promise<{data:CodeSerializerType}>}
+ */
+export const getCodeAssignmentByTeacher = codeId => {
+  return request(`${ASSIGNMENT_MODULE}/teacher/${codeId}`);
+};
+
 /**
  * 学生查看代码作业列表
  * @param courseId
@@ -210,6 +219,15 @@ export const getDocAssignmentListTeacherByCrs = courseId => {
   return request(`${ASSIGNMENT_MODULE}/teacher/course/${courseId}/document`);
 };
 
+/**
+ * 老师查看单个文档作业
+ * @param documentId
+ * @returns {Promise<{data:DocumentSerializerType}>}
+ */
+export const getDocAssignmentTeacherByCrs = documentId => {
+  return request(`${ASSIGNMENT_MODULE}/teacher/document/${documentId}`);
+};
+
 /**
  * 学生查看文档作业列表
  * @param courseId

+ 2 - 2
src/router/routes.js

@@ -85,7 +85,7 @@ export default [
         component: () => import("@/views/teacher/Code/detail")
       },
       {
-        path: "code/:codeId/test",
+        path: "code/:codeId/test/:testId",
         component: () => import("@/views/teacher/Code/test")
       },
 
@@ -98,7 +98,7 @@ export default [
         component: () => import("@/views/teacher/Document/detail")
       },
       {
-        path: "document/:documentId/content",
+        path: "document/:documentId/content/:groupWorkId",
         component: () => import("@/views/teacher/Document/docContent")
       },
       {

+ 5 - 14
src/views/student/Document/detail.vue

@@ -8,10 +8,10 @@
       ]"
     >
       <template slot="title">
-        {{ assignmentInfo.name }}
+        {{ detail.name }}
       </template>
       <template slot="content">
-        {{ assignmentInfo.description }}
+        {{ detail.description }}
       </template>
       <template slot="action" v-if="loadingDocResult">
         <a class="button is-primary">成绩:{{ docResult.result }}</a>
@@ -84,14 +84,6 @@ import DocumentStateTag from "@/components/DocumentStateTag";
 import timeMixins from "@/mixins/time";
 import PageSectionLoading from "@/components/PageBody/PageSectionLoading/index";
 
-const assignmentInfo = {
-  id: 0,
-  name: "",
-  description: "",
-  startAt: 0,
-  endAt: 0
-};
-
 export default {
   components: {
     PageSectionLoading,
@@ -101,15 +93,15 @@ export default {
   },
   mixins: [timeMixins],
   mounted() {
+    const { documentId } = this.$route.params;
     this.loadingDocDetail = true;
-    this.assignmentInfo = this.$route.query.assignmentInfo;
-    getDocAssignmentDetailByDocuId(this.assignmentInfo.id).then(res => {
+    getDocAssignmentDetailByDocuId(documentId).then(res => {
       this.detail = res.data;
       this.loadingDocDetail = false;
       this.isAvailable =
         this.detail.status === "AVAILABLE" || this.detail.status === "FINISHED";
     });
-    getDocResultById(this.assignmentInfo.id).then(res => {
+    getDocResultById(documentId).then(res => {
       this.docResult = res.data;
       // 有成绩
       // 修改为String
@@ -120,7 +112,6 @@ export default {
   },
   data() {
     return {
-      assignmentInfo,
       detail: {},
       docResult: {},
       loadingDocResult: false,

+ 1 - 6
src/views/student/Document/index.vue

@@ -22,12 +22,7 @@
           v-for="item in docList"
           class="column is-4-desktop"
         >
-          <router-link
-            :to="{
-              path: `${$route.path}/${item.id}`,
-              query: { assignmentInfo: item }
-            }"
-          >
+          <router-link :to="{ path: `${$route.path}/${item.id}` }">
             <card hoverable>
               {{ item.name }}
               <div>

+ 18 - 18
src/views/teacher/Code/detail.vue

@@ -4,14 +4,14 @@
       :loading="loadingCommittedGroups"
       :routes="[
         { name: '代码作业', path: 'code' },
-        { name: '作业详情', path: 'code/${assignmentInfo.id}' }
+        { name: '作业详情', path: `${$route.path}` }
       ]"
     >
       <template slot="title">
-        {{ assignmentInfo.name }}
+        {{ problemInfo.name }}
       </template>
       <template slot="content">
-        作业描述信息作业描述信息作业描述信息作业描述信息作业描述信息作业描述信息作业描述信息
+        {{ problemInfo.description }}
       </template>
     </page-header>
 
@@ -89,8 +89,7 @@
                 <b-table-column label="详情" centered>
                   <router-link
                     :to="{
-                      path: `/course-teacher/:courseId/code/detail/test`,
-                      query: { assignmentInfo: props.row }
+                      path: `${$route.path}/test/${props.row.id}`
                     }"
                     >查看详情</router-link
                   >
@@ -152,15 +151,9 @@ import PageHeader from "@/components/PageHeader";
 import PageBody from "@/components/PageBody/index";
 import { getCodeProcedureListByCodeId } from "@/api/assignment";
 import { getUnsubmittedCodeGroupsList } from "@/api/assignment";
-import PageSectionLoading from "@/components/PageBody/PageSectionLoading/index";
+import { getCodeAssignmentByTeacher } from "@/api/assignment";
 
-const assignmentInfo = {
-  id: 0,
-  name: "",
-  description: "",
-  startAt: 0,
-  endAt: 0
-};
+import PageSectionLoading from "@/components/PageBody/PageSectionLoading/index";
 
 const tag = {
   success: "tag is-success",
@@ -181,15 +174,18 @@ export default {
     PageSectionLoading
   },
   mounted() {
+    this.codeId = this.$route.params;
     this.loadingUncommittedGroups = true;
     this.loadingCommittedGroups = true;
-    this.assignmentInfo = this.$route.query.assignmentInfo;
-    getCodeProcedureListByCodeId(this.$route.params.codeId).then(res => {
+    getCodeAssignmentByTeacher(this.codeId).then(res => {
+      this.problemInfo = res.data.problem;
+    });
+    getCodeProcedureListByCodeId(this.codeId).then(res => {
       this.codeProcedureList = res.data;
       this.submitInfo.yes = "已提交:" + this.codeProcedureList.length;
       this.loadingCommittedGroups = false;
     });
-    getUnsubmittedCodeGroupsList(this.$route.params.codeId).then(res => {
+    getUnsubmittedCodeGroupsList(this.codeId).then(res => {
       this.unsubmitedGroups = res.data;
       this.submitInfo.no = "未提交:" + this.unsubmitedGroups.length;
       this.loadingUncommittedGroups = false;
@@ -197,10 +193,14 @@ export default {
   },
   data() {
     return {
+      codeId: null,
       codeProcedureList: [],
       unsubmitedGroups: [],
-      showResult: [],
-      assignmentInfo,
+      problemInfo: {
+        id: null,
+        name: null,
+        description: null
+      },
       tag,
       status,
       submitInfo: {

+ 1 - 4
src/views/teacher/Code/index.vue

@@ -36,10 +36,7 @@
             <b-table-column label="作业名称" centered>
               <router-link
                 :to="{
-                  path: `code/${props.row.id}`,
-                  query: {
-                    assignmentInfo: props.row.problem
-                  }
+                  path: `code/${props.row.id}`
                 }"
               >
                 {{ props.row.name }}

+ 4 - 5
src/views/teacher/Code/test.vue

@@ -3,7 +3,7 @@
     <page-header
       :routes="[
         { name: '代码作业', path: 'code' },
-        { name: '作业详情', path: `code/${assignmentInfo.id}` },
+        { name: '作业详情', path: `code/${$route.params.codeId}` },
         { name: '测试信息', path: `${$route.path}` }
       ]"
     >
@@ -31,12 +31,11 @@ export default {
     PageHeader
   },
   mounted() {
-    this.assignmentInfo = this.$route.query.assignmentInfo;
+    const { testId } = this.$route.params;
+    console.log(testId);
   },
   data() {
-    return {
-      assignmentInfo: {}
-    };
+    return {};
   }
 };
 </script>

+ 16 - 13
src/views/teacher/Document/detail.vue

@@ -4,14 +4,14 @@
       :loading="loadingCommittedGroups"
       :routes="[
         { name: '文档作业', path: 'document' },
-        { name: `作业详情`, path: `document` }
+        { name: `作业详情`, path: `${$route.path}` }
       ]"
     >
       <template slot="title">
-        {{ question.name }}
+        {{ problem.name }}
       </template>
       <template slot="content">
-        题目描述:{{ question.description }}
+        题目描述:{{ problem.description }}
       </template>
       <template slot="extraContent">
         题目进行阶段:{{ status }}
@@ -56,8 +56,7 @@
                 <b-table-column field="difficulty" label="详情" centered
                   ><router-link
                     :to="{
-                      path: `${$route.path}/content`,
-                      query: { groupWorkId: props.row.id }
+                      path: `${$route.path}/content/${props.row.id}`
                     }"
                     >查看详情</router-link
                   >
@@ -123,6 +122,7 @@ import PageHeader from "@/components/PageHeader";
 import PageBody from "@/components/PageBody/index";
 import { getSubmittedDocResultListByDocId } from "@/api/assignment";
 import { getUnsubmittedDocGroupsByDocId } from "@/api/assignment";
+import { getDocAssignmentTeacherByCrs } from "@/api/assignment";
 import { mapState } from "vuex";
 import PageSectionLoading from "@/components/PageBody/PageSectionLoading/index";
 
@@ -137,20 +137,20 @@ export default {
     PageHeader,
     PageSectionLoading
   },
-  created() {
-    this.docId = this.$route.query.docId;
-    this.question = this.$route.query.question;
-  },
   mounted() {
+    const { documentId } = this.$route.query;
     this.loadingCommittedGroups = true;
     this.loadingUncommittedGroups = true;
-    getSubmittedDocResultListByDocId(this.docId).then(res => {
+    getDocAssignmentTeacherByCrs(documentId).then(res => {
+      this.problem = res.data.problem;
+    });
+    getSubmittedDocResultListByDocId(documentId).then(res => {
       this.status = res.data.status;
       this.submittedData = res.data.result;
       this.submitInfo.yes = "已提交:" + this.submittedData.length;
       this.loadingCommittedGroups = false;
     });
-    getUnsubmittedDocGroupsByDocId(this.docId).then(res => {
+    getUnsubmittedDocGroupsByDocId(documentId).then(res => {
       this.unsubmitedGroups = res.data;
       this.submitInfo.no = "未提交:" + this.unsubmitedGroups.length;
       this.loadingUncommittedGroups = false;
@@ -158,11 +158,14 @@ export default {
   },
   data() {
     return {
+      problem: {
+        id: null,
+        name: null,
+        description: null
+      },
       submittedData: [],
       unsubmitedGroups: [],
       status: "",
-      question: null,
-      docId: null,
       submitInfo: {
         yes: "已提交",
         no: "未提交"

+ 4 - 6
src/views/teacher/Document/docContent.vue

@@ -6,7 +6,7 @@
         { name: '文档作业', path: 'document' },
         {
           name: `作业详情`,
-          path: `document/${groupWorkId}`
+          path: `document/${$route.params.documentId}`
         },
         { name: `文档内容`, path: `${$route.path}` }
       ]"
@@ -57,7 +57,6 @@ export default {
   },
   data() {
     return {
-      groupWorkId: null,
       contentResult: {
         content: "",
         group: "",
@@ -67,12 +66,11 @@ export default {
       loadingDocContent: false
     };
   },
-  created() {
-    this.groupWorkId = this.$route.query.groupWorkId;
-  },
+
   mounted() {
     this.loadingDocContent = true;
-    getDocContentByDocId(this.groupWorkId).then(res => {
+    const { groupWorkId } = this.$route.params;
+    getDocContentByDocId(groupWorkId).then(res => {
       this.contentResult = res.data;
       this.loadingDocContent = false;
     });

+ 1 - 2
src/views/teacher/Document/index.vue

@@ -32,8 +32,7 @@
               <b-table-column label="作业名称" centered>
                 <router-link
                   :to="{
-                    path: `${$route.path}/${props.row.id}`,
-                    query: { docId: props.row.id, question: props.row.problem }
+                    path: `${$route.path}/${props.row.id}`
                   }"
                 >
                   {{ props.row.name }}