feat: 改进设备树搜索功能,增加搜索类型选择
This commit is contained in:
@@ -11,15 +11,19 @@ import {
|
||||
NButton,
|
||||
NDropdown,
|
||||
NFlex,
|
||||
NGrid,
|
||||
NGridItem,
|
||||
NInput,
|
||||
NRadio,
|
||||
NRadioGroup,
|
||||
NSelect,
|
||||
NTab,
|
||||
NTabs,
|
||||
NTag,
|
||||
NTree,
|
||||
useThemeVars,
|
||||
type DropdownOption,
|
||||
type SelectOption,
|
||||
type TagProps,
|
||||
type TreeInst,
|
||||
type TreeOption,
|
||||
@@ -425,20 +429,26 @@ const stationDeviceTreeData = computed<TreeOption[]>(() => {
|
||||
|
||||
// ========== 设备树搜索 ==========
|
||||
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('');
|
||||
// 设备树将搜索框和单选框的值都交给NTree的pattern属性
|
||||
// 设备树将搜索框、选择器以及单选框的值都交给NTree的pattern属性
|
||||
// 但是如果一个车站下没有匹配的设备,那么这个车站节点也不会显示
|
||||
const searchPattern = computed(() => {
|
||||
const search = searchInput.value;
|
||||
const status = statusInput.value;
|
||||
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 { 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 { name, ipAddress, deviceId, deviceStatus } = device ?? {};
|
||||
const searchMatched = (name ?? '').includes(search) || (ipAddress ?? '').includes(search) || (deviceId ?? '').includes(search);
|
||||
const { deviceStatus } = device ?? {};
|
||||
const searchMatched = !!device?.[type]?.includes(search);
|
||||
const statusMatched = status === '' || status === deviceStatus;
|
||||
return searchMatched && statusMatched;
|
||||
};
|
||||
@@ -523,7 +533,14 @@ onMounted(() => {
|
||||
<div style="height: 100%; display: flex; flex-direction: column">
|
||||
<!-- 搜索和筛选 -->
|
||||
<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">
|
||||
<NRadioGroup v-model:value="statusInput">
|
||||
<NRadio value="">全部</NRadio>
|
||||
|
||||
Reference in New Issue
Block a user