阶段七:完成AccountList React feature化与账号状态边界

This commit is contained in:
Christ committed 2026-08-15 00:25:49 +08:00
1 parent c7c7023ad4
commit 03f108639d
20 files changed
+1277 -1320

No files matched your search

File diff suppressed because it is too large. Load diff
+3 -1
View File
@@ -171,7 +171,8 @@ app shell / routes
- 已完成阶段 6 第八个 PR 切片“Automation 账号任务与凭证门禁边界”:新增 `accountTaskCoordinator`,统一账号状态门禁、自动评价/商品擦亮调度、任务租约、Session 指纹阻断、凭证恢复和 Cookie 同步;`Center` 保留公开任务入口,Session 失效恢复、任务幂等、失败重试和账号暂停语义保持不变;Automation 测试、注释和 diff 门禁通过,整批修改合并为一个可回滚提交;阶段 6 完成;
- 已完成阶段 7 第一个 PR 切片“React Rules feature 化与 API/行为测试边界”:按 `app/features/rules` 提取 Rules API 适配层、领域类型、数据 Hook、异常面板和交互状态模型;规则页通过 Hook 管理服务端数据与请求代次,保留旧组件入口和现有 API 路径;行为测试覆盖成功、失败、重复提交、过期响应和页签切换;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
- 已完成阶段 7 第二个 PR 切片“React ItemList feature 化与批量发布行为边界”:按 `app/features/items` 提取商品/批量 API 适配层、批量任务类型、批量 Hook 和阶段指示器组件;批量预检、任务恢复、轮询取消、失败重试和过期响应均由 feature 状态边界负责;行为测试覆盖预检门禁、取消状态、失败重试、历史任务筛选和过期轮询响应;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
- 阶段 7 下一 PR 切片为“React AccountList feature 化与账号运行状态行为边界”:提取账号 API、运行状态 Hook 和账号编辑组件,补充账号切换、暂停/恢复、凭证失败和过期状态响应测试;
- 已完成阶段 7 第三个 PR 切片“React AccountList feature 化与账号运行状态行为边界”:按 `app/features/accounts` 提取账号 API 适配层、账号数据与运行状态 Hook、运行状态展示模型、账号编辑弹窗和登录/暂停状态模型;账号加载与运行状态轮询支持取消和请求代次门禁,密码登录响应按账号与代次隔离,旧组件入口保留兼容转发;行为测试覆盖账号切换、暂停/恢复、凭证失败、风控验证和过期响应;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
- 阶段 7 下一 PR 切片为“React CardList feature 化与卡密库存/批量追加行为边界”:提取卡密 API、库存 Hook 和批量追加组件,补充卡密筛选、追加预览、提交取消、失败重试和账号切换过期响应测试;
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
## 6. 阶段 0:治理文档与强约束
@@ -592,3 +593,4 @@ npm --prefix frontend run build
| 2026-08-14 | 完成阶段 6 第八个 PR 切片“Automation 账号任务与凭证门禁边界” | 新增 `accountTaskCoordinator`,统一账号状态门禁、自动评价/商品擦亮调度、任务租约、Session 指纹阻断、凭证恢复和 Cookie 同步;`Center` 保留公开任务入口,Session 失效恢复、任务幂等、失败重试和账号暂停语义保持不变;Automation 测试、注释和 diff 门禁通过并合并为一个可回滚提交 | 阶段 7:React Rules feature 化与 API/行为测试边界 |
| 2026-08-14 | 完成阶段 7 第一个 PR 切片“React Rules feature 化与 API/行为测试边界” | 新增 `app/features/rules` 的 API 适配层、领域类型、数据 Hook、异常面板和交互状态模型;规则请求支持并行加载与请求代次门禁,保存动作阻断重复提交;行为测试覆盖成功、失败、重复提交、过期响应和页签切换;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React ItemList feature 化与批量发布行为边界 |
| 2026-08-14 | 完成阶段 7 第二个 PR 切片“React ItemList feature 化与批量发布行为边界” | 新增 `app/features/items` 的 API 适配层、批量任务类型、批量 Hook、批量状态模型和阶段指示器组件;批量预检、任务恢复、轮询过期响应、安全取消和失败重试均有独立状态边界;行为测试覆盖预检门禁、取消状态、失败重试、历史任务筛选和过期轮询响应;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React AccountList feature 化与账号运行状态行为边界 |
| 2026-08-15 | 完成阶段 7 第三个 PR 切片“React AccountList feature 化与账号运行状态行为边界” | 新增 `app/features/accounts` 的 API 适配层、账号数据与运行状态 Hook、账号编辑弹窗、登录/暂停状态模型;账号加载和运行状态轮询具备取消与代次门禁,密码登录响应按账号与代次隔离,兼容入口保留;行为测试覆盖账号切换、暂停/恢复、凭证失败、风控验证和过期响应;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React CardList feature 化与卡密库存/批量追加行为边界 |
+31
View File
@@ -0,0 +1,31 @@
// 账号 feature 只通过本适配层访问账号相关网络接口,页面不再直接依赖共享 API 文件。
export {
cancelPasswordLogin,
checkPasswordLoginStatus,
checkQRLoginStatus,
completeQRVerification,
deleteAccount,
generateQRLogin,
getAccountAISettings,
getAccountBindings,
getAccountDetails,
getAccountRuntimeStatuses,
getAllAISettings,
getLongLoginSettings,
getNotificationChannels,
passwordLogin,
refreshAccountProfile,
setLongLoginSettings,
updateAccountAISettings,
updateAccountPauseDuration,
updateAccountSettings,
updateAccountStatus,
} from '../../../services/api';
// 账号 feature 重新导出接口返回类型,保持页面与网络契约的依赖方向稳定。
export type {
AccountRuntimeStatus,
LongLoginSettings,
PasswordLoginStartResponse,
PasswordLoginStatusResponse,
} from '../../../services/api';
@@ -0,0 +1,298 @@
import React from 'react';
import { createPortal } from 'react-dom';
import { Bell, Check, Clock, Eye, EyeOff, Key, Loader2, X } from 'lucide-react';
import { SquareQRCode } from '../../../../components/SquareQRCode';
import type { NotificationChannel } from '../../../../types';
import type { AccountEditForm, AccountEditModalProps } from '../types';
// AccountEditModal 负责账号备注、暂停、登录信息和通知绑定的编辑界面。
export const AccountEditModal: React.FC<AccountEditModalProps> = ({
account,
editForm,
setEditForm,
saving,
onClose,
onSave,
onRestartPause,
longLogin,
onToggleLongLogin,
passwordLoginView,
onPasswordLogin,
onCancelPasswordLogin,
notifChannels,
selectedChannelIds,
bindingsLoaded,
bindingsLoading,
bindingsLoadError,
onRetryBindings,
onToggleChannel,
onSettingsDirty,
}) => {
// updateField 用函数式更新避免连续输入事件读取旧表单快照。
const updateField = <K extends keyof AccountEditForm>(field: K, value: AccountEditForm[K]) => {
setEditForm(
// current 是事件发生前的最新编辑表单。
current => ({ ...current, [field]: value }),
);
};
// handleClose 关闭编辑弹窗并取消未完成的异步操作。
const handleClose = () => void onClose();
// handleSave 提交编辑表单并让父级刷新账号数据。
const handleSave = () => void onSave();
// handleRemarkChange 更新账号备注字段。
const handleRemarkChange = (event: React.ChangeEvent<HTMLInputElement>) => updateField('remark', event.target.value);
// handleCookieChange 更新账号 Cookie 字段。
const handleCookieChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => updateField('cookie', event.target.value);
// handleAutoConfirmToggle 切换自动确认发货设置。
const handleAutoConfirmToggle = () => updateField('auto_confirm', !editForm.auto_confirm);
// handlePauseDurationChange 更新账号暂停时长。
const handlePauseDurationChange = (event: React.ChangeEvent<HTMLInputElement>) => updateField('pause_duration', parseInt(event.target.value, 10) || 0);
// handleRestartPause 按当前时长立即重新暂停账号。
const handleRestartPause = () => void onRestartPause();
// handleLongLoginToggle 切换闲鱼官方长登录设置。
const handleLongLoginToggle = () => void onToggleLongLogin();
// handleUsernameChange 更新密码登录用户名。
const handleUsernameChange = (event: React.ChangeEvent<HTMLInputElement>) => updateField('username', event.target.value);
// handlePasswordChange 更新密码并清除待清空标记。
const handlePasswordChange = (event: React.ChangeEvent<HTMLInputElement>) => setEditForm(
// current 是密码输入前的最新编辑表单。
current => ({ ...current, login_password: event.target.value, clear_password: false }),
);
// handlePasswordVisibilityToggle 切换密码明文显示状态。
const handlePasswordVisibilityToggle = () => updateField('showLoginPassword', !editForm.showLoginPassword);
// handleClearPasswordChange 更新密码清空选项。
const handleClearPasswordChange = (event: React.ChangeEvent<HTMLInputElement>) => setEditForm(
// current 是勾选清空密码前的最新编辑表单。
current => ({ ...current, clear_password: event.target.checked, login_password: event.target.checked ? '' : current.login_password }),
);
// handleShowBrowserToggle 切换密码登录时是否展示浏览器。
const handleShowBrowserToggle = () => updateField('show_browser', !editForm.show_browser);
// handleCancelPasswordLogin 取消正在执行的密码登录。
const handleCancelPasswordLogin = () => void onCancelPasswordLogin();
// handlePasswordLogin 启动密码登录刷新授权。
const handlePasswordLogin = () => void onPasswordLogin();
// handleRetryBindings 重新加载当前账号的通知绑定。
const handleRetryBindings = () => void onRetryBindings();
// handleChannelClick 切换通知渠道并标记绑定表单已修改。
const handleChannelClick = (channelId: number) => {
if (!bindingsLoaded) return;
onToggleChannel(channelId);
onSettingsDirty();
};
// renderNotificationChannel 渲染单个通知渠道选项。
const renderNotificationChannel = (channel: NotificationChannel) => {
// checked 表示当前通知渠道是否已被选中。
const checked = selectedChannelIds.includes(Number(channel.id));
// handleChannelButtonClick 把渠道 ID 绑定到当前选项的点击事件。
const handleChannelButtonClick = () => handleChannelClick(Number(channel.id));
return (
<label key={channel.id} className="flex items-center gap-3 p-3 rounded-xl border border-gray-200 hover:bg-gray-50 cursor-pointer transition-colors">
<button
type="button"
onClick={handleChannelButtonClick}
disabled={!bindingsLoaded}
className={`w-5 h-5 rounded-md border-2 flex items-center justify-center transition-colors flex-shrink-0 ${checked ? 'bg-brand border-brand' : 'bg-white border-gray-300'}`}
>
{checked && <Check className="w-3.5 h-3.5 text-white" />}
</button>
<div className="flex-1 min-w-0">
<div className="font-bold text-gray-900 text-sm">{channel.name}</div>
<div className="text-xs text-gray-500">{channel.type}{channel.enabled ? '' : ' · 已停用'}</div>
</div>
</label>
);
};
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">编辑账号</h3>
<p className="text-sm text-gray-500 mt-1">{account.nickname || account.remark || account.id}</p>
</div>
<button onClick={handleClose} 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">
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">账号ID</label>
<input type="text" value={account.id} disabled className="w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500" />
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">备注</label>
<input
type="text"
value={editForm.remark}
onChange={handleRemarkChange}
placeholder="为账号添加备注"
className="w-full ios-input px-4 py-3 rounded-xl"
/>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">Cookie</label>
<textarea
value={editForm.cookie}
onChange={handleCookieChange}
placeholder="更新账号Cookie"
className="w-full ios-input px-4 py-3 rounded-xl h-32 resize-none font-mono text-xs"
/>
<p className="text-xs text-gray-500 mt-1">当前Cookie长度: {editForm.cookie.length} 字符</p>
</div>
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-xl">
<div>
<div className="font-bold text-gray-900 flex items-center gap-2"><Check className="w-4 h-4 text-green-500" />自动确认发货</div>
<div className="text-xs text-gray-500">自动将闲鱼订单标记为已发货</div>
</div>
<button
type="button"
onClick={handleAutoConfirmToggle}
className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${editForm.auto_confirm ? '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 ${editForm.auto_confirm ? 'translate-x-6' : 'translate-x-0'}`} />
</button>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2 flex items-center gap-2"><Clock className="w-4 h-4 text-blue-500" />暂停处理时长(分钟)</label>
<input
type="number"
value={editForm.pause_duration}
onChange={handlePauseDurationChange}
placeholder="0"
min="0"
max="1440"
className="w-full ios-input px-4 py-3 rounded-xl"
/>
<p className="text-xs text-gray-500 mt-1">设置后会暂停处理该账号的订单,到时间后自动恢复</p>
{editForm.pause_duration > 0 && !account.paused && editForm.pause_duration === (account.pause_duration || 0) && (
<button type="button" disabled={saving} onClick={handleRestartPause} className="mt-3 px-4 py-2 rounded-xl bg-amber-50 text-amber-700 hover:bg-amber-100 text-sm font-bold disabled:opacity-50">
立即按当前时长重新暂停
</button>
)}
</div>
<div className="border-t border-gray-200 pt-6">
<h3 className="text-lg font-bold text-gray-900 mb-4 flex items-center gap-2"><Key className="w-5 h-5 text-blue-500" />登录信息</h3>
<div className="space-y-4">
<div className="flex items-center justify-between gap-4 rounded-xl bg-blue-50 p-4">
<div>
<div className="font-bold text-gray-900">保存登录信息</div>
<div className="mt-1 text-xs text-gray-500">状态直接读取并修改闲鱼官方长登录设置</div>
{longLogin.error && <div className="mt-1 text-xs text-red-600">{longLogin.error}</div>}
</div>
<button
type="button"
aria-label="保存登录信息"
disabled={longLogin.loading || longLogin.saving || !longLogin.canOpen}
onClick={handleLongLoginToggle}
className={`relative h-8 w-14 flex-shrink-0 rounded-full transition-colors ${longLogin.enabled ? 'bg-brand' : 'bg-gray-300'} disabled:cursor-not-allowed disabled:opacity-50`}
>
<span className={`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-md transition-transform ${longLogin.enabled ? 'translate-x-6' : 'translate-x-0'}`} />
</button>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">用户名</label>
<input type="text" value={editForm.username} onChange={handleUsernameChange} placeholder="闲鱼账号/手机号" className="w-full ios-input px-4 py-3 rounded-xl" />
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">登录密码</label>
<div className="relative">
<input
type={editForm.showLoginPassword ? 'text' : 'password'}
value={editForm.login_password}
onChange={handlePasswordChange}
placeholder="用于自动登录"
className="w-full ios-input px-4 py-3 rounded-xl pr-12"
/>
<button type="button" onClick={handlePasswordVisibilityToggle} className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600">
{editForm.showLoginPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
</button>
</div>
<label className="mt-3 flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={editForm.clear_password}
onChange={handleClearPasswordChange}
className="w-4 h-4 accent-brand"
/>
<span className="text-sm font-bold text-gray-700">清空已保存密码</span>
</label>
</div>
<div className="flex items-center justify-between">
<div>
<div className="font-bold text-gray-900">登录时显示浏览器</div>
<div className="text-xs text-gray-500">调试时可开启查看登录过程</div>
</div>
<button type="button" onClick={handleShowBrowserToggle} className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${editForm.show_browser ? '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 ${editForm.show_browser ? 'translate-x-6' : 'translate-x-0'}`} />
</button>
</div>
<div className="rounded-xl border border-blue-100 bg-blue-50 p-4 space-y-3">
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
<div>
<div className="font-bold text-blue-950">立即执行账号密码登录</div>
<div className="text-xs text-blue-700 mt-1">需要在上方重新输入本次登录密码;成功后后端会更新 Cookie 和保存的登录信息。</div>
</div>
{(passwordLoginView.status === 'processing' || passwordLoginView.status === 'verification_required') ? (
<button type="button" onClick={handleCancelPasswordLogin} className="px-4 py-2 rounded-xl bg-white text-red-600 font-bold text-sm border border-red-100">取消登录</button>
) : (
<button type="button" onClick={handlePasswordLogin} className="px-4 py-2 rounded-xl bg-blue-600 text-white font-bold text-sm whitespace-nowrap">密码登录刷新授权</button>
)}
</div>
{passwordLoginView.message && (
<div className={`text-sm font-medium ${passwordLoginView.status === 'failed' ? 'text-red-700' : passwordLoginView.status === 'success' ? 'text-green-700' : 'text-blue-800'}`}>{passwordLoginView.message}</div>
)}
{passwordLoginView.status === 'verification_required' && (
<div className="rounded-xl border border-amber-200 bg-amber-50 p-3 text-amber-900">
<div className="font-extrabold">账号已触发平台风控,需要完成人脸识别</div>
<div className="text-xs mt-1 leading-5">请在闲鱼 App 或已打开的登录浏览器中按提示完成验证。本页面不会提供可直接打开的风控链接。</div>
{passwordLoginView.qrCodeUrl && <div className="mt-3 aspect-square w-48 overflow-hidden rounded-xl border bg-white"><SquareQRCode src={passwordLoginView.qrCodeUrl} alt="密码登录风控二维码" className="p-2" /></div>}
</div>
)}
</div>
</div>
</div>
{(notifChannels.length > 0 || bindingsLoading || bindingsLoadError) && (
<div className="border-t border-gray-200 pt-6">
<h3 className="text-lg font-bold text-gray-900 mb-1 flex items-center gap-2"><Bell className="w-5 h-5 text-blue-500" />通知渠道绑定</h3>
<p className="text-xs text-gray-500 mb-4">勾选后,该账号的 token 失效、自动恢复失败、风控验证等事件会推送到这些渠道</p>
{bindingsLoading && <div className="flex items-center gap-2 text-sm text-gray-500"><Loader2 className="w-4 h-4 animate-spin" />正在加载通知绑定</div>}
{bindingsLoadError && !bindingsLoading && (
<div className="mb-3 rounded-xl bg-amber-50 p-3 text-sm text-amber-800 flex items-center justify-between gap-3">
<span>{bindingsLoadError}</span>
<button type="button" className="font-bold whitespace-nowrap" onClick={handleRetryBindings}>重试</button>
</div>
)}
<div className="space-y-2">
{notifChannels.map(renderNotificationChannel)}
</div>
</div>
)}
</div>
<div className="modal-footer">
<div className="flex gap-3 w-full">
<button onClick={handleClose} 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={handleSave} 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" /> : <Check className="w-4 h-4" />}
{saving ? '保存中...' : '保存'}
</button>
</div>
</div>
</div>
</div>,
document.body,
);
};
+136
View File
@@ -0,0 +1,136 @@
import { useCallback, useEffect, useRef, useState, type Dispatch, type SetStateAction } from 'react';
import { getAccountDetails, getAccountRuntimeStatuses, getAllAISettings } from './api';
import type { AccountDetail } from '../../../types';
import { mergeAccountRuntimeStatuses } from './runtime';
import type { AccountAISettingsState } from './types';
// AccountsDataResult 暴露账号列表、加载状态和可复用的刷新动作。
export interface AccountsDataResult {
// accounts 是当前账号列表及其 AI、运行时展示字段。
accounts: AccountDetail[];
// setAccounts 允许页面在删除或任务设置保存后局部更新列表。
setAccounts: Dispatch<SetStateAction<AccountDetail[]>>;
// loading 表示账号基础数据是否正在加载。
loading: boolean;
// loadAccounts 刷新账号基础资料和 AI 设置。
loadAccounts: () => Promise<void>;
}
// mergeAccountAISettings 将 AI 配置补充到账号详情,缺省值保持页面原有行为。
export const mergeAccountAISettings = (
accounts: AccountDetail[],
allAISettings: AccountAISettingsState,
): AccountDetail[] => accounts.map(
// account 是待补充 AI 配置的账号对象。
account => ({
...account,
ai_enabled: allAISettings[account.id]?.ai_enabled ?? false,
max_discount_percent: allAISettings[account.id]?.max_discount_percent ?? 10,
max_discount_amount: allAISettings[account.id]?.max_discount_amount ?? 100,
max_bargain_rounds: allAISettings[account.id]?.max_bargain_rounds ?? 3,
custom_prompts: allAISettings[account.id]?.custom_prompts ?? '',
}),
);
// useAccountsData 统一管理账号加载、AI 合并和运行状态短轮询。
export const useAccountsData = (): AccountsDataResult => {
// accounts 保存页面当前可见的账号详情。
const [accounts, setAccounts] = useState<AccountDetail[]>([]);
// loading 表示首次加载或手动刷新的账号基础数据是否未完成。
const [loading, setLoading] = useState(true);
// accountLoadGeneration 丢弃切换或连续刷新后到达的旧账号响应。
const accountLoadGeneration = useRef(0);
// accountLoadAbort 保存当前账号加载请求的取消控制器。
const accountLoadAbort = useRef<AbortController | null>(null);
// loadAccounts 并行读取账号详情和 AI 设置,并只提交最新请求结果。
const loadAccounts = useCallback(
// 账号加载回调并行请求详情和 AI 设置。
async () => {
// generation 标记本次账号刷新请求的代次。
const generation = ++accountLoadGeneration.current;
accountLoadAbort.current?.abort();
// controller 让新刷新开始时主动取消旧的网络请求。
const controller = new AbortController();
accountLoadAbort.current = controller;
setLoading(true);
try {
// options 将同一个取消信号传给两个彼此独立的请求。
const options = { signal: controller.signal };
// results 让账号详情和 AI 配置并行加载,AI 失败不阻断账号列表。
const [detailsResult, aiResult] = await Promise.allSettled([
getAccountDetails(options),
getAllAISettings(options),
]);
if (generation !== accountLoadGeneration.current) return;
if (detailsResult.status === 'rejected') throw detailsResult.reason;
// allAISettings 是按账号 ID 索引的 AI 配置快照。
const allAISettings = aiResult.status === 'fulfilled' ? aiResult.value : {};
if (aiResult.status === 'rejected') console.error('加载 AI 设置失败:', aiResult.reason);
setAccounts(mergeAccountAISettings(detailsResult.value, allAISettings));
} catch (error /* 账号加载错误 */) {
if (generation === accountLoadGeneration.current && !controller.signal.aborted) {
console.error('加载账号失败:', error);
}
} finally {
if (generation === accountLoadGeneration.current) setLoading(false);
}
},
[],
);
useEffect(
// 账号数据副作用负责首次加载和运行状态轮询。
() => {
// cancelled 表示页面已卸载,阻止轮询继续写入 React 状态。
let cancelled = false;
// timer 保存下一次运行状态轮询的句柄。
let timer: number | null = null;
// runtimeController 取消页面卸载时仍在执行的运行状态请求。
const runtimeController = new AbortController();
// pollRuntimeStatuses 读取进程内运行状态并安排下一次轮询。
const pollRuntimeStatuses = async () => {
try {
// statuses 是后端按账号 ID 返回的最新运行状态快照。
const statuses = await getAccountRuntimeStatuses({ signal: runtimeController.signal, timeoutMs: 10_000 });
if (!cancelled) {
setAccounts(
// current 是运行状态轮询开始前的最新账号列表。
current => mergeAccountRuntimeStatuses(current, statuses),
);
}
} catch (error /* 运行状态轮询错误 */) {
if (!cancelled) console.error('加载账号运行状态失败:', error);
} finally {
if (!cancelled) {
timer = window.setTimeout(
// timerCallback 在两秒后启动下一次运行状态轮询。
() => void pollRuntimeStatuses(),
2_000,
);
}
}
};
void loadAccounts().finally(
// loadFinished 在初始账号加载完成后启动第一次状态轮询。
() => {
if (!cancelled) void pollRuntimeStatuses();
},
);
// cleanup 在页面卸载时停止账号请求和运行状态轮询。
const cleanup = () => {
cancelled = true;
runtimeController.abort();
accountLoadGeneration.current += 1;
accountLoadAbort.current?.abort();
if (timer !== null) window.clearTimeout(timer);
};
return cleanup;
},
[loadAccounts],
);
return { accounts, setAccounts, loading, loadAccounts };
};
+58
View File
@@ -0,0 +1,58 @@
import type { AccountRuntimeStatus } from './api';
import type { AccountDetail } from '../../../types';
import type { AccountRuntimePresentation } from './types';
// isOlderStatus 判断传入的运行时快照是否早于账号当前已展示的快照。
export const isOlderStatus = (currentUpdatedAt?: string, incomingUpdatedAt?: string): boolean => {
if (!currentUpdatedAt || !incomingUpdatedAt) return false;
// currentTime 是账号当前已展示快照的时间戳。
const currentTime = Date.parse(currentUpdatedAt);
// incomingTime 是本次轮询返回快照的时间戳。
const incomingTime = Date.parse(incomingUpdatedAt);
return Number.isFinite(currentTime) && Number.isFinite(incomingTime) && incomingTime < currentTime;
};
// mergeAccountRuntimeStatuses 将最新运行时快照合并到账号列表,并拒绝过期响应。
export const mergeAccountRuntimeStatuses = (
accounts: AccountDetail[],
statuses: Record<string, AccountRuntimeStatus>,
): AccountDetail[] => accounts.map(
// account 是待合并运行时快照的账号对象。
account => {
// status 是服务端按账号 ID 返回的运行时状态。
const status = statuses[account.id];
if (!status || isOlderStatus(account.runtime_updated_at, status.updated_at)) return account;
return {
...account,
runtime_state: status.state,
runtime_message: status.message || '',
runtime_connected: status.connected,
runtime_updated_at: status.updated_at,
};
},
);
// accountRuntimePresentation 将后端运行状态转换为列表徽标和状态点样式。
export const accountRuntimePresentation = (account: AccountDetail): AccountRuntimePresentation => {
if (!account.enabled || account.runtime_state === 'disabled') {
return { label: '已停用', badge: 'bg-gray-100 text-gray-500', dot: 'bg-gray-300' };
}
switch (account.runtime_state) {
case 'online':
return { label: '在线', badge: 'bg-green-100 text-green-700', dot: 'bg-green-500' };
case 'starting':
case 'connecting':
return { label: '连接中', badge: 'bg-blue-100 text-blue-700', dot: 'bg-blue-500' };
case 'reconnecting':
return { label: '重连中', badge: 'bg-amber-100 text-amber-700', dot: 'bg-amber-500' };
case 'auth_expired':
return { label: '登录已失效', badge: 'bg-red-100 text-red-700', dot: 'bg-red-500' };
case 'verification_required':
return { label: '需要验证', badge: 'bg-orange-100 text-orange-700', dot: 'bg-orange-500' };
case 'error':
case 'stopped':
return { label: '运行异常', badge: 'bg-red-100 text-red-700', dot: 'bg-red-500' };
default:
return { label: '状态检测中', badge: 'bg-gray-100 text-gray-600', dot: 'bg-gray-400' };
}
};
@@ -0,0 +1,73 @@
import { expect, test } from 'vitest';
import type { AccountDetail } from '../../../types';
import {
buildAccountLoginInfoUpdate,
isCurrentAccountRequest,
passwordLoginViewFromStatus,
shouldUpdateAccountPause,
} from './state';
// account 是账号编辑状态测试使用的最小领域对象。
const account = (overrides: Partial<AccountDetail> = {}): AccountDetail => ({
id: 'account-1',
enabled: true,
auto_confirm: false,
username: 'old-user',
show_browser: false,
pause_duration: 60,
...overrides,
});
test('账号切换后只接受当前请求代次和账号的响应',
// 旧账号响应即使更晚返回,也不能覆盖当前编辑账号。
() => {
expect(isCurrentAccountRequest(2, 2, 'account-2', 'account-2')).toBe(true);
expect(isCurrentAccountRequest(1, 2, 'account-2', 'account-2')).toBe(false);
expect(isCurrentAccountRequest(2, 2, 'account-1', 'account-2')).toBe(false);
});
test('暂停时长未变化时不会重复启动已结束的暂停',
// 相同的时长只保留当前状态,不自动重新提交暂停请求。
() => {
expect(shouldUpdateAccountPause(60, account({ paused: false }))).toBe(false);
expect(shouldUpdateAccountPause(30, account({ paused: true }))).toBe(true);
expect(shouldUpdateAccountPause(0, account({ paused: true }))).toBe(true);
});
test('凭证编辑不提交空白密码,并支持明确清空密码',
// 登录账号或浏览器开关变化时,空白密码不能覆盖已有凭证。
() => {
expect(buildAccountLoginInfoUpdate(account(), {
username: 'new-user',
login_password: '',
show_browser: true,
clear_password: false,
})).toEqual({ username: 'new-user', show_browser: true });
expect(buildAccountLoginInfoUpdate(account(), {
username: 'old-user',
login_password: '',
show_browser: false,
clear_password: true,
})).toEqual({ username: 'old-user', show_browser: false, clear_password: true });
});
test('密码登录风控和失败状态统一转换且不暴露验证链接',
// 风控状态只展示二维码和提示,失败状态展示后端错误说明。
() => {
expect(passwordLoginViewFromStatus({
status: 'verification_required',
message: '需要人脸验证',
verification_url: 'https://verification.example',
qr_code_url: 'https://qr.example',
})).toEqual({
sessionId: '',
status: 'verification_required',
message: '需要人脸验证',
qrCodeUrl: 'https://qr.example',
});
expect(passwordLoginViewFromStatus({ status: 'failed', error: '凭证失效' })).toMatchObject({
status: 'failed',
message: '凭证失效',
qrCodeUrl: '',
});
});
+86
View File
@@ -0,0 +1,86 @@
import type { AccountDetail } from '../../../types';
import type { PasswordLoginStatusResponse } from './api';
import type { AccountEditForm, PasswordLoginView } from './types';
// AccountLoginEditFields 描述账号编辑表单中参与登录信息比较的字段。
export type AccountLoginEditFields = Pick<AccountEditForm, 'username' | 'login_password' | 'show_browser'> & Pick<Partial<AccountEditForm>, 'clear_password'>;
// AccountLoginInfoPayload 描述需要提交给后端的登录信息变更。
export interface AccountLoginInfoPayload {
// username 是新的闲鱼登录账号。
username: string;
// login_password 是用户本次输入的新密码。
login_password?: string;
// clear_password 表示清空服务端已保存密码。
clear_password?: boolean;
// show_browser 表示密码登录时是否展示浏览器。
show_browser: boolean;
}
// shouldUpdateAccountPause 判断暂停时长是否真的发生变化,避免无意重启已结束的暂停。
export const shouldUpdateAccountPause = (
requestedMinutes: number,
account: Pick<AccountDetail, 'pause_duration' | 'paused'>,
): boolean => requestedMinutes !== (account.pause_duration || 0);
// buildAccountLoginInfoUpdate 只生成真正变化的登录字段,并拒绝提交空白密码。
export const buildAccountLoginInfoUpdate = (
account: AccountDetail,
form: AccountLoginEditFields,
): AccountLoginInfoPayload | null => {
// usernameChanged 表示登录账号是否被修改。
const usernameChanged = form.username !== (account.username || '');
// showBrowserChanged 表示登录浏览器展示开关是否被修改。
const showBrowserChanged = form.show_browser !== (account.show_browser || false);
// passwordChanged 表示用户是否输入了新的非空密码。
const passwordChanged = form.login_password !== '';
// passwordCleared 表示用户是否明确要求清空密码。
const passwordCleared = form.clear_password === true;
if (!usernameChanged && !showBrowserChanged && !passwordChanged && !passwordCleared) return null;
// payload 是提交给账号设置接口的登录信息补丁。
const payload: AccountLoginInfoPayload = {
username: form.username,
show_browser: form.show_browser,
};
if (passwordCleared) {
payload.clear_password = true;
} else if (passwordChanged) {
payload.login_password = form.login_password;
}
return payload;
};
// isCurrentAccountRequest 判断账号切换后异步响应是否仍属于当前请求。
export const isCurrentAccountRequest = (
requestGeneration: number,
currentGeneration: number,
requestAccountId: string,
currentAccountId: string,
): boolean => requestGeneration === currentGeneration && requestAccountId === currentAccountId;
// passwordLoginViewFromStatus 将密码登录接口状态转换为编辑弹窗状态。
export const passwordLoginViewFromStatus = (result: PasswordLoginStatusResponse): PasswordLoginView => {
if (result.status === 'success') {
return {
sessionId: '',
status: 'success',
message: result.message || '账号密码登录成功,授权信息已更新',
qrCodeUrl: '',
};
}
if (result.status === 'processing' || result.status === 'verification_required') {
return {
sessionId: '',
status: result.status,
message: result.message || (result.status === 'verification_required' ? '账号触发风控,需要完成人脸识别' : '登录处理中'),
qrCodeUrl: result.qr_code_url || '',
};
}
return {
sessionId: '',
status: 'failed',
message: result.error || result.message || '密码登录失败,请检查账号信息后重试',
qrCodeUrl: '',
};
};
+107
View File
@@ -0,0 +1,107 @@
import type { Dispatch, SetStateAction } from 'react';
import type { AccountDetail, AIReplySettings, NotificationChannel } from '../../../types';
// AccountEditForm 描述账号编辑弹窗中的可编辑字段。
export interface AccountEditForm {
// remark 是账号备注。
remark: string;
// cookie 是手工维护的授权 Cookie。
cookie: string;
// auto_confirm 表示是否自动确认发货。
auto_confirm: boolean;
// pause_duration 是账号订单处理暂停时长,单位为分钟。
pause_duration: number;
// username 是用于密码登录的闲鱼账号。
username: string;
// login_password 是本次输入或已保存的登录密码。
login_password: string;
// show_browser 表示密码登录时是否展示浏览器窗口。
show_browser: boolean;
// showLoginPassword 控制密码输入框是否显示明文。
showLoginPassword: boolean;
// clear_password 表示保存时清空服务端密码。
clear_password: boolean;
}
// PasswordLoginView 描述密码登录刷新授权的异步状态。
export interface PasswordLoginView {
// sessionId 是后端创建的密码登录会话标识。
sessionId: string;
// status 是当前密码登录阶段。
status: 'idle' | 'processing' | 'verification_required' | 'success' | 'failed';
// message 是面向用户展示的状态说明。
message: string;
// qrCodeUrl 是风控人脸验证二维码地址。
qrCodeUrl: string;
}
// LongLoginState 描述闲鱼官方长登录设置的读取和保存状态。
export interface LongLoginState {
// loading 表示正在读取长登录设置。
loading: boolean;
// saving 表示正在保存长登录设置。
saving: boolean;
// canOpen 表示当前账号是否允许修改长登录设置。
canOpen: boolean;
// enabled 表示闲鱼官方当前是否启用长登录。
enabled: boolean;
// error 保存读取或保存失败的用户可见说明。
error: string;
}
// AccountRuntimePresentation 是账号运行状态在列表中的展示信息。
export interface AccountRuntimePresentation {
// label 是状态徽标文本。
label: string;
// badge 是状态徽标使用的 Tailwind 样式。
badge: string;
// dot 是头像旁状态点使用的 Tailwind 样式。
dot: string;
}
// AccountEditModalProps 描述账号编辑组件需要的状态和交互回调。
export interface AccountEditModalProps {
// account 是当前正在编辑的账号。
account: AccountDetail;
// editForm 是编辑表单的当前值。
editForm: AccountEditForm;
// setEditForm 更新编辑表单字段。
setEditForm: Dispatch<SetStateAction<AccountEditForm>>;
// saving 表示保存或立即暂停动作正在执行。
saving: boolean;
// onClose 关闭编辑弹窗并取消未完成的登录操作。
onClose: () => void | Promise<void>;
// onSave 保存账号编辑内容。
onSave: () => void | Promise<void>;
// onRestartPause 按当前时长重新暂停账号。
onRestartPause: () => void | Promise<void>;
// longLogin 是官方长登录设置状态。
longLogin: LongLoginState;
// onToggleLongLogin 切换官方长登录设置。
onToggleLongLogin: () => void | Promise<void>;
// passwordLoginView 是密码登录刷新授权状态。
passwordLoginView: PasswordLoginView;
// onPasswordLogin 启动密码登录刷新授权。
onPasswordLogin: () => void | Promise<void>;
// onCancelPasswordLogin 取消当前密码登录会话。
onCancelPasswordLogin: () => void | Promise<void>;
// notifChannels 是可供账号绑定的通知渠道。
notifChannels: NotificationChannel[];
// selectedChannelIds 是当前已选中的通知渠道 ID。
selectedChannelIds: number[];
// bindingsLoaded 表示通知绑定是否成功加载。
bindingsLoaded: boolean;
// bindingsLoading 表示通知渠道和绑定关系正在加载。
bindingsLoading: boolean;
// bindingsLoadError 是通知绑定加载失败的说明。
bindingsLoadError: string;
// onRetryBindings 重新加载当前账号的通知绑定。
onRetryBindings: () => void | Promise<void>;
// onToggleChannel 切换一个通知渠道的选中状态。
onToggleChannel: (channelId: number) => void;
// onSettingsDirty 标记通知绑定已被用户修改。
onSettingsDirty: () => void;
}
// AccountAISettingsState 是账号列表合并 AI 配置时使用的索引结构。
export type AccountAISettingsState = Record<string, AIReplySettings>;
+81 -447
View File
@@ -2,8 +2,6 @@ import React, { useEffect, useRef, useState } from 'react';
import { createPortal } from 'react-dom';
import { AccountDetail, AIReplySettings, NotificationChannel } from '../types';
import {
getAccountDetails,
getAccountRuntimeStatuses,
updateAccountStatus,
deleteAccount,
generateQRLogin,
@@ -16,32 +14,32 @@ import {
checkPasswordLoginStatus,
cancelPasswordLogin,
updateAccountAISettings,
getAllAISettings,
getAccountAISettings,
getNotificationChannels,
getAccountBindings,
getLongLoginSettings,
setLongLoginSettings,
} from '../services/api';
import { shouldUpdateAccountPause } from './accountPause';
} from '../app/features/accounts/api';
import {
Plus, Power, Edit2, Trash2, QrCode, X, Check, Loader2,
Power, Edit2, Trash2, QrCode, X, Check, Loader2,
RefreshCw, Save, User, Clock, MessageCircle,
Upload, Key, Eye, EyeOff, Bot, Settings, AlertCircle, Bell, CalendarClock, Sparkles
Bot, Settings, AlertCircle, CalendarClock, Sparkles
} from 'lucide-react';
import { buildAccountLoginInfoUpdate } from './accountEdit';
import { buildAccountLoginInfoUpdate, isCurrentAccountRequest, passwordLoginViewFromStatus, shouldUpdateAccountPause } from '../app/features/accounts/state';
import { shouldSaveNotificationBindings } from './accountBindings';
import { mergeAccountRuntimeStatuses } from './accountRuntimeState';
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 { useAccountsData } from '../app/features/accounts/hooks';
import { accountRuntimePresentation } from '../app/features/accounts/runtime';
import type { AccountEditForm, LongLoginState, PasswordLoginView } from '../app/features/accounts/types';
type ModalType = 'edit' | 'ai-settings' | null;
const AccountList: React.FC = () => {
const [accounts, setAccounts] = useState<AccountDetail[]>([]);
const [loading, setLoading] = useState(true);
const { accounts, setAccounts, loading, loadAccounts } = useAccountsData();
const [accountSearch, setAccountSearch] = useState('');
const [refreshingProfileId, setRefreshingProfileId] = useState<string>('');
const [deletingAccountId, setDeletingAccountId] = useState<string>('');
@@ -57,7 +55,7 @@ const AccountList: React.FC = () => {
const [activeModal, setActiveModal] = useState<ModalType>(null);
const [editingAccount, setEditingAccount] = useState<AccountDetail | null>(null);
const [taskAccount, setTaskAccount] = useState<AccountDetail | null>(null);
const [longLogin, setLongLogin] = useState({ loading: false, saving: false, canOpen: false, enabled: false, error: '' });
const [longLogin, setLongLogin] = useState<LongLoginState>({ loading: false, saving: false, canOpen: false, enabled: false, error: '' });
// 通知渠道绑定(编辑弹窗用)
const [notifChannels, setNotifChannels] = useState<NotificationChannel[]>([]);
@@ -68,7 +66,7 @@ const AccountList: React.FC = () => {
const [bindingsLoadError, setBindingsLoadError] = useState('');
// 编辑表单状态
const [editForm, setEditForm] = useState({
const [editForm, setEditForm] = useState<AccountEditForm>({
remark: '',
cookie: '',
auto_confirm: false,
@@ -89,18 +87,11 @@ const AccountList: React.FC = () => {
custom_prompts: '',
});
const [saving, setSaving] = useState(false);
const [passwordLoginView, setPasswordLoginView] = useState<{
sessionId: string;
status: 'idle' | 'processing' | 'verification_required' | 'success' | 'failed';
message: string;
qrCodeUrl: string;
}>({ sessionId: '', status: 'idle', message: '', qrCodeUrl: '' });
const [passwordLoginView, setPasswordLoginView] = useState<PasswordLoginView>({ sessionId: '', status: 'idle', message: '', qrCodeUrl: '' });
const qrPollerRef = useRef<ReturnType<typeof createQRLoginPoller> | null>(null);
const qrRequestGateRef = useRef<ReturnType<typeof createLatestRequestGate> | null>(null);
const accountLoadGateRef = useRef<ReturnType<typeof createLatestRequestGate> | null>(null);
const bindingsLoadGateRef = useRef<ReturnType<typeof createLatestRequestGate> | null>(null);
const aiLoadGateRef = useRef<ReturnType<typeof createLatestRequestGate> | null>(null);
const accountLoadAbortRef = useRef<AbortController | null>(null);
const bindingsLoadAbortRef = useRef<AbortController | null>(null);
const aiLoadAbortRef = useRef<AbortController | null>(null);
const qrGenerateAbortRef = useRef<AbortController | null>(null);
@@ -108,13 +99,13 @@ const AccountList: React.FC = () => {
const qrCloseTimerRef = useRef<number | null>(null);
const passwordPollTimerRef = useRef<number | null>(null);
const passwordPollGenerationRef = useRef(0);
const passwordPollAccountRef = useRef('');
if (qrPollerRef.current === null) {
qrPollerRef.current = createQRLoginPoller();
}
if (qrRequestGateRef.current === null) {
qrRequestGateRef.current = createLatestRequestGate();
}
if (accountLoadGateRef.current === null) accountLoadGateRef.current = createLatestRequestGate();
if (bindingsLoadGateRef.current === null) bindingsLoadGateRef.current = createLatestRequestGate();
if (aiLoadGateRef.current === null) aiLoadGateRef.current = createLatestRequestGate();
@@ -153,114 +144,23 @@ const AccountList: React.FC = () => {
}, 1000);
};
const loadAccounts = async () => {
const generation = accountLoadGateRef.current!.next();
accountLoadAbortRef.current?.abort();
const controller = new AbortController();
accountLoadAbortRef.current = controller;
setLoading(true);
try {
const options = { signal: controller.signal };
const [detailsResult, aiResult] = await Promise.allSettled([getAccountDetails(options), getAllAISettings(options)]);
if (!accountLoadGateRef.current?.isCurrent(generation)) return;
if (detailsResult.status === 'rejected') throw detailsResult.reason;
const data = detailsResult.value;
const allAISettings = aiResult.status === 'fulfilled' ? aiResult.value : {};
if (aiResult.status === 'rejected') console.error('Failed to load AI settings:', aiResult.reason);
// 合并AI设置到账号数据
const accountsWithAI = data.map(account => ({
...account,
ai_enabled: allAISettings[account.id]?.ai_enabled ?? false,
max_discount_percent: allAISettings[account.id]?.max_discount_percent ?? 10,
max_discount_amount: allAISettings[account.id]?.max_discount_amount ?? 100,
max_bargain_rounds: allAISettings[account.id]?.max_bargain_rounds ?? 3,
custom_prompts: allAISettings[account.id]?.custom_prompts ?? '',
}));
if (accountLoadGateRef.current?.isCurrent(generation)) setAccounts(accountsWithAI);
} catch (error) {
if (accountLoadGateRef.current?.isCurrent(generation) && !controller.signal.aborted) {
console.error('Failed to load accounts:', error);
}
} finally {
if (accountLoadGateRef.current?.isCurrent(generation)) setLoading(false);
}
};
useEffect(() => {
let cancelled = false;
let timer: number | null = null;
const runtimeController = new AbortController();
const pollRuntimeStatuses = async () => {
try {
const statuses = await getAccountRuntimeStatuses({ signal: runtimeController.signal, timeoutMs: 10_000 });
if (!cancelled) {
setAccounts(current => mergeAccountRuntimeStatuses(current, statuses));
}
} catch (error) {
if (!cancelled) console.error('Failed to load account runtime statuses:', error);
} finally {
if (!cancelled) {
// 运行时状态只读取本地内存;短轮询让风控恢复提示在约 2 秒内收敛。
timer = window.setTimeout(() => void pollRuntimeStatuses(), 2_000);
}
}
};
void loadAccounts().finally(() => {
if (!cancelled) void pollRuntimeStatuses();
});
return () => {
cancelled = true;
runtimeController.abort();
if (timer !== null) window.clearTimeout(timer);
};
}, []);
useEffect(() => {
// 页面卸载时取消二维码、通知绑定、AI 设置和密码登录的异步资源。
return () => {
stopQRPolling();
qrRequestGateRef.current?.cancel();
accountLoadGateRef.current?.cancel();
bindingsLoadGateRef.current?.cancel();
aiLoadGateRef.current?.cancel();
accountLoadAbortRef.current?.abort();
bindingsLoadAbortRef.current?.abort();
aiLoadAbortRef.current?.abort();
qrGenerateAbortRef.current?.abort();
passwordPollAbortRef.current?.abort();
bindingsLoadGateRef.current?.cancel();
aiLoadGateRef.current?.cancel();
bindingsLoadAbortRef.current?.abort();
aiLoadAbortRef.current?.abort();
qrGenerateAbortRef.current?.abort();
passwordPollAbortRef.current?.abort();
clearQRCloseTimer();
passwordPollGenerationRef.current += 1;
clearPasswordPollTimer();
};
}, []);
const runtimePresentation = (account: AccountDetail) => {
if (!account.enabled || account.runtime_state === 'disabled') {
return { label: '已停用', badge: 'bg-gray-100 text-gray-500', dot: 'bg-gray-300' };
}
switch (account.runtime_state) {
case 'online':
return { label: '在线', badge: 'bg-green-100 text-green-700', dot: 'bg-green-500' };
case 'starting':
case 'connecting':
return { label: '连接中', badge: 'bg-blue-100 text-blue-700', dot: 'bg-blue-500' };
case 'reconnecting':
return { label: '重连中', badge: 'bg-amber-100 text-amber-700', dot: 'bg-amber-500' };
case 'auth_expired':
return { label: '登录已失效', badge: 'bg-red-100 text-red-700', dot: 'bg-red-500' };
case 'verification_required':
return { label: '需要验证', badge: 'bg-orange-100 text-orange-700', dot: 'bg-orange-500' };
case 'error':
case 'stopped':
return { label: '运行异常', badge: 'bg-red-100 text-red-700', dot: 'bg-red-500' };
default:
return { label: '状态检测中', badge: 'bg-gray-100 text-gray-600', dot: 'bg-gray-400' };
}
};
const handleToggle = async (id: string, currentStatus: boolean) => {
await updateAccountStatus(id, !currentStatus);
loadAccounts();
@@ -341,8 +241,16 @@ const AccountList: React.FC = () => {
setBindingsLoading(false);
};
// toggleNotificationChannel 使用函数式更新切换通知绑定,避免连续点击覆盖选择结果。
const toggleNotificationChannel = (channelId: number) => {
setSelectedChannelIds(current => current.includes(channelId)
? current.filter(id => id !== channelId)
: [...current, channelId]);
};
const openEditModal = async (account: AccountDetail) => {
passwordPollGenerationRef.current += 1;
passwordPollAccountRef.current = account.id;
passwordPollAbortRef.current?.abort();
clearPasswordPollTimer();
setPasswordLoginView({ sessionId: '', status: 'idle', message: '', qrCodeUrl: '' });
@@ -492,45 +400,39 @@ const AccountList: React.FC = () => {
}
};
const pollPasswordLogin = async (sessionId: string, generation: number) => {
passwordPollAbortRef.current?.abort();
const controller = new AbortController();
passwordPollAbortRef.current = controller;
// pollPasswordLogin 轮询密码登录状态,并按账号和请求代次隔离过期响应。
const pollPasswordLogin = async (sessionId: string, generation: number, accountId: string) => {
passwordPollAbortRef.current?.abort();
// controller 取消上一轮仍未完成的密码登录状态请求。
const controller = new AbortController();
passwordPollAbortRef.current = controller;
try {
const result = await checkPasswordLoginStatus(sessionId, controller.signal);
if (generation !== passwordPollGenerationRef.current) return;
// result 是后端返回的当前密码登录状态。
const result = await checkPasswordLoginStatus(sessionId, controller.signal);
if (!isCurrentAccountRequest(generation, passwordPollGenerationRef.current, accountId, passwordPollAccountRef.current)) return;
// nextView 是统一转换后的密码登录展示状态。
const nextView = { ...passwordLoginViewFromStatus(result), sessionId };
if (result.status === 'success') {
clearPasswordPollTimer();
setPasswordLoginView({
sessionId,
status: 'success',
message: result.message || '账号密码登录成功,授权信息已更新',
qrCodeUrl: '',
});
setPasswordLoginView(nextView);
setEditForm(current => ({ ...current, login_password: '', showLoginPassword: false }));
await loadAccounts();
return;
}
if (result.status === 'processing' || result.status === 'verification_required') {
setPasswordLoginView({
sessionId,
status: result.status,
message: result.message || (result.status === 'verification_required' ? '账号触发风控,需要完成人脸识别' : '登录处理中'),
qrCodeUrl: result.qr_code_url || '',
});
setPasswordLoginView(nextView);
clearPasswordPollTimer();
passwordPollTimerRef.current = window.setTimeout(() => void pollPasswordLogin(sessionId, generation), 1500);
passwordPollTimerRef.current = window.setTimeout(
// pollNextStatus 在短暂间隔后继续查询当前密码登录会话。
() => void pollPasswordLogin(sessionId, generation, accountId),
1500,
);
return;
}
clearPasswordPollTimer();
setPasswordLoginView({
sessionId,
status: 'failed',
message: result.error || result.message || '密码登录失败,请检查账号信息后重试',
qrCodeUrl: '',
});
} catch (error) {
if (generation !== passwordPollGenerationRef.current) return;
setPasswordLoginView(nextView);
} catch (error /* 密码登录状态查询错误 */) {
if (!isCurrentAccountRequest(generation, passwordPollGenerationRef.current, accountId, passwordPollAccountRef.current)) return;
clearPasswordPollTimer();
setPasswordLoginView({
sessionId,
@@ -541,6 +443,7 @@ const AccountList: React.FC = () => {
}
};
const handlePasswordLogin = async () => {
if (!editingAccount) return;
const account = editForm.username.trim();
@@ -551,6 +454,7 @@ const AccountList: React.FC = () => {
clearPasswordPollTimer();
passwordPollAbortRef.current?.abort();
const generation = ++passwordPollGenerationRef.current;
passwordPollAccountRef.current = editingAccount.id;
setPasswordLoginView({ sessionId: '', status: 'processing', message: '正在启动密码登录…', qrCodeUrl: '' });
try {
const result = await passwordLogin({
@@ -559,14 +463,14 @@ const AccountList: React.FC = () => {
password: editForm.login_password,
show_browser: editForm.show_browser,
});
if (generation !== passwordPollGenerationRef.current) return;
if (!isCurrentAccountRequest(generation, passwordPollGenerationRef.current, editingAccount.id, passwordPollAccountRef.current)) return;
if (!result.success || !result.session_id) {
throw new Error(result.message || '无法启动密码登录');
}
setPasswordLoginView({ sessionId: result.session_id, status: 'processing', message: result.message || '登录处理中', qrCodeUrl: '' });
await pollPasswordLogin(result.session_id, generation);
await pollPasswordLogin(result.session_id, generation, editingAccount.id);
} catch (error) {
if (generation !== passwordPollGenerationRef.current) return;
if (!isCurrentAccountRequest(generation, passwordPollGenerationRef.current, editingAccount.id, passwordPollAccountRef.current)) return;
setPasswordLoginView({
sessionId: '',
status: 'failed',
@@ -579,6 +483,7 @@ const AccountList: React.FC = () => {
const handleCancelPasswordLogin = async () => {
const sessionId = passwordLoginView.sessionId;
passwordPollGenerationRef.current += 1;
passwordPollAccountRef.current = '';
passwordPollAbortRef.current?.abort();
clearPasswordPollTimer();
if (sessionId) {
@@ -733,7 +638,7 @@ const AccountList: React.FC = () => {
{/* Account Grid */}
<div className="grid grid-cols-1 gap-6">
{filteredAccounts.map((account) => {
const runtime = runtimePresentation(account);
const runtime = accountRuntimePresentation(account);
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">
@@ -1053,304 +958,33 @@ const AccountList: React.FC = () => {
document.body
)}
{/* 编辑账号弹窗 */}
{activeModal === 'edit' && 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">编辑账号</h3>
<p className="text-sm text-gray-500 mt-1">{editingAccount.nickname || editingAccount.remark || editingAccount.id}</p>
</div>
<button
onClick={() => void closeEditModal()}
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">
{/* 账号ID */}
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">账号ID</label>
<input
type="text"
value={editingAccount.id}
disabled
className="w-full ios-input px-4 py-3 rounded-xl bg-gray-50 text-gray-500"
/>
</div>
{/* 备注 */}
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">备注</label>
<input
type="text"
value={editForm.remark}
onChange={(e) => setEditForm({ ...editForm, remark: e.target.value })}
placeholder="为账号添加备注"
className="w-full ios-input px-4 py-3 rounded-xl"
/>
</div>
{/* Cookie */}
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">Cookie</label>
<textarea
value={editForm.cookie}
onChange={(e) => setEditForm({ ...editForm, cookie: e.target.value })}
placeholder="更新账号Cookie"
className="w-full ios-input px-4 py-3 rounded-xl h-32 resize-none font-mono text-xs"
/>
<p className="text-xs text-gray-500 mt-1">当前Cookie长度: {editForm.cookie.length} 字符</p>
</div>
{/* 自动确认发货 */}
<div className="flex items-center justify-between p-4 bg-gray-50 rounded-xl">
<div>
<div className="font-bold text-gray-900 flex items-center gap-2">
<Check className="w-4 h-4 text-green-500" />
自动确认发货
</div>
<div className="text-xs text-gray-500">自动将闲鱼订单标记为已发货</div>
</div>
<button
type="button"
onClick={() => setEditForm({ ...editForm, auto_confirm: !editForm.auto_confirm })}
className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${
editForm.auto_confirm ? '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 ${
editForm.auto_confirm ? 'translate-x-6' : 'translate-x-0'
}`}
/>
</button>
</div>
{/* 暂停时长 */}
<div>
<label className="block text-sm font-bold text-gray-700 mb-2 flex items-center gap-2">
<Clock className="w-4 h-4 text-blue-500" />
暂停处理时长(分钟)
</label>
<input
type="number"
value={editForm.pause_duration}
onChange={(e) => setEditForm({ ...editForm, pause_duration: parseInt(e.target.value) || 0 })}
placeholder="0"
min="0"
max="1440"
className="w-full ios-input px-4 py-3 rounded-xl"
/>
<p className="text-xs text-gray-500 mt-1">设置后会暂停处理该账号的订单,到时间后自动恢复</p>
{editForm.pause_duration > 0 && !editingAccount.paused && editForm.pause_duration === (editingAccount.pause_duration || 0) && (
<button
type="button"
disabled={saving}
onClick={() => void handleRestartPause()}
className="mt-3 px-4 py-2 rounded-xl bg-amber-50 text-amber-700 hover:bg-amber-100 text-sm font-bold disabled:opacity-50"
>
立即按当前时长重新暂停
</button>
)}
</div>
{/* 登录信息 */}
<div className="border-t border-gray-200 pt-6">
<h3 className="text-lg font-bold text-gray-900 mb-4 flex items-center gap-2">
<Key className="w-5 h-5 text-blue-500" />
登录信息
</h3>
<div className="space-y-4">
<div className="flex items-center justify-between gap-4 rounded-xl bg-blue-50 p-4">
<div>
<div className="font-bold text-gray-900">保存登录信息</div>
<div className="mt-1 text-xs text-gray-500">状态直接读取并修改闲鱼官方长登录设置</div>
{longLogin.error && <div className="mt-1 text-xs text-red-600">{longLogin.error}</div>}
</div>
<button
type="button"
aria-label="保存登录信息"
disabled={longLogin.loading || longLogin.saving || !longLogin.canOpen}
onClick={() => void handleLongLoginToggle()}
className={`relative h-8 w-14 flex-shrink-0 rounded-full transition-colors ${longLogin.enabled ? 'bg-brand' : 'bg-gray-300'} disabled:cursor-not-allowed disabled:opacity-50`}
>
<span className={`absolute left-1 top-1 h-6 w-6 rounded-full bg-white shadow-md transition-transform ${longLogin.enabled ? 'translate-x-6' : 'translate-x-0'}`} />
</button>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">用户名</label>
<input
type="text"
value={editForm.username}
onChange={(e) => setEditForm({ ...editForm, username: e.target.value })}
placeholder="闲鱼账号/手机号"
className="w-full ios-input px-4 py-3 rounded-xl"
/>
</div>
<div>
<label className="block text-sm font-bold text-gray-700 mb-2">登录密码</label>
<div className="relative">
<input
type={editForm.showLoginPassword ? 'text' : 'password'}
value={editForm.login_password}
onChange={(e) => setEditForm({ ...editForm, login_password: e.target.value, clear_password: false })}
placeholder="用于自动登录"
className="w-full ios-input px-4 py-3 rounded-xl pr-12"
/>
<button
type="button"
onClick={() => setEditForm({ ...editForm, showLoginPassword: !editForm.showLoginPassword })}
className="absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600"
>
{editForm.showLoginPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
</button>
</div>
<label className="mt-3 flex items-center gap-3 cursor-pointer">
<input
type="checkbox"
checked={editForm.clear_password}
onChange={(e) => setEditForm({ ...editForm, clear_password: e.target.checked, login_password: e.target.checked ? '' : editForm.login_password })}
className="w-4 h-4 accent-brand"
/>
<span className="text-sm font-bold text-gray-700">清空已保存密码</span>
</label>
</div>
<div className="flex items-center justify-between">
<div>
<div className="font-bold text-gray-900">登录时显示浏览器</div>
<div className="text-xs text-gray-500">调试时可开启查看登录过程</div>
</div>
<button
type="button"
onClick={() => setEditForm({ ...editForm, show_browser: !editForm.show_browser })}
className={`w-14 h-8 rounded-full transition-colors duration-300 relative ${
editForm.show_browser ? '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 ${
editForm.show_browser ? 'translate-x-6' : 'translate-x-0'
}`}
/>
</button>
</div>
<div className="rounded-xl border border-blue-100 bg-blue-50 p-4 space-y-3">
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
<div>
<div className="font-bold text-blue-950">立即执行账号密码登录</div>
<div className="text-xs text-blue-700 mt-1">需要在上方重新输入本次登录密码;成功后后端会更新 Cookie 和保存的登录信息。</div>
</div>
{(passwordLoginView.status === 'processing' || passwordLoginView.status === 'verification_required') ? (
<button type="button" onClick={handleCancelPasswordLogin} className="px-4 py-2 rounded-xl bg-white text-red-600 font-bold text-sm border border-red-100">
取消登录
</button>
) : (
<button type="button" onClick={handlePasswordLogin} className="px-4 py-2 rounded-xl bg-blue-600 text-white font-bold text-sm whitespace-nowrap">
密码登录刷新授权
</button>
)}
</div>
{passwordLoginView.message && (
<div className={`text-sm font-medium ${passwordLoginView.status === 'failed' ? 'text-red-700' : passwordLoginView.status === 'success' ? 'text-green-700' : 'text-blue-800'}`}>
{passwordLoginView.message}
</div>
)}
{passwordLoginView.status === 'verification_required' && (
<div className="rounded-xl border border-amber-200 bg-amber-50 p-3 text-amber-900">
<div className="font-extrabold">账号已触发平台风控,需要完成人脸识别</div>
<div className="text-xs mt-1 leading-5">请在闲鱼 App 或已打开的登录浏览器中按提示完成验证。本页面不会提供可直接打开的风控链接。</div>
{passwordLoginView.qrCodeUrl && (
<div className="mt-3 aspect-square w-48 overflow-hidden rounded-xl border bg-white">
<SquareQRCode src={passwordLoginView.qrCodeUrl} alt="密码登录风控二维码" className="p-2" />
</div>
)}
</div>
)}
</div>
</div>
</div>
{/* 通知渠道绑定 */}
{(notifChannels.length > 0 || bindingsLoading || bindingsLoadError) && (
<div className="border-t border-gray-200 pt-6">
<h3 className="text-lg font-bold text-gray-900 mb-1 flex items-center gap-2">
<Bell className="w-5 h-5 text-blue-500" />
通知渠道绑定
</h3>
<p className="text-xs text-gray-500 mb-4">勾选后,该账号的 token 失效、自动恢复失败、风控验证等事件会推送到这些渠道</p>
{bindingsLoading && (
<div className="flex items-center gap-2 text-sm text-gray-500"><Loader2 className="w-4 h-4 animate-spin" />正在加载通知绑定</div>
)}
{bindingsLoadError && !bindingsLoading && (
<div className="mb-3 rounded-xl bg-amber-50 p-3 text-sm text-amber-800 flex items-center justify-between gap-3">
<span>{bindingsLoadError}</span>
<button type="button" className="font-bold whitespace-nowrap" onClick={() => loadNotificationBindings(editingAccount.id)}>重试</button>
</div>
)}
<div className="space-y-2">
{notifChannels.map(ch => {
const checked = selectedChannelIds.includes(Number(ch.id));
return (
<label
key={ch.id}
className="flex items-center gap-3 p-3 rounded-xl border border-gray-200 hover:bg-gray-50 cursor-pointer transition-colors"
>
<button
type="button"
onClick={() => {
if (!bindingsLoaded) return;
setSelectedChannelIds(prev =>
checked ? prev.filter(id => id !== Number(ch.id)) : [...prev, Number(ch.id)]
);
setBindingsDirty(true);
}}
disabled={!bindingsLoaded}
className={`w-5 h-5 rounded-md border-2 flex items-center justify-center transition-colors flex-shrink-0 ${
checked ? 'bg-brand border-brand' : 'bg-white border-gray-300'
}`}
>
{checked && <Check className="w-3.5 h-3.5 text-white" />}
</button>
<div className="flex-1 min-w-0">
<div className="font-bold text-gray-900 text-sm">{ch.name}</div>
<div className="text-xs text-gray-500">{ch.type}{ch.enabled ? '' : ' · 已停用'}</div>
</div>
</label>
);
})}
</div>
</div>
)}
</div>
<div className="modal-footer">
<div className="flex gap-3 w-full">
<button
onClick={() => void closeEditModal()}
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={handleSaveEdit}
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
{/* 编辑账号弹窗由 accounts feature 组件负责渲染和表单交互。 */}
{activeModal === 'edit' && editingAccount && (
<AccountEditModal
account={editingAccount}
editForm={editForm}
setEditForm={setEditForm}
saving={saving}
onClose={closeEditModal}
onSave={handleSaveEdit}
onRestartPause={handleRestartPause}
longLogin={longLogin}
onToggleLongLogin={handleLongLoginToggle}
passwordLoginView={passwordLoginView}
onPasswordLogin={handlePasswordLogin}
onCancelPasswordLogin={handleCancelPasswordLogin}
notifChannels={notifChannels}
selectedChannelIds={selectedChannelIds}
bindingsLoaded={bindingsLoaded}
bindingsLoading={bindingsLoading}
bindingsLoadError={bindingsLoadError}
onRetryBindings={() => loadNotificationBindings(editingAccount.id)}
onToggleChannel={toggleNotificationChannel}
onSettingsDirty={() => setBindingsDirty(true)}
/>
)}
{/* AI设置弹窗 */}
{activeModal === 'ai-settings' && editingAccount && createPortal(
<div className="modal-overlay-centered">
+8 -39
View File
@@ -1,39 +1,8 @@
import { AccountDetail } from '../types';
export interface AccountLoginEditForm {
username: string;
login_password: string;
show_browser: boolean;
clear_password?: boolean;
}
export interface AccountLoginInfoPayload {
username: string;
login_password?: string;
clear_password?: boolean;
show_browser: boolean;
}
export const buildAccountLoginInfoUpdate = (
account: AccountDetail,
form: AccountLoginEditForm,
): AccountLoginInfoPayload | null => {
const usernameChanged = form.username !== (account.username || '');
const showBrowserChanged = form.show_browser !== (account.show_browser || false);
const passwordChanged = form.login_password !== '';
const passwordCleared = form.clear_password === true;
if (!usernameChanged && !showBrowserChanged && !passwordChanged && !passwordCleared) {
return null;
}
const payload: AccountLoginInfoPayload = {
username: form.username,
show_browser: form.show_browser,
};
if (passwordCleared) {
payload.clear_password = true;
} else if (passwordChanged) {
payload.login_password = form.login_password;
}
return payload;
};
// 旧目录保留兼容入口,实际登录字段构造逻辑已归入 accounts feature。
export {
buildAccountLoginInfoUpdate,
} from '../app/features/accounts/state';
export type {
AccountLoginEditFields as AccountLoginEditForm,
AccountLoginInfoPayload,
} from '../app/features/accounts/state';
+2 -9
View File
@@ -1,9 +1,2 @@
import type { AccountDetail } from '../types';
export const shouldUpdateAccountPause = (
requestedMinutes: number,
account: Pick<AccountDetail, 'pause_duration' | 'paused'>,
): boolean => {
const savedMinutes = account.pause_duration || 0;
return requestedMinutes !== savedMinutes;
};
// 旧目录保留兼容入口,实际暂停时长门禁已归入 accounts feature。
export { shouldUpdateAccountPause } from '../app/features/accounts/state';
+2 -27
View File
@@ -1,27 +1,2 @@
import type { AccountRuntimeStatus } from '../services/api';
import type { AccountDetail } from '../types';
const isOlderStatus = (currentUpdatedAt?: string, incomingUpdatedAt?: string): boolean => {
if (!currentUpdatedAt || !incomingUpdatedAt) return false;
const currentTime = Date.parse(currentUpdatedAt);
const incomingTime = Date.parse(incomingUpdatedAt);
return Number.isFinite(currentTime) && Number.isFinite(incomingTime) && incomingTime < currentTime;
};
/**
* 将运行时快照合并到账号列表。较晚到达的旧请求不能覆盖更新的状态。
*/
export const mergeAccountRuntimeStatuses = (
accounts: AccountDetail[],
statuses: Record<string, AccountRuntimeStatus>,
): AccountDetail[] => accounts.map(account => {
const status = statuses[account.id];
if (!status || isOlderStatus(account.runtime_updated_at, status.updated_at)) return account;
return {
...account,
runtime_state: status.state,
runtime_message: status.message || '',
runtime_connected: status.connected,
runtime_updated_at: status.updated_at,
};
});
// 旧目录保留兼容入口,实际运行状态合并逻辑已归入 accounts feature。
export { mergeAccountRuntimeStatuses } from '../app/features/accounts/runtime';
+4 -1
View File
@@ -171,7 +171,10 @@ describe('frontend navigation routing', () => {
});
test('account editor exposes password-login refresh and never renders its verification URL', () => {
const accounts = readFrontendFile('components/AccountList.tsx');
const accounts = [
readFrontendFile('components/AccountList.tsx'),
readFrontendFile('app/features/accounts/components/AccountEditModal.tsx'),
].join('\n');
expect(accounts).toContain('passwordLogin({');
expect(accounts).toContain('checkPasswordLoginStatus(sessionId, controller.signal)');
expect(accounts).toContain('密码登录刷新授权');
@@ -413,4 +413,4 @@ import{r as h}from"./react-vendor-C_od1ZSF.js";/**
*
* This source code is licensed under the ISC license.
* See the LICENSE file in the root directory of this source tree.
*/const F1=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],_0=e("zap",F1);export{n2 as $,O1 as A,Q1 as B,i2 as C,r2 as D,l2 as E,s0 as F,u2 as G,K2 as H,c0 as I,d0 as J,f2 as K,z2 as L,P2 as M,e0 as N,k2 as O,D2 as P,I2 as Q,O2 as R,X2 as S,y0 as T,i0 as U,v2 as V,N2 as W,M0 as X,q2 as Y,_0 as Z,x2 as _,K1 as a,m2 as a0,B2 as a1,d2 as a2,o2 as a3,y2 as a4,b2 as a5,Z1 as a6,j2 as a7,p2 as a8,e2 as a9,J2 as aa,A2 as ab,n0 as ac,h2 as ad,g2 as ae,w2 as af,G2 as ag,L2 as ah,p0 as ai,l0 as aj,r0 as ak,X1 as al,a0 as am,$2 as an,H2 as ao,Q2 as b,t2 as c,a2 as d,V2 as e,c2 as f,Y2 as g,E2 as h,h0 as i,C2 as j,U2 as k,T2 as l,t0 as m,J1 as n,Z2 as o,k0 as p,Y1 as q,G1 as r,S2 as s,s2 as t,R2 as u,F2 as v,o0 as w,M2 as x,_2 as y,W2 as z};
*/const F1=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],_0=e("zap",F1);export{n2 as $,O1 as A,Q1 as B,i2 as C,r2 as D,l2 as E,s0 as F,u2 as G,K2 as H,c0 as I,d0 as J,f2 as K,z2 as L,P2 as M,e0 as N,k2 as O,D2 as P,I2 as Q,O2 as R,X2 as S,y0 as T,i0 as U,v2 as V,N2 as W,M0 as X,q2 as Y,_0 as Z,x2 as _,K1 as a,m2 as a0,B2 as a1,d2 as a2,o2 as a3,y2 as a4,b2 as a5,Z1 as a6,j2 as a7,p2 as a8,e2 as a9,J2 as aa,A2 as ab,n0 as ac,h2 as ad,g2 as ae,w2 as af,G2 as ag,L2 as ah,p0 as ai,l0 as aj,r0 as ak,X1 as al,a0 as am,$2 as an,H2 as ao,Q2 as b,t2 as c,a2 as d,V2 as e,c2 as f,Y2 as g,E2 as h,h0 as i,C2 as j,U2 as k,T2 as l,t0 as m,J1 as n,Z2 as o,Y1 as p,s2 as q,M2 as r,_2 as s,k0 as t,G1 as u,S2 as v,R2 as w,F2 as x,o0 as y,W2 as z};
@@ -0,0 +1,19 @@
import{j as e,r as l,c as Ns,b as qe,d as Ua}from"./react-vendor-C_od1ZSF.js";import{L as Wa,U as ma,M as os,C as cs,B as ua,S as pa,Z as ds,a as ft,b as _s,G as Ls,c as vs,d as ws,e as Ja,f as rt,A as As,D as Va,g as Is,P as ha,h as $t,E as ga,T as Ga,i as Qa,j as Oe,X as $e,k as Ka,l as Ha,m as ks,n as ba,o as tt,p as Qe,q as fa,K as Za,r as it,s as lt,Q as Kt,t as ot,u as bt,v as Rt,R as Je,w as ya,x as Ya,y as Ge,z as et,F as Os,H as jt,I as yt,J as Ot,N as ja,O as Xa,V as Rs,W as Ps,Y as el,_ as tl,$ as sl,a0 as al,a1 as Ht,a2 as Dt,a3 as xs,a4 as ll,a5 as rl,a6 as ms,a7 as $s,a8 as nl,a9 as il,aa as Pt,ab as Es,ac as Wt,ad as Na,ae as ol,af as cl,ag as Gt,ah as _a,ai as dl,aj as xl,ak as ml,al as ul,am as pl,an as hl,ao as Ts}from"./icons-vendor-C73Tbcy8.js";import{R as Mt,B as gl,X as Ds,Y as Ms,T as qt,a as bl,C as Zt,A as fl,b as yl,c as jl,P as qs,d as Bs,L as Nl}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))i(o);new MutationObserver(o=>{for(const v of o)if(v.type==="childList")for(const N of v.addedNodes)N.tagName==="LINK"&&N.rel==="modulepreload"&&i(N)}).observe(document,{childList:!0,subtree:!0});function a(o){const v={};return o.integrity&&(v.integrity=o.integrity),o.referrerPolicy&&(v.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?v.credentials="include":o.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function i(o){if(o.ep)return;o.ep=!0;const v=a(o);fetch(o.href,v)}})();const _l=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),us=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52Line truncated
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(_s,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:Fe,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:le,children:"取消"}),e.jsxs("button",{onClick:c,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:le,children:[le?e.jsx(Oe,{className:"w-4 h-4 animate-spin"}):e.jsx(tt,{className:"w-4 h-4"}),le?"保存中...":"保存"]})]})})]})}),document.body)]})},xn=t=>({total:Number((t==null?void 0:t.total)||0),success_count:Number((t==null?void 0:t.success_count)||0),failed_count:Number((t==null?void 0:t.failed_count)||0),results:Array.isArray(t==null?void 0:t.results)?t.results.map(s=>({order_id:String((s==null?void 0:s.order_id)||"unknown"),success:(s==null?void 0:s.success)===!0,message:String((s==null?void 0:s.message)||"")})):[]}),mn=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],Hs=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},a={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${s[t]||s.cancelled}`,children:a[t]||t})},un=()=>{const[t,s]=l.useState([]),[a,i]=l.useState([]),[o,v]=l.useState([]),[N,S]=l.useState({}),[p,w]=l.useState("all"),[y,$]=l.useState(""),[B,ee]=l.useState(""),[H,_]=l.useState(""),F=l.useRef(0),[T,J]=l.useState(1),[K,ae]=l.useState(1),[me,ue]=l.useState(!1),[k,Y]=l.useState(!1),[re,z]=l.useState(!1),[de,V]=l.useState(!1),[C,q]=l.useState(null),[A,X]=l.useState(null),[E,Z]=l.useState({}),[R,x]=l.useState(!1),[g,U]=l.useState(""),[j,M]=l.useState(!1),[ne,ce]=l.useState(null),[_e,Ie]=l.useState(null),[d,ie]=l.useState(null),[Se,u]=l.useState(!1),[G,se]=l.useState(null),[b,le]=l.useState(null),I=async()=>{const m=++F.current;ue(!0);try{const P=await er(y||void 0,p,T,20,H);if(m!==F.current)return;s(P.data),ae(P.total_pages)}catch(P){console.error("加载订单失败:",P)}finally{m===F.current&&ue(!1)}},pe=(m,P,he)=>{if(he&&he.trim())return he;if(N[`${m}:${P}`])return N[`${m}:${P}`];const we=a.find(Ke=>{if(he&&Ke.item_title){const Ue=he.toLowerCase(),We=Ke.item_title.toLowerCase();return We.includes(Ue)||Ue.includes(We)}return!1});return we!=null&&we.item_title?we.item_title:"未知商品"},te=m=>{const P={};m.forEach(he=>{he.item_id&&(P[`${he.cookie_id}:${he.item_id}`]=he.item_title||he.item_id)}),S(P)};l.useEffect(()=>{const m=window.setTimeout(()=>{J(1),_(B.trim())},300);return()=>window.clearTimeout(m)},[B]),l.useEffect(()=>{I()},[y,p,T,H]),l.useEffect(()=>{Promise.all([Et(),Nt()]).then(([m,P])=>{v(m),i(P),te(P)}).catch(m=>{console.error("加载商品列表失败:",m)})},[]);const Te=l.useMemo(()=>new Map(o.map(m=>[m.id,m])),[o]),Re=m=>{const P=Te.get(m),he=(P==null?void 0:P.remark)||(P==null?void 0:P.nickname);return he?`${he} · ${m.slice(0,6)}`:`账号 ${m.slice(0,8)}`},Me=m=>{const P=Te.get(m);return(P==null?void 0:P.remark)||(P==null?void 0:P.nickname)||"未命名账号"},f=async()=>{ue(!0);try{const m=await ar(y||void 0,p);await I(),m!=null&&m.message&&alert(m.message)}catch(m){console.error("同步订单失败:",m),alert((m==null?void 0:m.message)||"同步失败,请重试")}finally{ue(!1)}},L=m=>{U(m),ce(null),x(!0)},W=async m=>{var P;M(!0),ce(null);try{const he=await rr([g],m),we=(P=he==null?void 0:he.results)==null?void 0:P[0];we!=null&&we.success?(ce({success:!0,message:we.message}),I()):ce({success:!1,message:(we==null?void 0:we.message)||"发货失败"})}catch(he){ce({success:!1,message:(he==null?void 0:he.message)||"请求失败"})}finally{M(!1)}},Q=m=>{q(m),Y(!0)},Le=m=>{X({...m}),z(!0)},ve=async()=>{if(!(!A||!A.order_id))try{const m={};A.status!==void 0&&(m.order_status=A.status),A.buyer_id!==void 0&&(m.buyer_id=A.buyer_id),A.amount!==void 0&&(m.amount=A.amount),A.receiver_name!==void 0&&(m.receiver_name=A.receiver_name),A.receiver_phone!==void Line truncated
VIP-MONTH-002
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(b=>b.map(le=>`"${String(le).replace(/"/g,'""')}"`).join(",")).join(`
`),u=new Blob(["\uFEFF"+Se],{type:"text/csv;charset=utf-8"}),G=URL.createObjectURL(u),se=document.createElement("a");se.href=G,se.download="卡密组批量导入模板.csv",document.body.appendChild(se),se.click(),se.remove(),URL.revokeObjectURL(G)},ce=async()=>{if(F){me(!0),K(null);try{const d=await mr(F);if(K(d),d.created>0){const ie=await Xe();s(ie)}}catch(d){K({error:(d==null?void 0:d.message)||"上传失败"})}finally{me(!1)}}},_e=async()=>{if(!(!ue||!Y.trim())){me(!0),de(null);try{const d=await ur(ue,Y);de({added:d.added}),re("");const ie=await Xe();s(ie)}catch(d){alert("追加失败:"+((d==null?void 0:d.message)||"未知错误"))}finally{me(!1)}}},Ie=()=>{var d;_("create"),T(null),K(null),k((d=j[0])!=null&&d.id?String(j[0].id):""),re(""),de(null),ee(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:Ie,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Ot,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>v(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(et,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(ja,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:V,onChange:d=>C(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(jt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:q,onChange:d=>A(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",M.length," / ",t.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:M.map(d=>{let ie="";return d.type==="data"&&d.data_content?ie=`库存: ${d.data_content.split(`
`).filter(u=>u.trim()).length} 条`:d.type==="text"&&d.text_content?ie=d.text_content:d.type==="api"&&d.api_config?ie=d.api_config.url:d.type==="image"&&d.image_url&&(ie="图片链接"),e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(X,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>U(d.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(Xa,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${d.type==="text"?"bg-blue-50 text-blue-600":d.type==="data"?"bg-purple-50 text-purple-600":d.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:d.type==="text"?"文本":d.type==="data"?"批量":d.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:ie,children:ie})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:d.description||"-",children:d.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>g(d),className:`w-12 h-8 rounded-full relative transition-colors ${d.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${d.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>E(d),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(yt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>R(d.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Ge,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),M.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ha,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&N&&qe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>i(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx($e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:p.name||"",onChange:d=>w({...p,name:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:p.type||"text",onChange:d=>w({...p,type:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(N==null?void 0:N.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),p.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:p.api_url||"",onChange:d=>w({...p,api_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.Line truncated
卡号1:密码1
卡号2:密码2
或者
兑换码1
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:p.data_content?p.data_content.split(`
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),p.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:p.image_url||"",onChange:d=>w({...p,image_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),p.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:p.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:d=>{d.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:p.delay_seconds||0,onChange:d=>w({...p,delay_seconds:parseInt(d.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:p.description||"",onChange:d=>w({...p,description:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>w({...p,enabled:!p.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${p.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${p.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>i(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:Z,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),o&&qe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>v(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx($e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:y.name,onChange:d=>$({...y,name:d.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>$({...y,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${y.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(cs,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>$({...y,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${y.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Rs,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>$({...y,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${y.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children: Line truncated
CODE-789012
...`:"请输入每次发货时发送的固定文字"}),y.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:y.content.split(`
`).filter(d=>d.trim()).length})," 条"]})]}),y.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:y.api_method,onChange:d=>$({...y,api_method:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:y.api_timeout,onChange:d=>$({...y,api_timeout:parseInt(d.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:y.api_headers,onChange:d=>$({...y,api_headers:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:y.api_params,onChange:d=>$({...y,api_params:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:y.description,onChange:d=>$({...y,description:d.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:y.delay_seconds,onChange:d=>$({...y,delay_seconds:parseInt(d.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>v(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:x,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(et,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),B&&qe.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>ee(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx($e,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>_("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${H==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(el,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>_("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${H==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Ot,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),H==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),'。 类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:ne,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transit Line truncated
VIP-002
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),z&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",z.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>ee(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),H==="create"?e.jsxs("button",{onClick:ce,disabled:!F||ae,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[ae?e.jsx(Oe,{className:"w-4 h-4 animate-spin"}):e.jsx(Ot,{className:"w-4 h-4"}),ae?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:_e,disabled:!ue||!Y.trim()||ae||j.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[ae?e.jsx(Oe,{className:"w-4 h-4 animate-spin"}):e.jsx(et,{className:"w-4 h-4"}),ae?"处理中...":"追加卡密"]})]})]})}),document.body)]})},Ys="ydisks-amap-js-api",gn="c9b68d4ce9a2a97f22a4a439404488ca";let St=null;const bn=()=>gn,fn=()=>window.AMap?Promise.resolve(window.AMap):St||(St=new Promise((t,s)=>{const a=document.getElementById(Ys),i=a||document.createElement("script"),o=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(N)},v=()=>{window.AMap?(o(),t(window.AMap)):(o(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},N=window.setTimeout(()=>{o(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=v,i.id=Ys,i.async=!0,i.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(bn())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,i.onerror=()=>{o(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(i)}).catch(t=>{throw St=null,t}),St),Vt=t=>Number.isFinite(t)&&t!==0,yn=t=>{var o,v;const s=Number((o=t.location)==null?void 0:o.lng),a=Number((v=t.location)==null?void 0:v.lat),i={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:a,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!i.division_id||!i.province||!i.city||!i.poi_id||!i.poi_name||!Vt(s)||!Vt(a)||s<-180||s>180||a<-90||a>90?null:i},jn=async(t,s)=>{if(!Vt(t)||!Vt(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await fn();return new Promise((i,o)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(N,S)=>{var w;if(N!=="complete"){if(N==="no_data"){i([]);return}o(new Error("高德地图附近地址查询失败,请稍后重试"));return}const p=(((w=S==null?void 0:S.poiList)==null?void 0:w.pois)||[]).map(yn).filter(y=>y!==null);i(p)})})},Nn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),ys=t=>t==="running"||t==="canceling",_n=t=>!!(t!=null&&t.preview_id&&Number(t.valid||0)>0),vn=t=>!!(t!=null&&t.id&&Number(t.retryable||0)>0&&!ys(t.status)),wn=(t,s)=>t===s,Xs=t=>{switch(t){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return t||"-"}},ea=t=>{switch(t){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},kn=t=>{const[s,a]=l.useState(!1),[i,o]=l.useState("upload"),[v,N]=l.useState(null),[S,p]=l.useState(null),[w,y]=l.useState(""),[$,B]=l.useState(!1),[ee,H]=l.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[_,F]=l.useState(null),[T,J]=l.useState(null),[K,ae]=l.useState(null),[me,ue]=l.useState([]),[k,Y]=l.useState(null),[re,z]=l.useState(!1),de=l.useRef(!1),V=l.useRef(0),C=l.useCallback(async()=>{o("upload"),F(null),J(null),N(null),p(null),y(""),H({catId:"",catName:"",channelCatId:"",tbCatId:""}),ue([]),Y(null),a(!0),z(!0);try{const j=await Aa(20),M=Nn(j);if(M!=null&&M.id){const ne=await ht(M.id);ae(ne),J(ne),o(["running","canceling"].includes(ne.status)?"running":"done")}}catch(j){console.error("恢复最近批量铺货任务失败:",j)}finally{z(!1)}},[]),q=l.useCallback(async()=>{const j=w.trim();if(!t.selectedAccount){alert("请先选择默认发布账号");retu Line truncated
`),Ee=new Blob(["\uFEFF"+fe],{type:"text/csv;charset=utf-8"}),Ve=URL.createObjectURL(Ee),Fe=document.createElement("a");Fe.href=Ve,Fe.download="批量铺货模板.csv",document.body.appendChild(Fe),Fe.click(),Fe.remove(),URL.revokeObjectURL(Ve)},wt=()=>{X(c=>({...c,cookie_id:S||c.cookie_id})),J(!0)},ct=()=>{Z(c=>({...c,cookie_id:S||c.cookie_id})),ae(!0)},dt=async c=>{if(!(c?S:E.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");ue(!0),navigator.geolocation.getCurrentPosition(async fe=>{try{const Ee=await jn(fe.coords.longitude,fe.coords.latitude);if(!Ee.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");c?(f(Ee),L(Ee[0])):(Y(Ee),z(Ee[0]))}catch(Ee){alert((Ee==null?void 0:Ee.message)||"获取发货地失败")}finally{ue(!1)}},fe=>{ue(!1),alert(fe.code===fe.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},kt=c=>i.filter(D=>D.cookie_id===c.cookie_id&&D.item_id===c.item_id).length>0?i.filter(D=>D.cookie_id===c.cookie_id&&D.item_id===c.item_id):i.filter(D=>D.cookie_id===c.cookie_id&&!D.item_id),xt=l.useMemo(()=>new Map(v.map(c=>[c.id,c])),[v]),mt=l.useMemo(()=>w?s.filter(c=>c.cookie_id===w):s,[w,s]),Ze=c=>{const D=xt.get(c),fe=(D==null?void 0:D.remark)||(D==null?void 0:D.nickname);return fe?`${fe} · ${c.slice(0,6)}`:`账号 ${c.slice(0,8)}`},ut=c=>{const D=xt.get(c);return(D==null?void 0:D.remark)||(D==null?void 0:D.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(al,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:w,onChange:c=>y(c.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),v.map(c=>e.jsx("option",{value:c.id,children:Ze(c.id)},c.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(ot,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:S,onChange:c=>p(c.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),v.map(c=>e.jsx("option",{value:c.id,children:Ze(c.id)},c.id))]})]})]}),e.jsxs("button",{onClick:P,disabled:$||!S,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Je,{className:`w-4 h-4 ${$?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:wt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(et,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:ct,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Ht,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void W(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Dt,{className:"w-4 h-4"}),te&&["running","canceling"].includes(te.status)?"继续批量任务":"批量铺货"]}),te&&!["running","canceling"].includes(te.status)&&e.jsx("button",{onClick:()=>void Le(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[mt.map(c=>{const D=kt(c),fe=D.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex fl Line truncated
@@ -0,0 +1 @@
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:6Line truncated
@@ -1 +0,0 @@
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:6Line truncated
@@ -1,19 +0,0 @@
import{j as e,r as l,c as ws,b as ze,d as Ya}from"./react-vendor-C_od1ZSF.js";import{L as Xa,U as _a,M as xs,C as ms,B as va,S as wa,Z as us,a as _t,b as ks,G as Ds,c as Cs,d as Ss,e as el,f as nt,A as Ts,D as tl,g as Ms,P as ka,h as Ft,E as Ca,T as sl,i as al,j as Re,X as De,k as ll,l as rl,m as Ls,n as Sa,o as Xe,Q as Xt,p as ut,q as Ye,r as Nt,s as Tt,t as Fs,R as Ve,u as La,v as nl,w as He,K as il,x as mt,y as rt,z as at,F as qs,H as wt,I as vt,J as Dt,N as Ia,O as ol,V as Bs,W as zs,Y as cl,_ as dl,$ as xl,a0 as ml,a1 as es,a2 as Bt,a3 as ps,a4 as ul,a5 as pl,a6 as hs,a7 as Us,a8 as hl,a9 as gl,aa as Mt,ab as Ws,ac as Qt,ad as Aa,ae as bl,af as fl,ag as Zt,ah as Oa,ai as yl,aj as jl,ak as Nl,al as _l,am as vl,an as wl,ao as Js}from"./icons-vendor-BpMgNNfy.js";import{R as zt,B as kl,X as Vs,Y as Gs,T as Ut,a as Cl,C as ts,A as Sl,b as Ll,c as Il,P as Qs,d as Ks,L as Al}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const N of i)if(N.type==="childList")for(const j of N.addedNodes)j.tagName==="LINK"&&j.rel==="modulepreload"&&n(j)}).observe(document,{childList:!0,subtree:!0});function a(i){const N={};return i.integrity&&(N.integrity=i.integrity),i.referrerPolicy&&(N.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?N.credentials="include":i.crossOrigin==="anonymous"?N.credentials="omit":N.credentials="same-origin",N}function n(i){if(i.ep)return;i.ep=!0;const N=a(i);fetch(i.href,N)}})();const Ol=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),gs=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52Line truncated
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(ks,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:ct,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:te,children:"取消"}),e.jsxs("button",{onClick:ye,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:te,children:[te?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"}),te?"保存中...":"保存"]})]})})]})}),document.body)]})},hn=t=>({total:Number((t==null?void 0:t.total)||0),success_count:Number((t==null?void 0:t.success_count)||0),failed_count:Number((t==null?void 0:t.failed_count)||0),results:Array.isArray(t==null?void 0:t.results)?t.results.map(s=>({order_id:String((s==null?void 0:s.order_id)||"unknown"),success:(s==null?void 0:s.success)===!0,message:String((s==null?void 0:s.message)||"")})):[]}),gn=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],na=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},a={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${s[t]||s.cancelled}`,children:a[t]||t})},bn=()=>{const[t,s]=l.useState([]),[a,n]=l.useState([]),[i,N]=l.useState([]),[j,P]=l.useState({}),[g,L]=l.useState("all"),[f,F]=l.useState(""),[ee,de]=l.useState(""),[X,y]=l.useState(""),V=l.useRef(0),[D,G]=l.useState(1),[Y,he]=l.useState(1),[be,fe]=l.useState(!1),[k,ae]=l.useState(!1),[ce,z]=l.useState(!1),[ue,Q]=l.useState(!1),[S,B]=l.useState(null),[I,le]=l.useState(null),[$,K]=l.useState({}),[R,m]=l.useState(!1),[p,W]=l.useState(""),[w,J]=l.useState(!1),[xe,ie]=l.useState(null),[_e,Ae]=l.useState(null),[x,re]=l.useState(null),[Le,d]=l.useState(!1),[q,ne]=l.useState(null),[h,te]=l.useState(null),A=async()=>{const u=++V.current;fe(!0);try{const O=await cr(f||void 0,g,D,20,X);if(u!==V.current)return;s(O.data),he(O.total_pages)}catch(O){console.error("加载订单失败:",O)}finally{u===V.current&&fe(!1)}},oe=(u,O,pe)=>{if(pe&&pe.trim())return pe;if(j[`${u}:${O}`])return j[`${u}:${O}`];const ke=a.find(Ze=>{if(pe&&Ze.item_title){const qe=pe.toLowerCase(),Ge=Ze.item_title.toLowerCase();return Ge.includes(qe)||qe.includes(Ge)}return!1});return ke!=null&&ke.item_title?ke.item_title:"未知商品"},se=u=>{const O={};u.forEach(pe=>{pe.item_id&&(O[`${pe.cookie_id}:${pe.item_id}`]=pe.item_title||pe.item_id)}),P(O)};l.useEffect(()=>{const u=window.setTimeout(()=>{G(1),y(ee.trim())},300);return()=>window.clearTimeout(u)},[ee]),l.useEffect(()=>{A()},[f,g,D,X]),l.useEffect(()=>{Promise.all([qt(),kt()]).then(([u,O])=>{N(u),n(O),se(O)}).catch(u=>{console.error("加载商品列表失败:",u)})},[]);const Fe=l.useMemo(()=>new Map(i.map(u=>[u.id,u])),[i]),Pe=u=>{const O=Fe.get(u),pe=(O==null?void 0:O.remark)||(O==null?void 0:O.nickname);return pe?`${pe} · ${u.slice(0,6)}`:`账号 ${u.slice(0,8)}`},Te=u=>{const O=Fe.get(u);return(O==null?void 0:O.remark)||(O==null?void 0:O.nickname)||"未命名账号"},b=async()=>{fe(!0);try{const u=await mr(f||void 0,g);await A(),u!=null&&u.message&&alert(u.message)}catch(u){console.error("同步订单失败:",u),alert((u==null?void 0:u.message)||"同步失败,请重试")}finally{fe(!1)}},C=u=>{W(u),ie(null),m(!0)},U=async u=>{var O;J(!0),ie(null);try{const pe=await pr([p],u),ke=(O=pe==null?void 0:pe.results)==null?void 0:O[0];ke!=null&&ke.success?(ie({success:!0,message:ke.message}),A()):ie({success:!1,message:(ke==null?void 0:ke.message)||"发货失败"})}catch(pe){ie({success:!1,message:(pe==null?void 0:pe.message)||"请求失败"})}finally{J(!1)}},H=u=>{B(u),ae(!0)},Oe=u=>{le({...u}),z(!0)},ve=async()=>{if(!(!I||!I.order_id))try{const u={};I.status!==void 0&&(u.order_status=I.status),I.buyer_id!==void 0&&(u.buyer_id=I.buyer_id),I.amount!==void 0&&(u.amount=I.amount),I.receiver_name!==void 0&&(u.receiver_name=I.receiver_name),I.receiver_phon Line truncated
VIP-MONTH-002
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(h=>h.map(te=>`"${String(te).replace(/"/g,'""')}"`).join(",")).join(`
`),d=new Blob(["\uFEFF"+Le],{type:"text/csv;charset=utf-8"}),q=URL.createObjectURL(d),ne=document.createElement("a");ne.href=q,ne.download="卡密组批量导入模板.csv",document.body.appendChild(ne),ne.click(),ne.remove(),URL.revokeObjectURL(q)},ie=async()=>{if(V){be(!0),Y(null);try{const x=await Nr(V);if(Y(x),x.created>0){const re=await st();s(re)}}catch(x){Y({error:(x==null?void 0:x.message)||"上传失败"})}finally{be(!1)}}},_e=async()=>{if(!(!fe||!ae.trim())){be(!0),ue(null);try{const x=await _r(fe,ae);ue({added:x.added}),ce("");const re=await st();s(re)}catch(x){alert("追加失败:"+((x==null?void 0:x.message)||"未知错误"))}finally{be(!1)}}},Ae=()=>{var x;y("create"),D(null),Y(null),k((x=w[0])!=null&&x.id?String(w[0].id):""),ce(""),ue(null),de(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:Ae,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Dt,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>N(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(at,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(Ia,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:Q,onChange:x=>S(x.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(wt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:B,onChange:x=>I(x.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",J.length," / ",t.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:J.map(x=>{let re="";return x.type==="data"&&x.data_content?re=`库存: ${x.data_content.split(`
`).filter(d=>d.trim()).length} 条`:x.type==="text"&&x.text_content?re=x.text_content:x.type==="api"&&x.api_config?re=x.api_config.url:x.type==="image"&&x.image_url&&(re="图片链接"),e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(le,{type:x.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:x.name,children:x.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>W(x.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:x.id}),e.jsx(ol,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${x.type==="text"?"bg-blue-50 text-blue-600":x.type==="data"?"bg-purple-50 text-purple-600":x.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:x.type==="text"?"文本":x.type==="data"?"批量":x.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:re,children:re})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:x.description||"-",children:x.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>p(x),className:`w-12 h-8 rounded-full relative transition-colors ${x.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${x.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>$(x),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(vt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>R(x.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(He,{className:"h-4 w-4"})})]})})]},x.id)})})]})}),J.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ka,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&j&&ze.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>n(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(De,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:g.name||"",onChange:x=>L({...g,name:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:g.type||"text",onChange:x=>L({...g,type:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(j==null?void 0:j.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),g.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:g.api_url||"",onChange:x=>L({...g,api_url:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[eLine truncated
卡号1:密码1
卡号2:密码2
或者
兑换码1
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:g.data_content?g.data_content.split(`
`).filter(x=>x.trim()).length:0})," 条"]})]})]}),g.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:g.image_url||"",onChange:x=>L({...g,image_url:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),g.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:g.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:x=>{x.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:g.delay_seconds||0,onChange:x=>L({...g,delay_seconds:parseInt(x.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:g.description||"",onChange:x=>L({...g,description:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>L({...g,enabled:!g.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${g.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${g.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>n(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:K,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Xe,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),i&&ze.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>N(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(De,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:f.name,onChange:x=>F({...f,name:x.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>F({...f,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${f.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(ms,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>F({...f,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${f.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Bs,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>F({...f,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${f.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children: Line truncated
CODE-789012
...`:"请输入每次发货时发送的固定文字"}),f.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:f.content.split(`
`).filter(x=>x.trim()).length})," 条"]})]}),f.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:f.api_method,onChange:x=>F({...f,api_method:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:f.api_timeout,onChange:x=>F({...f,api_timeout:parseInt(x.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:f.api_headers,onChange:x=>F({...f,api_headers:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:f.api_params,onChange:x=>F({...f,api_params:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:f.description,onChange:x=>F({...f,description:x.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:f.delay_seconds,onChange:x=>F({...f,delay_seconds:parseInt(x.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>N(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:m,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(at,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),ee&&ze.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>de(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(De,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>y("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${X==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(cl,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>y("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${X==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Dt,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),X==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),'。 类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:xe,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transi Line truncated
VIP-002
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),z&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",z.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>de(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),X==="create"?e.jsxs("button",{onClick:ie,disabled:!V||he,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[he?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Dt,{className:"w-4 h-4"}),he?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:_e,disabled:!fe||!ae.trim()||he||w.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[he?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(at,{className:"w-4 h-4"}),he?"处理中...":"追加卡密"]})]})]})}),document.body)]})},oa="ydisks-amap-js-api",jn="c9b68d4ce9a2a97f22a4a439404488ca";let Rt=null;const Nn=()=>jn,_n=()=>window.AMap?Promise.resolve(window.AMap):Rt||(Rt=new Promise((t,s)=>{const a=document.getElementById(oa),n=a||document.createElement("script"),i=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(j)},N=()=>{window.AMap?(i(),t(window.AMap)):(i(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},j=window.setTimeout(()=>{i(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=N,n.id=oa,n.async=!0,n.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(Nn())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,n.onerror=()=>{i(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(n)}).catch(t=>{throw Rt=null,t}),Rt),Ht=t=>Number.isFinite(t)&&t!==0,vn=t=>{var i,N;const s=Number((i=t.location)==null?void 0:i.lng),a=Number((N=t.location)==null?void 0:N.lat),n={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:a,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!n.division_id||!n.province||!n.city||!n.poi_id||!n.poi_name||!Ht(s)||!Ht(a)||s<-180||s>180||a<-90||a>90?null:n},wn=async(t,s)=>{if(!Ht(t)||!Ht(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await _n();return new Promise((n,i)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(j,P)=>{var L;if(j!=="complete"){if(j==="no_data"){n([]);return}i(new Error("高德地图附近地址查询失败,请稍后重试"));return}const g=(((L=P==null?void 0:P.poiList)==null?void 0:L.pois)||[]).map(vn).filter(f=>f!==null);n(g)})})},kn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),_s=t=>t==="running"||t==="canceling",Cn=t=>!!(t!=null&&t.preview_id&&Number(t.valid||0)>0),Sn=t=>!!(t!=null&&t.id&&Number(t.retryable||0)>0&&!_s(t.status)),Ln=(t,s)=>t===s,ca=t=>{switch(t){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return t||"-"}},da=t=>{switch(t){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},In=t=>{const[s,a]=l.useState(!1),[n,i]=l.useState("upload"),[N,j]=l.useState(null),[P,g]=l.useState(null),[L,f]=l.useState(""),[F,ee]=l.useState(!1),[de,X]=l.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[y,V]=l.useState(null),[D,G]=l.useState(null),[Y,he]=l.useState(null),[be,fe]=l.useState([]),[k,ae]=l.useState(null),[ce,z]=l.useState(!1),ue=l.useRef(!1),Q=l.useRef(0),S=l.useCallback(async()=>{i("upload"),V(null),G(null),j(null),g(null),f(""),X({catId:"",catName:"",channelCatId:"",tbCatId:""}),fe([]),ae(null),a(!0),z(!0);try{const w=await Ma(20),J=kn(w);if(J!=null&&J.id){const xe=await yt(J.id);he(xe),G(xe),i(["running","canceling"].includes(xe.status)?"running":"done")}}catch(w){console.error("恢复最近批量铺货任务失败:",w)}finally{z(!1)}},[]),B=l.useCallback(async()=>{const w=L.trim();if(!t.selectedAccount){alert("请先选择默认发布账号"); Line truncated
`),Me=new Blob(["\uFEFF"+ye],{type:"text/csv;charset=utf-8"}),Qe=URL.createObjectURL(Me),We=document.createElement("a");We.href=Qe,We.download="批量铺货模板.csv",document.body.appendChild(We),We.click(),We.remove(),URL.revokeObjectURL(Qe)},Lt=()=>{le(c=>({...c,cookie_id:P||c.cookie_id})),G(!0)},pt=()=>{K(c=>({...c,cookie_id:P||c.cookie_id})),he(!0)},ht=async c=>{if(!(c?P:$.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");fe(!0),navigator.geolocation.getCurrentPosition(async ye=>{try{const Me=await wn(ye.coords.longitude,ye.coords.latitude);if(!Me.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");c?(b(Me),C(Me[0])):(ae(Me),z(Me[0]))}catch(Me){alert((Me==null?void 0:Me.message)||"获取发货地失败")}finally{fe(!1)}},ye=>{fe(!1),alert(ye.code===ye.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},It=c=>n.filter(T=>T.cookie_id===c.cookie_id&&T.item_id===c.item_id).length>0?n.filter(T=>T.cookie_id===c.cookie_id&&T.item_id===c.item_id):n.filter(T=>T.cookie_id===c.cookie_id&&!T.item_id),it=l.useMemo(()=>new Map(N.map(c=>[c.id,c])),[N]),gt=l.useMemo(()=>L?s.filter(c=>c.cookie_id===L):s,[L,s]),tt=c=>{const T=it.get(c),ye=(T==null?void 0:T.remark)||(T==null?void 0:T.nickname);return ye?`${ye} · ${c.slice(0,6)}`:`账号 ${c.slice(0,8)}`},bt=c=>{const T=it.get(c);return(T==null?void 0:T.remark)||(T==null?void 0:T.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(ml,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:L,onChange:c=>f(c.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),N.map(c=>e.jsx("option",{value:c.id,children:tt(c.id)},c.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(ut,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:P,onChange:c=>g(c.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),N.map(c=>e.jsx("option",{value:c.id,children:tt(c.id)},c.id))]})]})]}),e.jsxs("button",{onClick:O,disabled:F||!P,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Ve,{className:`w-4 h-4 ${F?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Lt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(at,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:pt,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(es,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void U(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Bt,{className:"w-4 h-4"}),se&&["running","canceling"].includes(se.status)?"继续批量任务":"批量铺货"]}),se&&!["running","canceling"].includes(se.status)&&e.jsx("button",{onClick:()=>void Oe(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[gt.map(c=>{const T=It(c),ye=T.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex Line truncated
+3 -3
View File
@@ -6,12 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ydisks闲鱼助手 - 自动发货与管家系统</title>
<meta name="description" content="Ydisks闲鱼助手 - 自动回复、自动发货、订单管理、AI智能议价一体化解决方案" />
<script type="module" crossorigin src="/static/assets/index-cbea0zA7.js"></script>
<script type="module" crossorigin src="/static/assets/index-B6IVu2Jz.js"></script>
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-C_od1ZSF.js">
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-BpMgNNfy.js">
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-C73Tbcy8.js">
<link rel="modulepreload" crossorigin href="/static/assets/vendor-D-Edl3pr.js">
<link rel="modulepreload" crossorigin href="/static/assets/charts-vendor-BxxJOyEX.js">
<link rel="stylesheet" crossorigin href="/static/assets/index-DMbguo3K.css">
<link rel="stylesheet" crossorigin href="/static/assets/index-DHTuTnpg.css">
</head>
<body>
<div id="root"></div>