chengj
2022-04-29 5ad93c6004026489bd22b32ef049f7c63efc1024
提交 | 用户 | age
52257f 1 import type { ExtractPropTypes } from 'vue';
V 2 import type { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
3
4 import { buildProps } from '/@/utils/props';
5
6 export enum ToolbarEnum {
7   SELECT_ALL,
8   UN_SELECT_ALL,
9   EXPAND_ALL,
10   UN_EXPAND_ALL,
11   CHECK_STRICTLY,
12   CHECK_UN_STRICTLY,
13 }
14
15 export const treeEmits = [
16   'update:expandedKeys',
17   'update:selectedKeys',
18   'update:value',
19   'change',
20   'check',
21   'update:searchValue',
22 ];
23
24 export interface TreeState {
25   expandedKeys: KeyType[];
26   selectedKeys: KeyType[];
27   checkedKeys: CheckKeys;
28   checkStrictly: boolean;
29 }
30
31 export interface FieldNames {
32   children?: string;
33   title?: string;
34   key?: string;
35 }
36
37 export type KeyType = string | number;
38
39 export type CheckKeys =
40   | KeyType[]
41   | { checked: string[] | number[]; halfChecked: string[] | number[] };
42
43 export const treeProps = buildProps({
44   value: {
45     type: [Object, Array] as PropType<KeyType[] | CheckKeys>,
46   },
47
48   renderIcon: {
49     type: Function as PropType<(params: Recordable) => string>,
50   },
51
52   helpMessage: {
53     type: [String, Array] as PropType<string | string[]>,
54     default: '',
55   },
56
57   title: {
58     type: String,
59     default: '',
60   },
61   toolbar: Boolean,
62   search: Boolean,
63   searchValue: {
64     type: String,
65     default: '',
66   },
67   checkStrictly: Boolean,
68   clickRowToExpand: {
69     type: Boolean,
70     default: false,
71   },
72   checkable: Boolean,
73   defaultExpandLevel: {
74     type: [String, Number] as PropType<string | number>,
75     default: '',
76   },
77   defaultExpandAll: Boolean,
78
79   fieldNames: {
80     type: Object as PropType<FieldNames>,
81   },
82
83   treeData: {
84     type: Array as PropType<TreeDataItem[]>,
85   },
86
87   actionList: {
88     type: Array as PropType<TreeActionItem[]>,
89     default: () => [],
90   },
91
92   expandedKeys: {
93     type: Array as PropType<KeyType[]>,
94     default: () => [],
95   },
96
97   selectedKeys: {
98     type: Array as PropType<KeyType[]>,
99     default: () => [],
100   },
101
102   checkedKeys: {
103     type: Array as PropType<CheckKeys>,
104     default: () => [],
105   },
106
107   beforeRightClick: {
108     type: Function as PropType<(...arg: any) => ContextMenuItem[] | ContextMenuOptions>,
109     default: undefined,
110   },
111
112   rightMenuList: {
113     type: Array as PropType<ContextMenuItem[]>,
114   },
115   // 自定义数据过滤判断方法(注: 不是整个过滤方法,而是内置过滤的判断方法,用于增强原本仅能通过title进行过滤的方式)
116   filterFn: {
117     type: Function as PropType<
170a4b 118       (searchValue: any, node: TreeItem, fieldNames: FieldNames) => boolean
52257f 119     >,
V 120     default: undefined,
121   },
122   // 高亮搜索值,仅高亮具体匹配值(通过title)值为true时使用默认色值,值为#xxx时使用此值替代且高亮开启
123   highlight: {
124     type: [Boolean, String] as PropType<Boolean | String>,
125     default: false,
126   },
127   // 搜索完成时自动展开结果
128   expandOnSearch: Boolean,
129   // 搜索完成自动选中所有结果,当且仅当 checkable===true 时生效
130   checkOnSearch: Boolean,
131   // 搜索完成自动select所有结果
132   selectedOnSearch: Boolean,
fb43e5 133   loading: {
Z 134     type: Boolean,
135     default: false,
136   },
52257f 137 });
V 138
139 export type TreeProps = ExtractPropTypes<typeof treeProps>;
140
141 export interface ContextMenuItem {
142   label: string;
143   icon?: string;
144   disabled?: boolean;
145   handler?: Fn;
146   divider?: boolean;
147   children?: ContextMenuItem[];
148 }
149
150 export interface ContextMenuOptions {
151   icon?: string;
152   styles?: any;
153   items?: ContextMenuItem[];
154 }
155
156 export interface TreeItem extends TreeDataItem {
157   icon?: any;
158 }
159
160 export interface TreeActionItem {
161   render: (record: Recordable) => any;
162   show?: boolean | ((record: Recordable) => boolean);
163 }
164
165 export interface InsertNodeParams {
166   parentKey: string | null;
167   node: TreeDataItem;
168   list?: TreeDataItem[];
169   push?: 'push' | 'unshift';
170 }
171
172 export interface TreeActionType {
173   checkAll: (checkAll: boolean) => void;
174   expandAll: (expandAll: boolean) => void;
175   setExpandedKeys: (keys: KeyType[]) => void;
176   getExpandedKeys: () => KeyType[];
177   setSelectedKeys: (keys: KeyType[]) => void;
178   getSelectedKeys: () => KeyType[];
179   setCheckedKeys: (keys: CheckKeys) => void;
180   getCheckedKeys: () => CheckKeys;
181   filterByLevel: (level: number) => void;
182   insertNodeByKey: (opt: InsertNodeParams) => void;
183   insertNodesByKey: (opt: InsertNodeParams) => void;
184   deleteNodeByKey: (key: string) => void;
185   updateNodeByKey: (key: string, node: Omit<TreeDataItem, 'key'>) => void;
186   setSearchValue: (value: string) => void;
187   getSearchValue: () => string;
5ad93c 188   getSelectedNode: (
C 189     key: KeyType,
190     treeList?: TreeItem[],
191     selectNode?: TreeItem | null,
192   ) => TreeItem | null;
52257f 193 }