You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

163 lines
6.1 KiB

function getArray(interval = 0, start = new Date(), end = new Date()) {
start.setDate(start.getDate() - interval);
end.setDate(end.getDate() + interval);
var array = [];
var dataArr = [];
var weeks = ['日', '一', '二', '三', '四', '五', '六'];
var num = 0;
while((end.getTime() - start.getTime()) >= 0) {
num ++;
var month = (start.getMonth() + 1).toString().length == 1 ? "0" + (start.getMonth() + 1).toString() : (start.getMonth() + 1);
var day = start.getDate().toString().length == 1 ? "0" + start.getDate() : start.getDate();
var week = weeks[start.getDay()];
dataArr.push(month + "月" + day + '日(周' + week + ')');
var obj = {};
if(num == 1){
obj.week = '今天';
}else{
obj.week = '周'+week;
}
obj.date = new Date().getFullYear()+'-'+month + '-' + day;
obj.date2 = month + '-' + day;
array.push(obj);
start.setDate(start.getDate() + 1);
}
return array;
}
function format(array) {
return array.map(item => {
return {
field: item.date,
title: item.date,
width: 110
}
})
}
//获取两日期之间日期列表函数
function getDiffDate(stime,etime){
//初始化日期列表,数组
var diffDate = new Array();
var i=0;
//开始日期小于等于结束日期,并循环
while(stime<=etime){
diffDate[i] = stime;
//获取开始日期时间戳
var stime_ts = new Date(stime).getTime();
//增加一天时间戳后的日期
var next_date = stime_ts + (24*60*60*1000);
//拼接年月日,这里的月份会返回(0-11),所以要+1
var next_dates_y = new Date(next_date).getFullYear()+'-';
var next_dates_m = (new Date(next_date).getMonth()+1 < 10)?'0'+(new Date(next_date).getMonth()+1)+'-':(new Date(next_date).getMonth()+1)+'-';
var next_dates_d = (new Date(next_date).getDate() < 10)?'0'+new Date(next_date).getDate():new Date(next_date).getDate();
stime = next_dates_y+next_dates_m+next_dates_d;
//增加数组key
i++;
}
return diffDate;
}
function mergeRows(res) {
var data = res.data;
var mergeIndex = 0;//定位需要添加合并属性的行数
var mark = 1; //这里涉及到简单的运算,mark是计算每次需要合并的格子数
var columsName = ['realmName'];//需要合并的列名称
var columsIndex = [0];//需要合并的列索引值
for (var k = 0; k < columsName.length; k++) { //这里循环所有要合并的列
var trArr = $(".layui-table-body>.layui-table").find("tr");//所有行
for (var i = 1; i < res.data.length; i++) { //这里循环表格当前的数据
var tdCurArr = trArr.eq(i).find("td").eq(columsIndex[k]);//获取当前行的当前列
var tdPreArr = trArr.eq(mergeIndex).find("td").eq(columsIndex[k]);//获取相同列的第一列
if (data[i][columsName[k]] == data[i-1][columsName[k]]) { //后一行的值与前一行的值做比较,相同就需要合并
mark += 1;
tdPreArr.each(function () {//相同列的第一列增加rowspan属性
$(this).attr("rowspan", mark);
});
tdCurArr.each(function () {//当前行隐藏
$(this).css("display", "none");
});
}else {
mergeIndex = i;
mark = 1;//一旦前后两行的值不一样了,那么需要合并的格子数mark就需要重新计算
}
if(mark > 1 && data[i].activityType == data[i - 1].activityType) {
var [start1, start2] = [new Date(data[i].startTime), new Date(data[i - 1].startTime)]
var [end1, end2] = [new Date(data[i].endTime), new Date(data[i - 1].endTime)]
if(!(end1 <= start2 || end2 <= start1)) {
tdPreArr.each(function () {
$(this).css({"background-color": "red", "color": "#fff"});
});
}
}
}
mergeIndex = 0;
mark = 1;
}
}
function mergeCols(array) {
var tab = document.querySelector("div .layui-table-main .layui-table");//获取目标label
var maxRow = array.length + 1, count = 1, index = 0;
for(var i = 0;i < tab.rows.length;i++) { //遍历所有行
for(var col = 1 ; col < maxRow ; col++){ //遍历每一行的每一个td
if(tab.rows[i].cells[col].innerText.length > 0 && tab.rows[i].cells[col].innerText == tab.rows[i].cells[col - 1].innerText && col < maxRow - 1) {
count++;
index = col - count + 1;
} else {
if(tab.rows[i].cells[col].innerText.length > 0 && tab.rows[i].cells[col].innerText == tab.rows[i].cells[col - 1].innerText && col === maxRow - 1) {
count++;
index = col - count + 1;
}
if(count > 1) {
tab.rows[i].cells[index].colSpan = count;
for(var j = 1; j < count; j++) {
tab.rows[i].cells[j+index].style.display = "none";
}
}
if(count == 1 && tab.rows[i].cells[col].innerText.length > 0 && tab.rows[i].cells[col].style.display != "none") {
tab.rows[i].cells[col].innerHTML = `<div style="min-width: 105px;margin-left: 5px;text-align: center;background-color: ${randomColorAndNotRed()};color: #fff;">${tab.rows[i].cells[col].innerText}</div>`
}
count = 1;
index = col;
}
}
}
}
function randomColorAndNotRed() {
var r = Math.floor(Math.random() * 200)
var g = Math.floor(Math.random() * 206 + 50)
var b = Math.floor(Math.random() * 206 + 50)
return `rgb(${r},${g},${b})`
}
function transformBeginTime(interval) {
return getFormatDateTime(interval)
}
function getFormatDateTime(interval){
var date = new Date();
date.setDate(date.getDate() - interval);
var year= date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
return [year, '-', month < 10 ? `0${month}` : month , '-', day < 10 ? `0${day}` : day, ' ', hour < 10 ? `0${hour}` : hour , ':', minute < 10 ? `0${minute}` : minute, ':', second < 10 ? `0${second}` : second ].join('');
}
Format();
function Format(){
var js=''
var json=JSON.parse(js)
console.dir(json.Uid) ;
}