12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <template>
- <view>
- <view ref='file' v-if="word"></view>
- <web-view v-else :webview-styles="webviewStyles" :src="url"></web-view>
- </view>
- </template>
- <script>
- const docx = require('docx-preview');
- window.JSZip = require('jszip')
- export default {
- data() {
- return {
- url: "",
- webviewStyles: {
- progress: {
- color: '#F07423'
- }
- },
- type: "",
- word: false,
- };
- },
- onLoad(param) {
- this.type = param.type;
- let title = ""
- if (this.type == 1) {
- title = "用户使用协议"
- } else if (this.type == 2) {
- title = "隐私协议"
- } else if (this.type == 3) {
- title = "入驻协议"
- }
- uni.setNavigationBarTitle({
- title: title
- })
- this.webviewStyles.progress.color = getApp().globalData.color1;
- this.queryProtocolConfigView();
- },
- methods: {
- async queryProtocolConfigView() {
- let res = await this.$myRequest({
- url: "/project/queryProtocolConfigView",
- data: {},
- })
- if (res.data.success) {
- const curryUrl = this.curry("/hybrid/html/web/viewer.html?file=")
- if (this.type == '1') { //使用协议
- this.isWord(res.data.single.userUseProtocol);
- this.url = curryUrl(res.data.single.userUseProtocol);
- } else if (this.type == '2') { //隐私协议
- this.isWord(res.data.single.userPrivacyProtocol);
- this.url = curryUrl(res.data.single.userPrivacyProtocol);
- } else if (this.type == '3') { //业主注册协议
- this.isWord(res.data.single.ownerRegistProtocol);
- this.url = curryUrl(res.data.single.ownerRegistProtocol);
- }
- }
- },
- curry(baseUrl) {
- return function(url) {
- let index = url.lastIndexOf('.');
- if (url.substring(index + 1).indexOf('pdf') > -1) {
- return baseUrl + url;
- } else {
- return url;
- }
- }
- },
- isWord(url) {
- let index = url.lastIndexOf('.');
- if (url.substring(index + 1).indexOf('docx') > -1) {
- this.word = true;
- docx.renderAsync(new Blob([url]),this.$refs.file) // 渲染到页面预览
- } else {
- this.word = false;
- }
- }
- }
- }
- </script>
- <style lang="scss">
- </style>
|