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) <noreply@anthropic.com>
This commit is contained in:
@@ -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 ?? "未";
|
||||
}
|
||||
|
||||
@@ -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<string, string> = {
|
||||
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 }) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<string, string> = {
|
||||
toutiaohao: "头条号",
|
||||
bilibili: "哔哩哔哩",
|
||||
xiaohongshu: "小红书",
|
||||
douyin: "抖音",
|
||||
kuaishou: "快手",
|
||||
wechat_oa: "微信公众号",
|
||||
baijiahao: "百家号",
|
||||
zhihu: "知乎",
|
||||
};
|
||||
return map[platform?.toLowerCase()] || titleCaseToken(platform);
|
||||
return translateDesktopPlatform(platform);
|
||||
}
|
||||
|
||||
function translateTaskStatus(status: string) {
|
||||
|
||||
Reference in New Issue
Block a user