index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { defineComponent, reactive, watch } from "vue";
  2. import state from "/src/state";
  3. import { api_musicPracticeRecordSave } from "../../api";
  4. import { browser, getBehaviorId, getCampId } from "/src/utils";
  5. import { getQuery } from "/src/utils/queryString";
  6. import { storeData } from "/src/store";
  7. import { getAudioDuration } from "/src/view/audio-list";
  8. const recordData = reactive({
  9. starTime: 0,
  10. });
  11. const handleRecord = () => {
  12. // 不是练习模式不记录
  13. if (state.modeType !== "practise") return;
  14. let total = Date.now() - recordData.starTime;
  15. recordData.starTime = Date.now();
  16. if (total < 0) total = 0;
  17. const totalTime = total / 1000;
  18. const rate = state.basePlayRate * state.originAudioPlayRate; // 播放倍率
  19. // 如果是选段,则选选段开头小节的速度
  20. const currentSpeed = state.sectionStatus && state.section.length === 2 && state.section[0].measureSpeed ? state.section[0].measureSpeed * state.basePlayRate : state.speed;
  21. const body = {
  22. clientType: storeData.user.clientType,
  23. musicSheetId: state.examSongId,
  24. sysMusicScoreId: state.examSongId,
  25. feature: "PRACTICE",
  26. practiceSource: "PRACTICE",
  27. playTime: totalTime,
  28. deviceType: browser().android ? "ANDROID" : "IOS",
  29. behaviorId: getBehaviorId(),
  30. sourceTime: getAudioDuration(), // 音频时长
  31. instrumentId: state.instrumentId,
  32. playRate: rate,
  33. partIndex: state.partIndex, // 音轨
  34. speed: currentSpeed, // 速度
  35. };
  36. api_musicPracticeRecordSave(body);
  37. };
  38. export const handleNoEndExit = () => {
  39. if (state.playState === "play") {
  40. handleRecord();
  41. }
  42. };
  43. /**
  44. * 记录练习时长, 仅记录练习模式的时长
  45. */
  46. export default defineComponent({
  47. name: "recordingTime",
  48. setup() {
  49. watch(
  50. () => state.playState,
  51. () => {
  52. if (state.playState === "play") {
  53. recordData.starTime = Date.now();
  54. } else {
  55. handleRecord();
  56. }
  57. }
  58. );
  59. return () => <div></div>;
  60. },
  61. });