index.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. const recordData = reactive({
  8. starTime: 0,
  9. });
  10. const handleRecord = () => {
  11. // 不是练习模式不记录
  12. if (state.modeType !== "practise") return;
  13. let total = Date.now() - recordData.starTime;
  14. recordData.starTime = Date.now();
  15. if (total < 0) total = 0;
  16. const totalTime = total / 1000;
  17. const body = {
  18. clientType: storeData.user.clientType,
  19. musicSheetId: state.examSongId,
  20. sysMusicScoreId: state.examSongId,
  21. feature: "PRACTICE",
  22. practiceSource: "PRACTICE",
  23. playTime: totalTime,
  24. deviceType: browser().android ? "ANDROID" : "IOS",
  25. behaviorId: getBehaviorId(),
  26. };
  27. api_musicPracticeRecordSave(body);
  28. };
  29. export const handleNoEndExit = () => {
  30. if (state.playState === "play") {
  31. handleRecord();
  32. }
  33. };
  34. /**
  35. * 记录练习时长, 仅记录练习模式的时长
  36. */
  37. export default defineComponent({
  38. name: "recordingTime",
  39. setup() {
  40. watch(
  41. () => state.playState,
  42. () => {
  43. if (state.playState === "play") {
  44. recordData.starTime = Date.now();
  45. } else {
  46. handleRecord();
  47. }
  48. }
  49. );
  50. return () => <div></div>;
  51. },
  52. });