detail.vue 16 KB

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