收口账号页面子模块边界

This commit is contained in:
Christ committed 2026-08-15 19:30:59 +08:00
1 parent afb7e2f0d9
commit 371bd9d17e
14 files changed
+500 -452

No files matched your search

@@ -0,0 +1,80 @@
import React from 'react';
import { createPortal } from 'react-dom';
import { Bot, Loader2, Save, Settings, X } from 'lucide-react';
import type { AccountDetail, AIReplySettings } from '../../../../types';
// AccountAISettingsModalProps 描述账号 AI 设置弹窗需要的状态和回调。
export interface AccountAISettingsModalProps {
// account 是当前正在编辑 AI 设置的账号。
account: AccountDetail;
// settings 是账号 AI 设置编辑草稿。
settings: AIReplySettings;
// saving 表示 AI 设置保存请求是否正在执行。
saving: boolean;
// onChange 更新 AI 设置草稿。
onChange: (settings: AIReplySettings) => void;
// onClose 关闭 AI 设置弹窗。
onClose: () => void;
// onSave 保存 AI 设置并刷新账号列表。
onSave: () => void | Promise<void>;
}
// AccountAISettingsModal 渲染账号 AI 自动回复策略编辑界面。
export const AccountAISettingsModal: React.FC<AccountAISettingsModalProps> = ({ account, settings, saving, onChange, onClose, onSave }) => {
// updateSettings 使用最新草稿合并单个 AI 字段变化。
const updateSettings = (patch: Partial<AIReplySettings>) => onChange({ ...settings, ...patch });
// handleEnabledChange 切换 AI 自动回复开关。
const handleEnabledChange = () => updateSettings({ ai_enabled: !settings.ai_enabled });
// handleDiscountPercentChange 更新最大折扣比例。
const handleDiscountPercentChange = (event: React.ChangeEvent<HTMLInputElement>) => updateSettings({ max_discount_percent: parseInt(event.target.value, 10) || 0 });
// handleDiscountAmountChange 更新最大折扣金额。
const handleDiscountAmountChange = (event: React.ChangeEvent<HTMLInputElement>) => updateSettings({ max_discount_amount: parseInt(event.target.value, 10) || 0 });
// handleBargainRoundsChange 更新最大砍价轮次。
const handleBargainRoundsChange = (event: React.ChangeEvent<HTMLInputElement>) => updateSettings({ max_bargain_rounds: parseInt(event.target.value, 10) || 1 });
// handlePromptChange 更新自定义 AI 提示词。
const handlePromptChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => updateSettings({ custom_prompts: event.target.value });
return createPortal(
<div className="modal-overlay-centered">
<div className="modal-container" style={{ maxWidth: '600px' }}>
<div className="modal-header">
<div>
<h3 className="text-2xl font-extrabold text-gray-900 flex items-center gap-2"><Bot className="w-6 h-6 text-purple-500" />AI助手设置</h3>
<p className="text-sm text-gray-500 mt-1">{account.nickname || account.remark || account.id}</p>
</div>
<button onClick={onClose} className="p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0" aria-label="关闭 AI 设置"><X className="w-5 h-5 text-gray-500" /></button>
</div>
<div className="modal-body space-y-6">
<div className="flex items-center justify-between p-4 bg-purple-50 rounded-xl">
<div><div className="font-bold text-gray-900 flex items-center gap-2"><Bot className="w-4 h-4 text-purple-500" />启用AI自动回复</div><div className="text-xs text-gray-500">AI将自动处理买家的砍价消息</div></div>
<button type="button" onClick={handleEnabledChange} className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${settings.ai_enabled ? 'bg-brand' : 'bg-gray-300'}`} aria-label="切换 AI 自动回复">
<span className={`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${settings.ai_enabled ? 'translate-x-6' : 'translate-x-0'}`} />
</button>
</div>
<div className="border-t border-gray-200 pt-6">
<h3 className="text-lg font-bold text-gray-900 mb-4">砍价策略</h3>
<div className="grid grid-cols-3 gap-4">
<div><label className="block text-sm font-bold text-gray-700 mb-2">最大折扣比例 (%)</label><input type="number" value={settings.max_discount_percent} onChange={handleDiscountPercentChange} className="w-full ios-input px-4 py-3 rounded-xl" min="0" max="100" /><p className="text-xs text-gray-500 mt-1">例如:10 表示最多降价 10%;设为 0 表示不允许降价</p></div>
<div><label className="block text-sm font-bold text-gray-700 mb-2">最大折扣金额 (元)</label><input type="number" value={settings.max_discount_amount} onChange={handleDiscountAmountChange} className="w-full ios-input px-4 py-3 rounded-xl" min="0" /><p className="text-xs text-gray-500 mt-1">例如:100 表示最多降价 100 元;设为 0 表示不允许降价</p></div>
<div><label className="block text-sm font-bold text-gray-700 mb-2">最大砍价轮次</label><input type="number" value={settings.max_bargain_rounds} onChange={handleBargainRoundsChange} className="w-full ios-input px-4 py-3 rounded-xl" min="1" max="10" /><p className="text-xs text-gray-500 mt-1">买家最多可以砍价的次数</p></div>
</div>
</div>
<div><label className="block text-sm font-bold text-gray-700 mb-2">自定义提示词(可选)</label><textarea value={settings.custom_prompts} onChange={handlePromptChange} placeholder="输入自定义的AI回复规则或风格指引...&#10;&#10;例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等" className="w-full ios-input px-4 py-3 rounded-xl h-40 resize-none" /></div>
<div className="bg-blue-50 border border-blue-200 rounded-xl p-4">
<h4 className="font-bold text-blue-900 mb-2 flex items-center gap-2"><Settings className="w-4 h-4" />AI如何工作</h4>
<ul className="text-xs text-blue-800 space-y-1"><li>• 自动识别买家的砍价请求</li><li>• 根据设定的策略智能回复</li><li>• 在合理范围内同意降价或礼貌拒绝</li><li>• 保持专业友好的沟通风格</li></ul>
</div>
</div>
<div className="modal-footer"><div className="flex gap-3 w-full">
<button onClick={onClose} className="flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors" disabled={saving}>取消</button>
<button onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => void onSave()} className="flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2" disabled={saving}>{saving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}{saving ? '保存中...' : '保存'}</button>
</div></div>
</div>
</div>,
document.body,
);
};
@@ -0,0 +1,138 @@
import React from 'react';
import { AlertCircle, Bot, CalendarClock, Check, Clock, Loader2, MessageCircle, Power, QrCode, RefreshCw, Sparkles, Trash2, User, Edit2 } from 'lucide-react';
import type { AccountDetail } from '../../../../types';
import { accountRuntimePresentation } from '../runtime';
// AccountCardProps 描述账号卡片展示所需的数据和动作。
export interface AccountCardProps {
// account 是当前账号的非敏感展示数据。
account: AccountDetail;
// refreshing 表示当前账号是否正在刷新资料。
refreshing: boolean;
// deleting 表示当前账号是否正在删除。
deleting: boolean;
// onRefreshProfile 刷新账号昵称和头像。
onRefreshProfile: (account: AccountDetail) => void | Promise<void>;
// onReauthorize 启动当前账号二维码重新授权。
onReauthorize: (account: AccountDetail) => void | Promise<void>;
// onEdit 打开账号编辑弹窗。
onEdit: (account: AccountDetail) => void | Promise<void>;
// onAI 打开账号 AI 设置弹窗。
onAI: (account: AccountDetail) => void | Promise<void>;
// onTasks 打开账号自动化任务弹窗。
onTasks: (account: AccountDetail) => void;
// onToggle 切换账号启用状态。
onToggle: (id: string, currentStatus: boolean) => void | Promise<void>;
// onDelete 打开账号删除确认框。
onDelete: (account: AccountDetail) => void;
}
// AccountCard 渲染单个账号的状态摘要与操作入口。
export const AccountCard = React.memo(/* AccountCard 负责渲染单个账号卡片及其操作。 */ function AccountCard({
account,
refreshing,
deleting,
onRefreshProfile,
onReauthorize,
onEdit,
onAI,
onTasks,
onToggle,
onDelete,
}: AccountCardProps) {
// runtime 保存账号运行状态的展示样式。
const runtime = accountRuntimePresentation(account);
// requiresLogin 表示当前账号是否需要重新授权。
const requiresLogin = account.runtime_state === 'auth_expired' || account.runtime_state === 'verification_required';
return (
<div className="ios-card rounded-xl p-6 group transition-all duration-300 hover:border-brand">
<div className="flex min-w-0 items-start gap-5 sm:gap-8">
<div className="relative">
{account.avatar_url ? (
<img
src={account.avatar_url}
alt={account.nickname || '账号头像'}
className="w-20 h-20 rounded-full object-cover shadow-md ring-4 ring-white bg-gray-100"
/>
) : (
<div className="w-20 h-20 rounded-full bg-gray-100 text-gray-400 shadow-md ring-4 ring-white flex items-center justify-center">
<User className="w-9 h-9" />
</div>
)}
<div className={`absolute -bottom-1 -right-1 w-6 h-6 rounded-full border-4 border-white flex items-center justify-center ${runtime.dot}`}>
{account.runtime_state === 'online' && <Check className="w-3 h-3 text-white" />}
</div>
</div>
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-2.5 mb-1">
<h3 className="text-xl font-extrabold text-gray-900 break-words">{account.nickname || account.remark || `账号 ${account.id.substring(0, 6)}...`}</h3>
<span className={`px-2.5 py-0.5 rounded-lg text-xs font-bold ${runtime.badge}`}>{runtime.label}</span>
{account.ai_enabled && (
<span className="px-2.5 py-0.5 rounded-lg bg-purple-100 text-purple-700 text-xs font-bold flex items-center gap-1">
<Bot className="w-3 h-3" /> AI
</span>
)}
{account.auto_rate_enabled && (
<span className="flex items-center gap-1 rounded-lg bg-emerald-100 px-2.5 py-0.5 text-xs font-bold text-emerald-700">
<MessageCircle className="h-3 w-3" /> 自动评价
</span>
)}
{account.auto_polish_enabled && (
<span className="flex items-center gap-1 rounded-lg bg-amber-100 px-2.5 py-0.5 text-xs font-bold text-amber-700">
<Sparkles className="h-3 w-3" /> 每日擦亮
</span>
)}
{account.auto_confirm && <span className="flex items-center gap-1 rounded-lg bg-blue-50 px-2.5 py-0.5 text-xs font-bold text-blue-700"><Check className="h-3 w-3" /> 自动确认发货</span>}
{account.profile_error && (
<span className="px-2.5 py-0.5 rounded-lg bg-amber-100 text-amber-700 text-xs font-bold flex items-center gap-1" title={account.profile_error}>
<AlertCircle className="w-3 h-3" /> 资料未同步
</span>
)}
</div>
<div className="mt-3 flex flex-wrap items-center justify-between gap-4">
<div className="text-sm font-medium text-gray-500">
<p>{account.remark || '暂无备注'}</p>
<p className="font-mono text-xs text-gray-400">ID: {account.id}</p>
</div>
{account.runtime_message && account.runtime_state !== 'online' && account.runtime_state !== 'disabled' && (
<div className={`mb-3 flex flex-wrap items-center gap-2 text-sm font-medium ${requiresLogin ? 'text-red-700' : 'text-amber-700'}`}>
<AlertCircle className="w-4 h-4 flex-shrink-0" />
<span>{account.runtime_message}</span>
{requiresLogin && (
<button type="button" onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => onReauthorize(account)} className="inline-flex items-center gap-1.5 rounded-lg bg-red-50 px-2.5 py-1 text-xs font-bold text-red-700 hover:bg-red-100">
<QrCode className="w-3.5 h-3.5" /> 重新授权
</button>
)}
</div>
)}
{account.paused && <span className="flex items-center gap-1.5 rounded-lg bg-blue-50 px-3 py-1.5 text-xs font-bold text-blue-700"><Clock className="h-3 w-3" /> 暂停处理中</span>}
<div className="mt-3 flex flex-wrap items-center justify-end gap-2">
<button onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => onRefreshProfile(account)} disabled={refreshing} className="p-3 rounded-xl transition-colors text-gray-600 hover:bg-gray-100 disabled:opacity-50" title="刷新昵称和头像">
<RefreshCw className={`w-5 h-5 ${refreshing ? 'animate-spin' : ''}`} />
</button>
<button onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => onReauthorize(account)} className={`p-3 rounded-xl transition-colors ${requiresLogin ? 'text-red-600 bg-red-50 hover:bg-red-100' : 'text-blue-600 hover:bg-blue-50'}`} title="重新扫码授权当前账号">
<QrCode className="w-5 h-5" />
</button>
<button onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => onEdit(account)} className="p-3 rounded-xl hover:bg-gray-100 transition-colors text-gray-600" title="编辑账号">
<Edit2 className="w-5 h-5" />
</button>
<button onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => onAI(account)} className="p-3 rounded-xl hover:bg-purple-100 transition-colors text-purple-600" title="AI设置">
<Bot className="w-5 h-5" />
</button>
<button onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => onTasks(account)} className="p-3 rounded-xl hover:bg-amber-100 transition-colors text-amber-600" title="自动评价与每日擦亮">
<CalendarClock className="w-5 h-5" />
</button>
<button onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => onToggle(account.id, account.enabled)} className={`p-3 rounded-xl transition-colors ${account.enabled ? 'text-green-600 hover:bg-green-50' : 'text-gray-400 hover:bg-gray-100'}`} title={account.enabled ? '停用账号' : '启用账号'}>
<Power className="w-5 h-5" />
</button>
<button onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => onDelete(account)} disabled={deleting} className="p-3 rounded-xl hover:bg-red-100 transition-colors text-red-500 disabled:cursor-not-allowed disabled:opacity-40" title={deleting ? '删除中…' : `删除账号 ${account.nickname || account.remark || account.id}`}>
{deleting ? <Loader2 className="w-5 h-5 animate-spin" /> : <Trash2 className="w-5 h-5" />}
</button>
</div>
</div>
</div>
</div>
</div>
);
});
@@ -0,0 +1,65 @@
import React from 'react';
import { createPortal } from 'react-dom';
import { AlertCircle, Loader2, Trash2, X } from 'lucide-react';
import type { AccountDetail } from '../../../../types';
// AccountDeleteDialogProps 描述账号删除确认框需要的状态和回调。
export interface AccountDeleteDialogProps {
// account 是待删除的账号摘要。
account: AccountDetail;
// deleting 表示删除请求是否正在执行。
deleting: boolean;
// error 是删除失败后的用户可见提示。
error: string;
// onClose 关闭删除确认框。
onClose: () => void;
// onConfirm 确认删除账号。
onConfirm: () => void | Promise<void>;
}
// AccountDeleteDialog 渲染账号删除确认框并通过 Portal 隔离页面布局。
export const AccountDeleteDialog: React.FC<AccountDeleteDialogProps> = ({ account, deleting, error, onClose, onConfirm }) => createPortal(
<div className="modal-overlay-centered" role="presentation">
<div className="h-fit w-full max-w-[400px] self-center overflow-hidden rounded-2xl border border-white/80 bg-white shadow-modal" role="dialog" aria-modal="true" aria-labelledby="delete-account-title" aria-describedby="delete-account-description">
<div className="relative overflow-hidden border-b border-red-100 bg-gradient-to-br from-red-50 via-white to-orange-50 px-5 py-5">
<div className="absolute -right-12 -top-16 h-36 w-36 rounded-full bg-red-200/35 blur-2xl" />
<div className="relative flex items-start gap-4">
<div className="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-red-600 text-white shadow-md shadow-red-200"><Trash2 className="h-5 w-5" /></div>
<div className="min-w-0 flex-1">
<h3 id="delete-account-title" className="text-lg font-extrabold tracking-tight text-gray-950">删除这个账号?</h3>
<p id="delete-account-description" className="mt-1 text-xs leading-5 text-gray-600">删除后,该账号的关联配置也会一并清理,此操作无法撤销。</p>
</div>
<button type="button" onClick={onClose} disabled={deleting} className="flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-white hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-40" aria-label="关闭删除确认"><X className="h-5 w-5" /></button>
</div>
</div>
<div className="px-5 py-4">
<div className="rounded-xl border border-gray-100 bg-gray-50/80 px-4 py-3">
<div className="text-sm font-extrabold text-gray-900">{account.nickname || account.remark || '未命名账号'}</div>
{account.remark && account.nickname && <div className="mt-1 text-sm text-gray-500">备注:{account.remark}</div>}
<div className="mt-1.5 break-all font-mono text-[11px] text-gray-400">ID: {account.id}</div>
</div>
{deleting && (
<div className="mt-4 flex items-center gap-3 rounded-xl border border-blue-100 bg-blue-50 px-4 py-3" role="progressbar" aria-label="正在删除账号">
<Loader2 className="h-5 w-5 flex-shrink-0 animate-spin text-brand" />
<div><div className="text-sm font-extrabold text-blue-950">正在删除账号</div><div className="mt-0.5 text-xs text-blue-700">正在清理关联数据,请保持页面打开…</div></div>
</div>
)}
{error && (
<div className="mt-4 flex items-start gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3" role="alert">
<AlertCircle className="mt-0.5 h-5 w-5 flex-shrink-0 text-red-600" />
<div><div className="text-sm font-extrabold text-red-800">删除失败</div><div className="mt-1 text-xs leading-5 text-red-700">{error}</div></div>
</div>
)}
</div>
<div className="flex gap-3 border-t border-gray-100 bg-gray-50/70 px-5 py-4">
<button type="button" onClick={onClose} disabled={deleting} className="flex-1 rounded-xl bg-white px-5 py-3 text-sm font-extrabold text-gray-700 ring-1 ring-gray-200 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50">取消</button>
<button type="button" onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => void onConfirm()} disabled={deleting} className="flex flex-1 items-center justify-center gap-2 rounded-xl bg-red-600 px-5 py-3 text-sm font-extrabold text-white shadow-lg shadow-red-200 transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:bg-red-400">
{deleting ? <><Loader2 className="h-4 w-4 animate-spin" />处理中</> : <><Trash2 className="h-4 w-4" />确认删除</>}
</button>
</div>
</div>
</div>,
document.body,
);
@@ -0,0 +1,55 @@
import React from 'react';
import { createPortal } from 'react-dom';
import { Check, Loader2, X } from 'lucide-react';
import type { AccountDetail } from '../../../../types';
import { RiskVerificationPanel } from '../../../../components/RiskVerificationPanel';
import { SquareQRCode } from '../../../../components/SquareQRCode';
// AccountQRCodeModalProps 描述二维码登录弹窗的展示状态和关闭回调。
export interface AccountQRCodeModalProps {
// target 是重新授权时的目标账号,新增账号时为空。
target: AccountDetail | null;
// status 是二维码登录当前阶段。
status: string;
// codeUrl 是待扫描的二维码地址。
codeUrl: string;
// errorMessage 是二维码生成或轮询失败提示。
errorMessage: string;
// faceQrUrl 是风控人脸验证二维码地址。
faceQrUrl: string;
// verificationScreenshot 是风控验证截图地址。
verificationScreenshot: string;
// onClose 关闭二维码登录弹窗并取消后台请求。
onClose: () => void;
}
// AccountQRCodeModal 渲染二维码登录、风控验证和结果状态。
export const AccountQRCodeModal: React.FC<AccountQRCodeModalProps> = ({ target, status, codeUrl, errorMessage, faceQrUrl, verificationScreenshot, onClose }) => createPortal(
<div className="modal-overlay-centered">
<div className="modal-container relative" style={{ maxWidth: '26rem' }}>
<button onClick={onClose} className="absolute top-4 right-4 z-10 w-9 h-9 flex items-center justify-center bg-gray-100 hover:bg-gray-200 rounded-full transition-colors" aria-label="关闭二维码登录">
<X className="w-5 h-5 text-gray-600" />
</button>
<div className="modal-body">
<div className="text-center">
<h3 className="text-2xl font-extrabold text-gray-900 mb-2">{target ? '重新授权账号' : '扫码添加账号'}</h3>
<p className="text-gray-500 mb-8 font-medium">{target ? `请用闲鱼APP扫码,为「${target.nickname || target.remark || target.id}」刷新授权` : '请打开闲鱼APP扫描下方二维码'}</p>
<div className={`w-full bg-surface-subtle rounded-xl mx-auto flex items-center justify-center overflow-hidden border-4 border-white shadow-inner mb-6 relative ${status === 'verification' ? 'max-w-72 min-h-64 h-auto p-2' : 'max-w-64 aspect-square'}`}>
{status === 'loading' && <Loader2 className="w-10 h-10 text-brand animate-spin" />}
{status === 'waiting' && <SquareQRCode src={codeUrl} alt="闲鱼登录二维码" className="p-2" />}
{status === 'success' && (
<div className="absolute inset-0 bg-white/95 flex flex-col items-center justify-center text-green-600 animate-fade-in">
<div className="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mb-4"><Check className="w-8 h-8" /></div>
<span className="font-bold text-lg">登录成功</span>
</div>
)}
{status === 'error' && <div className="px-5 text-center"><span className="block text-red-600 font-bold">二维码获取失败</span><span className="mt-2 block text-xs leading-5 text-gray-500">{errorMessage || '请关闭窗口后重新发起扫码登录。'}</span></div>}
{status === 'verification' && <RiskVerificationPanel faceQrUrl={faceQrUrl} verificationScreenshot={verificationScreenshot} />}
</div>
{status !== 'verification' && <p className="text-xs text-gray-400 font-medium bg-gray-50 py-2 rounded-xl">二维码有效期为5分钟,请尽快扫码。</p>}
</div>
</div>
</div>
</div>,
document.body,
);
@@ -0,0 +1,85 @@
// @vitest-environment jsdom
import { fireEvent, render, screen, cleanup } from '@testing-library/react';
import { afterEach, describe, expect, test, vi } from 'vitest';
import type { AccountDetail, AIReplySettings } from '../../../../types';
import { AccountAISettingsModal } from './AccountAISettingsModal';
import { AccountCard } from './AccountCard';
import { AccountDeleteDialog } from './AccountDeleteDialog';
import { AccountQRCodeModal } from './AccountQRCodeModal';
// accountFixture 是账号组件测试使用的最小非敏感账号摘要。
const accountFixture = {
id: 'account-1',
nickname: '测试账号',
remark: '测试备注',
enabled: true,
runtime_state: 'online',
runtime_message: '',
ai_enabled: true,
auto_rate_enabled: false,
auto_polish_enabled: false,
auto_confirm: false,
paused: false,
} as AccountDetail;
// aiSettingsFixture 是 AI 设置弹窗测试使用的编辑草稿。
const aiSettingsFixture: AIReplySettings = {
ai_enabled: false,
max_discount_percent: 10,
max_discount_amount: 100,
max_bargain_rounds: 3,
custom_prompts: '',
};
// noopAccountAction 是账号卡片测试使用的动作占位函数。
const noopAccountAction = (): void => undefined;
describe('账号 feature 展示组件', /* 当前回调覆盖账号页面子模块展示边界。 */ () => {
afterEach(/* 当前回调清理 Portal 和测试 DOM。 */ () => cleanup());
test('账号卡片展示状态并转发所有操作', /* 当前回调验证账号卡片的操作边界。 */ () => {
// onDelete 是删除操作测试替身。
const onDelete = vi.fn();
// onAI 是 AI 设置操作测试替身。
const onAI = vi.fn();
// onToggle 是启停操作测试替身。
const onToggle = vi.fn();
render(<AccountCard account={accountFixture} refreshing={false} deleting={false} onRefreshProfile={noopAccountAction} onReauthorize={noopAccountAction} onEdit={noopAccountAction} onAI={onAI} onTasks={noopAccountAction} onToggle={onToggle} onDelete={onDelete} />);
expect(screen.getByText('测试账号')).toBeTruthy();
fireEvent.click(screen.getByTitle('AI设置'));
fireEvent.click(screen.getByTitle('停用账号'));
fireEvent.click(screen.getByTitle('删除账号 测试账号'));
expect(onAI).toHaveBeenCalledWith(accountFixture);
expect(onToggle).toHaveBeenCalledWith(accountFixture.id, accountFixture.enabled);
expect(onDelete).toHaveBeenCalledWith(accountFixture);
});
test('AI 设置弹窗使用补丁更新并转发保存', /* 当前回调验证 AI 设置字段更新和保存动作。 */ () => {
// onChange 是 AI 设置草稿更新测试替身。
const onChange = vi.fn();
// onSave 是 AI 设置保存测试替身。
const onSave = vi.fn();
render(<AccountAISettingsModal account={accountFixture} settings={aiSettingsFixture} saving={false} onChange={onChange} onClose={noopAccountAction} onSave={onSave} />);
fireEvent.click(screen.getByLabelText('切换 AI 自动回复'));
fireEvent.change(screen.getByDisplayValue('10'), { target: { value: '20' } });
fireEvent.click(screen.getByText('保存'));
expect(onChange).toHaveBeenNthCalledWith(1, { ...aiSettingsFixture, ai_enabled: true });
expect(onChange).toHaveBeenNthCalledWith(2, { ...aiSettingsFixture, max_discount_percent: 20 });
expect(onSave).toHaveBeenCalledTimes(1);
});
test('删除确认框展示错误并转发确认动作', /* 当前回调验证删除确认框的错误和提交分支。 */ () => {
// onConfirm 是删除确认测试替身。
const onConfirm = vi.fn();
render(<AccountDeleteDialog account={accountFixture} deleting={false} error="删除失败" onClose={noopAccountAction} onConfirm={onConfirm} />);
expect(screen.getByRole('alert').textContent).toContain('删除失败');
fireEvent.click(screen.getByText('确认删除'));
expect(onConfirm).toHaveBeenCalledTimes(1);
});
test('二维码弹窗展示风控验证面板且不生成外部链接', /* 当前回调验证二维码风控状态的安全展示边界。 */ () => {
render(<AccountQRCodeModal target={accountFixture} status="verification" codeUrl="" errorMessage="" faceQrUrl="face-qr" verificationScreenshot="screen" onClose={noopAccountAction} />);
expect(screen.getByText('需要完成安全风控验证')).toBeTruthy();
expect(document.querySelectorAll('a')).toHaveLength(0);
});
});
+47 -424
View File
@@ -9,19 +9,16 @@ import {
completeQRVerification,
refreshAccountProfile,
} from '../app/features/accounts/api';
import {
Power, Edit2, Trash2, QrCode, X, Check, Loader2,
RefreshCw, Save, User, Clock, MessageCircle,
Bot, Settings, AlertCircle, CalendarClock, Sparkles
} from 'lucide-react';
import { Loader2, QrCode, User } from 'lucide-react';
import { createLatestRequestGate, createQRLoginPoller } from './qrPolling';
import { RiskVerificationPanel } from './RiskVerificationPanel';
import { SquareQRCode } from './SquareQRCode';
import AccountAutomationModal from './AccountAutomationModal';
import { AccountEditModal } from '../app/features/accounts/components/AccountEditModal';
import { AccountAISettingsModal } from '../app/features/accounts/components/AccountAISettingsModal';
import { AccountCard } from '../app/features/accounts/components/AccountCard';
import { AccountDeleteDialog } from '../app/features/accounts/components/AccountDeleteDialog';
import { AccountQRCodeModal } from '../app/features/accounts/components/AccountQRCodeModal';
import { useAccountsData } from '../app/features/accounts/hooks';
import { useAccountSubmodules, type AccountModalType } from '../app/features/accounts/submoduleHooks';
import { accountRuntimePresentation } from '../app/features/accounts/runtime';
import type { AccountEditForm } from '../app/features/accounts/types';
// AccountList 渲染账号列表组件。
@@ -358,140 +355,21 @@ const AccountList: React.FC = () => {
{/* Account Grid */}
<div className="grid grid-cols-1 gap-6">
{filteredAccounts.map(/* 当前回调处理集合中的单个元素。 */ (account) => {
// runtime 运行状态。
const runtime = accountRuntimePresentation(account);
// requiresLogin 是否需要重新登录。
const requiresLogin = account.runtime_state === 'auth_expired' || account.runtime_state === 'verification_required';
return (
<div key={account.id} className="ios-card rounded-xl p-6 group transition-all duration-300 hover:border-brand">
<div className="flex min-w-0 items-start gap-5 sm:gap-8">
<div className="relative">
{account.avatar_url ? (
<img
src={account.avatar_url}
alt={account.nickname || '账号头像'}
className="w-20 h-20 rounded-full object-cover shadow-md ring-4 ring-white bg-gray-100"
/>
) : (
<div className="w-20 h-20 rounded-full bg-gray-100 text-gray-400 shadow-md ring-4 ring-white flex items-center justify-center">
<User className="w-9 h-9" />
</div>
)}
<div className={`absolute -bottom-1 -right-1 w-6 h-6 rounded-full border-4 border-white flex items-center justify-center ${runtime.dot}`}>
{account.runtime_state === 'online' && <Check className="w-3 h-3 text-white" />}
</div>
</div>
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-2.5 mb-1">
<h3 className="text-xl font-extrabold text-gray-900 break-words">{account.nickname || account.remark || `账号 ${account.id.substring(0,6)}...`}</h3>
<span className={`px-2.5 py-0.5 rounded-lg text-xs font-bold ${runtime.badge}`}>{runtime.label}</span>
{account.ai_enabled && (
<span className="px-2.5 py-0.5 rounded-lg bg-purple-100 text-purple-700 text-xs font-bold flex items-center gap-1">
<Bot className="w-3 h-3" /> AI
</span>
)}
{account.auto_rate_enabled && (
<span className="flex items-center gap-1 rounded-lg bg-emerald-100 px-2.5 py-0.5 text-xs font-bold text-emerald-700">
<MessageCircle className="h-3 w-3" /> 自动评价
</span>
)}
{account.auto_polish_enabled && (
<span className="flex items-center gap-1 rounded-lg bg-amber-100 px-2.5 py-0.5 text-xs font-bold text-amber-700">
<Sparkles className="h-3 w-3" /> 每日擦亮
</span>
)}
{account.auto_confirm && <span className="flex items-center gap-1 rounded-lg bg-blue-50 px-2.5 py-0.5 text-xs font-bold text-blue-700"><Check className="h-3 w-3" /> 自动确认发货</span>}
{account.profile_error && (
<span
className="px-2.5 py-0.5 rounded-lg bg-amber-100 text-amber-700 text-xs font-bold flex items-center gap-1"
title={account.profile_error}
>
<AlertCircle className="w-3 h-3" /> 资料未同步
</span>
)}
</div>
<div className="mt-3 flex flex-wrap items-center justify-between gap-4">
<div className="text-sm font-medium text-gray-500">
<p>{account.remark || '暂无备注'}</p>
<p className="font-mono text-xs text-gray-400">ID: {account.id}</p>
</div>
{account.runtime_message && account.runtime_state !== 'online' && account.runtime_state !== 'disabled' && (
<div className={`mb-3 flex flex-wrap items-center gap-2 text-sm font-medium ${requiresLogin ? 'text-red-700' : 'text-amber-700'}`}>
<AlertCircle className="w-4 h-4 flex-shrink-0" />
<span>{account.runtime_message}</span>
{requiresLogin && (
<button
type="button"
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => startQRLogin(account)}
className="inline-flex items-center gap-1.5 rounded-lg bg-red-50 px-2.5 py-1 text-xs font-bold text-red-700 hover:bg-red-100"
>
<QrCode className="w-3.5 h-3.5" /> 重新授权
</button>
)}
</div>
)}
{account.paused && <span className="flex items-center gap-1.5 rounded-lg bg-blue-50 px-3 py-1.5 text-xs font-bold text-blue-700"><Clock className="h-3 w-3" /> 暂停处理中</span>}
<div className="mt-3 flex flex-wrap items-center justify-end gap-2">
<button
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => handleRefreshProfile(account)}
disabled={refreshingProfileId === account.id}
className="p-3 rounded-xl transition-colors text-gray-600 hover:bg-gray-100 disabled:opacity-50"
title="刷新昵称和头像"
>
<RefreshCw className={`w-5 h-5 ${refreshingProfileId === account.id ? 'animate-spin' : ''}`} />
</button>
<button
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => startQRLogin(account)}
className={`p-3 rounded-xl transition-colors ${requiresLogin ? 'text-red-600 bg-red-50 hover:bg-red-100' : 'text-blue-600 hover:bg-blue-50'}`}
title="重新扫码授权当前账号"
>
<QrCode className="w-5 h-5" />
</button>
<button
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => openEditModal(account)}
className="p-3 rounded-xl hover:bg-gray-100 transition-colors text-gray-600"
title="编辑账号"
>
<Edit2 className="w-5 h-5" />
</button>
<button
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => openAIModal(account)}
className="p-3 rounded-xl hover:bg-purple-100 transition-colors text-purple-600"
title="AI设置"
>
<Bot className="w-5 h-5" />
</button>
<button
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => setTaskAccount(account)}
className="p-3 rounded-xl hover:bg-amber-100 transition-colors text-amber-600"
title="自动评价与每日擦亮"
>
<CalendarClock className="w-5 h-5" />
</button>
<button
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => handleToggle(account.id, account.enabled)}
className={`p-3 rounded-xl transition-colors ${account.enabled ? 'text-green-600 hover:bg-green-50' : 'text-gray-400 hover:bg-gray-100'}`}
title={account.enabled ? '停用账号' : '启用账号'}
>
<Power className="w-5 h-5" />
</button>
<button
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => openDeleteDialog(account)}
disabled={deletingAccountId !== ''}
className="p-3 rounded-xl hover:bg-red-100 transition-colors text-red-500 disabled:cursor-not-allowed disabled:opacity-40"
title={deletingAccountId === account.id ? '删除中…' : `删除账号 ${account.nickname || account.remark || account.id}`}
>
{deletingAccountId === account.id
? <Loader2 className="w-5 h-5 animate-spin" />
: <Trash2 className="w-5 h-5" />}
</button>
</div>
</div>
</div>
</div>
</div>
)})}
{filteredAccounts.map(/* 当前回调处理集合中的单个元素。 */ account => (
<AccountCard
key={account.id}
account={account}
refreshing={refreshingProfileId === account.id}
deleting={deletingAccountId === account.id}
onRefreshProfile={handleRefreshProfile}
onReauthorize={startQRLogin}
onEdit={openEditModal}
onAI={openAIModal}
onTasks={setTaskAccount}
onToggle={handleToggle}
onDelete={openDeleteDialog}
/>
))}
{accounts.length === 0 && (
<div className="ios-card p-12 text-center">
@@ -530,155 +408,26 @@ const AccountList: React.FC = () => {
document.body
)}
{/* 删除账号确认弹窗 */}
{deleteDialogAccount && createPortal(
<div className="modal-overlay-centered" role="presentation">
<div
className="h-fit w-full max-w-[400px] self-center overflow-hidden rounded-2xl border border-white/80 bg-white shadow-modal"
role="dialog"
aria-modal="true"
aria-labelledby="delete-account-title"
aria-describedby="delete-account-description"
>
<div className="relative overflow-hidden border-b border-red-100 bg-gradient-to-br from-red-50 via-white to-orange-50 px-5 py-5">
<div className="absolute -right-12 -top-16 h-36 w-36 rounded-full bg-red-200/35 blur-2xl" />
<div className="relative flex items-start gap-4">
<div className="flex h-10 w-10 flex-shrink-0 items-center justify-center rounded-xl bg-red-600 text-white shadow-md shadow-red-200">
<Trash2 className="h-5 w-5" />
</div>
<div className="min-w-0 flex-1">
<h3 id="delete-account-title" className="text-lg font-extrabold tracking-tight text-gray-950">
删除这个账号?
</h3>
<p id="delete-account-description" className="mt-1 text-xs leading-5 text-gray-600">
删除后,该账号的关联配置也会一并清理,此操作无法撤销。
</p>
</div>
<button
type="button"
onClick={closeDeleteDialog}
disabled={deletingAccountId !== ''}
className="flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-white hover:text-gray-700 disabled:cursor-not-allowed disabled:opacity-40"
aria-label="关闭删除确认"
>
<X className="h-5 w-5" />
</button>
</div>
</div>
<div className="px-5 py-4">
<div className="rounded-xl border border-gray-100 bg-gray-50/80 px-4 py-3">
<div className="text-sm font-extrabold text-gray-900">
{deleteDialogAccount.nickname || deleteDialogAccount.remark || '未命名账号'}
</div>
{deleteDialogAccount.remark && deleteDialogAccount.nickname && (
<div className="mt-1 text-sm text-gray-500">备注:{deleteDialogAccount.remark}</div>
)}
<div className="mt-1.5 break-all font-mono text-[11px] text-gray-400">ID: {deleteDialogAccount.id}</div>
</div>
{deletingAccountId === deleteDialogAccount.id && (
<div
className="mt-4 flex items-center gap-3 rounded-xl border border-blue-100 bg-blue-50 px-4 py-3"
role="progressbar"
aria-label="正在删除账号"
>
<Loader2 className="h-5 w-5 flex-shrink-0 animate-spin text-brand" />
<div>
<div className="text-sm font-extrabold text-blue-950">正在删除账号</div>
<div className="mt-0.5 text-xs text-blue-700">正在清理关联数据,请保持页面打开…</div>
</div>
</div>
)}
{deleteError && (
<div className="mt-4 flex items-start gap-3 rounded-xl border border-red-100 bg-red-50 px-4 py-3" role="alert">
<AlertCircle className="mt-0.5 h-5 w-5 flex-shrink-0 text-red-600" />
<div>
<div className="text-sm font-extrabold text-red-800">删除失败</div>
<div className="mt-1 text-xs leading-5 text-red-700">{deleteError}</div>
</div>
</div>
)}
</div>
<div className="flex gap-3 border-t border-gray-100 bg-gray-50/70 px-5 py-4">
<button
type="button"
onClick={closeDeleteDialog}
disabled={deletingAccountId !== ''}
className="flex-1 rounded-xl bg-white px-5 py-3 text-sm font-extrabold text-gray-700 ring-1 ring-gray-200 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50"
>
取消
</button>
<button
type="button"
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => void confirmDeleteAccount()}
disabled={deletingAccountId !== ''}
className="flex flex-1 items-center justify-center gap-2 rounded-xl bg-red-600 px-5 py-3 text-sm font-extrabold text-white shadow-lg shadow-red-200 transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:bg-red-400"
>
{deletingAccountId === deleteDialogAccount.id ? (
<><Loader2 className="h-4 w-4 animate-spin" />处理中</>
) : (
<><Trash2 className="h-4 w-4" />确认删除</>
)}
</button>
</div>
</div>
</div>,
document.body
{deleteDialogAccount && (
<AccountDeleteDialog
account={deleteDialogAccount}
deleting={deletingAccountId === deleteDialogAccount.id}
error={deleteError}
onClose={closeDeleteDialog}
onConfirm={confirmDeleteAccount}
/>
)}
{/* QR Code Modal */}
{showQRModal && createPortal(
<div className="modal-overlay-centered">
<div className="modal-container relative" style={{maxWidth: '26rem'}}>
<button
onClick={closeQRModal}
className="absolute top-4 right-4 z-10 w-9 h-9 flex items-center justify-center bg-gray-100 hover:bg-gray-200 rounded-full transition-colors"
>
<X className="w-5 h-5 text-gray-600" />
</button>
<div className="modal-body">
<div className="text-center">
<h3 className="text-2xl font-extrabold text-gray-900 mb-2">
{qrReauthTarget ? '重新授权账号' : '扫码添加账号'}
</h3>
<p className="text-gray-500 mb-8 font-medium">
{qrReauthTarget
? `请用闲鱼APP扫码,为「${qrReauthTarget.nickname || qrReauthTarget.remark || qrReauthTarget.id}」刷新授权`
: '请打开闲鱼APP扫描下方二维码'}
</p>
<div className={`w-full bg-surface-subtle rounded-xl mx-auto flex items-center justify-center overflow-hidden border-4 border-white shadow-inner mb-6 relative ${qrStatus === 'verification' ? 'max-w-72 min-h-64 h-auto p-2' : 'max-w-64 aspect-square'}`}>
{qrStatus === 'loading' && <Loader2 className="w-10 h-10 text-brand animate-spin" />}
{qrStatus === 'waiting' && <SquareQRCode src={qrCodeUrl} alt="闲鱼登录二维码" className="p-2" />}
{qrStatus === 'success' && (
<div className="absolute inset-0 bg-white/95 flex flex-col items-center justify-center text-green-600 animate-fade-in">
<div className="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mb-4">
<Check className="w-8 h-8" />
</div>
<span className="font-bold text-lg">登录成功</span>
</div>
)}
{qrStatus === 'error' && (
<div className="px-5 text-center">
<span className="block text-red-600 font-bold">二维码获取失败</span>
<span className="mt-2 block text-xs leading-5 text-gray-500">{qrErrorMessage || '请关闭窗口后重新发起扫码登录。'}</span>
</div>
)}
{qrStatus === 'verification' && (
<RiskVerificationPanel faceQrUrl={faceQrUrl} verificationScreenshot={verificationScreenshot} />
)}
</div>
{qrStatus !== 'verification' && <p className="text-xs text-gray-400 font-medium bg-gray-50 py-2 rounded-xl">二维码有效期为5分钟,请尽快扫码。</p>}
</div>
</div>
</div>
</div>,
document.body
{showQRModal && (
<AccountQRCodeModal
target={qrReauthTarget}
status={qrStatus}
codeUrl={qrCodeUrl}
errorMessage={qrErrorMessage}
faceQrUrl={faceQrUrl}
verificationScreenshot={verificationScreenshot}
onClose={closeQRModal}
/>
)}
{/* 编辑账号弹窗由 accounts feature 组件负责渲染和表单交互。 */}
@@ -708,141 +457,15 @@ const AccountList: React.FC = () => {
)}
{/* AI设置弹窗 */}
{activeModal === 'ai-settings' && editingAccount && createPortal(
<div className="modal-overlay-centered">
<div className="modal-container" style={{maxWidth: '600px'}}>
<div className="modal-header">
<div>
<h3 className="text-2xl font-extrabold text-gray-900 flex items-center gap-2">
<Bot className="w-6 h-6 text-purple-500" />
AI助手设置
</h3>
<p className="text-sm text-gray-500 mt-1">{editingAccount.nickname || editingAccount.remark || editingAccount.id}</p>
</div>
<button
onClick={closeAIModal}
className="p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0"
>
<X className="w-5 h-5 text-gray-500" />
</button>
</div>
<div className="modal-body space-y-6">
{/* 启用AI */}
<div className="flex items-center justify-between p-4 bg-purple-50 rounded-xl">
<div>
<div className="font-bold text-gray-900 flex items-center gap-2">
<Bot className="w-4 h-4 text-purple-500" />
启用AI自动回复
</div>
<div className="text-xs text-gray-500">AI将自动处理买家的砍价消息</div>
</div>
<button
type="button"
onClick={/* 当前回调处理用户交互或异步状态变化。 */ () => setAiSettings({ ...aiSettings, ai_enabled: !aiSettings.ai_enabled })}
className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${
aiSettings.ai_enabled ? 'bg-brand' : 'bg-gray-300'
}`}
>
<span
className={`absolute left-1 top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 ${
aiSettings.ai_enabled ? 'translate-x-6' : 'translate-x-0'
}`}
/>
</button>
</div>
{/* 砍价策略 */}
<div className="border-t border-gray-200 pt-6">
<h3 className="text-lg font-bold text-gray-900 mb-4">砍价策略</h3>
<div className="grid grid-cols-3 gap-4">
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">最大折扣比例 (%)</label>
<input
type="number"
value={aiSettings.max_discount_percent}
onChange={/* 当前回调处理用户交互或异步状态变化。 */ (e) => setAiSettings({ ...aiSettings, max_discount_percent: parseInt(e.target.value) || 0 })}
className="w-full ios-input px-4 py-3 rounded-xl"
min="0"
max="100"
/>
<p className="text-xs text-gray-500 mt-1">例如:10 表示最多降价 10%;设为 0 表示不允许降价</p>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">最大折扣金额 (元)</label>
<input
type="number"
value={aiSettings.max_discount_amount}
onChange={/* 当前回调处理用户交互或异步状态变化。 */ (e) => setAiSettings({ ...aiSettings, max_discount_amount: parseInt(e.target.value) || 0 })}
className="w-full ios-input px-4 py-3 rounded-xl"
min="0"
/>
<p className="text-xs text-gray-500 mt-1">例如:100 表示最多降价 100 元;设为 0 表示不允许降价</p>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">最大砍价轮次</label>
<input
type="number"
value={aiSettings.max_bargain_rounds}
onChange={/* 当前回调处理用户交互或异步状态变化。 */ (e) => setAiSettings({ ...aiSettings, max_bargain_rounds: parseInt(e.target.value) || 1 })}
className="w-full ios-input px-4 py-3 rounded-xl"
min="1"
max="10"
/>
<p className="text-xs text-gray-500 mt-1">买家最多可以砍价的次数</p>
</div>
</div>
</div>
{/* 自定义提示词 */}
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">自定义提示词(可选)</label>
<textarea
value={aiSettings.custom_prompts}
onChange={/* 当前回调处理用户交互或异步状态变化。 */ (e) => setAiSettings({ ...aiSettings, custom_prompts: e.target.value })}
placeholder="输入自定义的AI回复规则或风格指引...&#10;&#10;例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等"
className="w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"
/>
</div>
{/* AI如何工作 */}
<div className="bg-blue-50 border border-blue-200 rounded-xl p-4">
<h4 className="font-bold text-blue-900 mb-2 flex items-center gap-2">
<Settings className="w-4 h-4" />
AI如何工作
</h4>
<ul className="text-xs text-blue-800 space-y-1">
<li>• 自动识别买家的砍价请求</li>
<li>• 根据设定的策略智能回复</li>
<li>• 在合理范围内同意降价或礼貌拒绝</li>
<li>• 保持专业友好的沟通风格</li>
</ul>
</div>
</div>
<div className="modal-footer">
<div className="flex gap-3 w-full">
<button
onClick={closeAIModal}
className="flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors"
disabled={saving}
>
取消
</button>
<button
onClick={handleSaveAISettings}
className="flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2"
disabled={saving}
>
{saving ? <Loader2 className="w-4 h-4 animate-spin" /> : <Save className="w-4 h-4" />}
{saving ? '保存中...' : '保存'}
</button>
</div>
</div>
</div>
</div>,
document.body
{activeModal === 'ai-settings' && editingAccount && (
<AccountAISettingsModal
account={editingAccount}
settings={aiSettings}
saving={saving}
onChange={setAiSettings}
onClose={closeAIModal}
onSave={handleSaveAISettings}
/>
)}
</div>
);
+2 -1
View File
@@ -161,10 +161,11 @@ describe('frontend navigation routing', () => {
test('QR verification removes the external link and clearly requires in-app risk verification', () => {
const accounts = readFrontendFile('components/AccountList.tsx'); /* accounts 表示账号集合。 */
const qrModal = readFrontendFile('app/features/accounts/components/AccountQRCodeModal.tsx'); /* qrModal 表示二维码登录弹窗。 */
const riskPanel = readFrontendFile('components/RiskVerificationPanel.tsx'); /* riskPanel 表示riskPanel。 */
expect(accounts).not.toContain('href={verificationUrl}');
expect(accounts).not.toContain('setVerificationUrl');
expect(accounts).toContain('RiskVerificationPanel');
expect(qrModal).toContain('RiskVerificationPanel');
expect(riskPanel).toContain('需要完成安全风控验证');
expect(riskPanel).toContain('请勿在浏览器中打开验证链接');
expect(riskPanel).toContain('系统会自动检测并刷新登录状态');