pdfPreView.vue
5.3 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<template>
<view class="material-detail">
<view class="nav-bar">
<view class="back" @click.stop="back">
<uni-icons type="left" :size="20" color="#000"></uni-icons>
</view>
<view class="nav-title">{{ title }}</view>
<!-- 从报告管理跳转时,右上角显示保存按钮 -->
<view v-if="showSaveBtn && reportImageUrl" class="nav-save-btn" @click.stop="saveReportImage">保存图片</view>
</view>
<!-- html 报告:统一用 web-view 展示内容,按钮放在导航栏,避免被覆盖 -->
<web-view v-if="fileUrltype === 'html'" :src="previewUrl"></web-view>
<view v-else-if="fileUrltype !== 'pdf'">
<lk-preview-office :url="previewUrl" :fileType="fileType"></lk-preview-office>
</view>
<view v-else>
<lk-preview-office :url="previewUrl" fileType="pdf"></lk-preview-office>
</view>
</view>
</template>
<script type="text/ecmascript-6">
import { report } from '@/mixin/index.js'
export default {
name: '',
mixins: [report],
data () {
return {
previewUrl: '',
title: '',
fileType: 'pdf',
Signature: true,
fileUrltype:'pdf',
showSaveBtn: false,
reportImageUrl: ''
}
},
onLoad (options) {
console.log(options)
this.fileUrltype = options.fileUrltype || 'pdf'
this.fileType = options.fileType || 'pdf'
this.Signature = options.Signature === 'false' ? false : (options.Signature || true);
if(this.fileType === 'docx') {
this.previewUrl = options.fileUrl
}else if(!this.Signature) {
this.previewUrl = options.fileUrl
}else {
this.previewUrl = options.fileUrl + '&OSSAccessKeyId='+ options.OSSAccessKeyId + '&Signature=' + options.Signature
}
this.title = options.fileName
// 来自报告管理的额外参数:是否显示保存按钮 & 报告图片地址
this.showSaveBtn = options.showSaveBtn === '1'
this.reportImageUrl = options.reportImageUrl ? decodeURIComponent(options.reportImageUrl) : ''
console.log(this.previewUrl)
// else this.setWv()
},
mounted () {
},
methods: {
back () {
uni.navigateBack({
delta: 1,
animationType: 'pop-out',
animationDuration: 100
})
},
// 保存报告图片到相册
saveReportImage () {
if (!this.reportImageUrl) {
uni.showToast({ title: '暂无可保存的图片', icon: 'none' })
return
}
uni.showLoading({ title: '保存中...', mask: true })
uni.downloadFile({
url: this.reportImageUrl,
success: res => {
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: () => {
uni.showToast({ title: '已保存到相册', icon: 'none' })
},
fail: () => {
uni.showToast({ title: '保存失败', icon: 'none' })
},
complete: () => {
uni.hideLoading()
}
})
} else {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
},
fail: () => {
uni.hideLoading()
uni.showToast({ title: '下载失败', icon: 'none' })
}
})
},
setWebviewStyle () {
const setWebviewStyleWithRetry = () => {
const currentWebview = this.$scope.$getAppWebview()
let [wv] = currentWebview.children(),
wvFlag = false
if (wv) {
wv.setStyle({
left: '71.9%',
top: '17.18%',
height: '82.82%',
width: '28.3%'
})
wvFlag = true;
}
return wvFlag
}
const retrySetWebviewStyle = () => {
if (!setWebviewStyleWithRetry()) {
// 如果未成功,继续重试
setTimeout(retrySetWebviewStyle, 50);
} else {
// 成功设置样式,结束循环
console.log('Webview样式设置成功');
}
};
setTimeout(retrySetWebviewStyle, 100);
}
}
}
</script>
<style scoped lang="scss">
.nav-bar {
position: fixed;
width: 100%;
height: toRpx(96);
left: 0;
top: toRpx(48);
z-index: 9;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: toRpx(32);
color: #1a1a1a;
.back {
position: absolute;
left: 0;
top: 0;
height: 100%;
aspect-ratio: 1/1;
display: flex;
align-items: center;
justify-content: center;
}
}
.nav-title {
max-width: 60%;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.nav-save-btn {
position: absolute;
right: toRpx(24);
top: 50%;
transform: translateY(-50%);
padding: 0 toRpx(24);
height: toRpx(64);
line-height: toRpx(64);
border-radius: toRpx(32);
background: linear-gradient(0deg, #2c66f7 0%, #48a6ff 100%);
color: #ffffff;
font-size: toRpx(24);
}
.file-box {
position: fixed;
top: 5.2vh;
height: 94.8vh;
left: 0;
width: 100vw;
}
.has-ai {
width: 71.36vw;
}
.AI-window {
width: 28.3vw;
height: 90.63vh;
position: fixed;
top: 9.37vh;
right: 0;
background: #f5f9ff;
.AI-title {
height: 5.73vh;
padding-top: 2.08vh;
font-size: toRpx(34);
font-weight: 500;
justify-content: center;
color: #333333;
}
}
</style>