index.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { defineComponent, onMounted, reactive, watch } from "vue";
  2. import styles from "./index.module.less";
  3. // import { verifyMembershipServices } from "../vip-verify";
  4. import { api_lessonTrainingSubmitTraining, api_lessonTrainingTrainingStudentDetail } from "../../api";
  5. import state, { handleSetSpeed, hanldeDirectSelection } from "/src/state";
  6. export default defineComponent({
  7. name: "HomeWork",
  8. props: {
  9. workeData: {
  10. type: Object,
  11. default: () => ({}),
  12. }
  13. },
  14. emits: ["change"],
  15. setup(props, {expose}) {
  16. const training = reactive({
  17. trainingTimes: "",
  18. trainingSpeed: 0,
  19. times: 0,
  20. workRecord: "",
  21. isAddOk: 0,
  22. starTime: 0,
  23. start: "" as any,
  24. end: "" as any,
  25. });
  26. /** 隐藏评测功能 */
  27. const handleHide = () => {
  28. const ids = ["studnetT-0", "studnetT-2", "studnetT-4"];
  29. for (let i = 0; i < ids.length; i++) {
  30. const speedBtn = document.getElementById(ids[i]);
  31. if (speedBtn) {
  32. speedBtn.style.pointerEvents = "none";
  33. speedBtn.style.opacity = ".5";
  34. }
  35. }
  36. };
  37. /** 获取作业详情 */
  38. const getWorkData = async () => {
  39. const workeData = props.workeData;
  40. if (workeData.id) {
  41. let trainingContent: any = {};
  42. try {
  43. trainingContent = JSON.parse(workeData.trainingContent);
  44. } catch (error) {
  45. console.log("🚀 ~ error:", error);
  46. }
  47. training.times = trainingContent.trainingTimes || 0;
  48. training.trainingTimes = (workeData.trainingTimes / 60).toFixed(1) || "0";
  49. training.trainingSpeed = trainingContent.practiceSpeed;
  50. training.start = Number(trainingContent.practiceChapterBegin);
  51. training.end = Number(trainingContent.practiceChapterEnd);
  52. if (training.isAddOk === 0) {
  53. setSection();
  54. }
  55. }
  56. };
  57. /**设置小节 */
  58. const setSection = () => {
  59. const startNotes = state.times.filter(
  60. (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == training.start
  61. )
  62. const endNotes = state.times.filter(
  63. (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == training.end
  64. )
  65. const startNote = startNotes[0]
  66. const endNote = endNotes[endNotes.length - 1]
  67. // console.log('🚀 ~ activeNote', startNote, endNote, questionExtendsInfo.value.end)
  68. if (startNote && endNote) {
  69. state.isSelectMeasureMode = true;
  70. // 设置小节
  71. hanldeDirectSelection([startNote, endNote]);
  72. //设置速度
  73. if (training.trainingSpeed) {
  74. handleSetSpeed(training.trainingSpeed);
  75. }
  76. }
  77. }
  78. const getWorkDetail = async () => {
  79. const res = await api_lessonTrainingTrainingStudentDetail(props.workeData.id);
  80. if (res?.code === 200) {
  81. training.trainingTimes = (res.data.trainingTimes / 60).toFixed(1) || "0";
  82. }
  83. };
  84. /** 添加作业记录 */
  85. const addHomeworkRecored = async () => {
  86. let total = Math.ceil((Date.now() - training.starTime) / 1000);
  87. try {
  88. const res = await api_lessonTrainingSubmitTraining({
  89. id: props.workeData.id,
  90. trainingTimes: total,
  91. });
  92. if (res?.code == 200) {
  93. getWorkDetail();
  94. }
  95. } catch (error) {}
  96. };
  97. watch(
  98. () => state.playState,
  99. () => {
  100. if (state.playState === "play") {
  101. training.starTime = Date.now();
  102. } else {
  103. addHomeworkRecored();
  104. }
  105. }
  106. );
  107. const handleAdd = () => {
  108. if (state.playState === "play") {
  109. console.log("退出");
  110. addHomeworkRecored();
  111. }
  112. }
  113. onMounted(() => {
  114. handleHide();
  115. getWorkData();
  116. // verifyMembershipServices();
  117. });
  118. expose({
  119. handleAdd
  120. })
  121. return () => (
  122. <div class={styles.homework}>
  123. {training.trainingTimes} / {training.times} 分钟
  124. </div>
  125. );
  126. },
  127. });