onlineTrainingDetails.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <template>
  2. <view class="details">
  3. <u-navbar back-text="" title="" back-icon-color="#FFFFFF" :background="{ background: '#3D5D4C' }" :border-bottom="false"></u-navbar>
  4. <!-- 视频 -->
  5. <view class="details-video" v-if="isPaly">
  6. <video class="details-video-con" id="myVideo" @timeupdate="timeUpdate" :src="videoInfo.videoUrl" controls
  7. :initial-time="initial_time" object-fit="fill" play-btn-position="center" @tap="videoClick">
  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="28" disabled="" active-color="#FFBC00" 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 > 5">
  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. }
  123. },
  124. onLoad(page) {
  125. if (page.id) {
  126. this.getClassesDetails(page.id);
  127. this.classesId = page.id
  128. }
  129. },
  130. beforeDestroy() {
  131. let playDuration = this.video_real_time;
  132. if (this.videoInfo.playDuration > this.video_real_time) {
  133. this.currentDuration = this.video_real_time;
  134. playDuration = this.videoInfo.playDuration
  135. } else {
  136. this.currentDuration = this.video_real_time
  137. }
  138. this.submitTimeLong({
  139. tabId: this.videoInfo.id,
  140. playDuration: playDuration,
  141. currentDuration: this.currentDuration
  142. }, 0, true)
  143. },
  144. methods: {
  145. /**
  146. * 显示倍速浮层
  147. * @param {Object} rate
  148. */
  149. showSwitchRate(rate) {
  150. let that = this;
  151. that.rateShow = true;
  152. },
  153. /**
  154. * 切换倍速
  155. * @param {Object} e
  156. */
  157. switchRate(e) {
  158. let that = this;
  159. let rate = Number(e.currentTarget.dataset.rate);
  160. that.currentRate = rate;
  161. that.rateShow = false;
  162. this.videoContext.playbackRate(rate);
  163. },
  164. /**
  165. * 视频点击
  166. * @param {Object} e
  167. */
  168. videoClick(e) {
  169. this.rateShow = false;
  170. },
  171. /**
  172. * 获取课程详情
  173. * @param {Object} id
  174. */
  175. getClassesDetails(id) {
  176. this.$u.api.training.getOnlineDetailsApi({
  177. id
  178. }).then(res => {
  179. if (res.code === 200) {
  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.tabId = res.data.chapterList[this.videoIndex].id
  186. this.form.tabId = res.data.chapterList[this.videoIndex].id
  187. this.query.pageNum = 1;
  188. this.isPaly = true
  189. this.getCommentList();
  190. }
  191. })
  192. },
  193. /**
  194. * 课程章节点击
  195. * @param {Object} index
  196. */
  197. classesClick(index) {
  198. this.isPaly = false;
  199. let playDuration = this.video_real_time;
  200. if (this.videoInfo.playDuration > this.video_real_time) {
  201. this.currentDuration = this.video_real_time;
  202. playDuration = this.videoInfo.playDuration
  203. } else {
  204. this.currentDuration = this.video_real_time
  205. }
  206. this.submitTimeLong ({
  207. tabId: this.videoInfo.id,
  208. playDuration: playDuration,
  209. currentDuration: this.currentDuration
  210. }, index);
  211. },
  212. /**
  213. * 控制视频不能快进
  214. * @param {Object} e
  215. */
  216. timeUpdate(e) {
  217. let isReady = 1; // 是否开启可以视频快进 1 禁止开启
  218. if (this.videoInfo.finishPercent === 100) {
  219. isReady = 3;
  220. }
  221. //跳转到指定播放位置 initial-time 时间为秒
  222. let that = this;
  223. //播放的总时长
  224. let duration = e.detail.duration
  225. //实时播放进度 秒数
  226. let currentTime = parseInt(e.detail.currentTime)
  227. //当前视频进度
  228. let jump_time = 0
  229. if (that.video_real_time == 0) {
  230. jump_time = parseInt(that.initial_time) + parseInt(that.video_real_time)
  231. } else {
  232. jump_time = parseInt(that.video_real_time)
  233. }
  234. console.log('jump_time', jump_time)
  235. console.log('that.initial_time', that.initial_time)
  236. console.log('this.playedTime', this.playedTime)
  237. console.log('that.video_real_time', that.video_real_time)
  238. if (jump_time > this.playedTime) {
  239. isReady = 1;
  240. } else {
  241. isReady = 3;
  242. }
  243. if(isReady === 1){
  244. if (currentTime > jump_time && currentTime - jump_time > 3) {
  245. let videoContext = wx.createVideoContext('myVideo')
  246. videoContext.seek(that.video_real_time)
  247. wx.showToast({
  248. title: '未完整看完该视频,不能快进',
  249. icon: 'none',
  250. duration: 2000,
  251. })
  252. }
  253. }
  254. that.video_real_time = currentTime //实时播放进度
  255. },
  256. /**
  257. * 提交课程时长
  258. */
  259. submitTimeLong({
  260. tabId,
  261. playDuration,
  262. currentDuration
  263. }, index, flag) {
  264. this.$u.api.training.videoTimeLongApi({
  265. tabId,
  266. playDuration,
  267. currentDuration
  268. }).then(res => {
  269. if (res.code === 200) {
  270. if (!flag) {
  271. this.$refs.uToast.show({
  272. title: '已记录章节时长!',
  273. type: 'success'
  274. })
  275. this.videoInfo = this.info.chapterList[index]
  276. this.form.tabId = this.videoInfo.id
  277. this.query.tabId = this.videoInfo.id
  278. this.videoIndex = index
  279. this.getClassesDetails(this.classesId);
  280. }
  281. } else {
  282. this.$refs.uToast.show({
  283. title: res.msg,
  284. type: 'error'
  285. })
  286. }
  287. })
  288. },
  289. /**
  290. * 获取评论列表
  291. */
  292. getCommentList() {
  293. this.$u.api.training.getClassesCommentApi(this.query).then(res => {
  294. if (res.code === 200) {
  295. this.total = Number(res.total);
  296. this.commentList = res.rows
  297. }
  298. })
  299. },
  300. /**
  301. * @param {Object} e 分页触发
  302. */
  303. pageChange(e) {
  304. this.query.pageNum = e.current
  305. this.getCommentList()
  306. },
  307. /**
  308. * 提交评论
  309. */
  310. submitCommet() {
  311. if (this.form.starLevel && this.form.content) {
  312. this.$u.api.training.addClassesCommentApi(this.form).then(res => {
  313. if (res.code === 200) {
  314. this.$refs.uToast.show({
  315. title: '评论成功!',
  316. type: 'success'
  317. })
  318. this.form.content = ''
  319. this.form.starLevel = 0
  320. this.getCommentList();
  321. } else {
  322. this.$refs.uToast.show({
  323. title: res.msg,
  324. type: 'error'
  325. })
  326. }
  327. })
  328. }
  329. if (!this.form.starLevel) {
  330. this.$refs.uToast.show({
  331. title: '请选择星级',
  332. type: 'warning'
  333. })
  334. }
  335. if (!this.form.content) {
  336. this.$refs.uToast.show({
  337. title: '请输入评论内容',
  338. type: 'warning'
  339. })
  340. }
  341. }
  342. }
  343. }
  344. </script>
  345. <style lang="scss" scoped>
  346. @import './onlineTrainingDetails.scss';
  347. </style>