detail.vue 14 KB

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