From b59435dec5d543f4d57354ef7401a177b0c74c9e Mon Sep 17 00:00:00 2001 From: liangxu Date: Wed, 29 Apr 2026 17:12:05 +0800 Subject: [PATCH] refactor(desktop/renderer): centralize platform label and short-name lookup Move the per-platform translation map out of HomeView/TasksView and the titleCaseToken fallback out of PublishManagementView into shared helpers on media-catalog. Single source of truth keeps renderer views consistent with the binding catalog when new platforms ship. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../src/renderer/lib/media-catalog.ts | 13 +++++++++++++ .../src/renderer/views/HomeView.vue | 15 +++------------ .../src/renderer/views/PublishManagementView.vue | 8 ++++---- .../src/renderer/views/TasksView.vue | 15 +++------------ 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/apps/desktop-client/src/renderer/lib/media-catalog.ts b/apps/desktop-client/src/renderer/lib/media-catalog.ts index 91255e8..98f1c43 100644 --- a/apps/desktop-client/src/renderer/lib/media-catalog.ts +++ b/apps/desktop-client/src/renderer/lib/media-catalog.ts @@ -169,3 +169,16 @@ export const desktopMonitoringMediaCatalog: DesktopMediaDefinition[] = aiPlatfor })); export const desktopMediaCatalog = [...desktopPublishMediaCatalog, ...desktopMonitoringMediaCatalog]; + +export function getDesktopMediaDefinition(platform: string): DesktopMediaDefinition | null { + const key = (platform ?? "").toLowerCase(); + return desktopMediaCatalog.find((item) => item.id === key) ?? null; +} + +export function translateDesktopPlatform(platform: string): string { + return getDesktopMediaDefinition(platform)?.label ?? "未知平台"; +} + +export function desktopPlatformShortName(platform: string): string { + return getDesktopMediaDefinition(platform)?.shortName ?? "未"; +} diff --git a/apps/desktop-client/src/renderer/views/HomeView.vue b/apps/desktop-client/src/renderer/views/HomeView.vue index d75616e..9c6fa68 100644 --- a/apps/desktop-client/src/renderer/views/HomeView.vue +++ b/apps/desktop-client/src/renderer/views/HomeView.vue @@ -4,21 +4,12 @@ import { DesktopOutlined, LinkOutlined, ClockCircleOutlined, AlertOutlined } fro import StatusBadge from "../components/StatusBadge.vue"; import { useDesktopRuntime } from "../composables/useDesktopRuntime"; -import { formatClock, formatRelativeTime, titleCaseToken } from "../lib/formatters"; +import { formatClock, formatRelativeTime } from "../lib/formatters"; +import { translateDesktopPlatform } from "../lib/media-catalog"; import { healthTone } from "../lib/runtime-ui"; function translatePlatform(platform: string) { - const map: Record = { - toutiaohao: "头条号", - bilibili: "哔哩哔哩", - xiaohongshu: "小红书", - douyin: "抖音", - kuaishou: "快手", - wechat_oa: "微信公众号", - baijiahao: "百家号", - zhihu: "知乎", - }; - return map[platform?.toLowerCase()] || titleCaseToken(platform); + return translateDesktopPlatform(platform); } function blockedAccountLabel(account: { authState: string; authReason: string | null }) { diff --git a/apps/desktop-client/src/renderer/views/PublishManagementView.vue b/apps/desktop-client/src/renderer/views/PublishManagementView.vue index bc2ca3b..e322216 100644 --- a/apps/desktop-client/src/renderer/views/PublishManagementView.vue +++ b/apps/desktop-client/src/renderer/views/PublishManagementView.vue @@ -14,8 +14,8 @@ import { computed, onMounted, onUnmounted, ref, watch } from "vue"; import StatusBadge from "../components/StatusBadge.vue"; import { useDesktopRuntime } from "../composables/useDesktopRuntime"; -import { formatDateTime, formatRelativeTime, titleCaseToken } from "../lib/formatters"; -import { desktopPublishMediaCatalog } from "../lib/media-catalog"; +import { formatDateTime, formatRelativeTime } from "../lib/formatters"; +import { desktopPlatformShortName, desktopPublishMediaCatalog, translateDesktopPlatform } from "../lib/media-catalog"; import { normalizePublisherErrorMessage } from "../../shared/publisher-errors"; const PAGE_SIZE = 10; @@ -52,7 +52,7 @@ function platformMeta(platform: string) { } function translatePlatform(platform: string) { - return platformMeta(platform)?.label || titleCaseToken(platform); + return platformMeta(platform)?.label || translateDesktopPlatform(platform); } function platformLogo(platform: string): string | null { @@ -64,7 +64,7 @@ function platformAccent(platform: string): string { } function platformShortName(platform: string): string { - return platformMeta(platform)?.shortName ?? titleCaseToken(platform).slice(0, 1); + return platformMeta(platform)?.shortName ?? desktopPlatformShortName(platform); } function statusLabel(status: DesktopTaskInfo["status"]): string { diff --git a/apps/desktop-client/src/renderer/views/TasksView.vue b/apps/desktop-client/src/renderer/views/TasksView.vue index 892f5c1..e8ae4e8 100644 --- a/apps/desktop-client/src/renderer/views/TasksView.vue +++ b/apps/desktop-client/src/renderer/views/TasksView.vue @@ -4,21 +4,12 @@ import { computed } from "vue"; import StatusBadge from "../components/StatusBadge.vue"; import SurfaceCard from "../components/SurfaceCard.vue"; import { useDesktopRuntime } from "../composables/useDesktopRuntime"; -import { formatRelativeTime, titleCaseToken } from "../lib/formatters"; +import { formatRelativeTime } from "../lib/formatters"; +import { translateDesktopPlatform } from "../lib/media-catalog"; import { taskTone } from "../lib/runtime-ui"; function translatePlatform(platform: string) { - const map: Record = { - toutiaohao: "头条号", - bilibili: "哔哩哔哩", - xiaohongshu: "小红书", - douyin: "抖音", - kuaishou: "快手", - wechat_oa: "微信公众号", - baijiahao: "百家号", - zhihu: "知乎", - }; - return map[platform?.toLowerCase()] || titleCaseToken(platform); + return translateDesktopPlatform(platform); } function translateTaskStatus(status: string) {