ah_sz_gqj/src/main/resources/static/js/commonUtils.js

117 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 格式化日对象
const getNowDate = () => {
var date = new Date();
var sign2 = "-";
var year = date.getFullYear() // 年
var month = date.getMonth() + 1; // 月
var day = date.getDate(); // 日
var hour = date.getHours(); // 时
var minutes = date.getMinutes(); // 分
var seconds = date.getSeconds() //秒
var weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'];
var week = weekArr[date.getDay()];
// 给一位数的数据前面加 “0”
if (month >= 1 && month <= 9) {
month = "0" + month;
}
if (day >= 0 && day <= 9) {
day = "0" + day;
}
if (hour >= 0 && hour <= 9) {
hour = "0" + hour;
}
if (minutes >= 0 && minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds >= 0 && seconds <= 9) {
seconds = "0" + seconds;
}
return year + "-" + month + "-" + day + "-" + hour + sign2 + minutes + sign2 + seconds;
}
function getTime() {
var today = new Date();
// 获取年、月、日、时、分、秒
var year = today.getFullYear();
var month = today.getMonth() + 1; // 月份是从 0 开始计数的需要加1
var day = today.getDate();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
// 格式化输出
var formattedTime = year + "" +
(month < 10 ? "0" : "") + month + "" +
(day < 10 ? "0" : "") + day + "" +
(hours < 10 ? "0" : "") + hours + "" +
(minutes < 10 ? "0" : "") + minutes + "" +
(seconds < 10 ? "0" : "") + seconds;
return formattedTime;
}
/**
* 获取当日时间
*/
function getNowTime() {
var nowDate = new Date();
var year = nowDate.getFullYear();
var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) :
nowDate.getMonth() + 1;
var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
var dateStr = year + "-" + month + "-" + day;
return dateStr;
}
// 获取当前日期 后几天的日期
function fun_date(aa) {
//time1表示当前时间
let date1 = new Date(), time1 = date1.getFullYear() + "-" + (date1.getMonth() + 1) + "-" + date1.getDate();
let date2 = new Date(date1);
date2.setDate(date1.getDate() + aa);
let month = date2.getMonth() + 1 < 10 ? "0" + (date2.getMonth() + 1) :
date2.getMonth() + 1;
let day = date2.getDate() < 10 ? "0" + date2.getDate() : date2.getDate();
let time2 = date2.getFullYear() + "-" + month + "-" + day;
return time2;
}
function formatSeconds(value) {
let hh = parseInt(value / 3600);
if (hh < 10) hh = "0" + hh;
let mm = parseInt((value - hh * 3600) / 60);
if (mm < 10) mm = "0" + mm;
let ss = parseInt((value - hh * 3600) % 60);
if (ss < 10) ss = "0" + ss;
let length = hh + ":" + mm + ":" + ss;
if (value > 0) {
return length;
} else {
return "00:00:00";
}
}
/*设置审核状态字体颜色*/
function setAuditStatus(value){
console.log(value)
if(value === '待试验' || value === '待提交' || value === '待审核' || value === '待审批' || value === '待审阅' || value === '待修改' || value === '待重新审阅'){
return '<span style="color: #5778f3">'+value+'</span>';
}else if(value === '审阅不通过' || value === '审核不通过' || value === '审批不通过'){
return '<span style="color: #f1895b ">'+value+'</span>';
}else if(value === '试验完成'){
return '<span style="color: #C4C4C4">'+value+'</span>';
}
}
/**
* 将日期转换为年月日
* */
function formatDate(dateString) {
if(!dateString){
return '';
}
const date = new Date(dateString);
const year = date.getFullYear();
const month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份是从0开始的
const day = ('0' + date.getDate()).slice(-2);
return `${year}${month}${day}`;
}