courseSection.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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) && menuItem.sectionType != 3" class="tagRe">待重修</view>
  39. <view v-else>
  40. <view v-if="menuItem.learning==1 && menuItem.sectionType != 3" 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. uni.$on('playNext', () => {
  105. //到时会触发每个节的监听事件,只允许当前节的接收
  106. if(this.nextMenuItem.recordingUrl&&this.isRebuild&&(this.newId==this.playSectionId)){
  107. //重修存在下一节
  108. uni.showModal({
  109. title: '提示',
  110. content: '是否播放下一节',
  111. success: function (res) {
  112. if (res.confirm) {
  113. console.log('用户点击确定');
  114. let nextId= this.nextMenuItem.sectionId>0?this.nextMenuItem.sectionId:this.nextMenuItem.menuId
  115. //设置播放的节ID
  116. this.$store.commit('setPlaySectionId', {playSectionId :nextId});
  117. this.$store.commit('setPlayVID', {playVID :this.nextMenuItem.recordingUrl});
  118. let ids = this.levelId.split('-');
  119. ids[2] = nextId
  120. uni.$emit('levelId', ids.join('-'))
  121. uni.$emit('getSection', this.nextMenuItem)
  122. }
  123. }
  124. });
  125. }
  126. });
  127. },
  128. methods: {
  129. getVideo(){
  130. console.log(this.menuItem)
  131. if(this.menuItem.sectionType==1||this.menuItem.sectionType==3){
  132. //录播
  133. if(!this.isBuy){
  134. //非购买
  135. if(!this.menuItem.tryListen){
  136. //不允许试听
  137. return
  138. }
  139. }
  140. if(!this.menuItem.recordingUrl){
  141. uni.showToast({
  142. title: '暂无播放地址数据',
  143. icon: 'error'
  144. });
  145. }
  146. if(this.playSectionId==this.newId){
  147. //切换为同一节
  148. return
  149. }
  150. if(this.playSectionId>0){
  151. //切换视频
  152. let oldSectionId = this.playSectionId
  153. uni.$emit('changeSection', oldSectionId)
  154. }
  155. //设置播放的节ID
  156. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  157. this.$store.commit('setPlayVID', {playVID :this.menuItem.recordingUrl});
  158. uni.$emit('levelId', this.levelId)
  159. uni.$emit('getSection', this.menuItem)
  160. uni.$on('playEnd',res => {
  161. console.log(1)
  162. uni.$off('playEnd')
  163. this.$emit('playEnd')
  164. })
  165. }
  166. if(this.menuItem.sectionType==2){
  167. //直播
  168. if(!this.isBuy){
  169. //非购买
  170. return
  171. }
  172. if(!this.menuItem.liveUrl){
  173. uni.showToast({
  174. title: '暂无直播地址数据',
  175. icon: 'error'
  176. });
  177. }
  178. if(this.playSectionId==this.newId){
  179. //切换为同一频道
  180. return
  181. }
  182. //设置播放的节ID
  183. this.$store.commit('setPlaySectionId', {playSectionId :this.newId});
  184. this.$store.commit('setPlayChannelId', {playChannelId :this.menuItem.liveUrl});
  185. uni.$emit('levelId', this.levelId)
  186. uni.$emit('getChannel', this.menuItem)
  187. uni.$on('playEnd',res => { //绑定播放结束,刷新章节列表
  188. uni.$off('playEnd')
  189. this.$emit('playEnd')
  190. })
  191. }
  192. }
  193. },
  194. computed: { ...mapGetters(['playSectionId','playChannelId','playVID']) }
  195. };
  196. </script>
  197. <style scoped lang="scss">
  198. .tagGreen{
  199. width: 80rpx;
  200. height: 28rpx;
  201. background: #34C759;
  202. border-radius: 8rpx;
  203. font-size: 20rpx;
  204. color: #FFFFFF;
  205. text-align: center;
  206. }
  207. .tagWillPlay{
  208. width: 80rpx;
  209. height: 28rpx;
  210. background: #EBF4FF;
  211. border-radius: 8rpx;
  212. font-size: 20rpx;
  213. color: #007AFF;
  214. text-align: center;
  215. }
  216. .tagPlaying{
  217. width: 80rpx;
  218. height: 28rpx;
  219. background: #FFF7EB;
  220. border-radius: 8rpx;
  221. font-size: 20rpx;
  222. color: #FF9500;
  223. text-align: center;
  224. }
  225. .tagPlayed{
  226. width: 80rpx;
  227. height: 28rpx;
  228. background: #EEEEEE;
  229. border-radius: 8rpx;
  230. font-size: 20rpx;
  231. color: #666666;
  232. text-align: center;
  233. }
  234. .tagRe{
  235. width: 80rpx;
  236. height: 28rpx;
  237. background: #FF3B30;
  238. border-radius: 8rpx;
  239. font-size: 20rpx;
  240. color: #FFFFFF;
  241. text-align: center;
  242. }
  243. .tryBox{
  244. width: 96rpx;
  245. height: 48rpx;
  246. background: #007AFF;
  247. border-radius: 24rpx;
  248. color: #FFFFFF;
  249. font-size: 30rpx;
  250. line-height: 48rpx;
  251. text-align: center;
  252. }
  253. .icon_up{
  254. width: 24rpx;
  255. height: 24rpx;
  256. }
  257. .t_content3{
  258. color: #007AFF;
  259. }
  260. .t_content2{
  261. color: #007AFF;
  262. }
  263. .t_content1{
  264. color: #007AFF;
  265. }
  266. .t_content{
  267. margin-left: 10rpx;
  268. color: #666666;
  269. flex:1;
  270. }
  271. .tagColor3{
  272. border: 2rpx solid #FF9500;
  273. color: #FF9500;
  274. }
  275. .tagColor2{
  276. border: 2rpx solid #FF3B30;
  277. color: #FF3B30;
  278. }
  279. .tagColor1{
  280. border: 2rpx solid #007AFF;
  281. color: #007AFF;
  282. }
  283. .color3{
  284. color: #FF9500;
  285. }
  286. .color2{
  287. color: #FF3B30;
  288. }
  289. .color1{
  290. color: #007AFF;
  291. }
  292. .tag{
  293. border-radius: 8rpx;
  294. font-size: 20rpx;
  295. padding: 5rpx;
  296. }
  297. </style>