From 7ce08c954a669376b7f6a10b3a5406353f861df9 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Mon, 19 Feb 2024 11:30:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=9B=BE=E5=83=8F=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/ViewerJsAsset.php | 3 +++ views/home/index.php | 9 +++++++-- web/js/home_script.js | 34 ++++++++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/assets/ViewerJsAsset.php b/assets/ViewerJsAsset.php index 5186b0e..577398b 100644 --- a/assets/ViewerJsAsset.php +++ b/assets/ViewerJsAsset.php @@ -10,4 +10,7 @@ class ViewerJsAsset extends AssetBundle public $js = [ 'viewer.min.js', ]; + public $css = [ + 'viewer.min.css' + ]; } \ No newline at end of file diff --git a/views/home/index.php b/views/home/index.php index ec02da8..f173d45 100644 --- a/views/home/index.php +++ b/views/home/index.php @@ -97,7 +97,7 @@ $this->registerCssFile('@web/css/home_style.css'); - + @@ -140,7 +140,12 @@ $this->registerCssFile('@web/css/home_style.css');
$item['type'] . ' file_icon']) ?> - $relativePath], ['class' => 'file_name']) ?> + + + $relativePath], ['class' => 'file_name', 'onclick' => 'previewImage(this, event)']) ?> + + $relativePath], ['class' => 'file_name']) ?> + diff --git a/web/js/home_script.js b/web/js/home_script.js index 4556286..5c660f7 100644 --- a/web/js/home_script.js +++ b/web/js/home_script.js @@ -391,8 +391,34 @@ function updateButtons() { $('.batch-delete-btn').toggle(count >= 1); } -// 在页面加载时调用updateButtons函数 -$(document).ready(updateButtons); - // 当checkbox的状态改变时,调用updateButtons函数 -$(document).on('change', '.select-item', updateButtons); \ No newline at end of file +$(document).on('change', '.select-item', updateButtons); + +$(document).ready(function() { + updateButtons(); +}); + +// image preview +function previewImage(element, event) { + event.preventDefault(); // 阻止默认的点击事件 + var hiddenImage = document.getElementById('hidden-image'); + hiddenImage.src = element.href; // 设置图像的URL + + // 创建一个新的 Viewer.js 实例 + var viewer = new Viewer(hiddenImage, { + toolbar: { + zoomIn: 1, + zoomOut: 1, + oneToOne: 1, + reset: 1, + rotateLeft: 1, + rotateRight: 1, + flipHorizontal: 1, + flipVertical: 1, + }, + hidden: function() { + viewer.destroy(); + } + }); + viewer.show(); +}