Przeglądaj źródła

feat: 新增视频播放-流量记录模块

wenxingxing 15 godzin temu
rodzic
commit
d2a27d4215
3 zmienionych plików z 55 dodań i 1 usunięć
  1. 5 1
      api/course.js
  2. 35 0
      pages/course/info.vue
  3. 15 0
      utils/common.js

+ 5 - 1
api/course.js

@@ -336,4 +336,8 @@ let request = new Request().http
  export function publicCourseAnswerClaimIntegralApi(data) {
  	return request('/app/course/publicCourseAnswer/claimIntegral', data, 'POST','application/json;charset=UTF-8');
  }
- 
+ 
+//  新版视频播放中-流量记录
+ export function newGetInternetTrafficApi(data) {
+ 	return request('/app/course/getInternetTraffic', data, 'POST','application/json;charset=UTF-8');
+ }

+ 35 - 0
pages/course/info.vue

@@ -456,7 +456,12 @@ import {
 	newPublicCourseAnswerApi,
 	publicCourseAnswerStatusApi,
 	publicCourseAnswerClaimIntegralApi,
+	newGetInternetTrafficApi,
 } from '@/api/course'
+import {
+	generateRandomString
+} from '@/utils/common.js';
+import dayjs from 'dayjs';
 import commentList from "./components/commentList.vue";
 import newCommentList from "./components/newCommentList.vue";
 import hallItem from "./components/hallItem.vue";
@@ -640,6 +645,8 @@ export default {
 				pageSize: 10,
 				total: 0,
 			},
+			// 流量记录相关
+			lastInternetTrafficDuration: 0, // 上次触发时的播放时长
 		}
 	},
 	computed: {
@@ -1603,6 +1610,9 @@ export default {
 		onTimeUpdate(data) {
 			this.playDuration = Math.round(data.time)
 			this.initStudyTime(this.playDuration)
+			if (!this.$isLogin()) {
+				this.handleInternetTraffic(this.playDuration)
+			}
 			if (data.time >= this.pickCatalog.seconds) {
 				this.countdowning = false; //观看时长开关关闭					  
 			}
@@ -1625,6 +1635,31 @@ export default {
 			}
 			// uni.$u.throttle(this.checkTherapy, 1000,false);
 		},
+		// 新版视频播放中-流量记录
+		handleInternetTraffic(duration) {
+			// 使用视频播放时长判断是否是6秒的倍数
+			let currentDuration = Number(Math.round(duration).toFixed(2));
+			// 当前视频的时长
+			let curVideoDuration = Number(Math.round(this.pickCatalog.seconds).toFixed(2));
+			let trafficUuId = generateRandomString(16)
+			// 判断是否是6秒的倍数,且只在进入新的6秒区间时触发一次
+			if (currentDuration > 0 && currentDuration % 6 === 0) {
+				// 检查是否已经在这个时间点触发过(防止拖动到6倍数位置时重复触发)
+				if (this.lastInternetTrafficDuration !== currentDuration) {
+					let params = {
+						appId: "wx40dcfa2797d6fc2d",
+						bufferRate: Math.ceil((currentDuration / curVideoDuration) * 100),
+						companyId: 101,
+						courseId: this.courseId,
+						duration: currentDuration,
+						uuId: dayjs().format('YYYYMMDD') + trafficUuId,
+						videoId: this.pickCatalog.videoId,
+					};
+					newGetInternetTrafficApi(params)
+					this.lastInternetTrafficDuration = currentDuration;
+				}
+			}
+		},
 		// 展示疗法
 		checkTherapy() {
 			let currentTime = Math.round(this.tempAudioDuration || 0)

+ 15 - 0
utils/common.js

@@ -882,4 +882,19 @@ export function formattedViewCount(views) {
   }
 
   return '0';
+}
+
+/**
+ * 随机字符串
+ * 
+ */
+export function generateRandomString(length) {
+	let result = '';
+	const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+	const charactersLength = characters.length;
+
+	for (let i = 0; i < length; i++) {
+		result += characters.charAt(Math.floor(Math.random() * charactersLength));
+	}
+	return result;
 }