2024-02-12 11:59:20 +08:00
|
|
|
$(document).on('click', '.rename-btn', function () {
|
|
|
|
var relativePath = $(this).attr('value');
|
|
|
|
var fileName = $(this).closest('tr').find('td:first').text().trim();
|
|
|
|
$('#renameRelativePath').val(relativePath);
|
|
|
|
$('#renameform-newname').val(fileName);
|
|
|
|
$('#renameModal').modal('show');
|
|
|
|
})
|
|
|
|
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
|
|
|
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
|
|
|
|
return new bootstrap.Tooltip(tooltipTriggerEl)
|
|
|
|
});
|
|
|
|
$(document).on('click', '.download-btn', function () {
|
|
|
|
window.location.href = $(this).attr('value');
|
|
|
|
});
|
2024-02-15 12:10:41 +08:00
|
|
|
$(document).on('click', '.folder-download-btn', function () {
|
|
|
|
var relativePath = $(this).attr('value');
|
|
|
|
window.open('index.php?r=home%2Fdownload-folder&relativePath=' + encodeURIComponent(relativePath), '_blank');
|
|
|
|
});
|
2024-02-12 11:59:20 +08:00
|
|
|
$(document).on('click', '.delete-btn', function () {
|
|
|
|
var relativePath = $(this).attr('value');
|
|
|
|
$('#deleteRelativePath').val(relativePath);
|
|
|
|
$('#deleteModal').modal('show');
|
2024-02-12 15:27:14 +08:00
|
|
|
});
|
|
|
|
$(document).on('click', '.file-upload-btn', function () {
|
2024-02-13 20:44:01 +08:00
|
|
|
// 触发文件输入元素的点击事件
|
|
|
|
$('#file-input').click();
|
2024-02-12 15:27:14 +08:00
|
|
|
});
|
2024-02-13 20:44:01 +08:00
|
|
|
$('#file-input').on('change', function () {
|
2024-02-15 10:54:25 +08:00
|
|
|
uploadFiles(this.files);
|
2024-02-13 20:44:01 +08:00
|
|
|
});
|
|
|
|
|
2024-02-12 15:27:14 +08:00
|
|
|
$(document).on('click', '.folder-upload-btn', function () {
|
2024-02-14 19:12:09 +08:00
|
|
|
// 触发文件输入元素的点击事件
|
|
|
|
$('#folder-input').click();
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#folder-input').on('change', function () {
|
2024-02-15 10:54:25 +08:00
|
|
|
uploadFiles(this.files);
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('click', '.offline-download-btn', function () {
|
|
|
|
console.log('你点击了离线下载,但功能尚未实现');
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('click', '.refresh-btn', function () {
|
|
|
|
window.location.reload();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('click', '.new-folder-btn', function () {
|
|
|
|
var relativePath = $(this).attr('value');
|
|
|
|
$('#newDirRelativePath').val(relativePath);
|
|
|
|
$('#newFolderModal').modal('show');
|
|
|
|
})
|
|
|
|
|
|
|
|
//上传
|
|
|
|
function uploadFiles(files) {
|
2024-02-14 19:12:09 +08:00
|
|
|
$('#progress-bar').show();
|
|
|
|
var formData = new FormData();
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
formData.append('files[]', files[i]);
|
|
|
|
}
|
|
|
|
formData.append('targetDir', $('#target-dir').val());
|
|
|
|
formData.append('_csrf', $('meta[name="csrf-token"]').attr('content'));
|
2024-02-15 10:54:25 +08:00
|
|
|
|
2024-02-14 19:12:09 +08:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.upload.onprogress = function (event) {
|
|
|
|
if (event.lengthComputable) {
|
|
|
|
var percentComplete = event.loaded / event.total * 100;
|
|
|
|
$('#progress-bar .progress-bar').css('width', percentComplete + '%').text(Math.round(percentComplete) + '%');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
xhr.onload = function () {
|
|
|
|
if (xhr.status !== 200) {
|
|
|
|
alert('An error occurred during the upload.');
|
|
|
|
}
|
|
|
|
window.location.reload();
|
|
|
|
};
|
|
|
|
xhr.open('POST', 'index.php?r=home%2Fupload');
|
|
|
|
xhr.send(formData);
|
2024-02-15 10:54:25 +08:00
|
|
|
}
|
2024-02-12 15:27:14 +08:00
|
|
|
|
2024-02-15 10:54:25 +08:00
|
|
|
//拖拽上传
|
2024-02-12 15:27:14 +08:00
|
|
|
var dropArea = document.getElementById('drop-area');
|
|
|
|
dropArea.addEventListener('dragover', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
});
|
|
|
|
dropArea.addEventListener('drop', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var items = event.dataTransfer.items;
|
2024-02-15 10:54:25 +08:00
|
|
|
var files = [];
|
2024-02-12 15:27:14 +08:00
|
|
|
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
var item = items[i];
|
2024-02-15 10:54:25 +08:00
|
|
|
files.push(item.getAsFile());
|
2024-02-12 15:27:14 +08:00
|
|
|
}
|
2024-02-15 10:54:25 +08:00
|
|
|
|
|
|
|
uploadFiles(files);
|
|
|
|
dropArea.classList.remove('dragging');
|
2024-02-12 15:27:14 +08:00
|
|
|
});
|
|
|
|
dropArea.addEventListener('dragenter', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
dropArea.classList.add('dragging');
|
|
|
|
});
|
|
|
|
|
|
|
|
dropArea.addEventListener('dragleave', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
if (!dropArea.contains(event.relatedTarget)) {
|
|
|
|
dropArea.classList.remove('dragging');
|
|
|
|
}
|
2024-02-15 10:54:25 +08:00
|
|
|
});
|