YNUtdPlatform/pages/YNEduApp/learnProj/pdfStudy.vue

134 lines
4.3 KiB
Vue
Raw Normal View History

2024-08-13 19:03:13 +08:00
<template>
2024-08-28 17:23:03 +08:00
<view>
<div>
2024-09-03 15:20:18 +08:00
<PdfView v-if="isShow" :path="path" />
2024-08-28 17:23:03 +08:00
</div>
</view>
2024-08-13 19:03:13 +08:00
</template>
<script>
2024-08-28 17:23:03 +08:00
import PdfView from './components/PdfView.vue'
import config from '@/config'
export default {
components: { PdfView },
data() {
return {
isShow: true,
path: '',
params: {},
2024-09-10 13:41:39 +08:00
timer: null,
// 剩余时间
surplusTime: null
2024-08-28 17:23:03 +08:00
}
},
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)
2024-09-05 18:17:59 +08:00
if (Number(opt.studyDuration) < Number(opt.allStudyDuration)) {
2024-09-10 13:41:39 +08:00
this.surplusTime = Number(opt.allStudyDuration) - Number(opt.studyDuration)
console.log('🚀 ~ onLoad ~ surplusTime:', this.surplusTime)
2024-09-03 15:20:18 +08:00
setTimeout(() => {
this.countDown()
2024-09-10 13:41:39 +08:00
}, 1300)
2024-09-03 15:20:18 +08:00
} else {
2024-09-10 13:41:39 +08:00
this.surplusTime = 0
2024-09-03 15:20:18 +08:00
// 提示-学习时长已满
uni.showToast({
title: '学习时长已满, 随时可以结束学习',
icon: 'none'
})
}
2024-09-10 13:41:39 +08:00
// 如果路径中带有http或者https则直接使用路径否则拼接路径
if (opt.path.indexOf('http') !== -1) {
this.path = opt.path + '?surplusTime=' + JSON.stringify(this.surplusTime)
} else {
this.path = config.fileUrl + opt.path + '?surplusTime=' + JSON.stringify(this.surplusTime)
}
console.log('🚀 ~ onLoad ~ this.params:', this.path)
console.log('🚀 ~ onLoad ~ this.params:', Number(opt.studyDuration), Number(opt.allStudyDuration))
2024-09-03 15:20:18 +08:00
},
onHide() {
clearInterval(this.timer)
// 关闭页面时,修改项目进度
this.updStudyDuration()
2024-08-28 17:23:03 +08:00
},
// 卸载
onUnload() {
console.log('🚀 ~ onUnload ~ 页面关闭')
clearInterval(this.timer)
// 关闭页面时,修改项目进度
2024-09-03 15:20:18 +08:00
this.updStudyDuration()
2024-08-28 17:23:03 +08:00
},
methods: {
// 根据allStudyDuration 倒计时
countDown() {
let allStudyDuration = Number(this.params.allStudyDuration) - Number(this.params.studyDuration)
this.timer = setInterval(() => {
allStudyDuration--
2024-09-03 15:20:18 +08:00
this.params.studyDuration++
console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration)
2024-08-28 17:23:03 +08:00
if (allStudyDuration <= 0) {
2024-09-05 18:17:59 +08:00
this.params.studyDuration = this.params.allStudyDuration
2024-08-28 17:23:03 +08:00
clearInterval(this.timer)
setTimeout(() => {
this.updStudyDuration()
2024-09-03 15:20:18 +08:00
// 提示-学习时长已满
uni.showToast({
title: '学习时长已满',
icon: 'none'
})
2024-08-28 17:23:03 +08:00
}, 1000)
}
console.log('🚀 ~ countDown ~ 剩余时间-->:', allStudyDuration)
2024-09-03 15:20:18 +08:00
console.log('🚀 ~ countDown ~ this.params.studyDuration:', this.params.studyDuration)
2024-08-28 17:23:03 +08:00
}, 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,
2024-09-03 15:20:18 +08:00
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)
2024-08-28 17:23:03 +08:00
}
console.log('🚀 ~ updStudyDuration ~ params:', params)
2024-09-06 14:53:49 +08:00
this.$verificationToken()
2024-08-28 17:23:03 +08:00
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
2024-09-03 15:20:18 +08:00
uni.reLaunch({
2024-08-28 17:23:03 +08:00
url: '/pages/YNEduApp/learnProj/learnProjDetail?id=' + this.params.studyId
})
},
fail: err => {
console.log('🚀 ~ handleEnd ~ err:', err)
}
})
}
}
}
</script>
2024-08-13 19:03:13 +08:00
2024-08-28 17:23:03 +08:00
<style lang="scss" scoped></style>