代码提交
This commit is contained in:
parent
3a2e9f757b
commit
1921755332
|
@ -20,12 +20,12 @@ const dateValues = ref([
|
|||
//能耗日历
|
||||
function energyCalendar() {
|
||||
let date = moment(calendarDate.value).format("YYYY-MM");
|
||||
let month = moment(calendarDate.value).format("MM")
|
||||
let month = moment(calendarDate.value).format("MM");
|
||||
getEnergyCalendar({ date })
|
||||
.then((res) => {
|
||||
if (res.code == 200) {
|
||||
dateValues.value = res.data;
|
||||
getDateValue(date,month)
|
||||
getDateValue(date, month);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -34,15 +34,29 @@ function energyCalendar() {
|
|||
console.log(err);
|
||||
});
|
||||
}
|
||||
function getDateValue(date,month) {
|
||||
let month1 = moment(calendarDate.value).format("MM")
|
||||
function getDateValue(date, month) {
|
||||
let month1 = moment(calendarDate.value).format("MM");
|
||||
if (dateValues.value != undefined && month == month1) {
|
||||
const foundDate = dateValues.value.find((item) => item.time === date);
|
||||
if (foundDate) {
|
||||
return foundDate ? foundDate.EH : "";
|
||||
return foundDate ? formatNumber(Number(foundDate.EH)) : "";
|
||||
}
|
||||
}
|
||||
}
|
||||
//保留两位小数点
|
||||
function formatNumber(num) {
|
||||
if (typeof num === "number" && !isNaN(num)) {
|
||||
// 确认输入参数为有效的数字
|
||||
if (Number.isInteger(num)) {
|
||||
return num; // 若是整数不做操作
|
||||
} else {
|
||||
return Number.parseFloat(num).toFixed(2); // 若是小数转换为浮点数并保留两位小数
|
||||
}
|
||||
} else {
|
||||
throw new Error("Invalid input"); // 非法输入时抛出错误
|
||||
}
|
||||
}
|
||||
//初始化执行能耗日历
|
||||
onMounted(() => {
|
||||
energyCalendar();
|
||||
});
|
||||
|
@ -80,7 +94,12 @@ onMounted(() => {
|
|||
<template #date-cell="{ data }">
|
||||
<p class="day">{{ data.day.split("-").slice(1)[1] }}</p>
|
||||
<p class="value">
|
||||
{{ getDateValue(data.day.split("-").slice(1)[1],data.day.split("-").slice(1)[0])}}
|
||||
{{
|
||||
getDateValue(
|
||||
data.day.split("-").slice(1)[1],
|
||||
data.day.split("-").slice(1)[0]
|
||||
)
|
||||
}}
|
||||
</p>
|
||||
</template>
|
||||
</el-calendar>
|
||||
|
|
Loading…
Reference in New Issue