courseSection.vue 11 KB

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