Files
geo/apps/desktop-client/src/renderer/views/AccountsView.vue
T

786 lines
20 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import { computed, ref } from "vue";
import { SearchOutlined, ReloadOutlined, ApiOutlined, ArrowRightOutlined, LinkOutlined, DeleteOutlined, EllipsisOutlined } from "@ant-design/icons-vue";
import StatusBadge from "../components/StatusBadge.vue";
import SurfaceCard from "../components/SurfaceCard.vue";
import { useDesktopRuntime } from "../composables/useDesktopRuntime";
import { showClientActionError } from "../lib/client-errors";
import { formatDateTime, titleCaseToken } from "../lib/formatters";
import { desktopPublishMediaCatalog } from "../lib/media-catalog";
import type { RuntimeAccount } from "../types";
const { snapshot, refresh, loading } = useDesktopRuntime();
const selectedPlatform = ref("all");
const selectedStatus = ref("all");
const searchQuery = ref("");
const bindPendingPlatformId = ref<string | null>(null);
const consolePendingAccountId = ref<string | null>(null);
const actionSuccess = ref<string | null>(null);
type AccountAuthState = "authorized" | "expired" | "attention" | "risk";
type AccountRow = Readonly<Omit<RuntimeAccount, "tags">> & { tags: readonly string[] };
const clientsById = computed(
() => new Map((snapshot.value?.clients ?? []).map((item) => [item.id, item])),
);
const accounts = computed(() => snapshot.value?.accounts ?? []);
const overview = computed(() => ({
authorized: accounts.value.filter((item) => item.health === "live").length,
attention: accounts.value.filter((item) => item.health === "captcha").length,
risk: accounts.value.filter((item) => item.health === "risk").length,
onlineClients: snapshot.value?.summary.onlineClients ?? 0,
}));
const platformCards = computed(() =>
desktopPublishMediaCatalog.map((platform) => {
const matched = accounts.value.filter((account) => account.platform === platform.id);
return {
...platform,
count: matched.length,
latestAccount: matched[0] ?? null,
};
}),
);
const statusOptions = [
{ value: "all", label: "全部状态" },
{ value: "authorized", label: "已授权" },
{ value: "attention", label: "待处理" },
{ value: "risk", label: "风险观察" },
{ value: "expired", label: "授权过期" },
] as const;
function platformMeta(platform: string) {
return (
desktopPublishMediaCatalog.find((item) => item.id === platform) ?? {
id: platform,
label: titleCaseToken(platform),
shortName: titleCaseToken(platform).slice(0, 1),
accent: "#64748b",
loginUrl: null,
logoUrl: null,
category: "publish",
description: "待接入平台",
}
);
}
function authState(account: AccountRow): AccountAuthState {
switch (account.health) {
case "live":
return "authorized";
case "expired":
return "expired";
case "captcha":
return "attention";
default:
return "risk";
}
}
function authStateLabel(account: AccountRow): string {
switch (authState(account)) {
case "authorized":
return "已授权";
case "expired":
return "授权过期";
case "attention":
return "待补登";
default:
return "风险观察";
}
}
function authStateTone(account: AccountRow) {
switch (authState(account)) {
case "authorized":
return "success" as const;
case "expired":
return "danger" as const;
case "attention":
return "warn" as const;
default:
return "info" as const;
}
}
function accountInitial(account: AccountRow): string {
return account.displayName.slice(0, 1).toUpperCase();
}
const filteredAccounts = computed(() => {
const keyword = searchQuery.value.trim().toLowerCase();
return accounts.value.filter((account) => {
if (selectedPlatform.value !== "all" && account.platform !== selectedPlatform.value) {
return false;
}
if (selectedStatus.value !== "all" && authState(account) !== selectedStatus.value) {
return false;
}
if (!keyword) {
return true;
}
const clientName = clientsById.value.get(account.clientId)?.deviceName ?? account.clientId;
const haystack = [
account.displayName,
account.platformUid,
platformMeta(account.platform).label,
clientName,
]
.join(" ")
.toLowerCase();
return haystack.includes(keyword);
});
});
function selectPlatform(platform: string) {
selectedPlatform.value = platform;
}
function resetFilters() {
selectedPlatform.value = "all";
selectedStatus.value = "all";
searchQuery.value = "";
}
async function bindPlatform(platformId: string) {
bindPendingPlatformId.value = platformId;
actionSuccess.value = null;
try {
const account = await window.desktopBridge.app.bindPublishAccount(platformId);
selectedPlatform.value = platformId;
actionSuccess.value = `${account.display_name} 已绑定到 ${platformMeta(platformId).label}`;
await refresh();
} catch (error) {
showClientActionError("bind-account", error);
} finally {
bindPendingPlatformId.value = null;
}
}
async function openConsole(account: AccountRow) {
consolePendingAccountId.value = account.id;
try {
await window.desktopBridge.app.openPublishAccountConsole({
id: account.id,
platform: account.platform,
platformUid: account.platformUid,
displayName: account.displayName,
});
} catch (error) {
showClientActionError("open-console", error);
} finally {
consolePendingAccountId.value = null;
}
}
const tableColumns = [
{ title: "昵称", key: "name", dataIndex: "name" },
{ title: "平台", key: "platform", dataIndex: "platform" },
{ title: "授权状态", key: "status", dataIndex: "status" },
{ title: "归属客户端", key: "client", dataIndex: "client" },
{ title: "授权时间", key: "syncTime", dataIndex: "syncTime" },
{ title: "操作", key: "actions", align: "right" as const }
];
</script>
<template>
<section class="media-view">
<section class="media-view__top-card">
<div class="media-view__header">
<div class="media-view__header-title">
<h2>账号管理</h2>
<p>先把平台授权跑通上面直接发起真实登录绑定下面看已授权账号状态和进入创作台入口</p>
</div>
<div class="media-view__header-actions">
<a-button :loading="loading" @click="refresh">
<template #icon><ReloadOutlined /></template>
刷新状态
</a-button>
</div>
</div>
<div class="overview-strip border-t">
<div class="overview-chip">
<span>已授权</span>
<strong>{{ overview.authorized }}</strong>
</div>
<div class="overview-chip">
<span>待处理</span>
<strong>{{ overview.attention }}</strong>
</div>
<div class="overview-chip">
<span>风险观察</span>
<strong>{{ overview.risk }}</strong>
</div>
<div class="overview-chip">
<span>在线客户端</span>
<strong>{{ overview.onlineClients }}</strong>
</div>
</div>
</section>
<section class="media-list-wrapper panel">
<div class="media-list-content">
<h4 class="media-list-title">选择平台进行授权</h4>
<p class="media-list-desc">点击平台即可发起真实登录登录成功后自动探测账号并回写到当前 desktop client</p>
<section class="media-grid">
<article
v-for="platform in platformCards"
:key="platform.id"
class="media-card"
:class="[
selectedPlatform === platform.id ? 'media-card--active' : '',
platform.latestAccount ? 'media-card--success' : 'media-card--default'
]"
@click="selectPlatform(platform.id)"
>
<div class="media-card__head">
<div class="media-card__identity">
<span class="media-card__badge" :style="{ color: platform.accent }">
<img v-if="platform.logoUrl" :src="platform.logoUrl" :alt="platform.label" style="width: 20px; height: 20px; object-fit: contain;" />
<span v-else>{{ platform.shortName }}</span>
</span>
<div class="media-card__identity-text">
<h3>{{ platform.label }}</h3>
<p>{{ platform.count > 0 ? `${platform.count} 个账号` : "未绑定" }}</p>
</div>
</div>
</div>
<div class="media-card__footer">
<div class="media-card__status">
<span v-if="platform.latestAccount" class="status-dot success"></span>
<span v-else class="status-dot default"></span>
<span class="status-text">{{ platform.latestAccount ? '已接入' : '待接入' }}</span>
</div>
<div class="media-card__actions">
<a-button
v-if="platform.count > 0"
class="action-btn-publish"
:loading="bindPendingPlatformId === platform.id"
@click.stop="bindPlatform(platform.id)"
>
新增账号 <ApiOutlined />
</a-button>
<a-button
v-else
class="action-btn-bind"
:loading="bindPendingPlatformId === platform.id"
@click.stop="bindPlatform(platform.id)"
>
绑定账号 <ArrowRightOutlined />
</a-button>
</div>
</div>
</article>
</section>
</div>
</section>
<div class="panel list-panel">
<div class="table-header">
<h3 class="panel-title">授权账号列表</h3>
<p class="panel-desc">当前共 {{ filteredAccounts.length }} 个媒体账号支持重新授权和直接进入创作台</p>
<div class="media-list-toolbar">
<div class="toolbar-filters">
<a-select
v-model:value="selectedPlatform"
style="width: 160px"
>
<a-select-option value="all">所有平台</a-select-option>
<a-select-option v-for="platform in platformCards" :key="platform.id" :value="platform.id">
{{ platform.label }}
</a-select-option>
</a-select>
<a-select
v-model:value="selectedStatus"
style="width: 160px"
>
<a-select-option v-for="option in statusOptions" :key="option.value" :value="option.value">
{{ option.label }}
</a-select-option>
</a-select>
<a-input
v-model:value="searchQuery"
placeholder="搜索昵称、UID、平台或客户端"
style="width: 280px"
allow-clear
>
<template #prefix>
<SearchOutlined style="color: #bfbfbf" />
</template>
</a-input>
</div>
</div>
</div>
<a-table
class="modern-table"
:columns="tableColumns"
:data-source="filteredAccounts"
:pagination="false"
>
<template #emptyText>
<a-empty description="暂无匹配账号" />
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'name'">
<div class="cell-primary-secondary">
<div class="user-avatar-wrap">
<span class="avatar-circle" :style="{ background: platformMeta(record.platform).accent }">
<img v-if="record.avatarUrl" :src="record.avatarUrl" :alt="record.displayName" />
<span v-else class="avatar-initial">{{ accountInitial(record) }}</span>
</span>
<div class="info-stack">
<span class="title">{{ record.displayName }}</span>
<span class="subtitle">{{ record.platformUid }}</span>
</div>
</div>
</div>
</template>
<template v-else-if="column.key === 'platform'">
<div class="platform-display">
<span class="platform-logo-mini">
<img v-if="platformMeta(record.platform).logoUrl" :src="platformMeta(record.platform).logoUrl!" />
<span v-else :style="{ color: platformMeta(record.platform).accent, fontWeight: 600 }">
{{ platformMeta(record.platform).shortName }}
</span>
</span>
<span>{{ platformMeta(record.platform).label }}</span>
</div>
</template>
<template v-else-if="column.key === 'status'">
<a-tag :color="record.health === 'live' ? 'green' : record.health === 'expired' ? 'red' : record.health === 'captcha' ? 'orange' : 'default'">
{{ authStateLabel(record) }}
</a-tag>
</template>
<template v-else-if="column.key === 'client'">
<div class="cell-primary-secondary">
<div class="info-stack">
<span class="title">{{ clientsById.get(record.clientId)?.deviceName ?? record.clientId }}</span>
<span class="subtitle">{{ record.online ? "在线" : "离线" }}</span>
</div>
</div>
</template>
<template v-else-if="column.key === 'syncTime'">
<div class="cell-primary-secondary">
<div class="info-stack">
<span class="title">{{ formatDateTime(record.lastSyncAt) }}</span>
<span class="subtitle">{{ record.partition }}</span>
</div>
</div>
</template>
<template v-else-if="column.key === 'actions'">
<div class="action-buttons">
<a-button
type="primary"
size="small"
:loading="consolePendingAccountId === record.id"
@click="openConsole(record)"
>
创作台
</a-button>
<a-button
size="small"
:loading="bindPendingPlatformId === record.platform"
@click="bindPlatform(record.platform)"
>
重新授权
</a-button>
</div>
</template>
</template>
</a-table>
</div>
</section>
</template>
<style scoped>
.media-view {
display: flex;
flex-direction: column;
gap: 20px;
}
.media-view__top-card {
background: #fff;
border: 1px solid #e6edf5;
border-radius: 12px;
overflow: hidden;
}
.media-view__header {
display: flex;
justify-content: space-between;
align-items: flex-start;
padding: 24px;
}
.media-view__header-title h2 {
margin: 0;
font-size: 20px;
font-weight: 600;
color: #1a1a1a;
line-height: 1.4;
}
.media-view__header-title p {
margin: 6px 0 0 0;
font-size: 13px;
color: #8c8c8c;
}
.media-view__header-actions {
display: flex;
gap: 12px;
}
.overview-strip {
display: flex;
background: #fafafb;
padding: 16px 24px;
gap: 32px;
}
.border-t {
border-top: 1px solid #e6edf5;
}
.overview-chip {
display: flex;
flex-direction: column;
}
.overview-chip span {
font-size: 13px;
color: #595959;
}
.overview-chip strong {
margin-top: 4px;
font-size: 24px;
font-weight: 600;
color: #1a1a1a;
line-height: 1.2;
}
.panel {
background: #ffffff;
border-radius: 12px;
border: 1px solid #e6edf5;
display: flex;
flex-direction: column;
}
.media-list-wrapper {
overflow: hidden;
}
.media-list-content {
padding: 24px;
}
.media-list-title {
font-size: 16px;
font-weight: 600;
color: #1a1a1a;
margin-bottom: 4px;
}
.media-list-desc {
font-size: 13px;
color: #8c8c8c;
margin-bottom: 20px;
}
.media-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 16px;
}
.media-card {
position: relative;
overflow: hidden;
padding: 16px;
border: 1px solid #e6edf5;
border-radius: 12px;
background: #fff;
transition: all 0.2s ease;
display: flex;
flex-direction: column;
cursor: pointer;
}
.media-card:hover {
transform: translateY(-2px);
box-shadow: 0 12px 24px rgba(31, 41, 55, 0.08);
border-color: #1677ff;
}
.media-card--active {
border-color: #1677ff;
background: #f0f7ff;
}
.media-card__head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.media-card__identity {
display: flex;
align-items: center;
gap: 12px;
}
.media-card__badge {
display: inline-flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border-radius: 10px;
background: #ffffff;
border: 1px solid #f0f0f0;
box-shadow: 0 2px 4px rgba(0,0,0,0.02);
font-size: 18px;
font-weight: 700;
}
.media-card__identity-text {
display: flex;
flex-direction: column;
}
.media-card__identity-text h3 {
margin: 0;
color: #1a1a1a;
font-size: 15px;
font-weight: 600;
}
.media-card__identity-text p {
margin: 2px 0 0;
color: #8c8c8c;
font-size: 12px;
}
.media-card__footer {
margin-top: 20px;
display: flex;
align-items: center;
justify-content: space-between;
}
.media-card__status {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: #8c8c8c;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.status-dot.success { background-color: #52c41a; }
.status-dot.default { background-color: #d9d9d9; }
.action-btn-bind {
border-radius: 6px;
font-size: 13px;
color: #fff;
background: #1677ff;
border: 1px solid #1677ff;
height: 32px;
padding: 0 12px;
display: flex;
align-items: center;
gap: 6px;
}
.action-btn-bind:hover {
background: #4096ff;
color: #fff;
border-color: #4096ff;
}
.action-btn-publish {
border-radius: 6px;
font-size: 13px;
color: #1677ff;
background: #e6f4ff;
border: 1px solid #91caff;
height: 32px;
padding: 0 12px;
display: flex;
align-items: center;
gap: 6px;
}
.action-btn-publish:hover {
background: #bae0ff;
color: #1677ff;
border-color: #69b1ff;
}
/* Table Card Panel */
.list-panel {
padding-bottom: 24px;
}
.table-header {
padding: 24px;
border-bottom: 1px solid #e6edf5;
}
.panel-title {
margin: 0;
font-size: 16px;
font-weight: 600;
color: #1a1a1a;
}
.panel-desc {
margin: 4px 0 0;
font-size: 13px;
color: #8c8c8c;
}
.media-list-toolbar {
margin-top: 16px;
display: flex;
justify-content: space-between;
align-items: center;
}
.toolbar-filters {
display: flex;
align-items: center;
gap: 12px;
}
/* Modern Enterprise Table Styles */
:deep(.modern-table) {
padding: 0 24px;
}
:deep(.modern-table .ant-table-thead > tr > th) {
background-color: #fcfcfd !important;
color: #4b5563;
font-weight: 600;
border-bottom: 1px solid #f3f4f6;
padding: 12px 16px;
}
:deep(.modern-table .ant-table-tbody > tr > td) {
padding: 16px;
border-bottom: 1px solid #f3f4f6;
color: #1f2937;
}
:deep(.modern-table .ant-table-tbody > tr:last-child > td) {
border-bottom: none;
}
:deep(.modern-table .ant-table-tbody > tr:hover > td) {
background-color: #f9fafb !important;
}
.cell-primary-secondary {
display: flex;
flex-direction: column;
}
.info-stack {
display: flex;
flex-direction: column;
}
.info-stack .title {
font-weight: 500;
color: #1f2937;
font-size: 14px;
}
.info-stack .subtitle {
color: #6b7280;
font-size: 12px;
margin-top: 2px;
}
.user-avatar-wrap {
display: flex;
align-items: center;
gap: 12px;
}
.avatar-circle {
width: 36px;
height: 36px;
border-radius: 50%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.avatar-circle img {
width: 100%;
height: 100%;
object-fit: cover;
}
.avatar-initial {
color: #fff;
font-weight: 600;
}
.platform-display {
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
color: #4b5563;
}
.platform-logo-mini {
width: 24px;
height: 24px;
background: #f3f4f6;
border-radius: 6px;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.platform-logo-mini img {
width: 16px;
height: 16px;
object-fit: contain;
}
.action-buttons {
display: flex;
gap: 8px;
justify-content: flex-end;
}
</style>