Commit ca10efb7 authored by Damon's avatar Damon

refactor: 答题卡&&试题详解重构

parent 7f6cb361
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
<view class="card"> <view class="card">
<view slot="head" class="u-flex head"> <view slot="head" class="u-flex head">
<view class="blue"></view> <view class="blue"></view>
<view class="title"> <view class="title">试题详解:</view>
{{ title }}
</view>
</view> </view>
<view class="u-flex content" slot="body"> <view class="u-flex content" slot="body">
<view class="lists">正确答案:{{ answer }}</view> <view class="lists">正确答案:{{ answer }}</view>
...@@ -17,10 +15,6 @@ ...@@ -17,10 +15,6 @@
export default { export default {
name: 'answerSheet', name: 'answerSheet',
props: { props: {
type: {
type: String,
default: 'wrong',
},
answer: { answer: {
type: String, type: String,
default: '', default: '',
...@@ -30,21 +24,12 @@ export default { ...@@ -30,21 +24,12 @@ export default {
default: '', default: '',
}, },
}, },
computed: {
title() {
return '试题详解:'
}
},
data() {
return {
}
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.card { .card {
padding: 20rpx 10rpx 20rpx 5rpx; padding: 20rpx 10rpx 20rpx 5rpx;
border: 2px solid #E8EBF3; border: 2px solid #e8ebf3;
border-radius: 10rpx; border-radius: 10rpx;
.head { .head {
font-size: 32rpx; font-size: 32rpx;
...@@ -53,7 +38,7 @@ export default { ...@@ -53,7 +38,7 @@ export default {
.blue { .blue {
width: 4rpx; width: 4rpx;
height: 34rpx; height: 34rpx;
background: #2953FF; background: #2953ff;
position: relative; position: relative;
left: -8rpx; left: -8rpx;
} }
...@@ -72,7 +57,7 @@ export default { ...@@ -72,7 +57,7 @@ export default {
line-height: 50rpx; line-height: 50rpx;
} }
.lists:nth-of-type(1) { .lists:nth-of-type(1) {
color: #2953FF; color: #2953ff;
} }
} }
} }
......
...@@ -6,11 +6,15 @@ ...@@ -6,11 +6,15 @@
:key="index" :key="index"
@click="select(index)" @click="select(index)"
> >
<view class="icons"> <view v-if="!item.confirm" :class="['icons', {'checked': item.checked}]">
<u-icon name="checkmark-circle" :color="item.checked ? '#409eff' : inherit" size="40"></u-icon> {{ item.sort }}
</view> </view>
<view v-else :class="[rightKey.includes(item.sort) === true ? 'success' : 'error']"></view>
<view class="text">{{ item.text }}</view> <view class="text">{{ item.text }}</view>
</view> </view>
<view class="btn" v-if="rightKey.length > 1">
<view :class="['confirm', {'active': getCheckedNum}]" @click="confirmMultiple">确定</view>
</view>
</view> </view>
</template> </template>
...@@ -26,10 +30,15 @@ export default { ...@@ -26,10 +30,15 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
rightKey: {
type: Array,
default: []
}
}, },
data() { data() {
return { return {
lists: [] lists: [],
submitStatus: false,
} }
}, },
watch: { watch: {
...@@ -38,6 +47,7 @@ export default { ...@@ -38,6 +47,7 @@ export default {
if (newValue.length > 0) { if (newValue.length > 0) {
this.lists = newValue.map((v) => { this.lists = newValue.map((v) => {
v.checked = false v.checked = false
v.confirm = false
return v return v
}) })
} }
...@@ -45,20 +55,39 @@ export default { ...@@ -45,20 +55,39 @@ export default {
immediate:true immediate:true
} }
}, },
created() { computed: {
getCheckedNum() {
const num = this.lists.filter(v => v.checked)
return num.length > 1 ? true : false
}
}, },
methods: { methods: {
select(index) { select(index) {
if (this.submitStatus) return
if (!this.multiple) { if (!this.multiple) {
this.lists.forEach(v => { this.lists.forEach(v => {
v.checked = false v.checked = false // 勾选
v.confirm = false // 确认答案
}) })
this.$set(this.lists[index], 'confirm', true)
} }
this.$set(this.lists[index], 'checked', !this.lists[index].checked) this.$set(this.lists[index], 'checked', !this.lists[index].checked)
if (!this.multiple) this.submitAnswer()
const lists = this.lists.filter(v => v.checked) },
this.$emit('change', lists) // 确认多选答案
confirmMultiple() {
const num = this.lists.filter(v => v.checked)
if (num.length > 1) {
this.lists.forEach(v => {
if(this.rightKey.includes(v.sort)) this.$set(v, 'checked', true)
if(v.checked) this.$set(v, 'confirm', true)
})
this.submitAnswer()
}
},
submitAnswer() {
this.submitStatus = true
this.$emit('change')
} }
}, },
} }
...@@ -70,11 +99,69 @@ export default { ...@@ -70,11 +99,69 @@ export default {
padding: 10rpx 0; padding: 10rpx 0;
width: 100%; width: 100%;
.icons { .icons {
padding: 5rpx 20rpx 0rpx 0; font-size: 28rpx;
color: #191C27;
border: 2rpx solid #9EA5BB;
text-align: center;
width: 40rpx;
height: 40rpx;
line-height: 40rpx;
border-radius: 10rpx;
}
.checked {
background: #2953FF;
border: 2rpx solid #2953FF;
color: #fff;
}
.success {
width: 40rpx;
height: 40rpx;
line-height: 40rpx;
border-radius: 10rpx;
background: #2953FF;
border: 2rpx solid #2953FF;
text-align: center;
}
.success:before {
content: '\2714';
color: #fff;
}
.error {
width: 40rpx;
height: 40rpx;
line-height: 40rpx;
border-radius: 10rpx;
background: #FA5A49;
border: 2rpx solid #FA5A49;
text-align: center;
}
.error:before {
content: '\2716';
color: #fff;
} }
.text { .text {
padding-left: 20rpx;
flex: 1; flex: 1;
} }
} }
.btn {
text-align: center;
margin-top: 50rpx;
.confirm {
width: 400rpx;
height: 100rpx;
line-height: 100rpx;
background: #D4D7DF;
color: #fff;
border-radius: 50rpx;
font-size: 32rpx;
font-weight: bold;
text-align: center;
}
.active {
background: #2953FF;
}
}
} }
</style> </style>
...@@ -13,14 +13,13 @@ ...@@ -13,14 +13,13 @@
<view class="title">{{ item.title }}</view> <view class="title">{{ item.title }}</view>
<view class="content"> <view class="content">
<answer-sheet <answer-sheet
ref="answerSheet"
:answerList="item.answerList" :answerList="item.answerList"
:rightKey="item.rightKey"
:multiple="item.type === 3" :multiple="item.type === 3"
@change="answerChange" @change="answerChange"
></answer-sheet> ></answer-sheet>
</view> </view>
<view class="btn" v-if="item.type === 3">
<u-button type="primary" size="medium" shape="circle">确定</u-button>
</view>
<view class="explain"> <view class="explain">
<answer-explanation :answer="item.answer" :explain="item.explain"></answer-explanation> <answer-explanation :answer="item.answer" :explain="item.explain"></answer-explanation>
</view> </view>
...@@ -115,7 +114,11 @@ export default { ...@@ -115,7 +114,11 @@ export default {
this.swiperCurrent = current this.swiperCurrent = current
}, },
answerChange(e) { answerChange(e) {
this.swiperCurrent = this.swiperCurrent + 1 // this.swiperCurrent = this.swiperCurrent + 1
this.$emit("answerChange", e)
},
confirmMultiple(index) {
this.$refs.answerSheet[index].confirmMultiple()
}, },
clear () { clear () {
this.list = [] this.list = []
...@@ -234,26 +237,12 @@ export default { ...@@ -234,26 +237,12 @@ export default {
font-size: 32rpx; font-size: 32rpx;
line-height: 50rpx; line-height: 50rpx;
font-weight: bold; font-weight: bold;
width: 100%;
text-align: left;
} }
.content, .explain, .btn { .content, .explain, .btn {
/deep/ .u-card {
background: transparent;
}
width: 100%; width: 100%;
padding-top: 50rpx; padding-top: 50rpx;
} }
.btn {
text-align: center;
/deep/ button {
width: 260rpx;
height: 80rpx;
}
}
.disabled {
/deep/ button {
background: #D4D7DF;
color: #fff;
}
}
} }
</style> </style>
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
:swiperDuration="swiperDuration" :swiperDuration="swiperDuration"
:list="list" :list="list"
:current="current" :current="current"
@answerChange="answerChange"
@change="swiperChange"> @change="swiperChange">
</swiper-limited-load> </swiper-limited-load>
</view> </view>
...@@ -26,37 +27,37 @@ ...@@ -26,37 +27,37 @@
</view> </view>
</view> </view>
<view class="u-flex"> <view class="u-flex">
<view class="c-list "> <view class="c-list" v-if="type === 1">
<u-icon name="close-circle" color="#FA5A49" size="40"></u-icon>
<text>0</text>
</view>
<view class="c-list u-padding-left-30">
<u-icon name="checkmark-circle" color="#2953FF" size="40"></u-icon>
<text>0</text>
</view>
</view>
<view class="u-flex">
<view class="c-list">
<u-icon name="star" color="#5A6073" size="40"></u-icon> <u-icon name="star" color="#5A6073" size="40"></u-icon>
<text>收藏</text> <text>收藏</text>
</view> </view>
<view class="c-list" v-else>
<u-icon name="file-text" color="#5A6073" size="40"></u-icon>
<text>交卷</text>
</view> </view>
</view> </view>
</view> </view>
<answer-operation-tips :show.sync="show" />
</view>
</template> </template>
<script> <script>
import swiperLimitedLoad from '@/components/swiper-limited-load/index.vue' import swiperLimitedLoad from '@/components/swiper-limited-load/index.vue'
import answerOperationTips from '@/components/answer-operation-tips/index.vue'
const NO_PREV_PAGE = -1 const NO_PREV_PAGE = -1
const NO_NEXT_PAGE = -2 const NO_NEXT_PAGE = -2
const app = getApp() const app = getApp()
export default { export default {
components: { components: {
swiperLimitedLoad, swiperLimitedLoad,
answerOperationTips
}, },
data() { data() {
return { return {
type: ['单选题', '判断题', '多选题'], show: false,
type: 1,
dataLength: 0, dataLength: 0,
index: 0, index: 0,
lists: [], lists: [],
...@@ -76,51 +77,62 @@ export default { ...@@ -76,51 +77,62 @@ export default {
title: '采用QS1电桥测量tanδ的接线方式一般有差接线及和接线。', title: '采用QS1电桥测量tanδ的接线方式一般有差接线及和接线。',
answerList: [ answerList: [
{ {
text: 'A:正确', sort: 'A',
text: '正确',
}, },
{ {
text: 'B:错误', sort: 'B',
text: '错误',
}, },
], ],
answer: 'A', answer: 'A',
explain: '极性电介质在外电场作用下,由偶极子分子的转向形成的极化称为偶极子式极化。', explain: '极性电介质在外电场作用下,由偶极子分子的转向形成的极化称为偶极子式极化。',
index: 0 index: 0,
rightKey: ['A']
}, },
{ {
type: 2, type: 2,
title: '空气间隙的操作冲击击穿电压数值大小不仅与间隙距离、电极形状、电极极性有关,而且与操作冲击电压波的波前时间的长短有关。', title: '空气间隙的操作冲击击穿电压数值大小不仅与间隙距离、电极形状、电极极性有关,而且与操作冲击电压波的波前时间的长短有关。',
answerList: [ answerList: [
{ {
text: 'A:正确', sort: 'A',
text: '正确',
}, },
{ {
text: 'B:错误', sort: 'B',
text: '错误',
}, },
], ],
answer: 'B', answer: 'B',
explain: '极性电介质在外电场作用下,由偶极子分子的转向形成的极化称为偶极子式极化。', explain: '极性电介质在外电场作用下,由偶极子分子的转向形成的极化称为偶极子式极化。',
index: 1 index: 1,
rightKey: ['B']
}, },
{ {
type: 3, type: 3,
title: '西林电桥采用正接线及反接线时,其测试原理相同', title: '西林电桥采用正接线及反接线时,其测试原理相同',
answerList: [ answerList: [
{ {
text: 'A:影响', sort: 'A',
text: '影响',
}, },
{ {
text: 'B:影响很小', sort: 'B',
text: '影响很小',
}, },
{ {
text: 'C:影响很大', sort: 'C',
text: '影响很大',
}, },
{ {
text: 'D:无影响', sort: 'D',
text: '无影响',
}, },
], ],
answer: 'B,C', answer: 'B,C',
explain: '双臂电桥是在单臂电桥的基础上增加特殊机构,以消除测试时连接线和接线柱接触电阻对测量结果的影响。', explain: '双臂电桥是在单臂电桥的基础上增加特殊机构,以消除测试时连接线和接线柱接触电阻对测量结果的影响。',
index: 2 index: 2,
rightKey: ['B','C']
} }
] ]
...@@ -159,6 +171,9 @@ export default { ...@@ -159,6 +171,9 @@ export default {
}) })
return return
} }
},
answerChange(e) {
console.log("e", e)
} }
}, },
} }
...@@ -174,41 +189,6 @@ export default { ...@@ -174,41 +189,6 @@ export default {
.swiper { .swiper {
width: 100%; width: 100%;
flex: 1; flex: 1;
.subject {
flex-flow: column;
padding: 20rpx;
.type {
width: 100%;
text-align: left;
padding: 20rpx 0;
}
.title {
color: #191C27;
font-size: 32rpx;
line-height: 50rpx;
font-weight: bold;
}
.content, .explain, .btn {
/deep/ .u-card {
background: transparent;
}
width: 100%;
padding-top: 50rpx;
}
.btn {
text-align: center;
/deep/ button {
width: 260rpx;
height: 80rpx;
}
}
.disabled {
/deep/ button {
background: #D4D7DF;
color: #fff;
}
}
}
} }
.bottom { .bottom {
width: 100%; width: 100%;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment