detail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <view v-if="isVip">
  3. <view class="video_play" v-if="videoInfo.video_src">
  4. <video
  5. id="myVideo"
  6. class="video_control"
  7. @play="_videoPlay"
  8. :src="videoInfo.video_src"
  9. @timeupdate="timeUpdate"
  10. :enable-progress-gesture="false"
  11. :enable-play-gesture="true"
  12. :enable-auto-rotation="true"
  13. :initial-time="videoInfo.inittime || 0"
  14. :show-bottom-progress="videoInfo.learn_status == 1"
  15. @ended="_videoEnd"
  16. @fullscreenchange="screenChange"
  17. ></video>
  18. <cover-view v-if="videoInfo.learn_status == 0" :class="bigsScreen ? 'bigScreen' : 'cover'"></cover-view>
  19. </view>
  20. <view class="video_title">{{ videoInfo.name }}</view>
  21. <view class="rich_text">
  22. <rich-text :nodes="videoInfo.content"></rich-text>
  23. </view>
  24. <view class="contact_follow" v-if="videoInfo.service?.url">
  25. <button class="contact_btn" @click.stop="openCustomer()">
  26. <uni-icons type="headphones" size="30" color="#FFFFFF"></uni-icons>
  27. </button>
  28. </view>
  29. <uni-popup ref="questionRef" type="center" :is-mask-click="false">
  30. <view class="popup_content">
  31. <!-- 答题区域 -->
  32. <view class="content" v-if="!show_answer">
  33. <!-- 问题内容 -->
  34. <view class="question_content">{{ questinInfo.question_title }}</view>
  35. <!-- 问题选项 -->
  36. <view class="question_options">
  37. <view v-for="(option, index) in questinInfo.answer_list" :key="index" :class="['question_answer', { active: answer_id == option.id }]" @click="_selectAnswer(option.id)">
  38. {{ option.value }}
  39. </view>
  40. </view>
  41. <view :class="['submit_btn', { active: answer_id }]" @click="_submitAnswer">提交</view>
  42. </view>
  43. <!-- 结果区域 -->
  44. <view class="content" v-else>
  45. <icon :type="answerInfo.is_answer == 1 ? 'success' : 'cancel'" size="64" />
  46. <view class="title">{{ answerInfo.is_answer == 1 ? '恭喜您,答对啦!' : '很遗憾,答错了' }}</view>
  47. <view class="tip">{{ answerInfo.is_answer == 1 ? '继续保持,你正在进步!' : '别灰心,再接再厉!' }}</view>
  48. <view class="score_content">
  49. <view>得分</view>
  50. <view :style="answerInfo.get_score == 0 ? 'color:red' : 'color:green'">+{{ answerInfo.get_score }}</view>
  51. </view>
  52. <view class="submit_btn active" @click="_goPlayVedio">继续学习视频</view>
  53. </view>
  54. </view>
  55. </uni-popup>
  56. </view>
  57. <view v-else>
  58. <view class="not_vip">
  59. <image src="https://kailin-mp.oss-cn-shenzhen.aliyuncs.com/static/icon/is_no_vip.png" style="width: 300rpx; height: 252rpx" />
  60. <view class="content">
  61. <text>您还不是会员,暂时无法观看视频,请联系客服。</text>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. videoInfo: {
  71. id: 0,
  72. name: '',
  73. content: '',
  74. video_src: '',
  75. },
  76. // 请求参数
  77. requestParam: {
  78. id: 0,
  79. },
  80. isReqing: false,
  81. videoContext: null,
  82. isAnswerQuestion: false,
  83. timer: null,
  84. currentTime: 0, // 新增变量用于存储当前播放时间
  85. questionTime_list: [],
  86. questinInfo: {},
  87. answer_id: null,
  88. is_correct: false,
  89. show_answer: false,
  90. answeredQuestions: new Set(), // 新增变量用于存储已回答的问题
  91. countdown: 0, // 新增变量用于存储倒计时时间
  92. bigsScreen: false,
  93. isVip: true,
  94. };
  95. },
  96. onLoad(param) {
  97. // 参数接收
  98. this.requestParam.id = param.id;
  99. // 如果存在产品ID的话
  100. if (this.requestParam.id > 0) {
  101. // 请求详情
  102. this.$http.request('api/video_course/get_detail', this.requestParam).then((re) => {
  103. // 成功渲染数据
  104. if (re.code == 'success') {
  105. // 刷新数据
  106. this.videoInfo = re.data;
  107. if (re.data.question_list) {
  108. this.questionTime_list = re.data?.question_list.map((item) => item.play_time);
  109. }
  110. // 获取视频容器的上下文
  111. this.videoContext = uni.createVideoContext('myVideo');
  112. // 暂停播放
  113. this.videoContext.stop();
  114. // #ifdef MP-WEIXIN
  115. uni.enableAlertBeforeUnload({
  116. message: '您确定要退出学习吗?',
  117. success: function (res) {
  118. console.log('方法注册成功:', res);
  119. },
  120. fail: function (errMsg) {
  121. console.log('方法注册失败:', errMsg);
  122. },
  123. });
  124. // #endif
  125. } else {
  126. if (re.code != 'no_login') {
  127. this.isVip = false;
  128. _isVip = false;
  129. // uni.showModal({
  130. // content: re.msg,
  131. // showCancel: false,
  132. // });
  133. }
  134. }
  135. });
  136. }
  137. // #ifdef MP-WEIXIN
  138. //分享按钮
  139. uni.showShareMenu({
  140. withShareTicket: true,
  141. menus: ['shareAppMessage', 'shareTimeline'],
  142. });
  143. // #endif
  144. },
  145. onUnload() {
  146. console.log('页面卸载');
  147. clearInterval(this.timer);
  148. },
  149. onShareAppMessage(obj) {
  150. return {
  151. title: `999智控终端平台\n${this.videoInfo.title}`,
  152. path: '/pages/video/detail?id=' + this.videoInfo.id,
  153. promise: new Promise((resolve, reject) => {
  154. this.$http
  155. .request('api/share_message/get_item', {
  156. item_id: this.videoInfo.id,
  157. pages: '/pages/video/detail',
  158. })
  159. .then((callback) => {
  160. console.log(callback, 'api/share_message/get_item');
  161. let obj = {
  162. title: callback.data?.title == '' ? `999智控终端平台\n${this.videoInfo.title}` : callback.data.title,
  163. path: '/pages/video/detail?id=' + this.videoInfo.id,
  164. };
  165. if (callback.data?.image_url !== '') {
  166. obj.imageUrl = callback.data.image_url;
  167. }
  168. resolve(obj);
  169. });
  170. }),
  171. };
  172. },
  173. onReady: function (res) {},
  174. onShow() {},
  175. methods: {
  176. openCustomer() {
  177. // #ifdef MP-WEIXIN
  178. console.log(1);
  179. wx.openCustomerServiceChat({
  180. extInfo: { url: this.videoInfo.service?.url },
  181. corpId: this.videoInfo.service?.corpid,
  182. success(res) {},
  183. });
  184. // #endif
  185. },
  186. timeUpdate(event) {
  187. this.currentTime = event.detail.currentTime; // 更新当前播放时间
  188. // 播放到对应的
  189. if (this.currentTime) {
  190. if (!this.timer) {
  191. this.timer = setInterval(() => {
  192. this._postVideoDuration(this.currentTime, 0);
  193. }, 3000);
  194. }
  195. if (this.currentTime == event.detail.duration) {
  196. this._postVideoDuration(this.currentTime, 1);
  197. }
  198. // 判断当前时间是否接近答题时间,并且该问题尚未回答
  199. if (this.questionTime_list.includes(parseInt(this.currentTime) + 3) && !this.answeredQuestions.has(parseInt(this.currentTime) + 3)) {
  200. this.countdown = 3;
  201. this._startCountdown();
  202. }
  203. if (this.questionTime_list.includes(parseInt(this.currentTime)) && !this.answeredQuestions.has(parseInt(this.currentTime))) {
  204. this.questinInfo = this.videoInfo.question_list.find((item) => item.play_time == parseInt(this.currentTime));
  205. this.videoContext.pause();
  206. this.videoContext.exitFullScreen();
  207. this.$refs.questionRef.open('center');
  208. //答题时间停止上报
  209. clearInterval(this.timer);
  210. this.timer = null;
  211. }
  212. }
  213. },
  214. _videoPlay() {
  215. console.log('开始播放');
  216. this.videoContext.requestFullScreen();
  217. },
  218. //上报视频播放时间
  219. _postVideoDuration(video_playtime, status) {
  220. if (status == 1) {
  221. clearInterval(this.timer);
  222. this.timer = null;
  223. }
  224. this.$http
  225. .request('api/video_learn_record/update_playtime', {
  226. record_id: this.videoInfo.record_id,
  227. video_playtime,
  228. status,
  229. })
  230. .then((re) => {
  231. if (re.code == 'success') {
  232. console.log('上报成功', video_playtime, status);
  233. }
  234. });
  235. },
  236. _selectAnswer(answer_id) {
  237. this.answer_id = answer_id;
  238. },
  239. _submitAnswer() {
  240. this.$http
  241. .request('api/video_learn_answer/play_exam', {
  242. record_id: this.videoInfo.record_id,
  243. course_id: this.questinInfo.course_id,
  244. question_id: this.questinInfo.question_id,
  245. answer_id: this.answer_id,
  246. })
  247. .then((re) => {
  248. if (re.code == 'success') {
  249. this.show_answer = true;
  250. this.answerInfo = re.data;
  251. // 将当前问题标记为已回答
  252. this.answeredQuestions.add(this.questinInfo.play_time);
  253. }
  254. });
  255. },
  256. _goPlayVedio() {
  257. this.questinInfo.isAnswer = true;
  258. this.show_answer = false;
  259. this.$refs.questionRef.close();
  260. uni.showToast({
  261. title: '2秒后切换横屏',
  262. icon: 'none',
  263. duration: 2000,
  264. });
  265. setTimeout(() => {
  266. this.videoContext.play();
  267. }, 2000);
  268. },
  269. _startCountdown() {
  270. const countdownInterval = setInterval(() => {
  271. if (this.countdown > 0) {
  272. uni.showToast({
  273. title: `${this.countdown}秒后进入答题`,
  274. icon: 'none',
  275. duration: 1000,
  276. });
  277. this.countdown--;
  278. } else {
  279. clearInterval(countdownInterval);
  280. }
  281. }, 1000);
  282. },
  283. _videoEnd() {
  284. const _this = this;
  285. this.videoContext.pause();
  286. this.videoContext.exitFullScreen();
  287. this._postVideoDuration(this.currentTime, 1);
  288. uni.showModal({
  289. title: '学习结束',
  290. content: '恭喜您学习结束,是否查看报告?',
  291. cancelText: '重新学习',
  292. success: (res) => {
  293. if (res.confirm) {
  294. uni.redirectTo({
  295. url: `/pages/video/record?type=learn&record_id=${this.videoInfo.record_id}`,
  296. });
  297. } else {
  298. //用户重新学习,将播放进度重新设为0
  299. setTimeout(() => {
  300. // 跳转到指定的时间位置
  301. _this.videoContext.seek(0);
  302. // _this.videoContext.play();
  303. }, 200);
  304. }
  305. },
  306. });
  307. },
  308. screenChange(event) {
  309. let fullScreen = event.detail.fullScreen;
  310. console.log('fullScreen', fullScreen);
  311. this.bigsScreen = fullScreen;
  312. },
  313. },
  314. };
  315. </script>
  316. <style lang="less">
  317. .video_play {
  318. width: 750rpx;
  319. display: block;
  320. font-size: 36rpx;
  321. overflow: hidden;
  322. font-weight: bold;
  323. line-height: 60rpx;
  324. background-color: #ffffff;
  325. position: relative;
  326. .video_control {
  327. width: 750rpx;
  328. display: block;
  329. font-size: 36rpx;
  330. overflow: hidden;
  331. font-weight: bold;
  332. line-height: 60rpx;
  333. background-color: #ffffff;
  334. }
  335. .cover {
  336. position: absolute;
  337. bottom: 0;
  338. z-index: 998;
  339. height: 20%;
  340. /* background-color: red; */
  341. background-color: rgba(255, 255, 255, 0.007);
  342. margin-left: 60px;
  343. width: 70%;
  344. }
  345. .bigScreen {
  346. position: absolute;
  347. bottom: -65%;
  348. z-index: 998;
  349. height: 20%;
  350. /* background-color: red; */
  351. background-color: rgba(255, 255, 255, 0.007);
  352. margin-left: 140px;
  353. width: 65%;
  354. }
  355. }
  356. .video_title {
  357. width: 700rpx;
  358. display: block;
  359. font-size: 36rpx;
  360. overflow: hidden;
  361. font-weight: bold;
  362. line-height: 60rpx;
  363. padding: 0rpx 25rpx;
  364. padding-top: 60rpx;
  365. background-color: #ffffff;
  366. }
  367. .video_time {
  368. width: 700rpx;
  369. color: #999999;
  370. display: block;
  371. font-size: 26rpx;
  372. overflow: hidden;
  373. line-height: 40rpx;
  374. padding: 0rpx 25rpx;
  375. background-color: #ffffff;
  376. }
  377. .rich_text {
  378. width: 700rpx;
  379. display: block;
  380. overflow: hidden;
  381. font-size: 26rpx;
  382. margin: 0rpx auto;
  383. min-height: 800rpx;
  384. line-height: 50rpx;
  385. padding: 10rpx 25rpx;
  386. background-color: #ffffff;
  387. [alt] {
  388. //web_view图片
  389. max-width: 100%; // 避免图片超宽
  390. vertical-align: bottom; // 避免图片之间间隙
  391. }
  392. }
  393. .video_poster {
  394. width: 700rpx;
  395. display: block;
  396. overflow: hidden;
  397. margin: 6rpx auto;
  398. padding: 10rpx 25rpx;
  399. background-color: #ffffff;
  400. .poster_img {
  401. width: 700rpx;
  402. display: block;
  403. }
  404. }
  405. .read_total {
  406. width: 700rpx;
  407. color: #999999;
  408. display: block;
  409. font-size: 26rpx;
  410. overflow: hidden;
  411. line-height: 60rpx;
  412. padding: 0rpx 25rpx;
  413. margin-bottom: 122rpx;
  414. background-color: #ffffff;
  415. }
  416. .handle_box {
  417. left: 0rpx;
  418. width: 700rpx;
  419. height: 120rpx;
  420. display: block;
  421. position: fixed;
  422. overflow: hidden;
  423. padding: 20rpx 25rpx;
  424. background-color: #ffffff;
  425. bottom: var(--window-bottom);
  426. border-top: 2rpx solid #dddddd;
  427. .click_box {
  428. border: none;
  429. float: right;
  430. display: block;
  431. height: 120rpx;
  432. padding: 0rpx 0rpx;
  433. line-height: 120rpx;
  434. margin-right: 20rpx;
  435. font-size: 24rpx !important;
  436. background-color: transparent;
  437. .uni-icons {
  438. font-size: 36rpx !important;
  439. }
  440. }
  441. .click_box::after {
  442. border: none;
  443. background-color: transparent;
  444. }
  445. }
  446. .popup_content {
  447. width: 600rpx;
  448. height: 800rpx;
  449. background-color: #ffffff;
  450. padding: 40rpx;
  451. border-radius: 10rpx;
  452. overflow: auto;
  453. .content {
  454. display: flex;
  455. flex-direction: column;
  456. gap: 20rpx;
  457. justify-content: space-around;
  458. height: 100%;
  459. align-items: center;
  460. .question_content {
  461. overflow-y: auto;
  462. font-size: 30rpx;
  463. font-weight: bold;
  464. }
  465. .question_options {
  466. display: flex;
  467. flex-direction: column;
  468. gap: 40rpx;
  469. width: 100%;
  470. .question_answer {
  471. height: 80rpx;
  472. width: 100%;
  473. border: 4rpx solid #e3e3e3;
  474. border-radius: 20rpx;
  475. display: flex;
  476. align-items: center;
  477. justify-content: center;
  478. &.active {
  479. border-color: #3c7aff;
  480. background-color: #dbeafe;
  481. }
  482. }
  483. }
  484. .submit_btn {
  485. width: 100%;
  486. display: flex;
  487. align-items: center;
  488. justify-content: center;
  489. color: #fff;
  490. height: 100rpx;
  491. background-color: #dddddd;
  492. border-radius: 20rpx;
  493. &.active {
  494. background-color: #5045e6;
  495. }
  496. }
  497. .title {
  498. font-size: 64rpx;
  499. font-weight: bold;
  500. }
  501. .score_content {
  502. background-color: #f3f5f7;
  503. padding: 40rpx;
  504. display: flex;
  505. align-items: center;
  506. justify-content: space-between;
  507. width: 100%;
  508. border-radius: 20rpx;
  509. box-sizing: border-box;
  510. }
  511. }
  512. }
  513. .contact_follow {
  514. bottom: 30%;
  515. right: 20rpx;
  516. width: 100rpx;
  517. height: 100rpx;
  518. display: block;
  519. position: fixed;
  520. border-radius: 50%;
  521. background-color: #1296db;
  522. .contact_btn {
  523. border: none;
  524. width: 100rpx;
  525. color: #ffffff;
  526. height: 100rpx;
  527. padding: 0rpx 0rpx;
  528. line-height: 100rpx;
  529. text-align: center;
  530. border-radius: 50%;
  531. background-color: #1296db;
  532. }
  533. .contact_btn::after {
  534. border: none;
  535. }
  536. }
  537. .not_vip {
  538. background-color: #ddd;
  539. width: 100vw;
  540. height: 100vh;
  541. display: flex;
  542. align-items: center;
  543. flex-direction: column;
  544. justify-content: center;
  545. .content {
  546. width: 70%;
  547. margin-top: 20rpx;
  548. text-align: center;
  549. }
  550. }
  551. </style>