功能完善

This commit is contained in:
2026-07-10 11:53:18 +08:00
parent 9f659b371a
commit dd846c82dc
6 changed files with 312 additions and 15 deletions

View File

@@ -6,6 +6,7 @@ export default { name: "TreeEntry" };
<script setup lang="ts">
import { computed, ref, watch, onMounted, onUnmounted } from "vue";
import ConfirmDialog from "./ConfirmDialog.vue";
import PromptDialog from "./PromptDialog.vue";
interface DirEntry {
name: string;
@@ -112,29 +113,62 @@ onUnmounted(() => {
document.removeEventListener("click", onDocumentClick);
});
// ── Prompt dialog state ──────────────────────────────────────
const promptShow = ref(false);
const promptTitle = ref("");
const promptMessage = ref("");
const promptPlaceholder = ref("");
const promptDefaultValue = ref("");
let promptCallback: ((value: string) => void) | null = null;
function openPrompt(
title: string,
message: string,
placeholder: string,
defaultValue: string,
cb: (value: string) => void,
) {
promptTitle.value = title;
promptMessage.value = message;
promptPlaceholder.value = placeholder;
promptDefaultValue.value = defaultValue;
promptCallback = cb;
promptShow.value = true;
}
function onPromptConfirm(value: string) {
promptShow.value = false;
promptCallback?.(value);
promptCallback = null;
}
function onPromptCancel() {
promptShow.value = false;
promptCallback = null;
}
// ── Actions ─────────────────────────────────────────────────
function handleCreateFolder() {
closeMenu();
const name = window.prompt("请输入文件夹名称:");
if (name && name.trim()) {
emit("createFolder", props.entry.path + "/" + name.trim());
}
openPrompt("新建文件夹", "", "输入文件夹名称", "", (name) => {
emit("createFolder", props.entry.path + "/" + name);
});
}
function handleCreateFile() {
closeMenu();
const name = window.prompt("输入文件名称(无需 .md 后缀)");
if (name && name.trim()) {
emit("createFile", props.entry.path + "/" + name.trim() + ".md");
}
openPrompt("新建 MD 文件", "", "输入文件名称(无需 .md 后缀)", "", (name) => {
emit("createFile", props.entry.path + "/" + name + ".md");
});
}
function handleRename() {
closeMenu();
const newName = window.prompt("请输入新名称", props.entry.name);
if (newName && newName.trim() && newName.trim() !== props.entry.name) {
emit("renameEntry", props.entry.path, newName.trim());
}
openPrompt("重命名", "", "输入新名称", props.entry.name, (newName) => {
if (newName !== props.entry.name) {
emit("renameEntry", props.entry.path, newName);
}
});
}
// ── Delete confirmation ─────────────────────────────────────
@@ -183,6 +217,17 @@ function onClick() {
@cancel="confirmShow = false"
/>
<!-- Prompt dialog -->
<PromptDialog
:show="promptShow"
:title="promptTitle"
:message="promptMessage"
:placeholder="promptPlaceholder"
:model-value="promptDefaultValue"
@confirm="onPromptConfirm"
@cancel="onPromptCancel"
/>
<template v-if="entry.is_dir">
<!-- Folder row -->
<div