diff --git a/public/CviLux_globalmap.jpg b/public/CviLux_globalmap.jpg new file mode 100644 index 0000000..1c323a1 Binary files /dev/null and b/public/CviLux_globalmap.jpg differ diff --git a/src/views/headquarters/HeadquartersManagement.vue b/src/views/headquarters/HeadquartersManagement.vue index 8b37a85..ea07577 100644 --- a/src/views/headquarters/HeadquartersManagement.vue +++ b/src/views/headquarters/HeadquartersManagement.vue @@ -80,10 +80,16 @@ onUnmounted(() => { 未來,瀚荃會持續精進提供更快、更好以及高附加價值的產品與服務來滿足您的需求。

- + -
+
+ +
{ diff --git a/src/views/headquarters/components/ElecCompare.vue b/src/views/headquarters/components/ElecCompare.vue index 19f7fef..07b0abe 100644 --- a/src/views/headquarters/components/ElecCompare.vue +++ b/src/views/headquarters/components/ElecCompare.vue @@ -5,35 +5,202 @@ import BarChart from "@/components/chart/BarChart.vue"; import { useI18n } from "vue-i18n"; const { locale, t } = useI18n(); -const props = defineProps({ - energyCostData: { - type: Object, - required: true, - }, + +// 假資料 +const fakeEnergyData = ref({ + buildings: [ + { + name: "A棟", + today: 100, + yesterday: 90, + week: 500, + lastWeek: 450, + month: 2000, + lastMonth: 1800, + year: 24000, + lastYear: 22000, + }, + { + name: "B棟", + today: 120, + yesterday: 110, + week: 600, + lastWeek: 550, + month: 2400, + lastMonth: 2200, + year: 28000, + lastYear: 26000, + }, + { + name: "C棟", + today: 80, + yesterday: 70, + week: 400, + lastWeek: 350, + month: 1600, + lastMonth: 1400, + year: 19000, + lastYear: 17000, + }, + { + name: "D棟", + today: 110, + yesterday: 100, + week: 550, + lastWeek: 500, + month: 2200, + lastMonth: 2000, + year: 26000, + lastYear: 24000, + }, + ], }); -const chartData = ref([]); // 初始化為空陣列 - -const labels = computed(() => [ - t("dashboard.today"), - t("dashboard.yesterday"), - t("dashboard.this_week"), - t("dashboard.last_week"), - t("dashboard.this_month"), - t("dashboard.last_month"), - t("dashboard.this_year"), - t("dashboard.last_year"), +const chartData = ref([]); +const currentType = ref({ + name: "today", +}); +const energyTypeList = ref([ + { + title: t("dashboard.daily_relative_change"), + key: "today", + }, + { + title: t("dashboard.weekly_relative_change"), + key: "week", + }, + { + title: t("dashboard.monthly_relative_change"), + key: "month", + }, + { + title: t("dashboard.yearly_relative_change"), + key: "year", + }, ]); + +const labels = computed(() => { + switch (currentType.value.name) { + case "today": + return [t("dashboard.today"), t("dashboard.yesterday")]; + case "week": + return [t("dashboard.this_week"), t("dashboard.last_week")]; + case "month": + return [t("dashboard.this_month"), t("dashboard.last_month")]; + case "year": + return [t("dashboard.this_year"), t("dashboard.last_year")]; + default: + return [t("dashboard.today"), t("dashboard.yesterday")]; + } +}); const barWidth = 30; // Set barWidth -const barChartOptions = ref({ +const barChartOptions = computed(() => ({ xAxis: { type: "category", - data: chartData.value.map((item) => item.category), + data: chartData.value.map((item) => item.name), axisLine: { lineStyle: { color: "#fff" } }, }, yAxis: { type: "value", show: false }, - series: [], // 初始化為空陣列 + grid: { + left: "-10%", + right: "1%", + bottom: "3%", + top: "4%", + containLabel: true, + }, + series: [ + { + name: "當前", + data: chartData.value.map((item) => item.current), + type: "bar", + barWidth: barWidth, + barGap: "-10%", + itemStyle: { + color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ + { offset: 0, color: "#186B80" }, + { offset: 1, color: "#50C3E3" }, + ]), + shadowBlur: 5, + shadowColor: "rgba(0, 0, 0, 0.3)", + shadowOffsetY: 2, + shadowOffsetX: 5, + }, + z: 3, + }, + { + name: "對比", + data: chartData.value.map((item) => item.last), + type: "bar", + barWidth: barWidth, + itemStyle: { + color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ + { offset: 0, color: "#988F2C" }, + { offset: 1, color: "#FFF26D" }, + ]), + shadowBlur: 5, + shadowColor: "rgba(0, 0, 0, 0.3)", + shadowOffsetY: 2, + shadowOffsetX: 5, + }, + }, + { + // this top + z: 6, + type: "pictorialBar", + symbolPosition: "end", + data: chartData.value.map((item) => item.current), + symbol: "diamond", + symbolOffset: ["-45%", "-50%"], + symbolSize: [barWidth, barWidth * 0.5], + itemStyle: { + borderWidth: 0, + color: "#50C3E3", + }, + }, + { + // this bot + z: 6, + type: "pictorialBar", + symbolPosition: "start", + data: chartData.value.map((item) => item.current), + symbol: "diamond", + symbolOffset: ["-45%", "50%"], + symbolSize: [barWidth, barWidth * 0.5], + itemStyle: { + borderWidth: 0, + color: "#50C3E3", + }, + }, + { + // last top + z: 3, + type: "pictorialBar", + symbolPosition: "end", + data: chartData.value.map((item) => item.last), + symbol: "diamond", + symbolOffset: ["45%", "-50%"], + symbolSize: [barWidth, barWidth * 0.5], + itemStyle: { + borderWidth: 0, + color: "#FFF26D", + }, + }, + { + // last bot + z: 3, + type: "pictorialBar", + symbolPosition: "start", + data: chartData.value.map((item) => item.last), + symbol: "diamond", + symbolOffset: ["45%", "50%"], + symbolSize: [barWidth, barWidth * 0.5], + itemStyle: { + borderWidth: 0, + color: "#FFF26D", + }, + }, + ], tooltip: { trigger: "axis", axisPointer: { type: "shadow" }, @@ -49,179 +216,56 @@ const barChartOptions = ref({ return tooltipText; }, }, -}); +})); -function updateChartData(newEnergyCostData) { - if (newEnergyCostData && newEnergyCostData.compare) { - // 從 props.energyCostData.compare 中提取資料 - const compareData = newEnergyCostData.compare; +function updateChartData() { + // 從 fakeEnergyData 提取資料 + chartData.value = fakeEnergyData.value.buildings.map((building) => { + let currentKey = currentType.value.name; + let lastKey; - // 轉換資料格式 - chartData.value = [ - { - category: t("dashboard.daily_relative_change"), - this: compareData.day.current, - last: compareData.day.last, - change: compareData.day.percentage, - }, - { - category: t("dashboard.weekly_relative_change"), - this: compareData.week.current, - last: compareData.week.last, - change: compareData.week.percentage, - }, - { - category: t("dashboard.monthly_relative_change"), - this: compareData.month.current, - last: compareData.month.last, - change: compareData.month.percentage, - }, - { - category: t("dashboard.yearly_relative_change"), - this: compareData.year.current, - last: compareData.year.last, - change: compareData.year.percentage, - }, - ]; + switch (currentType.value.name) { + case "today": + lastKey = "yesterday"; + break; + case "week": + lastKey = "lastWeek"; + break; + case "month": + lastKey = "lastMonth"; + break; + case "year": + lastKey = "lastYear"; + break; + default: + lastKey = "yesterday"; + } - // 更新 barChartOptions - barChartOptions.value = { - xAxis: { - type: "category", - data: chartData.value.map((item) => item.category), - axisLine: { lineStyle: { color: "#fff" } }, - }, - yAxis: { type: "value", show: false }, - grid: { - left: "-10%", - right: "1%", - bottom: "3%", - top: "4%", - containLabel: true, - }, - series: [ - { - name: "當前週期", - data: chartData.value.map((item) => item.this), - type: "bar", - barWidth: barWidth, - barGap: "-10%", - itemStyle: { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { offset: 0, color: "#186B80" }, - { offset: 1, color: "#50C3E3" }, - ]), - shadowBlur: 5, - shadowColor: "rgba(0, 0, 0, 0.3)", - shadowOffsetY: 2, - shadowOffsetX: 5, - }, - z: 3, - }, - { - name: "對比週期", - data: chartData.value.map((item) => item.last), - type: "bar", - barWidth: barWidth, - itemStyle: { - color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ - { offset: 0, color: "#988F2C" }, - { offset: 1, color: "#FFF26D" }, - ]), - shadowBlur: 5, - shadowColor: "rgba(0, 0, 0, 0.3)", - shadowOffsetY: 2, - shadowOffsetX: 5, - }, - }, - { - // this top - z: 6, - type: "pictorialBar", - symbolPosition: "end", - data: chartData.value.map((item) => item.this), - symbol: "diamond", - symbolOffset: ["-45%", "-50%"], - symbolSize: [barWidth, barWidth * 0.5], - itemStyle: { - borderWidth: 0, - color: "#50C3E3", - }, - }, - { - // this bot - z: 6, - type: "pictorialBar", - symbolPosition: "start", - data: chartData.value.map((item) => item.this), - symbol: "diamond", - symbolOffset: ["-45%", "50%"], - symbolSize: [barWidth, barWidth * 0.5], - itemStyle: { - borderWidth: 0, - color: "#50C3E3", - }, - }, - { - // last top - z: 3, - type: "pictorialBar", - symbolPosition: "end", - data: chartData.value.map((item) => item.last), - symbol: "diamond", - symbolOffset: ["45%", "-50%"], - symbolSize: [barWidth, barWidth * 0.5], - itemStyle: { - borderWidth: 0, - color: "#FFF26D", - }, - }, - { - // last bot - z: 3, - type: "pictorialBar", - symbolPosition: "start", - data: chartData.value.map((item) => item.last), - symbol: "diamond", - symbolOffset: ["45%", "50%"], - symbolSize: [barWidth, barWidth * 0.5], - itemStyle: { - borderWidth: 0, - color: "#FFF26D", - }, - }, - ], - tooltip: { - trigger: "axis", - axisPointer: { type: "shadow" }, - formatter: function (params) { - let tooltipText = `
${params[0].axisValueLabel}
`; - const filteredParams = params.filter( - (item) => item.seriesType === "bar" - ); - filteredParams.forEach((item) => { - tooltipText += `
${item.marker} ${ - item.value ? item.value : "-" - }
`; - }); - - return tooltipText; - }, - }, + return { + name: building.name, + current: building[currentKey], + last: building[lastKey], + difference: building[currentKey] - building[lastKey], }; - } + }); } -// 使用 watch 監聽 energyCostData 的變化 + +// 使用 watch 監聽 fakeEnergyData 的變化 watch( - () => props.energyCostData, - (newEnergyCostData) => { - updateChartData(newEnergyCostData); + () => [fakeEnergyData.value, currentType.value], + () => { + updateChartData(); }, - { immediate: true } // 立即執行一次,確保初始資料載入 + { deep: true, immediate: true } // 立即執行一次,確保初始資料載入 ); +// 监听 currentType 的变化 +watch(currentType, () => { + updateChartData(); +}); + watch(locale, () => { - updateChartData(props.energyCostData); + updateChartData(); }); @@ -229,9 +273,20 @@ watch(locale, () => {
-

+

{{ $t("dashboard.relative_energy_consumption") }}

+
{ class="w-1/4 text-center mx-1" >
- {{ labels[index * 2] }} + {{ labels[0] }}
- {{ data.this ?? "-" }} + {{ data.current ?? "-" }}
- {{ labels[index * 2 + 1] }} + {{ labels[1] }}
{ > {{ - data.change - ? (data.change > 0 ? "+" : "") + data.change + "%" + data.difference + ? (data.difference > 0 ? "+" : "") + data.difference : "-" }} diff --git a/src/views/headquarters/components/ElecRank.vue b/src/views/headquarters/components/ElecRank.vue index 232de2a..4d19214 100644 --- a/src/views/headquarters/components/ElecRank.vue +++ b/src/views/headquarters/components/ElecRank.vue @@ -37,7 +37,7 @@ const getCurrentEnergyData = () => {