能源管理: 週報表欄位名稱調整 、 日報表日期與欄位排序
This commit is contained in:
parent
a7ed0340b7
commit
acb1f89b0a
@ -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 對應
|
||||||
|
Loading…
Reference in New Issue
Block a user