detail.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. <template>
  2. <view class="">
  3. <view class="navbar">
  4. <view class="back">
  5. <text class="iconfont icon-fanhui " @click="backLast()"></text>
  6. </view>
  7. <text>视频学习</text>
  8. </view>
  9. <view class="msg" style="border-radius:0 0 10px 10px ;">
  10. <!-- <video src="" style="width: 100%;"></video> -->
  11. <video id="myVideo" :src="videoUrl" :initial-time="initialTime" @error="videoErrorCallback"
  12. @timeupdate="timeupdate" @play="videoPlay" @pause="videoPause" :title="videoTitle" :autoplay="true"
  13. show-loading @ended="videoEnd" controls style="width: 100%;"></video>
  14. <view class="title"><text style="margin-right: 7px;">{{msg.title}}</text> <text class="tag"
  15. v-for="item1 in msg.labels" :key="item1">{{item1}}</text></view>
  16. <view class="view1">
  17. <text style="color: darkgrey;">视频数量: <text
  18. style="color: coral;font-weight:550">{{msg.video_nums}}</text></text>
  19. <text style="color: darkgrey;" v-if="msg.user_count>0"> <text
  20. style="color: coral;font-weight:550">{{msg.user_count}}</text>人已学习</text>
  21. <text style="color: darkgrey;" v-else>暂无学习</text>
  22. </view>
  23. </view>
  24. <view class="msg content">
  25. <view class="tab">
  26. <view class="tab-item" :class="currentTab==0 ? 'active-item' :''" @click="changeTab(0)">
  27. 介绍
  28. <view class="line" v-if="currentTab==0">
  29. </view>
  30. </view>
  31. <view class="tab-item" :class="currentTab==1 ? 'active-item' :''" @click="changeTab(1)">
  32. 目录
  33. <view class="line" v-if="currentTab==1">
  34. </view>
  35. </view>
  36. </view>
  37. <view class="desc" v-if="currentTab==0">
  38. <div v-html="msg.description"></div>
  39. </view>
  40. <view class="directory" v-if="currentTab==1">
  41. <view class="chapt" v-for="(item,index) in directoryList" :key="index">
  42. <view class="chapt-title">
  43. {{item.title}}
  44. </view>
  45. <view class="dirc-list" v-for="(video,index1) in item.children " :key="index1"
  46. :class="video.id==videoId ? 'active-video' :''" @click="changeNextVideo(video,index1)">
  47. <view class="icon"></view>
  48. <view class="right">
  49. <view class="title">
  50. {{video.title}}
  51. </view>
  52. <view class="minte">
  53. <view>{{video.duration_text}}</view>
  54. <view class="progress">进度:<text
  55. style="color: #fd6308;font-weight: 550;">{{video.progress}} % </text></view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. var app = getApp()
  66. import navBar from '../../components/navBar/navbar.vue';
  67. import configData from '../../config.js'
  68. export default {
  69. data() {
  70. return {
  71. msg: '',
  72. currentTab: 1,
  73. directoryList: [],
  74. videoUrl: '', //当前视频列表
  75. videoId: '', //当前视频id
  76. currentVideo: '', //当前视频的序号
  77. videoList: [], //视频列表
  78. videoTitle: '', //当前视频的标题
  79. videoDuration: 0,
  80. currentMint: 0, //当前播放秒数防止重复发送,观看时长记录
  81. sendTime: 0, //视频观看进度发送间隔
  82. initialTime: 0, //当前视频播放秒数
  83. }
  84. },
  85. components: {
  86. navBar
  87. },
  88. onShow() {
  89. this.getSettings()
  90. },
  91. onLoad(options) {
  92. app.request('/course/show-detail?slug=' + options.slug, 'get').then(res => {
  93. console.log(res)
  94. this.msg = res.data.data.course
  95. this.directoryList = res.data.data.directory
  96. let file = res.data.data.directory
  97. let arr = file.filter(item => {
  98. return item.children.length > 0
  99. })
  100. if (arr.length == 0) {
  101. uni.showModal({
  102. title: '提示',
  103. content: '当前暂无可播放视频',
  104. showCancel: false,
  105. })
  106. } else {
  107. console.log(arr, '-----', arr1)
  108. let arr1 = []
  109. this.currentVideo = 0
  110. let indexProgress = [] //进度不为0 的下表
  111. arr.map(item => {
  112. item.children.map((item1, index) => {
  113. arr1.push(item1)
  114. })
  115. })
  116. arr1.map((item, index) => {
  117. if (item.progress == 0) {
  118. console.log(item, '---', index)
  119. indexProgress.push(index)
  120. }
  121. })
  122. console.log(indexProgress, 'indexProgressindexProgressindexProgress', arr1)
  123. if (indexProgress.length > 0) {
  124. this.currentVideo = indexProgress[0]
  125. } else {
  126. this.currentVideo = 0
  127. }
  128. this.videoList = arr1
  129. this.videoUrl = this.videoList[this.currentVideo].url_resource.url
  130. this.videoId = this.videoList[this.currentVideo].id
  131. this.videoTitle = this.videoList[this.currentVideo].title
  132. this.videoDuration = this.videoList[this.currentVideo].duration
  133. if (this.videoList[this.currentVideo].progress !== 100) {
  134. this.initialTime = this.videoDuration * this.videoList[this.currentVideo].progress
  135. }
  136. }
  137. })
  138. },
  139. methods: {
  140. getSettings() {
  141. app.request('/setting/keys', {
  142. keys: ['SENG_VIDEO_MSG'],
  143. }, 'post').then(res => {
  144. let data = res.data.data
  145. this.sendTime = data.SENG_VIDEO_MSG
  146. })
  147. },
  148. backLast: function() {
  149. uni.navigateBack()
  150. },
  151. //tab切换视频底部标签
  152. changeTab(e) {
  153. this.currentTab = e
  154. },
  155. //播放进度发生变化时
  156. timeupdate(event) {
  157. let currentTime = event.detail.currentTime
  158. if (currentTime) {
  159. let min = currentTime.toFixed(0)
  160. let yu = min % Number(this.sendTime)
  161. if (yu == 0 && min > 1 && this.currentMint !== min) {
  162. console.log(min, '-----', this.currentMint)
  163. this.currentMint = min
  164. this.postProgress(min)
  165. }
  166. }
  167. },
  168. //发送观看进度
  169. postProgress(currentTime) {
  170. let data = {
  171. course_id: this.msg.id,
  172. video_id: this.videoId,
  173. watch_seconds: currentTime
  174. }
  175. app.request('/course/video/look-record', data, 'post').then(res => {
  176. console.log(res, '观看进度')
  177. })
  178. },
  179. //点击切换视频
  180. changeNextVideo(item) {
  181. console.log(item, 'ppppp')
  182. let id = item.id
  183. this.videoId = item.id
  184. this.videoUrl = item.url_resource.url
  185. this.videoTitle = item.title
  186. this.videoDuration = item.duration
  187. if (item.progress !== 100) {
  188. this.initialTime = item.duration * item.progress
  189. }
  190. this.videoList.map((item1, index) => {
  191. if (item1.id == id) {
  192. this.currentVideo = index
  193. }
  194. })
  195. },
  196. //视频播放时触发
  197. videoPlay() {},
  198. //视频暂停播放
  199. videoPause() {},
  200. //视频播放结束
  201. videoEnd() {
  202. this.postProgress(this.videoDuration)
  203. setTimeout(() => {
  204. //播放结束自动播放下一节
  205. if (this.currentVideo == this.videoList.length - 1) {
  206. return
  207. } else {
  208. this.currentVideo++
  209. this.videoUrl = this.videoList[this.currentVideo].url_resource.url
  210. this.videoId = this.videoList[this.currentVideo].id
  211. this.videoTitle = this.videoList[this.currentVideo].title
  212. this.videoDuration = this.videoList[this.currentVideo].duration
  213. }
  214. }, 500)
  215. },
  216. //加载失败
  217. videoErrorCallback() {}
  218. }
  219. }
  220. </script>
  221. <style lang="scss">
  222. page {
  223. background-color: #EFF1F6;
  224. }
  225. .navbar {
  226. font-size: 32upx;
  227. height: 100upx;
  228. line-height: 100upx;
  229. color: #888888;
  230. position: relative;
  231. position: fixed;
  232. top: 0;
  233. z-index: 9999999;
  234. width: 100%;
  235. background-color: #FFFFFF;
  236. text-align: center;
  237. border-bottom: solid 2upx #EFF1F6;
  238. .back {
  239. height: 100upx;
  240. width: 100upx;
  241. text-align: center;
  242. position: absolute;
  243. float: left;
  244. left: 0upx;
  245. font-size: 32upx;
  246. }
  247. }
  248. .msg {
  249. margin-top: 100upx;
  250. background: white;
  251. padding-bottom: 10upx;
  252. .title {
  253. padding: 8px 0;
  254. font-weight: 550;
  255. color: #3e3e3e;
  256. font-size: 16px;
  257. padding: 0 30upx;
  258. }
  259. .tag {
  260. display: inline-block;
  261. border-radius: 3px;
  262. border: solid 1px #1c85f1;
  263. color: #1c85f1;
  264. font-size: 12px;
  265. padding: 0px 3px;
  266. margin-right: 5px;
  267. font-weight: normal;
  268. }
  269. .view1 {
  270. display: flex;
  271. align-items: center;
  272. justify-content: space-between;
  273. padding: 0 30upx;
  274. padding-top: 15upx;
  275. padding-bottom: 10px;
  276. font-size: 26upx;
  277. color: #888888;
  278. }
  279. .text1 {
  280. padding-left: 30upx;
  281. padding-top: 10upx;
  282. font-size: 32upx;
  283. color: black;
  284. font-weight: bold;
  285. }
  286. }
  287. .content {
  288. margin-top: 30upx;
  289. border-radius: 10px 10px 0 0;
  290. min-height: 30vh;
  291. .desc {
  292. padding: 5px 10px 10px;
  293. font-size: 14px;
  294. color: #3e3e3e;
  295. }
  296. }
  297. .tab {
  298. display: flex;
  299. width: 50vw;
  300. margin: 0 auto;
  301. padding: 10px 0;
  302. .tab-item {
  303. flex: 1;
  304. color: #6b6b6b;
  305. text-align: center;
  306. position: relative;
  307. .line {
  308. height: 3px;
  309. background-color: #1c85f1;
  310. border-radius: 8px;
  311. // position: absolute;
  312. left: 10px;
  313. width: 25px;
  314. bottom: 0;
  315. margin: 0 auto;
  316. margin-top: 8px;
  317. }
  318. }
  319. .active-item {
  320. color: #000;
  321. }
  322. }
  323. .directory {
  324. padding: 0 30upx;
  325. .chapt-title {
  326. // background-color: #eff2fc;
  327. border-left: 4px solid #1c85f1;
  328. font-size: 26upx;
  329. font-weight: 500;
  330. padding: 5px;
  331. color: #484848;
  332. border-radius: 2px;
  333. margin-bottom: 5px;
  334. }
  335. .chapt {
  336. padding-bottom: 10px;
  337. }
  338. .dirc-list {
  339. display: flex;
  340. padding-left: 10px;
  341. .right {
  342. flex: 1;
  343. padding: 10px;
  344. border-bottom: solid 1px #EFF1F6;
  345. font-size: 13px;
  346. .title {
  347. padding: 0;
  348. font-size: 13px;
  349. font-weight: 400 !important;
  350. margin-bottom: 5px;
  351. }
  352. }
  353. .minte {
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. }
  358. .progress {}
  359. }
  360. .active-video {
  361. .right {
  362. flex: 1;
  363. padding: 10px;
  364. border-bottom: solid 1px #EFF1F6;
  365. font-size: 13px;
  366. color: #1c85f1;
  367. .title {
  368. padding: 0;
  369. font-size: 13px;
  370. font-weight: 400 !important;
  371. margin-bottom: 5px;
  372. color: #1c85f1;
  373. }
  374. }
  375. }
  376. }
  377. </style>