chore(frontend): introduce prettier + eslint and prune unused code
Backend CI / Backend (push) Has been cancelled
Frontend CI / Frontend (push) Failing after 1m39s

- 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:
2026-05-01 20:39:09 +08:00
parent 21c7892ee4
commit 162abdc97c
258 changed files with 42261 additions and 37556 deletions
@@ -1,15 +1,15 @@
<script setup lang="ts">
import { MinusCircleFilled } from "@ant-design/icons-vue";
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
import { message, notification } from "ant-design-vue";
import type { ArticleDetail } from "@geo/shared-types";
import { computed, ref, watch, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { MinusCircleFilled } from '@ant-design/icons-vue'
import type { ArticleDetail } from '@geo/shared-types'
import { useMutation, useQuery, useQueryClient } from '@tanstack/vue-query'
import { message, notification } from 'ant-design-vue'
import { computed, ref, watch, watchEffect } from 'vue'
import { useI18n } from 'vue-i18n'
import CoverPickerModal from "@/components/CoverPickerModal.vue";
import { articlesApi, mediaApi, publishJobsApi, resolveApiURL, tenantAccountsApi } from "@/lib/api";
import { coverUploadRequired, deriveCoverFileName } from "@/lib/cover-requirements";
import { formatError } from "@/lib/errors";
import CoverPickerModal from '@/components/CoverPickerModal.vue'
import { articlesApi, mediaApi, publishJobsApi, resolveApiURL, tenantAccountsApi } from '@/lib/api'
import { coverUploadRequired, deriveCoverFileName } from '@/lib/cover-requirements'
import { formatError } from '@/lib/errors'
import {
accountInitial,
buildPublishAccountCards,
@@ -20,105 +20,105 @@ import {
healthLabel,
publishStateLabel,
type PublishAccountCard,
} from "@/lib/publish-account-cards";
} from '@/lib/publish-account-cards'
const props = defineProps<{
open: boolean;
articleId: number | null;
}>();
open: boolean
articleId: number | null
}>()
const emit = defineEmits<{
"update:open": [value: boolean];
published: [];
}>();
'update:open': [value: boolean]
published: []
}>()
const { t } = useI18n();
const queryClient = useQueryClient();
const { t } = useI18n()
const queryClient = useQueryClient()
const selectedAccountIds = ref<string[]>([]);
const coverEnabled = ref(false);
const coverAssetUrl = ref("");
const coverFileName = ref("");
const coverImageAssetId = ref<number | null>(null);
const coverPickerOpen = ref(false);
const selectionHydrated = ref(false);
const coverHydrated = ref(false);
const selectedAccountIds = ref<string[]>([])
const coverEnabled = ref(false)
const coverAssetUrl = ref('')
const coverFileName = ref('')
const coverImageAssetId = ref<number | null>(null)
const coverPickerOpen = ref(false)
const selectionHydrated = ref(false)
const coverHydrated = ref(false)
const detailQuery = useQuery({
queryKey: computed(() => ["articles", "detail", props.articleId, "publish-modal"]),
queryKey: computed(() => ['articles', 'detail', props.articleId, 'publish-modal']),
enabled: computed(() => props.open && Boolean(props.articleId)),
queryFn: () => articlesApi.detail(props.articleId as number),
});
})
const accountsQuery = useQuery({
queryKey: ["tenant", "desktop-accounts", "publish-modal"],
queryKey: ['tenant', 'desktop-accounts', 'publish-modal'],
enabled: computed(() => props.open),
queryFn: () => tenantAccountsApi.list(),
});
})
const platformsQuery = useQuery({
queryKey: ["media", "platforms", "publish-modal"],
queryKey: ['media', 'platforms', 'publish-modal'],
enabled: computed(() => props.open),
queryFn: () => mediaApi.platforms(),
});
})
watch(
() => props.open,
async (open) => {
if (!open) {
selectedAccountIds.value = [];
coverAssetUrl.value = "";
coverFileName.value = "";
coverImageAssetId.value = null;
coverEnabled.value = false;
selectionHydrated.value = false;
coverHydrated.value = false;
return;
selectedAccountIds.value = []
coverAssetUrl.value = ''
coverFileName.value = ''
coverImageAssetId.value = null
coverEnabled.value = false
selectionHydrated.value = false
coverHydrated.value = false
return
}
selectionHydrated.value = false;
coverHydrated.value = false;
selectionHydrated.value = false
coverHydrated.value = false
await Promise.allSettled([
props.articleId ? detailQuery.refetch() : Promise.resolve(),
accountsQuery.refetch(),
platformsQuery.refetch(),
]);
])
},
{ immediate: true },
);
)
const platformMap = computed(() => buildPublishPlatformMap(platformsQuery.data.value ?? []));
const platformMap = computed(() => buildPublishPlatformMap(platformsQuery.data.value ?? []))
const accountCards = computed<PublishAccountCard[]>(() =>
buildPublishAccountCards(accountsQuery.data.value ?? [], platformMap.value),
);
)
watch(
accountCards,
(cards) => {
const selectableIds = new Set(cards.filter((card) => card.selectable).map((card) => card.id));
selectedAccountIds.value = selectedAccountIds.value.filter((id) => selectableIds.has(id));
const selectableIds = new Set(cards.filter((card) => card.selectable).map((card) => card.id))
selectedAccountIds.value = selectedAccountIds.value.filter((id) => selectableIds.has(id))
},
{ immediate: true },
);
)
watchEffect(() => {
if (!props.open) {
return;
return
}
if (!coverHydrated.value && !detailQuery.isPending.value && !detailQuery.isFetching.value) {
const initialUrl = resolveApiURL(detailQuery.data.value?.cover_asset_url);
coverAssetUrl.value = initialUrl;
coverFileName.value = deriveCoverFileName(initialUrl);
coverImageAssetId.value = detailQuery.data.value?.cover_image_asset_id ?? null;
coverEnabled.value = Boolean(initialUrl);
coverHydrated.value = true;
const initialUrl = resolveApiURL(detailQuery.data.value?.cover_asset_url)
coverAssetUrl.value = initialUrl
coverFileName.value = deriveCoverFileName(initialUrl)
coverImageAssetId.value = detailQuery.data.value?.cover_image_asset_id ?? null
coverEnabled.value = Boolean(initialUrl)
coverHydrated.value = true
}
if (selectionHydrated.value) {
return;
return
}
if (
@@ -129,163 +129,176 @@ watchEffect(() => {
platformsQuery.isPending.value ||
platformsQuery.isFetching.value
) {
return;
return
}
selectedAccountIds.value = [];
selectionHydrated.value = true;
});
selectedAccountIds.value = []
selectionHydrated.value = true
})
const selectedCards = computed(() => {
const selected = new Set(selectedAccountIds.value);
return accountCards.value.filter((card) => selected.has(card.id));
});
const selected = new Set(selectedAccountIds.value)
return accountCards.value.filter((card) => selected.has(card.id))
})
const modalTitle = computed(() => detailQuery.data.value?.title || t("article.untitled"));
const selectedPlatformIds = computed(() => Array.from(new Set(selectedCards.value.map((card) => card.platformId))));
const selectedImmediateCount = computed(() => selectedCards.value.filter((card) => card.publishState === "immediate").length);
const selectedQueuedCount = computed(() => selectedCards.value.filter((card) => card.publishState === "queued").length);
const publishModalVisible = computed(() => props.open && !coverPickerOpen.value);
const coverRequired = computed(() => coverUploadRequired(selectedPlatformIds.value));
const effectiveCoverEnabled = computed(() => coverRequired.value || coverEnabled.value);
const normalizedCoverValue = computed(() => (effectiveCoverEnabled.value ? coverAssetUrl.value.trim() : ""));
const modalTitle = computed(() => detailQuery.data.value?.title || t('article.untitled'))
const selectedPlatformIds = computed(() =>
Array.from(new Set(selectedCards.value.map((card) => card.platformId))),
)
const selectedImmediateCount = computed(
() => selectedCards.value.filter((card) => card.publishState === 'immediate').length,
)
const selectedQueuedCount = computed(
() => selectedCards.value.filter((card) => card.publishState === 'queued').length,
)
const publishModalVisible = computed(() => props.open && !coverPickerOpen.value)
const coverRequired = computed(() => coverUploadRequired(selectedPlatformIds.value))
const effectiveCoverEnabled = computed(() => coverRequired.value || coverEnabled.value)
const normalizedCoverValue = computed(() =>
effectiveCoverEnabled.value ? coverAssetUrl.value.trim() : '',
)
watch(
coverRequired,
(required) => {
if (required) {
coverEnabled.value = true;
coverEnabled.value = true
}
},
{ immediate: true },
);
)
const publishMutation = useMutation({
mutationFn: async () => {
if (!props.articleId || !detailQuery.data.value) {
throw new Error("missing_article");
throw new Error('missing_article')
}
if (!selectedAccountIds.value.length) {
throw new Error("no_accounts_selected");
throw new Error('no_accounts_selected')
}
if (coverRequired.value && !normalizedCoverValue.value) {
throw new Error("cover_required_for_selected_platforms");
throw new Error('cover_required_for_selected_platforms')
}
const article = await persistCoverIfNeeded(detailQuery.data.value);
const article = await persistCoverIfNeeded(detailQuery.data.value)
return publishJobsApi.create({
title: article.title?.trim() || t("article.untitled"),
title: article.title?.trim() || t('article.untitled'),
content_ref: {
article_id: article.id,
},
accounts: selectedAccountIds.value.map((accountId) => ({
account_id: accountId,
})),
});
})
},
onSuccess: async () => {
notification.success({
message: "已提交发布任务",
message: '已提交发布任务',
description: successDescription(),
placement: "topRight",
placement: 'topRight',
duration: 5,
});
})
await Promise.all([
queryClient.invalidateQueries({ queryKey: ["articles"] }),
queryClient.invalidateQueries({ queryKey: ["workspace"] }),
queryClient.invalidateQueries({ queryKey: ["tenant", "desktop-accounts"] }),
queryClient.invalidateQueries({ queryKey: ["articles", "detail", props.articleId] }),
queryClient.invalidateQueries({ queryKey: ["articles", "detail", props.articleId, "publish-modal"] }),
queryClient.invalidateQueries({ queryKey: ["articles", "publish-records", props.articleId] }),
]);
queryClient.invalidateQueries({ queryKey: ['articles'] }),
queryClient.invalidateQueries({ queryKey: ['workspace'] }),
queryClient.invalidateQueries({ queryKey: ['tenant', 'desktop-accounts'] }),
queryClient.invalidateQueries({ queryKey: ['articles', 'detail', props.articleId] }),
queryClient.invalidateQueries({
queryKey: ['articles', 'detail', props.articleId, 'publish-modal'],
}),
queryClient.invalidateQueries({ queryKey: ['articles', 'publish-records', props.articleId] }),
])
emit("published");
emit("update:open", false);
emit('published')
emit('update:open', false)
},
onError: (error) => {
const normalized = error instanceof Error ? error.message : "";
if (normalized === "no_accounts_selected") {
message.warning("请先选择至少一个可发布账号");
return;
const normalized = error instanceof Error ? error.message : ''
if (normalized === 'no_accounts_selected') {
message.warning('请先选择至少一个可发布账号')
return
}
if (normalized === "cover_required_for_selected_platforms") {
message.warning(t("media.publish.messages.coverRequired"));
return;
if (normalized === 'cover_required_for_selected_platforms') {
message.warning(t('media.publish.messages.coverRequired'))
return
}
message.error(formatError(error));
message.error(formatError(error))
},
});
})
async function persistCoverIfNeeded(detail: ArticleDetail): Promise<ArticleDetail> {
const currentUrl = resolveApiURL(detail.cover_asset_url).trim();
const nextUrl = normalizedCoverValue.value.trim();
const currentAssetId = detail.cover_image_asset_id ?? null;
const currentUrl = resolveApiURL(detail.cover_asset_url).trim()
const nextUrl = normalizedCoverValue.value.trim()
const currentAssetId = detail.cover_image_asset_id ?? null
if (currentUrl === nextUrl && currentAssetId === coverImageAssetId.value) {
return detail;
return detail
}
return articlesApi.update(detail.id, {
title: detail.title?.trim() || t("article.untitled"),
markdown_content: detail.markdown_content ?? "",
title: detail.title?.trim() || t('article.untitled'),
markdown_content: detail.markdown_content ?? '',
cover_asset_url: nextUrl || null,
cover_image_asset_id: coverImageAssetId.value,
});
})
}
function successDescription(): string {
const total = selectedCards.value.length;
const total = selectedCards.value.length
if (total === 0) {
return "任务已进入发布队列。";
return '任务已进入发布队列。'
}
if (selectedQueuedCount.value === 0) {
return `${total} 个账号,在线客户端会立即开始消费。`;
return `${total} 个账号,在线客户端会立即开始消费。`
}
if (selectedImmediateCount.value === 0) {
return `${total} 个账号已进入离线队列,客户端上线后会自动继续发布。`;
return `${total} 个账号已进入离线队列,客户端上线后会自动继续发布。`
}
return `${total} 个账号:${selectedImmediateCount.value} 个立即发布,${selectedQueuedCount.value} 个离线排队。`;
return `${total} 个账号:${selectedImmediateCount.value} 个立即发布,${selectedQueuedCount.value} 个离线排队。`
}
function toggleAccount(accountId: string, selectable: boolean): void {
if (!selectable || publishMutation.isPending.value) {
return;
return
}
if (selectedAccountIds.value.includes(accountId)) {
selectedAccountIds.value = selectedAccountIds.value.filter((id) => id !== accountId);
return;
selectedAccountIds.value = selectedAccountIds.value.filter((id) => id !== accountId)
return
}
selectedAccountIds.value = [...selectedAccountIds.value, accountId];
selectedAccountIds.value = [...selectedAccountIds.value, accountId]
}
function isSelected(accountId: string): boolean {
return selectedAccountIds.value.includes(accountId);
return selectedAccountIds.value.includes(accountId)
}
function handleCoverToggle(checked: boolean): void {
if (coverRequired.value) {
coverEnabled.value = true;
return;
coverEnabled.value = true
return
}
coverEnabled.value = checked;
coverEnabled.value = checked
}
function handleCoverPicked(payload: { url: string; fileName: string; assetId?: number | null }): void {
coverAssetUrl.value = payload.url;
coverFileName.value = payload.fileName;
coverImageAssetId.value = payload.assetId ?? null;
coverEnabled.value = true;
function handleCoverPicked(payload: {
url: string
fileName: string
assetId?: number | null
}): void {
coverAssetUrl.value = payload.url
coverFileName.value = payload.fileName
coverImageAssetId.value = payload.assetId ?? null
coverEnabled.value = true
}
function handleRemoveCover(): void {
coverAssetUrl.value = "";
coverFileName.value = "";
coverImageAssetId.value = null;
coverAssetUrl.value = ''
coverFileName.value = ''
coverImageAssetId.value = null
}
</script>
<template>
@@ -304,7 +317,10 @@ function handleRemoveCover(): void {
<div>
<span class="publish-modal__eyebrow">发布标题</span>
<h3>{{ modalTitle }}</h3>
<p>在线账号会立即消费离线账号会自动排队数据库保留任务真相RabbitMQ 负责唤醒在线客户端</p>
<p>
在线账号会立即消费离线账号会自动排队数据库保留任务真相RabbitMQ
负责唤醒在线客户端
</p>
</div>
<div class="publish-modal__hero-metrics">
@@ -325,11 +341,19 @@ function handleRemoveCover(): void {
<section class="publish-modal__section">
<div class="publish-modal__section-header">
<h3><span class="required-star">*</span> 目标账号</h3>
<p class="muted">优先预选文章里已经勾选的平台账号支持同平台多账号授权异常或未绑定桌面客户端的账号不可选</p>
<h3>
<span class="required-star">*</span>
目标账号
</h3>
<p class="muted">
优先预选文章里已经勾选的平台账号支持同平台多账号授权异常或未绑定桌面客户端的账号不可选
</p>
</div>
<div v-if="accountsQuery.isPending.value || platformsQuery.isPending.value" class="publish-modal__loading">
<div
v-if="accountsQuery.isPending.value || platformsQuery.isPending.value"
class="publish-modal__loading"
>
<a-skeleton active :paragraph="{ rows: 5 }" />
</div>
@@ -348,12 +372,20 @@ function handleRemoveCover(): void {
<div class="publish-modal__card-header">
<div class="publish-modal__card-identity">
<span class="publish-modal__avatar" :style="{ background: account.platformAccent }">
<img v-if="account.avatarUrl" :src="account.avatarUrl" :alt="account.displayName" referrerpolicy="no-referrer" />
<img
v-if="account.avatarUrl"
:src="account.avatarUrl"
:alt="account.displayName"
referrerpolicy="no-referrer"
/>
<span v-else>{{ accountInitial(account) }}</span>
</span>
<div class="publish-modal__identity-copy">
<strong :title="account.displayName">{{ account.displayName }}</strong>
<span class="publish-modal__platform-line" :title="`${account.platformName} · ${account.platformUid}`">
<span
class="publish-modal__platform-line"
:title="`${account.platformName} · ${account.platformUid}`"
>
<img
v-if="account.platformLogoUrl"
class="publish-modal__platform-logo"
@@ -365,8 +397,12 @@ function handleRemoveCover(): void {
v-else
class="publish-modal__platform-logo publish-modal__platform-logo--fallback"
:style="{ background: account.platformAccent }"
>{{ account.platformShortName }}</span>
<span class="publish-modal__platform-text">{{ account.platformName }} · {{ account.platformUid }}</span>
>
{{ account.platformShortName }}
</span>
<span class="publish-modal__platform-text">
{{ account.platformName }} · {{ account.platformUid }}
</span>
</span>
</div>
</div>
@@ -377,12 +413,17 @@ function handleRemoveCover(): void {
<div class="publish-modal__card-footer">
<div class="publish-modal__tags">
<a-tag :color="healthColor(account.health)">{{ healthLabel(account.health) }}</a-tag>
<a-tag :color="healthColor(account.health)">
{{ healthLabel(account.health) }}
</a-tag>
<a-tag :color="clientStatusColor(account)">{{ clientStatusLabel(account) }}</a-tag>
</div>
<a-tooltip :title="account.statusText" placement="top">
<span class="publish-modal__state-pill" :class="`publish-modal__state-pill--${account.publishState}`">
<span
class="publish-modal__state-pill"
:class="`publish-modal__state-pill--${account.publishState}`"
>
{{ publishStateLabel(account.publishState) }}
</span>
</a-tooltip>
@@ -396,21 +437,33 @@ function handleRemoveCover(): void {
<section class="publish-modal__section">
<div class="publish-modal__section-header publish-modal__section-header--inline">
<h3>封面图</h3>
<a-switch :checked="effectiveCoverEnabled" :disabled="coverRequired" @change="handleCoverToggle" />
<a-switch
:checked="effectiveCoverEnabled"
:disabled="coverRequired"
@change="handleCoverToggle"
/>
</div>
<p class="muted">
{{ coverRequired ? t("media.publish.messages.coverRequired") : "默认关闭。需要时可在这里单独指定发布封面,并先写回文章。" }}
{{
coverRequired
? t('media.publish.messages.coverRequired')
: '默认关闭。需要时可在这里单独指定发布封面,并先写回文章。'
}}
</p>
<div v-if="effectiveCoverEnabled" class="publish-modal__cover-body">
<div class="publish-modal__cover-preview-wrap">
<button type="button" class="publish-modal__cover-preview" @click="coverPickerOpen = true">
<button
type="button"
class="publish-modal__cover-preview"
@click="coverPickerOpen = true"
>
<template v-if="coverAssetUrl">
<img :src="coverAssetUrl" alt="cover preview" />
</template>
<template v-else>
<span class="publish-modal__cover-plus">+</span>
<span>{{ t("media.publish.coverUpload") }}</span>
<span>{{ t('media.publish.coverUpload') }}</span>
</template>
</button>
@@ -456,7 +509,9 @@ function handleRemoveCover(): void {
border: 1px solid #e5e7eb;
border-radius: 12px;
background: #ffffff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.02), 0 4px 8px -2px rgba(0, 0, 0, 0.02);
box-shadow:
0 1px 3px 0 rgba(0, 0, 0, 0.02),
0 4px 8px -2px rgba(0, 0, 0, 0.02);
}
.publish-modal__eyebrow {
@@ -598,7 +653,9 @@ function handleRemoveCover(): void {
.publish-modal__card:hover:not(.publish-modal__card--disabled) {
border-color: #d1d5db;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
box-shadow:
0 4px 6px -1px rgba(0, 0, 0, 0.08),
0 2px 4px -1px rgba(0, 0, 0, 0.04);
transform: translateY(-2px);
}
@@ -609,7 +666,9 @@ function handleRemoveCover(): void {
}
.publish-modal__card--active:hover:not(.publish-modal__card--disabled) {
box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.15), 0 0 0 1px #3b82f6;
box-shadow:
0 4px 6px -1px rgba(59, 130, 246, 0.15),
0 0 0 1px #3b82f6;
}
.publish-modal__card--disabled {
@@ -692,7 +751,7 @@ function handleRemoveCover(): void {
font-weight: 600;
overflow: hidden;
flex-shrink: 0;
box-shadow: inset 0 0 0 1px rgba(0,0,0,0.05);
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}
.publish-modal__avatar img {