代码提交

This commit is contained in:
lixiaobang 2024-03-18 13:52:38 +08:00
parent 3a2e9f757b
commit 1921755332
2 changed files with 26 additions and 7 deletions

View File

@ -20,12 +20,12 @@ const dateValues = ref([
// //
function energyCalendar() { function energyCalendar() {
let date = moment(calendarDate.value).format("YYYY-MM"); let date = moment(calendarDate.value).format("YYYY-MM");
let month = moment(calendarDate.value).format("MM") let month = moment(calendarDate.value).format("MM");
getEnergyCalendar({ date }) getEnergyCalendar({ date })
.then((res) => { .then((res) => {
if (res.code == 200) { if (res.code == 200) {
dateValues.value = res.data; dateValues.value = res.data;
getDateValue(date,month) getDateValue(date, month);
} else { } else {
return false; return false;
} }
@ -34,15 +34,29 @@ function energyCalendar() {
console.log(err); console.log(err);
}); });
} }
function getDateValue(date,month) { function getDateValue(date, month) {
let month1 = moment(calendarDate.value).format("MM") let month1 = moment(calendarDate.value).format("MM");
if (dateValues.value != undefined && month == month1) { if (dateValues.value != undefined && month == month1) {
const foundDate = dateValues.value.find((item) => item.time === date); const foundDate = dateValues.value.find((item) => item.time === date);
if (foundDate) { 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(() => { onMounted(() => {
energyCalendar(); energyCalendar();
}); });
@ -80,7 +94,12 @@ onMounted(() => {
<template #date-cell="{ data }"> <template #date-cell="{ data }">
<p class="day">{{ data.day.split("-").slice(1)[1] }}</p> <p class="day">{{ data.day.split("-").slice(1)[1] }}</p>
<p class="value"> <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> </p>
</template> </template>
</el-calendar> </el-calendar>