Blame view

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