diff --git a/src/apis/asset/api.js b/src/apis/asset/api.js index ed19b27..c65b683 100644 --- a/src/apis/asset/api.js +++ b/src/apis/asset/api.js @@ -26,3 +26,5 @@ export const POST_ASSET_DEPARTMENT_API = `/AssetManage/SaveDepartment`; export const DELETE_ASSET_DEPARTMENT_API = `/AssetManage/DeleteDepartment`; export const GET_ASSET_ELECTYPE_API = `/AssetManage/GetElecType`; +export const POST_ASSET_ELECTYPE_API = `/AssetManage/SaveElecType`; +export const DELETE_ASSET_ELECTYPE_API = `/AssetManage/DeleteElecType`; diff --git a/src/apis/asset/index.js b/src/apis/asset/index.js index 7307466..7b05cc5 100644 --- a/src/apis/asset/index.js +++ b/src/apis/asset/index.js @@ -19,6 +19,8 @@ import { POST_ASSET_DEPARTMENT_API, DELETE_ASSET_DEPARTMENT_API, GET_ASSET_ELECTYPE_API, + POST_ASSET_ELECTYPE_API, + DELETE_ASSET_ELECTYPE_API } from "./api"; import instance from "@/util/request"; import apihandler from "@/util/apihandler"; @@ -246,6 +248,27 @@ export const deleteDepartmentItem = async (id) => { export const getElecTypeList = async () => { const res = await instance.post(GET_ASSET_ELECTYPE_API, {}); + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + }); +}; + +export const postElecTypeList = async ({ name, id }) => { + const res = await instance.post(POST_ASSET_ELECTYPE_API, { + name, + id, + }); + + return apihandler(res.code, res.data, { + msg: res.msg, + code: res.code, + }); +}; + +export const deleteElecTypeItem = async (id) => { + const res = await instance.post(DELETE_ASSET_ELECTYPE_API, { id }); + 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 d9a94ba..6db5bbe 100644 --- a/src/apis/energy/api.js +++ b/src/apis/energy/api.js @@ -2,8 +2,9 @@ export const GET_REALTIME_DIST_API = `/api/Energe/GetRealTimeDistribution`; export const GET_ELECUSE_DAY_API = `/api/Energe/GetElecUseDay`; export const GET_TAI_POWER_API = `/api/Energe/GetTaipower`; -export const GET_SIDEBAR_API = `/api/Energe/GetEnergySideBar`; +export const GET_SIDEBAR_API = `/api/GetSideBar`; export const GET_SEARCH_API = `/api/Energe/GetFilter`; export const GET_REPORT_API = `/api/Energe/GetReport`; +export const GET_Excel_API = `/api/Energe/GetReportExcel`; diff --git a/src/apis/energy/index.js b/src/apis/energy/index.js index a615b03..604631d 100644 --- a/src/apis/energy/index.js +++ b/src/apis/energy/index.js @@ -5,9 +5,11 @@ import { GET_SIDEBAR_API, GET_SEARCH_API, GET_REPORT_API, + GET_Excel_API, } from "./api"; -import instance from "@/util/request"; +import instance, { fileInstance } from "@/util/request"; import apihandler from "@/util/apihandler"; +import downloadExcel from "@/util/downloadExcel"; export const getRealTimeDist = async () => { const res = await instance.post(GET_REALTIME_DIST_API); @@ -36,8 +38,8 @@ export const getTaipower = async () => { }); }; -export const getEnergySideBar = async () => { - const res = await instance.post(GET_SIDEBAR_API); +export const getSideBar = async (system_type) => { + const res = await instance.post(GET_SIDEBAR_API, { system_type }); return apihandler(res.code, res.data, { msg: res.msg, @@ -76,3 +78,35 @@ export const getReport = async ({ code: res.code, }); }; + +export const getExcel = async ({ + department, + elecType, + floor, + start_time, + end_time, + type, +}) => { + const res = await fileInstance.post( + GET_Excel_API, + { + department, + elecType, + floor, + start_time, + end_time, + type, + }, + { responseType: "blob" } + ); + + return apihandler( + res.code, + res, + { + msg: res.msg, + code: res.code, + }, + downloadExcel + ); +}; diff --git a/src/components/navbar/NavbarItem.vue b/src/components/navbar/NavbarItem.vue index 7a88fba..4b8a892 100644 --- a/src/components/navbar/NavbarItem.vue +++ b/src/components/navbar/NavbarItem.vue @@ -2,7 +2,7 @@ import { onMounted, ref, watch, computed } from "vue"; import { AUTHPAGES } from "@/constant"; import { getAuth, getAllSysSidebar } from "@/apis/building"; -import { getEnergySideBar } from "@/apis/energy"; +import { getSideBar } from "@/apis/energy"; import useBuildingStore from "@/stores/useBuildingStore"; import useUserInfoStore from "@/stores/useUserInfoStore"; import { useI18n } from "vue-i18n"; @@ -42,15 +42,15 @@ const getSubMonitorPage = async (building) => { buildingStore.mainSubSys = res.data.history_Main_Systems; menu_array.value = res.data.history_Main_Systems; }; -const getSubEnergyPage = async () => { - const res = await getEnergySideBar(); +const getSubPage = async (system_type) => { + const res = await getSideBar(system_type); menu_array.value = res.data; }; const showDrawer = (authCode) => { if (authCode === "PF1") { getSubMonitorPage(); - } else if (authCode === "PF2") { - getSubEnergyPage(); + } else if (authCode === "PF2" || authCode === "PF11") { + getSubPage(authCode === "PF2" ? "Energy" : "Setting"); } currentAuthCode.value = authCode; open.value = true; @@ -105,7 +105,11 @@ onMounted(() => { :key="page.authCode" > diff --git a/src/constant/authPage.js b/src/constant/authPage.js index cd22406..956d94f 100644 --- a/src/constant/authPage.js +++ b/src/constant/authPage.js @@ -61,4 +61,10 @@ export const AUTHPAGES = [ pageName: "ProductSetting", navigate: "/productSetting", }, + { + authCode: "PF11", + icon: "cog", + pageName: "Setting", + navigate: "/Setting", + }, ]; diff --git a/src/router/index.js b/src/router/index.js index a545930..36f5941 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -8,6 +8,7 @@ import AssetManagement from "@/views/AssetManagement/AssetManagement.vue"; import AlertManagement from "@/views/alert/AlertManagement.vue"; import ProductSetting from "@/views/productSetting/ProductSetting.vue"; import EnergyManagement from "@/views/energyManagement/EnergyManagement.vue"; +import SettingManagement from "@/views/setting/SettingManagement.vue"; import Login from "@/views/login/Login.vue"; import useUserInfoStore from "@/stores/useUserInfoStore"; import useGetCookie from "@/hooks/useGetCookie"; @@ -84,6 +85,11 @@ const router = createRouter({ name: "energyManagement", component: EnergyManagement, }, + { + path: "/setting/:main_system_id/:sub_system_id/:type", + name: "setting", + component: SettingManagement, + }, { path: "/mytestfile/mjm", name: "mytestfile", diff --git a/src/views/AssetManagement/AssetManagement.vue b/src/views/AssetManagement/AssetManagement.vue index 3ed310d..beaaa18 100644 --- a/src/views/AssetManagement/AssetManagement.vue +++ b/src/views/AssetManagement/AssetManagement.vue @@ -4,12 +4,14 @@ import AssetMainList from "./components/AssetMainList.vue"; import AssetSubList from "./components/AssetSubList.vue"; import AssetTable from "./components/AssetTable.vue"; import { getOperationCompanyList } from "@/apis/operation"; -import { getIOTSchema, getElecTypeList } from "@/apis/asset"; +import { getDepartmentList, getIOTSchema, getElecTypeList, getAssetFloorList } from "@/apis/asset"; import useSearchParam from "@/hooks/useSearchParam"; const { searchParams, changeParams } = useSearchParam(); const companyOptions = ref([]); const iotSchemaOptions = ref([]); const elecTypeOptions = ref([]); +const departmentList = ref([]); +const floors = ref([]); const getCompany = async () => { const res = await getOperationCompanyList(); companyOptions.value = res.data.map((d) => ({ ...d, key: d.id })); @@ -22,10 +24,20 @@ const getElecType = async () => { const res = await getElecTypeList(); elecTypeOptions.value = res.data.map((d) => ({ ...d, key: d.id })); }; +const getDepartment = async () => { + const res = await getDepartmentList(); + departmentList.value = res.data.map((d) => ({ ...d, key: d.id })); +}; +const getFloors = async () => { + const res = await getAssetFloorList(); + floors.value = res.data[0]?.floors.map((d) => ({ ...d, key: d.floor_guid })); +}; onMounted(() => { getCompany(); getElecType(); + getDepartment(); + getFloors(); }); watch( @@ -44,6 +56,8 @@ provide("asset_modal_options", { companyOptions, iotSchemaOptions, elecTypeOptions, + departmentList, + floors, }); diff --git a/src/views/AssetManagement/components/AssetSubListAddModal.vue b/src/views/AssetManagement/components/AssetSubListAddModal.vue index de8be04..665ea00 100644 --- a/src/views/AssetManagement/components/AssetSubListAddModal.vue +++ b/src/views/AssetManagement/components/AssetSubListAddModal.vue @@ -15,6 +15,9 @@ const props = defineProps({ }); const mainSystem = ref([]); +const updateFileList = (files) => { + formState.value.icon = files; +}; const getMainSystems = async () => { const res = await getAssetMainList(); mainSystem.value = res.data.map((d) => ({ ...d, key: d.id })); @@ -33,6 +36,7 @@ const formState = ref({ system_key: "", system_value: "", system_parent_id: 0, + icon: [], }); const resetForm = () => { @@ -40,6 +44,7 @@ const resetForm = () => { system_key: "", system_value: "", system_parent_id: 0, + icon: [], }; }; @@ -120,6 +125,15 @@ const onOk = async () => { + + + - +
+ +
import { onMounted, ref, inject, onBeforeMount, watch, computed } from "vue"; import EffectScatter from "@/components/chart/EffectScatter.vue"; -import { - getAssetFloorList, - postAssetFloor, - deleteAssetFloor, -} from "@/apis/asset"; -import useFormErrorMessage from "@/hooks/useFormErrorMessage"; import useBuildingStore from "@/stores/useBuildingStore"; import * as yup from "yup"; import { twMerge } from "tailwind-merge"; import { useI18n } from "vue-i18n"; const { t } = useI18n(); -const { openToast, cancelToastOpen } = inject("app_toast"); const FILE_BASEURL = import.meta.env.VITE_FILE_API_BASEURL; const { totalCoordinates } = inject("asset_table_data"); +const { floors } = inject("asset_modal_options"); const { updateRightFields, formErrorMsg, formState } = inject( "asset_table_modal_form" ); @@ -34,7 +28,6 @@ onBeforeMount(() => { const asset_floor_chart = ref(null); const currentFloor = ref(null); -const selectedOption = ref("add"); const parsedCoordinates = ref(null); const defaultOption = (map, data = []) => { @@ -45,7 +38,10 @@ const defaultOption = (map, data = []) => { name: coordString, value: coordinate, itemStyle: { - color: coordString === formState.value.device_coordinate ? "#0000FF" : "#b02a02", + color: + coordString === formState.value.device_coordinate + ? "#0000FF" + : "#b02a02", }, }; }); @@ -75,13 +71,14 @@ const defaultOption = (map, data = []) => { watch(currentFloor, (newValue) => { if (newValue?.floor_map_name) { const coordinates = - (totalCoordinates.value?.[newValue.floor_guid]?.filter( + totalCoordinates.value?.[newValue.floor_guid]?.filter( (coord) => coord !== "" - ) || []); + ) || []; - parsedCoordinates.value = coordinates.length > 0 - ? coordinates.map((coord) => JSON.parse(coord)) - : []; + parsedCoordinates.value = + coordinates.length > 0 + ? coordinates.map((coord) => JSON.parse(coord)) + : []; asset_floor_chart.value.updateSvg( { @@ -92,12 +89,6 @@ watch(currentFloor, (newValue) => { ); } }); -const floors = ref([]); - -const getFloors = async () => { - const res = await getAssetFloorList(); - floors.value = res.data[0]?.floors.map((d) => ({ ...d, key: d.floor_guid })); -}; watch( formState, @@ -120,136 +111,31 @@ const getCoordinate = (position) => { formState.value.device_coordinate = JSON.stringify(position); }; -onMounted(() => { - getFloors(); -}); - -// modal -const openModal = () => { - if (selectedOption.value === "add") { - FloorFormState.value = { - full_name: "", - floorFile: [], - }; - } else if (selectedOption.value === "edit") { - const floor = floors.value.find( - (f) => f.floor_guid === formState.value.floor_guid - ); - if (floor) { - console.log("floor", floor); - FloorFormState.value = { - full_name: floor.full_name, - floorFile: [], - }; - } - } - asset_add_floor.showModal(); -}; - -const form = ref(null); -const FloorFormState = ref({ - full_name: "", - floorFile: [], -}); - -const floorScheme = yup.object({ - full_name: yup.string().required(t("button.required")), - floorFile: yup.array(), -}); - -const updateFileList = (files) => { - console.log("file", files); - FloorFormState.value.floorFile = files; -}; - -const { - formErrorMsg: floorFormErrorMsg, - handleSubmit, - handleErrorReset, - updateScheme, -} = useFormErrorMessage(floorScheme); -const onOk = async () => { - const value = handleSubmit(floorScheme, FloorFormState.value); - const formData = new FormData(form.value); - formData.append("floor_guid", selectedOption.value === "add" ? null :currentFloor.value.floor_guid); - formData.append("building_tag", store.selectedBuilding.building_tag); - formData.append("initMapName", FloorFormState.value.floorFile[0]?.name); - formData.append("mapFile", FloorFormState.value.floorFile[0]); - formData.delete("floorFile"); - for (let [key, value] of formData) { - console.log(key, value); - } - - const res = await postAssetFloor(formData); - if (res.isSuccess) { - getFloors(); - onCancel(); - } -}; -const onDelete = async () => { - openToast("warning", t("msg.sure_to_delete"), "#asset_add_table_item", async () => { - await cancelToastOpen(); - const res = await deleteAssetFloor({ - floor_guid: formState.value.floor_guid, - }); - if (res.isSuccess) { - getFloors(); - openToast("success", t("msg.delete_success"), "#asset_add_table_item"); - } else { - openToast("error", res.msg, "#asset_add_table_item"); - } - }); -}; - -const onCancel = () => { - FloorFormState.value = { - full_name: "", - floorFile: [], - }; - asset_add_floor.close(); -}; -