Commit e696089660131786ea24632ed75adc57b6ea58f4

Authored by Vben
1 parent 80b47c84

feat(tree): add clickRowToExpand option close #318

CHANGELOG.zh_CN.md
1 ## Wip 1 ## Wip
2 2
  3 +### ✨ Features
  4 +
  5 +- `BasicTree` 新增`clickRowToExpand`,用于单击树节点展开
  6 +
3 ### 🐛 Bug Fixes 7 ### 🐛 Bug Fixes
4 8
5 - 修复`Description`已知问题 9 - 修复`Description`已知问题
6 - 修复`BasicForm`已知问题 10 - 修复`BasicForm`已知问题
7 - 修复`BasicTree`下 ActionItem 的 show 属性逻辑问题 11 - 修复`BasicTree`下 ActionItem 的 show 属性逻辑问题
  12 +- 修复树组件 demo 示例样式错误
  13 +- 修复账号管理新增未清空旧数据
8 14
9 ## 2.0.2 (2021-03-04) 15 ## 2.0.2 (2021-03-04)
10 16
src/components/Tree/src/index.vue
@@ -121,7 +121,7 @@ @@ -121,7 +121,7 @@
121 return icon; 121 return icon;
122 } 122 }
123 123
124 - async function handleRightClick({ event, node }: any) { 124 + async function handleRightClick({ event, node }: Recordable) {
125 const { rightMenuList: menuList = [], beforeRightClick } = props; 125 const { rightMenuList: menuList = [], beforeRightClick } = props;
126 let rightMenuList: ContextMenuItem[] = []; 126 let rightMenuList: ContextMenuItem[] = [];
127 127
@@ -137,14 +137,14 @@ @@ -137,14 +137,14 @@
137 }); 137 });
138 } 138 }
139 139
140 - function setExpandedKeys(keys: string[]) { 140 + function setExpandedKeys(keys: Keys) {
141 state.expandedKeys = keys; 141 state.expandedKeys = keys;
142 } 142 }
143 143
144 function getExpandedKeys() { 144 function getExpandedKeys() {
145 return state.expandedKeys; 145 return state.expandedKeys;
146 } 146 }
147 - function setSelectedKeys(keys: string[]) { 147 + function setSelectedKeys(keys: Keys) {
148 state.selectedKeys = keys; 148 state.selectedKeys = keys;
149 } 149 }
150 150
@@ -182,10 +182,23 @@ @@ -182,10 +182,23 @@
182 searchState.searchData = filter(unref(treeDataRef), (node) => { 182 searchState.searchData = filter(unref(treeDataRef), (node) => {
183 const { title } = node; 183 const { title } = node;
184 return title?.includes(searchValue) ?? false; 184 return title?.includes(searchValue) ?? false;
185 - // || key?.includes(searchValue);  
186 }); 185 });
187 } 186 }
188 187
  188 + function handleClickNode(key: string, children: TreeItem[]) {
  189 + if (!props.clickRowToExpand || !children || children.length === 0) return;
  190 + if (!state.expandedKeys.includes(key)) {
  191 + setExpandedKeys([...state.expandedKeys, key]);
  192 + } else {
  193 + const keys = [...state.expandedKeys];
  194 + const index = keys.findIndex((item) => item === key);
  195 + if (index !== -1) {
  196 + keys.splice(index, 1);
  197 + }
  198 + setExpandedKeys(keys);
  199 + }
  200 + }
  201 +
