From b6b16a8c29f00d01b4a0c70e2485ae136f882a64 Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Wed, 28 Feb 2024 16:02:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=85=E5=89=8D=E7=AB=AF=E6=94=B9=E8=BF=9B?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7=E4=BA=A4=E4=BA=92?= =?UTF-8?q?=E4=BD=93=E9=AA=8C=20=E6=94=AF=E6=8C=81=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E9=94=AE=E7=9B=98=E5=BF=AB=E6=8D=B7=E9=94=AE=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=98=E5=9C=A8=E9=97=AE=E9=A2=98=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=A4=9A=E9=80=89=E9=80=BB=E8=BE=91=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=89=93=E5=BC=80=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/home/index.php | 14 ++++ web/js/home_script.js | 159 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 160 insertions(+), 13 deletions(-) diff --git a/views/home/index.php b/views/home/index.php index 345efcd..b296ab1 100644 --- a/views/home/index.php +++ b/views/home/index.php @@ -36,6 +36,7 @@ $this->registerCssFile('@web/css/home_style.css');

title) ?>

+ 'btn btn-outline-primary single-open-btn']) ?> 'btn btn-outline-primary single-download-btn']) ?> 'btn btn-outline-primary batch-zip-download-btn']) ?> 'btn btn-outline-primary batch-zip-btn']) ?> @@ -105,6 +106,19 @@ $this->registerCssFile('@web/css/home_style.css'); + diff --git a/web/js/home_script.js b/web/js/home_script.js index 08f451c..528977d 100644 --- a/web/js/home_script.js +++ b/web/js/home_script.js @@ -223,7 +223,17 @@ $(document).on('click', '.batch-delete-btn', function () { }); }); -//下面的代码实现了各种按钮/样式功能,建议别看了( +$(document).on('click', '.single-open-btn', function () { + // 下面这个写法无效,因为它目前只对支持预览的设置onclick事件的文件有效 + // $('.select-item:checked').first().closest('tr').find('.file_name').click(); + + var firstSelectedElement = $('.select-item:checked').first().closest('tr').find('.file_name')[0]; + if (firstSelectedElement) { + firstSelectedElement.click(); + } +}); + +//下面的代码实现了各种按钮/样式功能,建议别看了(写的头疼了 //上传 function uploadFiles(files) { @@ -321,20 +331,40 @@ for (var i = 0; i < itemCheckboxes.length; i++) { // 为document添加键盘事件监听器 document.addEventListener('keydown', function (event) { - // 如果用户按下了Ctrl+A if (event.ctrlKey && event.key === 'a') { - // 阻止默认的全选操作 event.preventDefault(); - // 获取所有的复选框 var checkboxes = document.querySelectorAll('.select-item'); - var selectAll = document.getElementById('select-all'); - selectAll.checked = !selectAll.checked; + var allChecked = Array.from(checkboxes).every(checkbox => checkbox.checked); for (var i = 0; i < checkboxes.length; i++) { - checkboxes[i].checked = selectAll.checked; - checkboxes[i].closest('tr').classList.toggle('selected', selectAll.checked); + checkboxes[i].checked = !allChecked; + checkboxes[i].closest('tr').classList.toggle('selected', !allChecked); } updateButtons(); } + if (event.ctrlKey && event.key === 'd') { + event.preventDefault(); + $('tr.selected').removeClass('selected').find('input[type="checkbox"]').prop('checked', false); + $('#select-all').prop('checked', false); + updateButtons(); + } + if (event.ctrlKey && event.key === 'c') { + var cp = $('.batch-copy-btn'); + if (cp.css('display') !== 'none') { + cp.click(); + } + } + if (event.ctrlKey && event.key === 'x') { + var ct = $('.batch-cut-btn'); + if (ct.css('display') !== 'none') { + ct.click(); + } + } + if (event.ctrlKey && event.key === 'v') { + var pe = $('.batch-paste-btn'); + if (pe.css('display') !== 'none') { + pe.click(); + } + } }); //行点击事件 @@ -342,9 +372,20 @@ $(document).on('click', 'tr', function (event) { if ($(event.target).is('input[type="checkbox"]') || $(event.target).is('a')) { return; } - $(this).toggleClass('selected'); - var checkbox = $(this).children(':first-child').find('input[type="checkbox"]'); - checkbox.prop('checked', !checkbox.prop('checked')); + var checkboxes = document.querySelectorAll('.select-item'); + // 检查是否所有的复选框都已经被选中 + var checkedCount = Array.from(checkboxes).filter(checkbox => checkbox.checked).length; + // 如果选中的复选框的数量大于或等于2,那么就将allChecked设置为true + var allChecked = checkedCount >= 2; // 如果Ctrl键没有被按下,取消所有其他行的选中状态 + if (!event.ctrlKey) { + $('tr.selected').not(this).removeClass('selected').find('input[type="checkbox"]').prop('checked', false); + } + // 切换当前行的选中状态 + if ((!allChecked) || (allChecked && event.ctrlKey)) { + $(this).toggleClass('selected'); + var checkbox = $(this).children(':first-child').find('input[type="checkbox"]'); + checkbox.prop('checked', !checkbox.prop('checked')); + } updateButtons(); }); @@ -355,7 +396,7 @@ function updateButtons() { var isSingleFile = count === 1 && !checkboxes.first().data('isDirectory'); var isSingleZip = isSingleFile && checkboxes.first().closest('tr').find('.file_icon').hasClass('fa-file-zipper'); var hasOperation = sessionStorage.getItem('operation') !== null; // 检查 sessionStorage 中是否存在 operation - + $('.single-open-btn').toggle(count === 1); $('.single-download-btn').toggle(isSingleFile); $('.batch-zip-download-btn').toggle(count > 0 && !isSingleFile); $('.batch-zip-btn').toggle(count >= 1); @@ -375,6 +416,97 @@ $(document).on('change', '.select-item', updateButtons); $(document).ready(function () { updateButtons(); + + $('tr').contextmenu(function (e) { + e.preventDefault(); + if ($(e.target).is('button') || $(e.target).is('i') || $(e.target).is('a')) { + e.preventDefault(); // 阻止事件的默认行为 + return; + } + // 获取点击的元素 + var clickedElement = $(this); + + if (!clickedElement.hasClass('selected')) { + $('tr.selected').removeClass('selected').find('input[type="checkbox"]').prop('checked', false); + clickedElement.addClass('selected'); + var checkbox = clickedElement.children(':first-child').find('input[type="checkbox"]'); + checkbox.prop('checked', true); + updateButtons(); + } + + $('#option-open').toggle($('.single-open-btn').css('display') !== 'none'); + $('#option-download').toggle($('.single-download-btn').css('display') !== 'none'); + $('#option-batch-zip-download').toggle($('.batch-zip-download-btn').css('display') !== 'none'); + $('#option-single-rename').toggle($('.single-rename-btn').css('display') !== 'none'); + $('#option-batch-copy').toggle($('.batch-copy-btn').css('display') !== 'none'); + $('#option-batch-cut').toggle($('.batch-cut-btn').css('display') !== 'none'); + $('#option-batch-paste').toggle($('.batch-paste-btn').css('display') !== 'none'); + $('#option-batch-delete').toggle($('.batch-delete-btn').css('display') !== 'none'); + $('#option-refresh').toggle($('.refresh-btn').css('display') !== 'none'); + + // 显示菜单 + $('#contextMenu').css({ + display: "block", + left: e.pageX, + top: e.pageY + }).addClass('show'); + $('#contextMenu .dropdown-menu').addClass('show'); + }); + // 当用户点击菜单项时 + $('#contextMenu a').off('click').on('click', function (e) { + e.preventDefault(); + // 获取点击的菜单项 + var clickedMenuItem = $(this).attr('id'); + + // 根据点击的菜单项执行相应的操作 + switch (clickedMenuItem) { + case 'option-open': + // 模拟点击打开按钮 + $('.single-open-btn').click(); + break; + case 'option-download': + // 模拟点击下载按钮 + $('.single-download-btn').click(); + break; + case 'option-batch-zip-download': + // 模拟点击打包下载按钮 + $('.batch-zip-download-btn').click(); + break; + case 'option-single-rename': + // 模拟点击重命名按钮 + $('.single-rename-btn').click(); + break; + case 'option-batch-copy': + // 模拟点击复制按钮 + $('.batch-copy-btn').click(); + break; + case 'option-batch-cut': + // 模拟点击剪切按钮 + $('.batch-cut-btn').click(); + break; + case 'option-batch-paste': + // 模拟点击粘贴按钮 + $('.batch-paste-btn').click(); + break; + case 'option-batch-delete': + // 模拟点击删除按钮 + $('.batch-delete-btn').click(); + break; + case 'option-refresh': + // 模拟点击刷新按钮 + $('.refresh-btn').click(); + break; + } + + // 隐藏菜单 + $('#contextMenu').hide().removeClass('show'); + }); + +// 当用户点击其他地方时,隐藏菜单 + $(document).click(function () { + $('#contextMenu').hide().removeClass('show'); + $('#contextMenu .dropdown-menu').removeClass('show'); + }); }); // image preview @@ -535,4 +667,5 @@ pdfModal.on('hidden.bs.modal', function () { $(document).on('click', '.create-collection-btn', function () { document.getElementById('collectiontasks-folder_path').value = $('.select-item:checked').first().data('relativePath'); $('#collectionModal').modal('show'); -}); \ No newline at end of file +}); +