学习任务-防作弊

This commit is contained in:
binbin_pan 2024-09-13 20:39:58 +08:00
parent 7586f432cc
commit 3592ca50a4
3 changed files with 349 additions and 30 deletions

View File

@ -29,6 +29,7 @@
<script> <script>
import config from '@/config' import config from '@/config'
import { pathToBase64, base64ToPath } from 'image-tools'
import { updStudyDuration } from '@/api/eduApp' import { updStudyDuration } from '@/api/eduApp'
export default { export default {
@ -55,7 +56,10 @@ export default {
currentTime: 0, currentTime: 0,
showModal: false, // showModal: false, //
content: '是否确认结束学习?', content: '是否确认结束学习?',
isEnd: false isEnd: false,
video: null,
isHide: false,
oldTime: 0
} }
}, },
onLoad(opt) { onLoad(opt) {
@ -75,17 +79,18 @@ export default {
if (opt.isEnd) { if (opt.isEnd) {
this.studyDuration = 0 this.studyDuration = 0
} }
this.video = uni.createVideoContext('myVideo')
}, },
onHide() { onHide() {
console.log('🚀 ~ onHide ~ 页面隐藏') console.log('🚀 ~ onHide ~ 页面隐藏')
if (!this.isEnd) { if (!this.isEnd && !this.isHide) {
// //
this.handleEnd() this.handleEnd()
} }
}, },
onUnload() { onUnload() {
console.log('🚀 ~ onUnload ~ 页面关闭') console.log('🚀 ~ onUnload ~ 页面关闭')
if (!this.isEnd) { if (!this.isEnd && !this.isHide) {
// //
this.handleEnd() this.handleEnd()
} }
@ -96,8 +101,19 @@ export default {
}, },
// //
videoTimeUpdate(e) { videoTimeUpdate(e) {
console.log('视频播放时间:', e.detail.currentTime)
this.currentTime = Math.ceil(e.detail.currentTime) this.currentTime = Math.ceil(e.detail.currentTime)
console.log('🚀 ~ 视频播放时间: ~ this.currentTime:', this.currentTime)
console.log('🚀 ~ 视频总时长: ~ this.allStudyDuration:', this.allStudyDuration)
const random1 = (this.allStudyDuration / 3) * 2
const random2 = this.allStudyDuration / 3
if (this.currentTime != this.oldTime) {
if (this.currentTime == random1 || this.currentTime == random2) {
this.oldTime = this.currentTime // , , ,
this.video.pause()
this.openPhotograph()
}
}
}, },
openModal() { openModal() {
this.showModal = true this.showModal = true
@ -119,8 +135,7 @@ export default {
return return
} }
// //
const video = uni.createVideoContext('myVideo') this.video.pause()
video.pause()
// - // -
console.log('当前播放时间:', this.currentTime, this.allStudyDuration) console.log('当前播放时间:', this.currentTime, this.allStudyDuration)
this.studyDuration = this.currentTime this.studyDuration = this.currentTime
@ -171,6 +186,92 @@ export default {
console.log('🚀 ~ handleEnd ~ err:', err) console.log('🚀 ~ handleEnd ~ err:', err)
} }
}) })
},
//
openPhotograph() {
this.isHide = true
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)
}
})
},
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()
uni.request({
url: config.baseUrl + '/exam-student/personalCenter/getFaceRecognition',
method: 'POST',
header: {
'content-type': 'application/json',
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: ''
})
this.isHide = false
this.video.play()
} else {
uni.showToast({
title: '人脸识别失败',
icon: ''
})
setTimeout(() => {
this.handleEnd()
}, 1000)
}
},
fail(err) {
console.log('🚀 ~ openFaceScan ~ 人脸识别失败', err)
uni.showToast({
title: '人脸识别失败',
icon: ''
})
setTimeout(() => {
this.handleEnd()
}, 1000)
}
})
} }
} }
} }

View File

