style(console): redesign route cards for narrow screens

The card was one flex row whose badges, filter chips, targets and five
hand-drawn icon buttons squeezed the route name on small screens. It is
now a grid driven by a container query: name and actions share the top
line, the filter summary (clamped to two lines) and targets follow, and
the tags wrap below; from 40rem the tags move up beside the title.

Targets of the same platform collapse into one tag with a count, long
ids truncate instead of widening the page, and the actions use lucide
icons with accessible labels.
This commit is contained in:
翅膀 committed 2026-10-17 01:47:38 +08:00
1 parent 76eb2e445c
commit 2eac368602
4 files changed
+176 -219

No files matched your search

+63 -60
View File
@@ -283,8 +283,13 @@
} }
/* ---- Route cards ---- */ /* ---- Route cards ---- */
.route-list {
@apply flex flex-col gap-2.5;
container-type: inline-size;
}
.route-card { .route-card {
@apply flex animate-rise items-center gap-4 rounded-xl border border-border bg-surface px-5 py-3.5 shadow-xs transition-all duration-150; @apply block animate-rise rounded-xl border border-border bg-surface px-4 py-3 shadow-xs transition-all duration-150;
} }
.route-card:hover { .route-card:hover {
@@ -295,28 +300,70 @@
@apply opacity-60; @apply opacity-60;
} }
.route-card-main { /* Mobile-first: title row with actions, then filters/targets, then the tags. */
@apply min-w-0 flex-1 space-y-2.5; .route-row {
@apply grid items-center gap-x-3 gap-y-2;
grid-template-columns: auto minmax(0, 1fr) auto;
grid-template-areas:
"lead title actions"
"body body body"
"tags tags tags";
} }
.route-card-header { .route-lead {
@apply flex flex-wrap items-center gap-2.5; @apply flex items-center;
grid-area: lead;
} }
.route-card-title { .route-title {
@apply flex min-w-0 flex-wrap items-center gap-2; @apply flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1;
grid-area: title;
} }
.route-name { .route-name {
@apply text-[15px] font-semibold tracking-tight text-text; @apply min-w-0 text-[15px] font-semibold tracking-tight text-text;
overflow-wrap: anywhere;
} }
.route-id { .route-id {
@apply rounded-md bg-surface-2 px-1.5 py-0.5 font-mono text-[11px] text-faint; @apply rounded-md bg-surface-2 px-1.5 py-0.5 font-mono text-[11px] text-faint;
} }
.route-card-badges { .route-position {
@apply ml-auto flex flex-wrap items-center gap-1.5; @apply grid h-5 min-w-5 place-items-center rounded-md bg-accent-dim px-1 font-mono text-[11px] font-semibold text-accent-text tabular-nums;
}
.route-tags {
@apply flex flex-wrap items-center justify-end gap-1.5;
grid-area: tags;
}
.route-actions {
@apply flex items-center gap-0.5;
grid-area: actions;
}
.route-body {
@apply min-w-0 space-y-2;
grid-area: body;
}
@container (min-width: 40rem) {
.route-row {
grid-template-columns: auto minmax(0, 1fr) auto auto;
grid-template-areas:
"lead title tags actions"
". body body body";
}
}
.route-summary {
@apply line-clamp-2 text-[12.5px] leading-relaxed text-muted;
overflow-wrap: anywhere;
}
.route-summary.is-empty {
@apply italic text-faint;
} }
.route-badge { .route-badge {
@@ -324,18 +371,18 @@
} }
.route-badge-dot { .route-badge-dot {
@apply inline-block h-1.5 w-1.5 rounded-full; @apply inline-block h-1.5 w-1.5 rounded-full bg-current;
} }
.route-badge-dc { .route-badge-discord {
@apply border-accent/20 bg-accent-dim/30 text-accent-text; @apply border-accent/20 bg-accent-dim/30 text-accent-text;
} }
.route-badge-tg { .route-badge-telegram {
@apply border-info/20 bg-info-dim/30 text-info; @apply border-info/20 bg-info-dim/30 text-info;
} }
.route-badge-fs { .route-badge-feishu {
@apply border-warn/20 bg-warn-dim/30 text-warn; @apply border-warn/20 bg-warn-dim/30 text-warn;
} }
@@ -351,44 +398,12 @@
@apply border-accent/30 bg-accent-dim/20 text-accent-text; @apply border-accent/30 bg-accent-dim/20 text-accent-text;
} }
.route-card-filters {
@apply flex flex-wrap items-center gap-2 text-xs;
}
.route-chip {
@apply inline-flex items-center gap-1.5 rounded-md border border-border bg-surface-2 px-2.5 py-1 text-[11.5px];
}
.route-chip-type {
@apply font-bold uppercase tracking-wider text-faint text-[10px];
}
.route-chip-val {
@apply font-medium text-text;
}
.route-chip.exclude {
@apply border-bad/20 bg-bad-dim/20;
}
.route-chip.exclude .route-chip-type {
@apply text-bad;
}
.route-chip-empty {
@apply italic text-muted;
}
.route-card-targets { .route-card-targets {
@apply flex flex-wrap items-center gap-2 text-xs; @apply flex flex-wrap items-center gap-2 text-xs;
} }
.route-target {
@apply inline-flex items-center;
}
.route-target-row { .route-target-row {
@apply inline-flex items-center gap-1.5 rounded-md border border-border/80 bg-surface-2/60 px-2 py-0.5 text-xs; @apply inline-flex min-w-0 max-w-full items-center gap-1.5 rounded-md border border-border/80 bg-surface-2/60 px-2 py-0.5 text-xs;
} }
.route-target-label { .route-target-label {
@@ -396,19 +411,7 @@
} }
.route-target-id { .route-target-id {
@apply font-mono text-[11.5px] text-text; @apply min-w-0 truncate font-mono text-[11.5px] text-text;
}
.route-card-actions {
@apply flex shrink-0 items-center gap-1 self-center;
}
.route-action-btn {
@apply flex h-7 w-7 items-center justify-center rounded-md text-muted transition-colors hover:bg-surface-2 hover:text-text disabled:pointer-events-none disabled:opacity-25;
}
.route-action-btn-danger:hover {
@apply bg-bad-dim/30 text-bad;
} }
/* ---- Toggle switch ---- */ /* ---- Toggle switch ---- */
+1 -1
View File
@@ -108,7 +108,7 @@
<p v-if="groupRoutesError" class="err">{{ groupRoutesError }}</p> <p v-if="groupRoutesError" class="err">{{ groupRoutesError }}</p>
<section class="space-y-2.5"> <section class="route-list">
<RouteCard <RouteCard
v-for="(r, i) in groupRoutes" v-for="(r, i) in groupRoutes"
:key="r.id" :key="r.id"
+110 -158
View File
@@ -1,86 +1,103 @@
<template> <template>
<RcCard variant="outline" padding="none" :class="cardClass"> <RcCard variant="outline" padding="none" :class="cardClass">
<div class="route-card-main"> <div class="route-row">
<div class="route-card-header"> <div class="route-lead">
<RcSwitch <RcSwitch
v-if="!readonly" v-if="!readonly"
:model-value="route.enabled" :model-value="route.enabled"
size="sm" size="sm"
@update:model-value="onToggle" @update:model-value="onToggle"
/> />
<span v-if="readonly" class="dot" :class="route.enabled ? 'ok' : 'bad'"></span> <span v-else class="dot" :class="route.enabled ? 'ok' : 'bad'"></span>
<div class="route-card-title"> </div>
<span class="route-name">{{ route.name || t("route.untitled") }}</span>
<div class="route-title">
<span class="route-name">{{ displayName }}</span>
<span class="route-id">{{ route.id }}</span> <span class="route-id">{{ route.id }}</span>
</div> </div>
<div class="route-card-badges">
<div v-if="hasTags" class="route-tags">
<RcBadge <RcBadge
v-for="(tg, i) in route.targets" v-for="p in platforms"
:key="i" :key="p.platform"
size="xs" size="xs"
class="route-badge" class="route-badge"
:class=" :class="`route-badge-${p.platform}`"
tg.platform === 'telegram'
? 'route-badge-tg'
: tg.platform === 'feishu'
? 'route-badge-fs'
: 'route-badge-dc'
"
> >
<span <span class="route-badge-dot"></span>
class="route-badge-dot" {{ platformLabel(p.platform) }}<template v-if="p.count > 1"> ×{{ p.count }}</template>
:class="
tg.platform === 'telegram'
? 'bg-info'
: tg.platform === 'feishu'
? 'bg-warn'
: 'bg-accent'
"
></span>
{{
tg.platform === "telegram"
? "Telegram"
: tg.platform === "feishu"
? t("route.feishu")
: "Discord"
}}
</RcBadge> </RcBadge>
<RcBadge
v-if="route.fallback"
variant="warning"
size="xs"
class="route-badge route-badge-fallback"
>{{ t("route.fallback") }}</RcBadge
>
<RcBadge
v-if="route.stop"
variant="destructive"
size="xs"
class="route-badge route-badge-stop"
>{{ t("route.stop") }}</RcBadge
>
<RcBadge <RcBadge
v-if="route.discordRoleIds?.length" v-if="route.discordRoleIds?.length"
size="xs" size="xs"
class="route-badge route-badge-role" class="route-badge route-badge-role"
:title="route.discordRoleIds.join(', ')"
>@roles</RcBadge >@roles</RcBadge
> >
</div> <RcBadge v-if="route.fallback" size="xs" class="route-badge route-badge-fallback">{{
t("route.fallback")
}}</RcBadge>
<RcBadge v-if="route.stop" size="xs" class="route-badge route-badge-stop">{{
t("route.stop")
}}</RcBadge>
</div> </div>
<div class="flex flex-wrap items-center gap-3"> <div v-if="!readonly" class="route-actions">
<div class="route-card-filters"> <RcButton
<span v-if="summary" class="route-chip"> type="button"
<span class="route-chip-val">{{ summary }}</span> variant="ghost"
</span> size="icon"
<span v-else class="route-chip route-chip-empty"> class="h-8 w-8 text-muted hover:text-text"
<span class="route-chip-type">{{ t("route.noFilters") }}</span> :disabled="atFirst"
</span> :title="t('route.moveUp')"
:aria-label="t('route.moveUp')"
@click="emit('move', route, -1)"
>
<ChevronUp :size="15" />
</RcButton>
<RcButton
type="button"
variant="ghost"
size="icon"
class="h-8 w-8 text-muted hover:text-text"
:disabled="atLast"
:title="t('route.moveDown')"
:aria-label="t('route.moveDown')"
@click="emit('move', route, 1)"
>
<ChevronDown :size="15" />
</RcButton>
<RcButton
type="button"
variant="ghost"
size="icon"
class="h-8 w-8 text-muted hover:text-text"
:title="t('routeEditor.editTitle')"
:aria-label="t('routeEditor.editTitle')"
@click="emit('edit', route)"
>
<Pencil :size="15" />
</RcButton>
<RcButton
type="button"
variant="ghost"
color="error"
size="icon"
class="h-8 w-8 text-muted hover:text-bad"
:title="t('routes.delete')"
:aria-label="t('routes.delete')"
@click="emit('delete', route)"
>
<Trash2 :size="15" />
</RcButton>
</div> </div>
<div class="route-body">
<p class="route-summary" :class="{ 'is-empty': !summary }" :title="summary || undefined">
{{ summary || t("route.noFilters") }}
</p>
<div v-if="route.targets.length" class="route-card-targets"> <div v-if="route.targets.length" class="route-card-targets">
<div v-for="(tg, i) in route.targets" :key="i" class="route-target"> <span v-for="(tg, i) in route.targets" :key="i" class="route-target-row">
<div class="route-target-row">
<span class="route-target-label"> <span class="route-target-label">
<template v-if="tg.platform === 'telegram' || tg.platform === 'feishu'">{{ <template v-if="tg.platform === 'telegram' || tg.platform === 'feishu'">{{
t("route.chat") t("route.chat")
@@ -95,109 +112,20 @@
<template v-else-if="tg.threadId">{{ tg.threadId }}</template> <template v-else-if="tg.threadId">{{ tg.threadId }}</template>
<template v-else>{{ tg.channelId }}</template> <template v-else>{{ tg.channelId }}</template>
</code> </code>
</span>
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
<div v-if="!readonly" class="route-card-actions">
<RcButton
type="button"
variant="ghost"
size="icon"
class="route-action-btn"
:disabled="atFirst"
:title="t('route.moveUp')"
@click="$emit('move', route, -1)"
>
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m18 15-6-6-6 6" />
</svg>
</RcButton>
<RcButton
type="button"
variant="ghost"
size="icon"
class="route-action-btn"
:disabled="atLast"
:title="t('route.moveDown')"
@click="$emit('move', route, 1)"
>
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="m6 9 6 6 6-6" />
</svg>
</RcButton>
<RcButton
type="button"
variant="ghost"
size="icon"
class="route-action-btn"
:title="t('routeEditor.editTitle')"
@click="$emit('edit', route)"
>
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z" />
<path d="m15 5 4 4" />
</svg>
</RcButton>
<RcButton
type="button"
variant="destructive"
size="icon"
class="route-action-btn route-action-btn-danger"
:title="t('routeEditor.close')"
@click="$emit('delete', route)"
>
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M18 6 6 18" />
<path d="m6 6 12 12" />
</svg>
</RcButton>
</div>
</RcCard> </RcCard>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import type { FilterNode, Route } from "~/types"; import { ChevronDown, ChevronUp, Pencil, Trash2 } from "lucide-vue-next";
import type { FilterNode, Route, RouteTarget } from "~/types";
import { describeNode } from "~/composables/useFilterNode"; import { describeNode } from "~/composables/useFilterNode";
type Platform = NonNullable<RouteTarget["platform"]>;
const { t } = useI18n(); const { t } = useI18n();
const props = defineProps<{ const props = defineProps<{
@@ -207,11 +135,6 @@ const props = defineProps<{
readonly?: boolean; readonly?: boolean;
}>(); }>();
const summary = computed(() => {
const node: FilterNode = props.route.ast ?? { all: props.route.filters };
return describeNode(node, t);
});
const cardClass = computed(() => `route-card${props.route.enabled ? "" : " disabled"}`);
const emit = defineEmits<{ const emit = defineEmits<{
(e: "toggle", route: Route): void; (e: "toggle", route: Route): void;
(e: "edit", route: Route): void; (e: "edit", route: Route): void;
@@ -219,8 +142,37 @@ const emit = defineEmits<{
(e: "move", route: Route, dir: -1 | 1): void; (e: "move", route: Route, dir: -1 | 1): void;
}>(); }>();
const displayName = computed(() => props.route.name || t("route.untitled"));
const summary = computed(() => {
const node: FilterNode = props.route.ast ?? { all: props.route.filters };
return describeNode(node, t);
});
const cardClass = computed(() => `route-card${props.route.enabled ? "" : " disabled"}`);
/** One tag per platform (in target order) with how many targets use it. */
const platforms = computed(() => {
const counts = new Map<Platform, number>();
for (const tg of props.route.targets) {
const platform: Platform = tg.platform ?? "discord";
counts.set(platform, (counts.get(platform) ?? 0) + 1);
}
return [...counts].map(([platform, count]) => ({ platform, count }));
});
const hasTags = computed(
() =>
platforms.value.length > 0 ||
!!props.route.discordRoleIds?.length ||
!!props.route.fallback ||
!!props.route.stop,
);
function platformLabel(platform: Platform): string {
if (platform === "telegram") return "Telegram";
if (platform === "feishu") return t("route.feishu");
return "Discord";
}
function onToggle(enabled: boolean): void { function onToggle(enabled: boolean): void {
const next = { ...props.route, enabled }; emit("toggle", { ...props.route, enabled });
emit("toggle", next);
} }
</script> </script>
+2
View File
@@ -142,6 +142,7 @@ const en: Dict = {
"group.routesIn": "Routes in {name}", "group.routesIn": "Routes in {name}",
"routes.emptyGroup": "No routes in this group yet.", "routes.emptyGroup": "No routes in this group yet.",
"routes.createFirst": "Create your first route", "routes.createFirst": "Create your first route",
"routes.delete": "Delete route",
"route.untitled": "(untitled)", "route.untitled": "(untitled)",
"route.noFilters": "no filters", "route.noFilters": "no filters",
"route.channel": "CHANNEL", "route.channel": "CHANNEL",
@@ -543,6 +544,7 @@ const zh: Dict = {
"group.routesIn": "{name} 的路由", "group.routesIn": "{name} 的路由",
"routes.emptyGroup": "该分组还没有路由。", "routes.emptyGroup": "该分组还没有路由。",
"routes.createFirst": "创建第一个路由", "routes.createFirst": "创建第一个路由",
"routes.delete": "删除路由",
"route.untitled": "(未命名)", "route.untitled": "(未命名)",
"route.noFilters": "无过滤器", "route.noFilters": "无过滤器",
"route.channel": "频道", "route.channel": "频道",