dbDetails.js 8.6 KB

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