123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- <template>
- <view>
-
- <view class="content1">
- <view class="hand-bar">
- <view class="timer-col">
- <uni-countdown v-if="timerFlag" :show-day="false" :hour="countHour" :minute="countMin"
- :second="countSec" @timeup="doHandler()"></uni-countdown>
- </view>
- <view class="hand-col">
- <button type="warn" @click="handHandExam(0)">交卷</button>
- </view>
- </view>
- <view v-if="paperData.actionOn && paperData.actionInterval>0" style="margin-top: -15px;">
- <action-checker :action-on="paperData.actionOn" :action-interval="paperData.actionInterval"
- :trigger="actionTrigger" @break="doHandler(3)" />
- </view>
- <!-- 导入组件 -->
- <view style="margin-bottom: 80px;">
- <exam-qu-item v-model="quData" @rest="handleRest" />
- </view>
- </view>
- <view class="bottom-bar">
- <uni-row :gutter="20">
- <uni-col :span="8">
- <button @click="handleNext(-1)" :disabled="!showPrevious">上题</button>
- </uni-col>
- <uni-col :span="8">
- <button @click="handleNext(1)" :disabled="!showNext">下题</button>
- </uni-col>
- <uni-col :span="8">
- <button type="primary" @click="showCard()">答题卡</button>
- </uni-col>
- </uni-row>
- </view>
- <uni-drawer ref="cardDrawer">
- <scroll-view scroll-y="true" class="scroll-y">
- <view>
- <view>
- <view class="card-title">答题卡</view>
- <view class="card-context">
- <view class="card-num card-com">未作答</view>
- <view class="card-num card-com right">已作答</view>
- </view>
- <view v-for="type in paperData.groupList">
- <view class="card-title">{{ type.quType_dictText }}</view>
- <view class="card-context">
- <view v-for="item in type.quList"
- :class="{'card-num ': true, 'current': item.quId === cardItem.quId, 'answered': item.answered}"
- @click="fetchQuData(item)">
- {{ item.sort}}
- </view>
- </view>
- </view>
- </view>
- </view>
- </scroll-view>
- </uni-drawer>
- <!-- 页面离开检测 -->
- <leave-checker v-if="paperData.leaveOn && paperData.leaveCount>0" :pageShow="pageShow"
- :leave-on="paperData.leaveOn" :leave-check="paperData.leaveCheck" :leave-count="paperData.leaveCount"
- :paper-id="paperData.id" @break="doHandler(2)" />
- </view>
- </template>
- <script>
- import {
- paperDetail,
- paperQuDetail,
- handExam
- } from '@/api/exam.js'
- import ExamQuItem from "./components/ExamQuItem.vue"
- import ActionChecker from "./components/ActionChecker.vue"
- import LeaveChecker from "./components/LeaveChecker.vue"
- import CamVideo from '../video/video.vue'
- export default {
- components: {
- ExamQuItem,
- ActionChecker,
- LeaveChecker
- },
- data() {
- return {
- // 全屏/不全屏
- showPrevious: false,
- showNext: true,
- cardShow: false,
- // 试卷ID
- paperId: '',
- // 当前答题卡
- cardItem: {},
- allItem: [],
- // 当前题目内容
- quData: {
- answerList: []
- },
- // 试卷信息
- paperData: {
- leftSeconds: 99999,
- radioList: [],
- multiList: [],
- judgeList: [],
- saqList: []
- },
- // 单选选定值
- radioValue: '',
- // 简答题值
- saqValue: '',
- // 多选选定值
- multiValue: [],
- // 已答ID
- answeredIds: [],
- timerFlag: false,
- countHour: 0,
- countMin: 0,
- countSec: 0,
- // 动作检测
- actionTrigger: 0,
- // 页面显示
- pageShow: true
- }
- },
- onHide: function() {
- // 程序隐藏
- this.pageShow = false
- },
- onShow: function() {
- console.log('显示了...')
- this.pageShow = true
- },
- onLoad: function(option) {
- this.paperId = option.id;
- this.fetchData(this.paperId);
- },
- mounted() {
- // #ifdef H5
- var a = document.getElementsByClassName('uni-page-head-hd')[0]
- a.style.display = 'none'
- // #endif
- },
- methods: {
- textBlur(e) {
- this.saqValue = e;
- },
- showCard() {
- // 触发变化
- this.actionTrigger = new Date().getTime()
- this.$refs.cardDrawer.open()
- },
- closeCard() {
- // 触发变化
- this.actionTrigger = new Date().getTime()
- this.cardShow = false
- },
- // 倒计时
- countdown() {
- // 剩余秒数
- const leftSeconds = this.paperData.leftSeconds
- // 转换时分
- this.countHour = parseInt(leftSeconds / 60 / 60)
- this.countMin = parseInt(leftSeconds / 60 % 60)
- this.countSec = parseInt(leftSeconds % 60)
- // 开始计时
- this.timerFlag = true
- },
- // 填充已答标签
- handleRest(fill) {
- this.cardItem.answered = fill
- this.actionTrigger = new Date().getTime()
- },
- // 答题卡样式
- cardItemClass(answered, quId) {
- if (quId === this.cardItem.quId) {
- return 'warning'
- }
- if (answered) {
- return 'success'
- }
- if (!answered) {
- return 'info'
- }
- },
- /**
- * 统计有多少题没答的
- * @returns {number}
- */
- countNotAnswered() {
- let notAnswered = 0
- // 判断全部未答
- this.paperData.groupList.forEach(function(item) {
- item.quList.forEach(function(qu) {
- if (!qu.answered) {
- notAnswered += 1
- }
- })
- })
- return notAnswered
- },
- // 上一题下一题
- handleNext(num) {
- let index = 0
- for (let i = 0; i < this.allItem.length; i++) {
- if (this.allItem[i].id === this.quData.id) {
- index = i
- }
- }
- index += num
- this.fetchQuData(this.allItem[index])
- },
- doHandler(flag) {
- // 打开
- uni.showLoading({
- title: '阅卷中...'
- });
- const params = {
- id: this.paperId,
- handFlag: flag
- }
- handExam(params).then(() => {
- uni.showToast({
- title: '交卷成功!',
- icon: 'none',
- duration: 2000
- });
- // 查看考试详情
- uni.redirectTo({
- url: '/pages/paper/detail?id=' + this.paperId
- });
- uni.hideLoading()
- })
- },
- // 交卷操作
- handHandExam() {
- const that = this
- const notAnswered = that.countNotAnswered()
- let msg = '确认要交卷吗?'
- if (notAnswered > 0) {
- msg = '您还有' + notAnswered + '题未作答,确认要交卷吗?'
- }
- uni.showModal({
- title: '提示',
- content: msg,
- success: function(res) {
- if (res.confirm) {
- that.doHandler(0)
- }
- }
- });
- },
- // 更新上下一题索引
- refreshIndex(item) {
- if (item.id === this.allItem[0].id) {
- this.showPrevious = false
- } else {
- this.showPrevious = true
- }
- // 最后一个索引
- const last = this.allItem.length - 1
- if (item.id === this.allItem[last].id) {
- this.showNext = false
- } else {
- this.showNext = true
- }
- },
- // 试卷详情
- fetchQuData(item) {
- // 打开
- uni.showLoading({
- title: '加载中...'
- });
- // 刷新索引
- this.refreshIndex(item)
- // 获得详情
- this.cardItem = item
- paperQuDetail(this.paperId, item.quId).then(data => {
- this.quData = data
- // 关闭详情
- uni.hideLoading()
- // 切换题目后滑动到顶部
- uni.pageScrollTo({
- duration: 500,
- scrollTop: 0
- })
- }).catch(err => {
- console.log(err)
- // 试题被删除
- if (err.code === 20010001) {
- setTimeout(() => {
- uni.switchTab({
- url: '/pages/exam/index'
- });
- }, 1500)
- }
- })
- // 触发变化
- this.actionTrigger = new Date().getTime()
- },
- // 试卷详情
- fetchData(id) {
- // 打开
- uni.showLoading({
- title: '加载中...'
- });
- paperDetail(id).then(data => {
- // 试卷内容
- this.paperData = data
- // 已经考完了,不允许
- if (this.paperData.state !== 0) {
- this.$router.push({
- name: 'ShowExam',
- params: {
- id: this.paperData.id
- }
- })
- }
- const that = this
- // 展开全部题目
- this.paperData.groupList.forEach(function(item) {
- item.quList.forEach(function(qu) {
- that.allItem.push(qu)
- })
- })
- if (!that.allItem || that.allItem.length == 0) {
- uni.showModal({
- title: '试卷内容出现问题,无法继续考试!',
- content: msg,
- success: function(res) {
- if (res.confirm) {
- }
- }
- });
- return
- }
- this.cardItem = that.allItem[0]
- // 当前选定
- this.fetchQuData(this.cardItem)
- // 倒计时
- this.countdown()
- })
- }
- }
- }
- </script>
- <style>
- .content1 {
- padding: 15px;
- padding-bottom: 60px;
- }
- </style>
|