detail.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. // app.request('/course/video?id=' + options.id, 'get').then(res => {
  139. // console.log(res)
  140. // })
  141. // app.request('/course/chapter?id=' + options.id, 'get').then(res => {
  142. // console.log(res)
  143. // })
  144. },
  145. methods: {
  146. getSettings() {
  147. app.request('/setting/keys', {
  148. keys: ['SENG_VIDEO_MSG'],
  149. }, 'post').then(res => {
  150. let data = res.data.data
  151. this.sendTime = data.SENG_VIDEO_MSG
  152. })
  153. },
  154. backLast: function() {
  155. uni.navigateBack()
  156. },
  157. //tab切换视频底部标签
  158. changeTab(e) {
  159. this.currentTab = e
  160. },
  161. //播放进度发生变化时
  162. timeupdate(event) {
  163. let currentTime = event.detail.currentTime
  164. if (currentTime) {
  165. let min = currentTime.toFixed(0)
  166. let yu = min % Number(this.sendTime)
  167. if (yu == 0 && min > 1 && this.currentMint !== min) {
  168. console.log(min, '-----', this.currentMint)
  169. this.currentMint = min
  170. this.postProgress(min)
  171. }
  172. }
  173. },
  174. //发送观看进度
  175. postProgress(currentTime) {
  176. let data = {
  177. course_id: this.msg.id,
  178. video_id: this.videoId,
  179. watch_seconds: currentTime
  180. }
  181. app.request('/course/video/look-record', data, 'post').then(res => {
  182. console.log(res, '观看进度')
  183. })
  184. },
  185. //点击切换视频
  186. changeNextVideo(item) {
  187. console.log(item, 'ppppp')
  188. let id = item.id
  189. this.videoId = item.id
  190. this.videoUrl = item.url_resource.url
  191. this.videoTitle = item.title
  192. this.videoDuration = item.duration
  193. if (item.progress !== 100) {
  194. this.initialTime = item.duration * item.progress
  195. }
  196. this.videoList.map((item1, index) => {
  197. if (item1.id == id) {
  198. this.currentVideo = index
  199. }
  200. })
  201. },
  202. //视频播放时触发
  203. videoPlay() {},
  204. //视频暂停播放
  205. videoPause() {},
  206. //视频播放结束
  207. videoEnd() {
  208. this.postProgress(this.videoDuration)
  209. setTimeout(() => {
  210. //播放结束自动播放下一节
  211. if (this.currentVideo == this.videoList.length - 1) {
  212. return
  213. } else {
  214. this.currentVideo++
  215. this.videoUrl = this.videoList[this.currentVideo].url_resource.url
  216. this.videoId = this.videoList[this.currentVideo].id
  217. this.videoTitle = this.videoList[this.currentVideo].title
  218. this.videoDuration = this.videoList[this.currentVideo].duration
  219. }
  220. }, 500)
  221. },
  222. //加载失败
  223. videoErrorCallback() {}
  224. }
  225. }
  226. </script>
  227. <style lang="scss">
  228. page {
  229. background-color: #EFF1F6;
  230. }
  231. .navbar {
  232. font-size: 32upx;
  233. height: 100upx;
  234. line-height: 100upx;
  235. color: #888888;
  236. position: relative;
  237. position: fixed;
  238. top: 0;
  239. z-index: 9999999;
  240. width: 100%;
  241. background-color: #FFFFFF;
  242. text-align: center;
  243. border-bottom: solid 2upx #EFF1F6;
  244. .back {
  245. height: 100upx;
  246. width: 100upx;
  247. text-align: center;
  248. position: absolute;
  249. float: left;
  250. left: 0upx;
  251. font-size: 32upx;
  252. }
  253. }
  254. .msg {
  255. margin-top: 100upx;
  256. background: white;
  257. padding-bottom: 10upx;
  258. .title {
  259. padding: 8px 0;
  260. font-weight: 550;
  261. color: #3e3e3e;
  262. font-size: 16px;
  263. padding: 0 30upx;
  264. }
  265. .tag {
  266. display: inline-block;
  267. border-radius: 3px;
  268. border: solid 1px #1c85f1;
  269. color: #1c85f1;
  270. font-size: 12px;
  271. padding: 0px 3px;
  272. margin-right: 5px;
  273. font-weight: normal;
  274. }
  275. .view1 {
  276. display: flex;
  277. align-items: center;
  278. justify-content: space-between;
  279. padding: 0 30upx;
  280. padding-top: 15upx;
  281. padding-bottom: 10px;
  282. font-size: 26upx;
  283. color: #888888;
  284. }
  285. .text1 {
  286. padding-left: 30upx;
  287. padding-top: 10upx;
  288. font-size: 32upx;
  289. color: black;
  290. font-weight: bold;
  291. }
  292. }
  293. .content {
  294. margin-top: 30upx;
  295. border-radius: 10px 10px 0 0;
  296. min-height: 30vh;
  297. .desc {
  298. padding: 5px 10px 10px;
  299. font-size: 14px;
  300. color: #3e3e3e;
  301. }
  302. }
  303. .tab {
  304. display: flex;
  305. width: 50vw;
  306. margin: 0 auto;
  307. padding: 10px 0;
  308. .tab-item {
  309. flex: 1;
  310. color: #6b6b6b;
  311. text-align: center;
  312. position: relative;
  313. .line {
  314. height: 3px;
  315. background-color: #1c85f1;
  316. border-radius: 8px;
  317. // position: absolute;
  318. left: 10px;
  319. width: 25px;
  320. bottom: 0;
  321. margin: 0 auto;
  322. margin-top: 8px;
  323. }
  324. }
  325. .active-item {
  326. color: #000;
  327. }
  328. }
  329. .directory {
  330. padding: 0 30upx;
  331. .chapt-title {
  332. // background-color: #eff2fc;
  333. border-left: 4px solid #1c85f1;
  334. font-size: 26upx;
  335. font-weight: 500;
  336. padding: 5px;
  337. color: #484848;
  338. border-radius: 2px;
  339. margin-bottom: 5px;
  340. }
  341. .chapt {
  342. padding-bottom: 10px;
  343. }
  344. .dirc-list {
  345. display: flex;
  346. padding-left: 10px;
  347. .right {
  348. flex: 1;
  349. padding: 10px;
  350. border-bottom: solid 1px #EFF1F6;
  351. font-size: 13px;
  352. .title {
  353. padding: 0;
  354. font-size: 13px;
  355. font-weight: 400 !important;
  356. margin-bottom: 5px;
  357. }
  358. }
  359. .minte {
  360. display: flex;
  361. align-items: center;
  362. justify-content: space-between;
  363. }
  364. .progress {}
  365. }
  366. .active-video {
  367. .right {
  368. flex: 1;
  369. padding: 10px;
  370. border-bottom: solid 1px #EFF1F6;
  371. font-size: 13px;
  372. color: #1c85f1;
  373. .title {
  374. padding: 0;
  375. font-size: 13px;
  376. font-weight: 400 !important;
  377. margin-bottom: 5px;
  378. color: #1c85f1;
  379. }
  380. }
  381. }
  382. }
  383. </style>