Commit f4920dd0 authored by 晏成浩's avatar 晏成浩

feat: 计时器

parent 0a527cae
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</div> </div>
</div> </div>
<div v-if="isShowContent" class="answer-dialog" @click="$event.stopPropagation()"> <div v-if="isShowContent" class="answer-dialog" @click="$event.stopPropagation()">
<div v-for="(item,idx) in replyList" :key="idx" class="student-as-box" :style="{borderColor:item.answer?'#42b983':'rgba(70, 131, 230, .3)'}"> <div @click="handleShowImg(item)" v-for="(item,idx) in replyList" :key="idx" class="student-as-box" :style="{borderColor:item.answer?'#42b983':'rgba(70, 131, 230, .3)',cursor:'pointer'}">
<img :src="require('@/assets/images/icon-student-avator.png')" alt=""> <img :src="require('@/assets/images/icon-student-avator.png')" alt="">
<div class="info-box"> <div class="info-box">
<p>{{ item.username }}</p> <p>{{ item.username }}</p>
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
<!-- <span></span>--> <!-- <span></span>-->
<!-- 没答案 选择题--> <!-- 没答案 选择题-->
<span v-if="!item.type||item.type!==1">{{ item.answer || '正在答题中' }}</span> <span v-if="!item.type||item.type!==1">{{ item.answer || '正在答题中' }}</span>
<img v-else @click="handleShowImg(item.answer)" :src="item.answer" alt=""> <span v-else>{{ '答案已提交' }}</span>
<!-- <img v-else @click="handleShowImg(item.answer)" :src="item.answer" alt="">-->
</div> </div>
</div> </div>
</div> </div>
...@@ -88,8 +89,8 @@ export default { ...@@ -88,8 +89,8 @@ export default {
console.log('teacher-stop-answer success: ', res); console.log('teacher-stop-answer success: ', res);
}) })
}, },
handleShowImg(imgSrc) { handleShowImg(payload) {
this.imgSrc = imgSrc if (`${payload.type}` === '1') this.imgSrc = payload.answer
}, },
handleImgClick(e) { handleImgClick(e) {
// this.imgSrc = '' // this.imgSrc = ''
......
<!--临时 演示用的计时器-->
<template>
<div class="timer">
<div class="set-time-box">
<el-input-number v-model="setMinutes" :step="1" step-strictly style="margin-right: 10px"></el-input-number>
分
<el-input-number v-model="setSeconds" :step="1" step-strictly style="margin-right: 10px;margin-left: 10px"></el-input-number>
秒
</div>
<div class="content-box">
<div class="minutes-box">{{getNumberWithString(timerMinutes)}}</div>
:
<div class="seconds-box">{{getNumberWithString(timerSecs)}}</div>
</div>
<div class="tool-box">
<el-button type="primary" @click="handleTimerStart" style="margin-right: 15px">开始</el-button>
<el-button type="success" @click="handleTimerFinish" style="margin-left: 15px">结束</el-button>
</div>
</div>
</template>
<script>
export default {
name: 'timer',
data() {
return {
setMinutes: 5,
setSeconds: 0,
// 剩余分钟
timerMinutes: 0,
// 剩余秒数
timerSecs: 0,
// 开始时间,
startTime: null,
// timer
timer: null,
}
},
computed: {
// 定时的秒数
// countSecs(){
// return
// },
},
mounted() {
},
methods: {
handleTimerStart() {
clearInterval(this.timer)
this.timerMinutes = this.setMinutes
this.timerSecs = this.setSeconds
this.startTime = new Date().getTime() / 1000
const countSecs = this.setMinutes * 60 + this.setSeconds
this.timer = setInterval(() => {
// 距离开始过了多少秒
const passSec = new Date().getTime() / 1000 - this.startTime
// 剩余秒数
const rmSec = countSecs - passSec
if (rmSec < 0) {
this.timerMinutes = 0
this.timerSecs = 0
clearInterval(this.timer)
} else {
this.timerMinutes = Math.floor(rmSec / 60)
this.timerSecs = Math.floor(rmSec % 60)
}
},100)
},
handleTimerFinish() {
this.timerMinutes = 0
this.timerSecs = 0
clearInterval(this.timer)
},
// 不足10 则 补0
getNumberWithString(val) {
if (val < 10) return `0${val}`
return val
}
},
beforeDestroy() {
clearInterval(this.timer)
}
}
</script>
<style scoped lang="scss">
.timer {
position: fixed;
top: 10px;
left: 120px;
border-radius: 20px;
background: white;
font-size: 30px;
padding: 15px;
.set-time-box{
display: flex;
font-size: 20px;
align-items: center;
}
.content-box{
margin:20px 0;
display: flex;
justify-content: center;
font-weight: bold;
font-size: 50px;
}
.tool-box{
display: flex;
justify-content: center;
}
}
</style>
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<!-- </div>--> <!-- </div>-->
<!-- </div>--> <!-- </div>-->
<answer-dialog v-if="showAnsModal" :question-img="currentImg" :quick-response="quickResponseData" @question-exit="handleQuestionExit" :reply-list="replyList"/> <answer-dialog v-if="showAnsModal" :question-img="currentImg" :quick-response="quickResponseData" @question-exit="handleQuestionExit" :reply-list="replyList"/>
<timer v-show="isShowTimer" />
</div> </div>
</template> </template>
<script> <script>
...@@ -84,6 +84,7 @@ import { ...@@ -84,6 +84,7 @@ import {
} from '@/assets/images/index' } from '@/assets/images/index'
import HWRTC from '@/utils/hwrtc' import HWRTC from '@/utils/hwrtc'
import socket from '@/utils/socket' import socket from '@/utils/socket'
import Timer from '@/views/paint-screen/components/timer';
import AnswerDialog from './components/answer-dialog' import AnswerDialog from './components/answer-dialog'
const paintTypes = [ const paintTypes = [
...@@ -102,6 +103,7 @@ const paintTypes = [ ...@@ -102,6 +103,7 @@ const paintTypes = [
// { title: '填空题', value: 2 } // 暂时屏蔽简答题 // { title: '填空题', value: 2 } // 暂时屏蔽简答题
] ]
}, },
{ title: 'timer', name: '计时器' },
// { title: 'question-stop', name: '停止答题' }, // { title: 'question-stop', name: '停止答题' },
{ title: 'full', name: '全屏' }, { title: 'full', name: '全屏' },
] ]
...@@ -154,6 +156,7 @@ Vue.use(GeekDrawBoard) ...@@ -154,6 +156,7 @@ Vue.use(GeekDrawBoard)
export default { export default {
components: { components: {
Timer,
AnswerDialog AnswerDialog
}, },
data() { data() {
...@@ -174,7 +177,8 @@ export default { ...@@ -174,7 +177,8 @@ export default {
currentIndex: 0, currentIndex: 0,
ansModal: false, ansModal: false,
showAnsModal: false, showAnsModal: false,
quickResponseData: null quickResponseData: null,
isShowTimer: false,
}; };
}, },
computed: { computed: {
...@@ -201,6 +205,9 @@ export default { ...@@ -201,6 +205,9 @@ export default {
// eslint-disable-next-line no-unused-expressions // eslint-disable-next-line no-unused-expressions
this.$refs.pain_main && this.$refs.pain_main.requestFullscreen(); this.$refs.pain_main && this.$refs.pain_main.requestFullscreen();
} }
if (title === 'timer') {
this.isShowTimer = !this.isShowTimer
}
}, },
handleToolItm(opt) { handleToolItm(opt) {
this.ansModal = false this.ansModal = false
......
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