From f6ec6e252205fe4b145d86d2af1428765110f5ac Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Wed, 21 Feb 2024 11:58:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0PDF=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E5=8A=9F=E8=83=BD(=E9=9C=80=E8=A6=81=E7=8E=B0=E4=BB=A3?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E5=99=A8=E6=94=AF=E6=8C=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/home/index.php | 13 +++++++++++-- web/js/home_script.js | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/views/home/index.php b/views/home/index.php index 88dc73b..c274fbc 100644 --- a/views/home/index.php +++ b/views/home/index.php @@ -22,7 +22,6 @@ use yii\helpers\Url; use yii\web\JqueryAsset; use yii\web\View; - $this->title = '文件管理'; $this->params['breadcrumbs'][] = $this->title; FontAwesomeAsset::register($this); @@ -156,6 +155,8 @@ $this->registerCssFile('@web/css/home_style.css'); $relativePath, 'type' => $item['rawType']], ['class' => 'file_name', 'onclick' => 'textEdit(this, event)']) ?> $relativePath, 'type' => $item['rawType']], ['class' => 'file_name', 'onclick' => 'previewAudio(this, event)']) ?> + + $relativePath, 'type' => $item['rawType']], ['class' => 'file_name', 'onclick' => 'previewPdf(this, event)']) ?> $relativePath], ['class' => 'file_name']) ?> @@ -310,11 +311,19 @@ Modal::begin([ 'size' => 'modal-lg', ]); -echo''; +echo ''; echo ''; echo ''; echo '
'; +Modal::end(); + +Modal::begin([ + 'title' => '

PDF预览

', + 'id' => 'pdfModal', + 'size' => 'modal-xl', +]); +//echo ''; Modal::end(); $this->registerJsFile('@web/js/home_script.js', ['depends' => [JqueryAsset::class], 'position' => View::POS_END]); ?> diff --git a/web/js/home_script.js b/web/js/home_script.js index 3eb430b..f33bc6a 100644 --- a/web/js/home_script.js +++ b/web/js/home_script.js @@ -505,4 +505,27 @@ $('#saveButton').on('click', function () { $('#ed-alert-fail').show(); } }); +}); + +//pdf preview +var pdfModal = $('#pdfModal'); + +function previewPdf(element, event) { + event.preventDefault(); + var pdfUrl = element.href; + var pdfObject = document.createElement('object'); + pdfObject.id = 'pdfObject'; + pdfObject.type = 'application/pdf'; + pdfObject.style.width = '100%'; + pdfObject.style.height = '500px'; + pdfObject.data = pdfUrl; + pdfModal.find('.modal-body').append(pdfObject); + pdfModal.modal('show'); +} + +pdfModal.on('hidden.bs.modal', function () { + var pdfObject = document.getElementById('pdfObject'); + if (pdfObject) { + pdfObject.remove(); + } }); \ No newline at end of file