import { useEffect, useMemo, useState } from "react"; import { Link, useNavigate, useParams } from "react-router"; import { useDataProvider, useList, useOne } from "@refinedev/core"; import { Alert, Button, Card, CardContent, ConfirmDialog, DetailList, Field, Input, PageHeader, PageState, Modal, Select, StatusPill, Table, TagInput, Textarea, conflictMessage, } from "./lib/ui.jsx"; import { useTitle } from "./lib/hooks.js"; const createInitial = { name: "", platform: "", platform_account_key: "", tags: [], cookies: "", }; const platforms = [ { value: "douyin", label: "抖音" }, { value: "xiaohongshu", label: "小红书" }, { value: "wechat-official", label: "公众号" }, { value: "kuaishou", label: "快手" }, ]; const reasonText = { account_revoked: "授权已撤销", account_paused: "账号已暂停", binding_missing: "未绑定运行环境", network_exit_missing: "未绑定固定出口", network_exit_unhealthy: "固定出口不健康", runtime_stop_pending: "运行环境停止结果待确认", runtime_missing: "运行环境未启动", runtime_active: "仍有活动运行实例", account_conflict: "账号状态已变化,请刷新后重试", environment_unavailable: "环境状态未知", }; // 账号可恢复性判定:授权、绑定、出口健康、账号暂停四层都要看。 export function accountReadiness(account, binding, bindingsError = false) { if (account.authorization_status !== "authorized") return { label: "授权已撤销", reason: "account_revoked", canResume: false, ready: false, }; if (bindingsError) return { label: "环境状态未知", reason: "environment_unavailable", canResume: false, ready: false, }; if (!binding) return { label: "未绑定运行环境", reason: "binding_missing", canResume: false, ready: false, }; const blocked = binding.cleanup_pending ? "runtime_stop_pending" : binding.network_exit_id && binding.network_exit_health !== "healthy" ? "network_exit_unhealthy" : ""; if (blocked) return { label: reasonText[blocked], reason: blocked, canResume: false, ready: false, }; if (account.runtime_status === "paused") { const stopped = !binding.runtime_instance_id; return { label: stopped ? "资源就绪,可恢复" : "等待运行环境停止", reason: stopped ? "" : "runtime_stop_pending", canResume: stopped, ready: false, }; } const schedule = binding.schedule_block_reason || ""; return { label: schedule ? reasonText[schedule] || `不可调度:${schedule}` : "可调度", reason: schedule, canResume: false, ready: !schedule, }; } function ReadinessPill({ readiness, paused }) { const tone = readiness.ready ? "success" : paused && readiness.canResume ? "warning" : "danger"; return ; } function AccountCreateForm({ onSubmit, busy, error }) { const [form, setForm] = useState(createInitial); const update = (key, value) => setForm((current) => ({ ...current, [key]: value })); const valid = form.name.trim() && form.platform && form.platform_account_key.trim(); async function submit(event) { event.preventDefault(); if (!valid) return; const data = { name: form.name.trim(), platform: form.platform.trim(), platform_account_key: form.platform_account_key.trim(), tags: form.tags, }; // cookies 非必填:留空代表创建后走扫码登录,凭据由后续同步链路补齐 if (form.cookies.trim()) data.cookies = form.cookies.trim(); await onSubmit(data); } return (
{error ? ( {conflictMessage(error, "该平台的账号 ID 已存在;表单内容已保留。")} ) : null}
update("name", event.target.value)} placeholder="如:店铺一号" /> update("platform_account_key", event.target.value) } /> update("tags", tags)} placeholder="如:主账号" />