dbDetails.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. const app = require('../../utils/util.js');
  2. const tools = require('../../utils/tools.js');
  3. // var app1 = getApp();
  4. Page({
  5. data: {
  6. url: '', //播放地址
  7. title: '', //视频标题
  8. message: '', //视频信息
  9. playTimes: 0, //播放次数
  10. playVideoDuration: 0, // 从这个时间点开始播放
  11. id: 0, //带过来的id
  12. studyLog: {}, //我得到的学习日志
  13. // intervalTime: 0, //隔五分钟清空重新计时 弹出信息确认在不在
  14. video_real_time: 0, //实时播放进度
  15. intervalCtx: null,
  16. videoContext: null,
  17. classInfo: {},
  18. showWW: true,
  19. showChange: true,
  20. showfullChange: false,
  21. networkType: '',
  22. isAgree: false, //表示不同意用4G
  23. fullScreen: false,
  24. spanTime: 0 //间隔时间弹窗小人
  25. },
  26. isClass(sessionKey) {
  27. wx.request({
  28. url: app.globalData.publicUrl + '/wx/student/selMyClas',
  29. method: "post",
  30. data: {
  31. sessionKey
  32. },
  33. success: (res) => {
  34. if (res.data.code == 0) {
  35. this.setData({
  36. classInfo: res.data.data
  37. })
  38. } else {
  39. if (res.data.msg == "运行时异常:学员不可同时存在两个班级中。") {
  40. wx.showModal({
  41. content: "学员不可同时存在多个班级中哦",
  42. showCancel: false,
  43. success(res) {
  44. if (res.confirm) {
  45. wx.switchTab({
  46. url: '../index/index'
  47. })
  48. }
  49. }
  50. })
  51. return false;
  52. } else {
  53. wx.showModal({
  54. content: "您当前还没有正在开放的班级!",
  55. showCancel: false,
  56. success(res) {
  57. if (res.confirm) {
  58. wx.switchTab({
  59. url: '../index/index'
  60. })
  61. }
  62. }
  63. })
  64. return false;
  65. }
  66. }
  67. }
  68. })
  69. },
  70. // 视频出错了
  71. videoErrorCallback: function (e) {
  72. console.log('视频错误信息:', e.detail.errMsg)
  73. },
  74. // 计时 五分钟弹出一个弹框
  75. // calculateTime() {
  76. // console.log(this.data.alertTime)
  77. // console.log(this.data.intervalTime)
  78. // let _this = this;
  79. // this.setData({
  80. // intervalTime: _this.data.intervalTime + 5
  81. // })
  82. // if (_this.data.intervalTime > 300) {
  83. // _this.data.videoContext.pause()
  84. // this.setData({
  85. // showWW: false,
  86. // intervalTime: 0
  87. // })
  88. // }
  89. // },
  90. // 点击开始播放视频
  91. async bindplay() {
  92. this.setData({
  93. showWW: true
  94. })
  95. const netStatus = await this.getNetStatus();
  96. this.setData({
  97. networkType: netStatus
  98. })
  99. if (netStatus != 'wifi' && !this.data.isAgree) {
  100. this.data.videoContext.pause()
  101. this.setData({
  102. showChange: false
  103. })
  104. }
  105. wx.onNetworkStatusChange((res) => {
  106. if (this.data.networkType == "wifi" && res.networkType != "wifi" && !this.data.isAgree) {
  107. this.data.videoContext.pause()
  108. this.setData({
  109. showChange: false
  110. })
  111. }
  112. })
  113. },
  114. goclose() {
  115. this.setData({
  116. showChange: true,
  117. isAgree: false
  118. })
  119. },
  120. goon() {
  121. this.setData({
  122. showChange: true,
  123. isAgree: true
  124. })
  125. this.data.videoContext.play()
  126. },
  127. fullScreenChange(e) {
  128. console.log(e.detail.fullScreen, "我是切换全屏的状态")
  129. this.setData({
  130. fullScreen: e.detail.fullScreen,
  131. })
  132. },
  133. startbf() {
  134. this.setData({
  135. showWW: true
  136. })
  137. this.data.videoContext.play()
  138. },
  139. // 视频暂停
  140. // bindpause() {
  141. // clearInterval(this.data.intervalCtx)
  142. // },
  143. // 得到录播列表
  144. getdbArr(sessionKey) {
  145. let _this = this;
  146. wx.request({
  147. method: "post",
  148. url: app.globalData.publicUrl + '/wx/course/selectRecordByCourseId',
  149. data: {
  150. sessionKey: sessionKey,
  151. courseId: _this.data.id
  152. },
  153. success: (e) => {
  154. console.log(e, "888888888888888888")
  155. this.setData({
  156. url: e.data.url,
  157. show: false,
  158. title: e.data.course.courseName,
  159. message: e.data.course.courseInfo,
  160. playTimes: e.data.course.playTimes,
  161. courseTime: e.data.course.courseTime
  162. })
  163. }
  164. })
  165. },
  166. // 获取学习进度
  167. getStudyLog(sessionKey) {
  168. let _this = this;
  169. wx.request({
  170. method: "post",
  171. url: app.globalData.publicUrl + '/wx/course/getStudyLog',
  172. data: {
  173. sessionKey: sessionKey,
  174. courseId: _this.data.id,
  175. },
  176. success: (e) => {
  177. if (e.data.studyLog.isDone == 1) {
  178. _this.setData({
  179. studyLog: e.data.studyLog,
  180. })
  181. } else {
  182. _this.setData({
  183. studyLog: e.data.studyLog,
  184. playVideoDuration: e.data.studyLog.studyTime
  185. })
  186. }
  187. }
  188. })
  189. },
  190. // 设置不可快进
  191. timeUpdate: function (e) {
  192. let _this = this;
  193. let currentTime = parseInt(e.detail.currentTime) //当前播放秒数
  194. if (currentTime != 0 && currentTime % 300 == 0) {
  195. if (currentTime != this.data.spanTime) {
  196. this.setData({
  197. spanTime: currentTime,
  198. showWW: false
  199. })
  200. _this.data.videoContext.pause()
  201. }
  202. }
  203. let studyTime = 'studyLog.studyTime'
  204. //实时给页面的学习记录赋值
  205. let jump_time = parseInt(_this.data.video_real_time); //定义跳转的时间
  206. if (_this.data.studyLog.isDone != 1) {
  207. if (currentTime > jump_time && currentTime - jump_time > 3 && currentTime > _this.data.playVideoDuration) {
  208. _this.data.videoContext.seek(_this.data.playVideoDuration)
  209. if (_this.data.video_real_time > 0) {
  210. wx.showToast({
  211. title: '该视频不可以快进哦!',
  212. icon: 'none',
  213. duration: 2000,
  214. })
  215. }
  216. _this.setData({
  217. video_real_time: _this.data.playVideoDuration, //实时播放进度
  218. })
  219. }
  220. if (currentTime > jump_time && currentTime - jump_time < 3 && currentTime > _this.data.playVideoDuration) {
  221. _this.setData({
  222. playVideoDuration: currentTime,
  223. [studyTime]: currentTime
  224. })
  225. }
  226. if (currentTime > jump_time && currentTime - jump_time < 3) {
  227. _this.setData({
  228. video_real_time: currentTime, //实时播放进度
  229. })
  230. }
  231. }
  232. },
  233. // 修改学习进度
  234. chechEndStatus: function () {
  235. let _this = this;
  236. if (this.data.classInfo.id != -1) {
  237. console.log(this.data.video_real_time)
  238. console.log(this.data.courseTime / 1000 - 10)
  239. if (this.data.video_real_time > this.data.courseTime / 1000 - 10) {
  240. let isDone = 'studyLog.isDone'
  241. this.setData({
  242. [isDone]: 1
  243. })
  244. wx.request({
  245. method: "post",
  246. url: app.globalData.publicUrl + '/wx/course/updateStudyLog',
  247. data: {
  248. studyLog: _this.data.studyLog
  249. },
  250. success: (e) => {
  251. wx.showModal({
  252. showCancel: false,
  253. content: "该录播视频已经看完啦,快去参与该节课的考试和评价吧!只有考试和评价都参与了,才可以继续进行下一节哦!",
  254. success(res) {
  255. if (res.confirm) {
  256. wx.navigateBack({
  257. delta: 1
  258. })
  259. }
  260. }
  261. })
  262. }
  263. })
  264. }
  265. }
  266. },
  267. onUnload() {
  268. let _this = this;
  269. if (_this.data.studyLog.isDone != '1') {
  270. if (this.data.video_real_time > this.data.courseTime / 1000 - 10) {
  271. let isDone = 'studyLog.isDone'
  272. this.setData({
  273. [isDone]: 1
  274. })
  275. }
  276. }
  277. if (_this.data.classInfo.id != -1) {
  278. wx.request({
  279. method: "post",
  280. url: app.globalData.publicUrl + '/wx/course/updateStudyLog',
  281. data: {
  282. studyLog: _this.data.studyLog
  283. },
  284. success: (e) => {
  285. console.log(e, "我修改进度成功了")
  286. }
  287. })
  288. }
  289. },
  290. onHide() {
  291. let _this = this;
  292. if (_this.data.studyLog.isDone != '1') {
  293. if (this.data.video_real_time > this.data.courseTime / 1000 - 10) {
  294. let isDone = 'studyLog.isDone'
  295. this.setData({
  296. [isDone]: 1
  297. })
  298. }
  299. }
  300. if (_this.data.classInfo.id != -1) {
  301. wx.request({
  302. method: "post",
  303. url: app.globalData.publicUrl + '/wx/course/updateStudyLog',
  304. data: {
  305. studyLog: _this.data.studyLog
  306. },
  307. success: (e) => {
  308. console.log(e, "我修改进度成功了")
  309. }
  310. })
  311. }
  312. },
  313. // 获取当前网络状态
  314. async getNetStatus() {
  315. return new Promise((resolve, reject) => {
  316. wx.getNetworkType({
  317. success: (res) => {
  318. resolve(res.networkType);
  319. }
  320. })
  321. });
  322. },
  323. async onLoad(options) {
  324. this.setData({
  325. options: options,
  326. id: options.id,
  327. videoContext: wx.createVideoContext('myVideo')
  328. })
  329. const sessionKey = await tools.checkSessionAndLogin();
  330. this.isClass(sessionKey);
  331. this.getStudyLog(sessionKey);
  332. this.getdbArr(sessionKey);
  333. }
  334. })