|
@@ -21,6 +21,8 @@ import playLoadData from '../coursewarePlay/datas/data.json';
|
|
|
// import { handleCheckVip } from '../hook/useFee';
|
|
|
import VideoClass from './video-class';
|
|
|
import { usePageVisibility } from '@vant/use';
|
|
|
+import { useInterval, useIntervalFn } from '@vueuse/core';
|
|
|
+import deepClone from '@/helpers/deep-clone';
|
|
|
|
|
|
// const materialType = {
|
|
|
// 视频: 'VIDEO',
|
|
@@ -165,6 +167,33 @@ export default defineComponent({
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const intervalFnRef = ref(); // 定时任务
|
|
|
+ // 播放视频总时长
|
|
|
+ const videoIntervalRef = useInterval(1000, { controls: true });
|
|
|
+ videoIntervalRef.pause();
|
|
|
+
|
|
|
+ // 更新时间
|
|
|
+ const updateStat = async () => {
|
|
|
+ try {
|
|
|
+ // 只有学生才统计数据
|
|
|
+ if (state.platformType === 'STUDENT') {
|
|
|
+ const videoTime = videoIntervalRef.counter.value;
|
|
|
+ if (videoTime <= 0) return;
|
|
|
+ videoIntervalRef.counter.value = 0;
|
|
|
+ await request.post(
|
|
|
+ `${state.platformApi}/studentCoursewarePlayRecord/save`,
|
|
|
+ {
|
|
|
+ data: {
|
|
|
+ playTime: videoTime
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ } catch {
|
|
|
+ //
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
onMounted(async () => {
|
|
|
const trainings = await getTrainingRecord();
|
|
|
// 初始化状态
|
|
@@ -177,6 +206,16 @@ export default defineComponent({
|
|
|
setRecord(trainings);
|
|
|
// 是否为会员
|
|
|
// data.isMember = handleCheckVip();
|
|
|
+
|
|
|
+ // 只有学生才统计数据
|
|
|
+ if (state.platformType === 'STUDENT') {
|
|
|
+ // 间隔多少时间同步数据
|
|
|
+ intervalFnRef.value = useIntervalFn(async () => {
|
|
|
+ // 同步数据时先进行有效时间进行保存
|
|
|
+ // initVideoCount(false, true);
|
|
|
+ await updateStat();
|
|
|
+ }, 5000);
|
|
|
+ }
|
|
|
});
|
|
|
// 返回
|
|
|
const goback = () => {
|
|
@@ -333,6 +372,40 @@ export default defineComponent({
|
|
|
item={m}
|
|
|
isMember={data.isMember}
|
|
|
modal={activeData.model}
|
|
|
+ onSeeked={() => {
|
|
|
+ videoIntervalRef.isActive.value &&
|
|
|
+ videoIntervalRef.pause();
|
|
|
+ }}
|
|
|
+ onSeeking={() => {
|
|
|
+ videoIntervalRef.isActive.value &&
|
|
|
+ videoIntervalRef.pause();
|
|
|
+ }}
|
|
|
+ onWaiting={() => {
|
|
|
+ videoIntervalRef.isActive.value &&
|
|
|
+ videoIntervalRef.pause();
|
|
|
+ }}
|
|
|
+ onTimeupdate={() => {
|
|
|
+ const activeVideoRef = m.videoEle;
|
|
|
+ console.log(
|
|
|
+ videoIntervalRef.isActive.value,
|
|
|
+ activeVideoRef?.currentTime(),
|
|
|
+ activeVideoRef?.paused(),
|
|
|
+ 'activeVideoRef?.paused()'
|
|
|
+ );
|
|
|
+ if (
|
|
|
+ !videoIntervalRef.isActive.value &&
|
|
|
+ activeVideoRef?.currentTime() > 0 &&
|
|
|
+ !activeVideoRef?.paused()
|
|
|
+ ) {
|
|
|
+ videoIntervalRef.resume();
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ onPause={() => {
|
|
|
+ clearTimeout(activeData.timer);
|
|
|
+ activeData.model = true;
|
|
|
+ videoIntervalRef.pause();
|
|
|
+ console.log('11111');
|
|
|
+ }}
|
|
|
onEnded={() => addTrainingRecord()}
|
|
|
onChangeModal={(status: boolean) => {
|
|
|
activeData.model = status;
|