Skip to content

Commit

Permalink
fix: 优化侧栏操作
Browse files Browse the repository at this point in the history
- 删除时先上下找 后向上找节点
- 重命名弹窗自动聚焦并全选input内容
  • Loading branch information
ZiuChen committed Apr 14, 2023
1 parent 219a53b commit 5b6f4ea
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/hooks/useTreeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,16 @@ export function useTreeData(activeNode: Ref<SidebarItem | null>, treeData: Ref<S
if (index !== undefined) {
parent[0].children?.splice(index, 1)

// 检查前一个节点是否存在
if (index - 1 >= 0) {
// 存在则选中前一个节点
activeNode.value = parent[0].children![index - 1]
}
// 检查后一个节点是否存在
else if (index + 1 <= parent[0].children!.length) {
if (index + 1 <= parent[0].children!.length) {
// 存在则选中后一个节点
activeNode.value = parent[0].children![index]
}
// 检查前一个节点是否存在
else if (index - 1 >= 0) {
// 存在则选中前一个节点
activeNode.value = parent[0].children![index - 1]
}

$emit(DELETE_FILE, node.key)
$emit(CATEGORY_CHANGE)
Expand All @@ -266,16 +266,17 @@ export function useTreeData(activeNode: Ref<SidebarItem | null>, treeData: Ref<S
const node = activeNode.value!
let title = activeNode.value!.title

const InputInstance = h(Input, {
defaultValue: title,
onInput: (value: string) => {
title = value
}
})

Modal.confirm({
title: `重命名${node.children ? '文件夹' : '文章'}:【${node.title}】`,
cancelText: '取消',
content: () =>
h(Input, {
defaultValue: title,
onInput: (value: string) => {
title = value
}
}),
content: () => InputInstance,
onOk() {
if (!title) {
Message.error('标题不能为空')
Expand All @@ -295,6 +296,12 @@ export function useTreeData(activeNode: Ref<SidebarItem | null>, treeData: Ref<S
$emit(RENAME_NODE, node.key)
$emit(CATEGORY_CHANGE)
Message.success('重命名成功')
},
onOpen() {
// 打开弹窗后自动聚焦并全选
InputInstance?.el?.querySelector('input').select()
// @ts-ignore
InputInstance.component?.ctx?.focus()
}
})
}
Expand Down

0 comments on commit 5b6f4ea

Please sign in to comment.