zhongshujie
2 天以前 ce70bc450a2401997bb850f89f3c4dc0a23e0a72
src/components/dialogExaminations/index.vue
@@ -30,7 +30,7 @@
                <!-- 标题 -->
                <div class="questionTitle">
                  <div class="titleContent">
                    <span class="questionNum" :style="{
                    <span class="questionNum" v-if="item.catalogName != '材料题'" :style="{
                      marginTop:
                        value.questionType == 'completion' ||
                          value.questionType == 'mathField'
@@ -38,6 +38,18 @@
                          : '0',
                    }">{{ index + 1 }}.
                    </span>
                    <span class="questionNum" v-if="
                      item.catalogName == '材料题' &&
                      value.questionType != 'material'
                    " :style="{
                        marginTop:
                          value.questionType == 'completion' ||
                            value.questionType == 'mathField'
                            ? '12px'
                            : '0',
                      }">{{ index }}.
                    </span>
                    <!-- 听力进度条 -->
                    <!-- <answerAudioPlayer :audioUrl="value.src" v-show="item.name == '听力题'" /> -->
                    <!-- 仅文字 -->
@@ -74,8 +86,8 @@
                          typeof itemText != 'string' &&
                          value.questionType == 'mathField'
                        " class="mathField" :menuItems="[]" @input="
                          onChangeInput($event, nindex, index, itemText.num)
                          ">
                            onChangeInput($event, nindex, index, itemText.num)
                            ">
                          {{ value.userAnswer[itemText.num] }}
                        </math-field>
                      </span>
@@ -95,9 +107,10 @@
                    </p>
                  </div>
                  <img :src="value.isCollect ? isHeart : heart" alt="" class="collect-png"
                    @click="setCollect(nindex, index)" v-if="!hideCollect && item.type != 'material'" />
                    @click="setCollect(nindex, index)" v-if="!hideCollect && value.questionType != 'material'" />
                  <!-- 收藏 -->
                </div>
                <!-- 选项 -->
                <div class="questionContent">
                  <!-- 单选 -->
                  <el-radio-group :disabled="value.isComplete" class="option" v-if="
@@ -106,10 +119,10 @@
                  " v-model="value.userAnswer">
                    <el-radio v-for="(content, contentIndex) in value.option" :key="contentIndex + 'contentIndex'"
                      :label="content.value" :class="value.optionStyle == 'Image' ||
                        value.optionStyle == 'TxtAndImage' ||
                        value.optionStyle == 'RichText'
                        ? 'optionImg'
                        : 'optionTxt'
                          value.optionStyle == 'TxtAndImage' ||
                          value.optionStyle == 'RichText'
                          ? 'optionImg'
                          : 'optionTxt'
                        ">
                      <p class="optionContent" v-if="value.optionStyle == 'Txt'">
                        {{ content.value }}、{{ content.txt }}
@@ -133,10 +146,10 @@
                    v-else-if="value.questionType == 'multipleChoice'">
                    <el-checkbox v-for="(content, contentCindex) in value.option" :key="contentCindex + 'contentCindex'"
                      :label="content.value" :name="content.text" :class="value.optionStyle == 'Image' ||
                        value.optionStyle == 'TxtAndImage' ||
                        value.optionStyle == 'RichText'
                        ? 'optionImg'
                        : 'optionTxt'
                          value.optionStyle == 'TxtAndImage' ||
                          value.optionStyle == 'RichText'
                          ? 'optionImg'
                          : 'optionTxt'
                        ">
                      <p class="optionContent" v-if="value.optionStyle == 'Txt'">
                        {{ content.value }}、{{ content.txt }}
@@ -175,7 +188,7 @@
                    <el-button @click="checkPares(value)" style="margin-top: 10px">查看解析</el-button>
                  </div>
                  <!-- 提交后解析 -->
                  <div class="analysis" v-if="value.isComplete">
                  <div class="analysis" v-if="value.isComplete && value.questionType != 'material'">
                    <el-collapse v-model="value.isUnfold" accordion v-if="
                      value.questionType != 'shortAnswer' &&
                      value.questionType != 'formula'
