This commit is contained in:
walkor 2022-12-04 21:34:17 +08:00
parent 5d4287411a
commit bbb723b540
2 changed files with 29 additions and 7 deletions

View File

@ -285,8 +285,8 @@ class UploadController extends Crud
if($size == 0) { if($size == 0) {
return("0 Bytes"); return("0 Bytes");
} }
$sizename = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); $size_name = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizename[$i]; return round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $size_name[$i];
} }
} }

View File

@ -117,7 +117,7 @@
layui.use(["laydate"], function() { layui.use(["laydate"], function() {
layui.laydate.render({ layui.laydate.render({
elem: "#created_at", elem: "#created_at",
range: ["#created_at-date-start", "#created_at-date-end"], range: ["#created_at-date-start", "#created_at-date-end"],
type: 'datetime', type: 'datetime',
}); });
}) })
@ -134,9 +134,9 @@
el: "#category", el: "#category",
name: "category", name: "category",
initValue: initValue, initValue: initValue,
data: e.data, data: e.data,
model: {"icon":"hidden","label":{"type":"text"}}, model: {"icon":"hidden","label":{"type":"text"}},
clickClose: 'true', clickClose: 'true',
radio: 'true', radio: 'true',
}) })
} }
@ -158,14 +158,18 @@
},{ },{
title: "主键", title: "主键",
field: "id", field: "id",
width: 80,
sort: true, sort: true,
},{ },{
title: "名字", title: "名字",
field: "name", field: "name",
},{ },{
title: "url", title: "文件",
field: "url", field: "url",
templet: function (d) { templet: function (d) {
if (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg'].indexOf(d.ext.toLowerCase()) !== -1) {
return '<img src="' + encodeURI(d['url']) + '" style="max-width:32px;max-height:32px;" />';
}
return '<a href="' + encodeURI(d['url']) + '" target="_blank">' + util.escape(d['url']) + '</a>'; return '<a href="' + encodeURI(d['url']) + '" target="_blank">' + util.escape(d['url']) + '</a>';
} }
},{ },{
@ -179,9 +183,13 @@
},{ },{
title: "文件大小", title: "文件大小",
field: "file_size", field: "file_size",
templet: function (d) {
return formatSize(d.file_size);
}
},{ },{
title: "mime类型", title: "mime类型",
field: "mime_type", field: "mime_type",
hide: true,
},{ },{
title: "图片宽度", title: "图片宽度",
field: "image_width", field: "image_width",
@ -394,6 +402,20 @@
scrollPos: 'fixed' scrollPos: 'fixed'
}); });
} }
// 格式化文件大小
let formatSize = function(value) {
if(null == value || '' === value){
return "0 Bytes";
}
let unitArr = ["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"];
let index = 0;
let srcSize = parseFloat(value);
index = Math.floor(Math.log(srcSize) / Math.log(1024));
let size =srcSize / Math.pow(1024, index);
size = size.toFixed(2);
return size + unitArr[index];
}
}) })
</script> </script>