courseSection.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <view style="display: flex;justify-content: space-between;align-items: center;" @click="getVideo">
  3. <view style="display: flex;justify-content: space-between;margin: 20rpx 0;width: 100%;">
  4. <view style="display: flex;align-items: center;flex:1;">
  5. <view class="tag tagColor1" v-if="menuItem.sectionType==1">录播</view>
  6. <view class="tag tagColor2" v-if="menuItem.sectionType==2">直播</view>
  7. <view class="tag tagColor3" v-if="menuItem.sectionType==3">回放</view>
  8. <view class="t_content">
  9. <view v-if="menuItem.sectionType==1" :class="playSectionId==newId && playNextId==playId?'color1':''">{{menuItem.name || ''}}</view>
  10. <view v-if="menuItem.sectionType==2" :class="playSectionId==newId && playNextId==playId?'color2':''">{{menuItem.name || ''}}</view>
  11. <view v-if="menuItem.sectionType==3" :class="playSectionId==newId && playNextId==playId?'color3':''">{{menuItem.name || ''}}</view>
  12. <view style="font-size: 20rpx;color: #FF3B30;" v-if="menuItem.sectionType==2 && menuItem.liveStartTime">
  13. <view v-if="menuItem.liveStartTime>nowTime || !isBuy">
  14. <text>{{$method.timestampToTime(menuItem.liveStartTime, isDay =false)}}</text>-
  15. <text>{{$method.timestampToTime(menuItem.liveEndTime, isDay =false)}}</text>
  16. </view>
  17. <template v-if="isLast()">
  18. <view v-if="liveLast.watchStatus == 'live'">
  19. <text>直播中</text>
  20. </view>
  21. <view v-if="liveLast.watchStatus == 'end'">
  22. <text>当前直播回放视频请稍后再查看</text>
  23. </view>
  24. </template>
  25. <!-- <view v-if="menuItem.liveStartTime<=nowTime&&menuItem.liveEndTime>nowTime">
  26. <text>直播中</text>
  27. </view>
  28. <view v-if="menuItem.liveEndTime<nowTime">
  29. <text>回放</text>
  30. </view> -->
  31. </view>
  32. </view>
  33. <view v-if="menuItem.sectionType==null">{{menuItem.name || ''}}</view>
  34. </view>
  35. <view style="font-size: 20rpx;color: #FF3B30;" v-if="menuItem.liveStartTime && menuItem.sectionType != 3 && isBuy">
  36. <template v-if="!isLast()">
  37. <view class="tagWillPlay" v-if="menuItem.liveStartTime>nowTime">
  38. <text>待开播</text>
  39. </view>
  40. <view class="tagPlaying" v-if="menuItem.liveStartTime<=nowTime&&menuItem.liveEndTime>nowTime">
  41. <text>直播中</text>
  42. </view>
  43. <view class="tagPlayed" v-if="menuItem.liveEndTime<nowTime">
  44. <text>已结束</text>
  45. </view>
  46. </template>
  47. </view>
  48. <!-- 直播课程没有学习状态 -->
  49. <template v-if="!isLive">
  50. <view v-if="(isRebuild||menuItem.rebuild>0)" class="tagRe">待重修</view>
  51. <view v-else>
  52. <view v-if="menuItem.learning==1" class="tagGreen">已看完</view>
  53. </view>
  54. </template>
  55. </view>
  56. <view v-if="menuItem.tryListen&&!isBuy" class="tryBox">
  57. 试看
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import { mapGetters } from 'vuex';
  63. import eventHub from '@/common/eventHub.js'
  64. import {WEBVIEW_URL} from '@/common/request.js'
  65. export default {
  66. name: 'courseSection',
  67. props: {
  68. isLive:false,
  69. orderGoodsId:{
  70. default:0
  71. },
  72. preItem:{
  73. default:undefined,
  74. },
  75. learningOrder:{ //是否设置学习顺序 1 章节顺序 0不设置 2从头学到尾顺序
  76. type:Number,
  77. default:0
  78. },
  79. courseId: {
  80. type: Number,
  81. default: 0
  82. },
  83. goodsId: {
  84. type: Number,
  85. default: 0
  86. },
  87. menuItem: {
  88. type: Object,
  89. default: {}
  90. },
  91. isBuy: {
  92. type: Boolean,
  93. default: false
  94. },
  95. levelId: {
  96. type: String,
  97. default: ""
  98. },
  99. isRebuild: {
  100. type: Boolean,
  101. default: false
  102. },
  103. gradeId: {
  104. type: Number,
  105. default: 0
  106. },
  107. nextMenuItem: {
  108. type: Object,
  109. default: {}
  110. },
  111. sectionMaxNum:{
  112. default:undefined,
  113. },
  114. },
  115. watch:{
  116. menuItem(val) {
  117. console.log(val,'val')
  118. }
  119. },
  120. data() {
  121. return {
  122. nowTime:0,
  123. newId:0,
  124. playId:'',
  125. clickLock:false, //点击锁,防止连续点击多次
  126. };
  127. },
  128. onLoad() {
  129. },
  130. created() {
  131. },
  132. mounted() {
  133. this.nowTime = Number(new Date().getTime()/1000).toFixed(0)
  134. this.newId= this.menuItem.sectionId>0?this.menuItem.sectionId:this.menuItem.menuId
  135. console.log(this.newId,'this.newId')
  136. console.log(this.playSectionId,'this.playSectionId')
  137. console.log(this.isRebuild)
  138. console.log(this.nextMenuItem,'nextMenuItem')
  139. console.log(this.menuItem,'this.menuItem')
  140. let moduleId = this.menuItem.moduleId || 0;
  141. let chapterId = this.menuItem.chapterId || 0;
  142. let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
  143. let playNextId = `moduleId${moduleId}chapterId${chapterId}sectionId${sectionId}${this.isRebuild?'isRebuild':''}`;
  144. this.playId = playNextId;
  145. uni.$off('playNext'+playNextId) //绑定前先移除之前的事件
  146. uni.$once('playNext'+playNextId, (data) => {
  147. //到时会触发每个节的监听事件,只允许当前节的接收
  148. let self = this
  149. if(this.nextMenuItem.recordingUrl&&this.isRebuild&&(this.newId==this.playSectionId) && data.fromRebuild){ // fromRebuild 来自重修目录的点击才弹出播放下一节
  150. //重修存在下一节
  151. uni.showModal({
  152. title: '提示',
  153. content: '是否播放下一节',
  154. success: function (res) {
  155. if (res.confirm) {
  156. console.log('用户点击确定');
  157. let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
  158. //设置播放的节ID
  159. self.$store.commit('setPlaySectionId', {playSectionId :nextId});
  160. self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
  161. let ids = self.levelId.split('-');
  162. ids[2] = nextId
  163. uni.$emit('levelId', ids.join('-'))
  164. uni.$emit('getSection', self.nextMenuItem)
  165. self.$emit('playEnd',{isRebuild:self.isRebuild})
  166. // uni.$off('playend')
  167. // uni.$on('playend',res => {
  168. // console.log('playend2')
  169. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  170. // })
  171. } else {
  172. let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
  173. //设置播放的节ID
  174. self.$store.commit('setPlaySectionId', {playSectionId :nextId});
  175. self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
  176. let ids = self.levelId.split('-');
  177. ids[2] = nextId
  178. self.$emit('playEnd',{isRebuild:self.isRebuild})
  179. }
  180. }
  181. });
  182. } else {
  183. this.$emit('playEnd',{isRebuild:this.isRebuild})
  184. }
  185. });
  186. },
  187. methods: {
  188. isLast() {
  189. if(this.liveLast) {
  190. let sectionASame = this.liveLast.sectionId == (this.menuItem.sectionId || this.menuItem.menuId)
  191. let chapterSame = this.liveLast.chapterId == (this.menuItem.chapterId || 0)
  192. let moduleSame = this.liveLast.moduleId == (this.menuItem.moduleId || 0);
  193. return sectionASame && chapterSame && moduleSame
  194. } else {
  195. return false;
  196. }
  197. },
  198. studyRecordMenuAllList() {
  199. return new Promise(resolve => {
  200. this.$api.studyRecordMenuAllList({
  201. courseId:this.courseId,
  202. gradeId:this.gradeId,
  203. goodsId:this.goodsId
  204. }).then(res => {
  205. if(res.data.code == 200) {
  206. resolve(res.data.data)
  207. }
  208. })
  209. })
  210. },
  211. gradeCheckGoodsStudy() {
  212. let moduleId = this.menuItem.moduleId || 0;
  213. let chapterId = this.menuItem.chapterId || 0;
  214. let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
  215. return new Promise(resolve => {
  216. this.$api.gradeCheckGoodsStudy({
  217. goodsId:this.goodsId,
  218. gradeId:this.gradeId,
  219. moduleId:this.menuItem.moduleId || 0,
  220. chapterId:this.menuItem.chapterId || 0,
  221. sectionId:this.menuItem.sectionId || this.menuItem.menuId
  222. }).then( res => {
  223. resolve(res.data.data)
  224. })
  225. })
  226. },
  227. goodsTodayStudySectionNum() {
  228. return new Promise(resolve => {
  229. this.$api.goodsTodayStudySectionNum({goodsId:this.goodsId,gradeId:this.gradeId}).then(res => {
  230. if(res.data.code == 200) {
  231. resolve(res.data.data)
  232. }
  233. })
  234. })
  235. },
  236. async getVideo(){
  237. if(this.clickLock) {
  238. return;
  239. }
  240. this.clickLock = true;
  241. if(this.learningOrder == 2 && !this.menuItem.isRebuild) { //要按从头到尾顺序学习, 且不是重修课程
  242. if(this.preItem) {
  243. let rows = await this.studyRecordMenuAllList();
  244. let newRows = [];
  245. for(let i = 0; i < rows.length; i++ ) {
  246. let moduleTrue = rows[i].moduleId == this.menuItem.moduleId || rows[i].moduleId == 0
  247. let chapterTrue = rows[i].chapterId == this.menuItem.chapterId || rows[i].chapterId == 0;
  248. let sectionTrue = (rows[i].sectionId == this.menuItem.sectionId) || (rows[i].sectionId == this.menuItem.menuId);
  249. if(moduleTrue && chapterTrue && sectionTrue) {
  250. break;
  251. } else {
  252. if(rows[i].sectionType != 2) {
  253. newRows.push(rows[i])
  254. }
  255. }
  256. }
  257. console.log(newRows)
  258. let isAllLearn = newRows.every(item => {
  259. return item.studyStatus == 1;
  260. })
  261. if(isAllLearn) {
  262. this.playVideo();
  263. } else {
  264. uni.showToast({
  265. icon:'none',
  266. title:'请按顺序学习视频课程'
  267. })
  268. }
  269. // if(this.preItem.menuType == 3) { //上一个是节
  270. // if(this.preItem.learning == 1) { //上一节学完
  271. // this.playVideo();
  272. // } else {
  273. // uni.showToast({
  274. // icon:'none',
  275. // title:'请按顺序学习视频课程'
  276. // })
  277. // }
  278. // } else if(this.preItem.menuType == 2) { //上一个是章
  279. // this.$api.reSectionList({chapterId: this.preItem.menuId || this.preItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.preItem.moduleId || 0}).then(res => {
  280. // if(res.data.code==200){
  281. // let lastItem = res.data.data[res.data.data.length -1];
  282. // if(lastItem.learning == 1) {
  283. // this.playVideo();
  284. // } else {
  285. // uni.showToast({
  286. // icon:'none',
  287. // title:'请按顺序学习视频课程'
  288. // })
  289. // }
  290. // }
  291. // });
  292. // } else if(this.preItem.menuType == 1) { //上一个是模块
  293. // this.$api.reChapterList({moduleId:this.preItem.menuId,gradeId:this.gradeId,courseId:this.courseId}).then(res => {
  294. // if(res.data.code==200){
  295. // let lastChapterItem = res.data.data[res.data.data.length -1];
  296. // this.$api.reSectionList({chapterId:lastChapterItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.menuItem.menuId || this.menuItem.moduleId}).then(res => {
  297. // if(res.data.code==200){
  298. // let lastSectionItem = res.data.data[res.data.data.length -1];
  299. // if(lastSectionItem.learning == 1) {
  300. // this.playVideo();
  301. // } else {
  302. // uni.showToast({
  303. // icon:'none',
  304. // title:'请按顺序学习视频课程'
  305. // })
  306. // }
  307. // }
  308. // });
  309. // }
  310. // });
  311. // }
  312. } else { //第一章第一节
  313. this.playVideo();
  314. }
  315. } else {
  316. this.playVideo();
  317. }
  318. setTimeout(() => {
  319. this.clickLock = false;
  320. },3000)
  321. },
  322. async playVideo() {
  323. if(this.menuItem.sectionType==1||this.menuItem.sectionType==3){
  324. //录播
  325. if(!this.isBuy){
  326. //非购买
  327. if(!this.menuItem.tryListen){
  328. //不允许试听
  329. this.clickLock = false;
  330. return
  331. } else {
  332. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  333. this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
  334. this.menuItem.courseId = this.courseId;
  335. uni.$emit('getSection', this.menuItem)
  336. return;
  337. }
  338. }
  339. let learnNum = await this.goodsTodayStudySectionNum()
  340. let hasLearn = await this.gradeCheckGoodsStudy();
  341. console.log(this.sectionMaxNum,'this.sectionMaxNum')
  342. console.log(learnNum,'learnNum')
  343. if(this.sectionMaxNum > 0) {
  344. if(learnNum >= this.sectionMaxNum && !hasLearn) {
  345. uni.showToast({
  346. icon:'none',
  347. title:`每天最多学习${this.sectionMaxNum}节`
  348. })
  349. this.clickLock = false;
  350. return;
  351. }
  352. }
  353. if(!this.menuItem.recordingUrl){
  354. uni.showToast({
  355. title: '暂无播放地址数据',
  356. icon: 'error'
  357. });
  358. this.clickLock = false;
  359. return;
  360. }
  361. /* if(this.playSectionId==this.newId){
  362. //切换为同一节
  363. return
  364. } */
  365. if(this.playSectionId>0){
  366. //切换视频
  367. let oldSectionId = this.playSectionId
  368. uni.$emit('changeSection', oldSectionId)
  369. }
  370. //设置播放的节ID
  371. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  372. this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
  373. this.$store.commit('updatePlayNextId',this.playId)
  374. uni.$emit('levelId', this.levelId)
  375. uni.$emit('getSection', this.menuItem)
  376. uni.$emit('isRebuild',this.isRebuild)
  377. console.log(this.menuItem,'menuItem')
  378. // uni.$off('playend')
  379. // uni.$on('playend',res => {
  380. // console.log('playend2')
  381. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  382. // })
  383. console.log(999)
  384. }
  385. if(this.menuItem.sectionType==2){
  386. //直播
  387. if(!this.isBuy){
  388. //非购买
  389. this.clickLock = false;
  390. return
  391. }
  392. let learnNum = await this.goodsTodayStudySectionNum()
  393. let hasLearn = await this.gradeCheckGoodsStudy();
  394. console.log(this.sectionMaxNum,'this.sectionMaxNum')
  395. console.log(learnNum,'learnNum')
  396. if(this.sectionMaxNum > 0) {
  397. if(learnNum >= this.sectionMaxNum && !hasLearn) {
  398. uni.showToast({
  399. icon:'none',
  400. title:`每天最多学习${this.sectionMaxNum}节`
  401. })
  402. this.clickLock = false;
  403. return;
  404. }
  405. }
  406. if(!this.menuItem.liveUrl){
  407. uni.showToast({
  408. title: '暂无直播地址数据',
  409. icon: 'error'
  410. });
  411. }
  412. if(this.playSectionId==this.newId){
  413. //切换为同一频道
  414. this.clickLock = false;
  415. return
  416. }
  417. let moduleId = this.menuItem.moduleId || 0;
  418. let chapterId = this.menuItem.chapterId || 0;
  419. let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
  420. let encode = encodeURIComponent(WEBVIEW_URL+'pages/live/index?token='+uni.getStorageSync('token')+'&userInfo='+JSON.stringify(this.userInfo)+'&channelId='+this.menuItem.liveUrl+'&gradeId='+this.gradeId+'&courseId='+this.courseId+'&goodsId='+this.goodsId+'&orderGoodsId='+this.orderGoodsId+'&sectionId='+sectionId+'&chapterId='+chapterId+'&moduleId='+moduleId)
  421. uni.navigateTo({
  422. url:`../../pages/webview/index?url=`+encode
  423. })
  424. return;
  425. //设置播放的节ID
  426. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  427. this.$store.commit('setPlayChannelId', {playChannelId :this.menuItem.liveUrl});
  428. this.$store.commit('updatePlayNextId',this.playId)
  429. uni.$emit('levelId', this.levelId)
  430. uni.$emit('getChannel', this.menuItem)
  431. uni.$emit('isRebuild',this.isRebuild)
  432. console.log(this.menuItem,'menuItem')
  433. // uni.$off('playend')
  434. // uni.$on('playend',res => {
  435. // console.log('playend1')
  436. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  437. // })
  438. console.log(888)
  439. }
  440. }
  441. },
  442. computed: { ...mapGetters(['playSectionId','playChannelId','playVID','playNextId','userInfo','liveLast']) }
  443. };
  444. </script>
  445. <style scoped lang="scss">
  446. .tagGreen{
  447. width: 80rpx;
  448. height: 28rpx;
  449. background: #34C759;
  450. border-radius: 8rpx;
  451. font-size: 20rpx;
  452. color: #FFFFFF;
  453. text-align: center;
  454. }
  455. .tagWillPlay{
  456. width: 80rpx;
  457. height: 28rpx;
  458. background: #EBF4FF;
  459. border-radius: 8rpx;
  460. font-size: 20rpx;
  461. color: #007AFF;
  462. text-align: center;
  463. }
  464. .tagPlaying{
  465. width: 80rpx;
  466. height: 28rpx;
  467. background: #FFF7EB;
  468. border-radius: 8rpx;
  469. font-size: 20rpx;
  470. color: #FF9500;
  471. text-align: center;
  472. }
  473. .tagPlayed{
  474. width: 80rpx;
  475. height: 28rpx;
  476. background: #EEEEEE;
  477. border-radius: 8rpx;
  478. font-size: 20rpx;
  479. color: #666666;
  480. text-align: center;
  481. }
  482. .tagRe{
  483. width: 80rpx;
  484. height: 28rpx;
  485. background: #FF3B30;
  486. border-radius: 8rpx;
  487. font-size: 20rpx;
  488. color: #FFFFFF;
  489. text-align: center;
  490. }
  491. .tryBox{
  492. width: 96rpx;
  493. height: 48rpx;
  494. background: #007AFF;
  495. border-radius: 24rpx;
  496. color: #FFFFFF;
  497. font-size: 30rpx;
  498. line-height: 48rpx;
  499. text-align: center;
  500. }
  501. .icon_up{
  502. width: 24rpx;
  503. height: 24rpx;
  504. }
  505. .t_content3{
  506. color: #007AFF;
  507. }
  508. .t_content2{
  509. color: #007AFF;
  510. }
  511. .t_content1{
  512. color: #007AFF;
  513. }
  514. .t_content{
  515. font-size: 30rpx;
  516. margin-left: 10rpx;
  517. color: #666666;
  518. flex:1;
  519. }
  520. .tagColor3{
  521. border: 2rpx solid #FF9500;
  522. color: #FF9500;
  523. }
  524. .tagColor2{
  525. border: 2rpx solid #FF3B30;
  526. color: #FF3B30;
  527. }
  528. .tagColor1{
  529. border: 2rpx solid #007AFF;
  530. color: #007AFF;
  531. }
  532. .color3{
  533. color: #FF9500;
  534. }
  535. .color2{
  536. color: #FF3B30;
  537. }
  538. .color1{
  539. color: #007AFF;
  540. }
  541. .tag{
  542. border-radius: 8rpx;
  543. font-size: 20rpx;
  544. padding: 5rpx;
  545. }
  546. </style>