index.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import { defineComponent, onMounted, reactive, ref } from "vue";
  2. import { getQuery } from "/src/utils/queryString";
  3. import request from "/src/utils/request";
  4. import { storeData } from "/src/store";
  5. import state, { handleSetSpeed, hanldeDirectSelection } from "/src/state";
  6. import { handleCloseModeMode } from "../../header-top";
  7. import { handleStartEvaluat } from "/src/view/evaluating";
  8. interface IquestionExtendsInfo {
  9. /** 评测难度 */
  10. difficulty?: "ONE" | "TWO" | "THREE" | "1" | "2" | "3" | "";
  11. /** 开始小节 */
  12. start?: string | number;
  13. /** 结束小节 */
  14. end?: string | number;
  15. /** 速度 */
  16. speed?: number;
  17. }
  18. const difficultyData: { [_: string]: any } = {
  19. ONE: "BEGINNER",
  20. TWO: "ADVANCED",
  21. THREE: "PERFORMER",
  22. "1": "BEGINNER",
  23. "2": "ADVANCED",
  24. "3": "PERFORMER",
  25. };
  26. export const unitTestData = reactive({
  27. /** 是否是选段模式 */
  28. isSelectMeasureMode: false,
  29. });
  30. export default defineComponent({
  31. name: "unitTest",
  32. setup() {
  33. const questionExtendsInfo = ref<IquestionExtendsInfo>({ difficulty: "" });
  34. /** 隐藏评测功能 */
  35. const handleHide = (list: string[]) => {
  36. const ids = list;
  37. for (let i = 0; i < ids.length; i++) {
  38. const speedBtn = document.getElementById(ids[i]);
  39. if (speedBtn) {
  40. speedBtn.style.pointerEvents = "none";
  41. if (ids[i] != "selectionBox") {
  42. speedBtn.style.opacity = ".7";
  43. }
  44. }
  45. }
  46. };
  47. /**
  48. * 如果是课后训练或者单元测验,获取数据
  49. * @param xml 获取的xml数据
  50. * @returns 格式化的xml数据
  51. */
  52. const getUnitData = async () => {
  53. const search = getQuery();
  54. if (!search.questionId) return "";
  55. handleHide(["tips-step-0", "tips-step-2", "selectionBox"]);
  56. handleStartEvaluat();
  57. handleCloseModeMode();
  58. try {
  59. const res: any = await request.get(`/examinationQuestion/detail?examinationQuestionId=${search.questionId}`);
  60. questionExtendsInfo.value = JSON.parse(res?.data?.questionExtendsInfo) || {};
  61. questionExtendsInfo.value.start = Number(questionExtendsInfo.value.start);
  62. questionExtendsInfo.value.end = Number(questionExtendsInfo.value.end);
  63. } catch (error) {
  64. console.error("解析单元测验曲谱题目失败", error);
  65. }
  66. setSection();
  67. };
  68. const getlessonTrainingData = async () => {
  69. const search = getQuery();
  70. if (!search.lessonTrainingId) return;
  71. handleHide(["tips-step-3", "selectionBox"]);
  72. try {
  73. const res: any = await request.post(`/studentLessonTraining/trainingRecord/${search.courseScheduleId}?userId=${storeData.user?.id}`);
  74. if (Array.isArray(res?.data?.trainings)) {
  75. const train = res.data.trainings.find((n: any) => n.materialId == search.materialId);
  76. const info = JSON.parse(train.trainingContent);
  77. // console.log("🚀 ~ info", info)
  78. questionExtendsInfo.value.start = Number(info.startSection);
  79. questionExtendsInfo.value.end = Number(info.endSection);
  80. questionExtendsInfo.value.speed = isNaN(info.speed) ? 0 : Number(info.speed);
  81. }
  82. } catch (error) {
  83. console.error("解析课后训练曲谱题目失败", error);
  84. }
  85. setSection();
  86. };
  87. /**设置小节 */
  88. const setSection = () => {
  89. const startNotes = state.times.filter((n: any) => n.MeasureNumberXML == questionExtendsInfo.value.start);
  90. const endNotes = state.times.filter((n: any) => n.MeasureNumberXML == questionExtendsInfo.value.end);
  91. const startNote = startNotes[0];
  92. const endNote = endNotes[endNotes.length - 1];
  93. // console.log('🚀 ~ activeNote', startNote, endNote, questionExtendsInfo.value.end)
  94. if (startNote && endNote) {
  95. state.isSelectMeasureMode = true;
  96. // 设置小节
  97. hanldeDirectSelection([startNote, endNote]);
  98. // 设置评测难度
  99. if (difficultyData[questionExtendsInfo.value.difficulty!]) {
  100. state.setting.evaluationDifficulty = difficultyData[questionExtendsInfo.value.difficulty!];
  101. }
  102. //设置速度
  103. if (questionExtendsInfo.value.speed) {
  104. handleSetSpeed(questionExtendsInfo.value.speed);
  105. }
  106. }
  107. };
  108. onMounted(() => {
  109. getUnitData();
  110. getlessonTrainingData();
  111. });
  112. return () => "";
  113. },
  114. });