diff --git a/src/App.svelte b/src/App.svelte index 2b09f3c..1463ce5 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -3,6 +3,7 @@ import request from './lib/request'; import type { Media } from './lib/interfaces'; import MediaItem from './lib/MediaItem.svelte'; + import MediaFormModal from './lib/MediaFormModal.svelte'; // 类型定义 interface ApiResponse { @@ -32,6 +33,9 @@ let totalItems = $state(0); let loading = $state(false); + // 模态框状态 + let showCreateModal = $state(false); + // 类别选项 const categories = [ { id: 'game', label: '游戏' }, @@ -109,6 +113,25 @@ localStorage.removeItem('auth'); } } + + // 处理创建新媒体 + async function handleCreate(media: Media) { + try { + const response = await request.post>('/media/create', { + ...media, + type: currentCategory + }); + + if (response.data.code === 0) { + showCreateModal = false; + await fetchMediaList(); + } else { + error = response.data.message || 'Failed to create media'; + } + } catch (e: any) { + error = e.message || 'Failed to create media'; + } + } @@ -177,15 +200,23 @@
-
- {#each categories as category} - - {/each} +
+
+ {#each categories as category} + + {/each} +
+
@@ -233,6 +264,13 @@
{/if} + showCreateModal = false} + submitMedia={handleCreate} + mode="add" +/> +