128 lines
2.7 KiB
Plaintext
128 lines
2.7 KiB
Plaintext
|
/**
|
|||
|
* 序号格式化
|
|||
|
* @param num
|
|||
|
*/
|
|||
|
function indexNumFormat(num) {
|
|||
|
switch (num) {
|
|||
|
case 0:
|
|||
|
num = "Ⅰ";
|
|||
|
break;
|
|||
|
case 1:
|
|||
|
num = "Ⅱ";
|
|||
|
break;
|
|||
|
case 2:
|
|||
|
num = "Ⅲ";
|
|||
|
break;
|
|||
|
case 3:
|
|||
|
num = "Ⅳ";
|
|||
|
break;
|
|||
|
case 4:
|
|||
|
num = "Ⅴ";
|
|||
|
break;
|
|||
|
case 5:
|
|||
|
num = "Ⅵ";
|
|||
|
break;
|
|||
|
case 6:
|
|||
|
num = "Ⅶ";
|
|||
|
break;
|
|||
|
case 7:
|
|||
|
num = "Ⅷ";
|
|||
|
break;
|
|||
|
case 8:
|
|||
|
num = "Ⅸ";
|
|||
|
break;
|
|||
|
}
|
|||
|
return num;
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* 计算时长
|
|||
|
* @param val
|
|||
|
*/
|
|||
|
function findDurationDate(val) {
|
|||
|
// 计算出相差天数
|
|||
|
let days = Math.floor(val / (24 * 3600 * 1000))
|
|||
|
// 计算出小时数
|
|||
|
let leave1 = val % (24 * 3600 * 1000) // 计算天数后剩余的毫秒数
|
|||
|
let hours = Math.floor(leave1 / (3600 * 1000))
|
|||
|
// 计算相差分钟数
|
|||
|
let leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数
|
|||
|
let minutes = Math.floor(leave2 / (60 * 1000))
|
|||
|
// 计算相差秒数
|
|||
|
let leave3 = leave2 % (60 * 1000) // 计算分钟数后剩余的毫秒数
|
|||
|
let seconds = Math.round(leave3 / 1000)
|
|||
|
if (days > 0) {
|
|||
|
if (days < 10) days = "0" + days;
|
|||
|
if (hours < 10) hours = "0" + hours;
|
|||
|
if (minutes < 10) minutes = "0" + minutes;
|
|||
|
if (seconds < 10) seconds = "0" + seconds;
|
|||
|
return days + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒';
|
|||
|
}
|
|||
|
if (hours > 0) {
|
|||
|
if (hours < 10) hours = "0" + hours;
|
|||
|
if (minutes < 10) minutes = "0" + minutes;
|
|||
|
if (seconds < 10) seconds = "0" + seconds;
|
|||
|
return hours + '小时' + minutes + '分钟' + seconds + '秒';
|
|||
|
}
|
|||
|
if (minutes > 0) {
|
|||
|
if (minutes < 10) minutes = "0" + minutes;
|
|||
|
if (seconds < 10) seconds = "0" + seconds;
|
|||
|
return minutes + '分钟' + seconds + '秒';
|
|||
|
}
|
|||
|
if (seconds > 0) {
|
|||
|
if (seconds < 10) seconds = "0" + seconds;
|
|||
|
return seconds + '秒';
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
module.exports = {
|
|||
|
indexNumFormat: indexNumFormat,
|
|||
|
findDurationDate: findDurationDate,
|
|||
|
split:function(str,sign){
|
|||
|
return str.split(sign);
|
|||
|
},
|
|||
|
parseStr:function(str){
|
|||
|
return JSON.parse(str);
|
|||
|
},
|
|||
|
evalStr:function(str){
|
|||
|
return eval(str);
|
|||
|
},
|
|||
|
dateStrEv:function(startDate,endDate){
|
|||
|
if(startDate){
|
|||
|
return startDate.split(" ")[0];
|
|||
|
}else if(endDate){
|
|||
|
return endDate.split(" ")[0];
|
|||
|
}else{
|
|||
|
return "未找到记录";
|
|||
|
}
|
|||
|
},
|
|||
|
dateStr:function(str){
|
|||
|
if(str){
|
|||
|
return str.split(" ")[0];
|
|||
|
}else{
|
|||
|
return "";
|
|||
|
}
|
|||
|
},
|
|||
|
timeStr:function(str){
|
|||
|
return str.split(" ")[1];
|
|||
|
},
|
|||
|
isHttpImg:function(str){
|
|||
|
if(str.indexOf("http:")>-1 || str.indexOf("https:")>-1){
|
|||
|
return true;
|
|||
|
}else{
|
|||
|
return false;
|
|||
|
}
|
|||
|
},
|
|||
|
birthDate:function(timestamp){
|
|||
|
var date = getDate(parseInt(timestamp));
|
|||
|
var mm = date.getMonth()+1;
|
|||
|
if(mm<10){
|
|||
|
mm = '0'+mm;
|
|||
|
}
|
|||
|
var dd = date.getDate();
|
|||
|
if(dd<10){
|
|||
|
dd = '0'+dd;
|
|||
|
}
|
|||
|
return date.getFullYear()+"-"+mm+"-"+dd;
|
|||
|
}
|
|||
|
}
|