courseDetailed.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <view class="details">
  3. <!-- 视频 -->
  4. <view class="details-video" v-if="isPlay">
  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="28" disabled="" active-color="#FFBC00" 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">
  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. isPlay: 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.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.tabId = res.data.chapterList[this.videoIndex].id
  186. this.form.tabId = res.data.chapterList[this.videoIndex].id
  187. this.query.pageNum = 1;
  188. this.isPlay = true
  189. this.getCommentList();
  190. }
  191. })
  192. },
  193. /**
  194. * 课程章节点击
  195. * @param {Object} index
  196. */
  197. classesClick(index) {
  198. this.isPlay = 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. if (tabId) {
  265. this.$u.api.training.videoTimeLongApi({
  266. tabId,
  267. playDuration,
  268. currentDuration
  269. }).then(res => {
  270. if (res.code === 200) {
  271. if (!flag) {
  272. this.$refs.uToast.show({
  273. title: '已记录章节时长!',
  274. type: 'success'
  275. })
  276. this.videoInfo = this.info.chapterList[index]
  277. this.form.tabId = this.videoInfo.id
  278. this.query.tabId = this.videoInfo.id
  279. this.videoIndex = index
  280. this.getClassesDetails(this.classesId);
  281. }
  282. } else {
  283. this.$refs.uToast.show({
  284. title: res.msg,
  285. type: 'error'
  286. })
  287. }
  288. })
  289. }
  290. },
  291. /**
  292. * 获取评论列表
  293. */
  294. getCommentList() {
  295. if (this.query.tabId) {
  296. this.$u.api.training.getClassesCommentApi(this.query).then(res => {
  297. if (res.code === 200) {
  298. this.total = Number(res.total);
  299. this.commentList = res.rows
  300. }
  301. })
  302. }
  303. },
  304. /**
  305. * @param {Object} e 分页触发
  306. */
  307. pageChange(e) {
  308. this.query.pageNum = e.current
  309. this.getCommentList()
  310. },
  311. /**
  312. * 提交评论
  313. */
  314. submitCommet() {
  315. if (this.form.tabId) {
  316. if (this.form.starLevel && this.form.content) {
  317. this.$u.api.training.addClassesCommentApi(this.form).then(res => {
  318. if (res.code === 200) {
  319. this.$refs.uToast.show({
  320. title: '评论成功!',
  321. type: 'success'
  322. })
  323. this.form.content = ''
  324. this.form.starLevel = 0
  325. this.getCommentList();
  326. } else {
  327. this.$refs.uToast.show({
  328. title: res.msg,
  329. type: 'error'
  330. })
  331. }
  332. })
  333. }
  334. if (!this.form.starLevel) {
  335. this.$refs.uToast.show({
  336. title: '请选择星级',
  337. type: 'warning'
  338. })
  339. }
  340. if (!this.form.content) {
  341. this.$refs.uToast.show({
  342. title: '请输入评论内容',
  343. type: 'warning'
  344. })
  345. }
  346. } else {
  347. this.$refs.uToast.show({
  348. title: '未找到课程章节,无法提交评论!',
  349. type: 'warning'
  350. })
  351. }
  352. }
  353. }
  354. }
  355. </script>
  356. <style lang="scss" scoped>
  357. @import './courseDetailed.scss';
  358. </style>