Kaynağa Gözat

移动端答题

natasha 1 yıl önce
ebeveyn
işleme
483ecdc853
1 değiştirilmiş dosya ile 172 ekleme ve 82 silme
  1. 172 82
      src/views/courseWare.vue

+ 172 - 82
src/views/courseWare.vue

@@ -118,7 +118,7 @@ import { getContens } from "@/api/ajax";
 import Cookies from "js-cookie";
 // import Preview from '@/componentsAnswer/PreviewAnswer.vue'
 import Preview from "@/components/Preview";
-import { getStaticContent } from "@/api/ajax";
+import { getStaticContent, getContent, LearnWebSI } from "@/api/ajax";
 import { setToken } from "@/utils/auth";
 export default {
   name: "CourseWare",
@@ -203,15 +203,18 @@ export default {
       deep: true,
     },
   },
-  created() {
+  async created() {
     const _this = this;
     if (_this.AccessToken) {
       const Mname = "login_control-ParseAccessToken";
-      getStaticContent(Mname, {
+      await getStaticContent(Mname, {
         access_token: _this.AccessToken,
       }).then((res) => {
         setToken(res);
         sessionStorage.setItem("GCLS_Token_Book", JSON.stringify(res));
+        if (_this.AppID === "Mobile_Task") {
+          _this.UserID = res.user_code;
+        }
       });
     }
     if (_this.ViewMode === "Answer") {
@@ -275,37 +278,75 @@ export default {
         courseware_id: _this.CoursewareID,
         user_id: _this.UserID,
       };
-      getContens(MethodName, data, AccessToken, AppID).then((res) => {
-        this.category = res.category;
-        this.themeColor = res.book_theme_color;
-        this.bookFontSize = res.book_font_size;
-        if (res.content) {
-          const _this = this;
-          if (!this.category || this.category == "OC") {
-            _this.context = {
-              id: _this.chapterId,
-              ui_type: JSON.parse(res.content).question
-                ? JSON.parse(res.content).question.ui_type
-                : "",
-              sort_number: 1,
-              content: JSON.parse(res.content),
-            };
+      if (_this.AppID === "Mobile_Task") {
+        const MethodName = "book-courseware_manager-GetCoursewareContent_View";
+        const data = {
+          id: _this.chapterId,
+        };
+        getContent(MethodName, data).then((res) => {
+          this.category = res.category;
+          this.themeColor = res.book_theme_color;
+          this.bookFontSize = res.book_font_size;
+          if (res.content) {
+            const _this = this;
+            if (!this.category || this.category == "OC") {
+              _this.context = {
+                id: _this.chapterId,
+                ui_type: JSON.parse(res.content).question
+                  ? JSON.parse(res.content).question.ui_type
+                  : "",
+                sort_number: 1,
+                content: JSON.parse(res.content),
+              };
+            } else {
+              _this.context = JSON.parse(res.content);
+            }
+            setTimeout(() => {
+              if (_this.ViewMode === "Answer") {
+                _this.$refs.previewBook.handleAnswerTimeStart();
+              }
+            }, 200);
           } else {
-            _this.context = JSON.parse(res.content);
+            const _this = this;
+            _this.context = null;
           }
-          setTimeout(() => {
-            if (_this.ViewMode === "Answer") {
-              _this.$refs.previewBook.handleAnswerTimeStart();
+          if (_this.ViewMode !== "Result") {
+            this.loading = false;
+          }
+        });
+      } else {
+        getContens(MethodName, data, AccessToken, AppID).then((res) => {
+          this.category = res.category;
+          this.themeColor = res.book_theme_color;
+          this.bookFontSize = res.book_font_size;
+          if (res.content) {
+            const _this = this;
+            if (!this.category || this.category == "OC") {
+              _this.context = {
+                id: _this.chapterId,
+                ui_type: JSON.parse(res.content).question
+                  ? JSON.parse(res.content).question.ui_type
+                  : "",
+                sort_number: 1,
+                content: JSON.parse(res.content),
+              };
+            } else {
+              _this.context = JSON.parse(res.content);
             }
-          }, 200);
-        } else {
-          const _this = this;
-          _this.context = null;
-        }
-        if (_this.ViewMode !== "Result") {
-          this.loading = false;
-        }
-      });
+            setTimeout(() => {
+              if (_this.ViewMode === "Answer") {
+                _this.$refs.previewBook.handleAnswerTimeStart();
+              }
+            }, 200);
+          } else {
+            const _this = this;
+            _this.context = null;
+          }
+          if (_this.ViewMode !== "Result") {
+            this.loading = false;
+          }
+        });
+      }
     },
     // 跳转编辑页面
     handleEdit() {
@@ -342,31 +383,56 @@ export default {
       // console.log("答对个数" + rightNumber);
       // console.log("答错个数" + errorNumber);
       this.loading = true;
-      const AppID = this.AppID;
-      const AccessToken = this.AccessToken;
-      const MethodName =
-        "/TeachingServer/BookIntegrationManager/SaveCoursewareExamAnswer";
-      let datas = {
-        courseware_id: this.CoursewareID,
-        user_id: this.UserID,
-        business_id: this.BusinessID,
-        exam_answer: {
-          duration: time,
-          count_right: rightNumber,
-          count_error: errorNumber,
-          content: data,
-        },
-      };
-      getContens(MethodName, datas, AccessToken, AppID)
-        .then((res) => {
-          this.loading = false;
-          if (res.status === 1) {
-            this.$message.success("提交成功");
-          }
-        })
-        .catch(() => {
-          this.loading = false;
-        });
+      if (this.AppID === "Mobile_Task") {
+        const MethodName = "teaching-task_manager-FinishMyTaskMaterial_Student";
+        const datas = {
+          task_id: this.BusinessID,
+          material_id: this.CoursewareID,
+          material_type: "COURSEWARE",
+          exam_answer: {
+            duration: time,
+            count_right: rightNumber,
+            count_error: errorNumber,
+            content: data,
+          },
+        };
+        LearnWebSI(MethodName, datas)
+          .then((res) => {
+            this.loading = false;
+            if (res.status === 1) {
+              this.$message.success("提交成功");
+            }
+          })
+          .catch(() => {
+            this.loading = false;
+          });
+      } else {
+        const AppID = this.AppID;
+        const AccessToken = this.AccessToken;
+        const MethodName =
+          "/TeachingServer/BookIntegrationManager/SaveCoursewareExamAnswer";
+        let datas = {
+          courseware_id: this.CoursewareID,
+          user_id: this.UserID,
+          business_id: this.BusinessID,
+          exam_answer: {
+            duration: time,
+            count_right: rightNumber,
+            count_error: errorNumber,
+            content: data,
+          },
+        };
+        getContens(MethodName, datas, AccessToken, AppID)
+          .then((res) => {
+            this.loading = false;
+            if (res.status === 1) {
+              this.$message.success("提交成功");
+            }
+          })
+          .catch(() => {
+            this.loading = false;
+          });
+      }
     },
     finishPreviewGroupId() {
       this.$refs.previewBook.submitPreviewGroupId();
@@ -380,33 +446,57 @@ export default {
     // 获取用户答题信息
     getUserAnswer() {
       this.loading = true;
-      const AppID = this.AppID;
-      const AccessToken = this.AccessToken;
-      const MethodName =
-        "/TeachingServer/BookIntegrationManager/GetCoursewareExamAnswer";
-      let datas = {
-        courseware_id: this.CoursewareID,
-        user_id: this.UserID,
-        business_id: this.BusinessID,
-      };
-      getContens(MethodName, datas, AccessToken, AppID)
-        .then((res) => {
-          if (res.status === 1) {
-            let exam_answer = res.exam_answer
-              ? JSON.parse(res.exam_answer)
-              : null;
-            if (!exam_answer) return;
-            this.bookAnswerContent = exam_answer.content;
-            this.duration = exam_answer.duration;
-            this.rightNumber = exam_answer.count_right;
-            this.errorNumber = exam_answer.count_error;
-          } else {
+      if (this.AppID === "Mobile_Task") {
+        const MethodName =
+          "teaching-task_manager-GetTaskMaterialStudentExamAnswer";
+        let datas = {
+          task_id: this.BusinessID,
+          material_id: this.CoursewareID,
+          material_type: "COURSEWARE",
+          student_id: this.UserID,
+        };
+        LearnWebSI(MethodName, datas)
+          .then((res) => {
             this.loading = false;
-          }
-        })
-        .catch(() => {
-          this.loading = false;
-        });
+            if (res.status === 1) {
+              this.bookAnswerContent = res.content;
+              this.duration = res.duration;
+              this.rightNumber = res.count_right;
+              this.errorNumber = res.count_error;
+            }
+          })
+          .catch(() => {
+            this.loading = false;
+          });
+      } else {
+        const AppID = this.AppID;
+        const AccessToken = this.AccessToken;
+        const MethodName =
+          "/TeachingServer/BookIntegrationManager/GetCoursewareExamAnswer";
+        let datas = {
+          courseware_id: this.CoursewareID,
+          user_id: this.UserID,
+          business_id: this.BusinessID,
+        };
+        getContens(MethodName, datas, AccessToken, AppID)
+          .then((res) => {
+            if (res.status === 1) {
+              let exam_answer = res.exam_answer
+                ? JSON.parse(res.exam_answer)
+                : null;
+              if (!exam_answer) return;
+              this.bookAnswerContent = exam_answer.content;
+              this.duration = exam_answer.duration;
+              this.rightNumber = exam_answer.count_right;
+              this.errorNumber = exam_answer.count_error;
+            } else {
+              this.loading = false;
+            }
+          })
+          .catch(() => {
+            this.loading = false;
+          });
+      }
     },
     handleDateTime(time) {
       if (parseInt(time / 60) < 10) {