Browse Source

教师中心

yuanyiming 1 year ago
parent
commit
f43d1f596e

+ 72 - 32
src/api/testDetail.js

@@ -2,50 +2,90 @@
 import request from '@/utils/request'
 // 获取问卷详情
 export function getTestCourseDetail(params) {
-    return request({
-        url: '/getTestCourseDetail',
-        method: 'get',
-        params,
-        hideloading: false
-    })
+  return request({
+    url: '/getTestCourseDetail',
+    method: 'get',
+    params,
+    hideloading: false
+  })
 }
 
 // 上传评测
 export function addTestWorks(data) {
-    return request({
-        url: '/addTestWorks',
-        method: 'post',
-        data,
-        hideloading: false
-    })
+  return request({
+    url: '/addTestWorks',
+    method: 'post',
+    data,
+    hideloading: false
+  })
 }
 
 // 保存评测
 export function addTestWorks2(data) {
-    return request({
-        url: '/addTestWorks2',
-        method: 'post',
-        data,
-        hideloading: false
-    })
+  return request({
+    url: '/addTestWorks2',
+    method: 'post',
+    data,
+    hideloading: false
+  })
 }
 
 // 删除评测问卷作业
 export function deleteTestCourseWorks(data) {
-    return request({
-        url: '/deleteTestCourseWorks',
-        method: 'post',
-        data,
-        hideloading: false
-    })
+  return request({
+    url: '/deleteTestCourseWorks',
+    method: 'post',
+    data,
+    hideloading: false
+  })
 }
 
-//查询问卷作业
+// 查询问卷作业
 export function selectTestCourseWorks(params) {
-    return request({
-        url: '/selectTestCourseWorks',
-        method: 'get',
-        params,
-        hideloading: false
-    })
-}
+  return request({
+    url: '/selectTestCourseWorks',
+    method: 'get',
+    params,
+    hideloading: false
+  })
+}
+
+// getCourseInfoTest
+export function getCourseInfoTest(params) {
+  return request({
+    url: '/getCourseInfoTest',
+    method: 'get',
+    params,
+    hideloading: false
+  })
+}
+
+// selectTestWorksCid
+export function selectTestWorksCid(params) {
+  return request({
+    url: '/selectTestWorksCid',
+    method: 'get',
+    params,
+    hideloading: false
+  })
+}
+
+// getTestWorks
+export function getTestWorks(params) {
+  return request({
+    url: '/getTestWorks',
+    method: 'get',
+    params,
+    hideloading: false
+  })
+}
+
+// getTestWorks2
+export function getTestWorks2(params) {
+  return request({
+    url: '/getTestWorks2',
+    method: 'get',
+    params,
+    hideloading: false
+  })
+}

+ 18 - 10
src/views/test/components/courseItem.vue

@@ -19,7 +19,7 @@
     <div class="cMiddle">
       <div class="cLeft">
         <div><span style="color: #aaadb1">题目数量:</span>{{ getNum(c.chapters) }}</div>
-        <div><span style="color: #aaadb1">截止时间:</span>{{ c.overtime ? c.overtime.split(' ')[0] : "暂无" }}</div>
+        <div><span style="color: #aaadb1">截止时间:</span>{{ c.overtime ? c.overtime.split(' ')[0] : '暂无' }}</div>
         <div><span style="color: #aaadb1">创建时间:</span>{{ c.time.split(' ')[0] }}</div>
       </div>
       <div class="cRight">
@@ -38,7 +38,7 @@
         </div>
       </div>
       <div class="cBRight">
-        <div class="editIcon" @click="goTo(c.courseId)">
+        <div class="editIcon" @click="goTo(c)">
           <img src="../../../assets/images/testStudent/edit.png" alt="" />
         </div>
         <div>填写</div>
@@ -56,7 +56,12 @@
           <div>{{ item.createTime }}</div>
         </div>
         <div class="cWItemRight">
-          <div @click.stop="doTest(item.courseid, item.id, item.name)" v-if="item.userid == userinfo.userid">修改</div>
+          <div
+            @click.stop="doTest(item.courseid, item.id, item.name, item.userid)"
+            v-if="item.userid == userinfo.userid"
+          >
+            修改
+          </div>
           <div @click.stop="deleteTest(item.id)" v-if="item.userid == userinfo.userid">删除</div>
         </div>
       </div>
