1.全局引用
import publicUtils from '@/util/publicUtil';
Vue.prototype.publicUtils = publicUtils;
2.工具类编写
export default {
getSize(val) {
var KB = val / 1024;
var MB = KB / 1024;
if (MB < 1024) {
return `${MB.toFixed(2)}MB`;
} else {
let GB = MB / 1024;
if (GB < 1024) {
return `${GB.toFixed(2)}GB`;
} else {
return `${(GB / 1024).toFixed(2)}TB`;
}
}
},
getProportion(width, height) {
if (height && width) {
return `${width} * ${height}`
}
return ``;
},
padZero(number) {
return number < 10 ? '0' + number : number;
},
timeFormat(seconds) {
var hours = Math.floor(seconds / 3600);
var minutes = Math.floor((seconds % 3600) / 60);
var remainingSeconds = seconds % 60;
// 在小时、分钟、秒数小于10时,在前面补零
var formattedHours = this.padZero(hours);
var formattedMinutes = this.padZero(minutes);
var formattedSeconds = this.padZero(remainingSeconds);
return formattedHours + ':' + formattedMinutes + ':' + formattedSeconds;
}
}
3.具体页面