You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

337 lines
10 KiB

<template>
<div class="box">
<h1 class="title">{{paperName}}</h1>
<div class="metas">
<div style="margin-right: 20px;">
<span class="name">总分</span>
<span class="val">100</span>
</div>
<div v-if="totalDuration !== ''">
<span class="name">考试时长:</span>
<span class="val">{{totalDuration}}分钟</span>
</div>
</div>
<ul class="tab">
<template v-for="(item,index) in tabs">
<li v-if="item.show" :key="index" :class="{active: active == item.id}" @click="tabChange(item.id)">{{item.name}}</li>
</template>
</ul>
<div class="wrap">
<div class="item" v-for="(item,index) in curType" :key="index">
<div class="answer">
<div class="info">
<p class="key">序号:</p>
<p class="val">{{index+1}}</p>
</div>
</div>
<div class="meta">
<p class="key">题干:</p>
<p class="val" v-html="item.questionStem"></p>
<div class="media" :id="item.mediaEleId"></div>
</div>
<template v-if="active != 5">
<div class="meta" v-if="active != 3">
<p class="key">选项:</p>
<div class="val">
<p v-for="(option,i) in item.options" :key="i">{{i}}.{{item.options[i]}}</p>
</div>
</div>
<div class="meta ans">
<div class="info">
<p class="key">正确答案</p>
<p class="val">{{item.answer}}</p>
</div>
</div>
</template>
<div class="meta">
<p class="key">答案解析</p>
<p class="val" v-html="item.answerAnalysis"></p>
</div>
</div>
</div>
</div>
</template>
<script>
import mixins from '@/mixins/setBackground'
import { mapState } from 'vuex'
export default {
props: ['data'],
mixins: [ mixins ],
data() {
return {
assPaperName: '',
assTotalDuration: 0,
selectVisible: false,
tabs: [
{
id: 1,
name: '单选题',
show: false
},{
id: 2,
name: '多选题',
show: false
},{
id: 3,
name: '填空题',
show: false
},{
id: 4,
name: '判断题',
show: false
},{
id: 5,
name: '简答题',
show: false
}
],
active: 1,
allData: {},
curType: [],
};
},
computed: {
...mapState('user', [
'userId'
]),
...mapState('testpaper', [
'id','paperName','totalDuration'
])
},
mounted() {
this.insertScript()
this.getData()
},
methods: {
getData() {
if(this.data){
this.initData(this.data)
}else{
this.$post(`${this.api.previewtestPaper}?id=${this.id}`)
.then(res => {
this.initData(res.data)
}).catch(err => {})
}
},
initData(data){
let index = 0
for(let i in data){
data[i].map((n,j) => {
index++
n.mediaEleId = `player${index}`
if(i == 'list3'){
let answer = []
for(let j in n){
if(j.includes('option') && n[j]){
answer.push(n[j])
}
}
n.answer = answer.join('|')
}
})
}
this.allData = data
let tabs = this.tabs
data.list1.length && (tabs[0].show = true)
data.list2.length && (tabs[1].show = true)
data.list3.length && (tabs[2].show = true)
data.list4.length && (tabs[3].show = true)
data.list5.length && (tabs[4].show = true)
for(let n of tabs){
if(n.show){
this.active = n.id
this.curType = this.allData[`list${n.id}`]
break
}
}
this.handleOptions()
},
initMedia(item){
if(item.videoAudio && !item.player){
this.$get(`${this.api.getPlayAuth}/${item.videoAudio}`).then(res => {
let playAuth = res.data.playAuth
this.$nextTick(() => {
item.player = new Aliplayer({
id: item.mediaEleId,
width: '100%',
autoplay: false,
vid : item.videoAudio,
playauth : playAuth,
encryptType:1, //当播放私有加密流时需要设置。
})
})
}).catch(res => {})
}
},
tabChange(id){
this.active = id
this.curType = this.allData[`list${id}`]
this.handleOptions()
},
handleOptions(){
let curType = this.curType
curType.forEach(n => {
this.initMedia(n)
if(!n.options){
let options = {}
for(let i in n){
if(i.includes('option') && n[i]){
options[i.replace('option','')] = n[i]
}
}
n.options = options
}
})
this.curType = curType
},
insertScript(){
const linkTag = document.createElement('link')
linkTag.id = 'aliplayerLink'
linkTag.rel = 'stylesheet'
linkTag.href = 'https://g.alicdn.com/de/prismplayer/2.8.2/skins/default/aliplayer-min.css'
document.body.appendChild(linkTag)
const scriptTag = document.createElement('script')
scriptTag.id = 'aliplayerScript'
scriptTag.type = 'text/javascript'
scriptTag.src = 'https://g.alicdn.com/de/prismplayer/2.8.2/aliplayer-min.js'
document.body.appendChild(scriptTag)
this.$once('hook:beforeDestroy', function () {
document.body.removeChild(document.querySelector('#aliplayerLink'))
document.body.removeChild(document.querySelector('#aliplayerScript'))
})
},
},
};
</script>
<style lang="scss" scoped>
.box{
width: 90%;
margin: 0 auto;
}
.title{
text-align: center;
font-size: 18px;
font-weight: 600;
}
.metas{
display: flex;
justify-content: center;
margin: 20px 0 30px;
.name{
font-size: 12px;
color: #717171;
}
.val{
font-size: 12px;
color: #929292;
}
}
.tab{
display: flex;
align-items: center;
margin-bottom: 10px;
li{
position: relative;
padding: 0 44px;
margin-right: 7px;
font-size: 13px;
line-height: 46px;
text-align: center;
color: #444;
border: 1px solid #ececec;
cursor: pointer;
&:hover{
opacity: .8;
}
&.active:after{
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 4px;
background-color: $main-color;
}
}
}
.wrap{
.item{
padding-bottom: 30px;
margin-bottom: 30px;
border-bottom: 1px dashed #f4f4f4;
.key{
font-weight: bold;
color: #333;
font-size: 14px;
}
.val{
line-height: 1.6;
color: #757575;
font-size: 14px;
}
.answer{
display: flex;
align-items: center;
padding: 15px;
margin: 15px 0;
font-size: 12px;
border: 1px solid #e8e8e8;
background-color: #f3f2f2;
.info{
display: inline-flex;
align-items: center;
margin-right: 30px;
}
}
.meta{
padding-left: 10px;
margin: 20px 0;
font-size: 12px;
&.ans{
display: flex;
align-items: center;
.info{
margin-right: 20px;
}
}
.key{
margin-bottom: 5px;
}
.media{
margin-top: 10px;
}
}
}
}
.btns{
display: flex;
justify-content: center;
margin-top: 20px;
button{
height: 30px;
padding: 0 30px;
margin: 0 15px;
font-size: 14px;
color: #333;
line-height: 30px;
background-color: #fff;
border: 1px solid #ededed;
border-radius: 4px;
cursor: pointer;
&.submit{
color: #fff;
background-color: $main-color;
border-color: $main-color;
}
&:hover{
opacity: .8;
}
}
}
</style>