index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  1. <template>
  2. <div class="school">
  3. <div class="top">
  4. <div class="search">
  5. <image src="@/static/images/search.png" mode="" class="search_icon"></image>
  6. <div class="s_input"><u-input v-model="searchValue" type="text" :border="false" /></div>
  7. <div class="searh_btn" @click="resetList">查询</div>
  8. </div>
  9. </div>
  10. <view class="CoursePage">
  11. <!-- 悬浮窗 -->
  12. <view v-if="nowPlay && showfu" class="showfu">
  13. <view class="imgBox">
  14. <image :src="nowPlay.cover" mode="widthFix" style="width: 88rpx;height: 88rpx;"></image>
  15. </view>
  16. <image v-if="play.ing" src="@/production/static/images/school/pause2.png" mode="widthFix"
  17. style="width: 60rpx;" @click.stop="stopVideo(nowPlay, play.index)"></image>
  18. <image v-else src="@/static/images/school/start.png" mode="widthFix" style="width: 60rpx;"
  19. @click.stop="playVideoSelf(nowPlay, play.index)"></image>
  20. <image src="@/static/images/school/xx.png" mode="widthFix" style="width: 40rpx;margin-right: 28rpx;"
  21. @click.stop="clearVideo"></image>
  22. </view>
  23. <div class="tabs">
  24. <u-tabs ref="tabs" :list="tabList" active-color="#F5222D" :show-bar="false" :current="curTab"
  25. @change="handleChangeTab"></u-tabs>
  26. </div>
  27. <view class="CourseBody">
  28. <view class="CourseList">
  29. <div v-if="courseList.length>0">
  30. <view class="CourseList-item" v-for="(item, i) in courseList" :key="item.id"
  31. @click="goDetail(item)">
  32. <view class="ItemInfo">
  33. <image :src="item.cover" mode="aspectFill" class="ItemInfo-teamcher">
  34. <view class="Info-right">
  35. <view class="Right-title">{{item.name}}</view>
  36. <view class="Right-teacher">{{item.day}} · {{item.author}}</view>
  37. <!-- 播放中 -->
  38. <view class="Right-play" v-if="item.type==1 && play.index === i&& play.ing"
  39. @click.stop="stopVideo(item, i)">
  40. <image v-if="play.index === i && play.ing"
  41. src="@/static/images/school/pause2.png" class="Play-icon" />
  42. <image v-else src="@/static/images/school/play2.png" class="Play-icon" />
  43. <view class="Play-Sound">
  44. <view class="SoundWave">
  45. <view v-for="ni in 20" :key="i + '_' + ni" class="Wave-line"
  46. :class=" play.index === i&& play.ing ? 'active' : ''" />
  47. </view>
  48. </view>
  49. <view class="Play-time" v-if="play.index === i">
  50. {{syTime | mediaTimeFormatter}}
  51. </view>
  52. </view>
  53. <!-- 播放暂停 -->
  54. <view class="Right-play"
  55. v-else-if="item.type==1 && play.index === i && !play.ing"
  56. @click.stop="playVideoSelf(item, i)">
  57. <image v-if="play.index === i && play.ing"
  58. src="@/static/images/school/pause2.png" class="Play-icon" />
  59. <image v-else src="@/static/images/school/play2.png" class="Play-icon" />
  60. <view class="Play-Sound">
  61. <view class="SoundWave">
  62. <view v-for="ni in 20" :key="i + '_' + ni" class="Wave-line"
  63. :class=" play.index === i&& play.ing ? 'active' : ''" />
  64. </view>
  65. </view>
  66. <view class="Play-time" v-if="play.index === i">
  67. {{syTime | mediaTimeFormatter}}
  68. </view>
  69. </view>
  70. <!-- 未播放 -->
  71. <div v-else>
  72. <view class="Right-play" v-if="item.type==1 "
  73. @click.stop="playVideoSelf(item, i)">
  74. <image src="@/static/images/school/play2.png" class="Play-icon" />
  75. <view class="Play-Sound">
  76. <view class="SoundWave">
  77. <view v-for="ni in 20" :key="i + '_' + ni" class="Wave-line"
  78. :class=" play.index === i&& play.ing ? 'active' : ''" />
  79. </view>
  80. </view>
  81. <view class="Play-time">{{ item.seconds | mediaTimeFormatter }}
  82. </view>
  83. </view>
  84. </div>
  85. <!-- <view :class="['Right-play', play.index == i ?'' : 'no_open']"
  86. v-if="item.type==1">
  87. <image v-if="play.index === i && play.ing"
  88. src="@/static/images/school/pause2.png" class="Play-icon"
  89. @click.stop="stopVideo(item, i)" />
  90. <image v-else src="@/static/images/school/play2.png" class="Play-icon"
  91. @click.stop="playVideoSelf(item, i)" />
  92. <view class="Play-Sound">
  93. <view class="SoundWave">
  94. <view v-for="ni in 20" :key="i + '_' + ni" class="Wave-line"
  95. :class=" play.index === i&& play.ing ? 'active' : ''" />
  96. </view>
  97. </view>
  98. <view class="Play-time" v-if="play.index === i">
  99. {{syTime | mediaTimeFormatter}}
  100. </view>
  101. <view v-else class="Play-time">{{ item.seconds | mediaTimeFormatter }}
  102. </view>
  103. </view> -->
  104. </view>
  105. </view>
  106. </view>
  107. </div>
  108. <div class="empty_image" v-else>
  109. <u-empty text="暂无课程"></u-empty>
  110. </div>
  111. </view>
  112. </view>
  113. </view>
  114. </div>
  115. </template>
  116. <script>
  117. import {
  118. AudioSlide
  119. } from "@/components/audio-slide.vue"
  120. let innerAudioContext = ''
  121. import {
  122. mapState
  123. } from "vuex"
  124. export default {
  125. components: {
  126. AudioSlide
  127. },
  128. data() {
  129. return {
  130. typd: 0,
  131. showfu: false,
  132. title_list: [],
  133. title: '赛季点击此处选择',
  134. page: 1,
  135. last: false,
  136. courseList: [],
  137. tabList: [{
  138. name: '全部'
  139. }],
  140. searchValue: '',
  141. curTab: 0,
  142. img: '',
  143. params: {
  144. page: 1,
  145. page_size: 15,
  146. week: 1,
  147. season: ''
  148. },
  149. play: {
  150. index: -1,
  151. ing: false,
  152. time: 0,
  153. stop: false
  154. },
  155. nowPlay: {}, //当前正在播放的视频
  156. syTime: 0, //剩余时间
  157. }
  158. },
  159. filters: {
  160. dateFormatter: (timestamp, fmt) => {
  161. fmt = fmt || "yyyy-MM-dd";
  162. if (typeof timestamp === 'string') {
  163. timestamp = timestamp.replace(/-/g, '/')
  164. }
  165. const $this = new Date(timestamp);
  166. const o = {
  167. "M+": $this.getMonth() + 1,
  168. "d+": $this.getDate(),
  169. "h+": $this.getHours(),
  170. "m+": $this.getMinutes(),
  171. "s+": $this.getSeconds(),
  172. "q+": Math.floor(($this.getMonth() + 3) / 3),
  173. S: $this.getMilliseconds()
  174. };
  175. if (/(y+)/.test(fmt)) {
  176. fmt = fmt.replace(
  177. RegExp.$1,
  178. ($this.getFullYear() + "").substr(4 - RegExp.$1.length)
  179. );
  180. }
  181. for (var k in o) {
  182. if (new RegExp("(" + k + ")").test(fmt)) {
  183. fmt = fmt.replace(
  184. RegExp.$1,
  185. RegExp.$1.length === 1 ?
  186. o[k] :
  187. ("00" + o[k]).substr(("" + o[k]).length)
  188. );
  189. }
  190. }
  191. return fmt;
  192. },
  193. mediaTimeFormatter: num => {
  194. if (!num) return "00:00";
  195. num = Math.floor(num);
  196. let hour = Math.floor(num / 3600);
  197. let minutes = Math.floor((num - hour * 3600) / 60);
  198. let second = num - hour * 3600 - minutes * 60;
  199. if (hour > 0) {
  200. return `${hour > 9 ? hour : "0" + hour}:${
  201. minutes > 9 ? minutes : "0" + minutes
  202. }:${second > 9 ? second : "0" + second}`;
  203. } else {
  204. return `${minutes > 9 ? minutes : "0" + minutes}:${
  205. second > 9 ? second : "0" + second
  206. }`;
  207. }
  208. }
  209. },
  210. onShow() {},
  211. onHide() {
  212. // 离开小程序,去聊天
  213. },
  214. onLoad(e) {
  215. this.getCategoryLlist()
  216. this.getCourseList()
  217. },
  218. onUnload() {},
  219. created() {
  220. },
  221. methods: {
  222. //播放视频
  223. playVideoSelf(data, index) {
  224. if (this.nowPlay && data.id !== this.nowPlay.id && innerAudioContext) innerAudioContext.destroy()
  225. console.log(data, '----', index)
  226. //判断当前视频是否处于播放状态是的话停止
  227. // 否
  228. console.log('playVideoSelf', this.play.stop == true, innerAudioContext.paused, this.play.index == index)
  229. if (this.play.stop == true && this.play.index == index && innerAudioContext.paused) {
  230. console.log('暂停后重新播放')
  231. if (!innerAudioContext.src) innerAudioContext.src = data.path
  232. innerAudioContext.play()
  233. } else {
  234. innerAudioContext = uni.createInnerAudioContext();
  235. innerAudioContext.src = data.path;
  236. innerAudioContext.autoplay = true;
  237. innerAudioContext.onPlay(() => {
  238. console.log('开始播放', innerAudioContext);
  239. this.play.stop = false
  240. this.play.index = index
  241. this.play.ing = true
  242. this.nowPlay = data
  243. this.showfu = true
  244. });
  245. innerAudioContext.onEnded(() => {
  246. // 音频播放完成
  247. console.log('音频播放完成')
  248. this.videoPlayEnd()
  249. })
  250. innerAudioContext.onTimeUpdate(() => {
  251. console.log('视频播放进度', innerAudioContext.currentTime)
  252. let time = Math.ceil(innerAudioContext.currentTime)
  253. if (this.play.time === time) return
  254. this.play.time = time
  255. this.countDownTime(time)
  256. })
  257. innerAudioContext.onPause(() => {
  258. this.play.ing = false
  259. })
  260. }
  261. },
  262. //暂停播放视频
  263. stopVideo() {
  264. console.log()
  265. this.play.stop = true
  266. innerAudioContext.pause()
  267. },
  268. //清除播放
  269. clearVideo() {
  270. innerAudioContext.stop()
  271. this.play = {
  272. index: -1,
  273. ing: false,
  274. time: 0,
  275. }
  276. this.nowPlay = {}
  277. this.showfu = false
  278. },
  279. //播放结束
  280. videoPlayEnd() {
  281. innerAudioContext.stop();
  282. innerAudioContext.destroy()
  283. //判断是否存在下一条
  284. console.log(this.play.index == this.courseList.length - 1)
  285. if (this.play.index == this.courseList.length - 1) {
  286. //不存在吓一跳
  287. this.play = {
  288. index: -1,
  289. ing: false,
  290. time: 0,
  291. }
  292. this.nowPlay = {}
  293. this.showfu = false
  294. return
  295. }
  296. this.play.index++
  297. this.play.ing = true
  298. this.nowPlay = this.courseList[this.play.index]
  299. console.log('this.play.index', this.play.index)
  300. console.log('this.courseList', this.courseList)
  301. console.log('nowPlay', this.nowPlay)
  302. console.log('innerAudioContext', innerAudioContext)
  303. this.playVideoSelf(this.nowPlay, this.play.index)
  304. },
  305. //播放时音频倒计时
  306. countDownTime() {
  307. let videoTime = this.nowPlay.seconds
  308. let nowTime = this.play.time || 0
  309. this.syTime = videoTime - nowTime
  310. },
  311. //点击课程分类
  312. handleChangeTab(index) {
  313. this.curTab = index
  314. this.resetList()
  315. },
  316. //课程分类
  317. getCategoryLlist() {
  318. this.$u.get('/dwbs/business/category/select-options').then(res => {
  319. console.log(res)
  320. this.tabList = [{
  321. id: 0,
  322. name: '全部'
  323. }].concat(res.data)
  324. })
  325. },
  326. //重置列表请求
  327. resetList() {
  328. this.page = 1
  329. this.last = false
  330. this.courseList = []
  331. this.getCourseList()
  332. },
  333. //课程列表
  334. getCourseList() {
  335. let index = this.curTab
  336. console.log(this.curTab)
  337. this.$u.get('/dwbs/business/schools', {
  338. page: this.page,
  339. name: this.searchValue,
  340. category_id: this.tabList[index].id !== 0 ? this.tabList[index].id : ''
  341. }).then(res => {
  342. let data = res.data.data
  343. if (this.page > 1 && data.length == 0) {
  344. uni.showToast({
  345. title: '暂无更多',
  346. icon: 'none'
  347. })
  348. this.last = true
  349. } else {
  350. this.courseList = this.courseList.concat(data)
  351. }
  352. })
  353. },
  354. //跳转详情
  355. goDetail(item) {
  356. if (item.type == 2) {
  357. uni.navigateTo({
  358. url: '/pages/school/detail?id=' + item.id
  359. })
  360. }
  361. }
  362. }
  363. }
  364. </script>
  365. <style lang="scss" scoped>
  366. page {
  367. background-color: #f5f5f5;
  368. }
  369. .top {
  370. padding: 12px;
  371. background-color: #FFFFFF;
  372. }
  373. .search {
  374. background: #F9F9FB;
  375. height: 40px;
  376. line-height: 40px;
  377. border-radius: 20px;
  378. display: flex;
  379. align-items: center;
  380. padding: 0 12px;
  381. .search_icon {
  382. width: 24px;
  383. height: 24px;
  384. margin-right: 5px;
  385. }
  386. .s_input {
  387. flex: 1
  388. }
  389. .searh_btn {
  390. background: linear-gradient(91deg, #FF232C 0%, #FF571B 99%);
  391. border-radius: 20px;
  392. text-align: center;
  393. height: 32px;
  394. width: 66px;
  395. line-height: 32px;
  396. font-size: 14px;
  397. color: #FFFFFF;
  398. }
  399. }
  400. .showfu {
  401. width: 268rpx;
  402. height: 96rpx;
  403. background: #5B5B5B;
  404. box-shadow: 0px 6px 12px rgba(0, 0, 0, 0.16);
  405. border-radius: 50rpx;
  406. position: fixed;
  407. right: 44rpx;
  408. bottom: 100px;
  409. display: flex;
  410. justify-content: space-between;
  411. align-items: center;
  412. .imgBox {
  413. width: 96rpx;
  414. height: 96rpx;
  415. border: 6rpx solid #FFFFFF;
  416. border-radius: 50%;
  417. overflow: hidden;
  418. }
  419. }
  420. .select {
  421. margin-top: 20rpx;
  422. padding-left: 30rpx;
  423. font-size: 34rpx;
  424. }
  425. .noTip {
  426. padding: 20rpx;
  427. text-align: center;
  428. width: 100%;
  429. color: #999999;
  430. }
  431. $rotate: 0deg;
  432. .CoursePage {
  433. background-color: #FFFFFF;
  434. margin-top: 10px;
  435. border-radius: 10px 10px 0px 0px;
  436. @include page();
  437. display: flex;
  438. flex-direction: column;
  439. justify-content: space-between;
  440. .CourseAudioDetail {
  441. @include page();
  442. position: fixed;
  443. height: 100%;
  444. bottom: 0;
  445. left: 0;
  446. right: 0;
  447. background-color: #FFFFFF;
  448. overflow: hidden;
  449. .CoursePlay {
  450. padding: 30rpx;
  451. width: 100%;
  452. box-sizing: border-box;
  453. display: flex;
  454. align-items: center;
  455. justify-content: flex-start;
  456. flex-direction: column;
  457. .PlayTitle {
  458. width: 100%;
  459. color: #333333;
  460. font-size: 40rpx;
  461. line-height: 60rpx;
  462. text-align: center;
  463. margin-bottom: 40rpx;
  464. }
  465. .PlayTeacher {
  466. color: #999999;
  467. font-size: 32rpx;
  468. line-height: 60rpx;
  469. text-align: center;
  470. margin-bottom: 40rpx;
  471. }
  472. .PlayCover {
  473. width: 496rpx;
  474. height: 496rpx;
  475. border-radius: 50%;
  476. background-color: #333333;
  477. padding: 26rpx;
  478. box-sizing: border-box;
  479. .CoverImg {
  480. display: block;
  481. width: 100%;
  482. height: 100%;
  483. border-radius: 50%;
  484. &.start {
  485. animation: rotate 10s 0s infinite linear;
  486. }
  487. &.paused {
  488. animation-play-state: paused;
  489. }
  490. }
  491. margin-bottom: 150rpx;
  492. }
  493. .AudioProgress {
  494. width: 100%;
  495. display: flex;
  496. align-items: center;
  497. justify-content: space-between;
  498. margin-bottom: 50rpx;
  499. .Progress-right {
  500. color: #EA4A41;
  501. font-size: 24rpx;
  502. margin-left: 30px;
  503. }
  504. .Progress-left {
  505. flex: 1;
  506. min-width: 0;
  507. .Audio-slide {
  508. margin: 0;
  509. }
  510. }
  511. }
  512. .AudioControl {
  513. display: flex;
  514. align-items: center;
  515. justify-content: space-between;
  516. width: 100%;
  517. image {
  518. &:nth-of-type(1),
  519. &:nth-last-of-type(1) {
  520. width: 43rpx;
  521. height: 38rpx;
  522. }
  523. &:nth-of-type(2),
  524. &:nth-last-of-type(2) {
  525. width: 38rpx;
  526. height: 46rpx;
  527. }
  528. &:nth-of-type(3) {
  529. width: 124rpx;
  530. height: 124rpx;
  531. }
  532. }
  533. }
  534. }
  535. }
  536. .CourseScrollBody {
  537. width: 100%;
  538. flex: 1;
  539. overflow: hidden;
  540. position: relative;
  541. }
  542. }
  543. .CourseBody {
  544. width: 100%;
  545. padding: 0 30rpx 30rpx;
  546. box-sizing: border-box;
  547. .CourseWeek {
  548. width: 100%;
  549. display: flex;
  550. align-items: center;
  551. justify-content: space-between;
  552. margin-bottom: 60rpx;
  553. .week {
  554. // width: 192rpx;
  555. padding: 0 30rpx;
  556. height: 68rpx;
  557. border-radius: 68rpx;
  558. text-align: center;
  559. line-height: 68rpx;
  560. background: #F8F8F8;
  561. color: #999999;
  562. font-size: 28rpx;
  563. &.active {
  564. color: #FFFFFF !important;
  565. background: linear-gradient(to right, #F97C55, #F44545) !important;
  566. }
  567. }
  568. }
  569. .CourseList {
  570. &-item {
  571. margin-bottom: 40rpx;
  572. background: #F6F6F6;
  573. border-radius: 5px;
  574. &:nth-last-of-type(1) {
  575. margin-bottom: 0;
  576. }
  577. .ItemTitle {
  578. color: #333333;
  579. font-size: 32rpx;
  580. line-height: 44rpx;
  581. margin-bottom: 30rpx;
  582. display: flex;
  583. align-items: center;
  584. justify-content: space-between;
  585. &-status {
  586. height: 44rpx;
  587. line-height: 44rpx;
  588. width: 118rpx;
  589. border: 2rpx solid #999999;
  590. color: #999999;
  591. text-align: center;
  592. font-size: 28rpx;
  593. box-sizing: border-box;
  594. &.active {
  595. border-color: #EA4A41 !important;
  596. color: #EA4A41 !important;
  597. }
  598. }
  599. }
  600. .ItemInfo {
  601. width: 100%;
  602. display: flex;
  603. align-items: stretch;
  604. justify-content: space-between;
  605. .ItemInfo-teamcher {
  606. display: block;
  607. width: 180rpx;
  608. height: 234rpx;
  609. }
  610. .Info-right {
  611. flex: 1;
  612. overflow: hidden;
  613. margin-left: 16rpx;
  614. display: flex;
  615. justify-content: space-between;
  616. flex-direction: column;
  617. align-items: flex-start;
  618. padding-top: 4px;
  619. .Right-title {
  620. color: #333333;
  621. font-size: 32rpx;
  622. overflow: hidden;
  623. display: -webkit-box; //将对象作为弹性伸缩盒子模型显示;
  624. text-overflow: ellipsis; //溢出部分用省略号代替
  625. -webkit-line-clamp: 2; //设置文本显示两行
  626. -webkit-box-orient: vertical; //从上到下排列子元素;
  627. line-height: 44rpx;
  628. }
  629. .Right-teacher {
  630. color: #999999;
  631. font-size: 28rpx;
  632. line-height: 40rpx;
  633. }
  634. .Right-play {
  635. width: 422rpx;
  636. height: 60rpx;
  637. padding: 12rpx 14rpx;
  638. box-sizing: border-box;
  639. display: flex;
  640. align-items: center;
  641. background: linear-gradient(to right, #F97C55, #F44545);
  642. border-radius: 60rpx;
  643. margin-bottom: 22rpx;
  644. display: flex;
  645. align-items: center;
  646. justify-content: space-between;
  647. &.no_open {
  648. background: #F8F8F8 !important;
  649. .Play-time {
  650. color: #999999 !important;
  651. }
  652. /deep/ .Wave-line {
  653. background: #999999 !important;
  654. }
  655. }
  656. .Play-icon {
  657. display: block;
  658. width: 36rpx;
  659. height: 36rpx;
  660. }
  661. .Play-time {
  662. color: #FFFFFF;
  663. font-size: 28rpx;
  664. }
  665. .Play-Sound {
  666. flex: 1;
  667. height: 100%;
  668. overflow: hidden;
  669. margin: 0 20rpx;
  670. }
  671. }
  672. }
  673. }
  674. }
  675. }
  676. }
  677. .SoundWave {
  678. width: 100%;
  679. height: 100%;
  680. display: flex;
  681. align-items: center;
  682. justify-content: space-between;
  683. .Wave-line {
  684. width: 4rpx;
  685. background: #FFFFFF;
  686. border-radius: 4rpx;
  687. @for $i from 1 through 20 {
  688. &:nth-of-type(#{$i}) {
  689. height: #{random(40)}rpx;
  690. }
  691. }
  692. &.active {
  693. @for $i from 1 through 20 {
  694. &:nth-of-type(#{$i}) {
  695. animation: load 2.5s #{(random(10)*0.2)+ 1}s infinite linear;
  696. }
  697. }
  698. }
  699. }
  700. }
  701. @keyframes load {
  702. 0% {
  703. height: 100%;
  704. }
  705. 30% {
  706. height: 20%;
  707. }
  708. 60% {
  709. height: 60%;
  710. }
  711. 100% {
  712. height: 10%;
  713. }
  714. }
  715. @keyframes rotate {
  716. 100% {
  717. transform: rotate(360deg);
  718. }
  719. }
  720. </style>