Browse Source

进度条显示,播放80%加积分

zhuf 1 year ago
parent
commit
d06b1ac18b

+ 65 - 12
src/components/video-player.vue

@@ -29,6 +29,45 @@ function getSourceType(src: string) {
     return `video/${ext}`
 }
 
+/* view_type = [
+  "txwx_jtjy_zj",
+  "txwx_mszy_zj",
+  "txwx_tskc_zj",
+  "txwx_zyfd"
+] */
+// function updateViewLog(d?: object) {
+//   request({
+//     url: '/openapi/user_view_log.php',
+//     data: {
+//       ...d,
+//     },
+//   })
+// }
+
+let timer: null | NodeJS.Timer = null
+let count = 0
+
+const INTERVAL = 2 * 3
+function startTimer(payload?: object) {
+  if (timer === null) {
+    timer = setInterval(() => {
+      count++
+      console.log('count : ', count)
+      if (count % INTERVAL === 0) {
+        console.log('3min')
+        emits('scoreAtTarget', payload)
+      }
+    }, 1000)
+  }
+}
+
+function pauseTimer() {
+  if (timer !== null) {
+    clearInterval(timer)
+    timer = null
+  }
+}
+
 onMounted(() => {
   if (!videoPlayerRef.value)
     return
@@ -44,7 +83,7 @@ onMounted(() => {
           'PlayToggle', // 播放
           'NextBtn', // 下一个
           'CurrentTimeDisplay', // 当前时间
-          // 'ProgressControl', // 进度条
+          'ProgressControl', // 进度条
           'DurationDisplay', // 时长
           'VolumePanel', // 音量
           'PlaybackRateMenuButton', // 倍速
@@ -61,19 +100,33 @@ onMounted(() => {
     },
     () => {
       console.log('player is ready')
+      timer = null
+      count = 0
       const p = player.value
-      let callbackExecuted = false
-      p.on('timeupdate', () => {
-        // 计算视频已经播放的百分比
-        const percentagePlayed = p.currentTime() / p.duration()
+      // p.on('timeupdate', () => {
+      //   // 计算视频已经播放的百分比
+      //   const percentagePlayed = p.currentTime() / p.duration()
 
-        if (percentagePlayed >= 0.9 && !callbackExecuted) {
-          // 执行回调函数
-          console.log('达到目标时间')
-          emits('scoreAtTarget')
-          p.off('timeupdate')
-          callbackExecuted = true
-        }
+      //   if (percentagePlayed >= 0.9 && !callbackExecuted) {
+      //     // 执行回调函数
+      //     console.log('达到目标时间')
+      //     emits('scoreAtTarget')
+      //     p.off('timeupdate')
+      //     callbackExecuted = true
+      //   }
+      // })
+      p.on('play', () => {
+        console.log('视频播放开始')
+        startTimer()
+      })
+      p.on('pause', () => {
+        console.log('视频暂停')
+        pauseTimer()
+      })
+      p.on('ended', () => {
+        console.log('视频播放结束')
+        pauseTimer()
+        emits('scoreAtTarget', { isover: 1 })
       })
     },
   )

+ 5 - 4
src/pages/detail/[type]/[tmk_id]/[tmz_id]/index.vue

@@ -62,12 +62,13 @@ function fixTruthPid(pid: string) {
   return truthPid
 }
 
-function scoreAtTarget(src: string) {
+function scoreAtTarget(payload: object) {
   return request({
-    url: `/txwx/${props.type}/detail`,
+    url: '/openapi/user_view_log.php',
     data: {
-      [theType.id]: props.tmz_id,
-      save: 1,
+      id: props.tmz_id,
+      view_type: `txwx_${props.type}`,
+      ...payload,
     },
   })
 }

+ 8 - 0
vite.config.ts

@@ -91,4 +91,12 @@ export default defineConfig({
   test: {
     environment: 'jsdom',
   },
+  build: {
+    minify: 'terser',
+    terserOptions: {
+      compress: {
+        drop_console: true,
+      },
+    },
+  },
 })