PdfView.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div class="pdfView-box">
  3. <div class="pdfView">
  4. <!-- <pdf
  5. v-for="i in curQue.data.numPages"
  6. ref="pdf"
  7. :key="i"
  8. :src="pdfSrc"
  9. :page="i"
  10. @progress="loadedRatio = $event"
  11. /> -->
  12. <iframe
  13. :src="curQue.data.newpath"
  14. width="100%"
  15. height="1000px"
  16. id="ifm"
  17. ></iframe>
  18. </div>
  19. <!-- <div v-show="loadedRatio !== 1" class="progress">
  20. <el-progress
  21. type="circle"
  22. :width="70"
  23. color="#53a7ff"
  24. :percentage="Math.floor(loadedRatio * 100)"
  25. />
  26. <br />
  27. <span>{{ remindShow }}</span>
  28. </div> -->
  29. </div>
  30. </template>
  31. <script>
  32. import pdf from "vue-pdf";
  33. const Base64 = require("js-base64").Base64;
  34. import { getToken, getConfig } from "../../../utils/auth";
  35. export default {
  36. // import引入的组件需要注入到对象中才能使用
  37. components: { pdf },
  38. props: ["curQue", "fn_data", "type"],
  39. data() {
  40. // 这里存放数据
  41. return {
  42. numPages: null,
  43. remindShow: "加载文件中,文件较大请耐心等待...",
  44. loadedRatio: 0,
  45. pdfSrc: "",
  46. };
  47. },
  48. created() {
  49. // this.getNumPages();
  50. let data = JSON.parse(getConfig());
  51. let file_preview_url = data.doc_preview_service_address;
  52. let path =
  53. `${file_preview_url}/onlinePreview?url=` +
  54. Base64.encode(this.curQue.data.file_url);
  55. this.curQue.data.newpath = path;
  56. },
  57. methods: {
  58. // getNumPages() {
  59. // let str = this.curQue.data.fileRelativePath;
  60. // str.replace(process.env.VUE_APP_BASE_API, '');
  61. // let loadingTask = pdf.createLoadingTask(`${process.env.VUE_APP_PDF}${str}`);
  62. // loadingTask.promise
  63. // .then(pdff => {
  64. // console.log("拿到结果");
  65. // this.pdfSrc = loadingTask;
  66. // this.numPages = pdff.numPages;
  67. // this.curQue.data.numPages = pdff.numPages;
  68. // })
  69. // .catch(err => {
  70. // console.error("pdf 加载失败", err);
  71. // });
  72. // },
  73. },
  74. };
  75. </script>
  76. <style scoped>
  77. /* @import url(); 引入css类 */
  78. .pdfView-box {
  79. width: 100%;
  80. }
  81. .pdfView {
  82. width: 100%;
  83. }
  84. .progress {
  85. position: absolute;
  86. right: 50%;
  87. top: 50%;
  88. text-align: center;
  89. width: 500px;
  90. margin-right: -250px;
  91. }
  92. </style>