@@ -189,8 +202,8 @@
                                <span v-html="arrayToString(value.answer)" class="correctBox"></span>
                              </p>
                              <p :class="value.isRight
                                ? 'correct textOverFlow'
                                : 'error textOverFlow'
                                  ? 'correct textOverFlow'
                                  : 'error textOverFlow'
                                " :title="arrayToString(value.userAnswer)" style="margin-left: 20px">
                                <span>您的答案:</span>
                                <span class="errorBox" v-if="isHaveAnswer(value.userAnswer)">{{
@@ -219,13 +232,12 @@
                                  fill="#d81e06" p-id="25746"></path>
                              </svg>
                            </span>
                            <div class="headerConent sitgBox">
                              <p v-if="!value.isUnfold">
                                <span class="analysisColor">展开解析</span><el-image />
                                <span class="analysisColor">展开解析</span>
                              </p>
                              <p v-else>
                                <span class="analysisColor">收起解析</span><el-image />
                                <span class="analysisColor">收起解析</span>
                              </p>
                            </div>
                          </div>
@@ -259,10 +271,10 @@
                        <div class="referBox" v-if="value.analysisCon">
                          <span>解析:</span>
                          <p v-html="value.analysisCon" :class="[
                            'subjectiveBox',
                            'ti-2',
                            value.isUnfold ? 'yincang' : '',
                          ].join(' ')
                              'subjectiveBox',
                              'ti-2',
                              value.isUnfold ? 'yincang' : '',
                            ].join(' ')
                            "></p>
                        </div>
                      </el-collapse-item>
