From 489ad1d4cf2f04766bc872e2af8bc282c33d6d5b Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Mon, 19 Feb 2024 13:00:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A7=86=E9=A2=91=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E9=A2=84=E8=A7=88=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- controllers/HomeController.php | 3 ++- views/home/index.php | 34 +++++++++++++++++++++++++++++++--- web/js/home_script.js | 24 ++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 44e6662..1281cbc 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ 计划实现的功能 ------------------- -文件预览 +文件预览(图像,视频ok) 文件收集 diff --git a/controllers/HomeController.php b/controllers/HomeController.php index 348bc66..db2e70e 100644 --- a/controllers/HomeController.php +++ b/controllers/HomeController.php @@ -84,7 +84,8 @@ class HomeController extends Controller $type = FileTypeDetector::detect($absolutePath); $lastModified = filemtime($absolutePath); $size = is_file($absolutePath) ? filesize($absolutePath) : null; - $directoryContents[$key] = ['name' => $item, 'type' => $type, 'lastModified' => $lastModified, 'size' => $size]; + $rawType = is_file($absolutePath) ? mime_content_type($absolutePath) : null; + $directoryContents[$key] = ['name' => $item, 'type' => $type, 'lastModified' => $lastModified, 'size' => $size, 'rawType' => $rawType]; } return $this->render('index', [ 'directoryContents' => $directoryContents, diff --git a/views/home/index.php b/views/home/index.php index f173d45..4afc39f 100644 --- a/views/home/index.php +++ b/views/home/index.php @@ -6,6 +6,7 @@ /* @var $directory string 当前路径 */ +use app\assets\PlyrAsset; use app\assets\ViewerJsAsset; use app\models\NewFolderForm; use app\models\RenameForm; @@ -26,6 +27,7 @@ $this->params['breadcrumbs'][] = $this->title; FontAwesomeAsset::register($this); JqueryAsset::register($this); ViewerJsAsset::register($this); +PlyrAsset::register($this); $this->registerCssFile('@web/css/home_style.css'); ?>
@@ -101,7 +103,8 @@ $this->registerCssFile('@web/css/home_style.css'); - + @@ -113,7 +116,10 @@ $this->registerCssFile('@web/css/home_style.css'); user->id . '/' . $relativePath; ?> - +
名称 最近修改时间 大小
+ $item['type'] . ' file_icon']) ?> @@ -141,8 +147,9 @@ $this->registerCssFile('@web/css/home_style.css'); $item['type'] . ' file_icon']) ?> - $relativePath], ['class' => 'file_name', 'onclick' => 'previewImage(this, event)']) ?> + + $relativePath, 'type' => $item['rawType']], ['class' => 'file_name', 'onclick' => 'previewVideo(this, event)']) ?> $relativePath], ['class' => 'file_name']) ?> @@ -171,6 +178,14 @@ $this->registerCssFile('@web/css/home_style.css');
+ + + + + + + + '

重命名文件/文件夹

', @@ -260,6 +275,19 @@ echo Html::submitButton('提交', ['class' => 'btn btn-primary']); ActiveForm::end(); Modal::end(); + +Modal::begin([ + 'title' => '

视频在线播放

', + 'id' => 'videoModal', + '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 5c660f7..57577af 100644 --- a/web/js/home_script.js +++ b/web/js/home_script.js @@ -422,3 +422,27 @@ function previewImage(element, event) { }); viewer.show(); } + +// video preview +var player; +var videoModal = $('#videoModal'); // 存储选择器的结果 + +function previewVideo(element, event) { + event.preventDefault(); // 阻止默认的点击事件 + var videoElement = document.getElementById('vPlayer'); + videoElement.src = element.href; // 设置视频的URL + videoElement.type = element.getAttribute('type'); // 设置视频的MIME类型 + + // 创建一个新的 Plyr 实例 + player = new Plyr(videoElement); + player.play(); + + // 显示模态框 + videoModal.modal('show'); +} + +videoModal.on('hidden.bs.modal', function (e) { + if (player) { + player.destroy(); + } +}); \ No newline at end of file