diff --git a/src/apis/alert/index.js b/src/apis/alert/index.js index edce98d..8e279e8 100644 --- a/src/apis/alert/index.js +++ b/src/apis/alert/index.js @@ -65,8 +65,12 @@ export const postOperationRecord = async (formData) => { }); }; -export const getAlertSubList = async () => { - const res = await instance.post(GET_ALERT_SUB_LIST_API, {}); +export const getAlertSubList = async ( + building_guid +) => { + const res = await instance.post(GET_ALERT_SUB_LIST_API, { + building_guid + }); return apihandler(res.code, res.data, { msg: res.msg, diff --git a/src/apis/asset/index.js b/src/apis/asset/index.js index 12a3dc1..e124482 100644 --- a/src/apis/asset/index.js +++ b/src/apis/asset/index.js @@ -31,8 +31,8 @@ import instance from "@/util/request"; import apihandler from "@/util/apihandler"; import { object } from "yup"; -export const getAssetMainList = async () => { - const res = await instance.post(GET_ASSET_MAIN_LIST_API); +export const getAssetMainList = async (building_guid) => { + const res = await instance.post(GET_ASSET_MAIN_LIST_API,{building_guid}); return apihandler(res.code, res.data, { msg: res.msg, @@ -49,11 +49,12 @@ export const deleteAssetMainItem = async (id) => { }); }; -export const postAssetMainList = async ({ id, system_key, system_value }) => { +export const postAssetMainList = async ({ id, system_key, system_value, building_guid }) => { const res = await instance.post(POST_ASSET_MAIN_LIST_API, { id, system_key, system_value, + building_guid }); return apihandler(res.code, res.data, { @@ -71,18 +72,8 @@ export const getAssetSubList = async (id) => { }); }; -export const postAssetSubList = async ({ - system_key, - system_value, - system_parent_id, - id, -}) => { - const res = await instance.post(POST_ASSET_SUB_LIST_API, { - system_key, - system_value, - system_parent_id, - id, - }); +export const postAssetSubList = async (formData) => { + const res = await instance.post(POST_ASSET_SUB_LIST_API, formData); return apihandler(res.code, res.data, { msg: res.msg, diff --git a/src/apis/building/index.js b/src/apis/building/index.js index 559820b..0c3579e 100644 --- a/src/apis/building/index.js +++ b/src/apis/building/index.js @@ -49,10 +49,8 @@ export const getAuth = async (lang) => { }); }; -export const getAllSysSidebar = async () => { - const res = await instance.post(GET_SUBAUTHPAGE_API, { - building_tag: "", - }); +export const getAllSysSidebar = async (building_guid) => { + const res = await instance.post(GET_SUBAUTHPAGE_API, {building_guid}); return apihandler(res.code, res.data, { msg: res.msg, code: res.code, diff --git a/src/apis/energy/api.js b/src/apis/energy/api.js index b10f171..9f427a0 100644 --- a/src/apis/energy/api.js +++ b/src/apis/energy/api.js @@ -12,6 +12,7 @@ export const GET_Excel_API = `/api/Energe/GetReportExcel`; export const GET_DEMAND_API = `/api/Energe/SearchDemandValue`; export const POST_ADD_DEMAND_API = `/api/Energe/AddDemandValue`; export const POST_EDIT_DEMAND_API = `/api/Energe/UpdateDemandValue`; +export const GET_REALTIME_DEMAND_API = `/api/Energe/GetRealTimeDemand`; // 碳排係數 export const GET_CARBON_API = `/api/Energe/SearchCarbonValue`; diff --git a/src/apis/energy/index.js b/src/apis/energy/index.js index 7bb4eba..1e7057c 100644 --- a/src/apis/energy/index.js +++ b/src/apis/energy/index.js @@ -8,6 +8,7 @@ import { GET_Excel_API, GET_DEMAND_API, POST_EDIT_DEMAND_API, + GET_REALTIME_DEMAND_API, GET_CARBON_API, POST_EDIT_CARBON_API, GET_TIME_ELEC_API, @@ -199,6 +200,15 @@ export const postEditCarbonValue = async ({ }); }; +export const getRealTimeDemand = async (building_guid) => { + const res = await instance.post(GET_REALTIME_DEMAND_API, { building_guid }); + + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + }); +}; + export const getTimeElec = async (building_guid) => { const res = await instance.post(GET_TIME_ELEC_API, { building_guid }); diff --git a/src/apis/system/index.js b/src/apis/system/index.js index 4810014..900ac6d 100644 --- a/src/apis/system/index.js +++ b/src/apis/system/index.js @@ -20,13 +20,13 @@ export const getSystemFloors = async (building_tag, sub_system_tag) => { export const getSystemDevices = async ({ sub_system_tag, - building_tag, - floor_tag, + building_guid, + department_id_list, }) => { const res = await instance.post(GET_SYSTEM_DEVICE_LIST_API, { sub_system_tag, - building_tag, - floor_tag, + building_guid, + department_id_list, }); return apihandler(res.code, res.data, { diff --git a/src/components/navbar/NavbarItem.vue b/src/components/navbar/NavbarItem.vue index 2ad7d4b..245aa17 100644 --- a/src/components/navbar/NavbarItem.vue +++ b/src/components/navbar/NavbarItem.vue @@ -37,8 +37,8 @@ const authPages = computed(() => ); const open = ref(false); -const getSubMonitorPage = async (building) => { - const res = await getAllSysSidebar(); +const getSubMonitorPage = async (building_guid) => { + const res = await getAllSysSidebar(building_guid); buildingStore.mainSubSys = res.data.history_Main_Systems; menu_array.value = res.data.history_Main_Systems; }; @@ -48,7 +48,7 @@ const getSubPage = async (system_type) => { }; const showDrawer = async (authCode) => { if (authCode === "PF1") { - await getSubMonitorPage(); + await getSubMonitorPage(buildingStore.selectedBuilding.building_guid); } else if (authCode === "PF2" || authCode === "PF11") { await getSubPage(authCode === "PF2" ? "Energy" : "Setting"); } @@ -71,7 +71,7 @@ watch( () => buildingStore.selectedBuilding, (newVal) => { if (newVal !== null) { - getSubMonitorPage(newVal.building_tag); + getSubMonitorPage(newVal.building_guid); } } ); diff --git a/src/views/AssetManagement/components/AssetMainList.vue b/src/views/AssetManagement/components/AssetMainList.vue index 85e96cf..7fdfb49 100644 --- a/src/views/AssetManagement/components/AssetMainList.vue +++ b/src/views/AssetManagement/components/AssetMainList.vue @@ -5,6 +5,8 @@ import { ref, onMounted, watch, inject } from "vue"; import useSearchParam from "@/hooks/useSearchParam"; import useActiveBtn from "@/hooks/useActiveBtn"; import { useI18n } from "vue-i18n"; +import useBuildingStore from "@/stores/useBuildingStore"; +const store = useBuildingStore(); const { t } = useI18n(); const { searchParams, changeParams } = useSearchParam(); const { items, changeActiveBtn, setItems, selectedBtn } = useActiveBtn(); @@ -17,7 +19,7 @@ const formState = ref({ }); const getMainSystems = async () => { - const res = await getAssetMainList(); + const res = await getAssetMainList(store.selectedBuilding.building_guid); const cate = res.data.map((d, index) => ({ ...d, title: d.system_key, @@ -60,9 +62,15 @@ const deleteItem = async (id) => { }); }; -onMounted(() => { - getMainSystems(); -}); +watch( + () => store.selectedBuilding, + (newBuilding) => { + if (newBuilding) { + getMainSystems(); + } + }, + { immediate: true } +); watch(selectedBtn, (newValue) => { changeParams({ diff --git a/src/views/AssetManagement/components/AssetMainListAddModal.vue b/src/views/AssetManagement/components/AssetMainListAddModal.vue index 7d01386..6804bf6 100644 --- a/src/views/AssetManagement/components/AssetMainListAddModal.vue +++ b/src/views/AssetManagement/components/AssetMainListAddModal.vue @@ -3,8 +3,11 @@ import { ref, defineProps, inject } from "vue"; import * as yup from "yup"; import useFormErrorMessage from "@/hooks/useFormErrorMessage"; import { postAssetMainList } from "@/apis/asset"; +import useBuildingStore from "@/stores/useBuildingStore"; import useSearchParam from "@/hooks/useSearchParam"; import { useI18n } from "vue-i18n"; + +const storeBuild = useBuildingStore(); const { t } = useI18n(); const { openToast } = inject("app_toast"); const { searchParams, changeParams } = useSearchParam(); @@ -30,6 +33,7 @@ const onOk = async () => { const res = await postAssetMainList({ ...props.formState, id: props.formState ? props.formState.id : 0, + building_guid:storeBuild.selectedBuilding?.building_guid || null, }); if (res.isSuccess) { diff --git a/src/views/AssetManagement/components/AssetSubList.vue b/src/views/AssetManagement/components/AssetSubList.vue index c6908e7..ea7e847 100644 --- a/src/views/AssetManagement/components/AssetSubList.vue +++ b/src/views/AssetManagement/components/AssetSubList.vue @@ -45,21 +45,41 @@ watch( deep: true, } ); +const formState = ref({ + id: 0, + system_key: "", + system_value: "", + system_parent_id: 0, + file: [], +}); -const editRecord = ref(null); -// 編輯 modal -const openModal = () => { + + +const openModal = (item) => { + if (item.id) { + formState.value = { ...item }; + + if (item.device_image) { + const subFile = item + ? { + name: item.device_image, + src: item.device_image, + ext: item.device_image?.split(".")[1], + } + : {}; + formState.value.file = [subFile]; + } + } else { + formState.value = { + id: 0, + system_key: "", + system_value: "", + system_parent_id: 0, + file: [], + }; + } asset_add_sub_item.showModal(); }; -const onCancel = () => { - editRecord.value = null; - asset_add_sub_item.close(); -}; - -const edit = (item) => { - editRecord.value = item; - openModal(); -}; const deleteItem = async (id) => { openToast("warning", t("msg.sure_to_delete"), "body", async () => { @@ -83,9 +103,8 @@ const deleteItem = async (id) => {