courseDetailed.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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="isPlay">
  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">
  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. isPlay: 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.school.getPackageCourseDetail({
  177. id
  178. }).then(res => {
  179. if (res.code === 200) {
  180. console.log(res)
  181. this.info = res.data;
  182. this.videoInfo = res.data.chapterList[this.videoIndex];
  183. this.initial_time = Number(res.data.chapterList[this.videoIndex].currentDuration)
  184. this.video_real_time = Number(res.data.chapterList[this.videoIndex].playDuration)
  185. this.playedTime = Number(res.data.chapterList[this.videoIndex].playDuration)
  186. this.query.tabId = res.data.chapterList[this.videoIndex].id
  187. this.form.tabId = res.data.chapterList[this.videoIndex].id
  188. this.query.pageNum = 1;
  189. this.isPlay = true
  190. this.getCommentList();
  191. }
  192. })
  193. },
  194. /**
  195. * 课程章节点击
  196. * @param {Object} index
  197. */
  198. classesClick(index) {
  199. this.isPlay = false;
  200. let playDuration = this.video_real_time;
  201. if (this.videoInfo.playDuration > this.video_real_time) {
  202. this.currentDuration = this.video_real_time;
  203. playDuration = this.videoInfo.playDuration
  204. } else {
  205. this.currentDuration = this.video_real_time
  206. }
  207. this.submitTimeLong ({
  208. tabId: this.videoInfo.id,
  209. playDuration: playDuration,
  210. currentDuration: this.currentDuration
  211. }, index);
  212. },
  213. /**
  214. * 控制视频不能快进
  215. * @param {Object} e
  216. */
  217. timeUpdate(e) {
  218. let isReady = 1; // 是否开启可以视频快进 1 禁止开启
  219. if (this.videoInfo.finishPercent === 100) {
  220. isReady = 3;
  221. }
  222. //跳转到指定播放位置 initial-time 时间为秒
  223. let that = this;
  224. //播放的总时长
  225. let duration = e.detail.duration
  226. //实时播放进度 秒数
  227. let currentTime = parseInt(e.detail.currentTime)
  228. //当前视频进度
  229. let jump_time = 0
  230. if (that.video_real_time == 0) {
  231. jump_time = parseInt(that.initial_time) + parseInt(that.video_real_time)
  232. } else {
  233. jump_time = parseInt(that.video_real_time)
  234. }
  235. console.log('jump_time', jump_time)
  236. console.log('that.initial_time', that.initial_time)
  237. console.log('this.playedTime', this.playedTime)
  238. console.log('that.video_real_time', that.video_real_time)
  239. if (jump_time > this.playedTime) {
  240. isReady = 1;
  241. } else {
  242. isReady = 3;
  243. }
  244. if(isReady === 1){
  245. if (currentTime > jump_time && currentTime - jump_time > 3) {
  246. let videoContext = wx.createVideoContext('myVideo')
  247. videoContext.seek(that.video_real_time)
  248. wx.showToast({
  249. title: '未完整看完该视频,不能快进',
  250. icon: 'none',
  251. duration: 2000,
  252. })
  253. }
  254. }
  255. that.video_real_time = currentTime //实时播放进度
  256. },
  257. /**
  258. * 提交课程时长
  259. */
  260. submitTimeLong({
  261. tabId,
  262. playDuration,
  263. currentDuration
  264. }, index, flag) {
  265. if (tabId) {
  266. this.$u.api.training.videoTimeLongApi({
  267. tabId,
  268. playDuration,
  269. currentDuration
  270. }).then(res => {
  271. if (res.code === 200) {
  272. if (!flag) {
  273. this.$refs.uToast.show({
  274. title: '已记录章节时长!',
  275. type: 'success'
  276. })
  277. this.videoInfo = this.info.chapterList[index]
  278. this.form.tabId = this.videoInfo.id
  279. this.query.tabId = this.videoInfo.id
  280. this.videoIndex = index
  281. this.getClassesDetails(this.classesId);
  282. }
  283. } else {
  284. this.$refs.uToast.show({
  285. title: res.msg,
  286. type: 'error'
  287. })
  288. }
  289. })
  290. }
  291. },
  292. /**
  293. * 获取评论列表
  294. */
  295. getCommentList() {
  296. if (this.query.tabId) {
  297. this.$u.api.training.getClassesCommentApi(this.query).then(res => {
  298. if (res.code === 200) {
  299. this.total = Number(res.total);
  300. this.commentList = res.rows
  301. }
  302. })
  303. }
  304. },
  305. /**
  306. * @param {Object} e 分页触发
  307. */
  308. pageChange(e) {
  309. this.query.pageNum = e.current
  310. this.getCommentList()
  311. },
  312. /**
  313. * 提交评论
  314. */
  315. submitCommet() {
  316. if (this.form.tabId) {
  317. if (this.form.starLevel && this.form.content) {
  318. this.$u.api.training.addClassesCommentApi(this.form).then(res => {
  319. if (res.code === 200) {
  320. this.$refs.uToast.show({
  321. title: '评论成功!',
  322. type: 'success'
  323. })
  324. this.form.content = ''
  325. this.form.starLevel = 0
  326. this.getCommentList();
  327. } else {
  328. this.$refs.uToast.show({
  329. title: res.msg,
  330. type: 'error'
  331. })
  332. }
  333. })
  334. }
  335. if (!this.form.starLevel) {
  336. this.$refs.uToast.show({
  337. title: '请选择星级',
  338. type: 'warning'
  339. })
  340. }
  341. if (!this.form.content) {
  342. this.$refs.uToast.show({
  343. title: '请输入评论内容',
  344. type: 'warning'
  345. })
  346. }
  347. } else {
  348. this.$refs.uToast.show({
  349. title: '未找到课程章节,无法提交评论!',
  350. type: 'warning'
  351. })
  352. }
  353. }
  354. }
  355. }
  356. </script>
  357. <style lang="scss" scoped>
  358. @import './courseDetailed.scss';
  359. </style>