index.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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, setSection } 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. state.userChooseEndIndex = training.end
  53. if (training.isAddOk === 0) {
  54. // 设置小节
  55. setSection(training.start, training.end, training.trainingSpeed);
  56. }
  57. }
  58. };
  59. const getWorkDetail = async () => {
  60. const res = await api_lessonTrainingTrainingStudentDetail(props.workeData.id);
  61. if (res?.code === 200) {
  62. training.trainingTimes = (res.data.trainingTimes / 60).toFixed(1) || "0";
  63. }
  64. };
  65. /** 添加作业记录 */
  66. const addHomeworkRecored = async () => {
  67. let total = Math.ceil((Date.now() - training.starTime) / 1000);
  68. try {
  69. const res = await api_lessonTrainingSubmitTraining({
  70. id: props.workeData.id,
  71. trainingTimes: total,
  72. });
  73. if (res?.code == 200) {
  74. getWorkDetail();
  75. }
  76. } catch (error) {}
  77. };
  78. watch(
  79. () => state.playState,
  80. () => {
  81. if (state.playState === "play") {
  82. training.starTime = Date.now();
  83. } else {
  84. addHomeworkRecored();
  85. }
  86. }
  87. );
  88. const handleAdd = () => {
  89. if (state.playState === "play") {
  90. console.log("退出");
  91. addHomeworkRecored();
  92. }
  93. }
  94. onMounted(() => {
  95. handleHide();
  96. getWorkData();
  97. // verifyMembershipServices();
  98. });
  99. expose({
  100. handleAdd,
  101. getWorkData
  102. })
  103. return () => (
  104. <div class={styles.homework}>
  105. {training.trainingTimes} / {training.times} 分钟
  106. </div>
  107. );
  108. },
  109. });