chore(frontend): introduce prettier + eslint and prune unused code
- Add Prettier 3 with prettier-plugin-organize-imports (sorts/removes unused imports) - Add ESLint 10 flat config with typescript-eslint + eslint-plugin-vue + eslint-config-prettier - Add root scripts: format, format:check, lint, lint:fix - Reformat 257 files across admin-web, ops-web, desktop-client, packages - Remove unused locals/exports flagged by --noUnusedLocals/--noUnusedParameters - Fix duplicate localTabLabel key, surrogate-pair regex u-flag, NBSP literal in regex - Skip server/ (Go) and apps/browser-extension/ (deprecated per ADR) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,69 +1,71 @@
|
||||
import type { DesktopAccountInfo, MediaPlatform, PlatformAccount } from "@geo/shared-types";
|
||||
import type { DesktopAccountInfo, MediaPlatform, PlatformAccount } from '@geo/shared-types'
|
||||
|
||||
export interface PublishPlatformOption {
|
||||
id: string;
|
||||
name: string;
|
||||
shortName: string;
|
||||
accent: string;
|
||||
accountLabel?: string;
|
||||
bound?: boolean;
|
||||
id: string
|
||||
name: string
|
||||
shortName: string
|
||||
accent: string
|
||||
accountLabel?: string
|
||||
bound?: boolean
|
||||
}
|
||||
|
||||
const platformCatalog: Record<string, Omit<PublishPlatformOption, "accountLabel" | "bound">> = {
|
||||
toutiaohao: { id: "toutiaohao", name: "头条号", shortName: "头", accent: "#f5222d" },
|
||||
baijiahao: { id: "baijiahao", name: "百家号", shortName: "百", accent: "#31445a" },
|
||||
sohuhao: { id: "sohuhao", name: "搜狐号", shortName: "搜", accent: "#fa8c16" },
|
||||
qiehao: { id: "qiehao", name: "企鹅号", shortName: "Q", accent: "#111827" },
|
||||
zhihu: { id: "zhihu", name: "知乎", shortName: "知", accent: "#1677ff" },
|
||||
wangyihao: { id: "wangyihao", name: "网易号", shortName: "网", accent: "#ff4d4f" },
|
||||
jianshu: { id: "jianshu", name: "简书", shortName: "简", accent: "#f56a5e" },
|
||||
bilibili: { id: "bilibili", name: "bilibili", shortName: "B", accent: "#eb2f96" },
|
||||
juejin: { id: "juejin", name: "稀土掘金", shortName: "掘", accent: "#1677ff" },
|
||||
smzdm: { id: "smzdm", name: "什么值得买", shortName: "值", accent: "#f5222d" },
|
||||
weixin_gzh: { id: "weixin_gzh", name: "微信公众号", shortName: "微", accent: "#13c26b" },
|
||||
zol: { id: "zol", name: "中关村在线", shortName: "Z", accent: "#ff4d4f" },
|
||||
dongchedi: { id: "dongchedi", name: "懂车帝", shortName: "懂", accent: "#fadb14" },
|
||||
};
|
||||
const platformCatalog: Record<string, Omit<PublishPlatformOption, 'accountLabel' | 'bound'>> = {
|
||||
toutiaohao: { id: 'toutiaohao', name: '头条号', shortName: '头', accent: '#f5222d' },
|
||||
baijiahao: { id: 'baijiahao', name: '百家号', shortName: '百', accent: '#31445a' },
|
||||
sohuhao: { id: 'sohuhao', name: '搜狐号', shortName: '搜', accent: '#fa8c16' },
|
||||
qiehao: { id: 'qiehao', name: '企鹅号', shortName: 'Q', accent: '#111827' },
|
||||
zhihu: { id: 'zhihu', name: '知乎', shortName: '知', accent: '#1677ff' },
|
||||
wangyihao: { id: 'wangyihao', name: '网易号', shortName: '网', accent: '#ff4d4f' },
|
||||
jianshu: { id: 'jianshu', name: '简书', shortName: '简', accent: '#f56a5e' },
|
||||
bilibili: { id: 'bilibili', name: 'bilibili', shortName: 'B', accent: '#eb2f96' },
|
||||
juejin: { id: 'juejin', name: '稀土掘金', shortName: '掘', accent: '#1677ff' },
|
||||
smzdm: { id: 'smzdm', name: '什么值得买', shortName: '值', accent: '#f5222d' },
|
||||
weixin_gzh: { id: 'weixin_gzh', name: '微信公众号', shortName: '微', accent: '#13c26b' },
|
||||
zol: { id: 'zol', name: '中关村在线', shortName: 'Z', accent: '#ff4d4f' },
|
||||
dongchedi: { id: 'dongchedi', name: '懂车帝', shortName: '懂', accent: '#fadb14' },
|
||||
}
|
||||
|
||||
const aiPlatformIds = new Set(["yuanbao", "kimi", "wenxin", "deepseek", "doubao", "qwen"]);
|
||||
const aiPlatformIds = new Set(['yuanbao', 'kimi', 'wenxin', 'deepseek', 'doubao', 'qwen'])
|
||||
|
||||
export function isAIPlatformId(platformId?: string | null): boolean {
|
||||
return aiPlatformIds.has(normalizePublishPlatformId(platformId));
|
||||
return aiPlatformIds.has(normalizePublishPlatformId(platformId))
|
||||
}
|
||||
|
||||
export function isPublishPlatformId(platformId?: string | null): boolean {
|
||||
const normalized = normalizePublishPlatformId(platformId);
|
||||
return Boolean(normalized) && !isAIPlatformId(normalized) && normalized in platformCatalog;
|
||||
const normalized = normalizePublishPlatformId(platformId)
|
||||
return Boolean(normalized) && !isAIPlatformId(normalized) && normalized in platformCatalog
|
||||
}
|
||||
|
||||
export function isMediaPublishAccount(account: DesktopAccountInfo): boolean {
|
||||
return !account.deleted_at && isPublishPlatformId(account.platform);
|
||||
return !account.deleted_at && isPublishPlatformId(account.platform)
|
||||
}
|
||||
|
||||
export function getPublishPlatformMeta(platformId: string): Omit<PublishPlatformOption, "accountLabel" | "bound"> {
|
||||
const normalized = normalizePublishPlatformId(platformId);
|
||||
const fallbackShortName = normalized.slice(0, 1).toUpperCase() || "?";
|
||||
export function getPublishPlatformMeta(
|
||||
platformId: string,
|
||||
): Omit<PublishPlatformOption, 'accountLabel' | 'bound'> {
|
||||
const normalized = normalizePublishPlatformId(platformId)
|
||||
const fallbackShortName = normalized.slice(0, 1).toUpperCase() || '?'
|
||||
|
||||
return platformCatalog[normalized] ?? {
|
||||
id: normalized,
|
||||
name: normalized || "--",
|
||||
shortName: fallbackShortName,
|
||||
accent: "#667085",
|
||||
};
|
||||
return (
|
||||
platformCatalog[normalized] ?? {
|
||||
id: normalized,
|
||||
name: normalized || '--',
|
||||
shortName: fallbackShortName,
|
||||
accent: '#667085',
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export function normalizePublishPlatformId(platformId?: string | null): string {
|
||||
return String(platformId ?? "").trim();
|
||||
return String(platformId ?? '').trim()
|
||||
}
|
||||
|
||||
export function normalizePublishPlatformIds(platformIds?: Array<string | null | undefined>): string[] {
|
||||
export function normalizePublishPlatformIds(
|
||||
platformIds?: Array<string | null | undefined>,
|
||||
): string[] {
|
||||
return Array.from(
|
||||
new Set(
|
||||
(platformIds ?? [])
|
||||
.map((item) => normalizePublishPlatformId(item))
|
||||
.filter(Boolean),
|
||||
),
|
||||
);
|
||||
new Set((platformIds ?? []).map((item) => normalizePublishPlatformId(item)).filter(Boolean)),
|
||||
)
|
||||
}
|
||||
|
||||
export function buildPublishPlatformOptions(
|
||||
@@ -73,46 +75,48 @@ export function buildPublishPlatformOptions(
|
||||
const boundPlatformIds = new Set(
|
||||
(accounts ?? [])
|
||||
.map((account) =>
|
||||
normalizePublishPlatformId("platform_id" in account ? account.platform_id : account.platform),
|
||||
normalizePublishPlatformId(
|
||||
'platform_id' in account ? account.platform_id : account.platform,
|
||||
),
|
||||
)
|
||||
.filter(Boolean),
|
||||
);
|
||||
)
|
||||
|
||||
return platforms.map((platform) => {
|
||||
const id = normalizePublishPlatformId(platform.platform_id);
|
||||
const id = normalizePublishPlatformId(platform.platform_id)
|
||||
return {
|
||||
id,
|
||||
name: platform.name,
|
||||
shortName: platform.short_name,
|
||||
accent: platform.accent_color,
|
||||
bound: boundPlatformIds.has(id),
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function serializeTargetPlatforms(platformIds: string[]): string | undefined {
|
||||
const next = normalizePublishPlatformIds(platformIds);
|
||||
return next.length ? next.join(",") : undefined;
|
||||
const next = normalizePublishPlatformIds(platformIds)
|
||||
return next.length ? next.join(',') : undefined
|
||||
}
|
||||
|
||||
export function parseTargetPlatforms(value?: string | null): string[] {
|
||||
if (!value) {
|
||||
return [];
|
||||
return []
|
||||
}
|
||||
|
||||
return normalizePublishPlatformIds(value.split(","));
|
||||
return normalizePublishPlatformIds(value.split(','))
|
||||
}
|
||||
|
||||
export function getPublishPlatformLabel(platformId: string): string {
|
||||
return getPublishPlatformMeta(platformId).name;
|
||||
return getPublishPlatformMeta(platformId).name
|
||||
}
|
||||
|
||||
export function formatPublishPlatformSummary(value?: string | null): string {
|
||||
const labels = parseTargetPlatforms(value).map(getPublishPlatformLabel);
|
||||
return labels.length ? labels.join("、") : "--";
|
||||
const labels = parseTargetPlatforms(value).map(getPublishPlatformLabel)
|
||||
return labels.length ? labels.join('、') : '--'
|
||||
}
|
||||
|
||||
export function formatPublishPlatformList(platformIds?: string[] | null): string {
|
||||
const labels = normalizePublishPlatformIds(platformIds ?? []).map(getPublishPlatformLabel);
|
||||
return labels.length ? labels.join("、") : "--";
|
||||
const labels = normalizePublishPlatformIds(platformIds ?? []).map(getPublishPlatformLabel)
|
||||
return labels.length ? labels.join('、') : '--'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user