Procházet zdrojové kódy

看课记录查询修改 营期 创建时间 更新时间 任意可以查询

xgb před 1 týdnem
rodič
revize
68b5a16f1e
1 změnil soubory, kde provedl 72 přidání a 28 odebrání
  1. 72 28
      src/views/course/courseWatchLog/index.vue

+ 72 - 28
src/views/course/courseWatchLog/index.vue

@@ -345,35 +345,58 @@ export default {
         this.videoList=response.list
       });
     },
-    createChange() {
-      if (this.createTime != null) {
-        const startDate = new Date(this.createTime[0]);
-        const endDate = new Date(this.createTime[1]);
-        const timeDiff = Math.abs(endDate.getTime() - startDate.getTime());
-        const diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
-
-        // 限制时间区间为一个月
-        if (diffDays >= 31) {
-          this.$message.warning('创建时间区间不能超过一个月');
+    checkDateRangeLimit(dateRange) {
+      if (dateRange && dateRange.length >= 2) {
+        const startDate = new Date(dateRange[0]);
+        const endDate = new Date(dateRange[1]);
+
+        // 设置时间为当天开始,避免时间部分影响计算
+        startDate.setHours(0, 0, 0, 0);
+        endDate.setHours(0, 0, 0, 0);
+
+        const timeDiff = Math.abs(endDate - startDate);
+        const diffDays = Math.ceil(timeDiff / (1000 * 60 * 60 * 24));
+
+        if (diffDays > 31) { // maxDays-1 因为包含起始日
+          this.$message.warning('时间区间不能超过一个月');
+          return false;
+        }
+      }
+      return true;
+    },
+    createChange(createTime) {
+      if (createTime && createTime.length >= 2) {
+        if(!this.checkDateRangeLimit(createTime)){
           this.createTime = null;
-          this.queryParams.sTime = null;
-          this.queryParams.eTime = null;
+          this.queryParams.sTime=null;
+          this.queryParams.eTime=null;
           return;
         }
 
-        this.queryParams.sTime = this.createTime[0];
-        this.queryParams.eTime = this.createTime[1];
+        // this.createTimeText = this.formatDateRange(createTime);
+        this.queryParams.sTime = this.formatDate(createTime[0]) || null;
+        this.queryParams.eTime = this.formatDate(createTime[1]) || null;
       } else {
+        this.createTimeText = '';
         this.queryParams.sTime = null;
         this.queryParams.eTime = null;
       }
     },
 
-    updateChange(){
-      if (this.updateTime != null) {
-        this.queryParams.upSTime = this.updateTime[0];
-        this.queryParams.upETime = this.updateTime[1];
+    updateChange(updateTime){
+      if (updateTime && updateTime.length >= 2) {
+        if(!this.checkDateRangeLimit(updateTime)){
+          this.updateTime = null;
+          this.queryParams.upSTime=null;
+          this.queryParams.upETime=null;
+          return;
+        }
+
+        // this.updateTime = this.formatDateRange(updateTime);
+        this.queryParams.upSTime = updateTime[0] || null;
+        this.queryParams.upETime = updateTime[1] || null;
       } else {
+        this.updateTime = [];
         this.queryParams.upSTime = null;
         this.queryParams.upETime = null;
       }
@@ -390,9 +413,11 @@ export default {
     /** 查询短链课程看课记录列表 */
     getList() {
 
-      // xgb 看课数据量太大必须限制时间
-      if (!this.createTime) {
-        this.$message.warning('请选择创建时间');
+      // xgb 看课数据量太大必须限制时间if (this.isEmptyArray(this.createTime) &&
+      if (this.isEmptyArray(this.createTime) &&
+        this.isEmptyArray(this.updateTime) &&
+        this.isEmptyArray(this.scheduleTime)) {
+        this.$message.warning('请选择创建时间或营期时间或最新更新时间');
         return;
       }
       this.loading = true;
@@ -404,7 +429,10 @@ export default {
         this.courseWatchLogList = response.rows;
         this.total = response.total;
         this.loading = false;
-      });
+      }).catch(() => {
+          this.loading = false;
+        }
+      );
     },
     // 取消按钮
     cancel() {
@@ -513,10 +541,17 @@ export default {
           this.msgSuccess("删除成功");
         }).catch(() => {});
     },
+    // 添加辅助方法
+    isEmptyArray(arr) {
+      return !arr || arr.length === 0;
+    },
     /** 导出按钮操作 */
     handleExport() {
-      if (!this.createTime) {
-        this.$message.warning('请选择创建时间');
+      // xgb 看课数据量太大必须限制时间
+      if (this.isEmptyArray(this.createTime) &&
+        this.isEmptyArray(this.updateTime) &&
+        this.isEmptyArray(this.scheduleTime)) {
+        this.$message.warning('请选择创建时间或营期时间或最新更新时间');
         return;
       }
       const queryParams = this.queryParams;
@@ -532,11 +567,20 @@ export default {
           this.exportLoading = false;
         }).catch(() => {});
     },
-    handleScheduleTimeChange(val) {
-      if (val) {
-        this.queryParams.scheduleStartTime = val[0];
-        this.queryParams.scheduleEndTime = val[1];
+    handleScheduleTimeChange(scheduleTime) {
+      if (scheduleTime && scheduleTime.length >= 2) {
+        if(!this.checkDateRangeLimit(scheduleTime)){
+          this.scheduleTime = null;
+          this.queryParams.scheduleStartTime=null;
+          this.queryParams.scheduleStartTime=null;
+          return;
+        }
+
+        // this.scheduleTime = this.formatDateRange(scheduleTime);
+        this.queryParams.scheduleStartTime = scheduleTime[0] || null;
+        this.queryParams.scheduleEndTime = scheduleTime[1] || null;
       } else {
+        this.scheduleTime = [];
         this.queryParams.scheduleStartTime = null;
         this.queryParams.scheduleEndTime = null;
       }