-
+
+function deleteFile(id) {
+ if (!confirm("确定删除?")) return;
+ const i = files.findIndex(f => f.id === id);
+ if (i > -1) files.splice(i, 1);
+ selected.delete(id);
+ render();
+}
+
+render();
+
\ No newline at end of file
diff --git a/code/file-preview/custom-file/index.js b/code/file-preview/custom-file/index.js
index c92133aa..2be15b3b 100644
--- a/code/file-preview/custom-file/index.js
+++ b/code/file-preview/custom-file/index.js
@@ -1,5 +1,5 @@
(function ($) {
- 'use strict';
+ "use strict";
// =====================
@@ -236,7 +236,7 @@
// 生成唯一ID
// =====================
generateUniqueId: function () {
- return 'file_' + Math.random().toString(36).slice(2) + Date.now();
+ return "file_" + Math.random().toString(36).slice(2) + Date.now();
},
// =====================
@@ -1146,10 +1146,10 @@
// 判断是否为图片文件
// =====================
isImageFile: function (filename) {
- if (!filename || typeof filename !== 'string') return false;
+ if (!filename || typeof filename !== "string") return false;
- const ext = filename.slice(filename.lastIndexOf('.') + 1).toLowerCase();
- const imageExts = new Set(['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp']);
+ const ext = filename.slice(filename.lastIndexOf(".") + 1).toLowerCase();
+ const imageExts = new Set(["jpg", "jpeg", "png", "gif", "bmp", "webp"]);
return imageExts.has(ext);
},
@@ -1159,38 +1159,50 @@
// =====================
formatFileSize: function (bytes) {
if (bytes === null || bytes === undefined || isNaN(bytes) || bytes <= 0) {
- return '-';
+ return "-";
}
var k = 1024;
- var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
+ var sizes = ["B", "KB", "MB", "GB", "TB"];
var i = Math.floor(Math.log(bytes) / Math.log(k));
i = Math.max(0, Math.min(i, sizes.length - 1));
- return (bytes / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i];
+ return (bytes / Math.pow(k, i)).toFixed(2) + " " + sizes[i];
},
// =====================
// 格式化日期
// =====================
formatDate: function (dateStr) {
- if (!dateStr) return '-';
+ if (!dateStr) return "-";
var date = new Date(dateStr);
if (isNaN(date.getTime())) {
- return '-';
+ return "-";
}
var year = date.getFullYear();
- var month = ('0' + (date.getMonth() + 1)).slice(-2);
- var day = ('0' + date.getDate()).slice(-2);
- var hours = ('0' + date.getHours()).slice(-2);
- var minutes = ('0' + date.getMinutes()).slice(-2);
- var seconds = ('0' + date.getSeconds()).slice(-2);
+ var month = ("0" + (date.getMonth() + 1)).slice(-2);
+ var day = ("0" + date.getDate()).slice(-2);
+ var hours = ("0" + date.getHours()).slice(-2);
+ var minutes = ("0" + date.getMinutes()).slice(-2);
+ var seconds = ("0" + date.getSeconds()).slice(-2);
- return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
+ return (
+ year +
+ "-" +
+ month +
+ "-" +
+ day +
+ " " +
+ hours +
+ ":" +
+ minutes +
+ ":" +
+ seconds
+ );
},
// =====================
@@ -1201,7 +1213,7 @@
const downloadDisabled = !this.hasPermission(file, 'download');
const deleteDisabled = !this.hasPermission(file, 'delete');
- let content = '';
+ let content = "";
if (this.isImageFile(file.name)) {
content = `
@@ -1228,6 +1240,12 @@
`;
+ // 预览状态(使用class标识)
+ const isPreview = this.previewFiles.has(file._id);
+
+ // 选中状态
+ const isSelected = this.selectedFiles.has(file._id);
+
return `
@@ -1492,10 +1510,11 @@
$.fn.G3File = function (options) {
var args = Array.prototype.slice.call(arguments, 1);
var instance;
+ var methodResult; // 存储方法调用结果
this.each(function () {
var $this = $(this);
- instance = $this.data('G3File');
+ instance = $this.data("G3File");
if (!instance) {
instance = new G3File(this, options);
@@ -1503,12 +1522,12 @@
} else if (typeof options === 'string') {
var method = options;
if (instance[method]) {
- instance[method].apply(instance, args);
+ // 保存方法调用结果
+ methodResult = instance[method].apply(instance, args);
}
}
});
return instance || this;
};
-
-})(jQuery);
\ No newline at end of file
+})(jQuery);
diff --git a/code/file-preview/test.html b/code/file-preview/test.html
index 31e35c46..9ea7e812 100644
--- a/code/file-preview/test.html
+++ b/code/file-preview/test.html
@@ -202,4 +202,4 @@
-