This commit is contained in:
binbin_pan 2024-11-26 18:32:28 +08:00
parent 1cebfe0821
commit 3b42c9d4cd
3 changed files with 109 additions and 119 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<view> <view>
<u-navbar leftIcon="" title="考试" :placeholder="true" /> <u-navbar leftIcon="" title="考试" :placeholder="true" />
<div class="content"> <div class="content" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">
<div class="top-content"> <div class="top-content">
<div class="top-wrapper"> <div class="top-wrapper">
<div class="time"> <div class="time">
@ -172,7 +172,9 @@ export default {
score: 0, score: 0,
passScore: 0, passScore: 0,
isHide: false, isHide: false,
failCount: 3 failCount: 3,
startX: 0, // X
endX: 0 // X
} }
}, },
onLoad(opt) { onLoad(opt) {
@ -581,6 +583,37 @@ export default {
console.log(err) console.log(err)
} }
}) })
},
touchStart(event) {
this.startX = 0
this.endX = 0
console.log('🚀 ~ 开始 ~ event:', event)
//
this.startX = event.touches[0].clientX
console.log('🚀 ~ touchStart ~ this.startX:', this.startX)
},
touchMove(event) {
console.log('🚀 ~ 移动 ~ event:', event)
//
this.endX = event.touches[0].clientX
console.log('🚀 ~ touchMove ~ this.endX:', this.endX)
},
touchEnd() {
//
if (this.startX != 0 && this.endX != 0 && this.startX - this.endX > 10) {
//
console.log('向左滑动')
this.currentIndex++
} else if (this.startX != 0 && this.endX != 0 && this.endX - this.startX > 10) {
//
console.log('向右滑动')
this.currentIndex--
}
if (this.currentIndex < 0) {
this.currentIndex = 0
} else if (this.currentIndex > this.questionList.length - 1) {
this.currentIndex = this.questionList.length - 1
}
} }
}, },
onBackPress(options) { onBackPress(options) {
@ -600,7 +633,8 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.content { .content {
padding: 10px; width: 100vw;
height: 90vh;
.top-content { .top-content {
background: #fff; background: #fff;
@ -664,6 +698,7 @@ export default {
} }
.question-wrapper { .question-wrapper {
padding: 10px;
.question-type-wrapper { .question-type-wrapper {
margin: 20px 0; margin: 20px 0;
display: flex; display: flex;

View File

@ -60,8 +60,6 @@ export default {
video: null, video: null,
isHide: false, isHide: false,
oldTime: 0, oldTime: 0,
random1: 0,
random2: 0,
// //
failCount: 3 failCount: 3
} }
@ -79,8 +77,6 @@ export default {
console.log('🚀 ~ onLoad ~ this.path:', this.path) console.log('🚀 ~ onLoad ~ this.path:', this.path)
this.studyDuration = this.currentTime = Number(opt.studyDuration) this.studyDuration = this.currentTime = Number(opt.studyDuration)
this.allStudyDuration = Number(opt.allStudyDuration) this.allStudyDuration = Number(opt.allStudyDuration)
this.random1 = ((this.allStudyDuration / 3) * 2).toFixed(0)
this.random2 = (this.allStudyDuration / 3).toFixed(0)
this.isEnd = opt.isEnd this.isEnd = opt.isEnd
if (opt.isEnd) { if (opt.isEnd) {
this.studyDuration = 0 this.studyDuration = 0
@ -108,18 +104,16 @@ export default {
}, },
// //
videoTimeUpdate(e) { videoTimeUpdate(e) {
this.currentTime = Math.ceil(e.detail.currentTime) let newTime = Math.ceil(e.detail.currentTime)
console.log('🚀 ~ 视频播放时间: ~ this.currentTime:', this.currentTime) if (this.currentTime != newTime) {
console.log('🚀 ~ 视频总时长: ~ this.allStudyDuration:', this.allStudyDuration) this.currentTime = newTime
console.log('🚀 ~ videoTimeUpdate ~ random1-2:', this.random1, this.random2) console.log('🚀 ~ 视频播放时间: ~ this.currentTime:', this.currentTime)
// 10
// if (this.currentTime != this.oldTime) { if (this.currentTime % 10 == 0) {
// if (this.currentTime == this.random2 || this.currentTime == this.random1) { console.log('学习时长:', this.currentTime)
// this.oldTime = this.currentTime // , , , this.updStudyDuration()
// this.video.pause() }
// this.openPhotograph() }
// }
// }
}, },
openModal() { openModal() {
this.showModal = true this.showModal = true
@ -164,11 +158,7 @@ export default {
studyPercentage: this.studyPercentage studyPercentage: this.studyPercentage
} }
console.log('🚀 ~ handleEnd ~ params:', params) console.log('🚀 ~ handleEnd ~ params:', params)
// updStudyDuration(params).then(res => {
// console.log('🚀 ~ handleEnd ~ res:', res)
// this.showModal = false
// uni.navigateBack()
// })
this.$verificationToken() this.$verificationToken()
uni.request({ uni.request({
url: config.baseUrl + '/exam-student/student/updStudyDuration', url: config.baseUrl + '/exam-student/student/updStudyDuration',
@ -193,106 +183,45 @@ export default {
} }
}) })
}, },
// //
openPhotograph() { updStudyDuration() {
this.isHide = true // -
setTimeout(() => { console.log('当前播放时间:', this.currentTime, this.allStudyDuration)
uni.chooseImage({ this.studyDuration = this.currentTime
count: 1, //
sizeType: ['compressed'], this.studyPercentage =
sourceType: ['camera'], Math.ceil((this.studyDuration / this.allStudyDuration) * 100).toFixed(2) > 100
success: res => { ? 100
let url = '' : Math.ceil((this.studyDuration / this.allStudyDuration) * 100).toFixed(2)
console.log('🚀 ~ res-拍照:', res) console.log('🚀 ~ handleEnd ~ this.studyPercentage:', this.studyPercentage)
this.imgToBase64(res.tempFilePaths[0]).then(base64 => {
url = base64 const params = {
console.log('🚀 ~ this.imgToBase64 ~ base64:', url) userId: uni.getStorageSync('userId'),
this.getFaceRecognition({ userId: uni.getStorageSync('userId'), img: url }) studyId: this.studyId,
}) stageId: this.stageId,
}, stageContentId: this.stageContentId,
fail(err) { stageType: this.stageType,
console.log('🚀 ~ openFaceScan ~ 人脸识别失败', err) studyCourseId: this.studyCourseId,
uni.showToast({ sourceId: this.sourceId,
title: '人脸识别失败', studyDuration: this.studyDuration,
icon: '' studyPercentage: this.studyPercentage
}) }
setTimeout(() => { console.log('🚀 ~ handleEnd ~ params:', params)
this.handleEnd()
}, 1000)
}
})
}, 100)
},
imgToBase64(data) {
return new Promise((resolve, reject) => {
pathToBase64(data)
.then(base64 => {
resolve(base64)
})
.catch(error => {
console.error(error)
reject(error)
})
})
},
//
getFaceRecognition(params) {
console.log('🚀 ~ getFaceRecognition ~ params:', params)
this.$verificationToken() this.$verificationToken()
uni.request({ uni.request({
url: config.baseUrl + '/exam-student/personalCenter/getFaceRecognition', url: config.baseUrl + '/exam-student/student/updStudyDuration',
method: 'POST', method: 'post',
data: params,
header: { header: {
'content-type': 'application/json', 'Content-Type': 'application/x-www-form-urlencoded',
Authorization: uni.getStorageSync('access_token') Authorization: uni.getStorageSync('access_token')
}, },
data: params,
success: res => { success: res => {
console.log('🚀 ~ openFaceScan ~ res-人脸识别:', res) console.log('🚀 ~ handleEnd ~ res:', res)
res = res.data
console.log('🚀 ~ openFaceScan ~ res-人脸识别:', res.code)
if (res.code == 200) {
//
uni.showToast({
title: '人脸识别成功',
icon: '',
duration: 1500
})
this.failCount = 3 //
this.isHide = false
this.video.play()
} else {
this.failCount--
if (this.failCount == 0) {
uni.showToast({
title: '人脸识别失败, 即将结束学习',
icon: 'none',
duration: 1500
})
setTimeout(() => {
this.handleEnd()
}, 1500)
} else {
uni.showToast({
title: '人脸识别失败, 请重新录入, 剩余次数: ' + this.failCount + '次',
icon: 'none',
duration: 1500
})
setTimeout(() => {
this.openPhotograph()
}, 1500)
}
}
}, },
fail(err) { fail: err => {
console.log('🚀 ~ openFaceScan ~ 人脸识别失败', err) console.log('🚀 ~ handleEnd ~ err:', err)
uni.showToast({
title: '人脸识别失败',
icon: ''
})
setTimeout(() => {
this.handleEnd()
}, 1000)
} }
}) })
} }

View File

@ -16,7 +16,7 @@
</div> </div>
</div> </div>
<div class="question-wrapper" v-for="(item, index) in questionList" :key="index"> <div class="question-wrapper" v-for="(item, index) in questionList" :key="index" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd">
<div v-if="item.examType != 2"> <div v-if="item.examType != 2">
<div class="title">{{ nowNum }}.{{ item.paperTopic }}{{ item.examType == 1 ? '(单选题)' : '(判断题)' }}</div> <div class="title">{{ nowNum }}.{{ item.paperTopic }}{{ item.examType == 1 ? '(单选题)' : '(判断题)' }}</div>
<u--image <u--image
@ -831,6 +831,32 @@ export default {
console.log(err) console.log(err)
} }
}) })
},
touchStart(event) {
this.startX = 0
this.endX = 0
console.log('🚀 ~ 开始 ~ event:', event)
//
this.startX = event.touches[0].clientX
console.log('🚀 ~ touchStart ~ this.startX:', this.startX)
},
touchMove(event) {
console.log('🚀 ~ 移动 ~ event:', event)
//
this.endX = event.touches[0].clientX
console.log('🚀 ~ touchMove ~ this.endX:', this.endX)
},
touchEnd() {
//
if (this.startX != 0 && this.endX != 0 && this.startX - this.endX > 10) {
//
console.log('向左滑动')
this.handleJump('next')
} else if (this.startX != 0 && this.endX != 0 && this.endX - this.startX > 10) {
//
console.log('向右滑动')
this.handleJump('prev')
}
} }
}, },
onBackPress(options) { onBackPress(options) {
@ -949,7 +975,7 @@ export default {
} }
.question-wrapper { .question-wrapper {
max-height: 500px; height: 500px;
overflow: auto; overflow: auto;
padding: 30px; padding: 30px;
color: #08428d; color: #08428d;