index.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // 不是练习模式不记录,web后台不记录
  12. if (state.modeType !== "practise" || state.systemType === 'web') 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 query: any = getQuery();
  18. const body: any = {
  19. clientType: storeData.user.clientType,
  20. musicSheetId: state.examSongId,
  21. sysMusicScoreId: state.examSongId,
  22. feature: "PRACTICE",
  23. practiceSource: "PRACTICE",
  24. playTime: totalTime,
  25. deviceType: browser().android ? "ANDROID" : "IOS",
  26. behaviorId: getBehaviorId(),
  27. };
  28. // 如果是作业模式,需要添加作业id
  29. if (query.workRecord || query.evaluatingRecord) {
  30. body.lessonDetailId = query.workRecord || query.evaluatingRecord
  31. }
  32. api_musicPracticeRecordSave(body);
  33. };
  34. export const handleNoEndExit = () => {
  35. if (state.playState === "play") {
  36. handleRecord();
  37. }
  38. };
  39. /**
  40. * 记录练习时长, 仅记录练习模式的时长
  41. */
  42. export default defineComponent({
  43. name: "recordingTime",
  44. setup() {
  45. watch(
  46. () => state.playState,
  47. () => {
  48. if (state.playState === "play") {
  49. recordData.starTime = Date.now();
  50. } else {
  51. handleRecord();
  52. }
  53. }
  54. );
  55. return () => <div></div>;
  56. },
  57. });