feat: 改进设备树搜索功能,增加搜索类型选择
This commit is contained in:
@@ -11,15 +11,19 @@ import {
|
|||||||
NButton,
|
NButton,
|
||||||
NDropdown,
|
NDropdown,
|
||||||
NFlex,
|
NFlex,
|
||||||
|
NGrid,
|
||||||
|
NGridItem,
|
||||||
NInput,
|
NInput,
|
||||||
NRadio,
|
NRadio,
|
||||||
NRadioGroup,
|
NRadioGroup,
|
||||||
|
NSelect,
|
||||||
NTab,
|
NTab,
|
||||||
NTabs,
|
NTabs,
|
||||||
NTag,
|
NTag,
|
||||||
NTree,
|
NTree,
|
||||||
useThemeVars,
|
useThemeVars,
|
||||||
type DropdownOption,
|
type DropdownOption,
|
||||||
|
type SelectOption,
|
||||||
type TagProps,
|
type TagProps,
|
||||||
type TreeInst,
|
type TreeInst,
|
||||||
type TreeOption,
|
type TreeOption,
|
||||||
@@ -425,20 +429,26 @@ const stationDeviceTreeData = computed<TreeOption[]>(() => {
|
|||||||
|
|
||||||
// ========== 设备树搜索 ==========
|
// ========== 设备树搜索 ==========
|
||||||
const searchInput = ref('');
|
const searchInput = ref('');
|
||||||
|
const searchTypeOptions: SelectOption[] = [
|
||||||
|
{ label: '设备名称', value: 'name' },
|
||||||
|
{ label: 'IP地址', value: 'ipAddress' },
|
||||||
|
];
|
||||||
|
type SearchType = 'name' | 'ipAddress';
|
||||||
|
const typeInput = ref<SearchType>('name');
|
||||||
const statusInput = ref('');
|
const statusInput = ref('');
|
||||||
// 设备树将搜索框和单选框的值都交给NTree的pattern属性
|
// 设备树将搜索框、选择器以及单选框的值都交给NTree的pattern属性
|
||||||
// 但是如果一个车站下没有匹配的设备,那么这个车站节点也不会显示
|
// 但是如果一个车站下没有匹配的设备,那么这个车站节点也不会显示
|
||||||
const searchPattern = computed(() => {
|
const searchPattern = computed(() => {
|
||||||
const search = searchInput.value;
|
const search = searchInput.value;
|
||||||
const status = statusInput.value;
|
const status = statusInput.value;
|
||||||
if (!search && !status) return ''; // 如果pattern非空会导致NTree组件认为筛选完成,UI上发生全量匹配
|
if (!search && !status) return ''; // 如果pattern非空会导致NTree组件认为筛选完成,UI上发生全量匹配
|
||||||
return JSON.stringify({ search: searchInput.value, status: statusInput.value });
|
return JSON.stringify({ search: searchInput.value, type: typeInput.value, status: statusInput.value });
|
||||||
});
|
});
|
||||||
const searchFilter = (pattern: string, node: TreeOption): boolean => {
|
const searchFilter = (pattern: string, node: TreeOption): boolean => {
|
||||||
const { search, status } = destr<{ search: string; status: string }>(pattern);
|
const { search, type, status } = destr<{ search: string; type: SearchType; status: string }>(pattern);
|
||||||
const device = node['device'] as NdmDeviceResultVO | undefined;
|
const device = node['device'] as NdmDeviceResultVO | undefined;
|
||||||
const { name, ipAddress, deviceId, deviceStatus } = device ?? {};
|
const { deviceStatus } = device ?? {};
|
||||||
const searchMatched = (name ?? '').includes(search) || (ipAddress ?? '').includes(search) || (deviceId ?? '').includes(search);
|
const searchMatched = !!device?.[type]?.includes(search);
|
||||||
const statusMatched = status === '' || status === deviceStatus;
|
const statusMatched = status === '' || status === deviceStatus;
|
||||||
return searchMatched && statusMatched;
|
return searchMatched && statusMatched;
|
||||||
};
|
};
|
||||||
@@ -523,7 +533,14 @@ onMounted(() => {
|
|||||||
<div style="height: 100%; display: flex; flex-direction: column">
|
<div style="height: 100%; display: flex; flex-direction: column">
|
||||||
<!-- 搜索和筛选 -->
|
<!-- 搜索和筛选 -->
|
||||||
<div style="padding: 12px; flex: 0 0 auto">
|
<div style="padding: 12px; flex: 0 0 auto">
|
||||||
<NInput v-model:value="searchInput" placeholder="搜索设备名称、设备ID或IP地址" clearable />
|
<NGrid :cols="10" :x-gap="8">
|
||||||
|
<NGridItem :span="7">
|
||||||
|
<NInput v-model:value="searchInput" placeholder="搜索设备名称或IP地址" clearable />
|
||||||
|
</NGridItem>
|
||||||
|
<NGridItem :span="3">
|
||||||
|
<NSelect v-model:value="typeInput" :options="searchTypeOptions" placeholder="搜索类型" />
|
||||||
|
</NGridItem>
|
||||||
|
</NGrid>
|
||||||
<NFlex align="center">
|
<NFlex align="center">
|
||||||
<NRadioGroup v-model:value="statusInput">
|
<NRadioGroup v-model:value="statusInput">
|
||||||
<NRadio value="">全部</NRadio>
|
<NRadio value="">全部</NRadio>
|
||||||
|
|||||||
Reference in New Issue
Block a user