提交 e6960896 作者: Vben

feat(tree): add clickRowToExpand option close #318

上级 80b47c84
## Wip ## Wip
### ✨ Features
- `BasicTree` 新增`clickRowToExpand`,用于单击树节点展开
### 🐛 Bug Fixes ### 🐛 Bug Fixes
- 修复`Description`已知问题 - 修复`Description`已知问题
- 修复`BasicForm`已知问题 - 修复`BasicForm`已知问题
- 修复`BasicTree`下 ActionItem 的 show 属性逻辑问题 - 修复`BasicTree`下 ActionItem 的 show 属性逻辑问题
- 修复树组件 demo 示例样式错误
- 修复账号管理新增未清空旧数据
## 2.0.2 (2021-03-04) ## 2.0.2 (2021-03-04)
......
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
return icon; return icon;
} }
async function handleRightClick({ event, node }: any) { async function handleRightClick({ event, node }: Recordable) {
const { rightMenuList: menuList = [], beforeRightClick } = props; const { rightMenuList: menuList = [], beforeRightClick } = props;
let rightMenuList: ContextMenuItem[] = []; let rightMenuList: ContextMenuItem[] = [];
...@@ -137,14 +137,14 @@ ...@@ -137,14 +137,14 @@
}); });
} }
function setExpandedKeys(keys: string[]) { function setExpandedKeys(keys: Keys) {
state.expandedKeys = keys; state.expandedKeys = keys;
} }
function getExpandedKeys() { function getExpandedKeys() {
return state.expandedKeys; return state.expandedKeys;
} }
function setSelectedKeys(keys: string[]) { function setSelectedKeys(keys: Keys) {
state.selectedKeys = keys; state.selectedKeys = keys;
} }
...@@ -182,10 +182,23 @@ ...@@ -182,10 +182,23 @@
searchState.searchData = filter(unref(treeDataRef), (node) => { searchState.searchData = filter(unref(treeDataRef), (node) => {
const { title } = node; const { title } = node;
return title?.includes(searchValue) ?? false; return title?.includes(searchValue) ?? false;
// || key?.includes(searchValue);
}); });
} }
function handleClickNode(key: string, children: TreeItem[]) {
if (!props.clickRowToExpand || !children || children.length === 0) return;
if (!state.expandedKeys.includes(key)) {
setExpandedKeys([...state.expandedKeys, key]);
} else {
const keys = [...state.expandedKeys];
const index = keys.findIndex((item) => item === key);
if (index !== -1) {
keys.splice(index, 1);
}
setExpandedKeys(keys);
}
}
watchEffect(() => { watchEffect(() => {
treeDataRef.value = props.treeData as TreeItem[]; treeDataRef.value = props.treeData as TreeItem[];
state.expandedKeys = props.expandedKeys; state.expandedKeys = props.expandedKeys;
...@@ -264,11 +277,15 @@ ...@@ -264,11 +277,15 @@
const propsData = omit(item, 'title'); const propsData = omit(item, 'title');
const icon = getIcon({ ...item, level }, item.icon); const icon = getIcon({ ...item, level }, item.icon);
const children = get(item, childrenField) || [];
return ( return (
<Tree.TreeNode {...propsData} node={toRaw(item)} key={get(item, keyField)}> <Tree.TreeNode {...propsData} node={toRaw(item)} key={get(item, keyField)}>
{{ {{
title: () => ( title: () => (
<span class={`${prefixCls}-title pl-2`}> <span
class={`${prefixCls}-title pl-2`}
onClick={handleClickNode.bind(null, item.key, children)}
>
{icon && <TreeIcon icon={icon} />} {icon && <TreeIcon icon={icon} />}
<span <span
class={`${prefixCls}__content`} class={`${prefixCls}__content`}
...@@ -279,8 +296,7 @@ ...@@ -279,8 +296,7 @@
<span class={`${prefixCls}__actions`}> {renderAction({ ...item, level })}</span> <span class={`${prefixCls}__actions`}> {renderAction({ ...item, level })}</span>
</span> </span>
), ),
default: () => default: () => renderTreeNode({ data: children, level: level + 1 }),
renderTreeNode({ data: get(item, childrenField) || [], level: level + 1 }),
}} }}
</Tree.TreeNode> </Tree.TreeNode>
); );
...@@ -289,7 +305,7 @@ ...@@ -289,7 +305,7 @@
return () => { return () => {
const { title, helpMessage, toolbar, search } = props; const { title, helpMessage, toolbar, search } = props;
return ( return (
<div class={[prefixCls, 'h-full bg-white']}> <div class={[prefixCls, 'h-full bg-white', attrs.class]}>
{(title || toolbar || search) && ( {(title || toolbar || search) && (
<TreeHeader <TreeHeader
checkAll={checkAll} checkAll={checkAll}
......
...@@ -21,6 +21,7 @@ export const basicProps = { ...@@ -21,6 +21,7 @@ export const basicProps = {
toolbar: propTypes.bool, toolbar: propTypes.bool,
search: propTypes.bool, search: propTypes.bool,
checkStrictly: propTypes.bool, checkStrictly: propTypes.bool,
clickRowToExpand: propTypes.bool.def(true),
replaceFields: { replaceFields: {
type: Object as PropType<ReplaceFields>, type: Object as PropType<ReplaceFields>,
......
...@@ -14,11 +14,10 @@ export interface ReplaceFields { ...@@ -14,11 +14,10 @@ export interface ReplaceFields {
key?: string; key?: string;
} }
export type Keys = string[] | number[]; export type Keys = (string | number)[];
export type CheckKeys = export type CheckKeys =
| string[] | (string | number)[]
| number[] | { checked: (string | number)[]; halfChecked: (string | number)[] };
| { checked: string[] | number[]; halfChecked: string[] | number[] };
export interface TreeActionType { export interface TreeActionType {
checkAll: (checkAll: boolean) => void; checkAll: (checkAll: boolean) => void;
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
setup(_, { emit }) { setup(_, { emit }) {
const isUpdate = ref(true); const isUpdate = ref(true);
const [registerForm, { setFieldsValue, updateSchema, validate }] = useForm({ const [registerForm, { setFieldsValue, updateSchema, resetFields, validate }] = useForm({
labelWidth: 100, labelWidth: 100,
schemas: accountFormSchema, schemas: accountFormSchema,
showActionButtonGroup: false, showActionButtonGroup: false,
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
}); });
const [registerModal, { setModalProps }] = useModalInner(async (data) => { const [registerModal, { setModalProps }] = useModalInner(async (data) => {
resetFields();
setModalProps({ confirmLoading: false }); setModalProps({ confirmLoading: false });
isUpdate.value = !!data?.isUpdate; isUpdate.value = !!data?.isUpdate;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论