From 19fc8ff7379a5c97ab997caa063944ed86230abb Mon Sep 17 00:00:00 2001 From: RB Date: Fri, 13 Oct 2023 11:49:21 +0800 Subject: [PATCH] =?UTF-8?q?be:=20=E6=9C=AC=E5=9C=B0=E5=8A=A0=E8=BD=BDPDF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/web/assets/js/file-preview.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/resources/web/assets/js/file-preview.js b/src/main/resources/web/assets/js/file-preview.js index 833b3a062..770e6e53f 100644 --- a/src/main/resources/web/assets/js/file-preview.js +++ b/src/main/resources/web/assets/js/file-preview.js @@ -194,17 +194,26 @@ class RbPreview extends React.Component { const currentUrl = this.props.urls[this.state.currentIndex] const fileName = $fileCutName(currentUrl) if (this._isDoc(fileName)) { - const ispdf = fileName.toLowerCase().endsWith('.pdf') - const setPreviewUrl = function (url) { - let previewUrl = ispdf ? url : (rb._officePreviewUrl || 'https://view.officeapps.live.com/op/embed.aspx?src=') + $encode(url) - if ($.browser.mobile && ispdf) { - previewUrl = `${rb.baseUrl}/assets/lib/pdfjs/web/viewer.html?src=${$encode(url)}` + const isPdfType = fileName.toLowerCase().endsWith('.pdf') + const setPreviewUrl = function (url, fullUrl) { + let previewUrl = (rb._officePreviewUrl || 'https://view.officeapps.live.com/op/embed.aspx?src=') + $encode(url) + if (isPdfType) { + if ($.browser.mobile) { + previewUrl = `${rb.baseUrl}/assets/lib/pdfjs/web/viewer.html?src=${$encode(url)}` + } else { + if (fullUrl) { + previewUrl = url + } else { + // 本地加载PDF + previewUrl = `${rb.baseUrl}/filex/` + url.split('/filex/')[1] + } + } } that.setState({ previewUrl: previewUrl, errorMsg: null }) } if ($isFullUrl(currentUrl)) { - setPreviewUrl(currentUrl) + setPreviewUrl(currentUrl, true) } else { $.get(`/filex/make-url?url=${currentUrl}`, (res) => { if (res.error_code > 0) this.setState({ errorMsg: res.error_msg })