@@ -273,18 +285,18 @@
            </ul>
          </div>
          <div class="bottom-btn" v-if="!loading">
            <el-button class="examinations-btn-box" @click="saveAnswer">保存</el-button>
            <el-button class="examinations-btn-box" @click="saveAnswer(page)">保存</el-button>
            <el-button @click="
              (page) => {
              () => {
                handleQuestion();
                saveAnswer(page);
                saveAnswer(this.page);
              }
            " class="examinations-btn-box" :style="{ borderColor: primaryColor }">提交</el-button>
            <el-button @click="redo" class="examinations-btn-box">重做</el-button>
            <el-button @click="
              (page) => {
              () => {
                openAnswers();
                saveAnswer(page);
                saveAnswer(this.page);
              }
            " class="examinations-btn-box" :style="{ borderColor: primaryColor }">查看答案</el-button>
          </div>
@@ -299,6 +311,7 @@
import { Message } from "element-ui";
import TEditorVue from "../teditor/index.vue";
import config from "@/assets/js/config";
import getQuestionList from "@/assets/methods/examination";
export default {
  name: "examination-option",
  components: { TEditorVue },
@@ -333,7 +346,7 @@
      type: Array,
      required: true,
      default: () => [],
    }
    },
  },
  data() {
    return {
@@ -371,10 +384,8 @@
  watch: {
    cardList: {
      handler(newVal, ol) {
        console.log("题目组件newVal", newVal);
        // this.cardData = this.cardList;
        if (newVal && newVal.length) {
          this.loading = false;
        if (newVal && newVal.length && this.loading) {
          this.handleCardle();
        }
      },
      immediate: true,
@@ -386,6 +397,68 @@
    this.getErrorList();
  },
  methods: {
    async openDialogQuestion() {
      this.localDialogVisible = true;
      await this.handleCardle();
    },
    // 处理逻辑问题
    async handleCardle() {
      this.loading = true;
      this.cardData = await getQuestionList(
        this.page,
        this.questionIDList,
        this.config.activeBook,
        this.cardList
      );
      if (this.cardData && this.cardData.length) {
        // 递归处理所有题目,展开 childList
        this.cardData = this.flattenCardData(this.cardData);
        this.loading = false;
      }
    },
    /**
     * 递归处理 cardData,将 material 类型题目的 childList 展开
     * 并为每个子题添加 parentIndex,方便后续定位
     */
    flattenCardData(cardData) {
      const processedData = [];
      cardData.forEach((section, sectionIndex) => {
        // 为每个大类(如单选题、材料题)创建一个新的对象
        const processedSection = {
          ...section,
          infoList: [], // 重置 infoList 用于存放处理后的题目
        };
        section.infoList.forEach((item, itemIndex) => {
          if (
            item.questionType == "material" &&
            item.childList &&
            item.childList.length > 0
          ) {
            // 如果是材料题且有子题
            // 1. 保留材料题本身(如果需要显示题干)
            processedSection.infoList.push(item);
            item.childList.forEach((child, childIndex) => {
              // 将子题添加到渲染列表
              processedSection.infoList.push(child);
            });
          } else {
            // 如果不是材料题,或者没有子题,直接添加
            processedSection.infoList.push(item);
          }
        });
        // 将处理好的 section 添加到最终结果中
        // 只有当处理后的 infoList 有内容时才添加该 section
        if (processedSection.infoList.length > 0) {
          processedData.push(processedSection);
        }
      });
      return processedData;
    },
    hadleOpenDialog() { },
    // 获取不受保护的图片
    getPublicImage(md5, width, height) {
@@ -473,15 +546,12 @@
    },
    // 批改题目  (练习,我的做题,我的收藏模式下)
    handleQuestion() {
      debugger
      let errorId = [];
      const list = this.cardData;
      for (let index = 0; index < list.length; index++) {
        const item = list[index];
        for (let cindex = 0; cindex < item.infoList.length; cindex++) {
          const citem = item.infoList[cindex];
          citem.isComplete = true;
          // 修改题目状态为完成
          citem.isComplete = true;
          // 批改题目
@@ -564,9 +634,9 @@
      }
    },
    // 保存按钮
    saveAnswer(e) {
      if (e) {
        const pageNum = e
    saveAnswer(page) {
      if (page) {
        const pageNum = page;
        const oldAnswerData = localStorage.getItem(
          this.config.activeBook.name + "oldAnswerData"
        );
@@ -579,6 +649,8 @@
            asnwerList.push({
              id: citem.id,
              userAnswer: citem.userAnswer,
              isComplete: citem.isComplete,
              isRight: citem.isRight,
            });
          }
        }
@@ -597,14 +669,6 @@
        );
        Message.success("保存成功");
      }
      // if(oldData[this.chapter]) {
      //   oldData[this.chapter][this.page] = asnwerList
      // } else {
      //   oldData[this.chapter] = {}
      //   oldData[this.chapter][this.page] = asnwerList
      // }
      // console.log(oldData);
    },
    handleCollect(infoNum, num) {
      this.cardData[infoNum].infoList[num].isCollect =
@@ -619,7 +683,6 @@
        item = this.cardData[num];
      }
      item.isCollect = !item.isCollect;
      console.log(111, item);
      if (this.cardData.length == 0) {
        this.collectList.push(item.id);
      } else {
@@ -637,7 +700,6 @@
        const item = this.allCollect[index];
        if (item.type == this.sourceType) item.collectList = this.collectList;
      }
      console.log("点击收藏按钮", this.allCollect);
      this.MG.identity
        .setUserKey({
          setKeyRequests: [
@@ -654,8 +716,7 @@
    },
    // 获取收藏id列表
    getCollectIdList() {
      console.log(this.cardList, "cardList")
      const token = localStorage.getItem("token");
      const token = localStorage.getItem(this.config.tokenKey);
      if (!token) return false;
      this.MG.identity
        .getUserKey({
@@ -665,7 +726,6 @@
        .then((res) => {
          try {
            const collect = JSON.parse(res[0].value);
            console.log("全部收藏id", collect);
            if (collect.length) {
              this.collectList = collect.find(
                (citem) => citem.type == this.sourceType
@@ -687,7 +747,7 @@
    },
    // 获取错题id列表
    getErrorList() {
      const token = localStorage.getItem("token");
      const token = localStorage.getItem(this.config.tokenKey);
      if (!token) return false;
      this.MG.identity
        .getUserKey({
@@ -717,17 +777,6 @@
    },
    closeDialog() {
      this.localDialogVisible = false;
    },
    openDialogQuestion() {
      this.localDialogVisible = true;
      console.log(this.cardList, "this.cardList组件");
      console.log(this.page, "this.page组件");
      console.log(this.questionIDList, "this.questionIDList组件");
      console.log(this.config.activeBook,"this.config.activeBook组件");
    },
  },
};
@@ -1116,7 +1165,6 @@
}
/deep/ .el-collapse-item__content {
  width: 100%;
  padding: 0 20px;
  background-color: #f4f4f4;
  font-size: 16px;
@@ -1439,7 +1487,7 @@
          color: #fff;
          font-weight: 900;
          font-size: 16px;
          font-family: 'FZLTXIHJW';
          font-family: "FZLTXIHJW";
          span:nth-child(2):hover {
            cursor: pointer;
@@ -1451,7 +1499,7 @@
          color: #fff;
          font-weight: 900;
          font-size: 16px;
          font-family: 'FZLTXIHJW';
          font-family: "FZLTXIHJW";
        }
      }
@@ -1473,8 +1521,6 @@
        }
      }
    }
    .notBox {
      position: absolute;