Browse Source

feat(课程同步): 添加课程数据同步功能并在多个时机触发

在多个组件中添加doSyncClassData方法用于同步课程数据
在setoTime、destroyed和mounted等生命周期中调用同步方法
统一处理课程数据同步逻辑,避免代码重复
lsc 1 week ago
parent
commit
96897f61fd

+ 24 - 18
src/components/easy2/studyStudent.vue

@@ -21969,6 +21969,7 @@ export default {
       }, 600000);
     },
     setoTime(time) {
+      this.doSyncClassData();
       let params = [
         {
           uid: this.userid,
@@ -25727,7 +25728,25 @@ export default {
         .catch(err => {
           console.error(err);
         });
-    }
+    },
+    doSyncClassData(){
+      if(this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840'){
+        let endTime = new Date().toLocaleString("zh-CN", { 
+            hour12: false, 
+            timeZone: "Asia/Shanghai" 
+          }).replace(/\//g, "-")
+        let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
+        this.syncClassData({
+          courseId: this.id,
+          title: this.courseDetail.title,
+          courseGrade: this.tcid2 ? this.tcid2 : '',
+          courseTime: courseTime,
+          startTime: this.startTime,
+          endTime: endTime,
+        })
+        console.log('同步数据')
+      }
+    },
   },
   directives: {
     // 使用局部注册指令的方式
@@ -25776,22 +25795,7 @@ export default {
     clearInterval(this.opertimer);
     this.opertimer = null;
     this.updateSplitScreenData(1);
-    if(this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840'){
-      let endTime = new Date().toLocaleString("zh-CN", { 
-          hour12: false, 
-          timeZone: "Asia/Shanghai" 
-        }).replace(/\//g, "-")
-      let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
-      this.syncClassData({
-        courseId: this.id,
-        title: this.courseDetail.title,
-        courseGrade: this.tcid2 ? this.tcid2 : '',
-        courseTime: courseTime,
-        startTime: this.startTime,
-        endTime: endTime,
-      })
-      console.log('同步数据')
-    }
+    this.doSyncClassData();
   },
   computed: {
     renderedFormula2() {
@@ -26027,7 +26031,9 @@ export default {
     } catch (error) {
       console.log(error)
     }
-
+    setTimeout(() => {
+      this.doSyncClassData();
+    }, 1000);
     this.getCode2()
     this.setOperationTime();
     this.selectEva();

+ 24 - 17
src/components/easy3/studyStudent.vue

@@ -17381,6 +17381,7 @@ export default {
       }, 600000);
     },
     setoTime(time) {
+      this.doSyncClassData();
       let params = [
         {
           uid: this.userid,
@@ -21052,7 +21053,25 @@ export default {
     StulookMode(flag) {
       this.IsStulook = flag;
       this.updateIsStulook();
-    }
+    },
+    doSyncClassData(){
+      if(this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840'){
+        let endTime = new Date().toLocaleString("zh-CN", { 
+            hour12: false, 
+            timeZone: "Asia/Shanghai" 
+          }).replace(/\//g, "-")
+        let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
+        this.syncClassData({
+          courseId: this.id,
+          title: this.courseDetail.title,
+          courseGrade: this.tcid2 ? this.tcid2 : '',
+          courseTime: courseTime,
+          startTime: this.startTime,
+          endTime: endTime,
+        })
+        console.log('同步数据')
+      }
+    },
   },
   directives: {
     // 使用局部注册指令的方式
@@ -21099,22 +21118,7 @@ export default {
     clearInterval(this.opertimer);
     this.opertimer = null;
 		this.updateSplitScreenData(1);
-    if(this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840'){
-      let endTime = new Date().toLocaleString("zh-CN", { 
-          hour12: false, 
-          timeZone: "Asia/Shanghai" 
-        }).replace(/\//g, "-")
-      let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
-      this.syncClassData({
-        courseId: this.id,
-        title: this.courseDetail.title,
-        courseGrade: this.tcid2 ? this.tcid2 : '',
-        courseTime: courseTime,
-        startTime: this.startTime,
-        endTime: endTime,
-      })
-      console.log('同步数据')
-    }
+    this.doSyncClassData();
   },
   computed: {
     renderedFormula2() {
@@ -21348,6 +21352,9 @@ export default {
     } catch (error) {
       console.log(error)
     }
+    setTimeout(() => {
+      this.doSyncClassData();
+    }, 1000);
     this.getCode2()
     this.setOperationTime();
     this.selectEva();

+ 23 - 16
src/components/pptEasyClass/index.vue

@@ -489,6 +489,7 @@ export default {
       }, 600000);
     },
     setoTime(time) {
+      this.doSyncClassData();
       let params = [
         {
           uid: this.userid,
@@ -513,26 +514,29 @@ export default {
 				this.jArray = Array;
 			})
 		},
+    doSyncClassData(){
+      if (this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840') {
+        let endTime = new Date().toLocaleString("zh-CN", {
+          hour12: false,
+          timeZone: "Asia/Shanghai"
+        }).replace(/\//g, "-")
+        let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
+        this.syncClassData({
+          courseId: this.id,
+          title: this.courseDetail.title,
+          courseGrade: this.tcid2 ? this.tcid2 : '',
+          courseTime: courseTime,
+          startTime: this.startTime,
+          endTime: endTime,
+        })
+        console.log('同步数据')
+      }
+    },
   },
   destroyed() {
     clearInterval(this.opertimer);
     this.opertimer = null;
-    if (this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840') {
-      let endTime = new Date().toLocaleString("zh-CN", {
-        hour12: false,
-        timeZone: "Asia/Shanghai"
-      }).replace(/\//g, "-")
-      let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
-      this.syncClassData({
-        courseId: this.id,
-        title: this.courseDetail.title,
-        courseGrade: this.tcid2 ? this.tcid2 : '',
-        courseTime: courseTime,
-        startTime: this.startTime,
-        endTime: endTime,
-      })
-      console.log('同步数据')
-    }
+    this.doSyncClassData();
   },
   async mounted() {
     this.setoTime("1");
@@ -554,6 +558,9 @@ export default {
         });
         this.userJson = res.data[0][0]
     }
+    setTimeout(() => {
+      this.doSyncClassData();
+    }, 1000);
   }
 };
 </script>

+ 23 - 16
src/components/studyStudent.vue

@@ -17315,6 +17315,7 @@ export default {
       }, 600000);
     },
     setoTime(time) {
+      this.doSyncClassData();
       let params = [
         {
           uid: this.userid,
@@ -21004,6 +21005,24 @@ export default {
       this.IsStulook = flag;
       this.updateIsStulook();
     },
+    doSyncClassData(){
+      if(this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840'){
+        let endTime = new Date().toLocaleString("zh-CN", { 
+            hour12: false, 
+            timeZone: "Asia/Shanghai" 
+          }).replace(/\//g, "-")
+        let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
+        this.syncClassData({
+          courseId: this.id,
+          title: this.courseDetail.title,
+          courseGrade: this.tcid2 ? this.tcid2 : '',
+          courseTime: courseTime,
+          startTime: this.startTime,
+          endTime: endTime,
+        })
+        console.log('同步数据')
+      }
+    },
   },
   directives: {
     // 使用局部注册指令的方式
@@ -21050,22 +21069,7 @@ export default {
     clearInterval(this.opertimer);
     this.opertimer = null;
 		this.updateSplitScreenData(1);
-    if(this.courseDetail.userid == this.userid && this.org == '16ace517-b5c7-4168-a9bb-a9e0035df840'){
-      let endTime = new Date().toLocaleString("zh-CN", { 
-          hour12: false, 
-          timeZone: "Asia/Shanghai" 
-        }).replace(/\//g, "-")
-      let courseTime = Math.floor((new Date(endTime) - new Date(this.startTime)) / (1000 * 60))
-      this.syncClassData({
-        courseId: this.id,
-        title: this.courseDetail.title,
-        courseGrade: this.tcid2 ? this.tcid2 : '',
-        courseTime: courseTime,
-        startTime: this.startTime,
-        endTime: endTime,
-      })
-      console.log('同步数据')
-    }
+    this.doSyncClassData();
   },
   computed: {
     renderedFormula2() {
@@ -21285,6 +21289,9 @@ export default {
         this.updateToolDetail(this.toolDetailIndex);
       }
     });
+    setTimeout(() => {
+      this.doSyncClassData();
+    }, 1000);
     this.getCode2()
     this.setOperationTime();
     this.selectEva();