formateDate

日期格式化函数

function formateDate(fmt, date) {
let _this = new Date(date)
let o = {
"M+": _this.getMonth() + 1,
"d+": _this.getDate(),
"h+": _this.getHours(),
"m+": _this.getMinutes(),
"s+": _this.getSeconds(),
"q+": Math.floor((_this.getMonth() + 3) / 3),
"S": _this.getMilliseconds()
};
if (/(y+)/.test(fmt))
fmt = fmt.replace(RegExp.$1, (_this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt))
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}

转载于:https://www.cnblogs.com/aloneCode/p/11466026.html

在vue的methods里有下面这个方法。帮我优化一下。 setcanvasetandpf(i, j, ctx, cwidth, cheight, zi) { ctx.beginPath() //绘制长方框 var huihua = 0 var szi = i if (zi == 0) { } else { szi = zi } //维修检测 this.drawroomstate(i, j, ctx, cwidth, cheight, szi, huihua) //入住情况 for (var m = 0; m < this.setandpf.data.set.length; m++) { var starttime = new Date(this.setandpf.data.set[m][13]) var endtime = new Date(this.setandpf.data.set[m][14]) var starttime1 = starttime.getFullYear() + "-" + (starttime.getMonth() + 1).toString().padStart(2, '0') + "-" + starttime.getDate().toString().padStart(2, '0') var endtime1 = endtime.getFullYear() + "-" + (endtime.getMonth() + 1).toString().padStart(2, '0') + "-" + endtime.getDate().toString().padStart(2, '0') var days = this.subdate(this.condate3[j], endtime1) if (this.roomlist[szi].id == this.setandpf.data.set[m][2] && this.condate3[j] == starttime1) { //开始时间在查询日期之间的入住信息 这里分为已完成,未完成2种情况 if (this.setandpf.data.set[m][18] == "1" && this.setandpf.data.set[m][12] != "0") { huihua = 1 var cc = this.getsalescolor(this.setandpf.data.set[m][5]) ctx.fillStyle = "#f2f3f6" //this.hexToRgba(cc.Row[4], 0.1) //表示已退房 ctx.fillRect(j * cwidth, szi * cheight, cwidth * (days) - 1, cheight - 1); // 绘制矩形 this.drawracts2(ctx, j, szi, cwidth, cheight, days) ctx.fillStyle = cc.Row[4]; //ota标识 ctx.fillRect(j * cwidth, szi * cheight, cwidth - 90, cheight - 1); // 绘制矩形 ctx.fillStyle = "black";//预定人 ctx.fillText(this.setandpf.data.set[m][3], j * cwidth + 15, szi * cheight + 15); ctx.font = '12px Arial';//来源渠道 ctx.fillText(cc.Row[1], j * cwidth + 15, szi * cheight + 33); this.roomstatus(j, szi, this.roomlist[szi].id, 'tui', days, this.roomstatudes.tui, this.setandpf.data.set[m][0]) } else if (this.setandpf.data.set[m][18] == "0") { const now = new Date(endtime); const todayAt14 = now.getFullYear() + "-" + (now.getMonth() + 1).toString().padStart(2, '0') + "-" + now.getDate().toString().padStart(2, '0') + " 14:30:00" const dateToCompare = this.formatedate1(new Date()); const todays = new Date() const dbtodays = todays.getFullYear() + "-" + (todays.getMonth() + 1).toString().padStart(2, '0') + "-" + todays.getDate().toString().padStart(2, '0') + " 14:30:00" if (this.condate3[j] == this.addDays(endtime1, -1) && dateToCompare > todayAt14) { huihua = 1 var cc = this.getsalescolor(this.setandpf.data.set[m][5]) ctx.fillStyle = this.hexToRgba(cc.Row[4], 0.3) //表示已退房 ctx.fillRect(j * cwidth, szi * cheight, cwidth * (days) - 1, cheight - 1); // 绘制矩形 this.drawracts2(ctx, j, szi, cwidth, cheight, days) ctx.fillStyle = cc.Row[4]; //ota标识 ctx.fillRect(j * cwidth, szi * cheight, cwidth - 90, cheight - 1); // 绘制矩形 ctx.fillStyle = "black";//预定人 ctx.fillText(this.setandpf.data.set[m][3], j * cwidth + 15, szi * cheight + 15); ctx.font = '12px Arial';//来源渠道 ctx.fillText(cc.Row[1], j * cwidth + 15, szi * cheight + 33); ctx.fillStyle = '#f56c6c'; ctx.fillRect(j * cwidth + (cwidth * (days - 1)) + 80, szi * cheight + 3, cwidth - 84, cheight - 35); // 绘制矩形 ctx.font = '12px Arial'; ctx.fillStyle = 'white'; ctx.fillText('超', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); this.roomstatus(j, szi, this.roomlist[szi].id, 'set', days, this.roomstatudes.zhu, this.setandpf.data.set[m][0]) } else { const now = new Date(endtime); const todayAt14 = now.getFullYear() + "-" + (now.getMonth() + 1).toString().padStart(2, '0') + "-" + now.getDate().toString().padStart(2, '0') + " 14:30:00" const dateToCompare = this.formatedate1(new Date()); huihua = 1 var cc = this.getsalescolor(this.setandpf.data.set[m][5]) ctx.fillStyle = this.hexToRgba(cc.Row[4], 0.3) //表示已退房 this.drawracts2(ctx, j, szi, cwidth, cheight, days) ctx.fillRect(j * cwidth, szi * cheight, cwidth * (days) - 1, cheight - 1); // 绘制矩形 ctx.fillStyle = cc.Row[4]; //ota标识 ctx.fillRect(j * cwidth, szi * cheight, cwidth - 90, cheight - 1); // 绘制矩形 ctx.fillStyle = "black";//预定人 ctx.fillText(this.setandpf.data.set[m][3], j * cwidth + 15, szi * cheight + 15); ctx.font = '12px Arial';//来源渠道 ctx.fillText(cc.Row[1], j * cwidth + 15, szi * cheight + 33); if (dateToCompare > todayAt14) { ctx.fillStyle = '#f2f3f6'; ctx.fillRect(j * cwidth + (cwidth * (days - 1)) + 80, szi * cheight + 3, cwidth - 84, cheight - 35); // 绘制矩形 ctx.font = '13px Arial'; ctx.fillStyle = 'red'; ctx.fillText('超', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); } else { ctx.fillStyle = '#67c23a'; //住背景 ctx.fillRect(j * cwidth + (cwidth * (days - 1)) + 80, szi * cheight + 3, cwidth - 84, cheight - 35); // 绘制矩形 ctx.font = '13px Arial'; ctx.fillStyle = 'white'; //住 ctx.fillText('住', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); } this.roomstatus(j, szi, this.roomlist[szi].id, 'set', days, this.roomstatudes.zhu, this.setandpf.data.set[m][0]) } } else { } break; } else { if (this.roomlist[szi].id == this.setandpf.data.set[m][2] && this.condate3[j] < endtime1 && this.condate3[j] > starttime1) { huihua = 1 if (this.setandpf.data.set[m][18] == "1") { this.roomstatus(j, i, this.roomlist[szi].id, 'set', days, this.roomstatudes.tui, this.setandpf.data.set[m][0]) } else { if (this.condate3[0] > starttime1 && this.condate3[0] == this.condate3[j]) { const now = new Date(endtime); const todayAt13 = now.getFullYear() + "-" + (now.getMonth() + 1).toString().padStart(2, '0') + "-" + now.getDate().toString().padStart(2, '0') + " 14:30:00" const todayAt14 = new Date(todayAt13) const dateToCompare = new Date(this.formatedate1(new Date()).replace(' ', 'T')); var cc = this.getsalescolor(this.setandpf.data.set[m][5]) ctx.fillStyle = this.hexToRgba(cc.Row[4], 0.3) //表示已退房 ctx.fillRect(j * cwidth, szi * cheight, cwidth * (days) - 1, cheight - 1); // 绘制矩形 this.drawracts2(ctx, j, szi, cwidth, cheight, days) ctx.fillStyle = cc.Row[4]; //ota标识 ctx.fillRect(j * cwidth, szi * cheight, cwidth - 90, cheight - 1); // 绘制矩形 ctx.fillStyle = "black";//预定人 ctx.fillText(this.setandpf.data.set[m][3], j * cwidth + 15, szi * cheight + 15); ctx.font = '12px Arial';//来源渠道 ctx.fillText(cc.Row[1], j * cwidth + 15, szi * cheight + 33); if (dateToCompare > todayAt14) { ctx.fillStyle = '#f2f3f6'; //住背景 ctx.fillRect(j * cwidth + (cwidth * (days - 1)) + 80, szi * cheight + 3, cwidth - 84, cheight - 35); // 绘制矩形 ctx.font = '12px Arial'; ctx.fillStyle = 'red'; //住 ctx.fillText('超', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); } else { ctx.fillStyle = '#67c23a'; //住背景 ctx.fillRect(j * cwidth + (cwidth * (days - 1)) + 80, szi * cheight + 3, cwidth - 84, cheight - 35); // 绘制矩形 ctx.font = '12px Arial'; ctx.fillStyle = 'red'; //住 ctx.fillText('住', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); } this.roomstatus(j, szi, this.roomlist[szi].id, 'set', days, this.roomstatudes.zhu, this.setandpf.data.set[m][0]) } else { this.roomstatus(j, szi, this.roomlist[szi].id, 'set', days, this.roomstatudes.zhu, this.setandpf.data.set[m][0]) } } break; } else { huihua = 0 } } if (this.roomlist[szi].id == this.setandpf.data.set[m][2] && this.condate3[0] > starttime1 && this.condate3[j] < endtime1 && this.condate3[0] == this.condate3[j]) { //入住时间小于查询开始日期 if (this.setandpf.data.set[m][18] == "1") { huihua = 1 var cc = this.getsalescolor(this.setandpf.data.set[m][5]) ctx.fillStyle = "#f2f3f6" //半透明背景 ctx.fillRect(j * cwidth, szi * cheight, cwidth * (days) - 1, cheight - 1); // 绘制矩形 this.drawracts2(ctx, j, szi, cwidth, cheight, days) ctx.fillStyle = cc.Row[4]; //ota标识 ctx.fillRect(j * cwidth, szi * cheight, cwidth - 90, cheight - 1); // 绘制矩形 ctx.fillStyle = "black";//预定人 ctx.fillText(this.setandpf.data.set[m][3], j * cwidth + 15, szi * cheight + 15); ctx.font = '12px Arial';//来源渠道 ctx.fillText(cc.Row[1], j * cwidth + 15, szi * cheight + 33); ctx.fillStyle = 'black'; //离 ctx.fillText('离', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); this.roomstatus(j, szi, this.roomlist[szi].id, 'set', days, this.roomstatudes.tui, this.setandpf.data.set[m][0]) } else { const now = new Date(endtime); const todayAt13 = now.getFullYear() + "-" + (now.getMonth() + 1).toString().padStart(2, '0') + "-" + now.getDate().toString().padStart(2, '0') + " 14:30:00" const todayAt14 = new Date(todayAt13) const dateToCompare = new Date(this.formatedate1(new Date()).replace(' ', 'T')); huihua = 1 var days = this.subdate(this.condate3[j], endtime1) var cc = this.getsalescolor(this.setandpf.data.set[m][5]) ctx.fillStyle = this.hexToRgba(cc.Row[4], 0.1) //半透明背景 ctx.fillRect(j * cwidth, szi * cheight, cwidth * (days) - 1, cheight - 1); // 绘制矩形 this.drawracts2(ctx, j, szi, cwidth, cheight, days) ctx.fillStyle = cc.Row[4]; //ota标识 ctx.fillRect(j * cwidth, szi * cheight, cwidth - 90, cheight - 1); // 绘制矩形 ctx.fillStyle = "black";//预定人 ctx.fillText(this.setandpf.data.set[m][3], j * cwidth + 15, szi * cheight + 15); ctx.font = '12px Arial';//来源渠道 ctx.fillText(cc.Row[1], j * cwidth + 15, szi * cheight + 33); if (dateToCompare > todayAt14) { ctx.fillStyle = '#f56c6c'; //住背景 ctx.fillRect(j * cwidth + (cwidth * (days - 1)) + 80, szi * cheight + 3, cwidth - 84, cheight - 35); // 绘制矩形 ctx.font = '12px Arial'; ctx.fillStyle = 'red'; //住 ctx.fillText('超', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); } else { ctx.fillStyle = '#67c23a'; //住背景 ctx.fillRect(j * cwidth + (cwidth * (days - 1)) + 80, szi * cheight + 3, cwidth - 84, cheight - 35); // 绘制矩形 ctx.font = '12px Arial'; ctx.fillStyle = 'red'; //住 ctx.fillText('住', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); } this.roomstatus(j, szi, this.roomlist[szi].id, 'set', days, this.roomstatudes.zhu, this.setandpf.data.set[m][0]) } break; } else { if (this.roomlist[szi].id == this.setandpf.data.set[m][2] && this.condate3[j] < endtime1 && this.condate3[0] > starttime1) { huihua = 1 this.roomstatus(j, szi, this.roomlist[szi].id, 'set', days, this.roomstatudes.zhu, this.setandpf.data.set[m][0]) } else { huihua = 0 } } } //预定情况 for (var m = 0; m < this.setandpf.data.pf.length; m++) { var starttime = new Date(this.setandpf.data.pf[m][10]) var endtime = new Date(this.setandpf.data.pf[m][11]) var starttime1 = starttime.getFullYear() + "-" + (starttime.getMonth() + 1).toString().padStart(2, '0') + "-" + starttime.getDate().toString().padStart(2, '0') var endtime1 = endtime.getFullYear() + "-" + (endtime.getMonth() + 1).toString().padStart(2, '0') + "-" + endtime.getDate().toString().padStart(2, '0') var days = this.subdate(this.condate3[j], endtime1) if (this.roomlist[szi].id == this.setandpf.data.pf[m][15] && this.condate3[j] == this.setandpf.data.pf[m][10]) { if (this.condate3[j] == this.setandpf.data.pf[m][10]) { huihua = 1 var cc = this.getsalescolor(this.setandpf.data.pf[m][9]) ctx.fillStyle = this.hexToRgba(cc.Row[4], 0.1) //半透明背景 ctx.fillRect(j * cwidth, szi * cheight, cwidth * days - 1, cheight - 1); // 绘制矩形 ctx.fillStyle = cc.Row[4]; //ota标识 ctx.fillRect(j * cwidth, szi * cheight, cwidth - 90, cheight - 1); // 绘制矩形 ctx.fillStyle = "black";//预定人 ctx.fillText(this.setandpf.data.pf[m][2], j * cwidth + 15, szi * cheight + 15); ctx.font = '12px Arial';//来源渠道 ctx.fillText(cc.Row[1], j * cwidth + 15, szi * cheight + 33); ctx.fillStyle = '#e6a23c'; //住背景 ctx.fillRect(j * cwidth + (cwidth * (days - 1)) + 80, szi * cheight + 3, cwidth - 84, cheight - 35); // 绘制矩形 ctx.font = '12px Arial'; ctx.fillStyle = 'white'; //住 ctx.fillText('预', j * cwidth + (cwidth * (days - 1)) + 82, szi * cheight + 15); this.drawracts2(ctx, j, szi, cwidth, cheight, days) this.roomstatus(j, szi, this.roomlist[szi].id, 'pf', days, this.roomstatudes.yu, this.setandpf.data.pf[m][0]) } break; } else { if (this.roomlist[szi].id == this.setandpf.data.pf[m][15] && this.condate3[j] < endtime1 && this.condate3[j] > starttime1) { this.roomstatus(j, szi, this.roomlist[szi].id, 'pf', days, this.roomstatudes.yu, this.setandpf.data.pf[m][0]) huihua = 1 } } } if (huihua == 0) { var newdate = new Date(); var mydate = newdate.getFullYear() + "-" + (newdate.getMonth() + 1).toString().padStart(2, '0') + "-" + newdate.getDate().toString().padStart(2, '0') if (this.condate3[j] == mydate) { //这里今天判断房间状态 if (this.roomlist[i].clean == 0) { const img = new Image(); // 设置图片源 img.src = '/src/assets/dasao.png'; // 替换为你的图片路径 img.onload = function () { ctx.drawImage(img, j * cwidth + 30, szi * cheight + 8, 25, 25) ctx.font = '12px Arial'; // 设置字体样式 ctx.fillText('打扫', j * cwidth + 30, szi * cheight + 46); } ctx.strokeStyle = "#dcdfe6" ctx.lineWidth = 1 ctx.fillStyle = '#303133'; // 设置文本颜色为黑色 ctx.font = '14px Arial'; // 设置字体样式 this.drawracts1(ctx, j, szi, cwidth, cheight) } else { ctx.strokeStyle = "#dcdfe6" ctx.lineWidth = 1 ctx.fillStyle = '#303133'; // 设置文本颜色为黑色 ctx.font = '14px Arial'; // 设置字体样式 //ctx.strokeRect(j * cwidth, szi * cheight, cwidth, cheight); // 绘制填充后的长方形 this.drawracts1(ctx, j, szi, cwidth, cheight) this.roomstatus(j, szi, 0, 'kong', 0, this.roomstatudes.kong) } } else { ctx.strokeStyle = "#dcdfe6" ctx.lineWidth = 1 ctx.fillStyle = '#303133'; // 设置文本颜色为黑色 ctx.font = '14px Arial'; // 设置字体样式 //ctx.strokeRect(j * cwidth, szi * cheight, cwidth, cheight); // 绘制填充后的长方形 this.drawracts1(ctx, j, szi, cwidth, cheight) this.roomstatus(j, szi, 0, 'kong', 0, this.roomstatudes.kong) } } ctx.stroke(); },
08-06
function setBtcLineK(dataValue) { $('.KchartBox').addClass('onloading') dataValue.forEach(item => { item['value'] = item.closePrice }) let avg = dataValue.length!=0?Number(dataValue[0].closePrice):0 // 渲染 if(echartsBtcK==null){ echartsBtcK = echarts.init($('.echartsBtcK')[0], null, { renderer: 'canvas', useDirtyRect: false }); } let optionBtcK = { tooltip: { trigger: 'axis', axisPointer: { animation: false }, formatter: function (params) { let time = '<h3 style="margin-bottom:14px">' + formateDate(Number(params[0].data.openTime),true)+ '</h3>' let liArr = '' params.forEach(i => { // console.log('111',i.marker); liArr += `<div style="margin-bottom:5px;display:flex;width:200px;align-items:center;"><span style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:#16C784;"></span>${i.seriesName} : <span style="font-weight:600;flex:1;text-align:right;">$${(i.value)}</span></div> <div style="margin-bottom:5px;display:flex;width:200px;align-items:center;"><span style="display:inline-block;margin-right:4px;border-radius:10px;width:10px;height:10px;background-color:#FFB328;"></span>成交量 : <span style="font-weight:600;flex:1;text-align:right;">${i.data.volume}</span></div> ` }) return time + liArr }, textStyle: { color: '#0D1421', fontSize: 14, lineHeight: 15, } }, color: ['#16C784'], legend: { show: false, itemWidth: 12, itemHeight: 12, data: [ { icon: 'roundRect', name: '价格', }, ] }, grid: [ { bottom: '30%', show: false, left: '3%', right: '3%', height: '60%', // containLabel: true }, { left: '3%', right: '3%', top: '80%', height: '16%', }, ], xAxis: [ { type: 'category', scale: true, data: dataValue.map(function (str) { return changeTimeNewShow(Number(str.openTime), true); }), axisLabel: { margin: 17, interval: 'auto', color: '#0D1421', // fontSize:12 }, axisLine: { lineStyle: { color: '#cbcccf', } }, z:1 }, { type: 'category', data: dataValue.map(function (str) { return formateDate(Number(str.openTime), true); }), gridIndex: 1, axisLine: { onZero: false, lineStyle: { color: '#cbcccf', } }, boundaryGap: false, axisTick: { show: false }, splitLine: { show: false }, axisLabel: { show: false }, }, ], yAxis: [ { type: 'value', scale: true, position: 'left', splitLine: { lineStyle: { type: "dashed" } }, axisLabel: { color: '#0D1421', inside: true, verticalAlign :'bottom', formatter: function (value) { // // 使用 toLocaleString 方法格式化数字 return numFormat(Number(value)); } }, }, { scale: true, gridIndex: 1, splitNumber: 2, axisLabel: { show: false }, axisLine: { show: false }, axisTick: { show: false }, splitLine: { show: false } } ], dataZoom: [ { type: 'inside', xAxisIndex: [0, 1], start: 0, end: 100, preventDefaultMouseMove: false, }, ], visualMap: [ { pieces: [ { gt: 0, lte: avg, }, { gt: avg, }, ], inRange: { color:['#EA3943','#16c784'], colorAlpha: 0.8 }, seriesIndex: 0, show: false, }, ], series: [ { name: '价格', type: 'line', smooth: true, showSymbol: false, data: dataValue, markLine: { data: [ {yAxis: avg, lineStyle: {type: 'dashed', color: '#cbcccf'}} ], label: { show: false }, symbol: ['none', 'none'] }, areaStyle: { opacity: .4, origin: avg, // color: 'yellow', } }, { name: '价格', type: 'bar', xAxisIndex: 1, yAxisIndex: 1, data: dataValue, itemStyle: { color: '#EFF1F3' } }, ] } if (optionBtcK && typeof optionBtcK === 'object') { echartsBtcK.setOption(optionBtcK, true) } window.addEventListener('resize', echartsBtcK.resize,true); echartsBtcK.resize() $('.KchartBox').removeClass('onloading') }帮我改写为veu3写法封装成组件
最新发布
08-28
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值