Merge branch 'next' of github.com:vueComponent/ant-design-vue into next
commit
1be269d275
|
@ -2,7 +2,7 @@ import { reactive, provide, VNodeTypes, PropType, defineComponent, watch } from
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import defaultRenderEmpty, { RenderEmptyHandler } from './renderEmpty';
|
import defaultRenderEmpty, { RenderEmptyHandler } from './renderEmpty';
|
||||||
import LocaleProvider, { Locale, ANT_MARK } from '../locale-provider';
|
import LocaleProvider, { Locale, ANT_MARK } from '../locale-provider';
|
||||||
|
import { TransformCellTextProps } from '../table/interface';
|
||||||
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
import LocaleReceiver from '../locale-provider/LocaleReceiver';
|
||||||
import { withInstall } from '../_util/type';
|
import { withInstall } from '../_util/type';
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ export interface ConfigConsumerProps {
|
||||||
rootPrefixCls?: string;
|
rootPrefixCls?: string;
|
||||||
getPrefixCls: (suffixCls?: string, customizePrefixCls?: string) => string;
|
getPrefixCls: (suffixCls?: string, customizePrefixCls?: string) => string;
|
||||||
renderEmpty: RenderEmptyHandler;
|
renderEmpty: RenderEmptyHandler;
|
||||||
|
transformCellText?: (tableProps: TransformCellTextProps) => any;
|
||||||
csp?: CSPConfig;
|
csp?: CSPConfig;
|
||||||
autoInsertSpaceInButton?: boolean;
|
autoInsertSpaceInButton?: boolean;
|
||||||
input?: {
|
input?: {
|
||||||
|
@ -55,6 +56,7 @@ export interface ConfigProviderProps {
|
||||||
prefixCls?: string;
|
prefixCls?: string;
|
||||||
children?: VNodeTypes;
|
children?: VNodeTypes;
|
||||||
renderEmpty?: RenderEmptyHandler;
|
renderEmpty?: RenderEmptyHandler;
|
||||||
|
transformCellText?: (tableProps: TransformCellTextProps) => any;
|
||||||
csp?: CSPConfig;
|
csp?: CSPConfig;
|
||||||
autoInsertSpaceInButton?: boolean;
|
autoInsertSpaceInButton?: boolean;
|
||||||
input?: {
|
input?: {
|
||||||
|
@ -89,6 +91,9 @@ const ConfigProvider = defineComponent({
|
||||||
renderEmpty: {
|
renderEmpty: {
|
||||||
type: Function as PropType<RenderEmptyHandler>,
|
type: Function as PropType<RenderEmptyHandler>,
|
||||||
},
|
},
|
||||||
|
transformCellText: {
|
||||||
|
type: Function as PropType<(tableProps: TransformCellTextProps) => any>,
|
||||||
|
},
|
||||||
csp: {
|
csp: {
|
||||||
type: Object as PropType<CSPConfig>,
|
type: Object as PropType<CSPConfig>,
|
||||||
},
|
},
|
||||||
|
|
|
@ -165,7 +165,7 @@ const Menu = defineComponent({
|
||||||
|
|
||||||
// Fix SVGElement e.target.className.indexOf is not a function
|
// Fix SVGElement e.target.className.indexOf is not a function
|
||||||
// https://github.com/ant-design/ant-design/issues/15699
|
// https://github.com/ant-design/ant-design/issues/15699
|
||||||
const { className } = e.target as (SVGAnimationElement | HTMLElement);
|
const { className } = e.target as SVGAnimationElement | HTMLElement;
|
||||||
// SVGAnimatedString.animVal should be identical to SVGAnimatedString.baseVal, unless during an animation.
|
// SVGAnimatedString.animVal should be identical to SVGAnimatedString.baseVal, unless during an animation.
|
||||||
const classNameValue =
|
const classNameValue =
|
||||||
Object.prototype.toString.call(className) === '[object SVGAnimatedString]'
|
Object.prototype.toString.call(className) === '[object SVGAnimatedString]'
|
||||||
|
|
|
@ -7,7 +7,7 @@ import CheckCircleFilled from '@ant-design/icons-vue/CheckCircleFilled';
|
||||||
import InfoCircleFilled from '@ant-design/icons-vue/InfoCircleFilled';
|
import InfoCircleFilled from '@ant-design/icons-vue/InfoCircleFilled';
|
||||||
|
|
||||||
let defaultDuration = 3;
|
let defaultDuration = 3;
|
||||||
let defaultTop: number;
|
let defaultTop: string;
|
||||||
let messageInstance: any;
|
let messageInstance: any;
|
||||||
let key = 1;
|
let key = 1;
|
||||||
let prefixCls = 'ant-message';
|
let prefixCls = 'ant-message';
|
||||||
|
@ -123,7 +123,7 @@ function isArgsProps(content: JointContent): content is ArgsProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ConfigOptions {
|
export interface ConfigOptions {
|
||||||
top?: number;
|
top?: string;
|
||||||
duration?: number;
|
duration?: number;
|
||||||
prefixCls?: string;
|
prefixCls?: string;
|
||||||
getContainer?: () => HTMLElement;
|
getContainer?: () => HTMLElement;
|
||||||
|
|
|
@ -180,6 +180,13 @@ export interface TableState {
|
||||||
columns?: ColumnProps[];
|
columns?: ColumnProps[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TransformCellTextProps {
|
||||||
|
text: any,
|
||||||
|
column: ColumnProps,
|
||||||
|
record: any,
|
||||||
|
index: number
|
||||||
|
}
|
||||||
|
|
||||||
// export type SelectionItemSelectFn = (key: string[]) => any;
|
// export type SelectionItemSelectFn = (key: string[]) => any;
|
||||||
|
|
||||||
// export interface SelectionItem {
|
// export interface SelectionItem {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { defineComponent, inject } from 'vue';
|
import { defineComponent, inject, VNode } from 'vue';
|
||||||
import omit from 'omit.js';
|
import omit from 'omit.js';
|
||||||
import debounce from 'lodash-es/debounce';
|
import debounce from 'lodash-es/debounce';
|
||||||
import FolderOpenOutlined from '@ant-design/icons-vue/FolderOpenOutlined';
|
import FolderOpenOutlined from '@ant-design/icons-vue/FolderOpenOutlined';
|
||||||
|
@ -7,7 +7,7 @@ import FileOutlined from '@ant-design/icons-vue/FileOutlined';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import { conductExpandParent, convertTreeToEntities } from '../vc-tree/src/util';
|
import { conductExpandParent, convertTreeToEntities } from '../vc-tree/src/util';
|
||||||
import Tree, { TreeProps } from './Tree';
|
import Tree, { CheckEvent, ExpendEvent, SelectEvent, TreeProps } from './Tree';
|
||||||
import {
|
import {
|
||||||
calcRangeKeys,
|
calcRangeKeys,
|
||||||
getFullKeyList,
|
getFullKeyList,
|
||||||
|
@ -25,11 +25,11 @@ import { defaultConfigProvider } from '../config-provider';
|
||||||
// selectedKeys?: string[]; }
|
// selectedKeys?: string[]; }
|
||||||
|
|
||||||
export interface DirectoryTreeState {
|
export interface DirectoryTreeState {
|
||||||
_expandedKeys?: string[];
|
_expandedKeys?: (string | number)[];
|
||||||
_selectedKeys?: string[];
|
_selectedKeys?: (string | number)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIcon(props) {
|
function getIcon(props: { isLeaf: boolean; expanded: boolean } & VNode) {
|
||||||
const { isLeaf, expanded } = props;
|
const { isLeaf, expanded } = props;
|
||||||
if (isLeaf) {
|
if (isLeaf) {
|
||||||
return <FileOutlined />;
|
return <FileOutlined />;
|
||||||
|
@ -56,7 +56,7 @@ export default defineComponent({
|
||||||
children: null,
|
children: null,
|
||||||
onDebounceExpand: null,
|
onDebounceExpand: null,
|
||||||
tree: null,
|
tree: null,
|
||||||
lastSelectedKey: [],
|
lastSelectedKey: '',
|
||||||
cachedSelectedKeys: [],
|
cachedSelectedKeys: [],
|
||||||
configProvider: inject('configProvider', defaultConfigProvider),
|
configProvider: inject('configProvider', defaultConfigProvider),
|
||||||
};
|
};
|
||||||
|
@ -100,7 +100,7 @@ export default defineComponent({
|
||||||
this.onDebounceExpand = debounce(this.expandFolderNode, 200, { leading: true });
|
this.onDebounceExpand = debounce(this.expandFolderNode, 200, { leading: true });
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleExpand(expandedKeys, info) {
|
handleExpand(expandedKeys: (string | number)[], info: ExpendEvent) {
|
||||||
this.setUncontrolledState({ _expandedKeys: expandedKeys });
|
this.setUncontrolledState({ _expandedKeys: expandedKeys });
|
||||||
this.$emit('update:expandedKeys', expandedKeys);
|
this.$emit('update:expandedKeys', expandedKeys);
|
||||||
this.$emit('expand', expandedKeys, info);
|
this.$emit('expand', expandedKeys, info);
|
||||||
|
@ -108,7 +108,7 @@ export default defineComponent({
|
||||||
return undefined;
|
return undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
handleClick(event, node) {
|
handleClick(event: MouseEvent, node: VNode) {
|
||||||
const { expandAction } = this.$props;
|
const { expandAction } = this.$props;
|
||||||
|
|
||||||
// Expand the tree
|
// Expand the tree
|
||||||
|
@ -118,7 +118,7 @@ export default defineComponent({
|
||||||
this.$emit('click', event, node);
|
this.$emit('click', event, node);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleDoubleClick(event, node) {
|
handleDoubleClick(event: MouseEvent, node: VNode) {
|
||||||
const { expandAction } = this.$props;
|
const { expandAction } = this.$props;
|
||||||
|
|
||||||
// Expand the tree
|
// Expand the tree
|
||||||
|
@ -130,7 +130,7 @@ export default defineComponent({
|
||||||
this.$emit('dblclick', event, node);
|
this.$emit('dblclick', event, node);
|
||||||
},
|
},
|
||||||
|
|
||||||
hanldeSelect(keys, event) {
|
hanldeSelect(keys: (string | number)[], event: SelectEvent) {
|
||||||
const { multiple } = this.$props;
|
const { multiple } = this.$props;
|
||||||
const children = this.children || [];
|
const children = this.children || [];
|
||||||
const { _expandedKeys: expandedKeys = [] } = this.$data;
|
const { _expandedKeys: expandedKeys = [] } = this.$data;
|
||||||
|
@ -150,7 +150,7 @@ export default defineComponent({
|
||||||
const shiftPick = nativeEvent.shiftKey;
|
const shiftPick = nativeEvent.shiftKey;
|
||||||
|
|
||||||
// Generate new selected keys
|
// Generate new selected keys
|
||||||
let newSelectedKeys;
|
let newSelectedKeys: (string | number)[];
|
||||||
if (multiple && ctrlPick) {
|
if (multiple && ctrlPick) {
|
||||||
// Control click
|
// Control click
|
||||||
newSelectedKeys = keys;
|
newSelectedKeys = keys;
|
||||||
|
@ -180,11 +180,11 @@ export default defineComponent({
|
||||||
|
|
||||||
this.setUncontrolledState(newState);
|
this.setUncontrolledState(newState);
|
||||||
},
|
},
|
||||||
setTreeRef(node) {
|
setTreeRef(node: VNode) {
|
||||||
this.tree = node;
|
this.tree = node;
|
||||||
},
|
},
|
||||||
|
|
||||||
expandFolderNode(event, node) {
|
expandFolderNode(event: MouseEvent, node: { isLeaf: boolean } & VNode) {
|
||||||
const { isLeaf } = node;
|
const { isLeaf } = node;
|
||||||
|
|
||||||
if (isLeaf || event.shiftKey || event.metaKey || event.ctrlKey) {
|
if (isLeaf || event.shiftKey || event.metaKey || event.ctrlKey) {
|
||||||
|
@ -201,7 +201,7 @@ export default defineComponent({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
setUncontrolledState(state) {
|
setUncontrolledState(state: unknown) {
|
||||||
const newState = omit(
|
const newState = omit(
|
||||||
state,
|
state,
|
||||||
Object.keys(getOptionProps(this)).map(p => `_${p}`),
|
Object.keys(getOptionProps(this)).map(p => `_${p}`),
|
||||||
|
@ -210,7 +210,7 @@ export default defineComponent({
|
||||||
this.setState(newState);
|
this.setState(newState);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleCheck(checkedObj, eventObj) {
|
handleCheck(checkedObj: (string | number)[], eventObj: CheckEvent) {
|
||||||
this.$emit('update:checkedKeys', checkedObj);
|
this.$emit('update:checkedKeys', checkedObj);
|
||||||
this.$emit('check', checkedObj, eventObj);
|
this.$emit('check', checkedObj, eventObj);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { defineComponent, inject } from 'vue';
|
import { defineComponent, inject, VNode, PropType } from 'vue';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
|
import LoadingOutlined from '@ant-design/icons-vue/LoadingOutlined';
|
||||||
import FileOutlined from '@ant-design/icons-vue/FileOutlined';
|
import FileOutlined from '@ant-design/icons-vue/FileOutlined';
|
||||||
|
@ -14,6 +14,46 @@ import { cloneElement } from '../_util/vnode';
|
||||||
import { defaultConfigProvider } from '../config-provider';
|
import { defaultConfigProvider } from '../config-provider';
|
||||||
|
|
||||||
const TreeNode = VcTree.TreeNode;
|
const TreeNode = VcTree.TreeNode;
|
||||||
|
|
||||||
|
export interface TreeDataItem {
|
||||||
|
key?: string | number;
|
||||||
|
title?: string;
|
||||||
|
isLeaf?: boolean;
|
||||||
|
selectable?: boolean;
|
||||||
|
children?: TreeDataItem[];
|
||||||
|
disableCheckbox?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
class?: string;
|
||||||
|
style?: any;
|
||||||
|
checkable?: boolean;
|
||||||
|
icon?: any;
|
||||||
|
slots?: any;
|
||||||
|
switcherIcon?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DefaultEvent {
|
||||||
|
nativeEvent: MouseEvent;
|
||||||
|
node: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CheckEvent extends DefaultEvent {
|
||||||
|
checked: boolean;
|
||||||
|
checkedNodes: VNode[];
|
||||||
|
checkedNodesPositions: { node: VNode; pos: string | number }[];
|
||||||
|
event: string;
|
||||||
|
halfCheckedKeys: (string | number)[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExpendEvent extends DefaultEvent {
|
||||||
|
expanded: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SelectEvent extends DefaultEvent {
|
||||||
|
event: string;
|
||||||
|
selected: boolean;
|
||||||
|
selectedNodes: VNode[];
|
||||||
|
}
|
||||||
|
|
||||||
function TreeProps() {
|
function TreeProps() {
|
||||||
return {
|
return {
|
||||||
showLine: PropTypes.looseBool,
|
showLine: PropTypes.looseBool,
|
||||||
|
@ -32,30 +72,36 @@ function TreeProps() {
|
||||||
/** 默认展开对应树节点 */
|
/** 默认展开对应树节点 */
|
||||||
defaultExpandParent: PropTypes.looseBool,
|
defaultExpandParent: PropTypes.looseBool,
|
||||||
/** 默认展开指定的树节点 */
|
/** 默认展开指定的树节点 */
|
||||||
defaultExpandedKeys: PropTypes.array,
|
defaultExpandedKeys: PropTypes.arrayOf(
|
||||||
|
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
),
|
||||||
/** (受控)展开指定的树节点 */
|
/** (受控)展开指定的树节点 */
|
||||||
expandedKeys: PropTypes.array,
|
expandedKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
||||||
/** (受控)选中复选框的树节点 */
|
/** (受控)选中复选框的树节点 */
|
||||||
checkedKeys: PropTypes.oneOfType([
|
checkedKeys: PropTypes.oneOfType([
|
||||||
PropTypes.array,
|
PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
checked: PropTypes.array,
|
checked: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
||||||
halfChecked: PropTypes.array,
|
halfChecked: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
||||||
}).loose,
|
}).loose,
|
||||||
]),
|
]),
|
||||||
/** 默认选中复选框的树节点 */
|
/** 默认选中复选框的树节点 */
|
||||||
defaultCheckedKeys: PropTypes.array,
|
defaultCheckedKeys: PropTypes.arrayOf(
|
||||||
|
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
),
|
||||||
/** (受控)设置选中的树节点 */
|
/** (受控)设置选中的树节点 */
|
||||||
selectedKeys: PropTypes.array,
|
selectedKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
||||||
/** 默认选中的树节点 */
|
/** 默认选中的树节点 */
|
||||||
defaultSelectedKeys: PropTypes.array,
|
defaultSelectedKeys: PropTypes.arrayOf(
|
||||||
|
PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
),
|
||||||
selectable: PropTypes.looseBool,
|
selectable: PropTypes.looseBool,
|
||||||
|
|
||||||
/** filter some AntTreeNodes as you need. it should return true */
|
/** filter some AntTreeNodes as you need. it should return true */
|
||||||
filterAntTreeNode: PropTypes.func,
|
filterAntTreeNode: PropTypes.func,
|
||||||
/** 异步加载数据 */
|
/** 异步加载数据 */
|
||||||
loadData: PropTypes.func,
|
loadData: PropTypes.func,
|
||||||
loadedKeys: PropTypes.array,
|
loadedKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
||||||
// onLoaded: (loadedKeys: string[], info: { event: 'load', node: AntTreeNode; }) => void,
|
// onLoaded: (loadedKeys: string[], info: { event: 'load', node: AntTreeNode; }) => void,
|
||||||
/** 响应右键点击 */
|
/** 响应右键点击 */
|
||||||
// onRightClick: (options: AntTreeNodeMouseEvent) => void,
|
// onRightClick: (options: AntTreeNodeMouseEvent) => void,
|
||||||
|
@ -77,7 +123,9 @@ function TreeProps() {
|
||||||
prefixCls: PropTypes.string,
|
prefixCls: PropTypes.string,
|
||||||
filterTreeNode: PropTypes.func,
|
filterTreeNode: PropTypes.func,
|
||||||
openAnimation: PropTypes.any,
|
openAnimation: PropTypes.any,
|
||||||
treeData: PropTypes.array,
|
treeData: {
|
||||||
|
type: Array as PropType<TreeDataItem[]>,
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* @default{title,key,children}
|
* @default{title,key,children}
|
||||||
* 替换treeNode中 title,key,children字段为treeData中对应的字段
|
* 替换treeNode中 title,key,children字段为treeData中对应的字段
|
||||||
|
@ -123,7 +171,7 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
TreeNode,
|
TreeNode,
|
||||||
methods: {
|
methods: {
|
||||||
renderSwitcherIcon(prefixCls: string, switcherIcon, { isLeaf, loading, expanded }) {
|
renderSwitcherIcon(prefixCls: string, switcherIcon: VNode, { isLeaf, loading, expanded }) {
|
||||||
const { showLine } = this.$props;
|
const { showLine } = this.$props;
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <LoadingOutlined class={`${prefixCls}-switcher-loading-icon`} />;
|
return <LoadingOutlined class={`${prefixCls}-switcher-loading-icon`} />;
|
||||||
|
@ -148,26 +196,19 @@ export default defineComponent({
|
||||||
<CaretDownFilled class={switcherCls} />
|
<CaretDownFilled class={switcherCls} />
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
updateTreeData(treeData) {
|
updateTreeData(treeData: TreeDataItem[]) {
|
||||||
const { $slots } = this;
|
const { $slots } = this;
|
||||||
const defaultFields = { children: 'children', title: 'title', key: 'key' };
|
const defaultFields = { children: 'children', title: 'title', key: 'key' };
|
||||||
const replaceFields = { ...defaultFields, ...this.$props.replaceFields };
|
const replaceFields = { ...defaultFields, ...this.$props.replaceFields };
|
||||||
return treeData.map(item => {
|
return treeData.map(item => {
|
||||||
const key = item[replaceFields.key];
|
const key = item[replaceFields.key];
|
||||||
const children = item[replaceFields.children];
|
const children = item[replaceFields.children];
|
||||||
const { slots = {}, scopedSlots = {}, class: cls, style, ...restProps } = item;
|
const { slots = {}, class: cls, style, ...restProps } = item;
|
||||||
const treeNodeProps = {
|
const treeNodeProps = {
|
||||||
...restProps,
|
...restProps,
|
||||||
icon: $slots[scopedSlots.icon] || $slots[slots.icon] || restProps.icon,
|
icon: $slots[slots.icon] || restProps.icon,
|
||||||
switcherIcon:
|
switcherIcon: $slots[slots.switcherIcon] || restProps.switcherIcon,
|
||||||
$slots[scopedSlots.switcherIcon] ||
|
title: $slots[slots.title] || $slots.title || restProps[replaceFields.title],
|
||||||
$slots[slots.switcherIcon] ||
|
|
||||||
restProps.switcherIcon,
|
|
||||||
title:
|
|
||||||
$slots[scopedSlots.title] ||
|
|
||||||
$slots[slots.title] ||
|
|
||||||
$slots.title ||
|
|
||||||
restProps[replaceFields.title],
|
|
||||||
dataRef: item,
|
dataRef: item,
|
||||||
key,
|
key,
|
||||||
class: cls,
|
class: cls,
|
||||||
|
@ -179,18 +220,18 @@ export default defineComponent({
|
||||||
return treeNodeProps;
|
return treeNodeProps;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setTreeRef(node) {
|
setTreeRef(node: VNode) {
|
||||||
this.tree = node;
|
this.tree = node;
|
||||||
},
|
},
|
||||||
handleCheck(checkedObj, eventObj) {
|
handleCheck(checkedObj: (number | string)[], eventObj: CheckEvent) {
|
||||||
this.$emit('update:checkedKeys', checkedObj);
|
this.$emit('update:checkedKeys', checkedObj);
|
||||||
this.$emit('check', checkedObj, eventObj);
|
this.$emit('check', checkedObj, eventObj);
|
||||||
},
|
},
|
||||||
handleExpand(expandedKeys, eventObj) {
|
handleExpand(expandedKeys: (number | string)[], eventObj: ExpendEvent) {
|
||||||
this.$emit('update:expandedKeys', expandedKeys);
|
this.$emit('update:expandedKeys', expandedKeys);
|
||||||
this.$emit('expand', expandedKeys, eventObj);
|
this.$emit('expand', expandedKeys, eventObj);
|
||||||
},
|
},
|
||||||
handleSelect(selectedKeys: string[], eventObj) {
|
handleSelect(selectedKeys: (number | string)[], eventObj: SelectEvent) {
|
||||||
this.$emit('update:selectedKeys', selectedKeys);
|
this.$emit('update:selectedKeys', selectedKeys);
|
||||||
this.$emit('select', selectedKeys, eventObj);
|
this.$emit('select', selectedKeys, eventObj);
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
import { VNode } from 'vue';
|
||||||
import { getNodeChildren, convertTreeToEntities } from '../vc-tree/src/util';
|
import { getNodeChildren, convertTreeToEntities } from '../vc-tree/src/util';
|
||||||
import { getSlot } from '../_util/props-util';
|
import { getSlot } from '../_util/props-util';
|
||||||
|
import { TreeDataItem } from './Tree';
|
||||||
|
|
||||||
enum Record {
|
enum Record {
|
||||||
None,
|
None,
|
||||||
|
@ -7,11 +9,13 @@ enum Record {
|
||||||
End,
|
End,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TreeKey = string | number;
|
||||||
|
|
||||||
// TODO: Move this logic into `rc-tree`
|
// TODO: Move this logic into `rc-tree`
|
||||||
function traverseNodesKey(rootChildren, callback) {
|
function traverseNodesKey(rootChildren: VNode[], callback?: Function) {
|
||||||
const nodeList = getNodeChildren(rootChildren) || [];
|
const nodeList = getNodeChildren(rootChildren) || [];
|
||||||
|
|
||||||
function processNode(node) {
|
function processNode(node: VNode) {
|
||||||
const { key } = node;
|
const { key } = node;
|
||||||
const children = getSlot(node);
|
const children = getSlot(node);
|
||||||
if (callback(key, node) !== false) {
|
if (callback(key, node) !== false) {
|
||||||
|
@ -22,13 +26,18 @@ function traverseNodesKey(rootChildren, callback) {
|
||||||
nodeList.forEach(processNode);
|
nodeList.forEach(processNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFullKeyList(children) {
|
export function getFullKeyList(children: VNode[]) {
|
||||||
const { keyEntities } = convertTreeToEntities(children);
|
const { keyEntities } = convertTreeToEntities(children);
|
||||||
return [...keyEntities.keys()];
|
return [...keyEntities.keys()];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 计算选中范围,只考虑expanded情况以优化性能 */
|
/** 计算选中范围,只考虑expanded情况以优化性能 */
|
||||||
export function calcRangeKeys(rootChildren, expandedKeys, startKey, endKey) {
|
export function calcRangeKeys(
|
||||||
|
rootChildren: VNode[],
|
||||||
|
expandedKeys: TreeKey[],
|
||||||
|
startKey: TreeKey,
|
||||||
|
endKey: TreeKey,
|
||||||
|
) {
|
||||||
const keys = [];
|
const keys = [];
|
||||||
let record = Record.None;
|
let record = Record.None;
|
||||||
|
|
||||||
|
@ -39,11 +48,11 @@ export function calcRangeKeys(rootChildren, expandedKeys, startKey, endKey) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function matchKey(key) {
|
function matchKey(key: TreeKey) {
|
||||||
return key === startKey || key === endKey;
|
return key === startKey || key === endKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
traverseNodesKey(rootChildren, key => {
|
traverseNodesKey(rootChildren, (key: TreeKey) => {
|
||||||
if (record === Record.End) {
|
if (record === Record.End) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -73,10 +82,10 @@ export function calcRangeKeys(rootChildren, expandedKeys, startKey, endKey) {
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertDirectoryKeysToNodes(rootChildren, keys) {
|
export function convertDirectoryKeysToNodes(rootChildren: VNode[], keys: TreeKey[]) {
|
||||||
const restKeys = [...keys];
|
const restKeys = [...keys];
|
||||||
const nodes = [];
|
const nodes = [];
|
||||||
traverseNodesKey(rootChildren, (key, node) => {
|
traverseNodesKey(rootChildren, (key: TreeKey, node: VNode) => {
|
||||||
const index = restKeys.indexOf(key);
|
const index = restKeys.indexOf(key);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
|
@ -88,13 +97,15 @@ export function convertDirectoryKeysToNodes(rootChildren, keys) {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getFullKeyListByTreeData(treeData: any, replaceFields: any = {}) {
|
export function getFullKeyListByTreeData(treeData: TreeDataItem[], replaceFields: any = {}) {
|
||||||
let keys = [];
|
let keys = [];
|
||||||
const { key = 'key', children = 'children' } = replaceFields(treeData || []).forEach(item => {
|
const { key = 'key', children = 'children' } = replaceFields(treeData || []).forEach(
|
||||||
keys.push(item[key]);
|
(item: TreeDataItem) => {
|
||||||
if (item[children]) {
|
keys.push(item[key]);
|
||||||
keys = [...keys, ...getFullKeyListByTreeData(item[children], replaceFields)];
|
if (item[children]) {
|
||||||
}
|
keys = [...keys, ...getFullKeyListByTreeData(item[children], replaceFields)];
|
||||||
});
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue