pdf.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view>
  3. <web-view v-if="fullUrl" :src="fullUrl" />
  4. <read-socket v-if="fileId && pageShow" v-model="fileId" :course-id="courseId" />
  5. <read-check v-if="fileId && pageShow && checkOn===true" :time-sec="checkSec" @break="checkBreak" />
  6. <face-check v-if="fileId && pageShow"
  7. :courseId="courseId"
  8. :fileId="fileId"
  9. @ok="pageShow=true"
  10. @no="pageShow=false"
  11. >
  12. </face-check>
  13. </view>
  14. </template>
  15. <script>
  16. import ReadSocket from './components/ReadSocket'
  17. import ReadCheck from './components/ReadCheck'
  18. import FaceCheck from './components/FaceCheck'
  19. export default {
  20. components: { ReadSocket, ReadCheck, FaceCheck},
  21. data() {
  22. return {
  23. courseId: null,
  24. fileId: null,
  25. checkOn: false,
  26. checkSec: 0,
  27. // 阅读器地址
  28. viewerUrl: null,
  29. // 完整预览路径
  30. fullUrl: '',
  31. // 页面隐藏状态
  32. pageShow: Boolean
  33. }
  34. },
  35. onLoad: function(option) {
  36. // #ifndef H5
  37. this.viewerUrl = `${this.$urls.api}/hybrid/html/web/viewer.html`
  38. // #endif
  39. // #ifdef H5
  40. this.viewerUrl = '/hybrid/html/web/viewer.html'
  41. // #endif
  42. const path = decodeURIComponent(option.path)
  43. this.courseId = option.courseId
  44. this.fileId = option.fileId
  45. this.checkOn = option.checkOn
  46. if(option.checkOn && option.checkOn==='true'){
  47. this.checkOn = true
  48. }
  49. if(option.checkSec){
  50. this.checkSec = parseInt(option.checkSec)
  51. }
  52. // 填充文件
  53. this.fillUrl(path)
  54. console.log('课件地址', this.fullUrl)
  55. },
  56. onHide: function(){
  57. // 程序隐藏
  58. console.log('隐藏了...')
  59. this.pageShow = false
  60. },
  61. onShow:function(){
  62. console.log('显示了...')
  63. this.pageShow = true
  64. },
  65. methods:{
  66. // 填充H5地址
  67. fillUrl(path){
  68. if(path.startsWith('https://') || path.startsWith('http://')){
  69. // 网络文件
  70. this.fullUrl = `${this.viewerUrl}?file=${path}`;
  71. }else{
  72. // 本地地址
  73. this.fullUrl = `${this.viewerUrl}?file=${this.$urls.api}${path}`;
  74. }
  75. },
  76. // 验证
  77. checkBreak(){
  78. uni.switchTab({
  79. url: '/pages/index/index'
  80. })
  81. }
  82. }
  83. }
  84. </script>