This commit is contained in:
parent
1cebfe0821
commit
3b42c9d4cd
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue