onlineTrainingDetails.vue 9.8 KB

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