courseDetail.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="details">
  3. <!-- 视频 -->
  4. <view class="details-video" v-if="isPaly">
  5. <video class="details-video-con" id="myVideo" @timeupdate="timeUpdate" :src="videoInfo.videoUrl" controls
  6. :initial-time="initial_time" object-fit="fill" play-btn-position="center" @tap="videoClick"
  7. @loadedmetadata="loadedmetadata">
  8. <cover-view class="video-control">
  9. <cover-view class="multi rate" @tap.stop="showSwitchRate">x {{ currentRate }}</cover-view>
  10. </cover-view>
  11. <cover-view class="multi-list rate" :class="{ active: rateShow }">
  12. <cover-view v-for="(item, index) in ['0.5', '1.0', '1.5', '2.0']" :key="index"
  13. class="multi-item rate" :data-rate="item" @tap="switchRate"
  14. :class="{ active: item == currentRate }">
  15. {{ item }}
  16. </cover-view>
  17. </cover-view>
  18. </video>
  19. </view>
  20. <!-- 介绍 -->
  21. <view class="details-content">
  22. <view class="details-content-title">{{ videoInfo.chapterName }}</view>
  23. <view class="details-content-progress">本课程
  24. 共{{ info.amount }}课,已学完{{ info.finishCount }}课,共进度{{ info.finishPercent || 0 }}%</view>
  25. <view class="details-content-teacher">主讲老师:{{ info.presenter }}</view>
  26. <view class="details-content-info">{{ videoInfo.chapterInfo }}</view>
  27. </view>
  28. <!-- 课程章节 -->
  29. <view class="details-classes">
  30. <view class="details-classes-header">
  31. <view>精选课程</view>
  32. <view>更多
  33. <u-icon name="arrow-right" size="22" color="#A3A3A3" />
  34. </view>
  35. </view>
  36. <view class="details-classes-list">
  37. <view class="details-classes-list-item" v-for="(item, index) in info.chapterList" :key="index"
  38. :class="{'active': index === videoIndex }" @click="classesClick(index)">
  39. <view>{{ index + 1 }}</view>
  40. <view>{{ item.flag === 2 ? '已学' : (item.finishPercent + '%') }}</view>
  41. </view>
  42. </view>
  43. </view>
  44. <view class="details-line">
  45. <view></view>
  46. </view>
  47. <!-- 评论 -->
  48. <view class="details-comment">
  49. <view class="details-comment-header">
  50. <view>课程评论</view>
  51. <view>共{{ total }}条评论</view>
  52. </view>
  53. <view class="details-comment-list">
  54. <view class="details-comment-list-item" v-for="(item, index) in commentList" :key="index">
  55. <view class="left">
  56. <u-avatar :src="item.createByAvatar" size="96" mode="square"></u-avatar>
  57. </view>
  58. <view class="right">
  59. <view>{{ item.createBy }}</view>
  60. <view>
  61. <u-rate :count="5" size="24" disabled="" active-color="#C4C4C4" v-model="item.starLevel">
  62. </u-rate>
  63. <text>{{ item.createTime }}</text>
  64. </view>
  65. <view>{{ item.content }}</view>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="details-comment-page" v-if="total">
  70. <wyb-pagination :padding="0" :totalItems="total" :current="query.pageNum" @change="pageChange" />
  71. </view>
  72. <view class="details-comment-mine">
  73. <text>我的评论</text>
  74. </view>
  75. <view class="details-comment-conent">
  76. <view class="details-comment-conent-star">
  77. <u-rate :count="5" size="40" active-color="#FFBC00" v-model="form.starLevel"></u-rate>
  78. </view>
  79. <view class="details-comment-content-textarea">
  80. <u-input v-model="form.content" placeholder="请输入您的评价" type="textarea"
  81. :custom-style="{ backgroundColor: '#F5F5F5', padding: '30rpx', borderRadius: '10rpx', minHeight: '280rpx' }">
  82. </u-input>
  83. </view>
  84. <view class="details-comment-conent-button" @click="submitCommet">提交</view>
  85. </view>
  86. </view>
  87. <u-toast ref="uToast" />
  88. </view>
  89. </template>
  90. <script>
  91. import wybPagination from '@/components/wyb-pagination/wyb-pagination.vue'
  92. export default {
  93. data() {
  94. return {
  95. info: {},
  96. videoContext: uni.createVideoContext('myVideo', this),
  97. videoInfo: {},
  98. videoIndex: 0,
  99. // 视频实时时间
  100. initial_time: 0,
  101. // 视频已经播放时间
  102. playedTime: 0,
  103. rateShow: false, // 倍速浮层
  104. currentRate: 1.0, // 默认倍速
  105. // 视频实际时间
  106. video_real_time: 0,
  107. classesId: '',
  108. isPaly: true,
  109. query: {
  110. pageNum: 1,
  111. pageSize: 5,
  112. tabId: ''
  113. },
  114. total: 0,
  115. commentList: [],
  116. form: {
  117. tabId: '',
  118. starLevel: 0,
  119. content: ''
  120. },
  121. currentDuration: 0,
  122. duration: 0
  123. }
  124. },
  125. onLoad(page) {
  126. if (page.id) {
  127. this.getClassesDetails(page.id);
  128. this.classesId = page.id
  129. this.query.tabId = this.classesId
  130. this.form.tabId = this.classesId
  131. }
  132. },
  133. beforeDestroy() {
  134. this.confirmSubmitDuration();
  135. },
  136. methods: {
  137. /**
  138. * 获取视频总时长
  139. * @param {Object} data
  140. */
  141. loadedmetadata(data) {
  142. this.duration = data.detail.duration;
  143. },
  144. /**
  145. * 显示倍速浮层
  146. * @param {Object} rate
  147. */
  148. showSwitchRate(rate) {
  149. let that = this;
  150. that.rateShow = true;
  151. },
  152. /**
  153. * 切换倍速
  154. * @param {Object} e
  155. */
  156. switchRate(e) {
  157. let that = this;
  158. let rate = Number(e.currentTarget.dataset.rate);
  159. that.currentRate = rate;
  160. that.rateShow = false;
  161. this.videoContext.playbackRate(rate);
  162. },
  163. /**
  164. * 视频点击
  165. * @param {Object} e
  166. */
  167. videoClick(e) {
  168. this.rateShow = false;
  169. },
  170. /**
  171. * 获取课程详情
  172. * @param {Object} id
  173. */
  174. getClassesDetails(id) {
  175. this.$u.api.school.getPackageCourseDetail({
  176. id
  177. }).then(res => {
  178. if (res.code === 200) {
  179. console.log(res)
  180. this.info = res.data;
  181. this.videoInfo = res.data.chapterList[this.videoIndex];
  182. this.initial_time = Number(res.data.chapterList[this.videoIndex].currentDuration)
  183. this.video_real_time = Number(res.data.chapterList[this.videoIndex].playDuration)
  184. this.playedTime = Number(res.data.chapterList[this.videoIndex].playDuration)
  185. this.query.pageNum = res.data.page;
  186. this.isPaly = true
  187. this.getCommentList();
  188. }
  189. })
  190. },
  191. /**
  192. * 课程章节点击
  193. * @param {Object} index
  194. */
  195. classesClick(index) {
  196. this.isPaly = false;
  197. let playDuration = this.video_real_time;
  198. if (this.videoInfo.playDuration > this.video_real_time) {
  199. this.currentDuration = this.video_real_time;
  200. playDuration = this.videoInfo.playDuration
  201. } else {
  202. this.currentDuration = this.video_real_time
  203. }
  204. this.submitTimeLong({
  205. tabId: this.videoInfo.id,
  206. playDuration: playDuration,
  207. duration: this.duration,
  208. currentDuration: this.currentDuration
  209. }, index);
  210. },
  211. /**
  212. * 控制视频不能快进
  213. * @param {Object} e
  214. */
  215. timeUpdate(e) {
  216. //播放的总时长
  217. let duration = e.detail.duration;
  218. //实时播放进度 秒数
  219. let jumpTime = parseInt(e.detail.currentTime);
  220. //当前视频进度
  221. if (jumpTime - this.playedTime > 3) {
  222. // 差别过大,调用seek方法跳转到实际观看时间
  223. this.videoContext.seek(this.playedTime);
  224. wx.showToast({
  225. title: '未完整看完该视频,不能快进',
  226. icon: 'none',
  227. duration: 2000
  228. });
  229. } else {
  230. this.video_real_time = parseInt(e.detail.currentTime);
  231. if (this.video_real_time > this.playedTime) {
  232. this.playedTime = this.video_real_time;
  233. }
  234. }
  235. if (parseInt(this.duration) !== 0 && parseInt(this.duration) === parseInt(this.video_real_time)) {
  236. this.videoContext.pause();
  237. this.confirmSubmitDuration()
  238. }
  239. },
  240. /**
  241. * 提交课程时长
  242. */
  243. submitTimeLong({
  244. tabId,
  245. playDuration,
  246. duration,
  247. currentDuration
  248. }, index, flag) {
  249. if (tabId) {
  250. this.$u.api.training.videoTimeLongApi({
  251. tabId,
  252. playDuration,
  253. duration,
  254. currentDuration
  255. }).then(res => {
  256. if (res.code === 200) {
  257. if (!flag) {
  258. this.$refs.uToast.show({
  259. title: '已记录章节时长!',
  260. type: 'success'
  261. })
  262. this.videoInfo = this.info.chapterList[index]
  263. this.videoIndex = index
  264. this.getClassesDetails(this.classesId);
  265. }
  266. } else {
  267. this.$refs.uToast.show({
  268. title: res.msg,
  269. type: 'error'
  270. })
  271. }
  272. })
  273. }
  274. },
  275. /**
  276. * 获取评论列表
  277. */
  278. getCommentList() {
  279. if (this.query.tabId) {
  280. this.$u.api.training.getClassesCommentApi(this.query).then(res => {
  281. if (res.code === 200) {
  282. this.total = Number(res.data.total);
  283. this.commentList = res.data.rows
  284. }
  285. })
  286. }
  287. },
  288. /**
  289. * @param {Object} e 分页触发
  290. */
  291. pageChange(e) {
  292. this.query.pageNum = e.current
  293. this.getCommentList()
  294. },
  295. /**
  296. * 提交评论
  297. */
  298. submitCommet() {
  299. if (this.form.tabId) {
  300. if (this.form.starLevel && this.form.content) {
  301. this.$u.api.training.addClassesCommentApi(this.form).then(res => {
  302. if (res.code === 200) {
  303. this.$refs.uToast.show({
  304. title: '评论成功!',
  305. type: 'success'
  306. })
  307. this.form.content = ''
  308. this.form.starLevel = 0
  309. this.getCommentList();
  310. } else {
  311. this.$refs.uToast.show({
  312. title: res.msg,
  313. type: 'error'
  314. })
  315. }
  316. })
  317. }
  318. if (!this.form.starLevel) {
  319. this.$refs.uToast.show({
  320. title: '请选择星级',
  321. type: 'warning'
  322. })
  323. }
  324. if (!this.form.content) {
  325. this.$refs.uToast.show({
  326. title: '请输入评论内容',
  327. type: 'warning'
  328. })
  329. }
  330. } else {
  331. this.$refs.uToast.show({
  332. title: '未找到课程章节,无法提交评论!',
  333. type: 'warning'
  334. })
  335. }
  336. },
  337. confirmSubmitDuration() {
  338. let playDuration = this.video_real_time;
  339. if (this.videoInfo.playDuration > this.video_real_time) {
  340. this.currentDuration = this.video_real_time;
  341. playDuration = this.videoInfo.playDuration
  342. } else {
  343. this.currentDuration = this.video_real_time
  344. }
  345. this.submitTimeLong({
  346. tabId: this.videoInfo.id,
  347. playDuration: playDuration,
  348. duration: this.duration,
  349. currentDuration: this.currentDuration
  350. }, 0, true)
  351. }
  352. }
  353. }
  354. </script>
  355. <style lang="scss" scoped>
  356. @import './courseDetail.scss';
  357. </style>