courseDetailed.vue 10 KB

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