catalogue.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <view class="content">
  3. <es-nav-bg title="课程目录"></es-nav-bg>
  4. <!-- <view class="es-view-w-x es-mt-10">
  5. <view class="banner es-icon-auto es-br-20">
  6. <image :src="data.imgUrl"></image>
  7. </view>
  8. </view> -->
  9. <view class="video es-mt-10 es-ml-20 es-mr-20 es-mb-10 es-br-10">
  10. <video ref="myVideo" id="myVideo" :src="pickCatalog.videoUrl"
  11. @error="videoErrorCallback" :enable-progress-gesture="data.isFast==1" :enable-danmu="false" :danmu-btn="false" :danmu-list="danmuList" :initial-time="studyTimes"
  12. :poster="poster" objectFit="contain" :show-progress="data.isFast==1" :title="pickCatalog.courseName" :controls="true" :show-fullscreen-btn="true" @controlstoggle="toggleBarChange"
  13. @timeupdate="onTimeUpdate" @fullscreenchange="onFullscreenChange" @loadedmetadata="onLoadedMetadata" >
  14. </video>
  15. <!-- #ifdef APP-PLUS -->
  16. <cover-image src="/static/images/other/yuan-1.png" class="video-1"></cover-image>
  17. <cover-image src="/static/images/other/yuan-2.png" class="video-2"></cover-image>
  18. <cover-image src="/static/images/other/yuan-3.png" class="video-3"></cover-image>
  19. <cover-image src="/static/images/other/yuan-4.png" class="video-4"></cover-image>
  20. <!-- #endif -->
  21. </view>
  22. <view class="es-bc-white es-br-20" style="margin-top: -194rpx;min-height: 300rpx;">
  23. <view class="es-h-194"></view>
  24. <view class="es-view-w-x es-mt-25">
  25. <view class="es es-ac">
  26. <view class="es-icon es-w-35 es-h-31 es-icon-course-icon-6"></view>
  27. <view class="es-ml-20 es-fs-30 es-fw-600 es-f1">目录<text
  28. class="es-ml-1 es-fs-24 es-c-99">({{catalogueList.length}})</text></view>
  29. <!-- <view class="es-icon-25 es-icon-course-close"></view> -->
  30. </view>
  31. <view class="es-f1 es-bc-fa es-h-70 es-br es es-ac es-mt-30">
  32. <view class="es-icon-26 es-ml-27 es-icon-search-search"></view>
  33. <view class="es-f1 es-ipt es-bc-white">
  34. <input v-model="searchText" placeholder="请输入关键字搜索" class="es-fs-24" placeholder-class="es-c-b4" />
  35. </view>
  36. <view @tap="search()" class="es-w-108 es-h-58 es-br es-bc es-mr-7 es es-ac es-pc es-fw-500 es-fs-26 es-on-act">搜索
  37. </view>
  38. </view>
  39. <!-- 下面是目录列表 -->
  40. <view v-for="(item, index) in catalogueList" :key="index" @click="pickCatalogAction(index)"
  41. style="min-height: 100rpx;box-sizing: border-box;padding: 20rpx;"
  42. class="es-mt-20 es es-ac es-icon-auto es-view-w-x"
  43. :class="index==pickCatalogIdx?'es-icon-course-cate-bg1 es-c':'es-icon-course-cate-bg2'">
  44. <view class="es-f1">
  45. <view class="es es-ac es-fs-28 es-fw-600">
  46. <text>第{{item.courseSort}}讲</text>
  47. <view class="es-w-60 es-h-31 es-ml-10 es-icon-course-play-loading es-icon" v-if="index==pickCatalogIdx"></view>
  48. </view>
  49. <view class="es-fs-22 es-mt-4">{{item.title}}</view>
  50. </view>
  51. <view
  52. :class="item.courseSort>2 && canShowVip(item) ? 'freeflag freeflag-member':'freeflag freeflag-free'">
  53. <text class="es-fs-22 es-fw-500" style="color: #fff;">
  54. {{ item.courseSort>2 && canShowVip(item) ? '限时特惠' : '免费'}}
  55. </text>
  56. </view>
  57. <!-- <view class="vip es-icon-auto es-icon-course-cate-bg3 es-w-87 es-h-42 es es-ac es-fs-22 es es-ac es-pc" v-if="index!=pickCatalogIdx">
  58. <view class="es-icon-22 es-icon-course-cate-vip"></view>
  59. <text class="es-ml-4 es-fs-22">{{ item.courseSort>2 && canShowVip(item) ? '限时特惠' : '免费'}}</text>
  60. </view> -->
  61. </view>
  62. </view>
  63. </view>
  64. <!-- #ifndef APP-PLUS -->
  65. <adMask :show="tipShow">
  66. <!-- 逐集观看提示弹窗 -->
  67. <view class="tipspop">
  68. <view class="jianyi_icon_box">
  69. <image class="jianyi_icon" src="@/static/images/ad/jianyi_icon.png" mode="aspectFill"></image>
  70. </view>
  71. <view class="tc_bg">
  72. <image src="@/static/images/ad/tc_bg.png" mode="widthFix" style="width: 100%;height: auto;"></image>
  73. </view>
  74. <view class="tipspop-con">
  75. <view class="tipspop-title">建议逐集观看,学习效果更佳</view>
  76. <view>是否返回逐集观看?</view>
  77. </view>
  78. <view class="tipspop-footer">
  79. <view class="tipspop-footer-l" @click="tipCancel">取消</view>
  80. <view @click="tipConfirm">确认</view>
  81. </view>
  82. </view>
  83. </adMask>
  84. <!-- #endif -->
  85. </view>
  86. </template>
  87. <script>
  88. import { getCourseById,getCourseVideoList,addDuration } from '@/api/course'
  89. export default {
  90. data() {
  91. return {
  92. catalogueList:[],
  93. pickCatalog:{videoUrl:"",thumbnail:"",duration:0,videoId:0,seconds:0},
  94. pickCatalogIdx:0,
  95. searchText:"",
  96. videoContext: null,
  97. video: {
  98. percent: 10, //进度百分比
  99. },
  100. data:{
  101. courseId:null,
  102. imgUrl:"",
  103. talentAvatar:"",
  104. price:"",
  105. remark:"",
  106. noteNum:0,
  107. courseName:"",
  108. description:"",
  109. cataIndex:0,
  110. isFast:false,
  111. isAutoPlay:false,
  112. },
  113. danmuList:[],
  114. tempStudyTimes:0,
  115. studyTimes:0,
  116. audioContext: null,
  117. audioPlayIng:false,
  118. showFullScreenBtn:true,
  119. isLearning:false,
  120. myVideo:null,
  121. showProgress:true,
  122. videoUrl:"https://1319721001.vod-qcloud.com/3525603bvodcq1319721001/2b3e76ac1253642698811158287/Hmod7JMfAowA.mp4",
  123. poster: "",
  124. videoId:null,
  125. isAutoPlay:false,
  126. tipShow: false,
  127. tipsIndex: null,
  128. isNext: 0
  129. }
  130. },
  131. onLoad(options) {
  132. this.courseId=options.courseId;
  133. this.videoId=options.videoId;
  134. this.isAutoPlay=options.isAutoPlay;
  135. this.tempStudyTimes=options.studyTimes;
  136. this.getCourseInfo();
  137. this.getCourseVideoList();
  138. },
  139. onShow(){
  140. // if(this.data!=null && !this.countdowning){
  141. // this.startCountsTime();
  142. // }
  143. },
  144. onReady() {
  145. this.videoContext = uni.createVideoContext("myVideo", this);
  146. },
  147. methods: {
  148. canShowVip(item){
  149. return true;
  150. if(this.myUserInfo.isVip){
  151. return false;
  152. }
  153. return item.isVip==1 && item.isBuy==0;
  154. },
  155. getCourseInfo(){
  156. getCourseById(this.courseId).then(res => {
  157. if(res.code==200){
  158. this.data=res.data;
  159. this.isNext = res.data.isNext;
  160. }
  161. },
  162. rej => {}
  163. );
  164. },
  165. search() {
  166. this.videoId = 0
  167. this.getCourseVideoList()
  168. },
  169. //课程目录
  170. getCourseVideoList(){
  171. let that=this;
  172. const params={"courseId":this.courseId,"keyword":this.searchText};
  173. getCourseVideoList(params,1,30).then(res => {
  174. if(res.code==200){
  175. this.catalogueList=res.data.list;
  176. if(this.catalogueList.length>0){
  177. if(this.videoId!=null &&this.videoId!= 0){
  178. console.log("qxj videoId="+this.videoId);
  179. this.pickCatalogIdx=this.getCatalogIdx();
  180. console.log("qxj pickCatalogIdx:"+this.pickCatalogIdx);
  181. this.pickCatalog=this.catalogueList[this.pickCatalogIdx];
  182. }else{
  183. this.pickCatalog=this.catalogueList[0];
  184. }
  185. if(this.tempStudyTimes>0){
  186. this.pickCatalog.studyTime=this.tempStudyTimes;
  187. this.initStudyTime(this.pickCatalog.studyTime);
  188. }else{
  189. if(this.pickCatalog.studyTime!=null){
  190. this.initStudyTime(this.pickCatalog.studyTime);
  191. }
  192. }
  193. //开始播放计时
  194. if(this.isAutoPlay==1){
  195. this.pickCatalogMethod(this.pickCatalogIdx);
  196. }
  197. this.poster=this.pickCatalog.thumbnail;
  198. }
  199. }
  200. },
  201. rej => {}
  202. );
  203. },
  204. addStudyCourse(){
  205. if(this.catalogueList.length==0){
  206. return;
  207. }
  208. this.pickCatalog=this.catalogueList[this.pickCatalogIdx];
  209. const parmas={"courseId":parseInt(this.courseId),"duration":this.courseDuration,"videoId":this.pickCatalog.videoId};
  210. addDuration(parmas).then(res => {
  211. if(res.code==200){
  212. this.courseDuration=0;
  213. }
  214. },
  215. rej => {}
  216. );
  217. },
  218. playVideo() {
  219. this.videoContext.play();
  220. },
  221. pauseVideo() {
  222. console.log("pause");
  223. // (uni.getElementById("myVideo"))?.pause(); //as写法测试。注意id不对时as会崩溃
  224. this.videoContext.pause();
  225. },
  226. pickCatalogAction(index){
  227. if(this.pickCatalogIdx == index) return
  228. if(this.isNext == 1 && this.pickCatalogIdx != index -1) {
  229. this.pauseVideo()
  230. this.openTips(index)
  231. return
  232. }
  233. //添加切换之前课程目录学习记录
  234. this.addStudyCourse();
  235. this.pickCatalogMethod(index);
  236. },
  237. pickCatalogMethod(index){
  238. this.pickCatalogIdx=index;
  239. this.pickCatalog=this.catalogueList[index];
  240. this.studyTimes=0;//当pickCatalog.studyTime=null 或者等于视频总时长时默认切为零
  241. if(this.pickCatalog.studyTime!=this.pickCatalog.seconds){
  242. this.studyTimes=this.pickCatalog.studyTime;
  243. }
  244. this.initStudyTime(this.studyTimes);
  245. this.poster=this.pickCatalog.thumbnail;
  246. let that=this;
  247. setTimeout(function(){
  248. that.playVideo();
  249. },200);
  250. },
  251. initStudyTime(times){
  252. this.studyTimes=times;
  253. this.courseDuration=times;
  254. },
  255. toggleBarChange(event){
  256. console.log("qxj toggleBarChange");
  257. this.showFullScreenBtn=!this.showFullScreenBtn;
  258. },
  259. onTimeUpdate(event){
  260. this.courseDuration = (event.detail.currentTime*1.0).toFixed(0);
  261. },
  262. onFullscreenChange(event){
  263. // 检查是否全屏
  264. if (event.fullscreen) {
  265. // 如果是全屏,则退出全屏
  266. //this.videoContext.exitFullScreen();
  267. }
  268. },
  269. onLoadedMetadata(e) {
  270. this.pickCatalog=this.catalogueList[this.pickCatalogIdx];
  271. if(this.pickCatalog.seconds==null){
  272. this.pickCatalog.seconds =(e.target.duration).toFixed(0);
  273. }
  274. },
  275. getCatalogIdx(){
  276. let index=0;
  277. for (var i = 0; i < this.catalogueList.length; i++) {
  278. let item=this.catalogueList[i];
  279. if(this.videoId==item.videoId){
  280. break;
  281. }
  282. index++;
  283. }
  284. return index;
  285. },
  286. videoErrorCallback(){
  287. },
  288. openTips(index){
  289. this.tipsIndex = index
  290. this.tipShow = true
  291. },
  292. tipConfirm() { // 提示确认
  293. this.tipsIndex = null
  294. this.tipShow = false
  295. // 继续播放
  296. this.playVideo()
  297. },
  298. tipCancel() { // 提示取消
  299. this.tipShow = false
  300. // 播放选择的一节
  301. //添加切换之前课程目录学习记录
  302. this.addStudyCourse();
  303. this.pickCatalogMethod(this.tipsIndex);
  304. },
  305. },
  306. onUnload() {
  307. this.addStudyCourse();
  308. let studyData={"studyTimes":this.courseDuration,"videoId":this.pickCatalog.videoId}
  309. uni.$emit('backStudyTime', studyData);
  310. }
  311. }
  312. </script>
  313. <style lang="scss" scoped>
  314. page {
  315. background-color: white;
  316. }
  317. @mixin u-flex($flexD, $alignI, $justifyC) {
  318. display: flex;
  319. flex-direction: $flexD;
  320. align-items: $alignI;
  321. justify-content: $justifyC;
  322. }
  323. .freeflag {
  324. min-width: 68rpx;
  325. // height: 32rpx;
  326. padding: 3rpx 12rpx;
  327. text-align: center;
  328. line-height: 32rpx;
  329. position: absolute;
  330. right: 0;
  331. top: 0;
  332. border-radius: 0 16rpx 0 16rpx;
  333. &-free {
  334. // background: url('@/static/image/hall/free_lable_bg.png') no-repeat right / 100% 32rpx;
  335. background-color: #2583EB;
  336. }
  337. &-member {
  338. // background: url('@/static/image/hall/member_label_bg.png') no-repeat right / 100% 32rpx;
  339. background-color: #FFB205;
  340. }
  341. }
  342. .banner {
  343. height: 430rpx;
  344. }
  345. .es-icon-course-icon-6 {
  346. background-image: url(/static/images/other/course/icon-6.png);
  347. }
  348. .es-icon-course-close {
  349. background-image: url(/static/images/other/course/close.png);
  350. }
  351. .es-icon-course-cate-bg1 {
  352. background-color: #eef5fd;
  353. border-radius: 16rpx 16rpx 16rpx 16rpx;
  354. // background-image: url(/static/images/other/course/cate-bg1.png);
  355. }
  356. .es-icon-course-cate-bg2 {
  357. background-color: #F5F7FA;
  358. border-radius: 16rpx 16rpx 16rpx 16rpx;
  359. // background-image: url(/static/images/other/course/cate-bg2.png);
  360. }
  361. .es-icon-course-cate-bg3 {
  362. background-image: url(/static/images/other/course/cate-bg3.png);
  363. }
  364. .es-icon-course-play-loading {
  365. background-image: url(/static/images/other/course/play-loading.png);
  366. }
  367. .es-icon-course-cate-vip {
  368. background-image: url(/static/images/other/course/vip.png);
  369. }
  370. .es-icon-search-search {
  371. background-image: url(/static/images/other/search/search.png);
  372. }
  373. .vip{
  374. position: absolute;
  375. right: 0;
  376. top:0;
  377. min-width: 87rpx;
  378. padding: 6rpx 10rpx;
  379. box-sizing: border-box;
  380. }
  381. .video {
  382. height: 380rpx;
  383. position: relative;
  384. display: flex;
  385. .cover{
  386. position: absolute;
  387. left: 0;
  388. top: 0;
  389. width: 100%;
  390. height: 100%;
  391. border-radius: 20rpx;
  392. }
  393. .playIcon{
  394. position: absolute;
  395. width:44rpx ;
  396. height: 44rpx;
  397. z-index: 10;
  398. right: 26rpx;
  399. bottom: 50rpx;
  400. }
  401. }
  402. .video video {
  403. width: 100%;
  404. height: 100%;
  405. border-radius: 20rpx;
  406. }
  407. .video .video-1,.video .video-2,.video .video-3,.video .video-4{
  408. position: absolute;
  409. width: 20rpx;
  410. height: 20rpx;
  411. z-index: 1;
  412. }
  413. .video .video-1{
  414. left:0;top:0;
  415. }
  416. .video .video-2{
  417. right:0;top:0;
  418. }
  419. .video .video-3{
  420. left:0;bottom:0;
  421. }
  422. .video .video-4{
  423. right:0;bottom:0;
  424. }
  425. .tipspop {
  426. width: 630rpx;
  427. // height: 376rpx;
  428. padding-bottom: 40rpx;
  429. background: linear-gradient( 180deg, #FFEDE3 0%, #FFFFFF 100%);
  430. border-radius: 32rpx 32rpx 32rpx 32rpx;
  431. position: relative;
  432. font-family: PingFang SC, PingFang SC;
  433. font-weight: 400;
  434. font-size: 28rpx;
  435. color: #757575;
  436. text-align: center;
  437. .jianyi_icon_box {
  438. width: 124rpx;
  439. height: 124rpx;
  440. border-radius: 50%;
  441. background: linear-gradient( 180deg, #FF9B45 0%, #2583EB 100%);
  442. border: 12rpx solid #FFFFFF;
  443. @include u-flex(row, center, center);
  444. position: absolute;
  445. left: 50%;
  446. top: -74rpx;
  447. transform: translateX(-50%);
  448. }
  449. .jianyi_icon {
  450. height: 64rpx;
  451. width: 64rpx;
  452. }
  453. .tc_bg {
  454. width: 100%;
  455. height: auto;
  456. border-radius: 32rpx 32rpx 0 0;
  457. overflow: hidden;
  458. }
  459. &-con {
  460. padding: 0 48rpx;
  461. }
  462. &-title {
  463. margin: 14rpx 0 20rpx 0;
  464. font-weight: 500;
  465. font-size: 34rpx;
  466. color: #333333;
  467. }
  468. &-footer {
  469. padding-top: 34rpx;
  470. @include u-flex(row, center, center);
  471. view {
  472. width: 248rpx;
  473. height: 84rpx;
  474. line-height: 84rpx;
  475. text-align: center;
  476. background: #2583EB;
  477. border-radius: 42rpx 42rpx 42rpx 42rpx;
  478. font-family: PingFang SC, PingFang SC;
  479. font-weight: 500;
  480. font-size: 32rpx;
  481. color: #FFFFFF;
  482. }
  483. .tipspop-footer-l{
  484. margin-right: 38rpx;
  485. background: #F4F4F4;
  486. color: #757575;
  487. }
  488. }
  489. }
  490. .tipsvip {
  491. width: 630rpx;
  492. // height: 624rpx;
  493. padding-bottom: 40rpx;
  494. box-sizing: border-box;
  495. background: #FFFFFF;
  496. border-radius: 32rpx 32rpx 32rpx 32rpx;
  497. overflow: hidden;
  498. font-family: PingFang SC, PingFang SC;
  499. font-weight: 400;
  500. font-size: 32rpx;
  501. color: #333333;
  502. line-height: 48rpx;
  503. .vipFrame {
  504. width: 100%;
  505. height: auto;
  506. }
  507. &-con {
  508. padding: 44rpx 48rpx;
  509. box-sizing: border-box;
  510. }
  511. &-footer {
  512. @include u-flex(row, center, center);
  513. &-btn {
  514. width: 534rpx;
  515. height: 84rpx;
  516. line-height: 84rpx;
  517. text-align: center;
  518. background: #2583EB;
  519. border-radius: 42rpx 42rpx 42rpx 42rpx;
  520. font-family: PingFang SC, PingFang SC;
  521. font-weight: 500;
  522. font-size: 32rpx;
  523. color: #FFFFFF;
  524. }
  525. }
  526. }
  527. </style>