Quellcode durchsuchen

feat: 优化看课统计、完课统计查询

caoliqin vor 5 Tagen
Ursprung
Commit
d0c9d42e2a

+ 28 - 0
src/utils/common.js

@@ -284,6 +284,34 @@ export function formatTime(timer) {
 	}
 }
 
+/**
+ * 获取日期范围
+ * @param {number} days - 从今天往前推的天数  
+ * @returns {Array} 返回格式化的日期数组 [开始日期, 结束日期]
+ * @example
+ * // 获取最近7天的日期范围
+ * const dateRange = getDateRange(7);
+ * // 返回: ["2024-01-01", "2024-01-08"]
+ */
+export function getDateRange(days) {
+	const today = new Date();
+	const startDate = new Date();
+	startDate.setDate(today.getDate() - days);
+
+	// 格式化日期为年-月-日格式
+	const formatDate = (date) => {
+		const year = date.getFullYear();
+		const month = String(date.getMonth() + 1).padStart(2, '0');
+		const day = String(date.getDate()).padStart(2, '0');
+		return `${year}-${month}-${day}`;
+	};
+
+	return [
+		formatDate(startDate), // days天前
+		formatDate(today)      // 今天
+	];
+}
+
 
 // export function callNumber(mobile){
 // 	var that=this;

+ 11 - 0
src/views/course/courseWatchLog/qw/statistics.vue

@@ -67,6 +67,7 @@
 <script>
 import { listCourseWatchLog, getCourseWatchLog, delCourseWatchLog, addCourseWatchLog, updateCourseWatchLog, exportCourseWatchLog,statisticsList } from "@/api/course/qw/courseWatchLog";
 import { courseList,videoList } from '@/api/course/courseRedPacketLog'
+import { getDateRange } from '@/utils/common'
 export default {
   name: "CourseWatchLog",
   data() {
@@ -124,6 +125,12 @@ export default {
     };
   },
   created() {
+    // 设置默认时间范围为最近7天
+    this.createTime = getDateRange(7);
+    // 设置查询参数的时间
+    this.queryParams.sTime = this.createTime[0];
+    this.queryParams.eTime = this.createTime[1];
+
     courseList().then(response => {
       this.courseLists = response.list;
     });
@@ -163,6 +170,10 @@ export default {
     },
     /** 查询短链课程看课记录列表 */
     getList() {
+      if (!this.queryParams.sTime || !this.queryParams.eTime) {
+        this.$message.warning("请选择创建时间");
+        return;
+      }
       this.loading = true;
       statisticsList(this.queryParams).then(response => {
         this.courseWatchLogList = response.rows;

+ 11 - 0
src/views/course/courseWatchLog/statistics.vue

@@ -67,6 +67,7 @@
 <script>
 import { listCourseWatchLog, getCourseWatchLog, delCourseWatchLog, addCourseWatchLog, updateCourseWatchLog, exportCourseWatchLog,statisticsList } from "@/api/course/courseWatchLog";
 import { courseList,videoList } from '@/api/course/courseRedPacketLog'
+import {getDateRange} from "@/utils/common";
 export default {
   name: "CourseWatchLog",
   data() {
@@ -124,6 +125,12 @@ export default {
     };
   },
   created() {
+    // 设置默认时间范围为最近7天
+    this.createTime = getDateRange(7);
+    // 设置查询参数的时间
+    this.queryParams.sTime = this.createTime[0];
+    this.queryParams.eTime = this.createTime[1];
+
     courseList().then(response => {
       this.courseLists = response.list;
     });
@@ -163,6 +170,10 @@ export default {
     },
     /** 查询短链课程看课记录列表 */
     getList() {
+      if (!this.queryParams.sTime || !this.queryParams.eTime) {
+        this.$message.warning("请选择创建时间");
+        return;
+      }
       this.loading = true;
       statisticsList(this.queryParams).then(response => {
         this.courseWatchLogList = response.rows;

+ 12 - 0
src/views/course/courseWatchLog/watchLogStatistics.vue

@@ -61,6 +61,7 @@
 import { listCourseWatchLog, getCourseWatchLog, delCourseWatchLog, addCourseWatchLog, updateCourseWatchLog, exportCourseWatchLog,watchLogStatistics,watchLogStatisticsExport } from "@/api/course/courseWatchLog";
 import {allList}from "@/api/company/company";
 import { courseList,videoList } from '@/api/course/courseRedPacketLog'
+import {getDateRange} from "@/utils/common";
 export default {
   name: "CourseWatchLog",
   data() {
@@ -122,6 +123,12 @@ export default {
     };
   },
   created() {
+    // 设置默认时间范围为最近7天
+    this.createTime = getDateRange(7);
+    // 设置查询参数的时间
+    this.queryParams.sTime = this.createTime[0];
+    this.queryParams.eTime = this.createTime[1];
+
     courseList().then(response => {
       this.courseLists = response.list;
     });
@@ -171,6 +178,11 @@ export default {
     },
     /** 查询短链课程看课记录列表 */
     getList() {
+      if (!this.queryParams.sTime || !this.queryParams.eTime) {
+        this.$message.warning("请选择创建时间");
+        return;
+      }
+
       this.loading = true;
       if(this.queryParams.logType == "10"){
         this.queryParams.logType = null;