feat: 支持通过管理页面完成首次初始化

初始化流程:

- 新增一次性 POST /initialize 接口,仅在系统尚未存在管理员时允许创建账号。

- 校验管理员密码不少于 8 个字符,初始化成功后自动建立会话并登录。

- 增加初始化并发保护,避免首次打开多个页面时互相覆盖密码。

前端与资源:

- 将初始化页面改为密码和确认密码表单,移除普通用户需要执行的 CLI 命令和数据库路径提示。

- 初始化成功后直接进入管理后台,并重新构建嵌入式前端资源。

- 增加未初始化接口回归测试和自动登录验证。

文档同步:

- 更新 README、文档站、GitHub Wiki、前端说明和 AGENTS.md。

- 明确 Docker 使用 XIANYU_ADMIN_PASSWORD 非交互初始化。

- 明确独立二进制和 Linux 安装包通过 Web 页面初始化,CLI 仅作为无浏览器或运维备用方式。

- 同步桌面端 Chromium runtime 内置、Linux 安装流程和 Windows/macOS 签名包说明。
This commit is contained in:
Christ committed 2026-08-12 03:04:28 +08:00
1 parent 80baba46ff
commit 6032dfed0f
15 files changed
+289 -67

No files matched your search

+5 -1
View File
@@ -4,7 +4,7 @@
The active application contains:
- `cmd/server/` — server entrypoint, administrator bootstrap (`-init-admin`), and HTTP server.
- `cmd/server/` — server entrypoint, administrator bootstrap (`/initialize` and `-init-admin`), and HTTP server.
- `cmd/init-admin/` — interactive administrator initialization CLI.
- `cmd/dbverify/` — migration + core CRUD verification tool across SQLite/MySQL/Postgres.
- `internal/server/` — chi HTTP API and SPA serving.
@@ -38,6 +38,10 @@ go run ./cmd/server -db data/xianyu_data.db -addr :8080
DATABASE_URL="mysql://user:pass@tcp(host:3306)/db" go run ./cmd/server -addr :8080
```
On a new database, open the management page after starting the server. The first-run page accepts
and confirms an administrator password, creates the `admin` user, and signs the user in automatically.
The CLI bootstrap remains available for headless or operational environments.
Disable browser automation when Chromium is unavailable:
```bash
+35 -12
View File
@@ -178,19 +178,37 @@ npm --prefix frontend run build
桌面端由两个进程组成:后台 `xianyu-server` 负责 HTTP API、账号运行时和 Chromium;
`xianyu-tray` 只负责 Windows 托盘或 macOS 菜单栏状态、打开管理页面和服务控制。
Chromium 不打进 Go 二进制,首次安装时由随包的 `browser-install` 自动下载到用户数据目录。
Chromium 不打进 Go 二进制,但 Windows 和 macOS 安装包会内置对应架构的 Playwright
driver 与 Chromium runtime,安装后无需用户再下载浏览器。
- Windows:安装器注册 `YdisksXianyuHelper` Windows Service,并将托盘控制器加入当前用户登录启动项。
- macOS:安装器注册当前登录用户的两个 LaunchAgent,分别运行后台服务和菜单栏控制器。
- Linux:下载对应架构的 tar 包后,以 root 执行 `./install.sh`;脚本创建专用系统用户、安装
systemd unit,并执行 Playwright Chromium 及系统依赖安装。卸载时执行 `./uninstall.sh`,
systemd unit,并执行 Playwright Chromium 及系统依赖安装。安装完成后打开管理页面,首次
设置管理员密码。卸载时执行 `./uninstall.sh`,
默认保留 `/var/lib/ydisks-xianyu-helper` 数据。
桌面端安装包由 GitHub Actions 的 `codex/desktop-packaging` 分支专用工作流构建。当前工作流
上传未签名的 Windows `.exe` 安装器和 macOS `.pkg` 作为 Actions artifact;正式对外分发前,
还应配置 Windows 代码签名证书、Apple Developer ID 和公证流程。
桌面端安装包由 GitHub Actions 的 `codex/desktop-packaging` 分支专用工作流构建:Linux 上传
amd64/arm64 tar 包,Windows 上传安装器,macOS 分别上传 arm64 和 amd64 安装包。Windows
和 macOS 安装包使用工作流中配置的固定签名证书签名;未配置对应 GitHub Secrets 时,签名
步骤会失败,不会生成可分发的安装包。
初始化管理员:
桌面端首次启动:
1. 安装对应平台的安装包。macOS 请选择 arm64(Apple Silicon)或 amd64(Intel)版本。
2. 启动后台服务和托盘/菜单栏控制器。
3. 打开托盘菜单中的管理页面,或访问 `http://127.0.0.1:8080`。
4. 如果数据库尚未初始化,页面会要求设置并确认管理员密码;完成后会自动登录,管理员用户名为 `admin`。
Linux 需要先安装并启动 systemd 服务:
```bash
sudo ./install.sh
```
然后访问 `http://127.0.0.1:8080` 完成首次初始化。
对于无浏览器环境、自动化部署或需要重置管理员密码的运维场景,仍可使用 CLI 初始化:
```bash
mkdir -p data
@@ -206,8 +224,8 @@ go run ./cmd/server \
go run ./cmd/server -db data/xianyu_data.db -addr :8080
```
首次启动会准备 Playwright 运行环境和 Chromium;下载速度取决于当前网络。启动完成后
访问 `http://localhost:8080`。
启动完成后访问 `http://localhost:8080`。如果数据库尚未初始化,直接在页面填写并确认
管理员密码即可,不需要知道数据库文件路径,也不需要先执行 CLI 命令。
如当前环境无法安装 Chromium,可以使用 `-no-browser` 启动:
@@ -247,7 +265,7 @@ DATABASE_URL > -db-url > -db
| --- | --- | --- |
| `DATABASE_URL` | 空 | 数据库连接 URL;生产环境推荐 PostgreSQL |
| `XIANYU_DATA_KEY` | 空 | 敏感字段加密主密钥;生产环境必须固定并备份 |
| `XIANYU_ADMIN_PASSWORD` | 空 | 非交互初始化或重置管理员时使用 |
| `XIANYU_ADMIN_PASSWORD` | 空 | Docker Compose 非交互初始化或重置管理员时使用;源码和桌面端可通过首次打开页面设置密码 |
| `XIANYU_UPLOAD_DIR` | `data/uploads` | 批量铺货上传文件与临时资源目录 |
| `LOG_LEVEL` | 系统设置或 `info` | `debug`、`info`、`warn`、`error` |
| `LOG_FORMAT` | 系统设置或 `text` | `text` 或 `json` |
@@ -560,15 +578,20 @@ go run ./cmd/dbverify "postgres://user:pass@127.0.0.1:5432/xianyu"
## 常见问题
### 首次部署无法完成管理员初始化
### 首次打开页面如何初始化管理员
确认 `.env` 已设置非空的 `XIANYU_ADMIN_PASSWORD`,然后执行:
启动服务后访问管理页面。如果数据库中还没有管理员,页面会显示“首次设置管理员密码”,
填写两次不少于 8 个字符的密码并提交即可。初始化成功后会自动登录,默认管理员用户名为
`admin`。
Docker Compose 使用非交互初始化,因此必须在 `.env` 中设置非空的
`XIANYU_ADMIN_PASSWORD`,然后执行:
```bash
docker compose up -d
```
源码运行时可执行:
无浏览器、自动化部署或需要重置管理员密码时可执行:
```bash
go run ./cmd/server -init-admin -db data/xianyu_data.db -admin-password '新密码'
+6 -7
View File
@@ -1133,9 +1133,10 @@
<span class="command">cd</span> Ydisks-Xianyu-Helper
<span class="command">cp</span> .env.example .env
<span class="comment"># 2. 修改 .env 填入自己的强密码与主密钥</span>
<span class="comment"># 2. 修改 .env 填入数据库密码、管理员密码与主密钥</span>
<span class="comment"># POSTGRES_PASSWORD=...</span>
<span class="comment"># XIANYU_DATA_KEY=...</span>
<span class="comment"># XIANYU_ADMIN_PASSWORD=...</span>
<span class="comment"># 3. 启动应用 (会自动拉取 GHCR 镜像并初始化 PostgreSQL 17)</span>
<span class="command">docker compose up</span> -d
@@ -1153,15 +1154,13 @@
<span class="command">npm</span> --prefix frontend ci
<span class="command">npm</span> --prefix frontend run build
<span class="comment"># 2. 初始化管理员账号 (使用默认 SQLite)</span>
<span class="comment"># 2. 启动服务端 (默认监听 :8080)</span>
<span class="command">mkdir</span> -p data
<span class="command">go run</span> ./cmd/server \
-init-admin \
-db data/xianyu_data.db \
-admin-password <span class="string">'设置管理员密码'</span>
-addr :8080
<span class="comment"># 3. 启动服务端 (默认监听 :8080)</span>
<span class="command">go run</span> ./cmd/server -db data/xianyu_data.db -addr :8080</code></pre>
<span class="comment"># 3. 浏览器访问 http://localhost:8080,在首次初始化页面设置管理员密码</span></code></pre>
</div>
</div>
@@ -1183,7 +1182,7 @@
<svg fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/></svg>
</div>
<div class="faq-answer">
使用 Docker Compose 部署时,服务在启动时会自动读取 <code>.env</code> 文件中的 <code>XIANYU_ADMIN_PASSWORD</code> 创建管理员,默认用户名统一为 <code>admin</code>。使用源码构建时,可运行 <code>go run ./cmd/server -init-admin -db ... -admin-password '你的密码'</code> 初始化。
使用 Docker Compose 部署时,服务会读取 <code>.env</code> 文件中的 <code>XIANYU_ADMIN_PASSWORD</code>,在首次启动时自动创建管理员,默认用户名为 <code>admin</code>。源码运行或桌面端安装后,首次访问管理页面会显示密码设置表单,填写并确认密码即可完成初始化并自动登录。无浏览器或自动化部署场景仍可使用 <code>-init-admin</code> CLI。
</div>
</div>
+2 -1
View File
@@ -6,7 +6,8 @@
## 推荐上线路径
1. 选择并启动数据库;生产环境推荐 PostgreSQL。
2. 设置并备份 `XIANYU_DATA_KEY`,初始化管理员后登录后台。
2. 设置并备份 `XIANYU_DATA_KEY`;启动服务后打开管理页面,首次填写管理员密码完成初始化。
默认管理员用户名为 `admin`。
3. 在“账号管理”扫码接入账号,确认账号为启用且在线状态。
4. 在“卡密库存”建立可交付内容。
5. 同步已有商品,或通过“商品管理”发布商品。
+12 -2
View File
@@ -18,7 +18,9 @@
3. 为 `XIANYU_DATA_KEY` 生成一次长期固定的随机值,例如 `openssl rand -base64 48`;不要在后续升级时更换。
4. 启动:`docker compose up -d`。
5. 查看:`docker compose ps` 和 `docker compose logs -f app`。
6. 打开 `http://服务器地址:8080`,用管理员账号登录。若未自动初始化,可按 README 的 `-init-admin` 命令执行。
6. 打开 `http://服务器地址:8080`。设置了 `XIANYU_ADMIN_PASSWORD` 时,Compose 会在首次启动
自动创建 `admin`;如果使用其他方式启动且数据库尚未初始化,页面会显示初始化表单,填写
两次不少于 8 个字符的密码即可。
默认连接已由 `compose.yml` 注入,不需要手写 PostgreSQL URL。若修改 `COMPOSE_PROJECT_NAME`,新卷名前缀也会变化;已有部署升级时保留原 `.env`,避免误用新空卷。
@@ -62,7 +64,15 @@ DATABASE_URL="postgres://user:URL编码后的密码@db.example:5432/xianyu?sslmo
## 初始化、备份和升级
初始化管理员:
### Web 页面初始化(推荐)
启动服务后访问管理页面。系统尚未存在管理员时,会显示“首次设置管理员密码”页面。输入并
确认不少于 8 个字符的密码,提交后系统会创建 `admin` 账号并自动登录。此流程不需要用户
知道 SQLite 文件路径,也不需要打开终端执行初始化命令。
### CLI 初始化(运维备用)
无浏览器、自动化部署或需要重置管理员密码时,可以使用 CLI:
```bash
go run ./cmd/server -init-admin -db data/xianyu_data.db -admin-password '强密码'
+73 -18
View File
@@ -11,7 +11,7 @@ import Notifications from './components/Notifications';
import Chat from './components/Chat';
import { readSidebarCollapsed, writeSidebarCollapsed } from './components/sidebarState';
import { YdisksBrandIcon } from './components/YdisksLogo';
import { login, logout, verifySession } from './services/api';
import { initializeAdmin, login, logout, verifySession } from './services/api';
import { ShieldCheck, ArrowRight, Loader2, User, Lock } from 'lucide-react';
interface DeliveryRuleTarget {
@@ -39,9 +39,6 @@ const TAB_TO_PATH: Record<string, string> = Object.fromEntries(
);
const tabFromPath = (): string => ROUTES[window.location.pathname] || 'dashboard';
// 检测 Windows 以显示对应的 CLI 命令(路径分隔符、引号、.exe 后缀)。
const isWindows = /Win/i.test(navigator.platform || navigator.userAgent);
const App: React.FC = () => {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [isAdmin, setIsAdmin] = useState(false);
@@ -52,6 +49,10 @@ const App: React.FC = () => {
const [password, setPassword] = useState('');
const [loginLoading, setLoginLoading] = useState(false);
const [loginError, setLoginError] = useState('');
const [initialPassword, setInitialPassword] = useState('');
const [initialPasswordConfirm, setInitialPasswordConfirm] = useState('');
const [initializing, setInitializing] = useState(false);
const [initializationError, setInitializationError] = useState('');
const [deliveryRuleTarget, setDeliveryRuleTarget] = useState<DeliveryRuleTarget | undefined>();
const [sidebarCollapsed, setSidebarCollapsed] = useState(readSidebarCollapsed);
@@ -133,6 +134,38 @@ const App: React.FC = () => {
}
};
const handleInitialize = async (e: React.FormEvent) => {
e.preventDefault();
setInitializationError('');
if (initialPassword.length < 8) {
setInitializationError('密码至少需要 8 个字符');
return;
}
if (initialPassword !== initialPasswordConfirm) {
setInitializationError('两次输入的密码不一致');
return;
}
setInitializing(true);
try {
const res = await initializeAdmin(initialPassword);
if (!res.success) {
setInitializationError(res.message || '初始化失败,请重试');
return;
}
setNeedsInit(false);
setIsLoggedIn(true);
setIsAdmin(res.is_admin === true);
setInitialPassword('');
setInitialPasswordConfirm('');
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
setInitializationError(msg || '初始化失败,请重试');
} finally {
setInitializing(false);
}
};
const handleLogout = async () => {
try {
await logout();
@@ -165,27 +198,49 @@ const App: React.FC = () => {
<div className="mx-auto mb-6 flex justify-center">
<YdisksBrandIcon sizeClass="w-24 h-24" />
</div>
<h2 className="text-3xl font-extrabold text-gray-900 mb-2 tracking-tight">系统尚未初始化</h2>
<p className="text-gray-600 font-medium">为避免默认口令风险,管理员必须通过服务器本机 CLI 初始化。</p>
<h2 className="text-3xl font-extrabold text-gray-900 mb-2 tracking-tight">首次设置管理员密码</h2>
<p className="text-gray-600 font-medium">设置完成后会自动进入系统,管理员账号为 admin。</p>
</div>
<div className="space-y-4">
<div className="p-4 rounded-2xl bg-gray-50 border border-gray-100">
<div className="text-sm font-bold text-gray-900 mb-2">请在服务器上执行:</div>
<pre className="text-xs bg-black text-white p-4 rounded-2xl overflow-x-auto">{isWindows
? '.\\xianyu-server.exe -init-admin -db data\\xianyu_data.db -admin-password "请设置密码"'
: './xianyu-server -init-admin -db data/xianyu_data.db -admin-password \'请设置密码\''}</pre>
<div className="text-xs text-gray-500 mt-2">完成后刷新页面即可进入登录。</div>
<form onSubmit={handleInitialize} className="space-y-5">
<div className="space-y-4">
<div className="relative group">
<Lock className="absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors" />
<input
type="password"
placeholder="设置管理员密码(至少 8 个字符)"
value={initialPassword}
onChange={e => setInitialPassword(e.target.value)}
autoFocus
className="w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"
/>
</div>
<div className="relative group">
<ShieldCheck className="absolute left-5 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-black transition-colors" />
<input
type="password"
placeholder="再次输入密码"
value={initialPasswordConfirm}
onChange={e => setInitialPasswordConfirm(e.target.value)}
className="w-full ios-input pl-14 pr-6 py-4.5 rounded-2xl text-base h-14"
/>
</div>
</div>
{initializationError && (
<div className="p-3 rounded-xl bg-red-50 text-red-500 text-sm text-center font-bold flex items-center justify-center gap-2">
<ShieldCheck className="w-4 h-4" /> {initializationError}
</div>
)}
<button
type="button"
onClick={() => window.location.reload()}
className="w-full ios-btn-primary h-14 rounded-2xl text-lg shadow-xl shadow-blue-200 mt-2 flex items-center justify-center gap-2 group"
type="submit"
disabled={initializing}
className="w-full ios-btn-primary h-14 rounded-2xl text-lg shadow-xl shadow-blue-200 mt-2 flex items-center justify-center gap-2 group disabled:opacity-70"
>
我已初始化,刷新 <ArrowRight className="w-5 h-5 group-hover:translate-x-1 transition-transform" />
{initializing ? <Loader2 className="w-5 h-5 animate-spin" /> : <>设置密码并进入系统 <ArrowRight className="w-5 h-5 group-hover:translate-x-1 transition-transform" /></>}
</button>
</div>
</form>
<div className="mt-8 pt-6 border-t border-gray-100 text-center">
<span className="text-xs text-gray-400 font-medium tracking-widest uppercase">Secure Bootstrap</span>
+5 -2
View File
@@ -8,7 +8,7 @@ React + Vite + TypeScript 单页应用,作为 Ydisks闲鱼助手 Go 后端的
frontend/
index.html 入口 HTML
index.tsx 应用入口(挂载 React、登录态判断、tab 路由)
App.tsx 主壳:侧边栏 + 内容区 + 登录/初始化
App.tsx 主壳:侧边栏 + 内容区 + 登录/首次初始化
components/ 业务组件(Dashboard / OrderList / CardList / Rules / Settings ...)
services/ 后端 API 封装(fetch 调用)
request.ts 统一请求工具(带 session cookie、错误处理)
@@ -48,7 +48,10 @@ Dashboard 的营收趋势柱状图使用统一的品牌蓝 `#0094f7` 表示同
应用使用 `window.history.pushState` 做 tab 导航,路径包括 `/app/dashboard`、`/app/accounts`、
`/app/chat`、`/app/cards`、`/app/items`、`/app/orders`、`/app/rules`、
`/app/notifications` 和管理员可见的 `/app/settings`。
未登录时显示登录表单(客户端状态,非独立路由)。后端 SPA catch-all 对非 API 的 GET 请求返回 `index.html`,支持深链刷新。
未登录时显示登录表单(客户端状态,非独立路由)。当后端 `/verify` 返回
`initialized: false` 时,显示首次初始化表单;用户确认不少于 8 个字符的管理员密码后,
前端调用 `/initialize` 创建 `admin` 并使用返回的会话自动进入系统。后端 SPA catch-all
对非 API 的 GET 请求返回 `index.html`,支持深链刷新。
## 测试
+4
View File
@@ -22,6 +22,10 @@ export const login = async (data: { username?: string; password?: string; email?
return post('/login', data, { skipAuthLogout: true });
};
export const initializeAdmin = async (password: string): Promise<LoginResponse> => {
return post('/initialize', { password }, { skipAuthLogout: true });
};
export const verifySession = async (): Promise<{ authenticated: boolean; initialized?: boolean; user_id?: number; username?: string; is_admin?: boolean }> => {
return get('/verify');
};
+1 -1
View File
@@ -1,5 +1,5 @@
// Package auth 实现 HttpOnly Cookie 会话认证,沿用 Fork 版安全基线:
// - 无默认口令(管理员必须经 init-admin CLI 初始化)
// - 无默认口令(管理员可经首次启动 Web UI 或 init-admin CLI 初始化)
// - 会话存 DB(sessions 表),HttpOnly + SameSite=Lax Cookie 传递
// - bcrypt 哈希,兼容老库无盐 SHA-26(首次登录静默升级)
//
+47
View File
@@ -30,6 +30,53 @@ type loginResponse struct {
IsAdmin bool `json:"is_admin"`
}
// initialize 首次启动时通过 Web UI 创建管理员账号。
// 该接口只允许在系统尚未存在管理员时调用,避免把初始化能力变成重置密码入口。
func (s *Server) initialize(w http.ResponseWriter, r *http.Request) {
var req struct {
Password string `json:"password"`
}
if err := decodeJSON(r, &req); err != nil {
writeErr(w, http.StatusBadRequest, "请求格式错误")
return
}
if utf8.RuneCountInString(req.Password) < 8 {
writeErr(w, http.StatusBadRequest, "密码至少需要 8 个字符")
return
}
// 同一进程内串行化初始化,避免两个首次打开的页面同时重置管理员密码。
s.initializationMu.Lock()
defer s.initializationMu.Unlock()
initialized, err := s.Store.Users.IsSystemInitialized(r.Context())
if err != nil {
writeErr(w, http.StatusInternalServerError, "检查系统初始化状态失败")
return
}
if initialized {
writeErr(w, http.StatusConflict, "系统已经初始化,请直接登录")
return
}
if _, err := auth.InitAdmin(r.Context(), s.Store, "admin@example.com", req.Password); err != nil {
writeErr(w, http.StatusInternalServerError, "初始化管理员失败")
return
}
// 初始化完成后立即建立会话,用户无需再手动输入一次 admin 账号和密码。
sid, user, err := s.Auth.Login(r.Context(), "admin", req.Password)
if err != nil || user == nil || sid == "" {
writeErr(w, http.StatusInternalServerError, "初始化完成,但自动登录失败,请使用 admin 账号登录")
return
}
s.Auth.SetSessionCookie(w, sid)
writeJSON(w, http.StatusOK, loginResponse{
Success: true, Message: "初始化成功", UserID: user.ID,
Username: user.Username, IsAdmin: user.IsAdmin,
})
}
// login 用户名密码登录(邮箱登录同走此接口,按字段判断)。
func (s *Server) login(w http.ResponseWriter, r *http.Request) {
var req loginRequest
+5 -3
View File
@@ -83,8 +83,9 @@ type Server struct {
qrOwners map[string]qrLoginOwner
// qrPersistLocks 按扫码会话串行化持久化,避免持有全局 qrMu 执行数据库、
// 资料刷新和账号重启等慢操作。
qrPersistLocks sync.Map
loginLimiter *loginFailureLimiter
qrPersistLocks sync.Map
loginLimiter *loginFailureLimiter
initializationMu sync.Mutex
}
// SetChatService installs the shared chat persistence and live event hub.
@@ -142,6 +143,7 @@ func (s *Server) Router() http.Handler {
r.Group(func(r chi.Router) {
r.Use(s.Auth.Middleware) // 解析 session,不强制登录
r.Post("/login", s.login)
r.Post("/initialize", s.initialize)
r.Get("/verify", s.verify)
r.Post("/logout", s.logout)
})
@@ -320,7 +322,7 @@ func setNoStore(w http.ResponseWriter) {
// 仅保留实际挂载的路由前缀,与 Router() 中的 mount* 一一对应。
func isAPIPath(path string) bool {
apiPrefixes := []string{
"/api/", "/admin/", "/health", "/login", "/logout", "/verify",
"/api/", "/admin/", "/health", "/login", "/initialize", "/logout", "/verify",
"/change-password", "/change-admin-password", "/account/",
"/cookies", "/cookie/", "/orders", "/analytics",
"/cards", "/automation-rules", "/items", "/keywords", "/default-replies", "/default-reply",
+74
View File
@@ -51,6 +51,22 @@ func newTestServer(t *testing.T) (*Server, *db.Store, func()) {
}
}
func newUninitializedTestServer(t *testing.T) (*Server, *db.Store, func()) {
t.Helper()
dbPath := filepath.Join(t.TempDir(), "test.db")
d, _, err := db.Open(context.Background(), dbPath)
if err != nil {
t.Fatalf("Open: %v", err)
}
store := db.NewStore(d, db.DialectSQLite)
mgr := account.NewManager(store, noopHandler{}, nil)
srv := New(store, mgr, false, "", ":0", nil, nil, nil)
return srv, store, func() {
mgr.StopAll()
_ = d.Close()
}
}
type roundTripFunc func(*http.Request) (*http.Response, error)
func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
@@ -143,6 +159,64 @@ func TestLoginWrongPassword(t *testing.T) {
}
}
func TestInitializeFromWebUI(t *testing.T) {
srv, store, cleanup := newUninitializedTestServer(t)
defer cleanup()
h := srv.Router()
shortReq := httptest.NewRequest(http.MethodPost, "/initialize", strings.NewReader(`{"password":"short"}`))
shortRec := httptest.NewRecorder()
h.ServeHTTP(shortRec, shortReq)
if shortRec.Code != http.StatusBadRequest {
t.Fatalf("短密码应返回 400,got %d body=%s", shortRec.Code, shortRec.Body.String())
}
initReq := httptest.NewRequest(http.MethodPost, "/initialize", strings.NewReader(`{"password":"newpassword"}`))
initRec := httptest.NewRecorder()
h.ServeHTTP(initRec, initReq)
if initRec.Code != http.StatusOK {
t.Fatalf("初始化 status=%d body=%s", initRec.Code, initRec.Body.String())
}
var initResult loginResponse
if err := json.Unmarshal(initRec.Body.Bytes(), &initResult); err != nil {
t.Fatalf("解析初始化响应: %v", err)
}
if !initResult.Success || !initResult.IsAdmin || initResult.Username != "admin" {
t.Fatalf("初始化响应异常: %+v", initResult)
}
admin, err := store.Users.GetAdmin(context.Background())
if err != nil || admin == nil {
t.Fatalf("初始化后 admin 不存在: admin=%+v err=%v", admin, err)
}
if _, ok, err := store.Users.VerifyAndUpgrade(context.Background(), "admin", "newpassword"); err != nil || !ok {
t.Fatalf("初始化密码不可用: ok=%v err=%v", ok, err)
}
cookies := initRec.Result().Cookies()
if len(cookies) == 0 || cookies[0].Name != "session" || cookies[0].Value == "" {
t.Fatalf("初始化后应自动建立会话: %+v", cookies)
}
verifyReq := httptest.NewRequest(http.MethodGet, "/verify", nil)
verifyReq.AddCookie(cookies[0])
verifyRec := httptest.NewRecorder()
h.ServeHTTP(verifyRec, verifyReq)
var verifyResult map[string]any
if err := json.Unmarshal(verifyRec.Body.Bytes(), &verifyResult); err != nil {
t.Fatalf("解析 verify 响应: %v", err)
}
if verifyResult["authenticated"] != true || verifyResult["initialized"] != true {
t.Fatalf("初始化后 verify 异常: %+v", verifyResult)
}
secondReq := httptest.NewRequest(http.MethodPost, "/initialize", strings.NewReader(`{"password":"anotherpw"}`))
secondRec := httptest.NewRecorder()
h.ServeHTTP(secondRec, secondReq)
if secondRec.Code != http.StatusConflict {
t.Fatalf("重复初始化应返回 409,got %d body=%s", secondRec.Code, secondRec.Body.String())
}
}
func TestUpdateCredentialsRenamesUserAndRevokesSessions(t *testing.T) {
srv, _, cleanup := newTestServer(t)
defer cleanup()
@@ -0,0 +1,19 @@
import{j as e,r,b as qe,c as ia,d as Ea}from"./react-vendor-C_od1ZSF.js";import{L as Ta,U as oa,M as as,C as ls,B as ca,S as da,Z as rs,a as yt,b as hs,c as gs,d as bs,e as Ma,f as nt,A as Cs,D as qa,g as Ss,P as xa,h as $t,E as ma,T as Fa,i as Ba,j as Re,X as De,k as za,l as Ua,m as fs,n as pa,o as Ye,Q as Kt,p as mt,q as Ze,r as ft,s as At,t as Ls,R as Ue,u as ua,v as Wa,w as Ke,K as Va,x as xt,y as rt,z as at,F as Os,G as Nt,H as jt,I as It,J as ha,N as Ja,O as Is,V as As,W as Qa,Y as Ga,_ as Ka,$ as Ha,a0 as Ht,a1 as Tt,a2 as ns,a3 as Za,a4 as Ya,a5 as is,a6 as Xa,a7 as el,a8 as Rt,a9 as Rs,aa as Wt,ab as ga,ac as tl,ad as sl,ae as Jt,af as ba,ag as al,ah as ll,ai as rl,aj as nl,ak as il,al as ol,am as $s}from"./icons-vendor-DjsKcZkz.js";import{R as Mt,B as cl,X as Ps,Y as Ds,T as qt,a as dl,C as Zt,A as xl,b as ml,c as pl,P as Es,d as Ts,L as ul}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 p of document.querySelectorAll('link[rel="modulepreload"]'))i(p);new MutationObserver(p=>{for(const v of p)if(v.type==="childList")for(const k of v.addedNodes)k.tagName==="LINK"&&k.rel==="modulepreload"&&i(k)}).observe(document,{childList:!0,subtree:!0});function l(p){const v={};return p.integrity&&(v.integrity=p.integrity),p.referrerPolicy&&(v.referrerPolicy=p.referrerPolicy),p.crossOrigin==="use-credentials"?v.credentials="include":p.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function i(p){if(p.ep)return;p.ep=!0;const v=l(p);fetch(p.href,v)}})();const hl=({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"})})}),os=({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.52 L 23.51 12.25 L 27.29 Line 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(hs,{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:Et,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:I,children:"取消"}),e.jsxs("button",{onClick:Ge,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:I,children:[I?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Ye,{className:"w-4 h-4"}),I?"保存中...":"保存"]})]})})]})}),document.body)]})},Zr=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)||"")})):[]}),Yr=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],Ks=({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"},l={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:l[t]||t})},Xr=()=>{const[t,s]=r.useState([]),[l,i]=r.useState([]),[p,v]=r.useState([]),[k,D]=r.useState({}),[g,R]=r.useState("all"),[y,J]=r.useState(""),[Z,pe]=r.useState(""),[de,N]=r.useState(""),q=r.useRef(0),[xe,Q]=r.useState(1),[Y,U]=r.useState(1),[be,ge]=r.useState(!1),[L,G]=r.useState(!1),[ae,H]=r.useState(!1),[me,$]=r.useState(!1),[T,X]=r.useState(null),[M,se]=r.useState(null),[we,je]=r.useState({}),[F,d]=r.useState(!1),[h,W]=r.useState(""),[w,ee]=r.useState(!1),[ie,_e]=r.useState(null),[$e,fe]=r.useState(null),[c,_]=r.useState(null),[re,x]=r.useState(!1),[u,I]=r.useState(null),[A,K]=r.useState(null),P=async()=>{const m=++q.current;ge(!0);try{const E=await Jl(y||void 0,g,xe,20,de);if(m!==q.current)return;s(E.data),U(E.total_pages)}catch(E){console.error("加载订单失败:",E)}finally{m===q.current&&ge(!1)}},ke=(m,E,oe)=>{if(oe&&oe.trim())return oe;if(k[`${m}:${E}`])return k[`${m}:${E}`];const ne=l.find(We=>{if(oe&&We.item_title){const et=oe.toLowerCase(),tt=We.item_title.toLowerCase();return tt.includes(et)||et.includes(tt)}return!1});return ne!=null&&ne.item_title?ne.item_title:"未知商品"},Oe=m=>{const E={};m.forEach(oe=>{oe.item_id&&(E[`${oe.cookie_id}:${oe.item_id}`]=oe.item_title||oe.item_id)}),D(E)};r.useEffect(()=>{const m=window.setTimeout(()=>{Q(1),N(Z.trim())},300);return()=>window.clearTimeout(m)},[Z]),r.useEffect(()=>{P()},[y,g,xe,de]),r.useEffect(()=>{Promise.all([Pt(),_t()]).then(([m,E])=>{v(m),i(E),Oe(E)}).catch(m=>{console.error("加载商品列表失败:",m)})},[]);const Pe=r.useMemo(()=>new Map(p.map(m=>[m.id,m])),[p]),Ee=m=>{const E=Pe.get(m),oe=(E==null?void 0:E.remark)||(E==null?void 0:E.nickname);return oe?`${oe} · ${m.slice(0,6)}`:`账号 ${m.slice(0,8)}`},Te=m=>{const E=Pe.get(m);return(E==null?void 0:E.remark)||(E==null?void 0:E.nickname)||"未命名账号"},f=async()=>{ge(!0);try{const m=await Kl(y||void 0,g);await P(),m!=null&&m.message&&alert(m.message)}catch(m){console.error("同步订单失败:",m),alert((m==null?void 0:m.message)||"同步失败,请重试")}finally{ge(!1)}},C=m=>{W(m),_e(null),d(!0)},B=async m=>{var E;ee(!0),_e(null);try{const oe=await Zl([h],m),ne=(E=oe==null?void 0:oe.results)==null?void 0:E[0];ne!=null&&ne.success?(_e({success:!0,message:ne.message}),P()):_e({success:!1,message:(ne==null?void 0:ne.message)||"发货失败"})}catch(oe){_e({success:!1,message:(oe==null?void 0:oe.message)||"请求失败"})}finally{ee(!1)}},V=m=>{X(m),G(!0)},Ce=m=>{se({...m}),H(!0)},Me=async()=>{if(!(!M||!M.order_id))try{const m={};M.status!==void 0&&(m.order_status=M.status),M.buyer_id!==void 0&&(m.buyer_id=M.buyer_id),M.amount!==void 0&&(m.amount=M.amount),M.receiver_name!==void 0&&(m.receiver_name=M.receiver_name),M.receiver_phone!= Line truncated
VIP-MONTH-002
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(A=>A.map(K=>`"${String(K).replace(/"/g,'""')}"`).join(",")).join(`
`),x=new Blob(["\uFEFF"+re],{type:"text/csv;charset=utf-8"}),u=URL.createObjectURL(x),I=document.createElement("a");I.href=u,I.download="卡密组批量导入模板.csv",document.body.appendChild(I),I.click(),I.remove(),URL.revokeObjectURL(u)},_e=async()=>{if(q){be(!0),Y(null);try{const c=await lr(q);if(Y(c),c.created>0){const _=await st();s(_)}}catch(c){Y({error:(c==null?void 0:c.message)||"上传失败"})}finally{be(!1)}}},$e=async()=>{if(!(!ge||!G.trim())){be(!0),me(null);try{const c=await rr(ge,G);me({added:c.added}),ae("");const _=await st();s(_)}catch(c){alert("追加失败:"+((c==null?void 0:c.message)||"未知错误"))}finally{be(!1)}}},fe=()=>{var c;N("create"),xe(null),Y(null),L((c=w[0])!=null&&c.id?String(w[0].id):""),ae(""),me(null),pe(!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:fe,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(It,{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(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(ha,{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:$,onChange:c=>T(c.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(Nt,{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:X,onChange:c=>M(c.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:["显示 ",ee.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:ee.map(c=>{let _="";return c.type==="data"&&c.data_content?_=`库存: ${c.data_content.split(`
`).filter(x=>x.trim()).length} 条`:c.type==="text"&&c.text_content?_=c.text_content:c.type==="api"&&c.api_config?_=c.api_config.url:c.type==="image"&&c.image_url&&(_="图片链接"),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(se,{type:c.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:c.name,children:c.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>W(c.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:c.id}),e.jsx(Ja,{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 ${c.type==="text"?"bg-blue-50 text-blue-600":c.type==="data"?"bg-purple-50 text-purple-600":c.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:c.type==="text"?"文本":c.type==="data"?"批量":c.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:_,children:_})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:c.description||"-",children:c.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>h(c),className:`w-12 h-8 rounded-full relative transition-colors ${c.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 ${c.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:()=>we(c),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(jt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>F(c.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Ke,{className:"h-4 w-4"})})]})})]},c.id)})})]})}),ee.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(xa,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),l&&k&&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(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:c=>R({...g,name:c.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:c=>R({...g,type:c.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:"批量数据"}),(k==null?void 0:k.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:c=>R({...g,api_url:c.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.jsLine 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(c=>c.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:c=>R({...g,image_url:c.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:c=>{c.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:c=>R({...g,delay_seconds:parseInt(c.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:c=>R({...g,description:c.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:()=>R({...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:()=>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:je,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),p&&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(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:y.name,onChange:c=>J({...y,name:c.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:()=>J({...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(ls,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>J({...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(Is,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>J({...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(c=>c.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:c=>J({...y,api_method:c.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:c=>J({...y,api_timeout:parseInt(c.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:c=>J({...y,api_headers:c.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:c=>J({...y,api_params:c.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:c=>J({...y,description:c.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:c=>J({...y,delay_seconds:parseInt(c.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:d,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),Z&&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:()=>pe(!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:()=>N("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 ${de==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Qa,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>N("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 ${de==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(It,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),de==="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:ie,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 tran 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:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),H&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",H.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:()=>pe(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),de==="create"?e.jsxs("button",{onClick:_e,disabled:!q||U,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[U?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(It,{className:"w-4 h-4"}),U?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:$e,disabled:!ge||!G.trim()||U||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:[U?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(at,{className:"w-4 h-4"}),U?"处理中...":"追加卡密"]})]})]})}),document.body)]})},sn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),an=t=>{const s=String(t||"").trim();return s?/^[¥¥]/.test(s)?s:`¥${s}`:"-"},ln=({onConfigureDelivery:t})=>{const[s,l]=r.useState([]),[i,p]=r.useState([]),[v,k]=r.useState([]),[D,g]=r.useState(""),[R,y]=r.useState(""),[J,Z]=r.useState(!1),[pe,de]=r.useState(!1),[N,q]=r.useState(!1),[xe,Q]=r.useState(!1),[Y,U]=r.useState(!1),[be,ge]=r.useState(!1),[L,G]=r.useState(!1),[ae,H]=r.useState("upload"),[me,$]=r.useState(null),[T,X]=r.useState(null),[M,se]=r.useState(""),[we,je]=r.useState(!1),[F,d]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[h,W]=r.useState(null),[w,ee]=r.useState(null),[ie,_e]=r.useState(null),$e=r.useRef(!1),[fe,c]=r.useState(null),[_,re]=r.useState({}),[x,u]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[I,A]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[K,P]=r.useState([]);r.useEffect(()=>{if(!be||I.images.length===0){P([]);return}const n=I.images.map((O,le)=>({key:O.name+le,url:URL.createObjectURL(O)}));return P(n),()=>{n.forEach(O=>URL.revokeObjectURL(O.url))}},[be,I.images]);const ke=async()=>{const n=await _t();l(n)},Oe=async()=>{p(await ms())};r.useEffect(()=>{Promise.all([Pt(),_t(),ms(),Us(20)]).then(([n,O,le,Je])=>{k(n),l(O),p(le);const Ge=Je.find(ze=>["running","canceling"].includes(ze.status))||Je.find(ze=>ze.status!=="preview");_e(Ge||null)}).catch(n=>console.error("加载商品配置失败:",n))},[]),r.useEffect(()=>{if(!L||!(w!=null&&w.id)||!["running","canceling"].includes(w.status))return;const n=window.setInterval(async()=>{if(!$e.current){$e.current=!0;try{const O=await gt(w.id);ee(O),_e(O),["running","canceling"].includes(O.status)||(H("done"),await ke(),await Oe())}catch(O){console.error("刷新批量铺货进度失败:",O)}finally{$e.current=!1}}},3e3);return()=>{window.clearInterval(n)}},[L,w==null?void 0:w.id,w==null?void 0:w.status]);const Pe=async()=>{if(!D)return alert("请先选择账号");Z(!0);try{const n=await nr(D);await ke(),alert((n==null?void 0:n.message)||"商品同步完成")}catch(n){console.error("同步商品失败:",n),alert((n==null?void 0:n.message)||"同步失败,请重试")}finally{Z(!1)}},Ee=n=>{c(n),re({...n}),Q(!0)},Te=async()=>{if(fe)try{await gr(fe.cookie_id,fe.item_id,{item_title:_.item_title||"",item_description:_.item_description||"",item_category:_.item_category||"",item_price:_.item_price||"",item_detail:_.item_detail||fe.item_detail||""}),await ke(),await Oe(),Q(!1),c(null)}catch(n){console.error("更新商品失败:",n),alert("更新失败,请重试")}},f=async n=>{if(confirm(`确认删除商品"${n.item_title}"吗?`))try{await ir(n.cookie_id,n.item_id),l(O=>O.filter(le=>!(le.cookie_id===n.cookie_id&&le.item_id===n.item_id)))}catch(O){console.error("删除商品失败:",O),alert("删除失败,请重试")}},C=async()=>{try{if(!x.cookie_id||!x.item_id){alert("请选择账号并填写商品ID");return}await or(x.cookie_id,{item_id:x.item_id,item_title:x.item_title,item_price:x.item_price,item_detail:x.item_image?JSON.stringify({item_image:x.item_image}):""}),await ke(),U(!1),u({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(n){console.error("添加商品失败:",n),alert("添加失败,请重试")}},B=async()=>{if(!I.cookie_id)return alert("请选择发布账号");if(!I.title.trim())return alert("请填写商品标题");if(!I.price.trim())return alert("请填写商品价格");if(!I.quantity||Number(I.quantity)<=0)return alert("库存数量必须大于 0");if(I.images.length===0)return alert("至少上传 1 张商品图片");if(I.postage_mode==="f Line truncated
`),Je=new Blob(["\uFEFF"+le],{type:"text/csv;charset=utf-8"}),Ge=URL.createObjectURL(Je),ze=document.createElement("a");ze.href=Ge,ze.download="批量铺货模板.csv",document.body.appendChild(ze),ze.click(),ze.remove(),URL.revokeObjectURL(Ge)},ne=()=>{u(n=>({...n,cookie_id:D||n.cookie_id})),U(!0)},We=()=>{A(n=>({...n,cookie_id:D||n.cookie_id})),ge(!0)},et=n=>i.filter(O=>O.cookie_id===n.cookie_id&&O.item_id===n.item_id).length>0?i.filter(O=>O.cookie_id===n.cookie_id&&O.item_id===n.item_id):i.filter(O=>O.cookie_id===n.cookie_id&&!O.item_id),tt=n=>{switch(n){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 n||"-"}},it=n=>{switch(n){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"}},Ve=r.useMemo(()=>new Map(v.map(n=>[n.id,n])),[v]),Qe=r.useMemo(()=>R?s.filter(n=>n.cookie_id===R):s,[R,s]),He=n=>{const O=Ve.get(n),le=(O==null?void 0:O.remark)||(O==null?void 0:O.nickname);return le?`${le} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},pt=n=>{const O=Ve.get(n);return(O==null?void 0:O.remark)||(O==null?void 0:O.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(Ha,{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:R,onChange:n=>y(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),v.map(n=>e.jsx("option",{value:n.id,children:He(n.id)},n.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(mt,{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:D,onChange:n=>g(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),v.map(n=>e.jsx("option",{value:n.id,children:He(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:Pe,disabled:J||!D,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(Ue,{className:`w-4 h-4 ${J?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:ne,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:We,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 V(),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(Tt,{className:"w-4 h-4"}),ie&&["running","canceling"].includes(ie.status)?"继续批量任务":"批量铺货"]}),ie&&!["running","canceling"].includes(ie.status)&&e.jsx("button",{onClick:()=>void Me(),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:[Qe.map(n=>{const O=et(n),le=O.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all gro Line truncated
@@ -1,19 +0,0 @@
import{j as e,r,b as qe,c as na,d as Da}from"./react-vendor-C_od1ZSF.js";import{L as Ta,U as ia,M as ss,C as as,B as oa,S as ca,Z as ls,a as ft,b as hs,c as gs,d as bs,e as Ea,f as nt,A as Cs,D as Ma,g as Ss,P as da,h as Rt,E as xa,T as qa,i as Fa,j as Pe,X as De,k as Ba,l as za,m as ys,n as ma,o as Ye,Q as Gt,p as mt,q as Ze,r as yt,s as At,t as Ls,R as Ue,u as pa,v as Ua,w as Ke,K as Wa,x as xt,y as rt,z as at,F as Os,G as _t,H as jt,I as It,J as ua,N as Va,O as Is,V as As,W as Ja,Y as Qa,_ as Ga,$ as Ka,a0 as Kt,a1 as Tt,a2 as rs,a3 as Ha,a4 as Za,a5 as ns,a6 as Ya,a7 as Xa,a8 as is,a9 as Rs,aa as Ut,ab as ha,ac as el,ad as tl,ae as Vt,af as ga,ag as sl,ah as al,ai as ll,aj as rl,ak as nl,al as il,am as ol}from"./icons-vendor-DjsKcZkz.js";import{R as Et,B as cl,X as $s,Y as Ps,T as Mt,a as dl,C as Ht,A as xl,b as ml,c as pl,P as Ds,d as Ts,L as ul}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 m of document.querySelectorAll('link[rel="modulepreload"]'))i(m);new MutationObserver(m=>{for(const v of m)if(v.type==="childList")for(const k of v.addedNodes)k.tagName==="LINK"&&k.rel==="modulepreload"&&i(k)}).observe(document,{childList:!0,subtree:!0});function l(m){const v={};return m.integrity&&(v.integrity=m.integrity),m.referrerPolicy&&(v.referrerPolicy=m.referrerPolicy),m.crossOrigin==="use-credentials"?v.credentials="include":m.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function i(m){if(m.ep)return;m.ep=!0;const v=l(m);fetch(m.href,v)}})();const hl=({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"})})}),os=({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.52 L 23.51 12.25 L 27.29 Line 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(hs,{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:Dt,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:I,children:"取消"}),e.jsxs("button",{onClick:Ge,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:I,children:[I?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(Ye,{className:"w-4 h-4"}),I?"保存中...":"保存"]})]})})]})}),document.body)]})},Hr=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)||"")})):[]}),Zr=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],Gs=({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"},l={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:l[t]||t})},Yr=()=>{const[t,s]=r.useState([]),[l,i]=r.useState([]),[m,v]=r.useState([]),[k,D]=r.useState({}),[g,R]=r.useState("all"),[f,Q]=r.useState(""),[Z,me]=r.useState(""),[ce,_]=r.useState(""),q=r.useRef(0),[de,G]=r.useState(1),[Y,U]=r.useState(1),[fe,ge]=r.useState(!1),[O,K]=r.useState(!1),[xe,F]=r.useState(!1),[J,$]=r.useState(!1),[E,se]=r.useState(null),[M,ae]=r.useState(null),[Le,Ne]=r.useState({}),[pe,u]=r.useState(!1),[h,W]=r.useState(""),[w,X]=r.useState(!1),[ne,_e]=r.useState(null),[Re,be]=r.useState(null),[c,N]=r.useState(null),[le,d]=r.useState(!1),[p,I]=r.useState(null),[A,H]=r.useState(null),P=async()=>{const x=++q.current;ge(!0);try{const T=await Vl(f||void 0,g,de,20,ce);if(x!==q.current)return;s(T.data),U(T.total_pages)}catch(T){console.error("加载订单失败:",T)}finally{x===q.current&&ge(!1)}},we=(x,T,ie)=>{if(ie&&ie.trim())return ie;if(k[`${x}:${T}`])return k[`${x}:${T}`];const re=l.find(We=>{if(ie&&We.item_title){const et=ie.toLowerCase(),tt=We.item_title.toLowerCase();return tt.includes(et)||et.includes(tt)}return!1});return re!=null&&re.item_title?re.item_title:"未知商品"},Oe=x=>{const T={};x.forEach(ie=>{ie.item_id&&(T[`${ie.cookie_id}:${ie.item_id}`]=ie.item_title||ie.item_id)}),D(T)};r.useEffect(()=>{const x=window.setTimeout(()=>{G(1),_(Z.trim())},300);return()=>window.clearTimeout(x)},[Z]),r.useEffect(()=>{P()},[f,g,de,ce]),r.useEffect(()=>{Promise.all([$t(),Nt()]).then(([x,T])=>{v(x),i(T),Oe(T)}).catch(x=>{console.error("加载商品列表失败:",x)})},[]);const $e=r.useMemo(()=>new Map(m.map(x=>[x.id,x])),[m]),Te=x=>{const T=$e.get(x),ie=(T==null?void 0:T.remark)||(T==null?void 0:T.nickname);return ie?`${ie} · ${x.slice(0,6)}`:`账号 ${x.slice(0,8)}`},Ee=x=>{const T=$e.get(x);return(T==null?void 0:T.remark)||(T==null?void 0:T.nickname)||"未命名账号"},y=async()=>{ge(!0);try{const x=await Gl(f||void 0,g);await P(),x!=null&&x.message&&alert(x.message)}catch(x){console.error("同步订单失败:",x),alert((x==null?void 0:x.message)||"同步失败,请重试")}finally{ge(!1)}},C=x=>{W(x),_e(null),u(!0)},B=async x=>{var T;X(!0),_e(null);try{const ie=await Hl([h],x),re=(T=ie==null?void 0:ie.results)==null?void 0:T[0];re!=null&&re.success?(_e({success:!0,message:re.message}),P()):_e({success:!1,message:(re==null?void 0:re.message)||"发货失败"})}catch(ie){_e({success:!1,message:(ie==null?void 0:ie.message)||"请求失败"})}finally{X(!1)}},V=x=>{se(x),K(!0)},ke=x=>{ae({...x}),F(!0)},Me=async()=>{if(!(!M||!M.order_id))try{const x={};M.status!==void 0&&(x.order_status=M.status),M.buyer_id!==void 0&&(x.buyer_id=M.buyer_id),M.amount!==void 0&&(x.amount=M.amount),M.receiver_name!==void 0&&(x.receiver_name=M.receiver_name),M.receiver_phone!== Line truncated
VIP-MONTH-002
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(A=>A.map(H=>`"${String(H).replace(/"/g,'""')}"`).join(",")).join(`
`),d=new Blob(["\uFEFF"+le],{type:"text/csv;charset=utf-8"}),p=URL.createObjectURL(d),I=document.createElement("a");I.href=p,I.download="卡密组批量导入模板.csv",document.body.appendChild(I),I.click(),I.remove(),URL.revokeObjectURL(p)},_e=async()=>{if(q){fe(!0),Y(null);try{const c=await ar(q);if(Y(c),c.created>0){const N=await st();s(N)}}catch(c){Y({error:(c==null?void 0:c.message)||"上传失败"})}finally{fe(!1)}}},Re=async()=>{if(!(!ge||!K.trim())){fe(!0),J(null);try{const c=await lr(ge,K);J({added:c.added}),xe("");const N=await st();s(N)}catch(c){alert("追加失败:"+((c==null?void 0:c.message)||"未知错误"))}finally{fe(!1)}}},be=()=>{var c;_("create"),de(null),Y(null),O((c=w[0])!=null&&c.id?String(w[0].id):""),xe(""),J(null),me(!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:be,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(It,{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(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(ua,{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:$,onChange:c=>E(c.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(_t,{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:se,onChange:c=>M(c.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:["显示 ",X.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:X.map(c=>{let N="";return c.type==="data"&&c.data_content?N=`库存: ${c.data_content.split(`
`).filter(d=>d.trim()).length} 条`:c.type==="text"&&c.text_content?N=c.text_content:c.type==="api"&&c.api_config?N=c.api_config.url:c.type==="image"&&c.image_url&&(N="图片链接"),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(ae,{type:c.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:c.name,children:c.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>W(c.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:c.id}),e.jsx(Va,{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 ${c.type==="text"?"bg-blue-50 text-blue-600":c.type==="data"?"bg-purple-50 text-purple-600":c.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:c.type==="text"?"文本":c.type==="data"?"批量":c.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:N,children:N})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:c.description||"-",children:c.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>h(c),className:`w-12 h-8 rounded-full relative transition-colors ${c.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 ${c.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:()=>Le(c),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(jt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>pe(c.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Ke,{className:"h-4 w-4"})})]})})]},c.id)})})]})}),X.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(da,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),l&&k&&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(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:c=>R({...g,name:c.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:c=>R({...g,type:c.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:"批量数据"}),(k==null?void 0:k.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:c=>R({...g,api_url:c.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.jsLine 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(c=>c.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:c=>R({...g,image_url:c.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:c=>{c.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:c=>R({...g,delay_seconds:parseInt(c.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:c=>R({...g,description:c.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:()=>R({...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:()=>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:Ne,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),m&&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(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:c=>Q({...f,name:c.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:()=>Q({...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(as,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>Q({...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(Is,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>Q({...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(c=>c.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:c=>Q({...f,api_method:c.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:c=>Q({...f,api_timeout:parseInt(c.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:c=>Q({...f,api_headers:c.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:c=>Q({...f,api_params:c.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:c=>Q({...f,description:c.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:c=>Q({...f,delay_seconds:parseInt(c.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:u,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),Z&&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:()=>me(!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:()=>_("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 ${ce==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Ja,{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 ${ce==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(It,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),ce==="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 tran 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:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),F&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",F.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:()=>me(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),ce==="create"?e.jsxs("button",{onClick:_e,disabled:!q||U,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[U?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(It,{className:"w-4 h-4"}),U?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:Re,disabled:!ge||!K.trim()||U||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:[U?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(at,{className:"w-4 h-4"}),U?"处理中...":"追加卡密"]})]})]})}),document.body)]})},tn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),sn=t=>{const s=String(t||"").trim();return s?/^[¥¥]/.test(s)?s:`¥${s}`:"-"},an=({onConfigureDelivery:t})=>{const[s,l]=r.useState([]),[i,m]=r.useState([]),[v,k]=r.useState([]),[D,g]=r.useState(""),[R,f]=r.useState(""),[Q,Z]=r.useState(!1),[me,ce]=r.useState(!1),[_,q]=r.useState(!1),[de,G]=r.useState(!1),[Y,U]=r.useState(!1),[fe,ge]=r.useState(!1),[O,K]=r.useState(!1),[xe,F]=r.useState("upload"),[J,$]=r.useState(null),[E,se]=r.useState(null),[M,ae]=r.useState(""),[Le,Ne]=r.useState(!1),[pe,u]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[h,W]=r.useState(null),[w,X]=r.useState(null),[ne,_e]=r.useState(null),Re=r.useRef(!1),[be,c]=r.useState(null),[N,le]=r.useState({}),[d,p]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[I,A]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[H,P]=r.useState([]);r.useEffect(()=>{if(!fe||I.images.length===0){P([]);return}const n=I.images.map((L,te)=>({key:L.name+te,url:URL.createObjectURL(L)}));return P(n),()=>{n.forEach(L=>URL.revokeObjectURL(L.url))}},[fe,I.images]);const we=async()=>{const n=await Nt();l(n)},Oe=async()=>{m(await ms())};r.useEffect(()=>{Promise.all([$t(),Nt(),ms(),zs(20)]).then(([n,L,te,Je])=>{k(n),l(L),m(te);const Ge=Je.find(ze=>["running","canceling"].includes(ze.status))||Je.find(ze=>ze.status!=="preview");_e(Ge||null)}).catch(n=>console.error("加载商品配置失败:",n))},[]),r.useEffect(()=>{if(!O||!(w!=null&&w.id)||!["running","canceling"].includes(w.status))return;const n=window.setInterval(async()=>{if(!Re.current){Re.current=!0;try{const L=await gt(w.id);X(L),_e(L),["running","canceling"].includes(L.status)||(F("done"),await we(),await Oe())}catch(L){console.error("刷新批量铺货进度失败:",L)}finally{Re.current=!1}}},3e3);return()=>{window.clearInterval(n)}},[O,w==null?void 0:w.id,w==null?void 0:w.status]);const $e=async()=>{if(!D)return alert("请先选择账号");Z(!0);try{const n=await rr(D);await we(),alert((n==null?void 0:n.message)||"商品同步完成")}catch(n){console.error("同步商品失败:",n),alert((n==null?void 0:n.message)||"同步失败,请重试")}finally{Z(!1)}},Te=n=>{c(n),le({...n}),G(!0)},Ee=async()=>{if(be)try{await hr(be.cookie_id,be.item_id,{item_title:N.item_title||"",item_description:N.item_description||"",item_category:N.item_category||"",item_price:N.item_price||"",item_detail:N.item_detail||be.item_detail||""}),await we(),await Oe(),G(!1),c(null)}catch(n){console.error("更新商品失败:",n),alert("更新失败,请重试")}},y=async n=>{if(confirm(`确认删除商品"${n.item_title}"吗?`))try{await nr(n.cookie_id,n.item_id),l(L=>L.filter(te=>!(te.cookie_id===n.cookie_id&&te.item_id===n.item_id)))}catch(L){console.error("删除商品失败:",L),alert("删除失败,请重试")}},C=async()=>{try{if(!d.cookie_id||!d.item_id){alert("请选择账号并填写商品ID");return}await ir(d.cookie_id,{item_id:d.item_id,item_title:d.item_title,item_price:d.item_price,item_detail:d.item_image?JSON.stringify({item_image:d.item_image}):""}),await we(),U(!1),p({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(n){console.error("添加商品失败:",n),alert("添加失败,请重试")}},B=async()=>{if(!I.cookie_id)return alert("请选择发布账号");if(!I.title.trim())return alert("请填写商品标题");if(!I.price.trim())return alert("请填写商品价格");if(!I.quantity||Number(I.quantity)<=0)return alert("库存数量必须大于 0");if(I.images.length===0)return alert("至少上传 1 张商品图片");if(I.postage_mode==="fi Line truncated
`),Je=new Blob(["\uFEFF"+te],{type:"text/csv;charset=utf-8"}),Ge=URL.createObjectURL(Je),ze=document.createElement("a");ze.href=Ge,ze.download="批量铺货模板.csv",document.body.appendChild(ze),ze.click(),ze.remove(),URL.revokeObjectURL(Ge)},re=()=>{p(n=>({...n,cookie_id:D||n.cookie_id})),U(!0)},We=()=>{A(n=>({...n,cookie_id:D||n.cookie_id})),ge(!0)},et=n=>i.filter(L=>L.cookie_id===n.cookie_id&&L.item_id===n.item_id).length>0?i.filter(L=>L.cookie_id===n.cookie_id&&L.item_id===n.item_id):i.filter(L=>L.cookie_id===n.cookie_id&&!L.item_id),tt=n=>{switch(n){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 n||"-"}},it=n=>{switch(n){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"}},Ve=r.useMemo(()=>new Map(v.map(n=>[n.id,n])),[v]),Qe=r.useMemo(()=>R?s.filter(n=>n.cookie_id===R):s,[R,s]),He=n=>{const L=Ve.get(n),te=(L==null?void 0:L.remark)||(L==null?void 0:L.nickname);return te?`${te} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},pt=n=>{const L=Ve.get(n);return(L==null?void 0:L.remark)||(L==null?void 0:L.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(Ka,{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:R,onChange:n=>f(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),v.map(n=>e.jsx("option",{value:n.id,children:He(n.id)},n.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(mt,{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:D,onChange:n=>g(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),v.map(n=>e.jsx("option",{value:n.id,children:He(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:$e,disabled:Q||!D,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(Ue,{className:`w-4 h-4 ${Q?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:re,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:We,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(Kt,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void V(),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(Tt,{className:"w-4 h-4"}),ne&&["running","canceling"].includes(ne.status)?"继续批量任务":"批量铺货"]}),ne&&!["running","canceling"].includes(ne.status)&&e.jsx("button",{onClick:()=>void Me(),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:[Qe.map(n=>{const L=et(n),te=L.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all gro Line truncated
+1 -1
View File
@@ -6,7 +6,7 @@
<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-DLBJvCyf.js"></script>
<script type="module" crossorigin src="/static/assets/index-Bp6jEzSl.js"></script>
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-C_od1ZSF.js">
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-DjsKcZkz.js">
<link rel="modulepreload" crossorigin href="/static/assets/vendor-D-Edl3pr.js">