@dt-frames/ui 1.0.7 → 1.0.10
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/es/components/forms/src/types/form.type.d.ts +3 -3
- package/es/components/index.d.ts +3 -2
- package/es/components/source/src/hooks/useFetch.d.ts +1 -2
- package/es/components/source/src/hooks/useSource.d.ts +4 -4
- package/es/components/source/src/types/source.type.d.ts +1 -9
- package/es/components/source/src/types/table.type.d.ts +1 -1
- package/es/components/table/src/components/TableActions.d.ts +2 -2
- package/es/components/table/src/components/setting/Download.d.ts +2 -2
- package/es/components/table/src/components/setting/Size.d.ts +2 -2
- package/es/components/table/src/index.d.ts +2 -2
- package/es/components/tree/index.d.ts +2 -0
- package/es/components/tree/src/hooks/useTree.d.ts +14 -0
- package/es/components/tree/src/props.d.ts +101 -0
- package/es/components/tree/src/type/tree.d.ts +85 -0
- package/es/components/tree/src/utils/tree.d.ts +5 -0
- package/es/components/upload/index.d.ts +3 -0
- package/es/components/upload/src/helper.d.ts +4 -0
- package/es/components/upload/src/index.d.ts +2784 -0
- package/es/components/upload/src/props.d.ts +40 -0
- package/es/components/upload/src/upload.d.ts +1630 -0
- package/es/index.js +1705 -235
- package/es/style/components/table/index.less +2 -2
- package/es/style/components/tree/index.less +41 -0
- package/es/style/components/upload/index.less +43 -0
- package/es/theme/sider/components/basic-menu/basic-menu.d.ts +3 -3
- package/es/theme/tabs/components/TabContent.d.ts +2 -2
- package/package.json +2 -1
- package/src/components/curd/src/hooks/useCurd.tsx +1 -1
- package/src/components/forms/src/components/formItem.vue +15 -2
- package/src/components/forms/src/hooks/useFormEvents.ts +4 -3
- package/src/components/forms/src/hooks/useFormValues.ts +1 -1
- package/src/components/forms/src/types/form.type.ts +3 -3
- package/src/components/index.ts +9 -3
- package/src/components/modal/src/index.vue +1 -1
- package/src/components/source/src/hooks/useFetch.ts +13 -42
- package/src/components/source/src/hooks/useSource.ts +30 -10
- package/src/components/source/src/types/source.type.ts +1 -21
- package/src/components/source/src/types/table.type.ts +1 -1
- package/src/components/table/index.less +2 -2
- package/src/components/table/src/components/TableRender.vue +1 -3
- package/src/components/table/src/hooks/useDataSource.ts +0 -13
- package/src/components/tree/index.less +41 -0
- package/src/components/tree/index.ts +5 -0
- package/src/components/tree/src/components/TreeHeader.vue +97 -0
- package/src/components/tree/src/hooks/useTree.ts +239 -0
- package/src/components/tree/src/index.vue +392 -0
- package/src/components/tree/src/props.ts +133 -0
- package/src/components/tree/src/type/tree.ts +105 -0
- package/src/components/tree/src/utils/tree.ts +73 -0
- package/src/components/upload/index.less +43 -0
- package/src/components/upload/index.ts +7 -0
- package/src/components/upload/src/helper.ts +32 -0
- package/src/components/upload/src/index.vue +38 -0
- package/src/components/upload/src/props.ts +48 -0
- package/src/components/upload/src/upload.vue +166 -0
- package/src/theme/header/helper/menu-tree.ts +2 -2
- package/src/theme/sider/helper/split-menu.ts +2 -2
- package/es/components/dialog/index.d.ts +0 -2
- package/es/components/dialog/src/hooks/useDialog.d.ts +0 -3
- package/src/components/dialog/index.ts +0 -5
- package/src/components/dialog/src/hooks/useDialog.ts +0 -85
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="dt-tree-header">
|
|
3
|
+
<slot name="headerTitle" v-if="slots.headerTitle"></slot>
|
|
4
|
+
|
|
5
|
+
<h4 v-if="!slots.headerTitle && title" class="headerTitle">{{ title }}</h4>
|
|
6
|
+
|
|
7
|
+
<div v-if="search || toolbar" class="dt-tree-search">
|
|
8
|
+
<div class="dt-tree-search-input" v-if="search">
|
|
9
|
+
<InputSearch size="small" allowClear v-model:value="searchValue" placeholder="搜索"/>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<Dropdown @click.prevent v-if="toolbar">
|
|
13
|
+
<i class="i ic:baseline-more-vert"></i>
|
|
14
|
+
<template #overlay>
|
|
15
|
+
<Menu @click="handleMenuClick">
|
|
16
|
+
<template v-for="item in toolbarList" :key="item.value">
|
|
17
|
+
<MenuItem v-bind="{ key: item.value }">
|
|
18
|
+
{{ item.label }}
|
|
19
|
+
</MenuItem>
|
|
20
|
+
<MenuDivider v-if="item.divider" />
|
|
21
|
+
</template>
|
|
22
|
+
</Menu>
|
|
23
|
+
</template>
|
|
24
|
+
</Dropdown>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script lang="ts" setup>
|
|
31
|
+
import { useSlots, ref, watch, computed } from 'vue'
|
|
32
|
+
import { InputSearch, Dropdown, Menu, MenuItem, MenuDivider } from 'ant-design-vue'
|
|
33
|
+
import { useDebounceFn } from '@vueuse/core'
|
|
34
|
+
import { searchProps } from '../props'
|
|
35
|
+
import { ToolbarEnum } from '../type/tree'
|
|
36
|
+
|
|
37
|
+
const slots = useSlots()
|
|
38
|
+
const emits = defineEmits([
|
|
39
|
+
'search',
|
|
40
|
+
'strictly-change',
|
|
41
|
+
'strictly-change'
|
|
42
|
+
])
|
|
43
|
+
const props = defineProps( searchProps )
|
|
44
|
+
|
|
45
|
+
const searchValue = ref('')
|
|
46
|
+
|
|
47
|
+
function emitChange(value?: string){
|
|
48
|
+
emits('search', value)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function handleMenuClick(e) {
|
|
52
|
+
const { key } = e;
|
|
53
|
+
switch (key) {
|
|
54
|
+
case ToolbarEnum.SELECT_ALL: props.checkAll?.(true); break
|
|
55
|
+
case ToolbarEnum.UN_SELECT_ALL: props.checkAll?.(false); break
|
|
56
|
+
case ToolbarEnum.EXPAND_ALL: props.expandAll?.(true); break
|
|
57
|
+
case ToolbarEnum.UN_EXPAND_ALL: props.expandAll?.(false); break
|
|
58
|
+
case ToolbarEnum.CHECK_STRICTLY: emits('strictly-change', false); break
|
|
59
|
+
case ToolbarEnum.CHECK_UN_STRICTLY: emits('strictly-change', true); break
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const toolbarList = computed(() => {
|
|
64
|
+
const { checkable } = props
|
|
65
|
+
|
|
66
|
+
const defaultToolbarList = [
|
|
67
|
+
{ label: '展开全部', value: ToolbarEnum.EXPAND_ALL },
|
|
68
|
+
{
|
|
69
|
+
label: '折叠全部',
|
|
70
|
+
value: ToolbarEnum.UN_EXPAND_ALL,
|
|
71
|
+
divider: checkable,
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
|
|
75
|
+
return checkable
|
|
76
|
+
? [
|
|
77
|
+
{ label: '选择全部', value: ToolbarEnum.SELECT_ALL },
|
|
78
|
+
{
|
|
79
|
+
label: '取消选择',
|
|
80
|
+
value: ToolbarEnum.UN_SELECT_ALL,
|
|
81
|
+
divider: checkable,
|
|
82
|
+
},
|
|
83
|
+
...defaultToolbarList,
|
|
84
|
+
{ label: '层级关联', value: ToolbarEnum.CHECK_STRICTLY },
|
|
85
|
+
{ label: '层级独立', value: ToolbarEnum.CHECK_UN_STRICTLY },
|
|
86
|
+
]
|
|
87
|
+
: defaultToolbarList;
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const debounceEmitChange = useDebounceFn(emitChange, 200)
|
|
91
|
+
watch(
|
|
92
|
+
() => searchValue.value,
|
|
93
|
+
(v) => {
|
|
94
|
+
debounceEmitChange(v);
|
|
95
|
+
},
|
|
96
|
+
)
|
|
97
|
+
</script>
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { TreeDataItem } from "ant-design-vue/lib/tree"
|
|
2
|
+
import { ComputedRef, Ref, unref } from "vue"
|
|
3
|
+
import { cloneDeep } from 'lodash-es'
|
|
4
|
+
import { FieldNames, InsertNodeParams, TreeItem, KeyType } from "../type/tree"
|
|
5
|
+
import { forEach } from "../utils/tree"
|
|
6
|
+
|
|
7
|
+
export function useTree(
|
|
8
|
+
treeDataRef: Ref<TreeDataItem[]>,
|
|
9
|
+
getFieldNames: ComputedRef<FieldNames>
|
|
10
|
+
) {
|
|
11
|
+
|
|
12
|
+
function getAllKeys(list?: TreeDataItem[]) {
|
|
13
|
+
const keys: string[] = []
|
|
14
|
+
const treeData = list || unref(treeDataRef)
|
|
15
|
+
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
|
16
|
+
|
|
17
|
+
if (!childrenField || !keyField) return keys
|
|
18
|
+
|
|
19
|
+
for (let index = 0; index < treeData.length; index++) {
|
|
20
|
+
const node = treeData[index]
|
|
21
|
+
keys.push(node[keyField]!)
|
|
22
|
+
|
|
23
|
+
const children = node[childrenField]
|
|
24
|
+
|
|
25
|
+
if (children && children.length) {
|
|
26
|
+
keys.push(...(getAllKeys(children) as string[]))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return keys as KeyType[]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function getEnabledKeys(list?: TreeDataItem[]) {
|
|
34
|
+
const keys: string[] = []
|
|
35
|
+
const treeData = list || unref(treeDataRef)
|
|
36
|
+
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
|
37
|
+
|
|
38
|
+
if (!childrenField || !keyField) return keys
|
|
39
|
+
|
|
40
|
+
for (let index = 0; index < treeData.length; index++) {
|
|
41
|
+
const node = treeData[index]
|
|
42
|
+
node.disabled !== true && node.selectable !== false && keys.push(node[keyField]!)
|
|
43
|
+
|
|
44
|
+
const children = node[childrenField]
|
|
45
|
+
if (children && children.length) {
|
|
46
|
+
keys.push(...(getEnabledKeys(children) as string[]))
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return keys as KeyType[]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 获取节点的keys
|
|
54
|
+
function getChildrenKeys(nodeKey: string | number, list?: TreeDataItem[]) {
|
|
55
|
+
const keys: KeyType[] = []
|
|
56
|
+
const treeData = list || unref(treeDataRef)
|
|
57
|
+
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
|
58
|
+
|
|
59
|
+
if (!childrenField || !keyField) return keys
|
|
60
|
+
|
|
61
|
+
for (let index = 0; index < treeData.length; index++) {
|
|
62
|
+
const node = treeData[index]
|
|
63
|
+
const children = node[childrenField]
|
|
64
|
+
|
|
65
|
+
if (nodeKey === node[keyField]) {
|
|
66
|
+
keys.push(node[keyField]!)
|
|
67
|
+
|
|
68
|
+
if (children && children.length) {
|
|
69
|
+
keys.push(...(getAllKeys(children) as KeyType[]))
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
if (children && children.length) {
|
|
73
|
+
keys.push(...getChildrenKeys(nodeKey, children))
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return keys as KeyType[]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
function updateNodeByKey(key: string, node: TreeDataItem, list?: TreeDataItem[]) {
|
|
83
|
+
if (!key) return
|
|
84
|
+
|
|
85
|
+
const treeData = list || unref(treeDataRef)
|
|
86
|
+
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
|
87
|
+
|
|
88
|
+
if (!childrenField || !keyField) return
|
|
89
|
+
|
|
90
|
+
for (let index = 0; index < treeData.length; index++) {
|
|
91
|
+
const element: any = treeData[index]
|
|
92
|
+
const children = element[childrenField]
|
|
93
|
+
|
|
94
|
+
if (element[keyField] === key) {
|
|
95
|
+
treeData[index] = { ...treeData[index], ...node }
|
|
96
|
+
break
|
|
97
|
+
} else if (children && children.length) {
|
|
98
|
+
updateNodeByKey(key, node, element[childrenField])
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
function filterByLevel(level = 1, list?: TreeDataItem[], currentLevel = 1) {
|
|
106
|
+
if (!level) return []
|
|
107
|
+
|
|
108
|
+
const res: (string | number)[] = []
|
|
109
|
+
const data = list || unref(treeDataRef) || []
|
|
110
|
+
|
|
111
|
+
for (let index = 0; index < data.length; index++) {
|
|
112
|
+
const item = data[index]
|
|
113
|
+
|
|
114
|
+
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
|
115
|
+
const key = keyField ? item[keyField] : ''
|
|
116
|
+
const children = childrenField ? item[childrenField] : []
|
|
117
|
+
res.push(key)
|
|
118
|
+
|
|
119
|
+
if (children && children.length && currentLevel < level) {
|
|
120
|
+
currentLevel += 1;
|
|
121
|
+
res.push(...filterByLevel(level, children, currentLevel));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return res as string[] | number[]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 添加节点
|
|
129
|
+
function insertNodeByKey({ parentKey = null, node, push = 'push' }: InsertNodeParams) {
|
|
130
|
+
const treeData: any = cloneDeep(unref(treeDataRef))
|
|
131
|
+
|
|
132
|
+
if (!parentKey) {
|
|
133
|
+
treeData[push](node)
|
|
134
|
+
treeDataRef.value = treeData
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
|
139
|
+
if (!childrenField || !keyField) return
|
|
140
|
+
|
|
141
|
+
forEach(treeData, (treeItem) => {
|
|
142
|
+
if (treeItem[keyField] === parentKey) {
|
|
143
|
+
treeItem[childrenField] = treeItem[childrenField] || []
|
|
144
|
+
treeItem[childrenField][push](node)
|
|
145
|
+
return true
|
|
146
|
+
}
|
|
147
|
+
})
|
|
148
|
+
treeDataRef.value = treeData
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 批量添加节点
|
|
152
|
+
function insertNodesByKey({ parentKey = null, list, push = 'push' }: InsertNodeParams) {
|
|
153
|
+
const treeData: any = cloneDeep(unref(treeDataRef))
|
|
154
|
+
|
|
155
|
+
if (!list || list.length < 1) return
|
|
156
|
+
|
|
157
|
+
if (!parentKey) {
|
|
158
|
+
for (let i = 0; i < list.length; i++) {
|
|
159
|
+
treeData[push](list[i]);
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
|
163
|
+
if (!childrenField || !keyField) return
|
|
164
|
+
|
|
165
|
+
forEach(treeData, (treeItem) => {
|
|
166
|
+
if (treeItem[keyField] === parentKey) {
|
|
167
|
+
treeItem[childrenField] = treeItem[childrenField] || []
|
|
168
|
+
|
|
169
|
+
for (let i = 0; i < list.length; i++) {
|
|
170
|
+
treeItem[childrenField][push](list[i])
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
treeDataRef.value = treeData
|
|
174
|
+
|
|
175
|
+
return true
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// 通过key 删除节点
|
|
182
|
+
function deleteNodeByKey(key: string, list?: TreeDataItem[]) {
|
|
183
|
+
if (!key) return
|
|
184
|
+
|
|
185
|
+
const treeData = list || unref(treeDataRef)
|
|
186
|
+
const { key: keyField, children: childrenField } = unref(getFieldNames)
|
|
187
|
+
|
|
188
|
+
if (!childrenField || !keyField) return
|
|
189
|
+
|
|
190
|
+
for (let index = 0; index < treeData.length; index++) {
|
|
191
|
+
const element: any = treeData[index]
|
|
192
|
+
const children = element[childrenField]
|
|
193
|
+
|
|
194
|
+
if (element[keyField] === key) {
|
|
195
|
+
|
|
196
|
+
treeData.splice(index, 1)
|
|
197
|
+
break
|
|
198
|
+
|
|
199
|
+
} else if (children && children.length) {
|
|
200
|
+
|
|
201
|
+
deleteNodeByKey(key, element[childrenField])
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function getSelectedNode(key: KeyType, list?: TreeItem[], selectedNode?: TreeItem | null) {
|
|
208
|
+
if (!key && key !== 0) return null
|
|
209
|
+
|
|
210
|
+
const treeData = list || unref(treeDataRef)
|
|
211
|
+
|
|
212
|
+
treeData.forEach(item => {
|
|
213
|
+
if (selectedNode?.key || selectedNode?.key === 0) return selectedNode
|
|
214
|
+
|
|
215
|
+
if (item.key === key) {
|
|
216
|
+
selectedNode = item
|
|
217
|
+
return
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (item.children && item.children.length) {
|
|
221
|
+
selectedNode = getSelectedNode(key, item.children, selectedNode)
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
return selectedNode || null
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
getAllKeys,
|
|
230
|
+
getEnabledKeys,
|
|
231
|
+
getChildrenKeys,
|
|
232
|
+
updateNodeByKey,
|
|
233
|
+
filterByLevel,
|
|
234
|
+
insertNodeByKey,
|
|
235
|
+
insertNodesByKey,
|
|
236
|
+
deleteNodeByKey,
|
|
237
|
+
getSelectedNode
|
|
238
|
+
}
|
|
239
|
+
}
|