@ -10,6 +10,7 @@
<script> <script>
import config from '@/config' import config from '@/config'
import { pathToBase64, base64ToPath } from 'image-tools'
export default { export default {
data() { data() {
@ -20,7 +21,10 @@ export default {
timer: null, timer: null,
isEnd: false, isEnd: false,
isShowImg: false, isShowImg: false,
time: '' time: '',
isHide: false,
allStudyDuration: 0,
random: 0
} }
}, },
onLoad(opt) { onLoad(opt) {
@ -33,6 +37,8 @@ export default {
// this.path = opt.path // this.path = opt.path
console.log('🚀 ~ onLoad ~ this.params:', this.path) console.log('🚀 ~ onLoad ~ this.params:', this.path)
console.log('🚀 ~ onLoad ~ this.params:', Number(opt.studyDuration), Number(opt.allStudyDuration)) console.log('🚀 ~ onLoad ~ this.params:', Number(opt.studyDuration), Number(opt.allStudyDuration))
this.allStudyDuration = Number(this.params.allStudyDuration) - Number(this.params.studyDuration)
this.random = (this.allStudyDuration / 2).toFixed(0)
if (Number(opt.studyDuration) < Number(opt.allStudyDuration)) { if (Number(opt.studyDuration) < Number(opt.allStudyDuration)) {
this.isEnd = false this.isEnd = false
@ -55,7 +61,7 @@ export default {
// onHide // onHide
onHide() { onHide() {
console.log('🚀 ~ onHide ~ 页面关闭') console.log('🚀 ~ onHide ~ 页面关闭')
if (this.isEnd) { if (this.isEnd || this.isHide) {
return return
} }
// //
@ -78,17 +84,24 @@ export default {
methods: { methods: {
// allStudyDuration // allStudyDuration
countDown() { countDown() {
let allStudyDuration = Number(this.params.allStudyDuration) - Number(this.params.studyDuration) // let allStudyDuration = Number(this.params.allStudyDuration) - Number(this.params.studyDuration)
// let studyDuration = Number(this.params.studyDuration) let minute = Math.floor(this.allStudyDuration / 60)
let minute = Math.floor(allStudyDuration / 60)
minute = String(minute).padStart(2, '0') minute = String(minute).padStart(2, '0')
let second = allStudyDuration % 60 let second = this.allStudyDuration % 60
second = String(second).padStart(2, '0')
this.time = minute + ':' + second this.time = minute + ':' + second
this.timer = setInterval(() => { this.timer = setInterval(() => {
allStudyDuration-- if (!this.isHide) {
this.allStudyDuration--
this.params.studyDuration++ this.params.studyDuration++
}
if (this.allStudyDuration == this.random) {
this.isShow = false
clearInterval(this.timer)
this.openPhotograph()
}
console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration) console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration)
if (allStudyDuration <= 0) { if (this.allStudyDuration <= 0) {
this.params.studyDuration = this.params.allStudyDuration this.params.studyDuration = this.params.allStudyDuration
this.isEnd = true this.isEnd = true
clearInterval(this.timer) clearInterval(this.timer)
@ -120,7 +133,7 @@ export default {
} }
} }
this.time = minute + ':' + second this.time = minute + ':' + second
console.log('🚀 ~ countDown ~ 剩余时间-->:', allStudyDuration) console.log('🚀 ~ countDown ~ 剩余时间-->:', this.allStudyDuration)
console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration) console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration)
}, 1000) }, 1000)
}, },
@ -168,6 +181,93 @@ export default {
uni.previewImage({ uni.previewImage({
urls: [this.path] urls: [this.path]
}) })
},
//
openPhotograph() {
this.isHide = true
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.updStudyDuration()
}, 1000)
}
})
},
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()
uni.request({
url: config.baseUrl + '/exam-student/personalCenter/getFaceRecognition',
method: 'POST',
header: {
'content-type': 'application/json',
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: ''
})
this.isHide = false
this.isShow = true
this.countDown()
} else {
uni.showToast({
title: '人脸识别失败',
icon: ''
})
setTimeout(() => {
this.updStudyDuration()
}, 1000)
}
},
fail(err) {
console.log('🚀 ~ openFaceScan ~ 人脸识别失败', err)
uni.showToast({
title: '人脸识别失败',
icon: ''
})
setTimeout(() => {
this.updStudyDuration()
}, 1000)
}
})
} }
} }
} }

View File

@ -9,6 +9,7 @@
<script> <script>
import PdfView from './components/PdfView.vue' import PdfView from './components/PdfView.vue'
import config from '@/config' import config from '@/config'
import { pathToBase64, base64ToPath } from 'image-tools'
export default { export default {
components: { PdfView }, components: { PdfView },
@ -19,7 +20,11 @@ export default {
params: {}, params: {},
timer: null, timer: null,
// //
surplusTime: null surplusTime: null,
isHide: false,
allStudyDuration: 0,
random1: 0,
random2: 0
} }
}, },
onLoad(opt) { onLoad(opt) {
@ -30,6 +35,9 @@ export default {
this.params.allStudyDuration = Number(opt.allStudyDuration) this.params.allStudyDuration = Number(opt.allStudyDuration)
if (Number(opt.studyDuration) < Number(opt.allStudyDuration)) { if (Number(opt.studyDuration) < Number(opt.allStudyDuration)) {
this.surplusTime = Number(opt.allStudyDuration) - Number(opt.studyDuration) this.surplusTime = Number(opt.allStudyDuration) - Number(opt.studyDuration)
this.allStudyDuration = Number(this.params.allStudyDuration) - Number(this.params.studyDuration)
this.random1 = (this.allStudyDuration / 3).toFixed(0)
this.random2 = ((this.allStudyDuration / 3) * 2).toFixed(0)
console.log('🚀 ~ onLoad ~ surplusTime:', this.surplusTime) console.log('🚀 ~ onLoad ~ surplusTime:', this.surplusTime)
setTimeout(() => { setTimeout(() => {
this.countDown() this.countDown()
@ -50,29 +58,45 @@ export default {
} }
console.log('🚀 ~ onLoad ~ this.params:', this.path) console.log('🚀 ~ onLoad ~ this.params:', this.path)
console.log('🚀 ~ onLoad ~ this.params:', Number(opt.studyDuration), Number(opt.allStudyDuration)) console.log('🚀 ~ onLoad ~ this.params:', Number(opt.studyDuration), Number(opt.allStudyDuration))
}, },
onHide() { onHide() {
if (!this.isHide) {
console.log('🚀 ~ onHide ~ 页面隐藏')
clearInterval(this.timer) clearInterval(this.timer)
// //
this.updStudyDuration() this.updStudyDuration()
}
}, },
// //
onUnload() { onUnload() {
console.log('🚀 ~ onUnload ~ 页面关闭') if (!this.isHide) {
console.log('🚀 ~ onHide ~ 页面隐藏')
clearInterval(this.timer) clearInterval(this.timer)
// //
this.updStudyDuration() this.updStudyDuration()
}
}, },
methods: { methods: {
// allStudyDuration // allStudyDuration
countDown() { countDown() {
let allStudyDuration = Number(this.params.allStudyDuration) - Number(this.params.studyDuration) // let allStudyDuration = Number(this.params.allStudyDuration) - Number(this.params.studyDuration)
this.timer = setInterval(() => { this.timer = setInterval(() => {
allStudyDuration-- if (!this.isHide) {
this.allStudyDuration--
this.params.studyDuration++ this.params.studyDuration++
}
if (this.allStudyDuration == this.random1) {
this.isShow = false
clearInterval(this.timer)
this.openPhotograph()
}
if (this.allStudyDuration == this.random2) {
this.isShow = false
clearInterval(this.timer)
this.openPhotograph()
}
console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration) console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration)
if (allStudyDuration <= 0) { if (this.allStudyDuration <= 0) {
this.params.studyDuration = this.params.allStudyDuration this.params.studyDuration = this.params.allStudyDuration
clearInterval(this.timer) clearInterval(this.timer)
setTimeout(() => { setTimeout(() => {
@ -84,7 +108,7 @@ export default {
}) })
}, 1000) }, 1000)
} }
console.log('🚀 ~ countDown ~ 剩余时间-->:', allStudyDuration) console.log('🚀 ~ countDown ~ 剩余时间-->:', this.allStudyDuration)
console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration) console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration)
}, 1000) }, 1000)
}, },
@ -125,6 +149,100 @@ export default {
console.log('🚀 ~ handleEnd ~ err:', err) console.log('🚀 ~ handleEnd ~ err:', err)
} }
}) })
},
//
openPhotograph() {
this.isHide = true
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.updStudyDuration()
}, 1000)
}
})
},
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()
uni.request({
url: config.baseUrl + '/exam-student/personalCenter/getFaceRecognition',
method: 'POST',
header: {
'content-type': 'application/json',
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: ''
})
this.isHide = false
// this.surplusTime
this.surplusTime = this.allStudyDuration
if (this.params.path.indexOf('http') !== -1) {
this.path = this.params.path + '?surplusTime=' + JSON.stringify(this.surplusTime)
} else {
this.path = config.fileUrl + this.params.path + '?surplusTime=' + JSON.stringify(this.surplusTime)
}
this.isShow = true
this.countDown()
} else {
uni.showToast({
title: '人脸识别失败',
icon: ''
})
setTimeout(() => {
this.updStudyDuration()
}, 1000)
}
},
fail(err) {
console.log('🚀 ~ openFaceScan ~ 人脸识别失败', err)
uni.showToast({
title: '人脸识别失败',
icon: ''
})
setTimeout(() => {
this.updStudyDuration()
}, 1000)
}
})
} }
} }
} }