@handaotech-design/bom 0.0.37 → 0.0.38
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
|
@@ -38,6 +38,7 @@ app.use(HdBomWorkbench);
|
|
|
38
38
|
| treeData | BOM数据 | [TreeDataType](#TreeDataType)[] | - |
|
|
39
39
|
| config | BOM树显示配置 | Object | - |
|
|
40
40
|
| maintainable | 是否开启维护模式 | boolean | false |
|
|
41
|
+
| treeShouldSelect | 是否应该被选中 | (node: DataNode) => Promise<boolean> | false |
|
|
41
42
|
| node-menu(v-slot) | 树节点菜单内容 | slot(tree-node: [TreeDataType](#TreeDataType)) | _ |
|
|
42
43
|
|
|
43
44
|
#### 事件
|
|
@@ -45,6 +46,13 @@ app.use(HdBomWorkbench);
|
|
|
45
46
|
|--------|---------|-----------------------------------------------|
|
|
46
47
|
| select | 树节点选中事件 | function(node: [TreeDataType](#TreeDataType)) |
|
|
47
48
|
|
|
49
|
+
#### expose
|
|
50
|
+
| 参数 | 说明 | 类型 |
|
|
51
|
+
|------------------------------|---------------|---------------------------------------------|
|
|
52
|
+
| updateTreeWithPreservedState | 更新树数据,并保持树状态 | (updateDataFn: () => Promise<void>) => void |
|
|
53
|
+
| getParentKeys | 获取节点所有父节点的key | (key: string): string[] | undefined |
|
|
54
|
+
| getDepth | 获取节点在树中的深度 | getDepth(key: string) | number |
|
|
55
|
+
|
|
48
56
|
具体交互参考 HdBomTree 组件
|
|
49
57
|
|
|
50
58
|
## HdBomWorkbench
|
|
@@ -59,9 +67,13 @@ app.use(HdBomWorkbench);
|
|
|
59
67
|
| treeConfig | BOM树显示配置 | Object | - |
|
|
60
68
|
| layoutConfig | 布局配置 | Object{maxLeftWidth: number // 布局左侧默认宽度} | {maxLeftWidth: 500} |
|
|
61
69
|
| maintainable | 是否开启维护模式 | boolean | false |
|
|
70
|
+
| shouldSelect | 是否应该被选中 | (node: DataNode) => Promise<boolean> | false |
|
|
62
71
|
| tree-node-menu(v-slot) | 树节点菜单内容 | slot | |
|
|
63
72
|
|
|
64
|
-
|
|
73
|
+
### expose
|
|
74
|
+
| 参数 | 说明 | 类型 |
|
|
75
|
+
|------------|--------------|--------------|
|
|
76
|
+
| getTreeApi | 获取树组件暴露的所有方法 | () => Object |
|
|
65
77
|
|
|
66
78
|
|
|
67
79
|
### TreeDataType
|
|
@@ -28,6 +28,7 @@ interface Props {
|
|
|
28
28
|
treeData: TreeProps['treeData']
|
|
29
29
|
config: BomTreeConfig
|
|
30
30
|
maintainable?: boolean
|
|
31
|
+
shouldSelect?: (node: DataNode) => Promise<boolean>
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
const expandedKeys = ref<(string | number)[]>([])
|
|
@@ -116,7 +117,10 @@ const selectFirstSelectableNode = (preserveExpanded = false) => {
|
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
type Key = string | number
|
|
119
|
-
const onSelected = (keys: Key[], { node }: { node: EventDataNode }) => {
|
|
120
|
+
const onSelected = async (keys: Key[], { node }: { node: EventDataNode }) => {
|
|
121
|
+
if (_.isFunction(props.shouldSelect) && node?.dataRef && !(await props.shouldSelect(node.dataRef))) {
|
|
122
|
+
return
|
|
123
|
+
}
|
|
120
124
|
const key = node?.dataRef?.key
|
|
121
125
|
if (key) {
|
|
122
126
|
selectedKeys.value = [key as string]
|
|
@@ -224,8 +228,11 @@ async function updateTreeWithPreservedState(updateDataFn: () => Promise<void>) {
|
|
|
224
228
|
})
|
|
225
229
|
}
|
|
226
230
|
|
|
227
|
-
|
|
231
|
+
function getDepth(key: string): number {
|
|
228
232
|
const parentKeys = getParentKeys(key)
|
|
233
|
+
if (_.isEmpty(parentKeys)) {
|
|
234
|
+
return -1
|
|
235
|
+
}
|
|
229
236
|
return parentKeys!.length + 1
|
|
230
237
|
}
|
|
231
238
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { ref, watch } from 'vue'
|
|
3
3
|
import * as _ from 'lodash-es'
|
|
4
|
+
import type { DataNode } from 'ant-design-vue/es/vc-tree-select/interface'
|
|
4
5
|
import type { BomNode, BomTreeConfig, Optional, WorkBenchLayoutConfig } from '../../models'
|
|
5
6
|
import { convertBomDataToTree } from '../../utils'
|
|
6
7
|
import HdLeftRight from '../left-right/index'
|
|
@@ -16,9 +17,10 @@ defineOptions({
|
|
|
16
17
|
interface Props {
|
|
17
18
|
moduleKey: string
|
|
18
19
|
bomData: Optional<BomNode[]>
|
|
19
|
-
treeConfig: BomTreeConfig
|
|
20
20
|
layoutConfig?: WorkBenchLayoutConfig
|
|
21
21
|
maintainable?: boolean
|
|
22
|
+
treeConfig: BomTreeConfig
|
|
23
|
+
treeShouldSelect?: (node: DataNode) => Promise<boolean>
|
|
22
24
|
}
|
|
23
25
|
const bomDataForTree = ref<BomNode[]>()
|
|
24
26
|
const selectedNode = ref<BomNode>()
|
|
@@ -41,22 +43,8 @@ watch(
|
|
|
41
43
|
{ immediate: true },
|
|
42
44
|
)
|
|
43
45
|
|
|
44
|
-
async function updateTreeWithPreservedState(fn: any) {
|
|
45
|
-
treeRef.value.updateTreeWithPreservedState(fn)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getParentKeys(key: string) {
|
|
49
|
-
return treeRef.value.getParentKeys(key)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function getDepth(key: string) {
|
|
53
|
-
return treeRef.value.getDepth(key)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
defineExpose({
|
|
57
|
-
|
|
58
|
-
getParentKeys,
|
|
59
|
-
getDepth,
|
|
47
|
+
getTreeApi: () => treeRef.value,
|
|
60
48
|
})
|
|
61
49
|
</script>
|
|
62
50
|
|
|
@@ -75,6 +63,7 @@ defineExpose({
|
|
|
75
63
|
:tree-data="bomDataForTree"
|
|
76
64
|
:config="props.treeConfig"
|
|
77
65
|
:maintainable="props.maintainable"
|
|
66
|
+
:should-select="props.treeShouldSelect"
|
|
78
67
|
@select="(data: BomNode) => onSelected(data)"
|
|
79
68
|
>
|
|
80
69
|
<template #node-menu="{ treeNode }">
|
|
@@ -28,6 +28,7 @@ interface Props {
|
|
|
28
28
|
treeData: TreeProps['treeData']
|
|
29
29
|
config: BomTreeConfig
|
|
30
30
|
maintainable?: boolean
|
|
31
|
+
shouldSelect?: (node: DataNode) => Promise<boolean>
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
const expandedKeys = ref<(string | number)[]>([])
|
|
@@ -116,7 +117,10 @@ const selectFirstSelectableNode = (preserveExpanded = false) => {
|
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
type Key = string | number
|
|
119
|
-
const onSelected = (keys: Key[], { node }: { node: EventDataNode }) => {
|
|
120
|
+
const onSelected = async (keys: Key[], { node }: { node: EventDataNode }) => {
|
|
121
|
+
if (_.isFunction(props.shouldSelect) && node?.dataRef && !(await props.shouldSelect(node.dataRef))) {
|
|
122
|
+
return
|
|
123
|
+
}
|
|
120
124
|
const key = node?.dataRef?.key
|
|
121
125
|
if (key) {
|
|
122
126
|
selectedKeys.value = [key as string]
|
|
@@ -224,8 +228,11 @@ async function updateTreeWithPreservedState(updateDataFn: () => Promise<void>) {
|
|
|
224
228
|
})
|
|
225
229
|
}
|
|
226
230
|
|
|
227
|
-
|
|
231
|
+
function getDepth(key: string): number {
|
|
228
232
|
const parentKeys = getParentKeys(key)
|
|
233
|
+
if (_.isEmpty(parentKeys)) {
|
|
234
|
+
return -1
|
|
235
|
+
}
|
|
229
236
|
return parentKeys!.length + 1
|
|
230
237
|
}
|
|
231
238
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
2
|
import { ref, watch } from 'vue'
|
|
3
3
|
import * as _ from 'lodash-es'
|
|
4
|
+
import type { DataNode } from 'ant-design-vue/es/vc-tree-select/interface'
|
|
4
5
|
import type { BomNode, BomTreeConfig, Optional, WorkBenchLayoutConfig } from '../../models'
|
|
5
6
|
import { convertBomDataToTree } from '../../utils'
|
|
6
7
|
import HdLeftRight from '../left-right/index'
|
|
@@ -16,9 +17,10 @@ defineOptions({
|
|
|
16
17
|
interface Props {
|
|
17
18
|
moduleKey: string
|
|
18
19
|
bomData: Optional<BomNode[]>
|
|
19
|
-
treeConfig: BomTreeConfig
|
|
20
20
|
layoutConfig?: WorkBenchLayoutConfig
|
|
21
21
|
maintainable?: boolean
|
|
22
|
+
treeConfig: BomTreeConfig
|
|
23
|
+
treeShouldSelect?: (node: DataNode) => Promise<boolean>
|
|
22
24
|
}
|
|
23
25
|
const bomDataForTree = ref<BomNode[]>()
|
|
24
26
|
const selectedNode = ref<BomNode>()
|
|
@@ -41,22 +43,8 @@ watch(
|
|
|
41
43
|
{ immediate: true },
|
|
42
44
|
)
|
|
43
45
|
|
|
44
|
-
async function updateTreeWithPreservedState(fn: any) {
|
|
45
|
-
treeRef.value.updateTreeWithPreservedState(fn)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function getParentKeys(key: string) {
|
|
49
|
-
return treeRef.value.getParentKeys(key)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function getDepth(key: string) {
|
|
53
|
-
return treeRef.value.getDepth(key)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
defineExpose({
|
|
57
|
-
|
|
58
|
-
getParentKeys,
|
|
59
|
-
getDepth,
|
|
47
|
+
getTreeApi: () => treeRef.value,
|
|
60
48
|
})
|
|
61
49
|
</script>
|
|
62
50
|
|
|
@@ -75,6 +63,7 @@ defineExpose({
|
|
|
75
63
|
:tree-data="bomDataForTree"
|
|
76
64
|
:config="props.treeConfig"
|
|
77
65
|
:maintainable="props.maintainable"
|
|
66
|
+
:should-select="props.treeShouldSelect"
|
|
78
67
|
@select="(data: BomNode) => onSelected(data)"
|
|
79
68
|
>
|
|
80
69
|
<template #node-menu="{ treeNode }">
|