@handaotech-design/bom 0.0.52 → 0.0.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -51,6 +51,8 @@ app.use(HdBomWorkbench);
|
|
|
51
51
|
|------------------------------|---------------|---------------------------------------------|
|
|
52
52
|
| updateTreeWithPreservedState | 更新树数据,并保持树状态 | (updateDataFn: () => Promise<void>) => void |
|
|
53
53
|
| getParentKeys | 获取节点所有父节点的key | (key: string): string[] | undefined |
|
|
54
|
+
| getParentNodes | 获取节点所有父节点 | (key: string): TreeNodeWithMeta[] |
|
|
55
|
+
| getPath | 获取从根到当前节点的完整路径(包含自身) | (key: string): TreeNodeWithMeta[] |
|
|
54
56
|
| getDepth | 获取节点在树中的深度 | getDepth(key: string) | number |
|
|
55
57
|
|
|
56
58
|
具体交互参考 HdBomTree 组件
|
|
@@ -101,17 +101,18 @@ const getParentKeys = (key: string): string[] | undefined => {
|
|
|
101
101
|
return treeNode?.parentKeys || []
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
const selectFirstSelectableNode = (preserveExpanded = false) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
nextTick(() => {
|
|
104
|
+
const selectFirstSelectableNode = async (preserveExpanded = false) => {
|
|
105
|
+
await nextTick()
|
|
106
|
+
if (firstSelectableKey.value) {
|
|
109
107
|
const parentKeys = getParentKeys(firstSelectableKey.value!) as string[]
|
|
110
108
|
expandedKeys.value = preserveExpanded
|
|
111
|
-
? Array.from(new Set([...expandedKeys.value, ...parentKeys]))
|
|
109
|
+
? Array.from(new Set([...expandedKeys.value, ...parentKeys]))
|
|
112
110
|
: parentKeys
|
|
113
111
|
selectedKeys.value = [firstSelectableKey.value!]
|
|
114
|
-
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
await expandToFirstSelectable(treeData.value)
|
|
115
|
+
}
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
const canLoadMoreRoot = computed(() => currentRootSize.value < filteredData.value.length)
|
|
@@ -276,9 +277,28 @@ function getDepth(key: string): number {
|
|
|
276
277
|
return parentKeys!.length + 1
|
|
277
278
|
}
|
|
278
279
|
|
|
280
|
+
function getParentNodes(key: string): TreeNodeWithMeta[] {
|
|
281
|
+
const parentKeys = getParentKeys(key)
|
|
282
|
+
if (!parentKeys?.length) {
|
|
283
|
+
return []
|
|
284
|
+
}
|
|
285
|
+
return parentKeys.map(k => keyToNodeMap.value.get(k)).filter(Boolean) as TreeNodeWithMeta[]
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function getPath(key: string): TreeNodeWithMeta[] {
|
|
289
|
+
const node = keyToNodeMap.value.get(key)
|
|
290
|
+
if (!node) {
|
|
291
|
+
return []
|
|
292
|
+
}
|
|
293
|
+
const parents = getParentNodes(key)
|
|
294
|
+
return [...parents, node]
|
|
295
|
+
}
|
|
296
|
+
|
|
279
297
|
defineExpose({
|
|
280
298
|
updateTreeWithPreservedState,
|
|
281
299
|
getParentKeys,
|
|
300
|
+
getParentNodes,
|
|
301
|
+
getPath,
|
|
282
302
|
getDepth,
|
|
283
303
|
})
|
|
284
304
|
|
|
@@ -303,11 +323,36 @@ async function _loadData(node: EventDataNode) {
|
|
|
303
323
|
})
|
|
304
324
|
|
|
305
325
|
node.dataRef!.children = treeData
|
|
326
|
+
|
|
327
|
+
await expandToFirstSelectable(treeData)
|
|
306
328
|
}
|
|
307
329
|
else {
|
|
308
330
|
node.isLeaf = true
|
|
309
331
|
}
|
|
310
332
|
}
|
|
333
|
+
|
|
334
|
+
async function expandToFirstSelectable(nodes: DataNode[]) {
|
|
335
|
+
if (_.isEmpty(nodes)) {
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
for (const child of nodes) {
|
|
339
|
+
if ((child as any).selectable) {
|
|
340
|
+
selectedKeys.value = [child.key as string]
|
|
341
|
+
const parentKeys = getParentKeys(child.key as string) || []
|
|
342
|
+
expandedKeys.value = Array.from(new Set([...expandedKeys.value, ...parentKeys]))
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
if (!(child as any).isLeaf && !(child as any).children?.length) {
|
|
346
|
+
expandedKeys.value = Array.from(new Set([...expandedKeys.value, child.key as string | number]))
|
|
347
|
+
// _loadData 会被 ant-tree 的 expand 自动触发
|
|
348
|
+
return
|
|
349
|
+
}
|
|
350
|
+
if ((child as any).children?.length) {
|
|
351
|
+
await expandToFirstSelectable((child as any).children)
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
311
356
|
</script>
|
|
312
357
|
|
|
313
358
|
<template>
|
|
@@ -8,6 +8,7 @@ import HdLeftRight from '../left-right/index'
|
|
|
8
8
|
import HdBomTree from '../bom-tree/index'
|
|
9
9
|
|
|
10
10
|
const props = defineProps<Props>()
|
|
11
|
+
const emit = defineEmits(['select'])
|
|
11
12
|
const COMPONENT_NAME = 'HdBomWorkbench'
|
|
12
13
|
const treeRef = ref()
|
|
13
14
|
defineOptions({
|
|
@@ -24,9 +25,9 @@ interface Props {
|
|
|
24
25
|
loadData?: (node: BomNode, eventNode?: EventDataNode) => Promise<BomNode[]>
|
|
25
26
|
}
|
|
26
27
|
const selectedNode = ref<BomNode>()
|
|
27
|
-
|
|
28
28
|
async function onSelected(data: BomNode) {
|
|
29
29
|
selectedNode.value = data
|
|
30
|
+
emit('select', data)
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
watch(
|
|
@@ -101,17 +101,18 @@ const getParentKeys = (key: string): string[] | undefined => {
|
|
|
101
101
|
return treeNode?.parentKeys || []
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
const selectFirstSelectableNode = (preserveExpanded = false) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
nextTick(() => {
|
|
104
|
+
const selectFirstSelectableNode = async (preserveExpanded = false) => {
|
|
105
|
+
await nextTick()
|
|
106
|
+
if (firstSelectableKey.value) {
|
|
109
107
|
const parentKeys = getParentKeys(firstSelectableKey.value!) as string[]
|
|
110
108
|
expandedKeys.value = preserveExpanded
|
|
111
|
-
? Array.from(new Set([...expandedKeys.value, ...parentKeys]))
|
|
109
|
+
? Array.from(new Set([...expandedKeys.value, ...parentKeys]))
|
|
112
110
|
: parentKeys
|
|
113
111
|
selectedKeys.value = [firstSelectableKey.value!]
|
|
114
|
-
}
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
await expandToFirstSelectable(treeData.value)
|
|
115
|
+
}
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
const canLoadMoreRoot = computed(() => currentRootSize.value < filteredData.value.length)
|
|
@@ -276,9 +277,28 @@ function getDepth(key: string): number {
|
|
|
276
277
|
return parentKeys!.length + 1
|
|
277
278
|
}
|
|
278
279
|
|
|
280
|
+
function getParentNodes(key: string): TreeNodeWithMeta[] {
|
|
281
|
+
const parentKeys = getParentKeys(key)
|
|
282
|
+
if (!parentKeys?.length) {
|
|
283
|
+
return []
|
|
284
|
+
}
|
|
285
|
+
return parentKeys.map(k => keyToNodeMap.value.get(k)).filter(Boolean) as TreeNodeWithMeta[]
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function getPath(key: string): TreeNodeWithMeta[] {
|
|
289
|
+
const node = keyToNodeMap.value.get(key)
|
|
290
|
+
if (!node) {
|
|
291
|
+
return []
|
|
292
|
+
}
|
|
293
|
+
const parents = getParentNodes(key)
|
|
294
|
+
return [...parents, node]
|
|
295
|
+
}
|
|
296
|
+
|
|
279
297
|
defineExpose({
|
|
280
298
|
updateTreeWithPreservedState,
|
|
281
299
|
getParentKeys,
|
|
300
|
+
getParentNodes,
|
|
301
|
+
getPath,
|
|
282
302
|
getDepth,
|
|
283
303
|
})
|
|
284
304
|
|
|
@@ -303,11 +323,36 @@ async function _loadData(node: EventDataNode) {
|
|
|
303
323
|
})
|
|
304
324
|
|
|
305
325
|
node.dataRef!.children = treeData
|
|
326
|
+
|
|
327
|
+
await expandToFirstSelectable(treeData)
|
|
306
328
|
}
|
|
307
329
|
else {
|
|
308
330
|
node.isLeaf = true
|
|
309
331
|
}
|
|
310
332
|
}
|
|
333
|
+
|
|
334
|
+
async function expandToFirstSelectable(nodes: DataNode[]) {
|
|
335
|
+
if (_.isEmpty(nodes)) {
|
|
336
|
+
return
|
|
337
|
+
}
|
|
338
|
+
for (const child of nodes) {
|
|
339
|
+
if ((child as any).selectable) {
|
|
340
|
+
selectedKeys.value = [child.key as string]
|
|
341
|
+
const parentKeys = getParentKeys(child.key as string) || []
|
|
342
|
+
expandedKeys.value = Array.from(new Set([...expandedKeys.value, ...parentKeys]))
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
if (!(child as any).isLeaf && !(child as any).children?.length) {
|
|
346
|
+
expandedKeys.value = Array.from(new Set([...expandedKeys.value, child.key as string | number]))
|
|
347
|
+
// _loadData 会被 ant-tree 的 expand 自动触发
|
|
348
|
+
return
|
|
349
|
+
}
|
|
350
|
+
if ((child as any).children?.length) {
|
|
351
|
+
await expandToFirstSelectable((child as any).children)
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
311
356
|
</script>
|
|
312
357
|
|
|
313
358
|
<template>
|
|
@@ -8,6 +8,7 @@ import HdLeftRight from '../left-right/index'
|
|
|
8
8
|
import HdBomTree from '../bom-tree/index'
|
|
9
9
|
|
|
10
10
|
const props = defineProps<Props>()
|
|
11
|
+
const emit = defineEmits(['select'])
|
|
11
12
|
const COMPONENT_NAME = 'HdBomWorkbench'
|
|
12
13
|
const treeRef = ref()
|
|
13
14
|
defineOptions({
|
|
@@ -24,9 +25,9 @@ interface Props {
|
|
|
24
25
|
loadData?: (node: BomNode, eventNode?: EventDataNode) => Promise<BomNode[]>
|
|
25
26
|
}
|
|
26
27
|
const selectedNode = ref<BomNode>()
|
|
27
|
-
|
|
28
28
|
async function onSelected(data: BomNode) {
|
|
29
29
|
selectedNode.value = data
|
|
30
|
+
emit('select', data)
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
watch(
|