189 watchEffect(() => { 202 watchEffect(() => {
190 treeDataRef.value = props.treeData as TreeItem[]; 203 treeDataRef.value = props.treeData as TreeItem[];
191 state.expandedKeys = props.expandedKeys; 204 state.expandedKeys = props.expandedKeys;
@@ -264,11 +277,15 @@ @@ -264,11 +277,15 @@
264 277
265 const propsData = omit(item, 'title'); 278 const propsData = omit(item, 'title');
266 const icon = getIcon({ ...item, level }, item.icon); 279 const icon = getIcon({ ...item, level }, item.icon);
  280 + const children = get(item, childrenField) || [];
267 return ( 281 return (
268 <Tree.TreeNode {...propsData} node={toRaw(item)} key={get(item, keyField)}> 282 <Tree.TreeNode {...propsData} node={toRaw(item)} key={get(item, keyField)}>
269 {{ 283 {{
270 title: () => ( 284 title: () => (
271 - <span class={`${prefixCls}-title pl-2`}> 285 + <span
  286 + class={`${prefixCls}-title pl-2`}
  287 + onClick={handleClickNode.bind(null, item.key, children)}
  288 + >
272 {icon && <TreeIcon icon={icon} />} 289 {icon && <TreeIcon icon={icon} />}
273 <span 290 <span
274 class={`${prefixCls}__content`} 291 class={`${prefixCls}__content`}
@@ -279,8 +296,7 @@ @@ -279,8 +296,7 @@
279 <span class={`${prefixCls}__actions`}> {renderAction({ ...item, level })}</span> 296 <span class={`${prefixCls}__actions`}> {renderAction({ ...item, level })}</span>
280 </span> 297 </span>
281 ), 298 ),
282 - default: () =>  
283 - renderTreeNode({ data: get(item, childrenField) || [], level: level + 1 }), 299 + default: () => renderTreeNode({ data: children, level: level + 1 }),
284 }} 300 }}
285 </Tree.TreeNode> 301 </Tree.TreeNode>
286 ); 302 );
@@ -289,7 +305,7 @@ @@ -289,7 +305,7 @@
289 return () => { 305 return () => {
290 const { title, helpMessage, toolbar, search } = props; 306 const { title, helpMessage, toolbar, search } = props;
291 return ( 307 return (
292 - <div class={[prefixCls, 'h-full bg-white']}> 308 + <div class={[prefixCls, 'h-full bg-white', attrs.class]}>
293 {(title || toolbar || search) && ( 309 {(title || toolbar || search) && (
294 <TreeHeader 310 <TreeHeader
295 checkAll={checkAll} 311 checkAll={checkAll}
src/components/Tree/src/props.ts
@@ -21,6 +21,7 @@ export const basicProps = { @@ -21,6 +21,7 @@ export const basicProps = {
21 toolbar: propTypes.bool, 21 toolbar: propTypes.bool,
22 search: propTypes.bool, 22 search: propTypes.bool,
23 checkStrictly: propTypes.bool, 23 checkStrictly: propTypes.bool,
  24 + clickRowToExpand: propTypes.bool.def(true),
24 25
25 replaceFields: { 26 replaceFields: {
26 type: Object as PropType<ReplaceFields>, 27 type: Object as PropType<ReplaceFields>,
src/components/Tree/src/types.ts
@@ -14,11 +14,10 @@ export interface ReplaceFields { @@ -14,11 +14,10 @@ export interface ReplaceFields {
14 key?: string; 14 key?: string;
15 } 15 }
16 16
17 -export type Keys = string[] | number[]; 17 +export type Keys = (string | number)[];
18 export type CheckKeys = 18 export type CheckKeys =
19 - | string[]  
20 - | number[]  
21 - | { checked: string[] | number[]; halfChecked: string[] | number[] }; 19 + | (string | number)[]
  20 + | { checked: (string | number)[]; halfChecked: (string | number)[] };
22 21
23 export interface TreeActionType { 22 export interface TreeActionType {
24 checkAll: (checkAll: boolean) => void; 23 checkAll: (checkAll: boolean) => void;
src/views/demo/system/account/AccountModal.vue
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 setup(_, { emit }) { 17 setup(_, { emit }) {
18 const isUpdate = ref(true); 18 const isUpdate = ref(true);
19 19
20 - const [registerForm, { setFieldsValue, updateSchema, validate }] = useForm({ 20 + const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
21 labelWidth: 100, 21 labelWidth: 100,
22 schemas: accountFormSchema, 22 schemas: accountFormSchema,
23 showActionButtonGroup: false, 23 showActionButtonGroup: false,
@@ -27,6 +27,7 @@ @@ -27,6 +27,7 @@
27 }); 27 });
28 28
29 const [registerModal, { setModalProps }] = useModalInner(async (data) => { 29 const [registerModal, { setModalProps }] = useModalInner(async (data) => {
  30 + resetFields();
30 setModalProps({ confirmLoading: false }); 31 setModalProps({ confirmLoading: false });
31 isUpdate.value = !!data?.isUpdate; 32 isUpdate.value = !!data?.isUpdate;
32 33