文件大小过滤器
import Vue from "vue";
Vue.filter("transformByte", function (bytes) {
if (bytes === 0 || bytes === "0") return "0 B";
if (!bytes) return "";
let k = 1024;
let sizes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
let i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toFixed(2) + " " + sizes[i];
});
Vue.filter("limitChar", function (str, num, suffix) {
if (str && str.length >= num) {
str = str.substring(0, num) + suffix || "";
}
return str || "";
});