diff --git a/src/views/energyManagement/components/EnergyHistoryTable/EnergyActionButton.vue b/src/views/energyManagement/components/EnergyHistoryTable/EnergyActionButton.vue index eff1440..57e91bd 100644 --- a/src/views/energyManagement/components/EnergyHistoryTable/EnergyActionButton.vue +++ b/src/views/energyManagement/components/EnergyHistoryTable/EnergyActionButton.vue @@ -12,7 +12,7 @@ const props = defineProps({ form: Object, }); -const { updateTableData } = inject("energy_table_data"); +const { updateTableData, loading, setLoading } = inject("energy_table_data"); let isToastOpen = ref({ open: false, @@ -30,6 +30,9 @@ const submit = async (e, type = "") => { e?.preventDefault(); e?.stopPropagation(); + // 若正在 loading 則直接阻止再次觸發 + if (loading.value) return; + const formData = new FormData(props.form); let params = {}; @@ -38,39 +41,45 @@ const submit = async (e, type = "") => { params = { ...params, [pair[0]]: pair[1] }; } - if (type === "export") { - const res = await getHistoryExportData({ - ...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, - content: err.msg, - }; - }); - } else { - const res = await getHistoryData({ - ...searchParams.value, - Type: - route.params.type != 1 - ? 2 - : searchParams.value.Type - ? searchParams.value.Type - : 1, - table_type: route.params.type, - }); - updateTableData(res.data); + try { + setLoading(true); + if (type === "export") { + await getHistoryExportData({ + ...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, + content: err.msg, + }; + }); + } else { + const res = await getHistoryData({ + ...searchParams.value, + Type: + route.params.type != 1 + ? 2 + : searchParams.value.Type + ? searchParams.value.Type + : 1, + table_type: route.params.type, + }); + updateTableData(res.data); + } + } finally { + setLoading(false); } }; const isSearchButtonDisabled = computed(() => { + if (loading.value) return true; if ( !searchParams.value.Points?.length || !searchParams.value.Device_list?.length diff --git a/src/views/energyManagement/components/EnergyHistoryTable/EnergyDataTable.vue b/src/views/energyManagement/components/EnergyHistoryTable/EnergyDataTable.vue index ec0aa70..bfd6ace 100644 --- a/src/views/energyManagement/components/EnergyHistoryTable/EnergyDataTable.vue +++ b/src/views/energyManagement/components/EnergyHistoryTable/EnergyDataTable.vue @@ -1,13 +1,13 @@