courseSection.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. },
  94. watch:{
  95. menuItem(val) {
  96. console.log(val,'val')
  97. }
  98. },
  99. data() {
  100. return {
  101. nowTime:0,
  102. newId:0,
  103. playId:'',
  104. clickLock:false, //点击锁,防止连续点击多次
  105. };
  106. },
  107. onLoad() {},
  108. created() {
  109. },
  110. mounted() {
  111. this.nowTime = Number(new Date().getTime()/1000).toFixed(0)
  112. this.newId= this.menuItem.sectionId>0?this.menuItem.sectionId:this.menuItem.menuId
  113. console.log(this.isRebuild)
  114. console.log(this.nextMenuItem,'nextMenuItem')
  115. console.log(this.menuItem,'this.menuItem')
  116. let moduleId = this.menuItem.moduleId || 0;
  117. let chapterId = this.menuItem.chapterId || 0;
  118. let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
  119. let playNextId = `moduleId${moduleId}chapterId${chapterId}sectionId${sectionId}${this.isRebuild?'isRebuild':''}`;
  120. this.playId = playNextId;
  121. uni.$off('playNext'+playNextId) //绑定前先移除之前的事件
  122. uni.$once('playNext'+playNextId, (data) => {
  123. //到时会触发每个节的监听事件,只允许当前节的接收
  124. let self = this
  125. if(this.nextMenuItem.recordingUrl&&this.isRebuild&&(this.newId==this.playSectionId) && data.fromRebuild){ // fromRebuild 来自重修目录的点击才弹出播放下一节
  126. //重修存在下一节
  127. uni.showModal({
  128. title: '提示',
  129. content: '是否播放下一节',
  130. success: function (res) {
  131. if (res.confirm) {
  132. console.log('用户点击确定');
  133. let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
  134. //设置播放的节ID
  135. self.$store.commit('setPlaySectionId', {playSectionId :nextId});
  136. self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
  137. let ids = self.levelId.split('-');
  138. ids[2] = nextId
  139. uni.$emit('levelId', ids.join('-'))
  140. uni.$emit('getSection', self.nextMenuItem)
  141. self.$emit('playEnd',{isRebuild:self.isRebuild})
  142. // uni.$off('playend')
  143. // uni.$on('playend',res => {
  144. // console.log('playend2')
  145. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  146. // })
  147. } else {
  148. let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
  149. //设置播放的节ID
  150. self.$store.commit('setPlaySectionId', {playSectionId :nextId});
  151. self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
  152. let ids = self.levelId.split('-');
  153. ids[2] = nextId
  154. self.$emit('playEnd',{isRebuild:self.isRebuild})
  155. }
  156. }
  157. });
  158. } else {
  159. this.$emit('playEnd',{isRebuild:this.isRebuild})
  160. }
  161. });
  162. },
  163. methods: {
  164. getVideo(){
  165. if(this.clickLock) {
  166. return;
  167. }
  168. this.clickLock = true;
  169. console.log(this.learningOrder,'this.learningOrder')
  170. console.log(this.preItem,'this.preItem')
  171. if(this.learningOrder == 2 && !this.isRebuild) { //要按从头到尾顺序学习, 且不是重修课程
  172. if(this.preItem) {
  173. if(this.preItem.menuType == 3) { //上一个是节
  174. if(this.preItem.learning == 1) { //上一节学完
  175. this.playVideo();
  176. } else {
  177. uni.showToast({
  178. icon:'none',
  179. title:'请按顺序学习视频课程'
  180. })
  181. }
  182. } else if(this.preItem.menuType == 2) { //上一个是章
  183. this.$api.reSectionList({chapterId: this.preItem.menuId || this.preItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.preItem.moduleId || 0}).then(res => {
  184. if(res.data.code==200){
  185. let lastItem = res.data.data[res.data.data.length -1];
  186. if(lastItem.learning == 1) {
  187. this.playVideo();
  188. } else {
  189. uni.showToast({
  190. icon:'none',
  191. title:'请按顺序学习视频课程'
  192. })
  193. }
  194. }
  195. });
  196. } else if(this.preItem.menuType == 1) { //上一个是模块
  197. this.$api.reChapterList({moduleId:this.preItem.menuId,gradeId:this.gradeId,courseId:this.courseId}).then(res => {
  198. if(res.data.code==200){
  199. let lastChapterItem = res.data.data[res.data.data.length -1];
  200. this.$api.reSectionList({chapterId:lastChapterItem.chapterId,gradeId:this.gradeId,courseId:this.courseId,moduleId:this.menuItem.menuId || this.menuItem.moduleId}).then(res => {
  201. if(res.data.code==200){
  202. let lastSectionItem = res.data.data[res.data.data.length -1];
  203. if(lastSectionItem.learning == 1) {
  204. this.playVideo();
  205. } else {
  206. uni.showToast({
  207. icon:'none',
  208. title:'请按顺序学习视频课程'
  209. })
  210. }
  211. }
  212. });
  213. }
  214. });
  215. }
  216. } else { //第一章第一节
  217. this.playVideo();
  218. }
  219. } else {
  220. this.playVideo();
  221. }
  222. setTimeout(() => {
  223. this.clickLock = false;
  224. },3000)
  225. },
  226. playVideo() {
  227. if(this.menuItem.sectionType==1||this.menuItem.sectionType==3){
  228. //录播
  229. if(!this.isBuy){
  230. //非购买
  231. if(!this.menuItem.tryListen){
  232. //不允许试听
  233. this.clickLock = false;
  234. return
  235. }
  236. }
  237. if(!this.menuItem.recordingUrl){
  238. uni.showToast({
  239. title: '暂无播放地址数据',
  240. icon: 'error'
  241. });
  242. this.clickLock = false;
  243. return;
  244. }
  245. /* if(this.playSectionId==this.newId){
  246. //切换为同一节
  247. return
  248. } */
  249. if(this.playSectionId>0){
  250. //切换视频
  251. let oldSectionId = this.playSectionId
  252. uni.$emit('changeSection', oldSectionId)
  253. }
  254. //设置播放的节ID
  255. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  256. this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
  257. this.$store.commit('updatePlayNextId',this.playId)
  258. uni.$emit('levelId', this.levelId)
  259. uni.$emit('getSection', this.menuItem)
  260. uni.$emit('isRebuild',this.isRebuild)
  261. console.log(this.menuItem,'menuItem')
  262. // uni.$off('playend')
  263. // uni.$on('playend',res => {
  264. // console.log('playend2')
  265. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  266. // })
  267. console.log(999)
  268. }
  269. if(this.menuItem.sectionType==2){
  270. //直播
  271. if(!this.isBuy){
  272. //非购买
  273. this.clickLock = false;
  274. return
  275. }
  276. if(!this.menuItem.liveUrl){
  277. uni.showToast({
  278. title: '暂无直播地址数据',
  279. icon: 'error'
  280. });
  281. }
  282. if(this.playSectionId==this.newId){
  283. //切换为同一频道
  284. this.clickLock = false;
  285. return
  286. }
  287. //设置播放的节ID
  288. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  289. this.$store.commit('setPlayChannelId', {playChannelId :this.menuItem.liveUrl});
  290. this.$store.commit('updatePlayNextId',this.playId)
  291. uni.$emit('levelId', this.levelId)
  292. uni.$emit('getChannel', this.menuItem)
  293. uni.$emit('isRebuild',this.isRebuild)
  294. console.log(this.menuItem,'menuItem')
  295. // uni.$off('playend')
  296. // uni.$on('playend',res => {
  297. // console.log('playend1')
  298. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  299. // })
  300. console.log(888)
  301. }
  302. }
  303. },
  304. computed: { ...mapGetters(['playSectionId','playChannelId','playVID','playNextId']) }
  305. };
  306. </script>
  307. <style scoped lang="scss">
  308. .tagGreen{
  309. width: 80rpx;
  310. height: 28rpx;
  311. background: #34C759;
  312. border-radius: 8rpx;
  313. font-size: 20rpx;
  314. color: #FFFFFF;
  315. text-align: center;
  316. }
  317. .tagWillPlay{
  318. width: 80rpx;
  319. height: 28rpx;
  320. background: #EBF4FF;
  321. border-radius: 8rpx;
  322. font-size: 20rpx;
  323. color: #007AFF;
  324. text-align: center;
  325. }
  326. .tagPlaying{
  327. width: 80rpx;
  328. height: 28rpx;
  329. background: #FFF7EB;
  330. border-radius: 8rpx;
  331. font-size: 20rpx;
  332. color: #FF9500;
  333. text-align: center;
  334. }
  335. .tagPlayed{
  336. width: 80rpx;
  337. height: 28rpx;
  338. background: #EEEEEE;
  339. border-radius: 8rpx;
  340. font-size: 20rpx;
  341. color: #666666;
  342. text-align: center;
  343. }
  344. .tagRe{
  345. width: 80rpx;
  346. height: 28rpx;
  347. background: #FF3B30;
  348. border-radius: 8rpx;
  349. font-size: 20rpx;
  350. color: #FFFFFF;
  351. text-align: center;
  352. }
  353. .tryBox{
  354. width: 96rpx;
  355. height: 48rpx;
  356. background: #007AFF;
  357. border-radius: 24rpx;
  358. color: #FFFFFF;
  359. font-size: 30rpx;
  360. line-height: 48rpx;
  361. text-align: center;
  362. }
  363. .icon_up{
  364. width: 24rpx;
  365. height: 24rpx;
  366. }
  367. .t_content3{
  368. color: #007AFF;
  369. }
  370. .t_content2{
  371. color: #007AFF;
  372. }
  373. .t_content1{
  374. color: #007AFF;
  375. }
  376. .t_content{
  377. margin-left: 10rpx;
  378. color: #666666;
  379. flex:1;
  380. }
  381. .tagColor3{
  382. border: 2rpx solid #FF9500;
  383. color: #FF9500;
  384. }
  385. .tagColor2{
  386. border: 2rpx solid #FF3B30;
  387. color: #FF3B30;
  388. }
  389. .tagColor1{
  390. border: 2rpx solid #007AFF;
  391. color: #007AFF;
  392. }
  393. .color3{
  394. color: #FF9500;
  395. }
  396. .color2{
  397. color: #FF3B30;
  398. }
  399. .color1{
  400. color: #007AFF;
  401. }
  402. .tag{
  403. border-radius: 8rpx;
  404. font-size: 20rpx;
  405. padding: 5rpx;
  406. }
  407. </style>