-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
145 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
提交tag: | ||
git push origin [tagname] | ||
|
||
build并发布demo: | ||
https://console.cloud.tencent.com/tcb/hosting/index?envId=vue-tree-4gi26kh195ddd24f&rid=4&moduleName=&tabId=file | ||
pnpm build:demo --enable-pre-post-scripts | ||
pnpm build:demo --enable-pre-post-scripts | ||
|
||
发布:pnpm -r publish -F @ysx-libs/vue-virtual-tree --access=public --git-checks=false |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
packages: | ||
# pnpm -r publish -F @ysx-libs/vue-virtual-tree --access=public --git-checks=false | ||
- 'projects/**' | ||
- '!**/test/**' | ||
- '!**/test/**' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
|
||
<template> | ||
<a-input v-model:value="searchKey" placeholder="请搜索" /> | ||
<VirTree | ||
ref="virTree" | ||
:source="list" | ||
:default-expanded-keys="defaultExpandKeys" | ||
:render-node="renderNode" | ||
:virtual="{ size: 26, remain: 8 }"> | ||
</VirTree> | ||
</template> | ||
|
||
<script setup lang="tsx"> | ||
import { watch } from 'vue'; | ||
import { | ||
BaseTreeNode, | ||
TreeNodeOptions, | ||
VirTree, | ||
NodeKey | ||
} from '@ysx-libs/vue-virtual-tree'; | ||
const prefixes = ['leaf', 'sub', 'sub', 'root']; | ||
function recursion(path = '0', level = 3, h = 10): TreeNodeOptions[] { | ||
const list = []; | ||
for (let i = 0; i < h; i += 1) { | ||
const nodeKey = `${path}-${i}`; | ||
const hasChildren = level > 0; | ||
const treeNode: TreeNodeOptions = { | ||
nodeKey, | ||
name: `${prefixes[level]}-${nodeKey}`, | ||
children: [], | ||
hasChildren | ||
}; | ||
if (hasChildren) { | ||
treeNode.children = recursion(nodeKey, level - 1); | ||
} | ||
list.push(treeNode); | ||
} | ||
return list; | ||
} | ||
let defaultExpandKeys = $ref<NodeKey[]>([]); | ||
let searchKey = $ref(''); | ||
let list = $ref(recursion()); | ||
watch(() => searchKey, newVal => { | ||
defaultExpandKeys = []; | ||
list = searchData(recursion(), newVal); | ||
}); | ||
const UNIQUE_WRAPPERS: [string, string] = ['##==-open_tag-==##', '##==-close_tag-==##']; | ||
function renderNode(node: BaseTreeNode) { | ||
const wrapValue = node.name.replace(searchKey, `<span class="node-highlight">$&</span>`); | ||
return <div innerHTML={ wrapValue }></div>; | ||
} | ||
function searchData(origin: TreeNodeOptions[], keyword: string) { | ||
const loop = (data: TreeNodeOptions[]) => { | ||
const result: TreeNodeOptions[] = []; | ||
data.forEach(item => { | ||
if (item.name.toLowerCase().includes(keyword.toLowerCase())) { | ||
result.push({ ...item }); | ||
} else if (item.children) { | ||
const filterData = loop(item.children); | ||
if (filterData.length) { | ||
defaultExpandKeys.push(item.nodeKey); | ||
result.push({ | ||
...item, | ||
children: filterData | ||
}); | ||
} | ||
} | ||
}); | ||
return result; | ||
} | ||
return loop(origin); | ||
} | ||
</script> | ||
|
||
|
||
<style> | ||
.node-highlight { | ||
color: #f60; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.