detail.vue 14 KB

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