代码提交
This commit is contained in:
parent
3a2e9f757b
commit
1921755332
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue