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>
<view>
<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-wrapper">
<div class="time">
@ -172,7 +172,9 @@ export default {
score: 0,
passScore: 0,
isHide: false,
failCount: 3
failCount: 3,
startX: 0, // X
endX: 0 // X
}
},
onLoad(opt) {
@ -581,6 +583,37 @@ export default {
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) {
@ -600,7 +633,8 @@ export default {
<style lang="scss" scoped>
.content {
padding: 10px;
width: 100vw;
height: 90vh;
.top-content {
background: #fff;
@ -664,6 +698,7 @@ export default {
}
.question-wrapper {
padding: 10px;
.question-type-wrapper {
margin: 20px 0;
display: flex;

View File

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

View File

@ -16,7 +16,7 @@
</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 class="title">{{ nowNum }}.{{ item.paperTopic }}{{ item.examType == 1 ? '(单选题)' : '(判断题)' }}</div>
<u--image
@ -831,6 +831,32 @@ export default {
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) {
@ -949,7 +975,7 @@ export default {
}
.question-wrapper {
max-height: 500px;
height: 500px;
overflow: auto;
padding: 30px;
color: #08428d;