courseSection.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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?'color1':''">{{menuItem.name}}</view>
  10. <view v-if="menuItem.sectionType==2" :class="playSectionId==newId?'color2':''">{{menuItem.name}}</view>
  11. <view v-if="menuItem.sectionType==3" :class="playSectionId==newId?'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. courseId: {
  55. type: Number,
  56. default: 0
  57. },
  58. goodsId: {
  59. type: Number,
  60. default: 0
  61. },
  62. menuItem: {
  63. type: Object,
  64. default: {}
  65. },
  66. isBuy: {
  67. type: Boolean,
  68. default: false
  69. },
  70. levelId: {
  71. type: String,
  72. default: ""
  73. },
  74. isRebuild: {
  75. type: Boolean,
  76. default: false
  77. },
  78. gradeId: {
  79. type: Number,
  80. default: 0
  81. },
  82. nextMenuItem: {
  83. type: Object,
  84. default: {}
  85. },
  86. },
  87. watch:{
  88. menuItem(val) {
  89. console.log(val,'val')
  90. }
  91. },
  92. data() {
  93. return {
  94. nowTime:0,
  95. newId:0
  96. };
  97. },
  98. onLoad() {},
  99. created() {
  100. },
  101. mounted() {
  102. this.nowTime = Number(new Date().getTime()/1000).toFixed(0)
  103. this.newId= this.menuItem.sectionId>0?this.menuItem.sectionId:this.menuItem.menuId
  104. console.log(this.isRebuild)
  105. console.log(this.nextMenuItem,'nextMenuItem')
  106. console.log(this.menuItem,'this.menuItem')
  107. let moduleId = this.menuItem.moduleId || 0;
  108. let chapterId = this.menuItem.chapterId || 0;
  109. let sectionId = this.menuItem.sectionId || this.menuItem.menuId;
  110. let playNextId = `moduleId${moduleId}chapterId${chapterId}sectionId${sectionId}${this.isRebuild?'isRebuild':''}`;
  111. uni.$off('playNext'+playNextId) //绑定前先移除之前的事件
  112. uni.$once('playNext'+playNextId, (data) => {
  113. //到时会触发每个节的监听事件,只允许当前节的接收
  114. let self = this
  115. if(this.nextMenuItem.recordingUrl&&this.isRebuild&&(this.newId==this.playSectionId) && data.fromRebuild){ // fromRebuild 来自重修目录的点击才弹出播放下一节
  116. //重修存在下一节
  117. uni.showModal({
  118. title: '提示',
  119. content: '是否播放下一节',
  120. success: function (res) {
  121. if (res.confirm) {
  122. console.log('用户点击确定');
  123. let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
  124. //设置播放的节ID
  125. self.$store.commit('setPlaySectionId', {playSectionId :nextId});
  126. self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
  127. let ids = self.levelId.split('-');
  128. ids[2] = nextId
  129. uni.$emit('levelId', ids.join('-'))
  130. uni.$emit('getSection', self.nextMenuItem)
  131. self.$emit('playEnd',{isRebuild:self.isRebuild})
  132. // uni.$off('playend')
  133. // uni.$on('playend',res => {
  134. // console.log('playend2')
  135. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  136. // })
  137. } else {
  138. let nextId= self.nextMenuItem.sectionId>0?self.nextMenuItem.sectionId:self.nextMenuItem.menuId
  139. //设置播放的节ID
  140. self.$store.commit('setPlaySectionId', {playSectionId :nextId});
  141. self.$store.commit('setPlayVID', {playVID :self.nextMenuItem.recordingUrl});
  142. let ids = self.levelId.split('-');
  143. ids[2] = nextId
  144. self.$emit('playEnd',{isRebuild:self.isRebuild})
  145. }
  146. }
  147. });
  148. } else {
  149. this.$emit('playEnd',{isRebuild:this.isRebuild})
  150. }
  151. });
  152. },
  153. methods: {
  154. getVideo(){
  155. if(this.menuItem.sectionType==1||this.menuItem.sectionType==3){
  156. //录播
  157. if(!this.isBuy){
  158. //非购买
  159. if(!this.menuItem.tryListen){
  160. //不允许试听
  161. return
  162. }
  163. }
  164. if(!this.menuItem.recordingUrl){
  165. uni.showToast({
  166. title: '暂无播放地址数据',
  167. icon: 'error'
  168. });
  169. }
  170. /* if(this.playSectionId==this.newId){
  171. //切换为同一节
  172. return
  173. } */
  174. if(this.playSectionId>0){
  175. //切换视频
  176. let oldSectionId = this.playSectionId
  177. uni.$emit('changeSection', oldSectionId)
  178. }
  179. //设置播放的节ID
  180. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  181. this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
  182. uni.$emit('levelId', this.levelId)
  183. uni.$emit('getSection', this.menuItem)
  184. uni.$emit('isRebuild',this.isRebuild)
  185. console.log(this.menuItem,'menuItem')
  186. // uni.$off('playend')
  187. // uni.$on('playend',res => {
  188. // console.log('playend2')
  189. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  190. // })
  191. console.log(999)
  192. }
  193. if(this.menuItem.sectionType==2){
  194. //直播
  195. if(!this.isBuy){
  196. //非购买
  197. return
  198. }
  199. if(!this.menuItem.liveUrl){
  200. uni.showToast({
  201. title: '暂无直播地址数据',
  202. icon: 'error'
  203. });
  204. }
  205. if(this.playSectionId==this.newId){
  206. //切换为同一频道
  207. return
  208. }
  209. //设置播放的节ID
  210. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  211. this.$store.commit('setPlayChannelId', {playChannelId :this.menuItem.liveUrl});
  212. uni.$emit('levelId', this.levelId)
  213. uni.$emit('getChannel', this.menuItem)
  214. uni.$emit('isRebuild',this.isRebuild)
  215. console.log(this.menuItem,'menuItem')
  216. // uni.$off('playend')
  217. // uni.$on('playend',res => {
  218. // console.log('playend1')
  219. // this.$emit('playEnd',{isRebuild:this.isRebuild})
  220. // })
  221. console.log(888)
  222. }
  223. }
  224. },
  225. computed: { ...mapGetters(['playSectionId','playChannelId','playVID']) }
  226. };
  227. </script>
  228. <style scoped lang="scss">
  229. .tagGreen{
  230. width: 80rpx;
  231. height: 28rpx;
  232. background: #34C759;
  233. border-radius: 8rpx;
  234. font-size: 20rpx;
  235. color: #FFFFFF;
  236. text-align: center;
  237. }
  238. .tagWillPlay{
  239. width: 80rpx;
  240. height: 28rpx;
  241. background: #EBF4FF;
  242. border-radius: 8rpx;
  243. font-size: 20rpx;
  244. color: #007AFF;
  245. text-align: center;
  246. }
  247. .tagPlaying{
  248. width: 80rpx;
  249. height: 28rpx;
  250. background: #FFF7EB;
  251. border-radius: 8rpx;
  252. font-size: 20rpx;
  253. color: #FF9500;
  254. text-align: center;
  255. }
  256. .tagPlayed{
  257. width: 80rpx;
  258. height: 28rpx;
  259. background: #EEEEEE;
  260. border-radius: 8rpx;
  261. font-size: 20rpx;
  262. color: #666666;
  263. text-align: center;
  264. }
  265. .tagRe{
  266. width: 80rpx;
  267. height: 28rpx;
  268. background: #FF3B30;
  269. border-radius: 8rpx;
  270. font-size: 20rpx;
  271. color: #FFFFFF;
  272. text-align: center;
  273. }
  274. .tryBox{
  275. width: 96rpx;
  276. height: 48rpx;
  277. background: #007AFF;
  278. border-radius: 24rpx;
  279. color: #FFFFFF;
  280. font-size: 30rpx;
  281. line-height: 48rpx;
  282. text-align: center;
  283. }
  284. .icon_up{
  285. width: 24rpx;
  286. height: 24rpx;
  287. }
  288. .t_content3{
  289. color: #007AFF;
  290. }
  291. .t_content2{
  292. color: #007AFF;
  293. }
  294. .t_content1{
  295. color: #007AFF;
  296. }
  297. .t_content{
  298. margin-left: 10rpx;
  299. color: #666666;
  300. flex:1;
  301. }
  302. .tagColor3{
  303. border: 2rpx solid #FF9500;
  304. color: #FF9500;
  305. }
  306. .tagColor2{
  307. border: 2rpx solid #FF3B30;
  308. color: #FF3B30;
  309. }
  310. .tagColor1{
  311. border: 2rpx solid #007AFF;
  312. color: #007AFF;
  313. }
  314. .color3{
  315. color: #FF9500;
  316. }
  317. .color2{
  318. color: #FF3B30;
  319. }
  320. .color1{
  321. color: #007AFF;
  322. }
  323. .tag{
  324. border-radius: 8rpx;
  325. font-size: 20rpx;
  326. padding: 5rpx;
  327. }
  328. </style>