fix: stablize station select options
This commit is contained in:
@@ -35,7 +35,16 @@ export function useStationListQuery() {
|
|||||||
online: pingResultList[index].status === 'fulfilled',
|
online: pingResultList[index].status === 'fulfilled',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
stationList.value.splice(0, stationList.value.length, ...stations);
|
const isSame =
|
||||||
|
stationList.value.length === stations.length &&
|
||||||
|
stationList.value.every((oldStation, index) => {
|
||||||
|
const newStation = stations[index];
|
||||||
|
return oldStation.code === newStation.code && oldStation.name === newStation.name && oldStation.deviceIdPrefix === newStation.deviceIdPrefix && oldStation.online === newStation.online;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!isSame) {
|
||||||
|
stationList.value.splice(0, stationList.value.length, ...stations);
|
||||||
|
}
|
||||||
|
|
||||||
updatedTime.value = dayjs().toJSON();
|
updatedTime.value = dayjs().toJSON();
|
||||||
|
|
||||||
|
|||||||
@@ -10,26 +10,11 @@ import dayjs from 'dayjs';
|
|||||||
import type { DataTableColumns, DataTableRowData, PaginationProps, SelectOption } from 'naive-ui';
|
import type { DataTableColumns, DataTableRowData, PaginationProps, SelectOption } from 'naive-ui';
|
||||||
import { NForm, NInput, NButton, NSpace, NDataTable, NFormItemGi, NGrid, NSelect, NGridItem, NDatePicker } from 'naive-ui';
|
import { NForm, NInput, NButton, NSpace, NDataTable, NFormItemGi, NGrid, NSelect, NGridItem, NDatePicker } from 'naive-ui';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { ref, reactive, onBeforeMount, h, shallowRef, watch, computed } from 'vue';
|
import { ref, reactive, onBeforeMount, h, computed } from 'vue';
|
||||||
|
|
||||||
const stationStore = useStationStore();
|
const stationStore = useStationStore();
|
||||||
const { stationList } = storeToRefs(stationStore);
|
const { stationList } = storeToRefs(stationStore);
|
||||||
|
|
||||||
// const stationSelectOptions = shallowRef<SelectOption[]>([]);
|
|
||||||
// watch(
|
|
||||||
// stationList,
|
|
||||||
// (list) => {
|
|
||||||
// const next = list.map<SelectOption>((station) => ({
|
|
||||||
// label: station.name,
|
|
||||||
// value: station.deviceIdPrefix,
|
|
||||||
// }));
|
|
||||||
// stationSelectOptions.value.splice(0, stationSelectOptions.value.length, ...next);
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// immediate: true,
|
|
||||||
// deep: true,
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
const stationSelectOptions = computed(() => {
|
const stationSelectOptions = computed(() => {
|
||||||
return stationList.value.map<SelectOption>((station) => ({
|
return stationList.value.map<SelectOption>((station) => ({
|
||||||
label: station.name,
|
label: station.name,
|
||||||
|
|||||||
@@ -24,31 +24,17 @@ import {
|
|||||||
type SelectOption,
|
type SelectOption,
|
||||||
} from 'naive-ui';
|
} from 'naive-ui';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import { computed, h, onBeforeMount, reactive, ref, shallowRef, watch } from 'vue';
|
import { computed, h, onBeforeMount, reactive, ref } from 'vue';
|
||||||
|
|
||||||
useStationListQuery();
|
useStationListQuery();
|
||||||
const stationStore = useStationStore();
|
const stationStore = useStationStore();
|
||||||
const { stationList } = storeToRefs(stationStore);
|
const { stationList } = storeToRefs(stationStore);
|
||||||
|
|
||||||
// const stationSelectOptions = shallowRef<SelectOption[]>([]);
|
|
||||||
// watch(
|
|
||||||
// stationList,
|
|
||||||
// (list) => {
|
|
||||||
// const next = list.map<SelectOption>((station) => ({
|
|
||||||
// label: station.name,
|
|
||||||
// value: station.deviceIdPrefix,
|
|
||||||
// }));
|
|
||||||
// stationSelectOptions.value.splice(0, stationSelectOptions.value.length, ...next);
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// immediate: true,
|
|
||||||
// deep: true,
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
const stationSelectOptions = computed(() => {
|
const stationSelectOptions = computed(() => {
|
||||||
return stationList.value.map<SelectOption>((station) => ({
|
return stationList.value.map<SelectOption>((station) => ({
|
||||||
label: station.name,
|
label: station.name,
|
||||||
value: station.deviceIdPrefix,
|
value: station.deviceIdPrefix,
|
||||||
|
disabled: !station.online,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user