123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import { defineComponent, onMounted, reactive, watch } from "vue";
- import styles from "./index.module.less";
- // import { verifyMembershipServices } from "../vip-verify";
- import { api_lessonTrainingSubmitTraining, api_lessonTrainingTrainingStudentDetail } from "../../api";
- import state, { handleSetSpeed, hanldeDirectSelection } from "/src/state";
- export default defineComponent({
- name: "HomeWork",
- props: {
- workeData: {
- type: Object,
- default: () => ({}),
- }
- },
- emits: ["change"],
- setup(props, {expose}) {
- const training = reactive({
- trainingTimes: "",
- trainingSpeed: 0,
- times: 0,
- workRecord: "",
- isAddOk: 0,
- starTime: 0,
- start: "" as any,
- end: "" as any,
- });
- /** 隐藏评测功能 */
- const handleHide = () => {
- const ids = ["studnetT-0", "studnetT-2", "studnetT-4"];
- for (let i = 0; i < ids.length; i++) {
- const speedBtn = document.getElementById(ids[i]);
- if (speedBtn) {
- speedBtn.style.pointerEvents = "none";
- speedBtn.style.opacity = ".5";
- }
- }
- };
- /** 获取作业详情 */
- const getWorkData = async () => {
- const workeData = props.workeData;
- if (workeData.id) {
- let trainingContent: any = {};
- try {
- trainingContent = JSON.parse(workeData.trainingContent);
- } catch (error) {
- console.log("🚀 ~ error:", error);
- }
- training.times = trainingContent.trainingTimes || 0;
- training.trainingTimes = (workeData.trainingTimes / 60).toFixed(1) || "0";
- training.trainingSpeed = trainingContent.practiceSpeed;
- training.start = Number(trainingContent.practiceChapterBegin);
- training.end = Number(trainingContent.practiceChapterEnd);
- if (training.isAddOk === 0) {
-
- setSection();
- }
- }
- };
- /**设置小节 */
- const setSection = () => {
- const startNotes = state.times.filter(
- (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == training.start
- )
- const endNotes = state.times.filter(
- (n: any) => n.noteElement.sourceMeasure.MeasureNumberXML == training.end
- )
- const startNote = startNotes[0]
- const endNote = endNotes[endNotes.length - 1]
- // console.log('🚀 ~ activeNote', startNote, endNote, questionExtendsInfo.value.end)
- if (startNote && endNote) {
- state.isSelectMeasureMode = true;
- // 设置小节
- hanldeDirectSelection([startNote, endNote]);
- //设置速度
- if (training.trainingSpeed) {
- handleSetSpeed(training.trainingSpeed);
- }
- }
- }
- const getWorkDetail = async () => {
- const res = await api_lessonTrainingTrainingStudentDetail(props.workeData.id);
- if (res?.code === 200) {
- training.trainingTimes = (res.data.trainingTimes / 60).toFixed(1) || "0";
- }
- };
- /** 添加作业记录 */
- const addHomeworkRecored = async () => {
- let total = Math.ceil((Date.now() - training.starTime) / 1000);
- try {
- const res = await api_lessonTrainingSubmitTraining({
- id: props.workeData.id,
- trainingTimes: total,
- });
- if (res?.code == 200) {
- getWorkDetail();
- }
- } catch (error) {}
- };
- watch(
- () => state.playState,
- () => {
- if (state.playState === "play") {
- training.starTime = Date.now();
- } else {
- addHomeworkRecored();
- }
- }
- );
- const handleAdd = () => {
- if (state.playState === "play") {
- console.log("退出");
- addHomeworkRecored();
- }
- }
- onMounted(() => {
- handleHide();
- getWorkData();
- // verifyMembershipServices();
- });
- expose({
- handleAdd
- })
- return () => (
- <div class={styles.homework}>
- {training.trainingTimes} / {training.times} 分钟
- </div>
- );
- },
- });
|