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

feat: 新增解答题

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