courseSection.vue 13 KB

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