u-pdf-reader.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view class="up-pdf-reader" :style="{ height: height }">
  3. <web-view :fullscreen="false"
  4. :src="viewerUrl" :style="{ width: '750rpx', height: height }"
  5. :webview-styles="{ width: '750rpx', height: height }"
  6. frameborder="0"
  7. ></web-view>
  8. </view>
  9. </template>
  10. <script>
  11. import props from './props.js';
  12. /**
  13. * pdfReader PDF阅读器
  14. * @description 基于pdf.js的PDF阅读器组件
  15. * @tutorial https://uview-plus.jiangruyi.com/components/pdfReader.html
  16. * @property {String} src PDF文件地址
  17. * @property {String} height 组件高度,默认为'700px'
  18. * @property {String} pdfjsDomain pdfjs资源域名,默认为'https://uview-plus.jiangruyi.com/h5'
  19. * @example <up-pdf-reader src="https://example.com/file.pdf"></up-pdf-reader>
  20. */
  21. export default {
  22. name: 'up-pdf-reader',
  23. mixins: [props],
  24. data() {
  25. return {
  26. baseUrlInner: 'https://uview-plus.jiangruyi.com/h5',
  27. viewerUrl: ''
  28. }
  29. },
  30. watch: {
  31. baseUrl: function (val) {
  32. this.baseUrl = val;
  33. },
  34. src: function (val) {
  35. this.viewerUrl = `${this.baseUrlInner}/static/pdfjs/web/viewer.html?file=` + encodeURIComponent(val);
  36. }
  37. },
  38. mounted() {
  39. if (this.baseUrl) {
  40. this.baseUrlInner = this.baseUrl;
  41. }
  42. this.viewerUrl = `${this.baseUrlInner}/static/pdfjs/web/viewer.html?file=` + encodeURIComponent(this.src);
  43. }
  44. }
  45. </script>
  46. <style lang="scss" scoped>
  47. .up-pdf-reader {
  48. }
  49. </style>