@@ -77,7 +82,7 @@ export default {
   computed: {
     ...mapGetters(['userinfo']),
     getNum() {
-      return function (array) {
+      return function(array) {
         let _array = JSON.parse(array)
         let num = 0
         _array.forEach(el => {
@@ -101,7 +106,7 @@ export default {
       }
     },
     getScore() {
-      return function (array) {
+      return function(array) {
         // let _array = JSON.parse(array)
         let _score = 0
         let scoreArray = []
@@ -140,11 +145,14 @@ export default {
   },
   methods: {
     goTo(cid) {
+      // return console.log(cid)
+      debugger
+
       // eslint-disable-next-line prettier/prettier
-      this.$router.push({ path: '/testDetail', query: { courseid: cid } })
+      this.$router.push({ path: '/testDetail', query: { courseid: cid.courseId, userid: cid.userid } })
     },
-    doTest(cid, tid, name) {
-      this.$router.push({ path: '/preview', query: { courseid: cid, tid: tid, name: name } })
+    doTest(cid, tid, name, userid) {
+      this.$router.push({ path: '/preview', query: { courseid: cid, tid: tid, name: name, userid: userid } })
     },
     checkTest(cid, tid, name) {
       this.$router.push({ path: '/check', query: { courseid: cid, tid: tid, name: name } })
@@ -338,7 +346,7 @@ export default {
     align-items: flex-start;
     width: 100%;
     border-top: 0.02667rem solid #e3e3e3;
-    .cWorksItem:last-child{
+    .cWorksItem:last-child {
       padding: 0;
     }
     .cWorksItem {
@@ -382,4 +390,4 @@ export default {
     }
   }
 }
-</style>
+</style>

+ 10 - 1
src/views/testDetail/components/choice.vue

@@ -82,6 +82,15 @@ export default {
         this.$emit('update:cJson', newValue)
       },
       deep: true
+    },
+    cJson: {
+      handler(newValue) {
+        if (JSON.stringify(newValue.answer2) !== JSON.stringify(this.checkJson.answer2)) {
+          this.checkJson = this.depthCopy(newValue)
+          this.$forceUpdate()
+        }
+      },
+      deep: true
     }
   },
   methods: {
@@ -195,4 +204,4 @@ export default {
     }
   }
 }
-</style>
+</style>

+ 305 - 0
src/views/testDetail/components/course.vue

@@ -0,0 +1,305 @@
+<template>
+  <div class="c_box">
+    <div class="choice_box" v-loading="isloading" v-if="checkJson">
+      <div class="title" style="display: flex;">
+        <span style="min-width: fit-content;">{{ tindex + 1 + '、' }}</span>
+        <span>{{ checkJson.title }}</span>
+      </div>
+      <div
+        class="detail"
+        v-if="checkJson.detail"
+        v-html="checkJson.detail"
+        style="color: #00000099;margin-top: 5px;"
+      ></div>
+      <div class="choices" v-if="checkJson.courses.length">
+        <div class="course" @click="openCourse()">
+          <div class="banner">
+            <div v-if="tid" class="isRate">已评分</div>
+            <img :src="courseDetail.cover" alt="" />
+          </div>
+          <div class="content">
+            <div class="c_c">
+              <span>课程名称:</span>
+              <!-- <el-tooltip :content="courseDetail.title" placement="top" effect="dark"> -->
+              <span>{{ courseDetail.title }}</span>
+              <!-- </el-tooltip> -->
+            </div>
+            <div class="c_c">
+              <span>课程类型:</span>
+              <span v-if="!courseDetail.name">{{ '暂无' }}</span>
+              <span v-else>{{ courseDetail.name }}</span>
+
+              <!-- <el-tooltip v-else :content="courseDetail.name" placement="top" effect="dark">
+              </el-tooltip> -->
+            </div>
+            <div class="c_c">
+              <span>创建人:</span>
+              <span>{{ courseDetail.username }}</span>
+            </div>
+            <div class="c_c">
+              <span>协作者:</span>
+              <span v-if="!courseDetail.xieName">{{ '暂无' }}</span>
+              <!-- <el-tooltip v-else :content="courseDetail.xieName" placement="top" effect="dark"> -->
+              <span>{{ courseDetail.xieName }}</span>
+              <!-- </el-tooltip> -->
+            </div>
+          </div>
+        </div>
+        <div class="page" v-if="checktype == '1'">
+          <el-button type="primary" size="mini" :disabled="page == 0" @click="setPage('-1')">上一个</el-button>
+          <div class="p_page">
+            <span>{{ page + 1 }}</span
+            ><span>/</span><span>{{ checkJson.courses.length }}</span>
+          </div>
+          <el-button type="primary" size="mini" :disabled="page == checkJson.courses.length - 1" @click="setPage('1')"
+            >下一个</el-button
+          >
+        </div>
+      </div>
+    </div>
+  </div>
+</template>
+
+<script>
+import { getCourseInfoTest } from '@/api/testDetail'
+
+export default {
+  props: {
+    tindex: {
+      type: Number
+    },
+    cJson: {
+      type: Object
+    },
+    checktype: {
+      type: Number,
+      default: 1
+    },
+    see: {
+      type: Boolean,
+      default: false
+    },
+    issetPage: {
+      type: Boolean,
+      default: false
+    },
+    tid: {
+      type: String
+    }
+  },
+  data() {
+    return {
+      option: {
+        1: { name: '附件' }
+      },
+      userid: this.$route.query.userid,
+      checkJson: undefined,
+      progress: 0,
+      isFinishSize: 0,
+      proVisible: false,
+      isAllSize: 0,
+      wurl: '',
+      isTong: false,
+      page: 0,
+      isloading: false,
+      courseDetail: {},
+      courseid: ''
+    }
+  },
+  computed: {},
+  watch: {
+    checkJson: {
+      handler(newValue) {
+        console.log('cJson', newValue)
+
+        this.$emit('update:cJson', newValue)
+      },
+      deep: true
+    },
+    cJson: {
+      handler(newValue) {
+        if (newValue.answer2 != this.checkJson.answer2) {
+          this.checkJson = this.depthCopy(newValue)
+          if (this.checkJson.courses.length) {
+            this.page = this.checkJson.courses.indexOf(this.courseid)
+            this.checkJson.answer2 = this.courseid
+          }
+          this.$forceUpdate()
+        }
+      },
+      deep: true
+    },
+    courseid: {
+      handler(newValue) {
+        if (this.issetPage) {
+          this.$emit('update:issetPage', false)
+        } else {
+          // console.log('courseidnewValue', newValue)
+          this.$emit('getTestWorkByCid', newValue)
+        }
+      },
+      deep: true
+    }
+  },
+  methods: {
+    depthCopy(s) {
+      return JSON.parse(JSON.stringify(s))
+    },
+    openFileBox() {
+      this.dialogVisiblefile = true
+    },
+    setPage(index) {
+      this.$emit('publish2')
+      setTimeout(() => {
+        if (index == '1') {
+          this.page++
+        } else if (index == '-1') {
+          this.page--
+        }
+        this.checkJson.answer2 = this.checkJson.courses[this.page]
+        this.courseid = this.checkJson.answer2
+        this.$forceUpdate()
+        this.getCourse(this.checkJson.answer2)
+      }, 500)
+    },
+    openCourse() {
+      top.postMessage({ cid: this.checkJson.answer2, screenType: '3' }, '*')
+    },
+    getCourse(id) {
+      // console.log('999999999999999');
+      this.isloading = true
+      let params = {
+        cid: id
+      }
+      getCourseInfoTest(params)
+        .then(res => {
+          // console.log('getCourseInfoTest', res)
+          this.isloading = false
+          this.courseDetail = res[0][0]
+          this.courseDetail.cover = JSON.parse(this.courseDetail.cover)[0].url
+        })
+        .catch(err => {
+          console.error(err)
+        })
+    }
+  },
+  mounted() {
+    this.checkJson = this.cJson ? this.depthCopy(this.cJson) : undefined
+    // console.log(' this.checkJson', this.checkJson)
+    if (this.checkJson.courses.length) {
+      this.page = this.checkJson.courses.indexOf(this.checkJson.answer2)
+      this.courseid = this.checkJson.answer2
+      this.getCourse(this.checkJson.answer2)
+    }
+  }
+}
+</script>
+
+<style scoped>
+.c_box {
+  width: 100%;
+  position: relative;
+}
+
+/* .mask {
+    position: absolute;
+    height: 100%;
+    width: 100%;
+    z-index: 2;
+} */
+
+.choice_box {
+  white-space: pre-line;
+}
+
+.choice_box > .title {
+  font-size: 16px;
+  font-weight: bold;
+}
+
+.choice_box > .choices {
+  margin-top: 10px;
+  display: flex;
+  flex-direction: column;
+  justify-content: center;
+  align-items: center;
+}
+
+.choices > .page {
+  margin-top: 10px;
+  display: flex;
+  align-items: center;
+}
+
+.p_page {
+  margin: 0 10px;
+}
+
+.course {
+  width: 100%;
+  display: flex;
+  align-items: center;
+  cursor: pointer;
+}
+
+.course > .banner {
+  width: 140px;
+  height: 90px;
+  border-radius: 5px;
+  overflow: hidden;
+  border: 1px solid #3896fc;
+  box-sizing: border-box;
+  padding: 5px;
+  margin-right: 15px;
+  position: relative;
+}
+
+.isRate {
+  position: absolute;
+  background: #0061ff;
+  width: 70px;
+  height: 30px;
+  border-radius: 5px;
+  color: #fff;
+  font-size: 14px;
+  text-align: center;
+  line-height: 30px;
+  top: 5px;
+  left: 5px;
+}
+
+.course > .banner > img {
+  width: 100%;
+  height: 100%;
+  object-fit: cover;
+}
+
+.course > .content {
+  width: calc(100% - 140px);
+  overflow: hidden;
+}
+
+.course > .content > .c_c {
+  display: flex;
+  /* align-items: center; */
+  justify-content: flex-start;
+}
+
+.course > .content > .c_c + .c_c {
+  margin-top: 5px;
+}
+
+.course > .content > .c_c span:nth-child(1) {
+  width: 60px;
+  flex-shrink: 0;
+}
+
+.course > .content > .c_c span:nth-child(2) {
+  max-width: 180px;
+  overflow: hidden;
+  /* white-space: nowrap; */
+  display: block;
+  text-align: left;
+  /* text-overflow: ellipsis; */
+}
+</style>

+ 156 - 0
src/views/testDetail/components/eva.vue

@@ -0,0 +1,156 @@
+<template>
+  <div class="c_box">
+    <div class="choice_box" v-if="checkJson">
+      <div class="title" style="display: flex;">
+        <span style="min-width: fit-content;">{{ tindex + 1 + '、' }}</span>
+        <span>{{ checkJson.title }}</span>
+      </div>
+      <div
+        class="detail"
+        v-if="checkJson.detail"
+        v-html="checkJson.detail"
+        style="color: #00000099;margin-top: 5px;"
+      ></div>
+      <div class="choices">
+        <div
+          class="score"
+          :class="{
+            active:
+              (checkJson.answer2 || checkJson.answer2 === 0) &&
+              (checkJson.answer2 > index || checkJson.answer2 === index)
+          }"
+          @click="score(index)"
+          v-for="(item, index) in parseInt(checkJson.big) - parseInt(checkJson.small) + 1"
+          :key="index"
+        >
+          {{ parseInt(checkJson.small) + index }}
+        </div>
+      </div>
+    </div>
+  </div>
+</template>
+
+<script>
+export default {
+  props: {
+    tindex: {
+      type: Number
+    },
+    cJson: {
+      type: Object
+    },
+    checktype: {
+      type: Number,
+      default: 1
+    },
+    see: {
+      type: Boolean,
+      default: false
+    }
+  },
+  data() {
+    return {
+      option: {
+        1: { name: '附件' }
+      },
+      userid: this.$route.query.userid,
+      checkJson: undefined,
+      progress: 0,
+      isFinishSize: 0,
+      proVisible: false,
+      isAllSize: 0,
+      wurl: '',
+      isTong: false
+    }
+  },
+  watch: {
+    checkJson: {
+      handler(newValue) {
+        this.$emit('update:cJson', newValue)
+      },
+      deep: true
+    },
+    cJson: {
+      handler(newValue) {
+        if (newValue.answer2 !== this.checkJson.answer2) {
+          this.checkJson = this.depthCopy(newValue)
+          this.$forceUpdate()
+        }
+      },
+      deep: true
+    }
+  },
+  methods: {
+    depthCopy(s) {
+      return JSON.parse(JSON.stringify(s))
+    },
+    openFileBox() {
+      this.dialogVisiblefile = true
+    },
+    score(index) {
+      if (this.checktype == '2') {
+        return
+      }
+      this.checkJson.answer2 = index
+    }
+  },
+  mounted() {
+    this.checkJson = this.cJson ? this.depthCopy(this.cJson) : undefined
+    // console.log('evathis.checkJson', this.checkJson)
+  }
+}
+</script>
+
+<style scoped>
+.c_box {
+  width: 100%;
+  position: relative;
+}
+
+/* .mask {
+    position: absolute;
+    height: 100%;
+    width: 100%;
+    z-index: 2;
+} */
+
+.choice_box {
+  white-space: pre-line;
+}
+
+.choice_box > .title {
+  font-weight: bold;
+  font-size: 16px;
+  margin-bottom: 10px;
+  /* width: 100%; */
+  /* word-break: break-all; */
+}
+
+.choice_box > .choices {
+  margin-top: 10px;
+  display: flex;
+  flex-wrap: wrap;
+  justify-content: center;
+  width: 90%;
+  margin: 0 auto;
+}
+
+.choices > .score {
+  width: 40px;
+  height: 40px;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+  margin: 0 20px 10px 0;
+  border-radius: 5px;
+  background: #dee0e3;
+  font-size: 18px;
+  font-weight: bold;
+  color: #fff;
+  cursor: pointer;
+}
+
+.choices > .score.active {
+  background: #65b1ff;
+}
+</style>

+ 29 - 5
src/views/testDetail/components/file.vue

@@ -107,6 +107,7 @@ import fileIcon from '../../../assets/images/fileIcon/word2.png'
 import wpdf from '../file/wPdf2.vue'
 import wVideo from '../file/wVideo.vue'
 import wOffice from '../file/wOffice.vue'
+
 export default {
   components: {
     wpdf,
@@ -159,6 +160,25 @@ export default {
         this.$emit('update:cJson', newValue)
       },
       deep: true
+    },
+    cJson: {
+      handler(newValue, oldVal) {
+        console.log('kkk', newValue, oldVal)
+        if (newValue.file && this.checkJson.file && newValue.file.length !== this.checkJson.file.length) {
+          this.checkJson = this.depthCopy(newValue)
+          this.$forceUpdate()
+        } else if (newValue.file && !this.checkJson.file) {
+          this.checkJson = this.depthCopy(newValue)
+          this.$forceUpdate()
+        } else if (!newValue.file && this.checkJson.file) {
+          this.checkJson = this.depthCopy(newValue)
+          this.$forceUpdate()
+        } else if (JSON.stringify(newValue) !== JSON.stringify(oldVal)) {
+          this.checkJson = this.depthCopy(newValue)
+          this.$forceUpdate()
+        }
+      },
+      deep: true
     }
   },
   methods: {
@@ -217,14 +237,14 @@ export default {
         }
         bucket
           .upload(params, options)
-          .on('httpUploadProgress', function (evt) {
+          .on('httpUploadProgress', function(evt) {
             //这里可以写进度条
             // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
             _this.progress = parseInt((evt.loaded / evt.total) * 100)
             _this.isFinishSize = (evt.loaded / 1024 / 1024).toFixed(2)
             _this.$forceUpdate()
           })
-          .send(function (err, data) {
+          .send(function(err, data) {
             _this.progress = 100
             _this.isFinishSize = _this.isAllSize
             _this.$forceUpdate()
@@ -321,6 +341,7 @@ export default {
                   type: _type
                 })
               }
+              _this.$emit('update:cJson', _this.checkJson)
               _this.$forceUpdate()
 
               console.log(_this.checkJson)
@@ -352,9 +373,10 @@ export default {
         Bucket: 'ccrb',
         Key: name
       }
-      s3.getObject(params, function (err, data) {
+      s3.getObject(params, function(err, data) {
         _this.downLoading = ''
-        if (err) console.log(err, err.stack) // an error occurred
+        if (err) console.log(err, err.stack)
+        // an error occurred
         else {
           let url = window.URL.createObjectURL(new Blob([data.Body]))
           let a = document.createElement('a')
@@ -384,10 +406,12 @@ export default {
     },
     delFile(index) {
       this.checkJson.file.splice(index, 1)
+      this.$emit('update:cJson', this.checkJson)
       this.$forceUpdate()
     }
   },
   mounted() {
+    console.log('接收数据', this.cJson)
     this.checkJson = this.cJson ? this.depthCopy(this.cJson) : undefined
   }
 }
@@ -575,4 +599,4 @@ export default {
     }
   }
 }
-</style>
+</style>

+ 10 - 1
src/views/testDetail/components/gap.vue

@@ -73,6 +73,15 @@ export default {
         this.$emit('update:cJson', newValue)
       },
       deep: true
+    },
+    cJson: {
+      handler(newValue) {
+        if (newValue.answer2 !== this.checkJson.answer2) {
+          this.checkJson = this.depthCopy(newValue)
+          this.$forceUpdate()
+        }
+      },
+      deep: true
     }
   },
   directives: {
@@ -182,4 +191,4 @@ export default {
     }
   }
 }
-</style>
+</style>

+ 374 - 237
src/views/testDetail/components/topic.vue

@@ -1,169 +1,251 @@
 <template>
-  <div class="testBox">
-    <div class="c_box">
-      <div class="c_box_title">{{ title }}</div>
-      <div class="c_box_brief" v-if="brief">{{ brief }}</div>
-      <div class="c_box_score">
-        <span>总分:{{ score }}</span>
-        <span v-if="name" style="margin-left: 10px">答题人:{{ name }}</span>
-        <!-- <span style="margin-left: 10px">总得分:{{ score2 }}</span> -->
-      </div>
-      <div class="c_body" v-if="isloading">
-        <div v-if="type == 3">
-          <div v-for="(item, index) in checkArray[page].array" :key="index" class="check_box">
+  <div class="c_box">
+    <div class="c_box_title">{{ title }}</div>
+    <div class="c_box_brief" v-if="brief">{{ brief }}</div>
+    <div class="c_box_score">
+      <span>总分:{{ score }}</span>
+      <span v-if="name" style="margin-left: 10px;">答题人:{{ name }}</span>
+      <span style="margin-left: 10px;">总得分:{{ score2 }}</span>
+    </div>
+    <div class="c_body" v-if="isloading">
+      <div v-if="type == 3">
+        <div v-for="(item, index) in checkArray[page].array" :key="index" class="check_box">
+          <div
+            class="title"
+            v-if="item.ttype != 1 || (!item.json && item.ttype == 1)"
+            :style="{ fontSize: item.ttype == 1 && '16px' }"
+          >
+            {{ selectType(item, index) }}
+          </div>
+          <div v-if="item.ttype == 1" class="answerBox">
+            <choiceV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-if="item.type == 1"
+              :see="see"
+              :isTeacher="isTeacher"
+            ></choiceV>
+            <gapV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-else-if="item.type == 3"
+              :see="see"
+              :isTeacher="isTeacher"
+            ></gapV>
+            <fileV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-else-if="item.type == 5"
+              :see="see"
+              :isTeacher="isTeacher"
+            ></fileV>
+            <courseV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-else-if="item.type == 6"
+              :see="see"
+              :isTeacher="isTeacher"
+              @getTestWorkByCid="getTestWorkByCid"
+              @publish2="publish2"
+              :issetPage.sync="issetPage"
+              :tid="tid"
+            ></courseV>
+            <evaV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-else-if="item.type == 7"
+              :see="see"
+              :isTeacher="isTeacher"
+            ></evaV>
+            <!-- <span v-else>暂未设置题目</span> -->
+          </div>
+          <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
             <div
               class="title"
-              v-if="item.ttype != 1 || (!item.json && item.ttype == 1)"
-              :style="{ fontSize: item.ttype == 1 && '16px' }"
+              v-if="item2.ttype != 1 || (!item2.json && item2.ttype == 1)"
+              :style="{ fontSize: item2.ttype == 1 && '16px' }"
             >
-              {{ selectType(item, index) }}
+              {{ selectType(item2, index2) }}
             </div>
-            <div v-if="item.ttype == 1" class="answerBox">
+            <div v-if="item2.ttype == 1" class="answerBox">
               <choiceV
-                :tindex="index"
-                :cJson.sync="item.json"
+                :tindex="index2"
+                :cJson.sync="item2.json"
                 :checktype="checktype"
-                v-if="item.type == 1"
+                v-if="item2.type == 1"
                 :see="see"
                 :isTeacher="isTeacher"
               ></choiceV>
               <gapV
-                :tindex="index"
-                :cJson.sync="item.json"
+                :tindex="index2"
+                :cJson.sync="item2.json"
                 :checktype="checktype"
-                v-else-if="item.type == 3"
+                v-else-if="item2.type == 3"
                 :see="see"
                 :isTeacher="isTeacher"
               ></gapV>
               <fileV
-                :tindex="index"
-                :cJson.sync="item.json"
+                :tindex="index2"
+                :cJson.sync="item2.json"
                 :checktype="checktype"
-                v-else-if="item.type == 5"
+                v-else-if="item2.type == 5"
                 :see="see"
                 :isTeacher="isTeacher"
               ></fileV>
-            </div>
-            <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
-              <div
-                class="title"
-                v-if="item2.ttype != 1 || (!item2.json && item2.ttype == 1)"
-                :style="{ fontSize: item2.ttype == 1 && '16px' }"
-              >
-                {{ selectType(item2, index2) }}
-              </div>
-              <div v-if="item2.ttype == 1" class="answerBox">
-                <choiceV
-                  :tindex="index2"
-                  :cJson.sync="item2.json"
-                  :checktype="checktype"
-                  v-if="item2.type == 1"
-                  :see="see"
-                  :isTeacher="isTeacher"
-                ></choiceV>
-                <gapV
-                  :tindex="index2"
-                  :cJson.sync="item2.json"
-                  :checktype="checktype"
-                  v-else-if="item2.type == 3"
-                  :see="see"
-                  :isTeacher="isTeacher"
-                ></gapV>
-                <fileV
-                  :tindex="index2"
-                  :cJson.sync="item2.json"
-                  :checktype="checktype"
-                  v-else-if="item2.type == 5"
-                  :see="see"
-                  :isTeacher="isTeacher"
-                ></fileV>
-              </div>
+              <courseV
+                :tindex="index2"
+                :cJson.sync="item2.json"
+                :checktype="checktype"
+                v-else-if="item2.type == 6"
+                :see="see"
+                :isTeacher="isTeacher"
+                @getTestWorkByCid="getTestWorkByCid"
+                @publish2="publish2"
+                :issetPage.sync="issetPage"
+                :tid="tid"
+              ></courseV>
+              <evaV
+                :tindex="index2"
+                :cJson.sync="item2.json"
+                :checktype="checktype"
+                v-else-if="item2.type == 7"
+                :see="see"
+                :isTeacher="isTeacher"
+              ></evaV>
+              <!-- <span v-else>暂未设置题目</span> -->
             </div>
           </div>
         </div>
-        <div v-else>
-          <div v-for="(item, index) in checkArray" :key="index" class="check_box">
+      </div>
+      <div v-else>
+        <div v-for="(item, index) in checkArray" :key="index" class="check_box">
+          <div
+            class="title"
+            v-if="item.ttype != 1 || (!item.json && item.ttype == 1)"
+            :style="{ fontSize: item.ttype == 1 && '16px' }"
+          >
+            {{ selectType(item, index) }}
+          </div>
+          <div v-if="item.ttype == 1" class="answerBox">
+            <choiceV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-if="item.type == 1"
+              :see="see"
+              :isTeacher="isTeacher"
+            ></choiceV>
+            <gapV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-else-if="item.type == 3"
+              :see="see"
+              :isTeacher="isTeacher"
+            ></gapV>
+            <fileV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-else-if="item.type == 5"
+              :see="see"
+              :isTeacher="isTeacher"
+            ></fileV>
+            <courseV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-else-if="item.type == 6"
+              :see="see"
+              :isTeacher="isTeacher"
+              @getTestWorkByCid="getTestWorkByCid"
+              @publish2="publish2"
+              :issetPage.sync="issetPage"
+              :tid="tid"
+            ></courseV>
+            <evaV
+              :tindex="index"
+              :cJson.sync="item.json"
+              :checktype="checktype"
+              v-else-if="item.type == 7"
+              :see="see"
+              :isTeacher="isTeacher"
+            ></evaV>
+            <!-- <span v-else>暂未设置题目</span> -->
+          </div>
+          <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
             <div
               class="title"
-              v-if="item.ttype != 1 || (!item.json && item.ttype == 1)"
-              :style="{ fontSize: item.ttype == 1 && '16px' }"
+              v-if="item2.ttype != 1 || (!item2.json && item2.ttype == 1)"
+              :style="{ fontSize: item2.ttype == 1 && '16px' }"
             >
-              {{ selectType(item, index) }}
+              {{ selectType(item2, index2) }}
             </div>
-            <div v-if="item.ttype == 1" class="answerBox">
+            <div v-if="item2.ttype == 1" class="answerBox">
               <choiceV
-                :tindex="index"
-                :cJson.sync="item.json"
+                :tindex="index2"
+                :cJson.sync="item2.json"
                 :checktype="checktype"
-                v-if="item.type == 1"
+                v-if="item2.type == 1"
                 :see="see"
                 :isTeacher="isTeacher"
               ></choiceV>
               <gapV
-                :tindex="index"
-                :cJson.sync="item.json"
+                :tindex="index2"
+                :cJson.sync="item2.json"
                 :checktype="checktype"
-                v-else-if="item.type == 3"
+                v-else-if="item2.type == 3"
                 :see="see"
                 :isTeacher="isTeacher"
               ></gapV>
               <fileV
-                :tindex="index"
-                :cJson.sync="item.json"
+                :tindex="index2"
+                :cJson.sync="item2.json"
                 :checktype="checktype"
-                v-else-if="item.type == 5"
+                v-else-if="item2.type == 5"
                 :see="see"
                 :isTeacher="isTeacher"
               ></fileV>
-            </div>
-            <div v-for="(item2, index2) in item.array" :key="`${index}-${index2}`" class="check_box_xia">
-              <div
-                class="title"
-                v-if="item2.ttype != 1 || (!item2.json && item2.ttype == 1)"
-                :style="{ fontSize: item2.ttype == 1 && '16px' }"
-              >
-                {{ selectType(item2, index2) }}
-              </div>
-              <div v-if="item2.ttype == 1" class="answerBox">
-                <choiceV
-                  :tindex="index2"
-                  :cJson.sync="item2.json"
-                  :checktype="checktype"
-                  v-if="item2.type == 1"
-                  :see="see"
-                  :isTeacher="isTeacher"
-                ></choiceV>
-                <gapV
-                  :tindex="index2"
-                  :cJson.sync="item2.json"
-                  :checktype="checktype"
-                  v-else-if="item2.type == 3"
-                  :see="see"
-                  :isTeacher="isTeacher"
-                ></gapV>
-                <fileV
-                  :tindex="index2"
-                  :cJson.sync="item2.json"
-                  :checktype="checktype"
-                  v-else-if="item2.type == 5"
-                  :see="see"
-                  :isTeacher="isTeacher"
-                ></fileV>
-              </div>
+              <coursev
+                :tindex="index2"
+                :cJson.sync="item2.json"
+                :checktype="checktype"
+                v-else-if="item2.type == 6"
+                :see="see"
+                :isTeacher="isTeacher"
+                @getTestWorkByCid="getTestWorkByCid"
+                @publish2="publish2"
+                :issetPage.sync="issetPage"
+                :tid="tid"
+              ></coursev>
+              <evaV
+                :tindex="index2"
+                :cJson.sync="item2.json"
+                :checktype="checktype"
+                v-else-if="item2.type == 7"
+                :see="see"
+                :isTeacher="isTeacher"
+              ></evaV>
+              <!-- <span v-else>暂未设置题目</span> -->
             </div>
           </div>
         </div>
+      </div>
 
-        <div v-if="checkArray.length > 1 && type == 3" class="page">
-          <el-button type="primary" size="mini" :disabled="page == 0" @click="setPage('-1')">上一页</el-button>
-          <div class="p_page">
-            <span>{{ page + 1 }}</span
-            ><span>/</span><span>{{ checkArray.length }}</span>
-          </div>
-          <el-button type="primary" size="mini" :disabled="page == checkArray.length - 1" @click="setPage('1')"
-            >下一页</el-button
-          >
+      <div v-if="checkArray.length > 1 && type == 3" class="page">
+        <el-button type="primary" size="mini" :disabled="page == 0" @click="setPage('-1')">上一页</el-button>
+        <div class="p_page">
+          <span>{{ page + 1 }}</span
+          ><span>/</span><span>{{ checkArray.length }}</span>
         </div>
+        <el-button type="primary" size="mini" :disabled="page == checkArray.length - 1" @click="setPage('1')"
+          >下一页</el-button
+        >
       </div>
     </div>
   </div>
@@ -173,6 +255,8 @@
 import choiceV from './choice.vue'
 import gapV from './gap.vue'
 import fileV from './file.vue'
+import courseV from './course.vue'
+import evaV from './eva.vue'
 export default {
   props: {
     cJson: {
@@ -199,12 +283,18 @@ export default {
     name: {
       type: String,
       default: ''
+    },
+    tid: {
+      type: String,
+      default: ''
     }
   },
   components: {
     choiceV,
     gapV,
-    fileV
+    fileV,
+    courseV,
+    evaV
   },
   data() {
     return {
@@ -216,18 +306,21 @@ export default {
         // 2: "问答题",
         3: '问答题',
         4: '添加文档',
-        5: '附件'
+        5: '附件',
+        6: '课程',
+        7: '评分'
       },
       isloading: true,
+      issetPage: false
     }
   },
   computed: {
     selectType() {
-      return function (item, index) {
+      return function(item, index) {
         if (item.ttype == 1) {
           return index + 1 + '、' + this.options2[item.type]
         } else if (item.ttype == 2) {
-          return `第${index + 1}组 (共${item.array.length}题)`
+          return `${item.name ? item.name : `第${index + 1}组`}(共${item.array.length}题)`
         } else if (item.ttype == 3) {
           return `分页${index + 1}`
         }
@@ -254,48 +347,50 @@ export default {
       })
       return score > 0 ? score + '分' : '未设置分数'
     },
-    // score2() {
-    //   let score = 0
-    //   // let type = 1
-    //   this.checkArray.forEach(el => {
-    //     if ((el.ttype == 3 || el.ttype == 2) && el.array.length > 0) {
-    //       el.array.forEach(item => {
-    //         if (item.ttype == 2 && item.array.length > 0) {
-    //           item.array.forEach(item2 => {
-    //             if (item2.ttype == 1 && item2.json) {
-    //               score += item2.json.score2 ? parseFloat(item2.json.score2) : 0
-    //             }
-    //           })
-    //         } else if (item.ttype == 1 && item.json) {
-    //           score += item.json.score2 ? parseFloat(item.json.score2) : 0
-    //         }
-    //       })
-    //     } else if (el.ttype == 1 && el.json) {
-    //       score += el.json.score2 ? parseFloat(el.json.score2) : 0
-    //     }
-    //   })
-    //   return score + '分'
-    // }
+    score2() {
+      let score = 0
+      // let type = 1
+      this.checkArray.forEach(el => {
+        if ((el.ttype == 3 || el.ttype == 2) && el.array.length > 0) {
+          el.array.forEach(item => {
+            if (item.ttype == 2 && item.array.length > 0) {
+              item.array.forEach(item2 => {
+                if (item2.ttype == 1 && item2.json) {
+                  score += item2.json.score2 ? parseFloat(item2.json.score2) : 0
+                }
+              })
+            } else if (item.ttype == 1 && item.json) {
+              score += item.json.score2 ? parseFloat(item.json.score2) : 0
+            }
+          })
+        } else if (el.ttype == 1 && el.json) {
+          score += el.json.score2 ? parseFloat(el.json.score2) : 0
+        }
+      })
+      return score + '分'
+    }
   },
   watch: {
     cJson: {
       handler(newVal, oldVal) {
-        console.log(newVal)
-        console.log(oldVal)
+        // console.log('newValtop',newVal)
+        // console.log(oldVal)
         this.checkArray = this.setJson(this.depthCopy(newVal))
+        this.$forceUpdate()
       },
       deep: true
     }
   },
   methods: {
-    setPage(index){
+    setPage(index) {
+      this.issetPage = true
       this.isloading = false
-      if(index == '1'){
+      if (index == '1') {
         this.page++
-      }else if(index == '-1'){
+      } else if (index == '-1') {
         this.page--
       }
-      setTimeout(()=>{
+      setTimeout(() => {
         this.isloading = true
       }, 50)
       this.$forceUpdate()
@@ -310,13 +405,33 @@ export default {
         let checkArray = _json.filter(item => {
           if (item.array) {
             item.array = item.array.filter(item2 => {
-              if (item2.ttype == 1 && item2.json && !item2.json.answer2) {
+              if (item2.ttype == 1 && item2.json && !item2.json.answer2 && item2.type != 6 && item.type != 7) {
                 item2.json.answer2 = []
+              } else if (item2.ttype == 1 && item2.json && !item2.json.answer2 && item2.type == 6) {
+                item2.json.answer2 = item2.json.courses[0]
+              } else if (
+                item2.ttype == 1 &&
+                item2.json &&
+                !item2.json.answer2 &&
+                item2.json.answer2 !== 0 &&
+                item2.type == 7
+              ) {
+                item2.json.answer2 = ''
               }
               if (item2.array) {
                 item2.array = item2.array.filter(item3 => {
-                  if (item3.ttype == 1 && item3.json && !item3.json.answer2) {
+                  if (item3.ttype == 1 && item3.json && !item3.json.answer2 && item3.type != 6 && item3.type != 7) {
                     item3.json.answer2 = []
+                  } else if (item3.ttype == 1 && item3.json && !item3.json.answer2 && item3.type == 6) {
+                    item3.json.answer2 = item3.json.courses[0]
+                  } else if (
+                    item3.ttype == 1 &&
+                    item3.json &&
+                    !item3.json.answer2 &&
+                    item3.json.answer2 !== 0 &&
+                    item3.type == 7
+                  ) {
+                    item3.json.answer2 = ''
                   }
                   return item3
                 })
@@ -324,108 +439,130 @@ export default {
               return (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
             })
           }
-          if (item.ttype == 1 && item.json && !item.json.answer2) {
+          if (item.ttype == 1 && item.json && !item.json.answer2 && item.type != 6 && item.type != 7) {
             item.json.answer2 = []
+          } else if (item.ttype == 1 && item.json && !item.json.answer2 && item.type == 6) {
+            item.json.answer2 = item.json.courses[0]
+          } else if (item.ttype == 1 && item.json && !item.json.answer2 && item.json.answer2 !== 0 && item.type == 7) {
+            item.json.answer2 = ''
           }
-          console.log(item.array)
+          // console.log('item.array', item.array)
           return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1
         })
-        console.log(checkArray)
+        // console.log('checkArray', checkArray)
+
         return checkArray
       } else {
         return []
       }
+    },
+    getTestWorkByCid(cid) {
+      this.$emit('getTestWorkByCid', cid)
+    },
+    publish2() {
+      this.$emit('publish2')
     }
   },
   mounted() {
+    // console.log('(this.tid', this.tid)
     this.checkArray = this.setJson(this.depthCopy(this.cJson))
   }
 }
 </script>
 
-<style lang="scss" scoped>
-.testBox {
-  margin: 0 0 20px 0;
-  min-height: 350px;
-  .c_box {
-    width: 95%;
-    margin: 0 auto;
-    background: #fff;
-    height: 100%;
-    .c_box_title {
-      width: 90%;
-      text-align: center;
-      font-size: 24px;
-      font-weight: bold;
-      word-break: break-all;
-      margin: 10px auto;
-    }
+<style scoped>
+.c_box {
+  width: 95%;
+  margin: 0 auto;
+  background: #fff;
+  height: calc(100% - 55px);
+  overflow: auto;
+}
 
-    .c_box_brief {
-      width: 90%;
-      text-align: left;
-      font-size: 14px;
-      word-break: break-all;
-      margin: 10px auto;
-      color: #373737;
-    }
+.c_box_title {
+  width: 90%;
+  text-align: center;
+  font-size: 24px;
+  font-weight: bold;
+  word-break: break-all;
+  margin: 10px auto;
+}
 
-    .c_box_score {
-      width: 90%;
-      text-align: center;
-      word-break: break-all;
-      margin: 0 auto;
-      font-size: 16px;
-      color: #373737;
-      padding: 0 0 20px 0;
-      border-bottom: 1px solid #eee;
-    }
+.c_box_brief {
+  width: 90%;
+  text-align: left;
+  font-size: 14px;
+  word-break: break-all;
+  margin: 10px auto;
+  color: #373737;
+}
 
-    .c_body {
-      width: 90%;
-      margin: 0 auto;
-      .check_box {
-        margin-top: 10px;
-        padding-top: 10px;
+.c_box_score {
+  width: 90%;
+  text-align: center;
+  word-break: break-all;
+  margin: 0 auto 20px;
+  font-size: 16px;
+  color: #373737;
+}
 
-        .title {
-          font-size: 20px;
-          word-break: break-all;
-          font-weight: bold;
-        }
-        .answerBox {
-          margin-top: 10px;
-        }
-        .check_box_xia {
-          padding: 15px 0;
-          .title {
-            font-size: 18px;
-            font-weight: bold;
-          }
-          .answerBox {
-            margin-top: 10px;
-          }
-          .noanswerBox {
-            margin-top: 10px;
-          }
-        }
-        // .check_box_xia + .check_box_xia {
-        //   border-top: 1px solid #eee;
-        // }
-      }
-      // .check_box:not(:first-child) {
-      //   border-top: 1px solid #eee;
-      // }
-      .page {
-        margin: 20px;
-        display: flex;
-        align-items: center;
-        justify-content: center;
-        .p_page {
-          margin: 0 10px;
-        }
-      }
-    }
-  }
+.c_body {
+  width: 90%;
+  margin: 0 auto;
+}
+
+.check_box {
+}
+
+.check_box + .check_box {
+  margin-top: 10px;
+  padding-top: 10px;
+  border-top: 1px solid #eee;
+}
+
+.check_box > .title {
+  font-size: 20px;
+  word-break: break-all;
+  font-weight: bold;
+}
+
+.check_box > .answerBox {
+  margin-top: 10px;
+}
+
+.check_box > .noanswerBox {
+  margin-top: 10px;
+}
+
+.check_box_xia {
+  padding: 15px 0;
+}
+
+.check_box_xia + .check_box_xia {
+  border-top: 1px solid #eee;
+}
+
+.check_box_xia > .title {
+  font-size: 18px;
+  font-weight: bold;
+}
+
+.check_box_xia > .answerBox {
+  margin-top: 10px;
+}
+
+.check_box_xia > .noanswerBox {
+  margin-top: 10px;
+}
+
+.page {
+  margin: 20px;
+  display: flex;
+  align-items: center;
+  justify-content: center;
+}
+
+.p_page {
+  margin: 0 10px;
 }
-</style>
+</style>

+ 307 - 16
src/views/testDetail/index.vue

@@ -6,7 +6,15 @@
       </template>
     </head-bar>
     <div class="step_box">
-      <topicVue :cJson="cJson" :title="title" :brief="brief" ref="topicVue"></topicVue>
+      <topicVue
+        :cJson.sync="cJson"
+        :title="title"
+        :brief="brief"
+        ref="topicVue"
+        @getTestWorkByCid="getTestWorkByCid"
+        @publish2="publish2"
+        :tid="tid"
+      ></topicVue>
     </div>
     <div class="edit_top">
       <div class="op_btn">
@@ -19,9 +27,16 @@
 <script>
 import { getTestCourseDetail } from '@/api/testDetail'
 import { addTestWorks } from '@/api/testDetail'
+import { addTestWorks2 } from '@/api/testDetail'
+import { selectTestWorksCid } from '@/api/testDetail'
+// import { getTestWorks } from '@/api/testDetail'
+// import { getTestWorks2 } from '@/api/testDetail'
+
 import headBar from '@/components/headBar.vue'
 import { mapGetters } from 'vuex'
 import topicVue from './components/topic.vue'
+// import course from './components/course.vue'
+
 export default {
   components: {
     headBar,
@@ -29,10 +44,16 @@ export default {
   },
   data() {
     return {
-      courseid: this.$route.query.courseid,
+      courseid: '',
+      cid: this.$route.query.courseid,
+      userid: this.$route.query.userid,
+      see: false,
+      tid: '',
       title: '',
       brief: '',
-      cJson: []
+      look: '',
+      cJson: [],
+      cJson2: []
     }
   },
   computed: {
@@ -44,39 +65,309 @@ export default {
     },
     getData() {
       const params = {
-        cid: this.courseid
+        cid: this.cid
       }
       getTestCourseDetail(params)
         .then(res => {
           this.cJson = JSON.parse(res[0][0].chapters)
+          // console.log('getTestCourseDetail', this.cJson)
+
+          this.cJson2 = JSON.parse(res[0][0].chapters)
           this.title = res[0][0].title
           this.brief = res[0][0].brief
+
+          this.see = res[0][0].open == 1 ? true : false
+
+          this.testType = []
+          for (var i = 0; i < res[1].length; i++) {
+            this.testType.push(res[1][i].typeid)
+          }
+          // console.log(this.testType)
+          this.look = res[0][0].look
+          // if (this.type == 3) {
+          //   this.getTestWorks2()
+          // } else {
+          //   this.getTestWorks()
+          // }
+          this.$forceUpdate()
+        })
+        .catch(err => {
+          console.error(err)
+        })
+    },
+    getTestWorkByCid(courseid) {
+      this.courseid = courseid
+      let params = {
+        cid: this.cid,
+        uid: this.userid
+      }
+      console.log('getTestWorkByCidparams', params)
+      let _courseid = courseid
+      selectTestWorksCid(params)
+        .then(res => {
+          console.log('selectTestWorksCid', res)
+          if (res[0].length) {
+            let rData = res[0]
+            this.tid = ''
+            // eslint-disable-next-line no-labels
+            aa: for (var i = 0; i < rData.length; i++) {
+              let rDataJson = this.JSONSetting(JSON.parse(rData[i].courseJson))
+              let _json = JSON.parse(rData[i].courseJson)
+              for (var j = 0; j < rDataJson.length; j++) {
+                let _param = rDataJson[j]
+                if (_param.type == 6 && _param.json.answer2 && _param.json.answer2 == _courseid) {
+                  this.cJson = _json
+                  console.log(this.cJson)
+                  // let cJson = this.setJSON(JSON.parse(JSON.stringify(this.cJson)))
+                  // let cJson2 = this.setJSON(this.setJson2(JSON.parse(JSON.stringify(this.cJson2))))
+                  // if (JSON.stringify(cJson) != JSON.stringify(cJson2)) {
+                  //   this.isReset = true
+                  // }
+                  this.tid = rData[i].id
+                  this.$forceUpdate()
+                  break aa
+                }
+              }
+            }
+            if (!this.tid) {
+              this.cJson = this.setJSON(this.setCourseid(JSON.parse(JSON.stringify(this.cJson2))))
+            }
+          } else {
+            this.tid = ''
+            this.cJson = this.setJSON(this.setCourseid(JSON.parse(JSON.stringify(this.cJson2))))
+          }
+          this.$forceUpdate()
         })
         .catch(err => {
           console.error(err)
         })
     },
+    setJson2(json) {
+      let _json = json
+      // this.type = _json[0].ttype;
+      let checkArray = _json.filter(item => {
+        if (item.array) {
+          item.array = item.array.filter(item2 => {
+            if (item2.ttype == 1 && item2.json && !item2.json.answer2) {
+              item2.json.answer2 = []
+            }
+            if (item2.array) {
+              item2.array = item2.array.filter(item3 => {
+                if (item3.ttype == 1 && item3.json && !item3.json.answer2) {
+                  item3.json.answer2 = []
+                }
+                return item3
+              })
+            }
+            return (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
+          })
+        }
+        if (item.ttype == 1 && item.json && !item.json.answer2) {
+          item.json.answer2 = []
+        }
+        // console.log(item.array)
+        return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1
+      })
+      // console.log(checkArray)
+      return checkArray
+    },
+    setCourseid(json) {
+      let _json = json
+      // this.type = _json[0].ttype;
+      let checkArray = _json.filter(item => {
+        if (item.array) {
+          item.array = item.array.filter(item2 => {
+            if (item2.ttype == 1 && item2.json && !item2.json.answer2 && item2.type != 6 && item2.type != 7) {
+              item2.json.answer2 = []
+            } else if (item2.type == 6) {
+              item2.json.answer2 = this.courseid ? this.courseid : ''
+            } else if (item2.type == 7) {
+              item2.json.answer2 = ''
+            }
+            if (item2.array) {
+              item2.array = item2.array.filter(item3 => {
+                if (item3.ttype == 1 && item3.json && !item3.json.answer2 && item3.type != 6 && item3.type != 7) {
+                  item3.json.answer2 = []
+                } else if (item3.type == 6) {
+                  item3.json.answer2 = this.courseid ? this.courseid : ''
+                } else if (item3.type == 7) {
+                  item3.json.answer2 = ''
+                }
+                return item3
+              })
+            }
+            return (item2.ttype != 1 && item2.array.length > 0) || item2.ttype == 1
+          })
+        }
+        if (item.ttype == 1 && item.json && !item.json.answer2 && item.type != 6 && item.type != 6 && item.type != 7) {
+          item.json.answer2 = []
+        } else if (item.type == 6) {
+          item.json.answer2 = this.courseid ? this.courseid : ''
+        } else if (item.type == 7) {
+          item.json.answer2 = ''
+        }
+        // console.log(item.array)
+        return (item.ttype != 1 && item.array.length > 0) || item.ttype == 1
+      })
+      console.log('checkArray', checkArray)
+      return checkArray
+    },
+    JSONSetting(json) {
+      let _json = json
+      let array = []
+      _json.filter(item => {
+        if (item.array) {
+          item.array = item.array.filter(item2 => {
+            if (item2.ttype == 1 && item2.json) {
+              array.push(item2)
+            }
+            if (item2.array) {
+              item2.array = item2.array.filter(item3 => {
+                if (item3.ttype == 1 && item3.json) {
+                  array.push(item3)
+                }
+                return item3
+              })
+            }
+            return item2
+          })
+        }
+        if (item.ttype == 1 && item.json) {
+          array.push(item)
+        }
+        // console.log(item.array)
+        return item
+      })
+      // console.log(array)
+      return array
+    },
+    setJSON(json) {
+      return json.filter(item => {
+        if (item.array) {
+          item.array = item.array.filter(item2 => {
+            if (item2.ttype == 1 && item2.json) {
+              delete item2.json.answer2
+              delete item2.json.score2
+              delete item2.json.file
+            }
+            if (item2.array) {
+              item2.array = item2.array.filter(item3 => {
+                if (item3.ttype == 1 && item3.json) {
+                  delete item3.json.answer2
+                  delete item3.json.score2
+                  delete item3.json.file
+                }
+                return item3
+              })
+            }
+            return item2
+          })
+        } else if (item.ttype == 1 && item.json) {
+          delete item.json.answer2
+          delete item.json.score2
+          delete item.json.file
+        }
+        return item
+        console.log(item.array)
+      })
+    },
+
+    panJSON(array) {
+      var pan = 0
+      for (var i = 0; i < array.length; i++) {
+        if (array[i].type != 6) {
+          let param = array[i].json
+          if (array[i].type == 5 && param.file && param.file.length > 0) {
+            pan++
+          } else if (param.answer2.length || typeof param.answer2 == 'number') {
+            pan++
+          }
+        }
+      }
+      if (pan > 0) {
+        return true
+      } else {
+        return false
+      }
+    },
+    publish2() {
+      console.log('publish2')
+      let cjson = this.$refs['topicVue'].checkArray
+      let _cjson = this.JSONSetting(JSON.parse(JSON.stringify(cjson)))
+      let pan = this.panJSON(_cjson)
+      if (!pan) {
+        setTimeout(() => {
+          this.isloading = false
+        }, 500)
+        return
+      }
+      let params = [
+        {
+          uid: this.tid ? this.tid : this.userid,
+          cid: this.cid,
+          cjson: encodeURIComponent(JSON.stringify(cjson)),
+          type: '2'
+        }
+      ]
+      if (this.tid) {
+        addTestWorks2(params)
+          .then(res => {
+            this.$message.success('保存成功')
+          })
+          .catch(err => {
+            console.error(err)
+          })
+      } else {
+        addTestWorks(params)
+          .then(res => {
+            this.$message.success('保存成功')
+          })
+          .catch(err => {
+            console.error(err)
+          })
+      }
+    },
     publish() {
+      console.log('publish')
+
       let cjson = this.$refs['topicVue'].checkArray
+
       const params = [
         {
-          uid: this.userinfo.userid,
-          cid: this.courseid,
-          cjson: JSON.stringify(cjson),
+          uid: this.tid ? this.tid : this.userid,
+          cid: this.cid,
+          cjson: encodeURIComponent(JSON.stringify(cjson)),
           type: 2
         }
       ]
-      addTestWorks(params)
-        .then(res => {
-          this.$message.success('提交成功')
-          this.back()
-        })
-        .catch(err => {
-          console.error(err)
-        })
+      // console.log(this.tid)
+      // return console.log('publish发布', params)
+      if (this.tid) {
+        addTestWorks2(params)
+          .then(res => {
+            this.$message.success('提交成功')
+            this.back()
+          })
+          .catch(err => {
+            console.error(err)
+          })
+      } else {
+        console.log('shangchuan')
+
+        addTestWorks(params)
+          .then(res => {
+            this.$message.success('提交成功')
+            this.back()
+          })
+          .catch(err => {
+            console.error(err)
+          })
+      }
     }
   },
   mounted() {
+    // console.log('userid', this.$route.query.userid)
+
     this.getData()
   }
 }
@@ -108,4 +399,4 @@ export default {
     }
   }
 }
-</style>
+</style>

+ 148 - 7
src/views/testDetail/preview.vue

@@ -6,7 +6,15 @@
       </template>
     </head-bar>
     <div class="step_box">
-      <topicVue :cJson="cJson" :title="name" :brief="brief" ref="topicVue"></topicVue>
+      <topicVue
+        :cJson="cJson"
+        @getTestWorkByCid="getTestWorkByCid"
+        @publish2="publish2"
+        :title="name"
+        :tid="tid"
+        :brief="brief"
+        ref="topicVue"
+      ></topicVue>
     </div>
     <div class="edit_top">
       <div class="op_btn">
@@ -18,6 +26,8 @@
 
 <script>
 import { selectTestCourseWorks } from '@/api/testDetail'
+import { selectTestWorksCid } from '@/api/testDetail'
+
 import { addTestWorks2 } from '@/api/testDetail'
 import headBar from '@/components/headBar.vue'
 import { mapGetters } from 'vuex'
@@ -29,12 +39,14 @@ export default {
   },
   data() {
     return {
-      courseid: this.$route.query.courseid,
+      courseid: '',
       tid: this.$route.query.tid,
       name: this.$route.query.name,
       title: '',
       brief: '',
-      cJson: []
+      cJson: [],
+      cid: this.$route.query.courseid,
+      userid: this.$route.query.userid
     }
   },
   computed: {
@@ -46,11 +58,12 @@ export default {
     },
     getData() {
       const params = {
-        cid: this.courseid,
+        cid: this.cid,
         tid: this.tid
       }
       selectTestCourseWorks(params)
         .then(res => {
+          console.log('修改', res)
           if (res[1].length) {
             this.cJson = JSON.parse(res[1][0].courseJson)
           }
@@ -62,14 +75,110 @@ export default {
           console.error(err)
         })
     },
+    JSONSetting(json) {
+      let _json = json
+      let array = []
+      _json.filter(item => {
+        if (item.array) {
+          item.array = item.array.filter(item2 => {
+            if (item2.ttype == 1 && item2.json) {
+              array.push(item2)
+            }
+            if (item2.array) {
+              item2.array = item2.array.filter(item3 => {
+                if (item3.ttype == 1 && item3.json) {
+                  array.push(item3)
+                }
+                return item3
+              })
+            }
+            return item2
+          })
+        }
+        if (item.ttype == 1 && item.json) {
+          array.push(item)
+        }
+        // console.log(item.array)
+        return item
+      })
+      // console.log(array)
+      return array
+    },
+    getTestWorkByCid(courseid) {
+      this.courseid = courseid
+      let params = {
+        cid: this.cid,
+        uid: this.userid
+      }
+      console.log('getTestWorkByCidparams', params)
+      let _courseid = courseid
+      selectTestWorksCid(params)
+        .then(res => {
+          console.log('selectTestWorksCid', res)
+          if (res[0].length) {
+            let rData = res[0]
+            this.tid = ''
+            // eslint-disable-next-line no-labels
+            aa: for (var i = 0; i < rData.length; i++) {
+              let rDataJson = this.JSONSetting(JSON.parse(rData[i].courseJson))
+              let _json = JSON.parse(rData[i].courseJson)
+              for (var j = 0; j < rDataJson.length; j++) {
+                let _param = rDataJson[j]
+                if (_param.type == 6 && _param.json.answer2 && _param.json.answer2 == _courseid) {
+                  this.cJson = _json
+                  console.log(this.cJson)
+                  // let cJson = this.setJSON(JSON.parse(JSON.stringify(this.cJson)))
+                  // let cJson2 = this.setJSON(this.setJson2(JSON.parse(JSON.stringify(this.cJson2))))
+                  // if (JSON.stringify(cJson) != JSON.stringify(cJson2)) {
+                  //   this.isReset = true
+                  // }
+                  this.tid = rData[i].id
+                  this.$forceUpdate()
+                  break aa
+                }
+              }
+            }
+            if (!this.tid) {
+              this.cJson = this.setJSON(this.setCourseid(JSON.parse(JSON.stringify(this.cJson2))))
+            }
+          } else {
+            this.tid = ''
+            this.cJson = this.setJSON(this.setCourseid(JSON.parse(JSON.stringify(this.cJson2))))
+          }
+          this.$forceUpdate()
+        })
+        .catch(err => {
+          console.error(err)
+        })
+    },
+    panJSON(array) {
+      var pan = 0
+      for (var i = 0; i < array.length; i++) {
+        if (array[i].type != 6) {
+          let param = array[i].json
+          console.log('????', param)
+          if (array[i].type == 5 && param.file && param.file.length > 0) {
+            pan++
+          } else if (param.answer2.length || typeof param.answer2 == 'number') {
+            pan++
+          }
+        }
+      }
+      if (pan > 0) {
+        return true
+      } else {
+        return false
+      }
+    },
+
     publish() {
       let cjson = this.$refs['topicVue'].checkArray
       const params = [
         {
           uid: this.tid,
-          cid: this.courseid,
-          cjson: JSON.stringify(cjson),
-          type: '2',
+          cid: this.cid,
+          cjson: encodeURIComponent(JSON.stringify(cjson)),
+          type: '2'
         }
       ]
       addTestWorks2(params)
@@ -80,8 +189,40 @@ export default {
         .catch(err => {
           console.error(err)
         })
+    },
+    publish2() {
+      let cjson = this.$refs['topicVue'].checkArray
+      let _cjson = this.JSONSetting(JSON.parse(JSON.stringify(cjson)))
+      let pan = this.panJSON(_cjson)
+      console.log('pan', pan)
+      if (!pan) {
+        setTimeout(() => {
+          this.isloading = false
+        }, 500)
+        return
+      }
+      let params = [
+        {
+          uid: this.tid,
+          cid: this.cid,
+          cjson: encodeURIComponent(JSON.stringify(cjson)),
+          type: '2'
+        }
+      ]
+      if (this.tid) {
+        addTestWorks2(params)
+          .then(res => {
+            this.$message.success('修改成功')
+          })
+          .catch(err => {
+            console.error(err)
+          })
+      } else {
+        console.log('tid呢')
+      }
     }
   },
+
   mounted() {
     this.getData()
   }