index.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { defineComponent, onMounted, reactive, watch } from "vue";
  2. import { useRoute } from "vue-router";
  3. // import { verifyMembershipServices } from "../vip-verify";
  4. import { api_lessonTrainingSubmitTraining } from "../../api";
  5. import state, { IDifficulty, handleSetSpeed, hanldeDirectSelection, setSection } from "/src/state";
  6. import { getQuery } from "/src/utils/queryString";
  7. import { evaluatingData } from "/src/view/evaluating";
  8. export default defineComponent({
  9. name: "EvaluatingWork",
  10. props: {
  11. workeData: {
  12. type: Object,
  13. default: () => ({}),
  14. },
  15. },
  16. setup(props, { expose }) {
  17. const query = getQuery();
  18. const evaluatingWorkData = reactive({
  19. difficulty: "" as IDifficulty,
  20. evaluatingRecord: props.workeData?.id,
  21. start: "" as any,
  22. end: "" as any,
  23. evaluateSpeed: 0,
  24. });
  25. /** 隐藏评测功能 */
  26. const handleHide = () => {
  27. const ids = ["studnetT-0"];
  28. for (let i = 0; i < ids.length; i++) {
  29. const speedBtn = document.getElementById(ids[i]);
  30. if (speedBtn) {
  31. speedBtn.style.pointerEvents = "none";
  32. speedBtn.style.opacity = ".5";
  33. }
  34. }
  35. };
  36. /** 获取作业详情 */
  37. const getWorkData = async () => {
  38. let trainingContent: any = {};
  39. try {
  40. trainingContent = JSON.parse(props.workeData.trainingContent);
  41. } catch (error) {
  42. console.log("🚀 ~ error:", error);
  43. }
  44. if (["BEGINNER", "ADVANCED", "PERFORMER"].includes(trainingContent.evaluateDifficult)) {
  45. evaluatingWorkData.difficulty = trainingContent.evaluateDifficult;
  46. state.setting.evaluationDifficulty = trainingContent.evaluateDifficult;
  47. evaluatingWorkData.evaluateSpeed = trainingContent.evaluateSpeed;
  48. evaluatingWorkData.start = Number(trainingContent.practiceChapterBegin);
  49. evaluatingWorkData.end = Number(trainingContent.practiceChapterEnd);
  50. // 设置小节
  51. setSection(evaluatingWorkData.start, evaluatingWorkData.end, evaluatingWorkData.evaluateSpeed);
  52. }
  53. };
  54. /** 添加记录 */
  55. const addEvaluatingWorkRecored = async (data: any) => {
  56. try {
  57. const res = await api_lessonTrainingSubmitTraining({
  58. id: evaluatingWorkData.evaluatingRecord,
  59. trainingTimes: data?.score || 0,
  60. });
  61. } catch (error) {
  62. console.log(error);
  63. }
  64. };
  65. watch(
  66. () => evaluatingData.resulstMode,
  67. () => {
  68. if (evaluatingData.resulstMode && evaluatingData.isComplete) {
  69. addEvaluatingWorkRecored(evaluatingData.resultData);
  70. }
  71. }
  72. );
  73. onMounted(() => {
  74. handleHide();
  75. getWorkData();
  76. // verifyMembershipServices();
  77. });
  78. return () => <div></div>;
  79. },
  80. });