var dateUtils = {
|
UNITS: {
|
'年': 31557600000,
|
'月': 2629800000,
|
'天': 86400000,
|
'小时': 3600000,
|
'分钟': 60000,
|
'秒': 1000
|
},
|
humanize: function(milliseconds) {
|
var humanize = '';
|
mui.each(this.UNITS, function(unit, value) {
|
if (milliseconds >= value) {
|
humanize = Math.floor(milliseconds / value) + unit + '前';
|
return false;
|
}
|
return true;
|
});
|
return humanize; // || '刚刚';
|
},
|
format: function(dateStr, notime) {
|
var date = this.parse(dateStr)
|
return this.openinfo_formatter_ttime(dateStr, 'notime');
|
/* var diff = Date.now() - date.getTime();
|
if (diff < this.UNITS['天']) {
|
return this.humanize(diff);
|
} else
|
return this.openinfo_formatter_ttime(dateStr, notime)
|
var _format = function (number) {
|
return (number < 10 ? ('0' + number) : number);
|
};
|
return date.getFullYear() + '/' + _format(date.getMonth() + 1) + '/' + _format(date.getDate()) + '-' + _format(
|
date.getHours()) + ':' + _format(date.getMinutes()); */
|
},
|
parse: function(str) { //将"yyyy-mm-dd HH:MM:ss"格式的字符串,转化为一个Date对象
|
var a = str.split(/[^0-9]/);
|
if (a.length == 1)
|
return new Date(a[0], 1, 1, 0, 0, 1);
|
else if (a.length == 2)
|
return new Date(a[0], a[1] - 1, 1, 0, 0, 1);
|
else if (a.length == 3)
|
return new Date(a[0], a[1] - 1, a[2], 0, 0, 1);
|
else if (a.length == 4)
|
return new Date(a[0], a[1] - 1, a[2], a[3], 0, 1);
|
else if (a.length == 5)
|
return new Date(a[0], a[1] - 1, a[2], a[3], a[4], 1);
|
else if (a.length >= 6)
|
return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
|
else
|
return new Date();
|
},
|
openinfo_formatter_ttime: function(cellvalue, nowhat) {
|
var cv_o = cellvalue.split(' ')[0];
|
var cv_t = cellvalue.split(' ')[1];
|
if (nowhat) {
|
cv_t = "";
|
}
|
var date = new Date();
|
var time = cv_o;
|
var h_m = "";
|
if (cv_t)
|
h_m = cv_t.split(':')[0] + ':' + cv_t.split(':')[1];
|
if (cv_o.split('-').length == 3)
|
if (date.getFullYear() == cv_o.split('-')[0]) {
|
time = " " + cv_o.split('-')[1] + '-' + cv_o.split('-')[2];
|
if (date.getMonth() + 1 == cv_o.split('-')[1]) {
|
if (date.getDate() == cv_o.split('-')[2])
|
time = "今天";
|
if (date.getDate() - 1 == cv_o.split('-')[2])
|
time = '昨天';
|
if (date.getDate() - 2 == cv_o.split('-')[2])
|
time = '前天';
|
}
|
} else {
|
time = cv_o.split('-')[1] + '-' + cv_o.split('-')[2];
|
if (date.getFullYear() - 1 == cv_o.split('-')[0]) {
|
//time = time + " 去年";
|
}
|
if (date.getFullYear() - 2 == cv_o.split('-')[0]) {
|
//time = time + " 前年";
|
}
|
time = cv_o.split('-')[0] + '-' + time;
|
}
|
return time + (h_m ? (" " + h_m) : "");
|
},
|
getDate: function(type) {
|
const date = new Date();
|
|
let year = date.getFullYear();
|
let month = date.getMonth() + 1;
|
let day = date.getDate();
|
|
if (type === 'start') {
|
year = year - 10;
|
} else if (type === 'end') {
|
year = year + 10;
|
}
|
month = month > 9 ? month : '0' + month;;
|
day = day > 9 ? day : '0' + day;
|
|
return `${year}-${month}-${day}`;
|
},
|
getShortDate: function(dateStr) {
|
var date = new Date()
|
if (dateStr) {
|
dateStr = dateStr.trim()
|
|
if (dateStr != "")
|
date = this.parse(dateStr)
|
}
|
//console.log("getShortDate2",dateStr,date)
|
let year = date.getFullYear();
|
let month = date.getMonth() + 1;
|
return `${year}年${month}月`;
|
},
|
toDateTimeString: function(date) {
|
let year = date.getFullYear();
|
let month = date.getMonth() + 1;
|
let day = date.getDate();
|
let hour = date.getHours();
|
let minute = date.getMinutes();
|
let second = date.getSeconds();
|
month = month > 9 ? month : '0' + month;;
|
day = day > 9 ? day : '0' + day;
|
hour = hour > 9 ? hour : '0' + hour;
|
minute = minute > 9 ? minute : '0' + minute;
|
second = second > 9 ? second : '0' + second;
|
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
},
|
toDateString: function(date) {
|
let year = date.getFullYear();
|
let month = date.getMonth() + 1;
|
let day = date.getDate();
|
month = month > 9 ? month : '0' + month;;
|
day = day > 9 ? day : '0' + day;
|
return `${year}-${month}-${day}`;
|
},
|
toTimeString: function(date) {
|
let hour = date.getHours();
|
let minute = date.getMinutes();
|
let second = date.getSeconds();
|
hour = hour > 9 ? hour : '0' + hour;
|
minute = minute > 9 ? minute : '0' + minute;
|
second = second > 9 ? second : '0' + second;
|
return `${hour}:${minute}:${second}`;
|
},
|
toShortTimeString: function(date) {
|
let hour = date.getHours();
|
let minute = date.getMinutes();
|
hour = hour > 9 ? hour : '0' + hour;
|
minute = minute > 9 ? minute : '0' + minute;
|
return `${hour}:${minute}`;
|
},
|
|
toShortDateTimeString: function(date) {
|
let month = date.getMonth() + 1;
|
let day = date.getDate();
|
month = month > 9 ? month : '0' + month;;
|
day = day > 9 ? day : '0' + day;
|
let hour = date.getHours();
|
let minute = date.getMinutes();
|
hour = hour > 9 ? hour : '0' + hour;
|
minute = minute > 9 ? minute : '0' + minute;
|
return `${month}-${day} ${hour}:${minute}`;
|
},
|
|
}
|
var fileUtils = {
|
isPictureType: function(fileName) {
|
if (".tiff.pjp.jfif.bmp.gif.svg.png.xbm.dib.jxl.jpeg.svgz.jpg.webp.ico.tif.pjpeg.avif.image".indexOf(
|
fileName
|
.split('.').pop().toLowerCase()) < 0) //图片
|
{
|
return false
|
}
|
return true
|
},
|
isDocumentType: function(fileName) {
|
//#ifdef MP-WEIXIN
|
if (".doc.xls.ppt.pdf.docx.xlsx.pptx".indexOf(fileName.split('.').pop().toLowerCase()) < 0) //文档
|
{
|
return false
|
}
|
return true
|
//#endif
|
//#ifdef MP-DINGTALK
|
if (".pdf".indexOf(fileName.split('.').pop().toLowerCase()) < 0) //文档
|
{
|
return false
|
}
|
return true
|
//#endif
|
return false
|
|
},
|
isVideoType: function(fileName) {
|
if (".mp4.webm.ogg.video".indexOf(fileName.split('.').pop().toLowerCase()) < 0) //视频
|
{
|
return false
|
}
|
return true
|
},
|
isAudioType: function(fileName) {
|
if (".mp3.audio".indexOf(fileName.split('.').pop().toLowerCase()) < 0) //视频
|
{
|
return false
|
}
|
return true
|
},
|
isCanPreviewType: function(fileName) {
|
if (this.isDocumentType(fileName) || this.isPictureType(fileName) || this.isVideoType(fileName) || this
|
.isAudioType(fileName)) //视频
|
{
|
return true
|
}
|
return false
|
},
|
getTypeBgColor: function(fileName) {
|
let color = '#ccc'
|
if (this.isPictureType(fileName)) {
|
color = '#e5e5e5'
|
} else if (this.isVideoType(fileName)) {
|
color = '#456476'
|
} else if (this.isAudioType(fileName)) {
|
color = '#f0f0f0'
|
} else if (".doc.docx".indexOf(fileName.split('.').pop().toLowerCase()) > -1) //文档
|
{
|
color = '#059fff'
|
} else if (".xls.xlsx".indexOf(fileName.split('.').pop().toLowerCase()) > -1) //文档
|
{
|
color = '#16b251'
|
} else if (".ppt.pptx".indexOf(fileName.split('.').pop().toLowerCase()) > -1) //文档
|
{
|
color = '#f9661d'
|
} else if (".pdf".indexOf(fileName.split('.').pop().toLowerCase()) > -1) //文档
|
{
|
color = '#fa493d'
|
}
|
return color
|
},
|
getFileSizeStr(size) {
|
let sizeStr
|
if (size > 1024 * 1024)
|
sizeStr = Math.round(size / (1024 * 1024)) + ' MB'
|
else if (size > 1024)
|
sizeStr = Math.round(size / (1024)) + ' KB'
|
else
|
sizeStr = (size) + ' B'
|
return sizeStr
|
},
|
|
|
}
|
|
var taskstate = {
|
'未读': 'fs-mail_close',
|
'已读': 'fs-mail_open',
|
'执行': 'fs-run_man',
|
'退回': 'fs-goback',
|
'完成': 'fs-flag',
|
'提交': 'fs-TaskSubmission',
|
'搁置': 'fs-pause',
|
'出错': 'fs-wrong',
|
'终止': 'fs-Due',
|
'归档': 'fs-project_doc',
|
'计划': 'fs-project_manage',
|
'等待': 'fs-wait',
|
'编辑': 'fs-PRJ_edit',
|
'审核': 'fs-Audit',
|
'删除': 'fs-delete_solid_circle',
|
'撤回': 'fs-return_key'
|
};
|
var eventstate = {
|
'问题': 'fs-question2',
|
'错误': 'fs-bug',
|
'需求': 'fs-CirclPlus',
|
'建议': 'fs-suggest',
|
'讨论': 'fs-discuss',
|
}
|
export default {
|
dateUtils,
|
fileUtils,
|
taskstate,
|
eventstate
|
}
|