|
@@ -1,7 +1,8 @@
|
|
|
import request from '@/helpers/request'
|
|
|
import { getSecondRPM } from '@/helpers/utils'
|
|
|
import { state } from '@/state'
|
|
|
-import { computed, defineComponent, onMounted, onUnmounted, reactive, ref } from 'vue'
|
|
|
+import { usePageVisibility } from '@vant/use'
|
|
|
+import { computed, defineComponent, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
|
|
import { useRoute } from 'vue-router'
|
|
|
import styles from './index.module.less'
|
|
|
|
|
@@ -14,13 +15,27 @@ export default defineComponent({
|
|
|
}
|
|
|
},
|
|
|
setup(props) {
|
|
|
+ const pageVisibility = usePageVisibility()
|
|
|
+
|
|
|
+ watch(pageVisibility, (value) => {
|
|
|
+ console.log("🚀 ~ value", value)
|
|
|
+ if (value == 'hidden') {
|
|
|
+ clearInterval(timerRecord.value)
|
|
|
+ handleRecord()
|
|
|
+ } else {
|
|
|
+ // 页面显示
|
|
|
+ handleStartInterval()
|
|
|
+ }
|
|
|
+ })
|
|
|
const route = useRoute()
|
|
|
const saveModel = reactive({
|
|
|
- startTime: Date.now(),
|
|
|
- timer: null as any,
|
|
|
- totalTime: 0,
|
|
|
- loading: false
|
|
|
+ /**当前时长 */
|
|
|
+ currentTime: 0,
|
|
|
+ /**记录的开始时间 */
|
|
|
+ startTime: 0,
|
|
|
+ timer: null as any
|
|
|
})
|
|
|
+ /** 建议学习总时长 */
|
|
|
const total = computed(() => {
|
|
|
const _total = props.list.reduce(
|
|
|
(_total: number, item: any) => _total + item.adviseStudyTimeSecond,
|
|
@@ -29,42 +44,41 @@ export default defineComponent({
|
|
|
return _total
|
|
|
})
|
|
|
|
|
|
- const handleRecord = async () => {
|
|
|
- if (saveModel.loading) return
|
|
|
- saveModel.loading = true
|
|
|
- try {
|
|
|
- const res: any = await request.post(
|
|
|
- `${state.platformApi}/courseSchedule/coursewarePlayTime`,
|
|
|
- {
|
|
|
- params: {
|
|
|
- courseScheduleId: route.query.courseId,
|
|
|
- playTime: saveModel.totalTime
|
|
|
- }
|
|
|
- }
|
|
|
- )
|
|
|
- } catch (error) {}
|
|
|
+ const handleRecord = () => {
|
|
|
+ saveModel.currentTime++
|
|
|
+ const playTime = saveModel.currentTime - saveModel.startTime
|
|
|
+ // 1分钟记录1次
|
|
|
+ if (playTime >= 60) {
|
|
|
+ saveModel.startTime = saveModel.currentTime
|
|
|
+ request.post(`${state.platformApi}/courseSchedule/coursewarePlayTime`, {
|
|
|
+ params: {
|
|
|
+ courseScheduleId: route.query.courseId,
|
|
|
+ playTime
|
|
|
+ },
|
|
|
+ hideLoading: true
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
const timerRecord = ref()
|
|
|
+ const handleStartInterval = () => {
|
|
|
+ clearInterval(timerRecord.value)
|
|
|
+ timerRecord.value = setInterval(handleRecord, 1000)
|
|
|
+ }
|
|
|
onMounted(() => {
|
|
|
- timerRecord.value = setInterval(() => {
|
|
|
- if (saveModel.totalTime > total.value){
|
|
|
- handleRecord()
|
|
|
- }
|
|
|
- saveModel.totalTime = Math.floor((Date.now() - saveModel.startTime) / 1000)
|
|
|
- }, 1000)
|
|
|
+ handleStartInterval()
|
|
|
})
|
|
|
onUnmounted(() => {
|
|
|
clearInterval(timerRecord.value)
|
|
|
})
|
|
|
return () => (
|
|
|
- <div class={styles.playRecordTimeWrap}>
|
|
|
- <div
|
|
|
- class={styles.playRecordTime}
|
|
|
- style={{ display: saveModel.totalTime > total.value ? 'none' : '' }}
|
|
|
- >
|
|
|
+ <div
|
|
|
+ class={styles.playRecordTimeWrap}
|
|
|
+ style={{ display: saveModel.currentTime > total.value ? 'none' : '' }}
|
|
|
+ >
|
|
|
+ <div class={styles.playRecordTime}>
|
|
|
<div class={styles.timeLoad}></div>
|
|
|
<div>
|
|
|
- {getSecondRPM(saveModel.totalTime)} / {getSecondRPM(total.value)}
|
|
|
+ {getSecondRPM(saveModel.currentTime)} / {getSecondRPM(total.value)}
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|