| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564 |
- <!-- 学习课程 -->
- <template>
- <div class="learningCourse">
- <div class="page-container-top-max-big-box">
- <p class="top-1-p">开始学习</p>
- <p class="top-2-p" @click="backPage()">返回</p>
- </div>
- <div class="content-box">
- <div class="left-max-big-box">
- <coursewareComponent ref="coursewareComponent"></coursewareComponent>
- </div>
- <div class="right-max-big-box">
- <p class="title-p">{{newData.courseName}}</p>
- <div class="text-p" style="color:#666;">{{secondsToMinutes(newData.totalDuration)}}分钟丨{{newData.totalCreditHours}}学时丨{{newData.totalPoints}}积分</div>
- <div class="text-p">已学 {{newData.learnedCoursewareCount}} / 总 {{newData.totalCoursewareCount}} 课件</div>
- <div class="progress-box">
- <p class="progress-title-box">学习进度</p>
- <div class="progress-min-box">
- <el-progress :stroke-width="12" :percentage="newData.coursewares[0].progress?newData.coursewares[0].progress:0"></el-progress>
- </div>
- </div>
- <div class="learning-for-max-big-box scrollbar-box">
- <div class="for-max-big-box"
- v-for="(item,index) in newData.coursewares" :key="index">
- <div class="for-big-box" @click="checkLearningButton(index)"
- :class="checkLearningIndex == index ?'check-for-box':''">
- <p>{{item.coursewareName}}</p>
- <p>已学习:{{formatTime(item.learnedDuration)}} / {{formatTime(item.minLearningDuration)}}</p>
- <p :class="item.learnStatus ==2 ?'colorA':''">{{item.learnStatus==2?'已学完':'未学完'}}</p>
- </div>
- <p class="for-button" @click="finishStudying(index)"
- v-if="item.learnStatus != 2 && item.learnedDuration == item.minLearningDuration && checkLearningIndex == index">
- 若已完成学习,请点此确认
- </p>
- </div>
- </div>
- </div>
- </div>
- <el-dialog
- title="请完成安全验证"
- :visible.sync="dialogVisible"
- width="340px"
- :close-on-click-modal="false"
- :show-close="false"
- append-to-body
- center>
- <div class="verify-container">
- <VerifySlider
- v-if="dialogVisible"
- tips="请按住滑块,拖动到最后边"
- success-tips="验证通过"
- @success="onVerifySuccess" />
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import StudyTimer from '@/utils/timerUtils/StudyTimer';
- import CountdownTimer from '@/utils/timerUtils/CountdownTimer';
- import { VerifySlider } from 'vue-verify-slider';
- import coursewareComponent from "@/views/safetyEducationExaminationNew/components/coursewareComponent.vue";
- import {
- examUserCourseLearningCoursewareList,examUserCoursewareLearningReportProgress,
- examUserCoursewareLearningConfirmCompletion,examUserCoursewareLearningRestart
- } from "@/api/safetyEducationExaminationNew/index";
- export default {
- name: 'index',
- components: {
- VerifySlider,
- coursewareComponent,
- },
- data() {
- return {
- examId:null,
- courseId:null,
- newData:{
- courseName:"",
- totalDuration:0,
- totalCreditHours:0,
- totalPoints:0,
- learnedCoursewareCount:0,
- totalCoursewareCount:0,
- progress:0,
- coursewares:[
- {
- coursewareName:'视频课件名称',
- listData2:1,
- learnedDuration:590,
- minLearningDuration:600,
- learnStatus:2,
- attachmentPath:'http://192.168.1.8/statics/bigFile/20260801/0731dbcb-622b-4468-ade2-e20820b122eb.mp4',
- attachmentType:'mp4',
- materialType:'1',
- articleContent:'',
- },
- {
- coursewareName:'docx课件名称',
- listData2:1,
- learnedDuration:600,
- minLearningDuration:600,
- learnStatus:0,
- attachmentPath:'http://192.168.1.8/statics/2026/08/01/b68f1b1d-99ea-44e0-94b5-4bad4ac3ff1f.docx',
- attachmentType:'.docx',
- materialType:'3',
- articleContent:'',
- },
- {
- coursewareName:'xlsx课件名称',
- listData2:1,
- learnedDuration:600,
- minLearningDuration:600,
- learnStatus:1,
- attachmentPath:'http://192.168.1.8/statics/2026/08/01/270eb79e-627b-4fdf-9f1a-397bd9784d39.xlsx',
- attachmentType:'.xlsx',
- materialType:'3',
- articleContent:'',
- },
- {
- coursewareName:'pdf课件名称',
- listData2:1,
- learnedDuration:600,
- minLearningDuration:600,
- learnStatus:1,
- attachmentPath:'http://192.168.1.8/statics/2026/08/01/b251bd69-120c-48d5-b662-c28e308cd61b.pdf',
- attachmentType:'.pdf',
- materialType:'3',
- articleContent:'',
- },
- {
- coursewareName:'富文本课件名称',
- listData2:1,
- learnedDuration:600,
- minLearningDuration:600,
- learnStatus:1,
- attachmentPath:'',
- attachmentType:'',
- materialType:'4',
- articleContent:"<p><img style=\"max-width: 100%;\" src=\"../statics/2026/08/01/e2788e82-745c-4b49-82e0-ebb6f2a30713.jpeg\" alt=\"1.jpeg\"> </p>"
- },
- {
- coursewareName:'xlsx课件名称',
- listData2:1,
- learnedDuration:600,
- minLearningDuration:600,
- learnStatus:1,
- attachmentPath:'http://192.168.1.8/statics/2026/08/01/270eb79e-627b-4fdf-9f1a-397bd9784d39.xlsx',
- attachmentType:'.xlsx',
- materialType:'3',
- articleContent:'',
- },
- ],
- },
- //当前选中
- checkLearningIndex:0,
- //学习计时器
- studyTimer: null,
- //验证计时器
- countdownTimer:null,
- //验证器弹窗状态
- dialogVisible:false,
- //验证器弹窗间隔时间
- verificationTime:0,
- //心跳回报时间
- heartbeatValue:30,
- }
- },
- created() {
- },
- mounted() {
- this.initialization();
- },
- methods: {
- //初始化
- initialization(){
- this.$set(this,'courseId',this.$route.params.courseId)
- this.$set(this,'examId',this.$route.params.examId)
- this.$nextTick(()=>{
- this.examUserCourseLearningCoursewareList();
- })
- },
- //获取课程下的课件列表
- examUserCourseLearningCoursewareList(){
- examUserCourseLearningCoursewareList({ courseId:this.courseId,examId:this.examId }).then(response => {
- this.$set(this, 'newData', response.data)
- if(response.data.popupVerifyEnabled == 1){
- if (this.countdown) {
- this.countdown.clear();
- this.countdown = null;
- }
- this.$set(this,'verificationTime',this.accMul(response.data.popupIntervalMinutes,60));
- this.startCountdown();//验证码倒计时
- }
- this.initTimer();//学习计时器
- this.courseRendering(this.checkLearningIndex);//课件渲染
- })
- },
- //返回
- backPage() {
- this.$router.back()
- },
- //完成课件学习
- finishStudying(index){
- let self = this;
- this.$confirm('确认完成课件学习?', "警告", {
- confirmButtonText: "确认",
- cancelButtonText: "取消",
- type: "warning"
- }).then(function() {
- }).then(() => {
- self.examUserCoursewareLearningConfirmCompletion();
- }).catch(() => {});
- },
- //切换课件
- checkLearningButton(index){
- let self = this;
- if(this.newData.coursewares[this.checkLearningIndex].learnStatus == 2){
- self.$set(self,'checkLearningIndex',index);
- self.initTimer();
- self.courseRendering(index);
- }else{
- self.handleToggle();
- self.verificationHandleToggle();
- if(this.checkLearningIndex != index){
- this.$confirm('确认切换课件?', "警告", {
- confirmButtonText: "确认",
- cancelButtonText: "取消",
- type: "warning"
- }).then(function() {
- }).then(() => {
- self.$set(self,'checkLearningIndex',index);
- self.initTimer();
- self.verificationHandleToggle();
- self.courseRendering(index);
- }).catch(() => {
- self.handleToggle();
- self.verificationHandleToggle();
- });
- }
- }
- },
- //课件渲染
- courseRendering(index){
- let name = this.newData.coursewares[index].coursewareName;
- let url = '';
- let type = '';
- if(this.newData.coursewares[index].materialType == 1){
- //视频
- type = 'video'
- url = this.newData.coursewares[index].attachmentPath;
- }else if(this.newData.coursewares[index].materialType == 3){
- //文档
- if(this.newData.coursewares[index].attachmentType == '.docx'){
- type = 'docx'
- }else if(this.newData.coursewares[index].attachmentType == '.xlsx'){
- type = 'excel'
- }else if(this.newData.coursewares[index].attachmentType == '.pdf'){
- type = 'pdf'
- }
- url = this.newData.coursewares[index].attachmentPath;
- }else if(this.newData.coursewares[index].materialType == 4){
- //文章
- type = 'text'
- url = this.newData.coursewares[index].articleContent;
- }
- this.$refs['coursewareComponent'].initialize(name,url,type);
- },
- //学习完成
- examUserCoursewareLearningConfirmCompletion(){
- let self = this;
- let obj = {
- coursewareId:this.newData.coursewares[this.checkLearningIndex].coursewareId,
- courseId:this.courseId,
- examId:this.examId,
- }
- examUserCoursewareLearningConfirmCompletion(obj).then(response => {
- for(let i=0;i<self.newData.coursewares.length;i++){
- if(self.newData.coursewares[i].learnStatus!=2 && i!=this.checkLearningIndex){
- this.$set(this,'checkLearningIndex',i);
- break
- }
- }
- this.examUserCourseLearningCoursewareList();
- this.msgSuccess(response.message)
- })
- },
- //心跳接口
- examUserCoursewareLearningReportProgress(){
- let obj = {
- coursewareId:this.newData.coursewares[this.checkLearningIndex].coursewareId,
- courseId:this.courseId,
- examId:this.examId,
- duration:this.heartbeatValue,
- }
- examUserCoursewareLearningReportProgress(obj).then(response => {})
- },
- //倒计时时间换算
- formatTime(totalSeconds) {
- if (typeof totalSeconds !== 'number' || totalSeconds <= 0) {
- return '0秒';
- }
- const minutes = Math.floor(totalSeconds / 60);
- const seconds = totalSeconds % 60;
- if (minutes > 0 && seconds > 0) {
- return `${minutes}分${seconds}秒`;
- } else if (minutes > 0 && seconds === 0) {
- return `${minutes}分`;
- } else {
- return `${seconds}秒`;
- }
- },
- //展示时间换算
- secondsToMinutes(totalSeconds) {
- if (typeof totalSeconds !== 'number' || totalSeconds <= 0) {
- return 1;
- }
- return Math.ceil(totalSeconds / 60);
- },
- /*=================================== 验证器 ===================================*/
- onVerifySuccess() {
- this.$message.success('验证成功');
- this.$set(this,'dialogVisible',false);
- this.handleToggle();
- this.startCountdown();
- //如果是视频课件 则继续播放视频
- if(this.newData.coursewares[this.checkLearningIndex].materialType == 1){
- this.$refs['coursewareComponent'].resumeVideo();
- }
- },
- /*=================================== 学习定时器 ===================================*/
- // 初始化定时器
- initTimer() {
- let self = this;
- if(this.newData.coursewares[this.checkLearningIndex].learnedDuration == this.newData.coursewares[this.checkLearningIndex].minLearningDuration){
- return
- }
- this.studyTimer = new StudyTimer({
- initialSeconds: self.newData.coursewares[self.checkLearningIndex].learnedDuration,
- maxSeconds: self.newData.coursewares[self.checkLearningIndex].minLearningDuration,
- onTick: (elapsedSeconds) => {
- //每次计时
- this.$set(self.newData.coursewares[self.checkLearningIndex],'learnedDuration',elapsedSeconds);
- //心跳判断
- if (elapsedSeconds % this.heartbeatValue === 0) {
- //调用心跳方法
- this.examUserCoursewareLearningReportProgress();
- }
- },
- onMaxTimeReached: (elapsedSeconds) => {
- //达到最大值
- this.$set(self.newData.coursewares[self.checkLearningIndex],'learnedDuration',elapsedSeconds);
- //调用心跳方法
- this.examUserCoursewareLearningReportProgress();
- }
- });
- this.studyTimer.resume();
- },
- // 切换暂停/继续
- handleToggle() {
- if (!this.studyTimer) return;
- if (this.studyTimer.isRunning) {
- this.studyTimer.pause();
- } else {
- this.studyTimer.resume();
- }
- },
- // 清除定时器
- clearTimer() {
- if (this.studyTimer) {
- this.studyTimer.clear();
- this.studyTimer = null;
- }
- },
- /*=================================== 验证定时器 ===================================*/
- // 1. 启动倒计时
- startCountdown() {
- if(this.verificationTime == 0){
- return
- }
- this.countdown = new CountdownTimer({
- targetSeconds: this.verificationTime,
- // 达到目标值时触发的回调
- onTargetReached: (elapsedSeconds) => {
- //倒计时结束 开启弹窗
- this.handleToggle();
- this.verificationHandleToggle();
- this.$set(this,'dialogVisible',true);
- //如果是视频课件 则暂停播放视频
- if(this.newData.coursewares[this.checkLearningIndex].materialType == 1){
- this.$refs['coursewareComponent'].pauseVideo();
- }
- }
- });
- if (this.countdown) {
- this.countdown.start();
- }
- },
- // 2. 暂停/继续
- verificationHandleToggle() {
- if (!this.countdown) return;
- this.countdown.toggle();
- },
- // 3. 清除倒计时
- clearCountdown() {
- if (this.countdown) {
- this.countdown.clear();
- this.countdown = null;
- }
- },
- //乘法
- accMul(arg1,arg2){
- var m=0,s1=arg1.toString(),s2=arg2.toString();
- try{m+=s1.split(".")[1].length}catch(e){}
- try{m+=s2.split(".")[1].length}catch(e){}
- return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)
- },
- },
- beforeDestroy() {
- if (this.studyTimer) {
- this.studyTimer.destroy();
- this.studyTimer = null;
- }
- if (this.countdownTimer) {
- this.countdownTimer.destroy();
- this.countdownTimer = null;
- }
- },
- }
- </script>
- <style scoped lang="scss">
- .learningCourse {
- flex:1;
- display: flex;
- flex-direction: column;
- background:#FFFFFF;
- border-radius:10px;
- overflow: hidden;
- padding:0;
- box-shadow: 0 0 8px 1px rgba(0, 0, 0, 0.1);
- margin:10px;
- ::v-deep .el-progress .el-progress__text{
- margin-left:10px;
- margin-top:1px;
- }
- .content-box{
- flex: 1;
- display: flex;
- overflow: hidden;
- .left-max-big-box{
- flex:1;
- display: flex;
- flex-direction: column;
- background-color: #dedede;
- margin:20px 20px;
- border-radius:10px;
- overflow: hidden;
- box-shadow: 0 0 15px rgba(0, 0, 0, 0.4);
- border:1px solid #dedede;
- }
- .right-max-big-box{
- padding:20px 0;
- width:400px;
- display: flex;
- flex-direction: column;
- overflow: hidden;
- border-left: 1px solid #dedede;
- .title-p{
- font-size:16px;
- font-weight:700;
- line-height:30px;
- padding:0 20px;
- }
- .text-p{
- font-size:14px;
- line-height:20px;
- margin-bottom:20px;
- padding:0 20px;
- }
- .progress-box{
- width:400px;
- height:20px;
- display: flex;
- padding:0 20px;
- .progress-title-box{
- font-size:14px;
- line-height:20px;
- font-weight:700;
- }
- .progress-min-box{
- flex:1;
- padding:0 0 0 20px;
- .el-progress{
- margin-top:1px;
- }
- }
- }
- .learning-for-max-big-box{
- flex:1;
- display: flex;
- flex-direction: column;
- padding:0 20px;
- .for-max-big-box{
- margin-top:40px;
- .for-big-box{
- cursor: pointer;
- border-radius:6px;
- border:1px solid #666;
- padding:15px 10px;
- position: relative;
- p{
- line-height:30px;
- }
- p:nth-child(1){
- font-size:16px;
- font-weight:700;
- /*单行省略号*/
- display:block;
- overflow:hidden;
- text-overflow:ellipsis;
- white-space:nowrap;
- }
- p:nth-child(2){
- font-size:14px;
- }
- p:nth-child(3){
- font-size:14px;
- position: absolute;
- bottom: 16px;
- right: 16px;
- color:#fff!important;
- background-color: #999;
- border-radius:4px;
- width:60px;
- line-height:24px;
- text-align: center;
- }
- .colorA{
- background-color: #0183fa!important;
- }
- }
- .for-button{
- margin-top:20px;
- background-color: #13CE66;
- color:#fff;
- text-align: center;
- line-height:30px;
- border-radius:4px;
- cursor: pointer;
- font-size:14px;
- }
- .check-for-box{
- background-color: rgba(1,131,250,0.1);
- border:1px solid #0183fa!important;
- p{
- color:#0183fa!important;
- }
- }
- }
- }
- }
- }
- }
- </style>
|