Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 41 additions & 50 deletions AGENTS.md

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions apps/admin/src/lib/components/admin/article/article-table.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
<script lang="ts">
import {
ARTICLE_ACTION_ICONS,
Archive,
Edit,
Eye,
Lock,
MessageSquare,
MoreHorizontal,
Send,
Trash2,
Undo2
} from '@lucide/svelte'
import {
ARTICLE_ACTION_LABELS,
ARTICLE_ACTIONS,
type ArticleStatusAction
} from '$lib/constants/article'
import ArticleStatusBadge from '$lib/components/admin/article/article-status-badge.svelte'
import { Edit, Eye, MessageSquare, MoreHorizontal, Trash2 } from '@lucide/svelte'
import ConfirmDialog from '$lib/components/admin/confirm-dialog.svelte'
import type { Article } from '@myblog/api/modules/article/types'
import * as DropdownMenu from '$ui/dropdown-menu'
import type { LucideIcon } from '@lucide/svelte'
import { goto } from '$lib/utils/navigation'
import { Button } from '$ui/button'
import * as Table from '$ui/table'
Expand All @@ -22,6 +32,15 @@ interface Props {

let { articles, onStatusAction, onDelete }: Props = $props()

// 状态操作的图标映射,与 ARTICLE_ACTION_LABELS 一一对应。
// 图标只随本组件引入,避免图标桶经常量模块进入页面状态模块与单测的编译图。
const ARTICLE_ACTION_ICONS: Record<ArticleStatusAction, LucideIcon> = {
publish: Send,
unpublish: Undo2,
archive: Archive,
private: Lock
}

// 待删除文章,用于确认对话框;为空时隐藏对话框。
let deleteTarget = $state<Article | null>(null)
let isDeleting = $state(false)
Expand Down
74 changes: 74 additions & 0 deletions apps/admin/src/lib/components/admin/category/category-table.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<script lang="ts">
import {
CATEGORY_ROW_BASE_PADDING_REM,
CATEGORY_ROW_INDENT_PER_LEVEL_REM,
CATEGORY_STATUS_CONFIG,
type CategoryRow
} from '$lib/constants/category'
import { FolderPlus, MoreHorizontal, Pencil, Trash2 } from '@lucide/svelte'
import type { Category } from '@myblog/api/modules/category/types'
import * as DropdownMenu from '$ui/dropdown-menu'
import { Button } from '$ui/button'
import { Badge } from '$ui/badge'

interface Props {
rows: CategoryRow[]
onCreateChild: (category: Category) => void
onEdit: (category: Category) => void
onDelete: (category: Category) => void
}

let { rows, onCreateChild, onEdit, onDelete }: Props = $props()
</script>

<!-- 分类列表:层级缩进呈现树形归属,URL 标识在窄屏折叠 -->
<div class="divide-y">
{#each rows as row (row.category.id)}
{@const statusConfig = CATEGORY_STATUS_CONFIG[row.category.status]!}
<div
class="flex flex-wrap items-center gap-4 px-4 py-3"
style="padding-left: {CATEGORY_ROW_BASE_PADDING_REM +
row.depth * CATEGORY_ROW_INDENT_PER_LEVEL_REM}rem"
>
<div class="flex min-w-0 flex-1 items-center gap-3">
{#if row.depth > 0}
<span class="text-muted-foreground">└</span>
{/if}
<!-- 名称允许截断收缩,slug 在窄屏隐藏,避免行内内容撑出可视区 -->
<span class="min-w-0 truncate font-medium">{row.category.name}</span>
<span class="hidden font-mono text-xs text-muted-foreground md:inline"
>/{row.category.slug}</span
>
<Badge variant={statusConfig.variant}>{statusConfig.label}</Badge>
{#if row.category.isFeatured}
<Badge variant="outline">精选</Badge>
{/if}
</div>
<span class="shrink-0 text-sm text-muted-foreground tabular-nums">
{row.category.articleCount} 篇文章
</span>

<DropdownMenu.Root>
<DropdownMenu.Trigger>
<Button variant="ghost" size="icon" aria-label={`分类操作 ${row.category.name}`}>
<MoreHorizontal />
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content align="end">
<DropdownMenu.Item onSelect={() => onCreateChild(row.category)}>
<FolderPlus data-icon="inline-start" />
新建子分类
</DropdownMenu.Item>
<DropdownMenu.Item onSelect={() => onEdit(row.category)}>
<Pencil data-icon="inline-start" />
编辑
</DropdownMenu.Item>
<DropdownMenu.Item variant="destructive" onSelect={() => onDelete(row.category)}>
<Trash2 data-icon="inline-start" />
删除
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Root>
</div>
{/each}
</div>
130 changes: 130 additions & 0 deletions apps/admin/src/lib/components/admin/comment/comment-table.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<script lang="ts">
import {
COMMENT_ACTION_LABELS,
COMMENT_ACTIONS,
COMMENT_STATUS_CONFIG,
type CommentAction
} from '$lib/constants/comment'
import { ArchiveX, Ban, CircleCheck, CircleX, Trash2, MoreHorizontal } from '@lucide/svelte'
import type { AdminComment } from '@myblog/api/modules/comment/types'
import * as DropdownMenu from '$ui/dropdown-menu'
import type { LucideIcon } from '@lucide/svelte'
import { Button } from '$ui/button'
import * as Table from '$ui/table'
import { Badge } from '$ui/badge'

interface Props {
comments: AdminComment[]
onAction: (comment: AdminComment, action: CommentAction) => void
}

let { comments, onAction }: Props = $props()

// 审核动作的图标映射,与 COMMENT_ACTION_LABELS 一一对应。
// 图标只随本组件引入,避免图标桶经常量模块进入页面状态模块与单测的编译图。
const COMMENT_ACTION_ICONS: Record<CommentAction, LucideIcon> = {
approve: CircleCheck,
reject: CircleX,
spam: Ban,
trash: ArchiveX,
delete: Trash2
}

// 游客评论与登录用户评论共用列表,两种形态都缺少展示名称时按匿名呈现。
const ANONYMOUS_AUTHOR_NAME = '匿名'

// 提取评论者展示名称,登录用户优先使用昵称,游客回退到提交时填写的姓名。
function getAuthorName(comment: AdminComment): string {
return (
comment.user?.nickname || comment.user?.username || comment.authorName || ANONYMOUS_AUTHOR_NAME
)
}

// 提取归属文章标题,后端未装配文章归属时回退到文章编号。
function getArticleTitle(comment: AdminComment): string {
return comment.article?.title ?? `#${comment.articleId}`
}

// 评论时间按管理端统一口径只展示日期。
function formatCreatedAt(comment: AdminComment): string {
return new Date(comment.createdAt).toLocaleDateString('zh-CN')
}
</script>

<!-- 评论表格:所属文章与评论时间在窄屏折叠,评论内容、评论者与状态保持可见 -->
<Table.Root>
<Table.Header>
<Table.Row>
<Table.Head class="min-w-64">评论内容</Table.Head>
<Table.Head>评论者</Table.Head>
<Table.Head class="hidden md:table-cell">所属文章</Table.Head>
<Table.Head>状态</Table.Head>
<Table.Head class="hidden md:table-cell">评论时间</Table.Head>
<Table.Head class="w-px text-center whitespace-nowrap">操作</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{#each comments as comment (comment.id)}
<Table.Row>
<Table.Cell>
<div class="flex flex-col gap-1">
<p class="line-clamp-2 max-w-64 text-sm">{comment.content}</p>
<!-- 所属文章与评论时间在窄屏并入评论内容列副行,md 及以上恢复独立列 -->
<span
class="flex max-w-64 flex-wrap items-center gap-x-1.5 text-xs text-muted-foreground md:hidden"
>
<span class="line-clamp-1 max-w-40">{getArticleTitle(comment)}</span>
<span aria-hidden="true">·</span>
<span class="tabular-nums">{formatCreatedAt(comment)}</span>
</span>
</div>
</Table.Cell>
<Table.Cell>
<span class="text-sm">{getAuthorName(comment)}</span>
</Table.Cell>
<Table.Cell class="hidden md:table-cell">
<span class="line-clamp-1 max-w-40 text-sm text-muted-foreground">
{getArticleTitle(comment)}
</span>
</Table.Cell>
<Table.Cell>
<Badge variant={COMMENT_STATUS_CONFIG[comment.status].variant}>
{COMMENT_STATUS_CONFIG[comment.status].label}
</Badge>
</Table.Cell>
<Table.Cell class="hidden md:table-cell">
<span class="text-sm text-muted-foreground tabular-nums">
{formatCreatedAt(comment)}
</span>
</Table.Cell>
<Table.Cell>
<div class="flex items-center justify-center gap-1">
<DropdownMenu.Root>
<DropdownMenu.Trigger>
<Button
variant="ghost"
size="icon"
aria-label={`评论操作 ${getAuthorName(comment)}`}
>
<MoreHorizontal />
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content align="end">
{#each COMMENT_ACTIONS[comment.status] as action (action)}
{@const ActionIcon = COMMENT_ACTION_ICONS[action]}
<DropdownMenu.Item
variant={action === 'delete' ? 'destructive' : 'default'}
onSelect={() => onAction(comment, action)}
>
<ActionIcon data-icon="inline-start" />
{COMMENT_ACTION_LABELS[action]}
</DropdownMenu.Item>
{/each}
</DropdownMenu.Content>
</DropdownMenu.Root>
</div>
</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
131 changes: 131 additions & 0 deletions apps/admin/src/lib/components/admin/dict/dict-item-table.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<script lang="ts">
import type { DictItem, DictType } from '@myblog/api/modules/dict/types'
import { ListTree, Pencil, Plus, Trash2 } from '@lucide/svelte'
import { dictStatusOf } from '$lib/constants/dict'
import { Spinner } from '$ui/spinner'
import { Button } from '$ui/button'
import * as Table from '$ui/table'
import * as Empty from '$ui/empty'
import { Badge } from '$ui/badge'
import * as Card from '$ui/card'

interface Props {
type: DictType | null
items: DictItem[]
isLoading: boolean
onCreate: () => void
onEdit: (item: DictItem) => void
onDelete: (item: DictItem) => void
}

let { type, items, isLoading, onCreate, onEdit, onDelete }: Props = $props()
</script>

<!-- 字典项表格:卡片头部在窄屏换行,描述与排序列按断点折叠,主要字段保持可见 -->
<Card.Root class="lg:col-span-2">
<Card.Header class="flex flex-wrap items-center justify-between gap-2 pb-3">
<Card.Title class="flex min-w-0 items-center gap-2 text-base">
<span class="truncate">字典项</span>
{#if type}
<span class="truncate font-mono text-xs text-muted-foreground">{type.code}</span>
{/if}
</Card.Title>
<Button size="sm" onclick={onCreate} disabled={!type}>
<Plus data-icon="inline-start" />
新建字典项
</Button>
</Card.Header>
<Card.Content class="p-0">
{#if !type}
<div class="flex h-64 items-center justify-center">
<p class="text-sm text-muted-foreground">请先选择字典类型</p>
</div>
{:else if isLoading}
<div class="flex h-64 items-center justify-center">
<Spinner class="size-6" aria-label="正在加载字典项" />
</div>
{:else if items.length === 0}
<Empty.Root class="h-64 border-0">
<Empty.Header>
<Empty.Media variant="icon">
<ListTree />
</Empty.Media>
<Empty.Title>暂无字典项</Empty.Title>
<Empty.Description>为当前字典类型添加可选值</Empty.Description>
</Empty.Header>
<Empty.Content>
<Button size="sm" onclick={onCreate}>
<Plus data-icon="inline-start" />
新建字典项
</Button>
</Empty.Content>
</Empty.Root>
{:else}
<Table.Root>
<Table.Header>
<Table.Row>
<Table.Head>值</Table.Head>
<Table.Head>显示名</Table.Head>
<Table.Head class="hidden md:table-cell">描述</Table.Head>
<Table.Head class="hidden sm:table-cell">排序</Table.Head>
<Table.Head>状态</Table.Head>
<Table.Head class="w-px text-center whitespace-nowrap">操作</Table.Head>
</Table.Row>
</Table.Header>
<Table.Body>
{#each items as item (item.id)}
{@const status = dictStatusOf(item.status)}
<Table.Row>
<Table.Cell>
<code
class="rounded-sm bg-muted px-1.5 py-0.5 font-mono text-xs text-muted-foreground"
>
{item.value}
</code>
</Table.Cell>
<Table.Cell>
<span class="font-medium">{item.label}</span>
<!-- 描述在窄屏并入显示名列副行,md 及以上恢复独立列 -->
{#if item.description}
<span class="block text-sm text-muted-foreground md:hidden">
{item.description}
</span>
{/if}
</Table.Cell>
<Table.Cell class="hidden md:table-cell">
<span class="text-sm text-muted-foreground">{item.description || '—'}</span>
</Table.Cell>
<Table.Cell class="hidden sm:table-cell">
<span class="text-sm tabular-nums">{item.sortOrder}</span>
</Table.Cell>
<Table.Cell>
<Badge variant={status.variant}>{status.label}</Badge>
</Table.Cell>
<Table.Cell>
<div class="flex items-center justify-center gap-1">
<Button
variant="ghost"
size="icon"
aria-label={`编辑字典项 ${item.label}`}
onclick={() => onEdit(item)}
>
<Pencil />
</Button>
<Button
variant="ghost"
size="icon"
class="text-destructive hover:text-destructive"
aria-label={`删除字典项 ${item.label}`}
onclick={() => onDelete(item)}
>
<Trash2 />
</Button>
</div>
</Table.Cell>
</Table.Row>
{/each}
</Table.Body>
</Table.Root>
{/if}
</Card.Content>
</Card.Root>
Loading
Loading