90 lines
2.5 KiB
Vue
Raw Normal View History

2024-07-03 16:48:32 +08:00
<template>
2024-07-04 11:38:52 +08:00
<div class="container-page">
2024-07-03 16:48:32 +08:00
<a-input class="search-tree" v-model="searchKey" placeholder="请输入搜索关键词">
<template #prefix>
<icon-search />
</template>
</a-input>
2024-07-04 11:38:52 +08:00
<div class="tree-box">
<a-scrollbar style="height: 100%; overflow: auto" outer-class="scrollbar">
<a-tree :data="treeData" :show-line="true">
<template #title="node">
<span class="tree-title">{{ node.title }}</span>
</template>
<template #icon="node">
<SvgIcon name="folder-close" :size="16" v-if="!node.isLeaf && !node.expanded"></SvgIcon>
<SvgIcon name="folder-open" :size="16" v-if="!node.isLeaf && node.expanded"></SvgIcon>
<SvgIcon name="txt" :size="16" v-if="node.isLeaf"></SvgIcon>
</template>
</a-tree>
</a-scrollbar>
</div>
2024-07-03 16:48:32 +08:00
</div>
</template>
<script setup lang="ts">
import { fileTreeData } from "@/views/file-management/document-library/components/file-tree-data.js";
const searchKey = ref("");
const treeData = computed(() => {
if (!searchKey.value) return sourceTree.value;
return searchData(searchKey.value);
});
// 搜索树
const searchData = (keyword: string) => {
const loop = (tree: any) => {
const result: any = []; // 存储搜索结果
tree.forEach((item: any) => {
// 匹配节点
if (item.title.toLowerCase().indexOf(keyword.toLowerCase()) > -1) {
result.push({ ...item });
} else if (item.children) {
// 不匹配但是有children深层遍历
// filterData 存储遍历结果
const filterData = loop(item.children);
// 如果在深层遍历中,匹配到
if (filterData.length) {
// 将结果存储到children中
result.push({
...item,
children: filterData
});
}
}
});
return result;
};
// 开始递归
return loop(sourceTree.value);
};
const sourceTree = ref(fileTreeData.tree);
</script>
<style lang="scss" scoped>
2024-07-04 11:38:52 +08:00
.container-page {
box-sizing: border-box;
padding: $padding;
height: 100%;
.search-tree {
height: 32px;
margin-bottom: $margin;
}
.tree-box {
height: calc(100% - 32px - $margin);
.scrollbar {
height: 100%;
.tree-title {
white-space: nowrap;
}
}
}
2024-07-03 16:48:32 +08:00
}
2024-07-04 13:05:30 +08:00
// 修改底部横向滚动条高度
:deep(.arco-scrollbar-thumb-direction-horizontal .arco-scrollbar-thumb-bar) {
height: 4px;
}
2024-07-03 16:48:32 +08:00
</style>