detail.vue 15 KB

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