闫增涛
2025-01-22 428df13a42db5fc6f8b61b6d646b1d035203a146
packageCourse/components/teaching/index.js
@@ -96,56 +96,63 @@
                cmsPath: data.productLinkPath
              })
              .then((res) => {
                const dataTeach = res.datas.cmsDatas[0]?.datas.find(
                  (item) => item.refCode == 'jsek_interaction'
                )
                app.MG.store
                  .getProductDetail({
                    path: '*',
                    queryType: '*',
                    productId: this.properties.bookId,
                    cmsPath: dataTeach.productLinkPath
                  })
                  .then((res) => {
                    let datas = res.datas.cmsDatas[0] ? res.datas.cmsDatas[0].datas : []
                    const dataRes = []
                    if (datas?.length > 0) {
                      datas.forEach(async (item) => {
                        const cmsRes = await app.MG.store
                          .getProductDetail({
                            path: '*',
                            queryType: '*',
                            productId: this.properties.bookId,
                            cmsPath: item.productLinkPath
                try {
                  const dataTeach = res.datas.cmsDatas[0]?.datas.find(
                    (item) => item.refCode == 'jsek_interaction'
                  )
                  app.MG.store
                    .getProductDetail({
                      path: '*',
                      queryType: '*',
                      productId: this.properties.bookId,
                      cmsPath: dataTeach.productLinkPath
                    })
                    .then((res) => {
                      let datas = res.datas.cmsDatas[0] ? res.datas.cmsDatas[0].datas : []
                      const dataRes = []
                      if (datas?.length > 0) {
                        datas.forEach(async (item) => {
                          const cmsRes = await app.MG.store
                            .getProductDetail({
                              path: '*',
                              queryType: '*',
                              productId: this.properties.bookId,
                              cmsPath: item.productLinkPath
                            })
                          if (
                            cmsRes.datas.cmsDatas[0].datas &&
                            cmsRes.datas.cmsDatas[0].datas.length > 0
                          ) {
                            cmsRes.datas.cmsDatas[0].datas.forEach((item, i) => {
                              item.subList = []
                              item.updateDate = '-'
                              if (this.data.dataList.length > 0) {
                                this.data.dataList.forEach((mitem) => {
                                  if (mitem.name == item.name) {
                                    item.updateDate = moment(mitem.updateDate).format(
                                      'YYYY-MM-DD HH:mm:ss'
                                    )
                                    item.subList.push(mitem)
                                  }
                                })
                              }
                              dataRes.push(item)
                            })
                          }
                          const resList = dataRes.sort((a, b) => b.subList.length - a.subList.length)
                          this.setData({
                            cmsDataList: resList,
                            loading: false
                          })
                        if (
                          cmsRes.datas.cmsDatas[0].datas &&
                          cmsRes.datas.cmsDatas[0].datas.length > 0
                        ) {
                          cmsRes.datas.cmsDatas[0].datas.forEach((item, i) => {
                            item.subList = []
                            item.updateDate = '-'
                            if (this.data.dataList.length > 0) {
                              this.data.dataList.forEach((mitem) => {
                                if (mitem.name == item.name) {
                                  item.updateDate = moment(mitem.updateDate).format(
                                    'YYYY-MM-DD HH:mm:ss'
                                  )
                                  item.subList.push(mitem)
                                }
                              })
                            }
                            dataRes.push(item)
                          })
                        }
                        const resList = dataRes.sort((a, b) => b.subList.length - a.subList.length)
                        this.setData({
                          cmsDataList: resList,
                          loading: false
                        })
                      })
                    }
                      }
                    })
                } catch (error) {
                  this.setData({
                    cmsDataList: [],
                    loading: false
                  })
                }
              })
          } catch (error) {
            this.setData({
@@ -214,7 +221,6 @@
    },
    // 处理数据结构
    chageData(arr, zrr) {
      let newData = []
      // 题库题目类型
      const questionTypeList = [{
          name: '单选题',
@@ -259,23 +265,32 @@
      ]
      for (let i = 0; i < arr.length; i++) {
        const item = arr[i]
        item.questionTypeList = questionTypeList
        for (let j = 0; j < zrr.length; j++) {
          const ele = zrr[j]
          const qusObj = item.question.find((citem) => citem.cmsItemId == ele.id)
          if (qusObj?.cmsItemId) {
            ele.userAnswer = qusObj.answer
            const index = findIndexByValue(questionTypeList, ele.questionType)
            if (index > -1) {
              item.questionTypeList[index].data.push(ele)
        item.questionTypeList = JSON.parse(JSON.stringify(questionTypeList));
        item.other = []
        for (let j = 0; j < item.question.length; j++) {
          const ele = item.question[j]
          const data = zrr.find((sitem) => sitem.id == ele.cmsItemId)
          const index = findIndexById(zrr, ele.cmsItemId)
          if (index > -1) {
            item.other[index] = {
              ...data,
              userAnswer: ele.answer
            }
          }
        }
        item.questionTypeList = item.questionTypeList.filter((item) => item.data.length > 0)
        newData.push(item)
        if (item.other.length > 0) {
          item.other.forEach((aitem) => {
            const index = findIndexByValue(item.questionTypeList, aitem.questionType)
            if (index > -1) {
              item.questionTypeList[index].data.push(aitem)
            }
          })
        }
        item.questionTypeList = item.questionTypeList.filter((xitem) => xitem.data.length > 0)
      }
      return newData.filter((item) => item.questionTypeList.length > 0)
      return arr
    },
    findIndexByValue(res, type) {
      for (let i = 0; i < res.length; i++) {
        if (res[i].value == type) {
@@ -284,6 +299,16 @@
      }
      return -1 // 如果未找到,则返回 -1
    },
    findIndexById(res, id) {
      for (let i = 0; i < res.length; i++) {
        if (res[i].id == id) {
          return i
        }
      }
      return -1 // 如果未找到,则返回 -1
    },
    toDetail(e) {
      const {
        item