u
This commit is contained in:
commit
6f4190422a
9 files changed
+269
-258
No files matched your search
@@ -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 @@
|
||||
</div>
|
||||
`;
|
||||
|
||||
// 预览状态(使用class标识)
|
||||
const isPreview = this.previewFiles.has(file._id);
|
||||
|
||||
// 选中状态
|
||||
const isSelected = this.selectedFiles.has(file._id);
|
||||
|
||||
return `
|
||||
<div class="g3-file-item" data-id="${file.id}">
|
||||
<input type="checkbox" class="g3-file-checkbox" />
|
||||
@@ -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);
|
||||
})(jQuery);
|
||||
@@ -202,4 +202,4 @@
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
Reference in new issue
Block a user