forked from EduCraft/curriculum-project-hub
Merge branch 'chore/detail-delete-button'
This commit is contained in:
@@ -515,7 +515,7 @@
|
|||||||
|
|
||||||
{#if modal === "detail" && detailNode}
|
{#if modal === "detail" && detailNode}
|
||||||
<Modal maxW={680} title="详情 · {detailNode.name}" onclose={() => (modal = null)}>
|
<Modal maxW={680} title="详情 · {detailNode.name}" onclose={() => (modal = null)}>
|
||||||
<OverviewPanel node={detailNode} />
|
<OverviewPanel node={detailNode} ondeleted={() => { modal = null; refresh(); }} />
|
||||||
</Modal>
|
</Modal>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -6,15 +6,32 @@
|
|||||||
import type { ExportJob, NodeDetail } from "./types.js";
|
import type { ExportJob, NodeDetail } from "./types.js";
|
||||||
import Modal from "./Modal.svelte";
|
import Modal from "./Modal.svelte";
|
||||||
|
|
||||||
let { node }: { node: NodeDetail } = $props();
|
let { node, ondeleted }: { node: NodeDetail; ondeleted?: () => void } = $props();
|
||||||
|
|
||||||
let showEditDesc = $state(false);
|
let showEditDesc = $state(false);
|
||||||
let descDraft = $state("");
|
let descDraft = $state("");
|
||||||
let exportJob = $state<ExportJob | null>(null);
|
let exportJob = $state<ExportJob | null>(null);
|
||||||
|
let deleting = $state(false);
|
||||||
|
|
||||||
const canEdit = $derived(node.role === "MANAGE" || node.role === "EDIT");
|
const canEdit = $derived(node.role === "MANAGE" || node.role === "EDIT");
|
||||||
|
const canManage = $derived(node.role === "MANAGE");
|
||||||
const roleLabel = $derived(ROLE_LABEL[node.role]);
|
const roleLabel = $derived(ROLE_LABEL[node.role]);
|
||||||
|
|
||||||
|
/** 删除(进回收站,可恢复;ADR-0031)。MANAGE 专属,与右键菜单同语义。 */
|
||||||
|
async function deleteNode(): Promise<void> {
|
||||||
|
if (!confirm(`删除「${node.name}」?移入回收站,可在回收站恢复。`)) return;
|
||||||
|
deleting = true;
|
||||||
|
try {
|
||||||
|
await api(`/database/api/nodes/${node.id}`, { method: "DELETE" });
|
||||||
|
toastOk("已移入回收站");
|
||||||
|
ondeleted?.();
|
||||||
|
} catch (e) {
|
||||||
|
toastErr(e instanceof Error ? e.message : String(e));
|
||||||
|
} finally {
|
||||||
|
deleting = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
void node.id;
|
void node.id;
|
||||||
exportJob = null;
|
exportJob = null;
|
||||||
@@ -113,6 +130,17 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if canManage}
|
||||||
|
<div class="my-4 border-t border-line-soft"></div>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span class="quiet">删除后移入回收站,可恢复</span>
|
||||||
|
<button class="btn btn-danger disabled:opacity-50" onclick={deleteNode} disabled={deleting}>
|
||||||
|
{deleting ? "删除中…" : `删除此${node.kind === "PROJECT" ? "项目" : "文件夹"}`}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if showEditDesc}
|
{#if showEditDesc}
|
||||||
|
|||||||
Reference in New Issue
Block a user