能源管理: 週報表欄位名稱調整 、 日報表日期與欄位排序

This commit is contained in:
koko 2025-07-28 13:11:34 +08:00
parent a7ed0340b7
commit acb1f89b0a

View File

@ -35,9 +35,23 @@ const columns = computed(() => {
if (tableData.value && tableData.value.length > 0) { if (tableData.value && tableData.value.length > 0) {
const firstDataItem = tableData.value[0]; const firstDataItem = tableData.value[0];
if (firstDataItem && firstDataItem.data) { if (firstDataItem && firstDataItem.data) {
firstDataItem.data.forEach((item, index) => {
const sortedData = [...firstDataItem.data].sort((a, b) =>
dayjs(a.time).valueOf() - dayjs(b.time).valueOf()
);
sortedData.forEach((item, index) => {
let formatString = "MM/DD"; // let formatString = "MM/DD"; //
switch (route.params.type) { switch (route.params.type) {
case "1":
formatString = "MM/DD";
break;
case "2":
//
const startOfWeek = dayjs(item.time).startOf('week');
const endOfWeek = dayjs(item.time).endOf('week');
formatString = `${startOfWeek.format("MM/DD")}-${endOfWeek.format("MM/DD")}`;
break;
case "3": case "3":
formatString = "YYYY/MM"; formatString = "YYYY/MM";
break; break;
@ -45,7 +59,7 @@ const columns = computed(() => {
formatString = "YYYY"; formatString = "YYYY";
break; break;
default: default:
formatString = "MM/DD"; // case 1 case 2 "MM-DD" formatString = "MM/DD ";
break; break;
} }
const formattedTime = dayjs(item.time).format(formatString); const formattedTime = dayjs(item.time).format(formatString);
@ -73,8 +87,13 @@ const dataSource = computed(() => {
return tableData.value.map((item) => { return tableData.value.map((item) => {
let subtotalValue = 0; let subtotalValue = 0;
const newData = {}; // data 便 Table const newData = {}; // data 便 Table
if (item.data && item.data.length > 0) {
item.data.forEach((dataItem, index) => { const sortedData = [...item.data].sort((a, b) =>
dayjs(a.time).valueOf() - dayjs(b.time).valueOf()
);
if (sortedData && sortedData.length > 0) {
sortedData.forEach((dataItem, index) => {
const value = parseFloat(dataItem.value || 0); const value = parseFloat(dataItem.value || 0);
subtotalValue += value; subtotalValue += value;
// newData key columns key // newData key columns key