128 lines
4.0 KiB
Vue
128 lines
4.0 KiB
Vue
<template>
|
||
<view>
|
||
<div>
|
||
<PdfView v-if="isShow" :path="path" />
|
||
</div>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import PdfView from './components/PdfView.vue'
|
||
import config from '@/config'
|
||
|
||
export default {
|
||
components: { PdfView },
|
||
data() {
|
||
return {
|
||
isShow: true,
|
||
path: '',
|
||
params: {},
|
||
timer: null
|
||
}
|
||
},
|
||
onLoad(opt) {
|
||
opt = JSON.parse(opt.params)
|
||
console.log('🚀 ~ onLoad ~ opt:', opt)
|
||
this.params = JSON.parse(JSON.stringify(opt))
|
||
this.params.studyDuration = Number(opt.studyDuration)
|
||
this.params.allStudyDuration = Number(opt.allStudyDuration)
|
||
// 如果路径中带有http或者https则直接使用路径,否则拼接路径
|
||
if (opt.path.indexOf('http') !== -1) {
|
||
this.path = opt.path
|
||
} else {
|
||
this.path = config.fileUrl + opt.path
|
||
}
|
||
console.log('🚀 ~ onLoad ~ this.params:', this.path)
|
||
console.log('🚀 ~ onLoad ~ this.params:', Number(opt.studyDuration), Number(opt.allStudyDuration))
|
||
if (Number(opt.studyDuration) < Number(opt.allStudyDuration)) {
|
||
setTimeout(() => {
|
||
this.countDown()
|
||
}, 1000)
|
||
} else {
|
||
// 提示-学习时长已满
|
||
uni.showToast({
|
||
title: '学习时长已满, 随时可以结束学习',
|
||
icon: 'none'
|
||
})
|
||
}
|
||
},
|
||
onHide() {
|
||
clearInterval(this.timer)
|
||
// 关闭页面时,修改项目进度
|
||
this.updStudyDuration()
|
||
},
|
||
// 卸载
|
||
onUnload() {
|
||
console.log('🚀 ~ onUnload ~ 页面关闭')
|
||
clearInterval(this.timer)
|
||
// 关闭页面时,修改项目进度
|
||
this.updStudyDuration()
|
||
},
|
||
methods: {
|
||
// 根据allStudyDuration 倒计时
|
||
countDown() {
|
||
let allStudyDuration = Number(this.params.allStudyDuration) - Number(this.params.studyDuration)
|
||
this.timer = setInterval(() => {
|
||
allStudyDuration--
|
||
this.params.studyDuration++
|
||
console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration)
|
||
if (allStudyDuration <= 0) {
|
||
this.params.studyDuration = this.params.allStudyDuration
|
||
clearInterval(this.timer)
|
||
setTimeout(() => {
|
||
this.updStudyDuration()
|
||
// 提示-学习时长已满
|
||
uni.showToast({
|
||
title: '学习时长已满',
|
||
icon: 'none'
|
||
})
|
||
}, 1000)
|
||
}
|
||
console.log('🚀 ~ countDown ~ 剩余时间-->:', allStudyDuration)
|
||
console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration)
|
||
}, 1000)
|
||
},
|
||
// 修改项目进度
|
||
updStudyDuration() {
|
||
const params = {
|
||
userId: this.params.userId,
|
||
studyId: this.params.studyId,
|
||
stageId: this.params.stageId,
|
||
stageContentId: this.params.stageContentId,
|
||
stageType: this.params.stageType,
|
||
studyCourseId: this.params.studyCourseId,
|
||
sourceId: this.params.sourceId,
|
||
studyDuration: this.params.studyDuration,
|
||
studyPercentage:
|
||
Math.ceil((Number(this.params.studyDuration) / Number(this.params.allStudyDuration)) * 100).toFixed(2) > 100
|
||
? 100
|
||
: Math.ceil((Number(this.params.studyDuration) / Number(this.params.allStudyDuration)) * 100).toFixed(2)
|
||
}
|
||
console.log('🚀 ~ updStudyDuration ~ params:', params)
|
||
this.$verificationToken()
|
||
uni.request({
|
||
url: config.baseUrl + '/exam-student/student/updStudyDuration',
|
||
method: 'post',
|
||
data: params,
|
||
header: {
|
||
'Content-Type': 'application/x-www-form-urlencoded',
|
||
Authorization: uni.getStorageSync('access_token')
|
||
},
|
||
success: res => {
|
||
console.log('🚀 ~ handleEnd ~ res:', res)
|
||
this.isShow = false
|
||
uni.reLaunch({
|
||
url: '/pages/YNEduApp/learnProj/learnProjDetail?id=' + this.params.studyId
|
||
})
|
||
},
|
||
fail: err => {
|
||
console.log('🚀 ~ handleEnd ~ err:', err)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped></style>
|