能源管理 : 歷史table 新增 loading 狀態管理 | 負責廠商: 提交bug修正
This commit is contained in:
parent
5808c8ddc3
commit
0670e596ab
@ -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
|
||||||
|
|||||||
@ -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>
|
||||||
|
|||||||
@ -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>
|
||||||
|
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user