From ac5c88a047e39e5bbb25222fc1ca5f36664eced8 Mon Sep 17 00:00:00 2001 From: ko1234 Date: Mon, 21 Jul 2025 09:51:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=9F=E5=88=A5=E5=88=A4=E6=96=B7=20|=20=20?= =?UTF-8?q?=E8=83=BD=E6=BA=90=E7=AE=A1=E7=90=86=E5=8C=AF=E5=87=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/history/api.js | 4 ++ src/apis/history/index.js | 63 +++++++++++++++---- src/components/navbar/Navbar.vue | 4 ++ src/components/navbar/NavbarBuilding.vue | 40 ++++++------ src/stores/useBuildingStore.js | 10 +++ .../EnergyHistoryTable/EnergyActionButton.vue | 8 ++- .../components/HistoryActionButton.vue | 23 ++++--- .../history/components/HistorySearch.vue | 1 - 8 files changed, 108 insertions(+), 45 deletions(-) diff --git a/src/apis/history/api.js b/src/apis/history/api.js index 64de717..c5c90fb 100644 --- a/src/apis/history/api.js +++ b/src/apis/history/api.js @@ -4,6 +4,10 @@ export const GET_HISTORY_SIDEBAR_API = `/api/History/GetDeviceInfo`; export const GET_HISTORY_POINT_API = `/api/History/GetAllDevPoi`; export const GET_HISTORY_DATA_API = `/api/History/GetHistoryData`; export const GET_HISTORY_EXPORT_API = `/api/ExportHistoryExcel`; +export const GET_HISTORY_EXPORT_REPORT_API = `/api/History/GetHistoryExcelReport`; +export const GET_HISTORY_EXPORT_CURVE_API = `/api/History/GetHistoricalCurveExcelReport`; +export const GET_HISTORY_EXPORT_QUICK_API = `/api/History/GetQuickMeteringExcelReport`; +export const GET_HISTORY_EXPORT_CLASS_API = `/api/History/GetElectricityClassificationExcelReport`; export const GET_HISTORY_FAVORITE_API = `/api/History/GetHistoryFavorite`; export const POST_HISTORY_FAVORITE_API = `/api/History/SaveHistoryFavorite`; diff --git a/src/apis/history/index.js b/src/apis/history/index.js index c393159..5bc8564 100644 --- a/src/apis/history/index.js +++ b/src/apis/history/index.js @@ -7,6 +7,10 @@ import { DELETE_HISTORY_FAVORITE_API, UPDATE_HISTORY_FAVORITE_API, GET_HISTORY_EXPORT_API, + GET_HISTORY_EXPORT_REPORT_API, + GET_HISTORY_EXPORT_CURVE_API, + GET_HISTORY_EXPORT_QUICK_API, + GET_HISTORY_EXPORT_CLASS_API, } from "./api"; import instance, { fileInstance } from "@/util/request"; import apihandler from "@/util/apiHandler"; @@ -81,7 +85,52 @@ export const getHistoryData = async ({ }; export const getHistoryExportData = async ({ + Start_date, + End_date, + Start_time, + End_time, + Device_list, + Points, Type, + table_type, +}) => { + const api = + parseInt(table_type) === 1 + ? GET_HISTORY_EXPORT_CURVE_API + : parseInt(table_type) === 2 + ? GET_HISTORY_EXPORT_QUICK_API + : parseInt(table_type) === 3 + ? GET_HISTORY_EXPORT_CLASS_API + : GET_HISTORY_EXPORT_API; + + const res = await fileInstance.post( + api, + { + Start_date: Start_date, + End_date: End_date, + Start_time: Start_time, + End_time: End_time, + Points: Array.isArray(Points) ? Points : [Points], + Device_list: Array.isArray(Device_list) ? Device_list : [Device_list], + Type: parseInt(Type), + Building_tag_list: [...new Set(Device_list.map((d) => d.split("_")[1]))], + table_type: parseInt(table_type), + }, + { responseType: "blob" } + ); + + return apihandler( + res.code, + res, + { + msg: res.msg, + code: res.code, + }, + downloadExcel + ); +}; + +export const getHistoryExportReport = async ({ Start_date, End_date, Start_time, @@ -89,19 +138,8 @@ export const getHistoryExportData = async ({ Device_list, Points, }) => { - /* - { - Type, - Start_date, - End_date, - Start_time, - End_time, - Device_list, - Points, - } - */ const res = await fileInstance.post( - GET_HISTORY_EXPORT_API, + GET_HISTORY_EXPORT_REPORT_API, { // ...exportContent, Start_date: Start_date, @@ -110,7 +148,6 @@ export const getHistoryExportData = async ({ End_time: End_time, Points: Array.isArray(Points) ? Points : [Points], Device_list: Array.isArray(Device_list) ? Device_list : [Device_list], - Type: parseInt(Type), Building_tag_list: [...new Set(Device_list.map((d) => d.split("_")[1]))], }, { responseType: "blob" } diff --git a/src/components/navbar/Navbar.vue b/src/components/navbar/Navbar.vue index 6610ac3..19b6e6d 100644 --- a/src/components/navbar/Navbar.vue +++ b/src/components/navbar/Navbar.vue @@ -5,6 +5,8 @@ import NavbarItem from "./NavbarItem.vue"; import NavbarBuilding from "./NavbarBuilding.vue"; import Logo from "@/assets/img/logo.svg"; import useUserInfoStore from "@/stores/useUserInfoStore"; +import useBuildingStore from "@/stores/useBuildingStore"; + import AlarmDrawer from "@/components/alarm/AlarmDrawer.vue"; import NavbarLang from "./NavbarLang.vue"; import { twMerge } from "tailwind-merge"; @@ -14,6 +16,7 @@ const menuShow = ref(true); const router = useRouter(); const store = useUserInfoStore(); +const storeBuilding = useBuildingStore(); onMounted(() => { const name = store.user.user_name; if (name) { @@ -32,6 +35,7 @@ const logout = () => { document.cookie = "user_name=; Max-Age=0"; store.user.token = ""; store.user.user_name = ""; + storeBuilding.deleteBuilding(); router.push({ path: "/login" }); }; diff --git a/src/components/navbar/NavbarBuilding.vue b/src/components/navbar/NavbarBuilding.vue index e6198b1..d36fb9d 100644 --- a/src/components/navbar/NavbarBuilding.vue +++ b/src/components/navbar/NavbarBuilding.vue @@ -14,20 +14,20 @@ onMounted(() => { - diff --git a/src/stores/useBuildingStore.js b/src/stores/useBuildingStore.js index a396bda..feb0623 100644 --- a/src/stores/useBuildingStore.js +++ b/src/stores/useBuildingStore.js @@ -77,6 +77,15 @@ const useBuildingStore = defineStore("buildingInfo", () => { })) || []; }; + // 清除localStorage建築物 + const deleteBuilding = () => { + localStorage.removeItem("CviBuildingList"); + localStorage.removeItem("CviBuilding"); + buildings.value = []; + selectedBuilding.value = null; + } + + // 當 selectedBuilding 改變時,更新 floorList 和 deptList watch(selectedBuilding, async (newBuilding) => { if (newBuilding) { @@ -102,6 +111,7 @@ const useBuildingStore = defineStore("buildingInfo", () => { mainSys, subSys, selectedSystem, + deleteBuilding, fetchBuildings, fetchFloorList, fetchDepartmentList, diff --git a/src/views/energyManagement/components/EnergyHistoryTable/EnergyActionButton.vue b/src/views/energyManagement/components/EnergyHistoryTable/EnergyActionButton.vue index 6c06d2e..eff1440 100644 --- a/src/views/energyManagement/components/EnergyHistoryTable/EnergyActionButton.vue +++ b/src/views/energyManagement/components/EnergyHistoryTable/EnergyActionButton.vue @@ -40,9 +40,15 @@ const submit = async (e, type = "") => { if (type === "export") { const res = await getHistoryExportData({ - type: searchParams.value.selectedType, ...params, ...searchParams.value, + Type: + route.params.type != 1 + ? 2 + : searchParams.value.Type + ? searchParams.value.Type + : 1, + table_type: route.params.type, }).catch((err) => { isToastOpen.value = { open: true, diff --git a/src/views/history/components/HistoryActionButton.vue b/src/views/history/components/HistoryActionButton.vue index 83c5d8b..c5ed9c4 100644 --- a/src/views/history/components/HistoryActionButton.vue +++ b/src/views/history/components/HistoryActionButton.vue @@ -1,6 +1,6 @@