feat(oa): add WeChat host page to preview exported OA PDF
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
8ac1eb3d40
commit
fb625253f6
2 files changed
+87
No files matched your search
@@ -64,6 +64,14 @@
|
||||
"navigationBarTextStyle": "black"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/oa/pdf-preview/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "文档预览",
|
||||
"navigationBarBackgroundColor": "#ecfdf5",
|
||||
"navigationBarTextStyle": "black"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/oa/drafts/index",
|
||||
"style": {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<template>
|
||||
<view class="pdf-preview">
|
||||
<view class="pdf-preview__tip">{{ tip }}</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
tip: '正在打开文档…',
|
||||
_opened: false
|
||||
}
|
||||
},
|
||||
onLoad(query) {
|
||||
const url = decodeURIComponent(String((query && query.url) || '').trim())
|
||||
const name = decodeURIComponent(
|
||||
String((query && query.name) || 'approval.pdf').trim()
|
||||
)
|
||||
if (!url || !/^https?:\/\//i.test(url)) {
|
||||
this.tip = '文件地址无效'
|
||||
uni.showToast({ title: '文件地址无效', icon: 'none' })
|
||||
return
|
||||
}
|
||||
this.openPdf(url, name)
|
||||
},
|
||||
methods: {
|
||||
openPdf(url, name) {
|
||||
if (this._opened) return
|
||||
this._opened = true
|
||||
uni.downloadFile({
|
||||
url,
|
||||
success: (res) => {
|
||||
if (!res || res.statusCode !== 200 || !res.tempFilePath) {
|
||||
this.tip = '下载失败'
|
||||
uni.showToast({ title: '下载 PDF 失败', icon: 'none' })
|
||||
this._opened = false
|
||||
return
|
||||
}
|
||||
uni.openDocument({
|
||||
filePath: res.tempFilePath,
|
||||
fileType: 'pdf',
|
||||
showMenu: true,
|
||||
success: () => {
|
||||
this.tip = '已打开预览'
|
||||
setTimeout(() => {
|
||||
uni.navigateBack({ fail: () => {} })
|
||||
}, 300)
|
||||
},
|
||||
fail: () => {
|
||||
this.tip = '无法打开文档'
|
||||
uni.showToast({ title: '无法打开 PDF', icon: 'none' })
|
||||
this._opened = false
|
||||
}
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
this.tip = '下载失败'
|
||||
uni.showToast({ title: '下载 PDF 失败', icon: 'none' })
|
||||
this._opened = false
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.pdf-preview {
|
||||
min-height: 100vh;
|
||||
padding: 48rpx 32rpx;
|
||||
background: #f5f7fa;
|
||||
}
|
||||
.pdf-preview__tip {
|
||||
text-align: center;
|
||||
color: #64748b;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user