diff --git a/package.json b/package.json index a5071fd..5cc8b6d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vxe-pc-ui", - "version": "4.3.13", + "version": "4.3.14", "description": "A vue based PC component library", "scripts": { "update": "npm install --legacy-peer-deps", @@ -63,7 +63,7 @@ "vue": "3.5.5", "vue-i18n": "^9.13.1", "vue-router": "^4.3.2", - "vxe-table": "^4.9.11" + "vxe-table": "^4.9.13" }, "vetur": { "tags": "helper/vetur/tags.json", diff --git a/packages/tree/src/tree.ts b/packages/tree/src/tree.ts index d7077ac..47e78d4 100644 --- a/packages/tree/src/tree.ts +++ b/packages/tree/src/tree.ts @@ -288,9 +288,9 @@ export default defineComponent({ emit('update:checkNodeKey', value) } - const setRadioNode = (node: any, checked: boolean) => { + const setRadioNode = (node: any) => { if (node) { - reactData.selectRadioKey = checked ? getNodeId(node) : null + reactData.selectRadioKey = getNodeId(node) } return nextTick() } @@ -370,19 +370,82 @@ export default defineComponent({ const treeMethods: TreeMethods = { dispatchEvent, + clearCurrentNode () { + reactData.currentNode = null + return nextTick() + }, + getCurrentNodeId () { + const { currentNode } = reactData + if (currentNode) { + return getNodeId(currentNode) + } + return null + }, + getCurrentNode () { + const { currentNode, nodeMaps } = reactData + if (currentNode) { + const nodeItem = nodeMaps[currentNode] + if (nodeItem) { + return nodeItem.item + } + } + return null + }, + setCurrentNodeId (nodeKey) { + const { nodeMaps } = reactData + const nodeItem = nodeMaps[nodeKey] + reactData.currentNode = nodeItem ? nodeItem.item : null + return nextTick() + }, + setCurrentNode (node) { + reactData.currentNode = node + return nextTick() + }, clearRadioNode () { reactData.selectRadioKey = null return nextTick() }, + getRadioNodeId () { + return reactData.selectRadioKey || null + }, + getRadioNode () { + const { selectRadioKey, nodeMaps } = reactData + if (selectRadioKey) { + const nodeItem = nodeMaps[selectRadioKey] + if (nodeItem) { + return nodeItem.item + } + } + return null + }, + setRadioNodeId (nodeKey) { + reactData.selectRadioKey = nodeKey + return nextTick() + }, setRadioNode, setCheckboxNode, setCheckboxByNodeId, + getCheckboxNodeIds () { + const { selectCheckboxMaps } = reactData + return Object.keys(selectCheckboxMaps) + }, + getCheckboxNodes () { + const { nodeMaps, selectCheckboxMaps } = reactData + const list: any[] = [] + XEUtils.each(selectCheckboxMaps, (item, nodeid) => { + const nodeItem = nodeMaps[nodeid] + if (nodeItem) { + list.push(nodeItem.item) + } + }) + return list + }, clearCheckboxNode () { reactData.selectCheckboxMaps = {} return nextTick() }, setAllCheckboxNode (checked) { - const selectMaps: Record = Object.assign({}, reactData.selectCheckboxMaps) + const selectMaps: Record = {} const childrenField = computeChildrenField.value if (checked) { XEUtils.eachTree(reactData.treeList, (node) => { @@ -416,6 +479,21 @@ export default defineComponent({ } return nextTick() }, + getExpandNodeIds () { + const { treeExpandedMaps } = reactData + return Object.keys(treeExpandedMaps) + }, + getExpandNodes () { + const { nodeMaps, treeExpandedMaps } = reactData + const list: any[] = [] + XEUtils.each(treeExpandedMaps, (item, nodeid) => { + const nodeItem = nodeMaps[nodeid] + if (nodeItem) { + list.push(nodeItem.item) + } + }) + return list + }, setExpandNode (nodes, expanded) { const expandedMaps: Record = Object.assign({}, reactData.treeExpandedMaps) if (nodes) { @@ -457,13 +535,19 @@ export default defineComponent({ } return nextTick() }, - setAllExpandNode () { - const expandedMaps: Record = Object.assign({}, reactData.treeExpandedMaps) + setAllExpandNode (expanded) { + const expandedMaps: Record = {} const childrenField = computeChildrenField.value - XEUtils.eachTree(reactData.treeList, (node) => { - const nodeid = getNodeId(node) - expandedMaps[nodeid] = true - }, { children: childrenField }) + if (expanded) { + XEUtils.eachTree(reactData.treeList, (node) => { + const childList: any[] = XEUtils.get(node, childrenField) + const hasChild = childList && childList.length + if (hasChild) { + const nodeid = getNodeId(node) + expandedMaps[nodeid] = true + } + }, { children: childrenField }) + } reactData.treeExpandedMaps = expandedMaps return nextTick() }, diff --git a/types/components/tree.d.ts b/types/components/tree.d.ts index 18316f4..5926df2 100644 --- a/types/components/tree.d.ts +++ b/types/components/tree.d.ts @@ -6,7 +6,7 @@ import { DefineVxeComponentApp, DefineVxeComponentOptions, DefineVxeComponentIns export declare const VxeTree: DefineVxeComponentApp export type VxeTreeComponent = DefineVxeComponentOptions -export type VxeTreeInstance = DefineVxeComponentInstance +export type VxeTreeInstance = DefineVxeComponentInstance, VxeTreeConstructor> export interface VxeTreeConstructor extends VxeComponentBaseOptions, VxeTreeMethods { props: VxeTreeProps @@ -176,8 +176,18 @@ export interface TreeInternalData { export interface TreeMethods { dispatchEvent(type: ValueOf, params: Record, evnt: Event | null): void + getCurrentNodeId(): string | number | null + getCurrentNode(): any | null + clearCurrentNode(): Promise + setCurrentNodeId(nodeKey: string | number): Promise + setCurrentNode(node: any): Promise + getRadioNodeId(): string | number | null + getRadioNode(): any | null clearRadioNode(): Promise - setRadioNode(node: any, checked: boolean): Promise + setRadioNodeId(nodeKey: string | number): Promise + setRadioNode(node: any): Promise + getCheckboxNodeIds(): (string | number)[] + getCheckboxNodes(): D[] clearCheckboxNode(): Promise setAllCheckboxNode(checked: boolean): Promise setCheckboxNode(nodeList: any | any[], checked: boolean): Promise @@ -193,6 +203,8 @@ export interface TreeMethods { toggleExpandByNodeId(nodeKeys: any | any[]): Promise toggleExpandNode(nodeList: any | any[]): Promise setAllExpandNode(expanded: boolean): Promise + getExpandNodeIds(): (string | number)[] + getExpandNodes(): D[] reloadExpandNode(node: any): Promise clearExpandLoaded(node: any): Promise loadChildrenNode(node: any, childRecords: any[]): Promise