details.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="pageContainer">
  3. <ss-preview :fileUrl="fileUrl" v-if="fileUrl" :fileType="fileType" :imageList="imageList"></ss-preview>
  4. <view class="countDownTime" v-show="countDownTime">剩余时间:{{ countDownTime }}s</view>
  5. <!-- 人脸校验 -->
  6. <tq-face ref="faceRef"
  7. @success="faceSuccess"
  8. @close="faceClose"
  9. ></tq-face>
  10. </view>
  11. </template>
  12. <script>
  13. import ssPreview from '@/uni_modules/ss-preview/components/ss-preview/ss-preview.vue'
  14. import { materialDetail, saveUserMaterial } from "@/api/learnMobile/index";
  15. let deepSetInterval;
  16. let countDownInterval;
  17. export default {
  18. components: {
  19. ssPreview
  20. },
  21. data() {
  22. return {
  23. fileType: '2', //类型(1.预览图片,2.预览文件,3.预览视频)
  24. showPreview: false,
  25. id: '',
  26. fileUrl: '',
  27. imageList: [],
  28. startTime: '',
  29. endTime: '',
  30. countDownTime: '',
  31. recordId: '',
  32. isValidFace: false, //是否检验人脸
  33. lastTime: '', //人脸校验前剩余时间
  34. rdTime: '',//触发人脸时间点
  35. }
  36. },
  37. onLoad(option) {
  38. this.id = option.id
  39. console.log('参数', option)
  40. this.startTime = this.dayjs().format('YYYY-MM-DD HH:mm:ss')
  41. this.getData();
  42. },
  43. //页面销毁事件
  44. onUnload() {
  45. console.log('销毁')
  46. clearInterval(deepSetInterval)
  47. clearInterval(countDownInterval)
  48. },
  49. methods: {
  50. getRandomInteger(min, max) {
  51. return Math.floor(Math.random() * (max - min + 1)) + min;
  52. },
  53. randomTime(time) {
  54. let max = time-1
  55. this.rdTime = this.getRandomInteger(1,max)
  56. },
  57. async getData() {
  58. let { data, code } = await materialDetail({
  59. id: this.id
  60. })
  61. if (code == '0') {
  62. if (data.type === 1) {
  63. this.fileType = '2'
  64. }
  65. if (data.type === 2) {
  66. this.fileType = '3'
  67. }
  68. this.randomTime(data.learnTime)
  69. this.countDown(data.learnTime)
  70. this.fileUrl = this.$getImages(data.annexUrl)
  71. }
  72. },
  73. /**倒计时 */
  74. countDown(time) {
  75. countDownInterval = setInterval(() => {
  76. if(time == this.rdTime && !this.isValidFace) {
  77. this.lastTime = time
  78. clearInterval(countDownInterval)
  79. this.openFace()
  80. return
  81. }
  82. time--
  83. this.countDownTime = time
  84. if (time <= 0) {
  85. clearInterval(countDownInterval)
  86. this.countDownTime = 0
  87. this.endTime = this.dayjs().format('YYYY-MM-DD HH:mm:ss')
  88. this.saveLearn()
  89. }
  90. }, 1000)
  91. },
  92. /**保存学习记录 */
  93. async saveLearn() {
  94. let { code, data } = await saveUserMaterial({
  95. startTime: this.startTime,
  96. endTime: this.dayjs().format('YYYY-MM-DD HH:mm:ss'),//this.endTime,
  97. materialId: this.id,
  98. recordId: this.recordId
  99. })
  100. if (code == '0') {
  101. // uni.showToast({
  102. // title: '学习成功'
  103. // })
  104. this.recordId = data.recordId
  105. if (!deepSetInterval) {
  106. this.deepSaveLearn()
  107. }
  108. }
  109. },
  110. deepSaveLearn() {
  111. if (deepSetInterval) clearInterval(deepSetInterval);
  112. deepSetInterval = setInterval(e => {
  113. this.saveLearn()
  114. }, 5000)
  115. },
  116. openFace() {
  117. this.$refs.faceRef.show()
  118. },
  119. faceClose() {
  120. uni.navigateBack()
  121. },
  122. faceSuccess() {
  123. this.isValidFace = true
  124. this.countDown(this.lastTime)
  125. }
  126. },
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .pageContainer {
  131. height: 100%;
  132. .nodata-image {
  133. height: 500px;
  134. width: 100%;
  135. }
  136. .countDownTime {
  137. position: fixed;
  138. z-index: 999;
  139. // width: 400rpx;
  140. bottom: 0;
  141. left: 0;
  142. background: rgba(255, 255, 255, .4);
  143. color: rgba(0, 0, 0, .6);
  144. border-radius: 4rpx;
  145. padding: 4rpx 18rpx;
  146. }
  147. }
  148. </style>