能源管理 : 歷史table 新增 loading 狀態管理 | 負責廠商: 提交bug修正

This commit is contained in:
koko 2025-11-19 14:57:52 +08:00
parent 5808c8ddc3
commit 0670e596ab
4 changed files with 49 additions and 33 deletions

View File

@ -12,7 +12,7 @@ const props = defineProps({
form: Object, form: Object,
}); });
const { updateTableData } = inject("energy_table_data"); const { updateTableData, loading, setLoading } = inject("energy_table_data");
let isToastOpen = ref({ let isToastOpen = ref({
open: false, open: false,
@ -30,6 +30,9 @@ const submit = async (e, type = "") => {
e?.preventDefault(); e?.preventDefault();
e?.stopPropagation(); e?.stopPropagation();
// loading
if (loading.value) return;
const formData = new FormData(props.form); const formData = new FormData(props.form);
let params = {}; let params = {};
@ -38,8 +41,10 @@ const submit = async (e, type = "") => {
params = { ...params, [pair[0]]: pair[1] }; params = { ...params, [pair[0]]: pair[1] };
} }
try {
setLoading(true);
if (type === "export") { if (type === "export") {
const res = await getHistoryExportData({ await getHistoryExportData({
...params, ...params,
...searchParams.value, ...searchParams.value,
Type: Type:
@ -68,9 +73,13 @@ const submit = async (e, type = "") => {
}); });
updateTableData(res.data); updateTableData(res.data);
} }
} finally {
setLoading(false);
}
}; };
const isSearchButtonDisabled = computed(() => { const isSearchButtonDisabled = computed(() => {
if (loading.value) return true;
if ( if (
!searchParams.value.Points?.length || !searchParams.value.Points?.length ||
!searchParams.value.Device_list?.length !searchParams.value.Device_list?.length

View File

@ -1,13 +1,13 @@
<script setup> <script setup>
import Table from "@/components/customUI/Table.vue"; import Table from "@/components/customUI/Table.vue";
import EnergyDataCahrt from "./EnergyDataCahrt.vue"; import EnergyDataCahrt from "./EnergyDataCahrt.vue";
import { inject, computed, watch, ref, onMounted } from "vue"; import { inject, computed, watch, ref } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
const { t } = useI18n(); const { t } = useI18n();
const route = useRoute(); const route = useRoute();
const { tableData } = inject("energy_table_data"); const { tableData, loading } = inject("energy_table_data");
const routeType = ref(1); const routeType = ref(1);
const processedTableData = ref([]); // 使 ref const processedTableData = ref([]); // 使 ref
@ -160,7 +160,7 @@ watch(
</script> </script>
<template> <template>
<Table :columns="columns" :dataSource="processedTableData"> <Table :columns="columns" :dataSource="processedTableData" :loading="loading">
<template #beforeTable> <template #beforeTable>
<EnergyDataCahrt v-if="route.params.type == 1" class="mb-10" /> <EnergyDataCahrt v-if="route.params.type == 1" class="mb-10" />
</template> </template>

View File

@ -9,9 +9,13 @@ const tableData = ref([]);
const deptData = ref([]); const deptData = ref([]);
const elecType = ref([]); const elecType = ref([]);
const subSystem = ref(null); const subSystem = ref(null);
const loading = ref(false);
const updateTableData = (data) => { const updateTableData = (data) => {
tableData.value = data ? data : []; tableData.value = data ? data : [];
}; };
const setLoading = (val) => {
loading.value = !!val;
};
provide("energy_table_data", { provide("energy_table_data", {
tableData, tableData,
@ -19,6 +23,8 @@ provide("energy_table_data", {
deptData, deptData,
elecType, elecType,
subSystem, subSystem,
loading,
setLoading,
}); });
</script> </script>

View File

@ -38,6 +38,7 @@ const onCancel = () => {
const onOk = async () => { const onOk = async () => {
const value = await handleSubmit(deptScheme, props.formState); const value = await handleSubmit(deptScheme, props.formState);
let res;
if (props.formState?.id) { if (props.formState?.id) {
res = await updateOperationCompany(value); res = await updateOperationCompany(value);
} else { } else {