Administrator
2021-08-17 90cf4906f4eb91d82aa08045f52c278dc0926eb5
src/views/startexam/index.vue
@@ -90,6 +90,7 @@
                                <el-button :class="{ 'answered': subjectIds[index].answered }"
                                           circle
                                           v-for="(value, index) in subjectIds"
                                            :style="{background: value.color}"
                                           :key="index"
                                           @click="toSubject(value.everyID, value.type, index)">&nbsp;{{index + 1}}&nbsp;</el-button>
                            </el-row>
@@ -109,7 +110,7 @@
import { saveAndNext } from '@/api/exam/answer'
import { getSubjectIds } from '@/api/exam/exam'
import { getCurrentTime } from '@/api/exam/examRecord'
import { getSubjectAnswer } from '@/api/exam/subject'
import { getSubjectResultInfo } from '@/api/exam/subject'
import moment from 'moment'
import { messageSuccess, messageFail, messageWarn, isNotEmpty } from '@/util/util'
@@ -141,7 +142,8 @@
        return {
            loadingLast: false,
            loadingNext: false,
            //1:绿色 2:红色  3:无色
            result:3,
            currentTime: 0,
            startTime: 0,
            endTime: 0,
@@ -254,7 +256,8 @@
                            index: i + 1,
                            answered: false,
                            answer: '',
                            score: subjectData[i].score
                            score: subjectData[i].score,
                            color: '#fff'
                        })
                    }
@@ -265,7 +268,7 @@
                    this.updateSubjectIndex()
                    // 获取当前题目信息
                    getSubjectAnswer({
                    getSubjectResultInfo({
                        id: this.subjectIds[0].everyID,
                    }).then(response => {
                        if (isNotEmpty(response.data.data)) {
@@ -303,7 +306,7 @@
                    this.subjectIndex = index
                    this.saveCurrentSubjectAndGetNextSubject(nextSubjectType.last, everyID, type)
                    this.saveCurrentSubjectAndGetNextSubjectLast(nextSubjectType.last, everyID, type)
                    break
@@ -319,7 +322,7 @@
                if (this.subjectIds[i].everyID == this.query.subjectId) {
                    this.subjectIds[i].answer = this.getAnswer()
                    this.markAnswered(this.subjectIds[i].answer, i)
                    if (i === this.subjectIds.length - 1) {
@@ -331,7 +334,7 @@
                    this.subjectIndex = index
                    this.saveCurrentSubjectAndGetNextSubject(nextSubjectType.next, everyID)
                    this.saveCurrentSubjectAndGetNextSubject(nextSubjectType.next, everyID,this.subjectIds[i-1])
                    break
@@ -341,17 +344,94 @@
        },
        // 保存当前题目,同时根据序号加载下一题
        saveCurrentSubjectAndGetNextSubject (nextType, nextSubjectId) {
        saveCurrentSubjectAndGetNextSubject (nextType, nextSubjectId,subjectIds) {
            this.startLoading(nextType)
            getSubjectAnswer({ id: nextSubjectId }).then(response => {
            var data  = {
                id:nextSubjectId,
                preSubJectId:this.query.subjectId,
                preResult:this.getAnswer()
            }
            getSubjectResultInfo(data).then(response => {
                if (response.data.data !== null) {
                    // 保存成功后更新答题卡状态
                    const subject = response.data.data
                    //结果
                    this.result = response.data.data.result;
                    if(this.result==1){
                         subjectIds.color = "#67C23A"
                    }
                    if(this.result==2){
                        subjectIds.color = "red"
                    }
                    const { id, choicesType } = subject
                    this.query.subjectId = id
                    this.query.type = choicesType
                    for (let i = 0; i < this.subjectIds.length; i++) {
                        if (this.subjectIds[i].everyID == nextSubjectId) {
                            subject.answer = this.subjectIds[i].answer
                            break
                        }
                    }
                    this.setSubjectInfo(subject)
                    // store.dispatch('SetSubjectInfo', subject).then(() => { })
                }
                // 更新时间
                getCurrentTime().then(response => {
                    this.subjectStartTime = moment(response.data.data)
                })
                this.endLoading(nextType)
            }).catch((error) => {
                console.log(error)
                messageFail(this, '获取题目失败')
                this.endLoading(nextType)
            })
        },
        // 保存当前题目,同时根据序号加载上一题
        saveCurrentSubjectAndGetNextSubjectLast (nextType, nextSubjectId) {
            this.startLoading(nextType)
            var data  = {
                id:nextSubjectId
            }
            getSubjectResultInfo(data).then(response => {
                if (response.data.data !== null) {
                    // 保存成功后更新答题卡状态
                    const subject = response.data.data
                    //结果
                    this.result = response.data.data.result;
                    // if(this.result==1){
                    //      subjectIds.color = "#67C23A"
                    // }
                    // if(this.result==2){
                    //     subjectIds.color = "red"
                    // }
                    const { id, choicesType } = subject
                    this.query.subjectId = id