courseSection.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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. goodsTodayStudySectionNum() {
  169. return new Promise(resolve => {
  170. this.$api.goodsTodayStudySectionNum({goodsId:this.goodsId,gradeId:this.gradeId}).then(res => {
  171. if(res.data.code == 200) {
  172. resolve(res.data.data)
  173. }
  174. })
  175. })
  176. },
  177. async getVideo(){
  178. if(this.clickLock) {
  179. return;
  180. }
  181. this.clickLock = true;
  182. console.log(this.learningOrder,'this.learningOrder')
  183. console.log(this.preItem,'this.preItem')
  184. // let learnNum = await this.goodsTodayStudySectionNum()
  185. // if(this.sectionMaxNum > 0) {
  186. // if(learnNum >= this.sectionMaxNum) {
  187. // uni.showToast({
  188. // icon:'none',
  189. // title:`每天最多学习${this.sectionMaxNum}节`
  190. // })
  191. // return;
  192. // }
  193. // }
  194. if(this.learningOrder == 2 && !this.isRebuild) { //要按从头到尾顺序学习, 且不是重修课程
  195. if(this.preItem) {
  196. if(this.preItem.menuType == 3) { //上一个是节
  197. if(this.preItem.learning == 1) { //上一节学完
  198. this.playVideo();
  199. } else {
  200. uni.showToast({
  201. icon:'none',
  202. title:'请按顺序学习视频课程'
  203. })
  204. }
  205. } else if(this.preItem.menuType == 2) { //上一个是章
  206. this.$api.reSectionList({chapterId: this.preItem.menuId || this.preItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.preItem.moduleId || 0}).then(res => {
  207. if(res.data.code==200){
  208. let lastItem = res.data.data[res.data.data.length -1];
  209. if(lastItem.learning == 1) {
  210. this.playVideo();
  211. } else {
  212. uni.showToast({
  213. icon:'none',
  214. title:'请按顺序学习视频课程'
  215. })
  216. }
  217. }
  218. });
  219. } else if(this.preItem.menuType == 1) { //上一个是模块
  220. this.$api.reChapterList({moduleId:this.preItem.menuId,gradeId:this.gradeId,courseId:this.courseId}).then(res => {
  221. if(res.data.code==200){
  222. let lastChapterItem = res.data.data[res.data.data.length -1];
  223. this.$api.reSectionList({chapterId:lastChapterItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.menuItem.menuId || this.menuItem.moduleId}).then(res => {
  224. if(res.data.code==200){
  225. let lastSectionItem = res.data.data[res.data.data.length -1];
  226. if(lastSectionItem.learning == 1) {
  227. this.playVideo();
  228. } else {
  229. uni.showToast({
  230. icon:'none',
  231. title:'请按顺序学习视频课程'
  232. })
  233. }
  234. }
  235. });
  236. }
  237. });
  238. }
  239. } else { //第一章第一节
  240. this.playVideo();
  241. }
  242. } else {
  243. this.playVideo();
  244. }
  245. setTimeout(() => {
  246. this.clickLock = false;
  247. },3000)
  248. },
  249. playVideo() {
  250. if(this.menuItem.sectionType==1||this.menuItem.sectionType==3){
  251. //录播
  252. if(!this.isBuy){
  253. //非购买
  254. if(!this.menuItem.tryListen){
  255. //不允许试听
  256. this.clickLock = false;
  257. return
  258. }
  259. }
  260. if(!this.menuItem.recordingUrl){
  261. uni.showToast({
  262. title: '暂无播放地址数据',
  263. icon: 'error'
  264. });
  265. this.clickLock = false;
  266. return;
  267. }
  268. /* if(this.playSectionId==this.newId){
  269. //切换为同一节
  270. return
  271. } */
  272. if(this.playSectionId>0){
  273. //切换视频
  274. let oldSectionId = this.playSectionId
  275. uni.$emit('changeSection', oldSectionId)
  276. }
  277. //设置播放的节ID
  278. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  279. this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
  280. this.$store.commit('updatePlayNextId',this.playId)
  281. uni.$emit('levelId', this.levelId)
  282. uni.$emit('getSection', this.menuItem)
  283. uni.$emit('isRebuild',this.isRebuild)
  284. console.log(this.menuItem,'menuItem')
  285. // uni.$off('playend')
  286. // uni.$on('playend',res => {
  287. // console.log('playend2')
  288. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  289. // })
  290. console.log(999)
  291. }
  292. if(this.menuItem.sectionType==2){
  293. //直播
  294. if(!this.isBuy){
  295. //非购买
  296. this.clickLock = false;
  297. return
  298. }
  299. if(!this.menuItem.liveUrl){
  300. uni.showToast({
  301. title: '暂无直播地址数据',
  302. icon: 'error'
  303. });
  304. }
  305. if(this.playSectionId==this.newId){
  306. //切换为同一频道
  307. this.clickLock = false;
  308. return
  309. }
  310. //设置播放的节ID
  311. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  312. this.$store.commit('setPlayChannelId', {playChannelId :this.menuItem.liveUrl});
  313. this.$store.commit('updatePlayNextId',this.playId)
  314. uni.$emit('levelId', this.levelId)
  315. uni.$emit('getChannel', this.menuItem)
  316. uni.$emit('isRebuild',this.isRebuild)
  317. console.log(this.menuItem,'menuItem')
  318. // uni.$off('playend')
  319. // uni.$on('playend',res => {
  320. // console.log('playend1')
  321. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  322. // })
  323. console.log(888)
  324. }
  325. }
  326. },
  327. computed: { ...mapGetters(['playSectionId','playChannelId','playVID','playNextId']) }
  328. };
  329. </script>
  330. <style scoped lang="scss">
  331. .tagGreen{
  332. width: 80rpx;
  333. height: 28rpx;
  334. background: #34C759;
  335. border-radius: 8rpx;
  336. font-size: 20rpx;
  337. color: #FFFFFF;
  338. text-align: center;
  339. }
  340. .tagWillPlay{
  341. width: 80rpx;
  342. height: 28rpx;
  343. background: #EBF4FF;
  344. border-radius: 8rpx;
  345. font-size: 20rpx;
  346. color: #007AFF;
  347. text-align: center;
  348. }
  349. .tagPlaying{
  350. width: 80rpx;
  351. height: 28rpx;
  352. background: #FFF7EB;
  353. border-radius: 8rpx;
  354. font-size: 20rpx;
  355. color: #FF9500;
  356. text-align: center;
  357. }
  358. .tagPlayed{
  359. width: 80rpx;
  360. height: 28rpx;
  361. background: #EEEEEE;
  362. border-radius: 8rpx;
  363. font-size: 20rpx;
  364. color: #666666;
  365. text-align: center;
  366. }
  367. .tagRe{
  368. width: 80rpx;
  369. height: 28rpx;
  370. background: #FF3B30;
  371. border-radius: 8rpx;
  372. font-size: 20rpx;
  373. color: #FFFFFF;
  374. text-align: center;
  375. }
  376. .tryBox{
  377. width: 96rpx;
  378. height: 48rpx;
  379. background: #007AFF;
  380. border-radius: 24rpx;
  381. color: #FFFFFF;
  382. font-size: 30rpx;
  383. line-height: 48rpx;
  384. text-align: center;
  385. }
  386. .icon_up{
  387. width: 24rpx;
  388. height: 24rpx;
  389. }
  390. .t_content3{
  391. color: #007AFF;
  392. }
  393. .t_content2{
  394. color: #007AFF;
  395. }
  396. .t_content1{
  397. color: #007AFF;
  398. }
  399. .t_content{
  400. margin-left: 10rpx;
  401. color: #666666;
  402. flex:1;
  403. }
  404. .tagColor3{
  405. border: 2rpx solid #FF9500;
  406. color: #FF9500;
  407. }
  408. .tagColor2{
  409. border: 2rpx solid #FF3B30;
  410. color: #FF3B30;
  411. }
  412. .tagColor1{
  413. border: 2rpx solid #007AFF;
  414. color: #007AFF;
  415. }
  416. .color3{
  417. color: #FF9500;
  418. }
  419. .color2{
  420. color: #FF3B30;
  421. }
  422. .color1{
  423. color: #007AFF;
  424. }
  425. .tag{
  426. border-radius: 8rpx;
  427. font-size: 20rpx;
  428. padding: 5rpx;
  429. }
  430. </style>