提交 26b4b778 authored 作者: lihuihui's avatar lihuihui

feat: 新增解答题

上级 9d79903a
......@@ -2,7 +2,7 @@ import axios from 'axios'
import _ from 'lodash'
export default class API {
constructor (config) {
constructor(config) {
/* 创建一个 自定义配置axios实例 */
// 让ajax携带cookie
axios.defaults.withCredentials = true
......@@ -22,12 +22,12 @@ export default class API {
}
/* 获取当前Vue创建实例 */
getVueInstance () {
getVueInstance() {
return window.G.$instance_vue
}
/* 重新封装 请求时的执行函数 */
_request (_config = {}) {
_request(_config = {}) {
/* 具体执行请求成功后业务逻辑前,先执行该方法 */
const beforeSuccess = _config.beforeSuccess ? _config.beforeSuccess : this._reqSuccess
/* 具体执行请求失败后业务逻辑前,先执行该方法 */
......@@ -57,8 +57,7 @@ export default class API {
_config.data = fr
}
/* 创建并根据参数发起请求 */
return this._axios(_config)
.then(beforeSuccess.bind(this), beforeFail.bind(this))
return this._axios(_config).then(beforeSuccess.bind(this), beforeFail.bind(this))
}
/**
......@@ -66,7 +65,7 @@ export default class API {
* 注意:如果不能满足需求,可在接口定义处重新实现
* @param {[object]} res 返回数据
*/
_reqSuccess (res) {
_reqSuccess(res) {
const { status, data } = res
let err = null
if (status === 200) {
......@@ -82,7 +81,7 @@ export default class API {
* 注意:如果不能满足需求,可在接口定义处重新实现
* @param {[object]} res 如果未到达 response 阶段,则无res.response
*/
_reqFail (res) {
_reqFail(res) {
let err = null
if (res.code === 'ECONNABORTED') {
err = new Error('网络超时,请稍后重试')
......@@ -111,22 +110,22 @@ export default class API {
}
/* 重新实现 get请求 */
get (url, data, config) {
get(url, data, config) {
return this._request(_.assignIn({ url, method: 'GET', params: data }, config))
}
/* 重新实现 post请求 */
post (url, data, config) {
post(url, data, config) {
return this._request(_.assignIn({ url, method: 'POST', data: data }, config))
}
/* 重新实现 put请求 */
put (url, data, config) {
put(url, data, config) {
return this._request(_.assignIn({ url, method: 'PUT', data: data }, config))
}
/* 重新实现 delete请求 */
delete (url, data, config) {
delete(url, data, config) {
return this._request(_.assignIn({ url, method: 'DELETE', params: data }, config))
}
}
......@@ -138,6 +138,7 @@ export default {
},
methods: {
goQuestion(n) {
this.$emit('switchQuestion')
this.questionParams.questionIndex = n - 1
}
}
......
......@@ -30,6 +30,17 @@
</template>
</ul>
</template>
<!-- 问答题 -->
<template v-if="questionData.question_item_type == 3">
<div class="title-type">
<div class="type">{{ questionData.question_item_title }}</div>
<div class="num">{{ questionData.q_order }}/{{ questionParams.question.total_question_count }}</div>
</div>
<div class="title">
<div class="num">{{ questionData.q_order }}.</div><div class="des" v-html="questionData.content"></div>
</div>
<el-input @input="QAChange(questionData.question_item_id, questionData.id)" type="textarea" placeholder="请输入内容" v-model="questionData.textContent"></el-input>
</template>
<!-- 复合题 -->
<template v-if="questionData.question_item_type == 5">
<div class="title-type">
......@@ -89,7 +100,8 @@ export default {
return {
questionData: {},
clearTime: null,
setCacheTime: null
setCacheTime: null,
textarea: ''
}
},
beforeDestroy() {
......@@ -142,9 +154,38 @@ export default {
this.questionData[k] = item[k]
})
typeof this.questionData.options === 'string' && (this.questionData.options = JSON.parse(currentItem.options))
const pId = this.questionData.question_item_id
const cId = this.questionData.id
console.log(this.questionData.question_item_id, this.questionData.id, '321++')
// 问答题答案回显
if (this.questionParams.answerRecord[pId]) {
if (this.questionParams.answerRecord[pId][cId]) {
this.questionData.textContent = this.questionParams.answerRecord[pId][cId].answer[0]
return
}
}
this.questionData.textContent = ''
}
}
})
console.log(this.questionData, '===123', this.questionParams)
},
// 问答题回答
QAChange(pId, cId) {
this.questionParams.answerRecord[pId]
? this.questionParams.answerRecord[pId][cId]
? this.questionParams.answerRecord[pId][cId].answer = [this.questionData.textContent]
: this.questionParams.answerRecord[pId][cId] = {
answer: [this.questionData.textContent],
sign: false
}
: this.questionParams.answerRecord[pId] = {
[cId]: {
answer: [this.questionData.textContent],
sign: false
}
}
this.$forceUpdate()
},
// 选项选择
changeOptions: _.debounce(function(type, pId, cId, optId) {
......@@ -286,6 +327,11 @@ export default {
}
</script>
<style lang="scss" scoped>
::v-deep{
.el-textarea__inner{
height: 150px;
}
}
.title-type{
width: 100%;
height: 45px;
......
......@@ -15,6 +15,7 @@
<div class="left" ref="wrapper2">
<div>
<question
style="padding-bottom: 30px"
v-if="Object.keys(questionParams.question).length"
:contentHeight="contentHeight"
:questionParams="questionParams"
......@@ -24,7 +25,12 @@
</div>
</div>
<div class="right" ref="wrapper">
<answer-card :questionParams="questionParams" :changeTime="changeTime" :info="sInfo.info"></answer-card>
<answer-card
:questionParams="questionParams"
:changeTime="changeTime"
:info="sInfo.info"
@switchQuestion="switchQuestion"
></answer-card>
</div>
<ul class="flag-tips">
<li>
......@@ -221,8 +227,7 @@ export default {
const param = {
answer: JSON.stringify(this.questionParams.answerRecord)
}
action.Exam.endExam(this.$route.params.examId, param)
.then(res => {
action.Exam.endExam(this.$route.params.examId, param).then(res => {
if (!n) {
clearInterval(this.clearTime)
this.$router.replace({
......@@ -232,28 +237,28 @@ export default {
// this.sendExamInfo(6)
window.localStorage.setItem('showflag', 'true')
})
.catch(err => {
if (err.message.indexOf('error') !== -1) {
this.$confirm('网络异常,请保持网络通畅', '提示', {
distinguishCancelAndClose: true,
confirmButtonText: '退出考试',
cancelButtonText: '重新提交',
type: 'warning'
})
.then(() => {
this.$router.replace({
path: `/login/${JSON.parse(window.localStorage.getItem('examInfo')).exam_id}`
})
})
.catch(action => {
action === 'cancel' && this.endExamRequest()
})
} else {
this.$alert(err.message, {
callback: action => {}
})
}
})
// .catch(err => {
// if (err.message.indexOf('error') !== -1) {
// this.$confirm('网络异常,请保持网络通畅', '提示', {
// distinguishCancelAndClose: true,
// confirmButtonText: '退出考试',
// cancelButtonText: '重新提交',
// type: 'warning'
// })
// .then(() => {
// this.$router.replace({
// path: `/login/${JSON.parse(window.localStorage.getItem('examInfo')).exam_id}`
// })
// })
// .catch(action => {
// action === 'cancel' && this.endExamRequest()
// })
// } else {
// this.$alert(err.message, {
// callback: action => {}
// })
// }
// })
},
countDown(time) {
const lefttime = parseInt(time / 1000)
......@@ -301,11 +306,18 @@ export default {
this.questionParams.questionIndex + 1 !== this.questionParams.question.total_question_count &&
this.questionParams.questionIndex++
}
this.refreshBscroll()
// this.initBscroll()
},
refreshBscroll() {
this.$nextTick(() => {
this.domBScroll.refresh()
this.domBScroll.scrollTo(0, -10, 0)
})
// this.initBscroll()
},
switchQuestion() {
console.log(1111)
this.refreshBscroll()
},
getTopic() {
action.Exam.getTopic(this.$route.params.examId)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论