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