import { defineComponent, reactive, watch } from "vue"; import state from "/src/state"; import { api_musicPracticeRecordSave } from "../../api"; import { browser, getBehaviorId, getCampId } from "/src/utils"; import { getQuery } from "/src/utils/queryString"; import { storeData } from "/src/store"; import { getAudioDuration } from "/src/view/audio-list"; const recordData = reactive({ starTime: 0, }); const handleRecord = () => { // 不是练习模式不记录 if (state.modeType !== "practise") return; let total = Date.now() - recordData.starTime; recordData.starTime = Date.now(); if (total < 0) total = 0; const totalTime = total / 1000; const rate = state.basePlayRate * state.originAudioPlayRate; // 播放倍率 // 如果是选段,则选选段开头小节的速度 const currentSpeed = state.sectionStatus && state.section.length === 2 && state.section[0].measureSpeed ? state.section[0].measureSpeed * state.basePlayRate : state.speed; const body = { clientType: storeData.user.clientType, musicSheetId: state.examSongId, sysMusicScoreId: state.examSongId, feature: "PRACTICE", practiceSource: "PRACTICE", playTime: totalTime, deviceType: browser().android ? "ANDROID" : "IOS", behaviorId: getBehaviorId(), sourceTime: getAudioDuration(), // 音频时长 instrumentId: state.instrumentId, playRate: rate, partIndex: state.partIndex, // 音轨 speed: currentSpeed, // 速度 }; api_musicPracticeRecordSave(body); }; export const handleNoEndExit = () => { if (state.playState === "play") { handleRecord(); } }; /** * 记录练习时长, 仅记录练习模式的时长 */ export default defineComponent({ name: "recordingTime", setup() { watch( () => state.playState, () => { if (state.playState === "play") { recordData.starTime = Date.now(); } else { handleRecord(); } } ); return () =>
; }, });