123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- import {courseTypes, courseTypeTexts, htmlTypes, logicStatus} from "../../model/enum";
- import Api from "../../model/api";
- import {getDataSet, getEventParam, showLoading, toast} from "../../utils/utils";
- import Route from "../../model/route";
- import {wxToPromise} from "../../utils/wx";
- Page({
- data: {
- id: '',
- type: '',
- item: {},
- obj: {},
- plan: {},
- fileList: [],
- videoList: [],
- videoIndex: 0,
- courseTypeTexts: courseTypeTexts,
- courseTypesEnum: courseTypes,
- videoItem: {},
- scanTime: 0,
- nodeTime: 0,
- lessStatus: logicStatus.NO,
- show: false,
- currentTime: 0,
- scanOkTime: 0,
- videoContext: null,
- tempFilePath: ''
- },
- async onLoad(options) {
- let id = options.id;
- let obj = JSON.parse(options.detail);
- let plan = JSON.parse(options.plan);
- let type = options.type;
- wx.setNavigationBarTitle({title: courseTypeTexts[type]});
- const videoContext = wx.createVideoContext('myVideo3');
- this.setData({
- id, plan,
- obj, type, videoContext
- }, async () => {
- showLoading();
- await this.getData();
- wx.hideLoading()
- this.data.videoContext.seek(this.data.nodeTime)
- })
- },
- async getData() {
- const res = await Api.getCourseDetail(this.data.id, this.data.obj.eduStuId);
- if (this.data.obj.isOnline) {
- res.data.isQuestion = res.data.suitangUpper;
- } else {
- res.data.isQuestion = res.data.suitangLower;
- }
- let fileList = [];
- let videoItem = {};
- if (res.data.enclosureUrl) {
- if (this.data.type == courseTypes.RECORD) {
- videoItem = JSON.parse(res.data.enclosureUrl)[0];
- if (videoItem.verifyInterval) {
- let scanTime = videoItem.verifyInterval;
- this.setData({scanTime})
- }
- const less = await Api.getRecordedLesson({
- stuId: this.data.obj.eduStuId,
- scheduleId: this.data.id
- })
- if (less.data) {
- let nodeTime = less.data.status == logicStatus.YES ? videoItem.duration : less.data.nodeTime || 0;
- let lessStatus = less.data.status;
- this.setData({nodeTime, lessStatus, videoItem})
- } else {
- this.setData({nodeTime: 0, lessStatus: logicStatus.NO, videoItem})
- }
- } else {
- fileList = JSON.parse(res.data.enclosureUrl);
- }
- }
- let videoList = [];
- if (this.data.type == courseTypes.PLAYBACK && res.data.videoPlaybackUrl) {
- videoList = res.data.videoPlaybackUrl.split(",");
- }
- this.compare(res.data, this.data.plan);
- this.setData({
- item: res.data, fileList, videoList
- })
- },
- compare(newData, oldData) {
- if (!oldData) {
- return;
- }
- if (newData.courseProcess != oldData.courseProcess ||
- newData.courseStatus != oldData.courseStatus ||
- newData.liveStatus != oldData.liveStatus
- ) {
- const eventChannel = this.getOpenerEventChannel()
- eventChannel.emit('refresh');
- }
- },
- async downloadFile(e) {
- let url = getDataSet(e, "url");
- let end = url.substr(url.lastIndexOf(".") + 1);
- showLoading('下载中...')
- let filePath = "";
- if (this.data.tempFilePath) {
- filePath = this.data.tempFilePath;
- } else {
- const res = await wxToPromise("downloadFile", {url});
- if (res.statusCode === 200) {
- filePath = res.tempFilePath
- this.setData({tempFilePath: filePath})
- } else {
- toast(`下载文档失败,请稍后重试${res.statusCode}:${res.errMsg}`)
- }
- }
- try {
- await wx.openDocument({
- filePath
- })
- } catch (e) {
- console.log(e)
- toast(`打开文档失败,请稍后重试${e.msg}`)
- }
- wx.hideLoading();
- },
- toTeacher(e) {
- let id = getDataSet(e, "id");
- Route.toTeacher(id);
- },
- clickImg(e) {
- let id = this.data.item.id;
- let eId = this.data.obj.eduStuId;
- Route.toNews(htmlTypes.SEAT, id, "座位图", eId);
- },
- async refresh(e) {
- await this.getData();
- const eventChannel = this.getOpenerEventChannel()
- eventChannel.emit('refresh');
- },
- changeVideo(e) {
- let index = getDataSet(e, "index");
- this.setData({
- videoIndex: index,
- })
- },
- // 以下是录播课的逻辑算法 待分离
- async onUnload() {
- await this.changeProgress();
- },
- async onHide() {
- await this.changeProgress();
- },
- async changeProgress() {
- if (this.data.type == courseTypes.RECORD) {
- const res = await Api.changeVideoProgress({
- stuId: this.data.obj.eduStuId,
- scheduleId: this.data.id,
- nodeTime: this.data.nodeTime
- })
- if (res.data == logicStatus.YES) {
- await this.getData(false);
- const eventChannel = this.getOpenerEventChannel()
- eventChannel.emit('refresh');
- }
- }
- },
- async timeUpdate(e) {
- let currentTime = parseInt(getEventParam(e, "currentTime"));
- console.log("timeUpdate", currentTime, this.data.scanTime)
- if (this.data.scanTime) {//需要处理验证人脸情况
- let flag = currentTime % this.data.scanTime;
- if (flag == 0 && currentTime != this.data.scanOkTime &&
- currentTime >= this.data.nodeTime && currentTime != this.data.videoItem.duration) {
- console.log("暂停,弹出人脸识别")
- this.data.videoContext.exitFullScreen();
- this.data.videoContext.pause();
- this.setData({
- show: true,
- currentTime
- });
- }
- }
- if (currentTime - this.data.nodeTime <= 1) {
- if (currentTime - this.data.nodeTime >= 0) {
- this.data.nodeTime = currentTime;
- if (this.data.nodeTime == this.data.videoItem.duration) {
- if (this.data.lessStatus == logicStatus.NO) {
- await wx.showModal({
- title: "恭喜你,视频已学完!",
- showCancel: false
- })
- this.data.lessStatus = logicStatus.YES;
- await this.changeProgress();
- }
- }
- }
- } else {
- this.data.videoContext.seek(this.data.nodeTime)
- }
- },
- scanOk(e) {
- this.data.scanOkTime = getEventParam(e, "currentTime");
- this.setData({
- show: false,
- });
- setTimeout(() => {
- this.data.videoContext.play();
- }, 500)
- },
- });
|