fix(device-params-config-modal): loading state and data life cycle
This commit is contained in:
@@ -72,7 +72,7 @@ import type { Station } from '@/apis/domains';
|
||||
import { postDefParameterPage, putDefParameter } from '@/apis/requests';
|
||||
import { useQueryControlStore } from '@/stores/query-control';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { NForm, NFormItemGi, NGrid, NInputNumber, NModal, NTabPane, NTabs, NTimePicker } from 'naive-ui';
|
||||
import { NForm, NFormItemGi, NGrid, NInputNumber, NModal, NTabPane, NTabs, NTimePicker, NSpin, NFlex } from 'naive-ui';
|
||||
import { ref, toRefs, watch } from 'vue';
|
||||
|
||||
const props = defineProps<{
|
||||
@@ -134,11 +134,12 @@ const onAfterModalEnter = () => {
|
||||
const onBeforeModalLeave = () => {
|
||||
saveDeviceParams({ tabName: activeTabName.value, params: deviceConfigParams.value });
|
||||
activeTabName.value = DeviceConfigParamPrefix.Switch;
|
||||
deviceConfigParams.value = [];
|
||||
};
|
||||
|
||||
const deviceConfigParams = ref<DeviceParamItem[]>([]);
|
||||
|
||||
const { mutate: getDeviceParams } = useMutation({
|
||||
const { mutate: getDeviceParams, isPending: paramsLoading } = useMutation({
|
||||
mutationFn: async ({ deviceKeyPrefix }: { deviceKeyPrefix: string }) => {
|
||||
if (!station.value) throw new Error('请先选择车站');
|
||||
const { records } = await postDefParameterPage(station.value.code, {
|
||||
@@ -220,7 +221,10 @@ const { mutate: saveDeviceParams } = useMutation({
|
||||
>
|
||||
<NTabs v-model:value="activeTabName" type="card" @before-leave="onBeforeTabLeave">
|
||||
<NTabPane v-for="pane in tabPanes" :key="pane.name" :tab="pane.tab" :name="pane.name">
|
||||
<NForm>
|
||||
<NFlex v-if="paramsLoading" :justify="'center'" :align="'center'">
|
||||
<NSpin :show="paramsLoading" description="加载设备参数中..." />
|
||||
</NFlex>
|
||||
<NForm v-else>
|
||||
<NGrid :cols="1">
|
||||
<NFormItemGi v-for="item in deviceConfigParams" :key="item.key" label-placement="left" :span="1" :label="item.name">
|
||||
<!-- 监视器计划配置渲染时间选择器,其他配置项渲染数字输入框 -->
|
||||
|
||||
Reference in New Issue
Block a user