feat: 完善聊天识别与规则页面响应式布局

- 按闲鱼协议字段识别官方系统消息、交易卡片和闲小蜜,清理空会话壳并补齐历史消息校正\n- 同步 README、项目展示页和 GitHub Wiki,补充在线聊天、账号自动评价与每日擦亮说明\n- 优化自动化规则页面的中等宽度布局,补充前端类型、响应式测试和嵌入资源
This commit is contained in:
Christ committed 2026-08-08 23:48:42 +08:00
1 parent 4d1f58c5ec
commit fe3f715cdc
27 files changed
+336 -32

No files matched your search

+14 -4
View File
@@ -13,7 +13,7 @@
[Docker 部署](#docker-部署) · [开发指南](#开发指南) · [开源协议](#开源协议)
操作手册见仓库内的 [GitHub Wiki 文档](docs/wiki/Home.md):包含数据库选择、账号接入、
批量铺货、自动化发货、AI、通知和运维流程。
在线聊天、账号自动任务、批量铺货、自动化发货、AI、通知和运维流程。
> [!IMPORTANT]
> 本项目是社区维护的非官方工具,与闲鱼、阿里巴巴集团及其关联公司无隶属、合作或
@@ -57,8 +57,9 @@ Ydisks 支持管理渠道、推广账号、原始链接、推广短链与域名
| --- | --- |
| 账号管理 | 多账号启停、扫码登录、密码登录、资料刷新、在线状态、登录审计与备注管理 |
| 凭证续期 | Cookie/token 定时续期、WebSocket 凭证更新、失效恢复、冷却与失败停用 |
| 即时消息 | 闲鱼 WebSocket 长连接、消息收发、关键词回复、默认回复及仅回复一次 |
| 即时消息 | 按账号隔离的在线聊天、会话列表与历史消息、闲鱼表情、文本/图片收发、官方系统消息识别、关键词回复、默认回复及仅回复一次 |
| 自动化中心 | 付款后自动发货、评价后赠品、超时未评价提醒、失败任务恢复与幂等检查点 |
| 账号自动任务 | 账号级持续扫描待评价订单并统一好评、按北京时间每日擦亮、手动立即执行、执行记录与幂等保护 |
| 卡密库存 | 文本、批量卡密和图片三种交付类型,库存追加、批量导入、规格与延迟发送 |
| 商品管理 | 商品同步、手工关联、单商品发布、CSV + ZIP 批量铺货、关键词获取默认类目、逐行类目优先、自动识别与“电子资料”最终兜底、任务恢复与结果导出 |
| 订单管理 | 订单同步、插入、编辑、平台发货、补发卡密、仅确认发货及异常状态处理 |
@@ -97,7 +98,13 @@ flowchart LR
## 页面预览
![Ydisks闲鱼助手预览](https://raw.githubusercontent.com/Christ9038/Ydisks-Xianyu-Helper/main/docs/img/preview.png)
![Ydisks闲鱼助手预览](https://raw.githubusercontent.com/Christ9038/Ydisks-Xianyu-Helper/main/docs/img/preview_account.png)
![Ydisks闲鱼助手预览](https://raw.githubusercontent.com/Christ9038/Ydisks-Xianyu-Helper/main/docs/img/preview_im.png)
![Ydisks闲鱼助手预览](https://raw.githubusercontent.com/Christ9038/Ydisks-Xianyu-Helper/main/docs/img/preview_auto.png)
## 快速开始
@@ -203,7 +210,9 @@ go run ./cmd/server -db data/xianyu_data.db -addr :8080 -no-browser
4. 等待账号状态变为在线,再同步商品和订单。
5. 在“卡密库存”创建交付内容。
6. 在“自动化规则”将闲鱼商品与卡密、规格和触发条件关联。
7. 按需配置关键词回复、默认回复、AI 回复和通知渠道。
7. 在“在线聊天”按账号查看历史会话、发送文本/表情/图片;官方交易卡片和闲小蜜消息会以系统消息显示,不会进入普通用户回复链。
8. 在“账号管理 → 自动评价与每日擦亮”按账号配置统一评价文案、评价开关和擦亮时间;确认测试账号行为后再启用。
9. 按需配置关键词回复、默认回复、AI 回复和通知渠道。
扫码登录是推荐方式。密码登录适合已有明确需求的环境,但更容易触发平台安全校验。
无论使用哪种方式,都不要把 Cookie、密码、二维码或人脸验证地址分享给不可信第三方。
@@ -290,6 +299,7 @@ DATABASE_URL="postgres://user:pass@127.0.0.1:5432/xianyu?sslmode=disable" ./xian
以下配置通过 Web 管理后台维护并保存在数据库中:
- **账号设置**:启停状态、备注、通知渠道绑定和单账号 AI 回复策略
- **账号自动任务**:自动评价开关、统一好评文案(最多 500 个字符)、每日擦亮开关、北京时间执行时间和最近执行记录
- **自动化规则**:触发条件、商品、规格、卡密组、发送数量、延迟和后续动作
- **回复规则**:关键词、文本或图片回复、默认回复及回复次数限制
- **AI 设置**:OpenAI 兼容 API 地址、API Key、模型和全局提示词
Binary file not shown.

Before

Width:  |  Height:  |  Size: 494 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 KiB

+9 -3
View File
@@ -4,12 +4,12 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ydisks闲鱼助手 - 基于 Go 与 React 构建的闲鱼多账号管理与自动发货系统</title>
<meta name="description" content="Ydisks闲鱼助手是一个面向闲鱼卖家的自托管管理系统。整合多账号登录、WebSocket即时消息、卡密库存交付、AI智能客服、自动化规则与多渠道告警。">
<meta name="description" content="Ydisks闲鱼助手是一个面向闲鱼卖家的自托管管理系统。整合多账号登录、按账号隔离的在线聊天、账号自动评价与每日擦亮、卡密库存交付、AI智能客服、自动化规则与多渠道告警。">
<meta name="keywords" content="闲鱼助手, 闲鱼自动发货, 闲鱼多账号管理, 闲鱼自动回复, 闲鱼AI客服, 闲鱼卡密发货, Go, React, Ydisks">
<!-- Open Graph -->
<meta property="og:title" content="Ydisks闲鱼助手 - 闲鱼多账号管理与自动发货系统">
<meta property="og:description" content="基于 Go 1.26 + React 19 构建的闲鱼自托管管理后台。自动化发货、AI回复、即时消息与风控续期。">
<meta property="og:description" content="基于 Go 1.26 + React 19 构建的闲鱼自托管管理后台。在线聊天、账号自动评价与每日擦亮、自动化发货、AI回复与风控续期。">
<meta property="og:type" content="website">
<meta property="og:image" content="img/slogan.png">
@@ -976,7 +976,7 @@
<div class="feature-card">
<div class="feature-icon-box">💬</div>
<h3 class="feature-card-title">WebSocket 即时消息处理</h3>
<p class="feature-card-desc">内置 Go 原生闲鱼 WebSocket 长连接通道,实时接收与推送聊天消息,支持关键词回复、默认回复及单次回复控制。</p>
<p class="feature-card-desc">按账号隔离在线聊天、历史消息和实时同步,支持闲鱼表情、文本/图片收发,并识别交易卡片与闲小蜜系统消息;普通消息继续支持关键词、默认回复及单次回复控制。</p>
</div>
<!-- Card 3 -->
@@ -986,6 +986,12 @@
<p class="feature-card-desc">自动关联买家付款事件,支持付款即发货、评价后赠品发放、超时提醒评价,内置幂等检查点防止重复发送。</p>
</div>
<div class="feature-card">
<div class="feature-icon-box">✨</div>
<h3 class="feature-card-title">账号自动评价与每日擦亮</h3>
<p class="feature-card-desc">按账号持续扫描待评价订单并使用统一文案评价;每日擦亮按北京时间执行,每个账号每天最多一次,并支持手动执行与结果记录。</p>
</div>
<!-- Card 4 -->
<div class="feature-card">
<div class="feature-icon-box">📦</div>
+4 -1
View File
@@ -1,4 +1,7 @@
# 登录续期与风控能力补齐计划
# 登录续期与风控能力实施记录
> 本文最初是实施计划。当前列出的五个阶段均已落地;后续协议变化应以实际代码、测试和
> 本文的实施记录为准,不应把“目标流程”误读为尚未实现的功能。
## 目标
+8 -5
View File
@@ -1,6 +1,7 @@
# Ydisks闲鱼助手 Wiki
本 Wiki 面向管理后台操作人员。先完成“部署与数据库”和“账号接入”,再配置库存、商品、自动化与 AI。
本 Wiki 面向管理后台操作人员。先完成“部署与数据库”和“账号接入”,再配置库存、商品、
在线聊天、账号自动任务、交易自动化与 AI。
## 推荐上线路径
@@ -9,15 +10,17 @@
3. 在“账号管理”扫码接入账号,确认账号为启用且在线状态。
4. 在“卡密库存”建立可交付内容。
5. 同步已有商品,或通过“商品管理”发布商品。
6. 在“自动化规则”建立付款发货、评价赠品或求评价规则。
7. 可选:在“系统与 AI”配置模型,再为每个账号启用 AI。
8. 建立通知渠道并绑定到账号;用测试通知验证。
9. 用小额测试订单验证“卡密发送 → 确认发货”全过程后,再开放正式商品。
6. 在“在线聊天”确认账号会话和历史消息正常,必要时发送测试文本或图片。
7. 在“账号自动任务”配置自动评价和每日擦亮;在“自动化规则”建立付款发货、评价赠品或求评价规则。
8. 可选:在“系统与 AI”配置模型,再为每个账号启用 AI。
9. 建立通知渠道并绑定到账号;用测试通知验证。
10. 用小额测试订单验证“卡密发送 → 确认发货”全过程后,再开放正式商品。
## 先读这些页面
- [部署与数据库](部署与数据库)
- [账号、库存与商品](账号、库存与商品)
- [在线聊天与账号自动任务](在线聊天与账号自动任务)
- [批量铺货](批量铺货)
- [自动化发货与回复](自动化发货与回复)
- [AI、通知与运维](AI、通知与运维)
+1
View File
@@ -3,6 +3,7 @@
- [首页](Home)
- [部署与数据库](部署与数据库)
- [账号、库存与商品](账号、库存与商品)
- [在线聊天与账号自动任务](在线聊天与账号自动任务)
- [批量铺货](批量铺货)
- [自动化发货与回复](自动化发货与回复)
- [AI、通知与运维](AI、通知与运维)
@@ -0,0 +1,62 @@
# 在线聊天与账号自动任务
## 在线聊天
进入“在线聊天”后,顶部按账号显示 Tab;每个账号拥有独立的会话列表和消息状态。下方是标准两栏布局:左侧为会话列表,右侧为当前会话消息窗口。
聊天功能包括:
- 会话联系人、头像、昵称、用户 ID、商品摘要和未读数;列表按闲鱼会话最后消息时间倒序。
- 进入会话后优先读取本地缓存,再从闲鱼历史消息接口补齐记录;底部可继续加载更早消息和更多历史联系人。
- 文本消息、闲鱼文字表情和图片发送。当前不支持从管理后台发送视频,因此界面不提供视频发送按钮。
- 发送方按“对方/我”区分,并显示对应头像;账号之间的会话和实时消息完全隔离。
- 应用使用后端 `/api/chat/ws` 推送实时事件;刷新或重连后仍以历史接口和本地数据库为准,不只依赖 WebSocket 存续期间收到的消息。
### 官方消息识别
闲鱼的交易卡片和平台通知不能当作普通用户消息处理。当前按协议元数据识别:
- `contentType=14`:平台通知类消息;
- `contentType=26`:交易卡片;
- 发送方用户 ID `1400`:闲小蜜;
- “发来一条新消息”:官方通知占位内容。
识别出的消息不会进入关键词、默认回复或 AI 回复链,并在聊天窗口中以居中的系统消息卡片展示。联系人分页返回的空会话壳不会导入列表,避免出现只有“暂无消息”的伪联系人。
如果昵称或头像缺失,点击会话列表刷新按钮;系统联系人闲小蜜使用平台头像和固定名称,不应把订单卡片标题当成用户昵称。
## 账号自动评价
入口为“账号管理 → 自动评价与每日擦亮”。自动评价是账号级开关,不针对不同买家配置不同文案:
1. 开启“自动评价”;
2. 填写统一好评文案,最多 500 个字符;
3. 保存后,后台持续扫描该账号的待评价订单;
4. 每个待评价订单按交易订单 ID 幂等执行,已经处理过的订单不会重复评价。
它不是每日任务。可以点击“立即评价”执行一次扫描,也可以依赖后台持续扫描。账号停用或暂停时不会执行。
## 每日自动擦亮
每日擦亮同样是账号级开关,但与自动评价不同:
- 按北京时间判断执行时间;
- 每个账号每天最多执行一次;
- 默认执行时间为 `03:00`,可在 `HH:mm` 范围内调整;
- 后台调用商品列表接口并逐个执行擦亮;当前实现按每页 20 条、最多 20 页读取商品;
- 可以点击“立即擦亮”手动触发,但当天已成功执行时会被幂等保护跳过;
- 页面会显示最近完成时间、本次发现数量、成功数、失败数和跳过数。
如果执行中部分商品失败,任务会记录失败原因并进入可重试状态;不要仅根据按钮返回就判断所有商品都已成功,应该查看本次执行结果。
## 与交易自动化的边界
“账号自动评价/每日擦亮”处理账号级任务;“自动化规则”处理订单和聊天触发的业务规则:
- 付款后自动发货;
- 评价后发送赠品;
- 超时未评价求评价;
- 关键词回复、默认回复和 AI 回复。
闲鱼官方系统消息只用于平台事件识别,不应被配置为普通买家关键词触发自动回复。
+2
View File
@@ -10,6 +10,8 @@
系统通知卡片只进入自动化判断;买家普通消息走关键词、默认回复和 AI 规则。
账号级自动评价和每日擦亮不属于上表的订单规则,配置入口在“账号管理 → 自动评价与每日擦亮”,执行方式见[在线聊天与账号自动任务](在线聊天与账号自动任务)。
## 配置付款自动发货
前提:账号在线、商品已同步、卡密组已建立且有库存。
+1 -1
View File
@@ -302,7 +302,7 @@ const App: React.FC = () => {
onLogout={handleLogout}
/>
<main className={`h-screen flex-1 overflow-y-auto scroll-smooth transition-[margin] duration-300 ${sidebarCollapsed ? 'ml-16' : 'ml-64'} ${activeTab === 'chat' ? 'p-4 md:p-6' : 'p-8 md:p-12'}`}>
<main className={`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${sidebarCollapsed ? 'ml-16' : 'ml-64'} ${activeTab === 'chat' ? 'p-4 md:p-6' : 'p-8 md:p-12'}`}>
{/* Subtle background decoration */}
<div className="fixed top-0 right-0 w-[800px] h-[800px] bg-gradient-to-bl from-blue-50 to-transparent rounded-full blur-[120px] pointer-events-none -z-10 opacity-60"></div>
+3 -1
View File
@@ -45,7 +45,9 @@ Dashboard 的营收趋势柱状图使用统一的品牌蓝 `#0094f7` 表示同
## 路由
应用使用 `window.history.pushState` 做 tab 导航,路径形如 `/app/dashboard`、`/app/rules`、`/app/settings`。
应用使用 `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`,支持深链刷新。
## 测试
+6
View File
@@ -37,6 +37,12 @@ describe('online chat UI contract', () => {
expect(chat).toContain('sendChatImage');
});
test('renders official notices as neutral system messages', () => {
const chat = source('components/Chat.tsx');
expect(chat).toContain("message.message_type === 'system'");
expect(chat).toContain('justify-center py-1');
});
test('sidebar exposes collapse control and chat primary navigation', () => {
const sidebar = source('components/Sidebar.tsx');
expect(sidebar).toContain("id: 'chat'");
+11
View File
@@ -449,6 +449,17 @@ const Chat: React.FC = () => {
</div>}
{messages.map(message => {
const outgoing = message.direction === 'outgoing';
const system = message.message_type === 'system';
if (system) {
return (
<div key={message.message_key} className="flex justify-center py-1">
<div className="max-w-[82%] rounded-xl border border-slate-200 bg-slate-100 px-4 py-2 text-center text-xs leading-5 text-slate-500">
{renderXianyuText(message.content)}
<div className="mt-1 text-[10px] text-slate-400">{messageTime(message.sent_at)}</div>
</div>
</div>
);
}
return (
<div key={message.message_key} className={`flex items-end gap-2.5 ${outgoing ? 'justify-end' : 'justify-start'}`}>
{!outgoing && <div className="h-9 w-9 shrink-0 overflow-hidden rounded-full bg-slate-200 ring-2 ring-white">
+5 -5
View File
@@ -801,7 +801,7 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
: '编辑默认回复';
return (
<div className="space-y-8 animate-fade-in">
<div className="min-w-0 space-y-8 animate-fade-in">
<div className="flex flex-col xl:flex-row justify-between xl:items-end gap-4">
<div>
<h2 className="text-4xl font-extrabold text-gray-900 tracking-tight">自动化规则</h2>
@@ -814,7 +814,7 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
setSelectedAccountId(event.target.value);
setAutomationPage(1);
}}
className="ios-input px-4 py-3 rounded-2xl text-sm min-w-64"
className="ios-input w-full px-4 py-3 rounded-2xl text-sm sm:w-64"
>
<option value="">全部账号</option>
{accounts.map(account => (
@@ -904,8 +904,8 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
)}
{activeTab === 'automation' && (
<div className="grid grid-cols-1 2xl:grid-cols-[360px_1fr] gap-6">
<aside className="space-y-4">
<div className="grid min-w-0 grid-cols-1 gap-6 xl:grid-cols-[minmax(270px,0.72fr)_minmax(0,1.28fr)]">
<aside className="min-w-0 space-y-4">
<div className="bg-white rounded-xl p-5 border border-gray-100 shadow-sm">
<h3 className="font-black text-gray-900 mb-1">新建规则</h3>
<p className="text-sm text-gray-500 mb-4">先选自动化类型,再配置对应动作。</p>
@@ -958,7 +958,7 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
</div>
</aside>
<section className="space-y-4">
<section className="min-w-0 space-y-4">
<div className="rounded-xl border border-gray-100 bg-[#FAFAFA] p-4 shadow-sm">
<div className="flex flex-col gap-3 xl:flex-row xl:items-center">
<div className="relative min-w-0 flex-1">
+16
View File
@@ -0,0 +1,16 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import { describe, expect, test } from 'vitest';
const source = (path: string) => readFileSync(resolve(__dirname, path), 'utf8');
describe('responsive rules layout', () => {
test('allows the rules page to shrink inside the sidebar layout', () => {
const app = source('App.tsx');
const rules = source('components/Rules.tsx');
expect(app).toContain('h-screen min-w-0 flex-1 overflow-x-hidden');
expect(rules).toContain('min-w-0 space-y-8');
expect(rules).toContain('xl:grid-cols-[minmax(270px,0.72fr)_minmax(0,1.28fr)]');
expect(rules).not.toContain('2xl:grid-cols-[360px_1fr]');
});
});
+2 -1
View File
@@ -106,7 +106,8 @@ export interface ChatMessage {
direction: 'incoming' | 'outgoing';
sender_id: string;
sender_name: string;
message_type: 'text' | 'image' | 'video';
/** text/image/video are peer messages; system is an official platform notice or trade card. */
message_type: 'text' | 'image' | 'video' | 'system';
content: string;
status: 'received' | 'sending' | 'sent' | 'failed';
sent_at: number;
+82 -1
View File
@@ -65,6 +65,12 @@ func (s *Service) RecordConversationPage(ctx context.Context, accountID, myID st
}
lastWrap, _ := conv["lastMessage"].(map[string]any)
last, _ := lastWrap["message"].(map[string]any)
// The conversation endpoint can return empty shells for notification
// recipients. The official web client does not render these as contacts;
// importing them creates fake users such as numeric IDs with “暂无消息”.
if len(last) == 0 {
continue
}
// reminderTitle belongs to the message presentation layer. Depending on
// the message type it may contain a nickname, an order-state prompt, or
// another card title. The official web client resolves conversation
@@ -72,10 +78,17 @@ func (s *Service) RecordConversationPage(ctx context.Context, accountID, myID st
// as the session nickname.
peerName := ""
custom := map[string]any{}
extension := mapValue(last["extension"])
if content, ok := last["content"].(map[string]any); ok {
custom, _ = content["custom"].(map[string]any)
}
summary := cleanNilString(custom["summary"])
if summary == "" {
summary = cleanNilString(extension["reminderContent"])
}
if summary == "" {
summary = cleanNilString(extension["detailNotice"])
}
if summary == "" {
if encoded := cleanNilString(custom["data"]); encoded != "" {
var decoded map[string]any
@@ -240,6 +253,14 @@ func (s *Service) RecordIncoming(ctx context.Context, in Incoming) (*db.ChatMess
BuyerName: in.BuyerName, BuyerAvatar: extractString(in.Raw, "avatar", "avatarUrl", "senderAvatar"),
ItemID: in.ItemID, ItemTitle: extractString(in.Raw, "itemTitle", "title")}
messageType, content := extractMessageContent(in.Raw, in.Text)
if isOfficialSystemMessage(in.Raw, in.BuyerID, in.Text) {
messageType = "system"
if strings.TrimSuffix(strings.TrimSpace(in.BuyerID), "@goofish") == "1400" {
in.BuyerName = "闲小蜜"
session.BuyerName = "闲小蜜"
session.BuyerAvatar = xianxiaomiAvatar
}
}
message := db.ChatMessage{MessageKey: key, Direction: "incoming", SenderID: in.BuyerID,
SenderName: in.BuyerName, MessageType: messageType, Content: content, Status: "received", SentAt: sentAt}
stored, inserted, err := s.store.Chats.SaveMessage(ctx, session, message, true)
@@ -260,7 +281,7 @@ func (s *Service) RecordHistoryPage(ctx context.Context, accountID, chatID, myID
continue
}
session.CookieID, session.ChatID = accountID, chatID
if message.Direction == "incoming" {
if message.Direction == "incoming" && message.MessageType != "system" {
if session.BuyerID == "" {
session.BuyerID = message.SenderID
}
@@ -269,6 +290,12 @@ func (s *Service) RecordHistoryPage(ctx context.Context, accountID, chatID, myID
if err != nil {
return page, err
}
if message.MessageType == "system" {
if err := s.store.Chats.UpdateMessageType(ctx, accountID, message.MessageKey, "system"); err != nil {
return page, err
}
stored.MessageType = "system"
}
page.Messages = append(page.Messages, *stored)
}
return page, nil
@@ -307,6 +334,12 @@ func parseHistoryMessage(accountID, chatID, myID string, model map[string]any) (
}
}
messageType, content := extractMessageContent(rawContent, fallback)
if isOfficialSystemMessage(rawContent, senderID, fallback) {
messageType = "system"
if senderID == "1400" {
senderName = "闲小蜜"
}
}
if content == "" {
content = "[系统消息]"
}
@@ -406,6 +439,54 @@ func extractMessageContent(raw map[string]any, fallback string) (string, string)
return "text", strings.TrimSpace(fallback)
}
// isOfficialSystemMessage recognizes platform-generated IM content using the
// protocol metadata, rather than matching a growing list of Chinese prompts.
// contentType=14 is a platform notice and contentType=26 is an official trade
// card. User 1400 is 闲小蜜, whose messages are also not peer chat.
func isOfficialSystemMessage(raw map[string]any, senderID, fallback string) bool {
if strings.TrimSuffix(strings.TrimSpace(senderID), "@goofish") == "1400" {
return true
}
if contentType := findOfficialContentType(raw); contentType == "14" || contentType == "26" {
return true
}
return strings.TrimSpace(fallback) == "发来一条新消息"
}
// findOfficialContentType walks decoded history content as well as live WS
// envelopes. History stores the inner content JSON under custom.data, while
// live messages expose it under 1.6.3 or 1.10.extJson.
func findOfficialContentType(value any) string {
var found string
var walk func(any)
walk = func(current any) {
if found != "" {
return
}
switch typed := current.(type) {
case string:
var nested any
if json.Unmarshal([]byte(typed), &nested) == nil {
walk(nested)
}
case map[string]any:
if candidate := strings.TrimSpace(fmt.Sprint(typed["contentType"])); candidate == "14" || candidate == "26" {
found = candidate
return
}
for _, child := range typed {
walk(child)
}
case []any:
for _, child := range typed {
walk(child)
}
}
}
walk(value)
return found
}
func (s *Service) CreateOutgoing(ctx context.Context, session db.ChatSession, text string) (*db.ChatMessage, error) {
return s.CreateOutgoingMedia(ctx, session, "text", strings.TrimSpace(text))
}
+76
View File
@@ -58,6 +58,54 @@ func TestRecordHistoryPageParsesDirectionMediaAndDeduplicates(t *testing.T) {
}
}
func TestRecordHistoryPageClassifiesOfficialCardsAsSystem(t *testing.T) {
store, cleanup := chatTestStore(t)
defer cleanup()
service := New(store)
encoded := base64.StdEncoding.EncodeToString([]byte(`{"contentType":26,"dxCard":{"item":{"main":{"exContent":{"title":"我已拍下,待付款"}}}}}`))
body := map[string]any{"userMessageModels": []any{
map[string]any{"message": map[string]any{
"messageId": "official-card", "createAt": float64(3000),
"extension": map[string]any{"senderUserId": "peer@goofish", "reminderTitle": "买家已拍下,待付款"},
"content": map[string]any{"custom": map[string]any{"data": encoded, "summary": "[我已拍下,待付款]"}},
}},
}}
session := db.ChatSession{CookieID: "account-1", ChatID: "official", BuyerID: "peer", BuyerName: "真实昵称"}
if _, _, err := store.Chats.SaveMessage(context.Background(), session, db.ChatMessage{
MessageKey: "official-card", Direction: "incoming", SenderID: "peer", SenderName: "真实昵称",
MessageType: "text", Content: "[我已拍下,待付款]", Status: "received", SentAt: 3000,
}, false); err != nil {
t.Fatal(err)
}
page, err := service.RecordHistoryPage(context.Background(), "account-1", "official", "self", session, body)
if err != nil {
t.Fatal(err)
}
if len(page.Messages) != 1 || page.Messages[0].MessageType != "system" || page.Messages[0].Direction != "incoming" {
t.Fatalf("official card was not classified as system: %+v", page.Messages)
}
if page.Messages[0].SenderName != "真实昵称" {
t.Fatalf("history sender metadata unexpectedly changed: %+v", page.Messages[0])
}
}
func TestRecordIncomingClassifiesXianxiaomiAndPlaceholder(t *testing.T) {
store, cleanup := chatTestStore(t)
defer cleanup()
service := New(store)
message, inserted, err := service.RecordIncoming(context.Background(), Incoming{
AccountID: "account-1", ChatID: "xiaomi", BuyerID: "1400@goofish",
BuyerName: "闲小蜜发来一条新消息", Text: "邀您填写售后问卷",
Raw: map[string]any{"messageId": "xiaomi-1"},
})
if err != nil || !inserted {
t.Fatalf("record xianxiaomi message: message=%+v inserted=%v err=%v", message, inserted, err)
}
if message.MessageType != "system" || message.SenderName != "闲小蜜" {
t.Fatalf("xianxiaomi message was not classified: %+v", message)
}
}
func TestRecordConversationPageImportsHistoricalContacts(t *testing.T) {
store, cleanup := chatTestStore(t)
defer cleanup()
@@ -124,6 +172,34 @@ func TestRecordConversationPageHandlesXianxiaomiAndRemovesInvisibleSessions(t *t
}
}
func TestRecordConversationPageSkipsEmptyConversationShells(t *testing.T) {
store, cleanup := chatTestStore(t)
defer cleanup()
service := New(store)
body := map[string]any{"userConvs": []any{
map[string]any{"singleChatUserConversation": map[string]any{
"singleChatConversation": map[string]any{"cid": "empty@goofish", "pairFirst": "self@goofish", "pairSecond": "69@goofish"},
}},
map[string]any{"singleChatUserConversation": map[string]any{
"singleChatConversation": map[string]any{"cid": "system@goofish", "pairFirst": "self@goofish", "pairSecond": "1400@goofish"},
"lastMessage": map[string]any{"message": map[string]any{
"createAt": float64(100), "reminderContent": "邀您填写售后问卷",
}},
}},
}}
if _, err := service.RecordConversationPage(context.Background(), "account-1", "self", body); err != nil {
t.Fatal(err)
}
owner, _ := store.Users.GetByUsername(context.Background(), "owner")
rows, err := store.Chats.ListSessions(context.Background(), owner.ID, "account-1", 20)
if err != nil {
t.Fatal(err)
}
if len(rows) != 1 || rows[0].ChatID != "system" {
t.Fatalf("empty conversation shell was imported: %+v", rows)
}
}
func TestDeleteEmptySessionsRemovesGhostsButKeepsRealConversation(t *testing.T) {
store, cleanup := chatTestStore(t)
defer cleanup()
+9
View File
@@ -110,6 +110,7 @@ func (s *ChatStore) LatestUnmaskedPeerName(ctx context.Context, cookieID, chatID
var name string
err := s.DB.QueryRowContext(ctx, `SELECT sender_name FROM chat_messages
WHERE cookie_id=? AND chat_id=? AND direction='incoming' AND sender_name<>'' AND sender_name NOT LIKE '%***%'
AND message_type<>'system'
AND sender_name<>content AND sender_name NOT IN ('交易消息','系统消息','卡片消息','我完成了评价','对方完成了评价',
'快给ta一个评价吧~','卖家已发货','买家已付款','买家已确认收货','等待您发货','超时未付款,系统关闭了订单','邀您填写售后问卷')
ORDER BY sent_at DESC,id DESC LIMIT 1`, cookieID, chatID).Scan(&name)
@@ -197,6 +198,14 @@ func (s *ChatStore) GetMessageByKey(ctx context.Context, cookieID, key string) (
return &m, err
}
// UpdateMessageType refreshes the classification of an already persisted
// message when a later history response exposes richer protocol metadata.
func (s *ChatStore) UpdateMessageType(ctx context.Context, cookieID, key, messageType string) error {
_, err := s.DB.ExecContext(ctx, `UPDATE chat_messages SET message_type=?
WHERE cookie_id=? AND message_key=?`, messageType, cookieID, key)
return err
}
func (s *ChatStore) ListSessions(ctx context.Context, userID int64, cookieID string, limit int) ([]ChatSession, error) {
if limit <= 0 || limit > 500 {
limit = 200
+6
View File
@@ -266,6 +266,12 @@ func extractChatMessage(decrypted map[string]any, accountID, cookieStr string) *
// - contentType=26:交易卡片,如“我已拍下,待付款”“我发起了退款申请”
// 付款待发货卡片已经在 handleMessage 前半段进入 automation.Center,这里不能再进入聊天回复链。
func isNonUserChatNotice(m1, m10 map[string]any, reminder string) bool {
if strings.TrimSuffix(strings.TrimSpace(toString(m10["senderUserId"])), "@goofish") == "1400" {
return true
}
if strings.TrimSpace(reminder) == "发来一条新消息" {
return true
}
if sessionType := strings.TrimSpace(toString(m10["sessionType"])); sessionType != "" && sessionType != "1" {
return true
}
+9
View File
@@ -287,6 +287,15 @@ func TestIsNonUserChatNotice(t *testing.T) {
}
}
func TestIsNonUserChatNoticeFiltersOfficialSenderAndPlaceholder(t *testing.T) {
if !isNonUserChatNotice(map[string]any{}, map[string]any{"senderUserId": "1400", "reminderContent": "邀您填写售后问卷"}, "邀您填写售后问卷") {
t.Error("闲小蜜消息应判为官方系统消息")
}
if !isNonUserChatNotice(map[string]any{}, map[string]any{"senderUserId": "peer-1"}, "发来一条新消息") {
t.Error("官方通知占位文本不应进入聊天回复")
}
}
// TestToStringAndTrimFloatInt 数字/字符串安全转换。
func TestToStringAndTrimFloatInt(t *testing.T) {
if got := toString(float64(26)); got != "26" {
@@ -0,0 +1 @@
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.container{width:100%}@media(min-width:640px){.container{max-width:640px}}@media(min-width:768px){.container{max-width:768px}}@media(min-width:1024px){.container{max-width:1024px}}@media(min-width:1280px){.container{max-wLine truncated
@@ -1 +0,0 @@
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.container{width:100%}@media(min-width:640px){.container{max-width:640px}}@media(min-width:768px){.container{max-width:768px}}@media(min-width:1024px){.container{max-width:1024px}}@media(min-width:1280px){.container{max-wLine truncated
@@ -1,10 +1,10 @@
import{j as e,r,b as Fe,c as aa,d as Ra}from"./react-vendor-C_od1ZSF.js";import{L as $a,U as la,M as ts,C as ss,B as ra,S as na,Z as as,a as yt,b as us,c as hs,d as gs,e as Pa,f as rt,A as ks,D as Da,g as Cs,P as ia,h as At,E as oa,T as Ea,i as Ta,j as Re,X as $e,k as Fa,l as Ma,m as bs,n as ca,o as He,Q as Qt,p as ot,q as Ke,r as ft,s as It,t as Ss,R as Be,u as da,v as qa,w as Qe,K as Ba,x as it,y as lt,z as tt,F as Ls,G as _t,H as jt,I as Ot,J as xa,N as za,O as Os,V as Is,W as Ua,Y as Wa,_ as Va,$ as Ja,a0 as Gt,a1 as Dt,a2 as ls,a3 as Qa,a4 as Ga,a5 as rs,a6 as Ka,a7 as Ha,a8 as ns,a9 as As,aa as zt,ab as ma,ac as Za,ad as Ya,ae as Wt,af as pa,ag as Xa,ah as el,ai as tl,aj as sl,ak as al,al as ll,am as rl}from"./icons-vendor-DjsKcZkz.js";import{R as Et,B as nl,X as Rs,Y as $s,T as Tt,a as il,C as Kt,A as ol,b as cl,c as dl,P as Ps,d as Ds,L as xl}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 x of document.querySelectorAll('link[rel="modulepreload"]'))i(x);new MutationObserver(x=>{for(const v of x)if(v.type==="childList")for(const S of v.addedNodes)S.tagName==="LINK"&&S.rel==="modulepreload"&&i(S)}).observe(document,{childList:!0,subtree:!0});function l(x){const v={};return x.integrity&&(v.integrity=x.integrity),x.referrerPolicy&&(v.referrerPolicy=x.referrerPolicy),x.crossOrigin==="use-credentials"?v.credentials="include":x.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function i(x){if(x.ep)return;x.ep=!0;const v=l(x);fetch(x.href,v)}})();const ml=({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"})})}),is=({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:"#0094f7"}),e.jsx("stop",{offset:"100%",stopColor:"#287efe"})]})}),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 10.34 L 31.54 8.78 L 36.33 7.56 L 41.8Line truncated
import{j as e,r,b as Fe,c as ra,d as Pa}from"./react-vendor-C_od1ZSF.js";import{L as Da,U as na,M as ts,C as ss,B as ia,S as oa,Z as as,a as yt,b as us,c as hs,d as gs,e as Ea,f as rt,A as ks,D as Ta,g as Cs,P as ca,h as At,E as da,T as Fa,i as Ma,j as Re,X as $e,k as qa,l as Ba,m as bs,n as xa,o as He,Q as Qt,p as ot,q as Ke,r as ft,s as It,t as Ss,R as Be,u as ma,v as za,w as Qe,K as Ua,x as it,y as lt,z as tt,F as Ls,G as _t,H as jt,I as Ot,J as pa,N as Wa,O as Os,V as Is,W as Va,Y as Ja,_ as Qa,$ as Ga,a0 as Gt,a1 as Dt,a2 as ls,a3 as Ka,a4 as Ha,a5 as rs,a6 as Za,a7 as Ya,a8 as ns,a9 as As,aa as zt,ab as ua,ac as Xa,ad as el,ae as Wt,af as ha,ag as tl,ah as sl,ai as al,aj as ll,ak as rl,al as nl,am as il}from"./icons-vendor-DjsKcZkz.js";import{R as Et,B as ol,X as Rs,Y as $s,T as Tt,a as cl,C as Kt,A as dl,b as xl,c as ml,P as Ps,d as Ds,L as pl}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 x of document.querySelectorAll('link[rel="modulepreload"]'))i(x);new MutationObserver(x=>{for(const v of x)if(v.type==="childList")for(const S of v.addedNodes)S.tagName==="LINK"&&S.rel==="modulepreload"&&i(S)}).observe(document,{childList:!0,subtree:!0});function l(x){const v={};return x.integrity&&(v.integrity=x.integrity),x.referrerPolicy&&(v.referrerPolicy=x.referrerPolicy),x.crossOrigin==="use-credentials"?v.credentials="include":x.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function i(x){if(x.ep)return;x.ep=!0;const v=l(x);fetch(x.href,v)}})();const ul=({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"})})}),is=({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:"#0094f7"}),e.jsx("stop",{offset:"100%",stopColor:"#287efe"})]})}),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 10.34 L 31.54 8.78 L 36.33 7.56 L 41.8Line 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(us,{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:Pt,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:R,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",disabled:R,children:[R?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(He,{className:"w-4 h-4"}),R?"保存中...":"保存"]})]})})]})}),document.body)]})},Qr=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)||"")})):[]}),Gr=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],Qs=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-[#0094f7] 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})},Kr=()=>{const[t,s]=r.useState([]),[l,i]=r.useState([]),[x,v]=r.useState([]),[S,$]=r.useState({}),[f,I]=r.useState("all"),[y,J]=r.useState(""),[H,me]=r.useState(""),[ne,N]=r.useState(""),M=r.useRef(0),[ie,G]=r.useState(1),[Z,W]=r.useState(1),[ge,ue]=r.useState(!1),[O,Q]=r.useState(!1),[ce,q]=r.useState(!1),[V,A]=r.useState(!1),[D,ae]=r.useState(null),[E,le]=r.useState(null),[Se,je]=r.useState({}),[pe,u]=r.useState(!1),[b,z]=r.useState(""),[w,Y]=r.useState(!1),[oe,he]=r.useState(null),[Ie,fe]=r.useState(null),[d,k]=r.useState(null),[p,c]=r.useState(!1),[_,R]=r.useState(null),[U,K]=r.useState(null),te=async()=>{const g=++M.current;ue(!0);try{const B=await zl(y||void 0,f,ie,20,ne);if(g!==M.current)return;s(B.data),W(B.total_pages)}catch(B){console.error("加载订单失败:",B)}finally{g===M.current&&ue(!1)}},Ne=(g,B,_e)=>{if(_e&&_e.trim())return _e;if(S[`${g}:${B}`])return S[`${g}:${B}`];const Oe=l.find(Ye=>{if(_e&&Ye.item_title){const st=_e.toLowerCase(),Xe=Ye.item_title.toLowerCase();return Xe.includes(st)||st.includes(Xe)}return!1});return Oe!=null&&Oe.item_title?Oe.item_title:"未知商品"},h=g=>{const B={};g.forEach(_e=>{_e.item_id&&(B[`${_e.cookie_id}:${_e.item_id}`]=_e.item_title||_e.item_id)}),$(B)};r.useEffect(()=>{const g=window.setTimeout(()=>{G(1),N(H.trim())},300);return()=>window.clearTimeout(g)},[H]),r.useEffect(()=>{te()},[y,f,ie,ne]),r.useEffect(()=>{Promise.all([Rt(),Nt()]).then(([g,B])=>{v(g),i(B),h(B)}).catch(g=>{console.error("加载商品列表失败:",g)})},[]);const C=r.useMemo(()=>new Map(x.map(g=>[g.id,g])),[x]),F=g=>{const B=C.get(g),_e=(B==null?void 0:B.remark)||(B==null?void 0:B.nickname);return _e?`${_e} · ${g.slice(0,6)}`:`账号 ${g.slice(0,8)}`},T=g=>{const B=C.get(g);return(B==null?void 0:B.remark)||(B==null?void 0:B.nickname)||"未命名账号"},ve=async()=>{ue(!0);try{const g=await Vl(y||void 0,f);await te(),g!=null&&g.message&&alert(g.message)}catch(g){console.error("同步订单失败:",g),alert((g==null?void 0:g.message)||"同步失败,请重试")}finally{ue(!1)}},Ee=g=>{z(g),he(null),u(!0)},we=async g=>{var B;Y(!0),he(null);try{const _e=await Ql([b],g),Oe=(B=_e==null?void 0:_e.results)==null?void 0:B[0];Oe!=null&&Oe.success?(he({success:!0,message:Oe.message}),te()):he({success:!1,message:(Oe==null?void 0:Oe.message)||"发货失败"})}catch(_e){he({success:!1,message:(_e==null?void 0:_e.message)||"请求失败"})}finally{Y(!1)}},Pe=g=>{ae(g),Q(!0)},de=g=>{le({...g}),q(!0)},Te=async()=>{if(!(!E||!E.order_id))try{const g={};E.status!==void 0&&(g.order_status=E.status),E.buyer_id!==void 0&&(g.buyer_id=E.buyer_id),E.amount!==void 0&&(g.amount=E.amount),E.receiver_name!==void 0&&(g.receiver_name=E.receiver_name),E.receiver_phon 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(us,{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:Pt,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:R,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",disabled:R,children:[R?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(He,{className:"w-4 h-4"}),R?"保存中...":"保存"]})]})})]})}),document.body)]})},Kr=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)||"")})):[]}),Hr=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],Qs=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-[#0094f7] 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})},Zr=()=>{const[t,s]=r.useState([]),[l,i]=r.useState([]),[x,v]=r.useState([]),[S,$]=r.useState({}),[f,I]=r.useState("all"),[y,J]=r.useState(""),[H,me]=r.useState(""),[ne,N]=r.useState(""),M=r.useRef(0),[ie,G]=r.useState(1),[Z,W]=r.useState(1),[ge,ue]=r.useState(!1),[O,Q]=r.useState(!1),[ce,q]=r.useState(!1),[V,A]=r.useState(!1),[D,ae]=r.useState(null),[E,le]=r.useState(null),[Se,je]=r.useState({}),[pe,h]=r.useState(!1),[b,z]=r.useState(""),[w,Y]=r.useState(!1),[oe,he]=r.useState(null),[Ie,fe]=r.useState(null),[d,k]=r.useState(null),[p,c]=r.useState(!1),[_,R]=r.useState(null),[U,K]=r.useState(null),te=async()=>{const g=++M.current;ue(!0);try{const B=await Wl(y||void 0,f,ie,20,ne);if(g!==M.current)return;s(B.data),W(B.total_pages)}catch(B){console.error("加载订单失败:",B)}finally{g===M.current&&ue(!1)}},Ne=(g,B,_e)=>{if(_e&&_e.trim())return _e;if(S[`${g}:${B}`])return S[`${g}:${B}`];const Oe=l.find(Ye=>{if(_e&&Ye.item_title){const st=_e.toLowerCase(),Xe=Ye.item_title.toLowerCase();return Xe.includes(st)||st.includes(Xe)}return!1});return Oe!=null&&Oe.item_title?Oe.item_title:"未知商品"},u=g=>{const B={};g.forEach(_e=>{_e.item_id&&(B[`${_e.cookie_id}:${_e.item_id}`]=_e.item_title||_e.item_id)}),$(B)};r.useEffect(()=>{const g=window.setTimeout(()=>{G(1),N(H.trim())},300);return()=>window.clearTimeout(g)},[H]),r.useEffect(()=>{te()},[y,f,ie,ne]),r.useEffect(()=>{Promise.all([Rt(),Nt()]).then(([g,B])=>{v(g),i(B),u(B)}).catch(g=>{console.error("加载商品列表失败:",g)})},[]);const C=r.useMemo(()=>new Map(x.map(g=>[g.id,g])),[x]),T=g=>{const B=C.get(g),_e=(B==null?void 0:B.remark)||(B==null?void 0:B.nickname);return _e?`${_e} · ${g.slice(0,6)}`:`账号 ${g.slice(0,8)}`},F=g=>{const B=C.get(g);return(B==null?void 0:B.remark)||(B==null?void 0:B.nickname)||"未命名账号"},ve=async()=>{ue(!0);try{const g=await Ql(y||void 0,f);await te(),g!=null&&g.message&&alert(g.message)}catch(g){console.error("同步订单失败:",g),alert((g==null?void 0:g.message)||"同步失败,请重试")}finally{ue(!1)}},Ee=g=>{z(g),he(null),h(!0)},we=async g=>{var B;Y(!0),he(null);try{const _e=await Kl([b],g),Oe=(B=_e==null?void 0:_e.results)==null?void 0:B[0];Oe!=null&&Oe.success?(he({success:!0,message:Oe.message}),te()):he({success:!1,message:(Oe==null?void 0:Oe.message)||"发货失败"})}catch(_e){he({success:!1,message:(_e==null?void 0:_e.message)||"请求失败"})}finally{Y(!1)}},Pe=g=>{ae(g),Q(!0)},de=g=>{le({...g}),q(!0)},Te=async()=>{if(!(!E||!E.order_id))try{const g={};E.status!==void 0&&(g.order_status=E.status),E.buyer_id!==void 0&&(g.buyer_id=E.buyer_id),E.amount!==void 0&&(g.amount=E.amount),E.receiver_name!==void 0&&(g.receiver_name=E.receiver_name),E.receiver_phon Line truncated
VIP-MONTH-002
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(U=>U.map(K=>`"${String(K).replace(/"/g,'""')}"`).join(",")).join(`
`),c=new Blob(["\uFEFF"+p],{type:"text/csv;charset=utf-8"}),_=URL.createObjectURL(c),R=document.createElement("a");R.href=_,R.download="卡密组批量导入模板.csv",document.body.appendChild(R),R.click(),R.remove(),URL.revokeObjectURL(_)},he=async()=>{if(M){ge(!0),Z(null);try{const d=await er(M);if(Z(d),d.created>0){const k=await et();s(k)}}catch(d){Z({error:(d==null?void 0:d.message)||"上传失败"})}finally{ge(!1)}}},Ie=async()=>{if(!(!ue||!Q.trim())){ge(!0),V(null);try{const d=await tr(ue,Q);V({added:d.added}),ce("");const k=await et();s(k)}catch(d){alert("追加失败:"+((d==null?void 0:d.message)||"未知错误"))}finally{ge(!1)}}},fe=()=>{var d;N("create"),ie(null),Z(null),O((d=w[0])!=null&&d.id?String(w[0].id):""),ce(""),V(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: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(Ot,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>v(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(tt,{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-[#FAFAFA] 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(xa,{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:A,onChange:d=>D(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(_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:ae,onChange:d=>E(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",Y.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:Y.map(d=>{let k="";return d.type==="data"&&d.data_content?k=`库存: ${d.data_content.split(`
`).filter(c=>c.trim()).length} 条`:d.type==="text"&&d.text_content?k=d.text_content:d.type==="api"&&d.api_config?k=d.api_config.url:d.type==="image"&&d.image_url&&(k="图片链接"),e.jsxs("tr",{className:"hover:bg-[#FFFDE7]/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(le,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>z(d.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(za,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${d.type==="text"?"bg-blue-50 text-blue-600":d.type==="data"?"bg-purple-50 text-purple-600":d.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:d.type==="text"?"文本":d.type==="data"?"批量":d.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:k,children:k})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:d.description||"-",children:d.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>b(d),className:`w-12 h-8 rounded-full relative transition-colors ${d.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${d.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>Se(d),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(d.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Qe,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),Y.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ia,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),l&&S&&Fe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>i(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx($e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:f.name||"",onChange:d=>I({...f,name:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:f.type||"text",onChange:d=>I({...f,type:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(S==null?void 0:S.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),f.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:f.api_url||"",onChange:d=>I({...f,api_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxLine truncated
`),c=new Blob(["\uFEFF"+p],{type:"text/csv;charset=utf-8"}),_=URL.createObjectURL(c),R=document.createElement("a");R.href=_,R.download="卡密组批量导入模板.csv",document.body.appendChild(R),R.click(),R.remove(),URL.revokeObjectURL(_)},he=async()=>{if(M){ge(!0),Z(null);try{const d=await sr(M);if(Z(d),d.created>0){const k=await et();s(k)}}catch(d){Z({error:(d==null?void 0:d.message)||"上传失败"})}finally{ge(!1)}}},Ie=async()=>{if(!(!ue||!Q.trim())){ge(!0),V(null);try{const d=await ar(ue,Q);V({added:d.added}),ce("");const k=await et();s(k)}catch(d){alert("追加失败:"+((d==null?void 0:d.message)||"未知错误"))}finally{ge(!1)}}},fe=()=>{var d;N("create"),ie(null),Z(null),O((d=w[0])!=null&&d.id?String(w[0].id):""),ce(""),V(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: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(Ot,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>v(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(tt,{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-[#FAFAFA] 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(pa,{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:A,onChange:d=>D(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(_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:ae,onChange:d=>E(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",Y.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:Y.map(d=>{let k="";return d.type==="data"&&d.data_content?k=`库存: ${d.data_content.split(`
`).filter(c=>c.trim()).length} 条`:d.type==="text"&&d.text_content?k=d.text_content:d.type==="api"&&d.api_config?k=d.api_config.url:d.type==="image"&&d.image_url&&(k="图片链接"),e.jsxs("tr",{className:"hover:bg-[#FFFDE7]/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(le,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>z(d.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(Wa,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${d.type==="text"?"bg-blue-50 text-blue-600":d.type==="data"?"bg-purple-50 text-purple-600":d.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:d.type==="text"?"文本":d.type==="data"?"批量":d.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:k,children:k})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:d.description||"-",children:d.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>b(d),className:`w-12 h-8 rounded-full relative transition-colors ${d.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${d.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>Se(d),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(d.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Qe,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),Y.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ca,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),l&&S&&Fe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>i(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx($e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:f.name||"",onChange:d=>I({...f,name:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:f.type||"text",onChange:d=>I({...f,type:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(S==null?void 0:S.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),f.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:f.api_url||"",onChange:d=>I({...f,api_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxLine truncated
卡号1:密码1
卡号2:密码2
或者
@@ -13,7 +13,7 @@ VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),f.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:f.image_url||"",onChange:d=>I({...f,image_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),f.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:f.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:d=>{d.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:f.delay_seconds||0,onChange:d=>I({...f,delay_seconds:parseInt(d.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:f.description||"",onChange:d=>I({...f,description:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>I({...f,enabled:!f.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${f.enabled?"bg-[#0094f7]":"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 ${f.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(He,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),x&&Fe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>v(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx($e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:y.name,onChange:d=>J({...y,name:d.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>J({...y,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${y.type==="data"?"bg-[#0094f7] text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(ss,{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-[#0094f7] text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Os,{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-[#0094f7] text-white":"bg-gray-100 text-grayLine truncated
CODE-789012
...`:"请输入每次发货时发送的固定文字"}),y.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-[#0094f7]",children:y.content.split(`
`).filter(d=>d.trim()).length})," 条"]})]}),y.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:y.api_method,onChange:d=>J({...y,api_method:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:y.api_timeout,onChange:d=>J({...y,api_timeout:parseInt(d.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:y.api_headers,onChange:d=>J({...y,api_headers:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:y.api_params,onChange:d=>J({...y,api_params:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:y.description,onChange:d=>J({...y,description:d.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:y.delay_seconds,onChange:d=>J({...y,delay_seconds:parseInt(d.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>v(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick: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(tt,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),H&&Fe.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($e,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>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 ${ne==="create"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Ua,{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 ${ne==="append"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Ot,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),ne==="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:oe,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 Line truncated
`).filter(d=>d.trim()).length})," 条"]})]}),y.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:y.api_method,onChange:d=>J({...y,api_method:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:y.api_timeout,onChange:d=>J({...y,api_timeout:parseInt(d.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:y.api_headers,onChange:d=>J({...y,api_headers:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:y.api_params,onChange:d=>J({...y,api_params:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:y.description,onChange:d=>J({...y,description:d.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:y.delay_seconds,onChange:d=>J({...y,delay_seconds:parseInt(d.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>v(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:h,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(tt,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),H&&Fe.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($e,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>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 ${ne==="create"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Va,{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 ${ne==="append"?"bg-[#0094f7] text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Ot,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),ne==="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:oe,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 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:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),q&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",q.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:"关闭"}),ne==="create"?e.jsxs("button",{onClick:he,disabled:!M||W,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[W?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Ot,{className:"w-4 h-4"}),W?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:Ie,disabled:!ue||!Q.trim()||W||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:[W?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(tt,{className:"w-4 h-4"}),W?"处理中...":"追加卡密"]})]})]})}),document.body)]})},Yr=t=>t.find(s=>s.status==="running"||s.status==="canceling"),Xr=t=>{const s=String(t||"").trim();return s?/^[¥¥]/.test(s)?s:`¥${s}`:"-"},en=({onConfigureDelivery:t})=>{const[s,l]=r.useState([]),[i,x]=r.useState([]),[v,S]=r.useState([]),[$,f]=r.useState(""),[I,y]=r.useState(""),[J,H]=r.useState(!1),[me,ne]=r.useState(!1),[N,M]=r.useState(!1),[ie,G]=r.useState(!1),[Z,W]=r.useState(!1),[ge,ue]=r.useState(!1),[O,Q]=r.useState(!1),[ce,q]=r.useState("upload"),[V,A]=r.useState(null),[D,ae]=r.useState(null),[E,le]=r.useState(""),[Se,je]=r.useState(!1),[pe,u]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[b,z]=r.useState(null),[w,Y]=r.useState(null),[oe,he]=r.useState(null),Ie=r.useRef(!1),[fe,d]=r.useState(null),[k,p]=r.useState({}),[c,_]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[R,U]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[K,te]=r.useState([]);r.useEffect(()=>{if(!ge||R.images.length===0){te([]);return}const n=R.images.map((L,re)=>({key:L.name+re,url:URL.createObjectURL(L)}));return te(n),()=>{n.forEach(L=>URL.revokeObjectURL(L.url))}},[ge,R.images]);const Ne=async()=>{const n=await Nt();l(n)},h=async()=>{x(await xs())};r.useEffect(()=>{Promise.all([Rt(),Nt(),xs(),Bs(20)]).then(([n,L,re,Ve])=>{S(n),l(L),x(re);const Je=Ve.find(qe=>["running","canceling"].includes(qe.status))||Ve.find(qe=>qe.status!=="preview");he(Je||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(!Ie.current){Ie.current=!0;try{const L=await gt(w.id);Y(L),he(L),["running","canceling"].includes(L.status)||(q("done"),await Ne(),await h())}catch(L){console.error("刷新批量铺货进度失败:",L)}finally{Ie.current=!1}}},3e3);return()=>{window.clearInterval(n)}},[O,w==null?void 0:w.id,w==null?void 0:w.status]);const C=async()=>{if(!$)return alert("请先选择账号");H(!0);try{const n=await sr($);await Ne(),alert((n==null?void 0:n.message)||"商品同步完成")}catch(n){console.error("同步商品失败:",n),alert((n==null?void 0:n.message)||"同步失败,请重试")}finally{H(!1)}},F=n=>{d(n),p({...n}),G(!0)},T=async()=>{if(fe)try{await mr(fe.cookie_id,fe.item_id,{item_title:k.item_title||"",item_description:k.item_description||"",item_category:k.item_category||"",item_price:k.item_price||"",item_detail:k.item_detail||fe.item_detail||""}),await Ne(),await h(),G(!1),d(null)}catch(n){console.error("更新商品失败:",n),alert("更新失败,请重试")}},ve=async n=>{if(confirm(`确认删除商品"${n.item_title}"吗?`))try{await ar(n.cookie_id,n.item_id),l(L=>L.filter(re=>!(re.cookie_id===n.cookie_id&&re.item_id===n.item_id)))}catch(L){console.error("删除商品失败:",L),alert("删除失败,请重试")}},Ee=async()=>{try{if(!c.cookie_id||!c.item_id){alert("请选择账号并填写商品ID");return}await lr(c.cookie_id,{item_id:c.item_id,item_title:c.item_title,item_price:c.item_price,item_detail:c.item_image?JSON.stringify({item_image:c.item_image}):""}),await Ne(),W(!1),_({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(n){console.error("添加商品失败:",n),alert("添加失败,请重试")}},we=async()=>{if(!R.cookie_id)return alert("请选择发布账号");if(!R.title.trim())return alert("请填写商品标题");if(!R.price.trim())return alert("请填写商品价格");if(!R.quantity||Number(R.quantity)<=0)return alert("库存数量必须大于 0");if(R.images.length===0)return alert("至少上传 1 张商品图片");if(R.postage_mode==="fixe Line truncated
`),Ve=new Blob(["\uFEFF"+re],{type:"text/csv;charset=utf-8"}),Je=URL.createObjectURL(Ve),qe=document.createElement("a");qe.href=Je,qe.download="批量铺货模板.csv",document.body.appendChild(qe),qe.click(),qe.remove(),URL.revokeObjectURL(Je)},Oe=()=>{_(n=>({...n,cookie_id:$||n.cookie_id})),W(!0)},Ye=()=>{U(n=>({...n,cookie_id:$||n.cookie_id})),ue(!0)},st=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),Xe=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||"-"}},ze=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"}},We=r.useMemo(()=>new Map(v.map(n=>[n.id,n])),[v]),ct=r.useMemo(()=>I?s.filter(n=>n.cookie_id===I):s,[I,s]),Ge=n=>{const L=We.get(n),re=(L==null?void 0:L.remark)||(L==null?void 0:L.nickname);return re?`${re} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},dt=n=>{const L=We.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(Ja,{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:I,onChange:n=>y(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ge(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(ot,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:$,onChange:n=>f(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:C,disabled:J||!$,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(Be,{className:`w-4 h-4 ${J?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Oe,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(tt,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:Ye,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-600 text-white hover:bg-emerald-700 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Gt,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Pe(),className:"px-5 py-3 rounded-2xl font-bold bg-blue-600 text-white hover:bg-blue-700 transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Dt,{className:"w-4 h-4"}),oe&&["running","canceling"].includes(oe.status)?"继续批量任务":"批量铺货"]}),oe&&!["running","canceling"].includes(oe.status)&&e.jsx("button",{onClick:()=>void Te(),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:[ct.map(n=>{const L=st(n),re=L.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group r Line truncated
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:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),q&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",q.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:"关闭"}),ne==="create"?e.jsxs("button",{onClick:he,disabled:!M||W,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[W?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Ot,{className:"w-4 h-4"}),W?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:Ie,disabled:!ue||!Q.trim()||W||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:[W?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(tt,{className:"w-4 h-4"}),W?"处理中...":"追加卡密"]})]})]})}),document.body)]})},en=t=>t.find(s=>s.status==="running"||s.status==="canceling"),tn=t=>{const s=String(t||"").trim();return s?/^[¥¥]/.test(s)?s:`¥${s}`:"-"},sn=({onConfigureDelivery:t})=>{const[s,l]=r.useState([]),[i,x]=r.useState([]),[v,S]=r.useState([]),[$,f]=r.useState(""),[I,y]=r.useState(""),[J,H]=r.useState(!1),[me,ne]=r.useState(!1),[N,M]=r.useState(!1),[ie,G]=r.useState(!1),[Z,W]=r.useState(!1),[ge,ue]=r.useState(!1),[O,Q]=r.useState(!1),[ce,q]=r.useState("upload"),[V,A]=r.useState(null),[D,ae]=r.useState(null),[E,le]=r.useState(""),[Se,je]=r.useState(!1),[pe,h]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[b,z]=r.useState(null),[w,Y]=r.useState(null),[oe,he]=r.useState(null),Ie=r.useRef(!1),[fe,d]=r.useState(null),[k,p]=r.useState({}),[c,_]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[R,U]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[K,te]=r.useState([]);r.useEffect(()=>{if(!ge||R.images.length===0){te([]);return}const n=R.images.map((L,re)=>({key:L.name+re,url:URL.createObjectURL(L)}));return te(n),()=>{n.forEach(L=>URL.revokeObjectURL(L.url))}},[ge,R.images]);const Ne=async()=>{const n=await Nt();l(n)},u=async()=>{x(await xs())};r.useEffect(()=>{Promise.all([Rt(),Nt(),xs(),Bs(20)]).then(([n,L,re,Ve])=>{S(n),l(L),x(re);const Je=Ve.find(qe=>["running","canceling"].includes(qe.status))||Ve.find(qe=>qe.status!=="preview");he(Je||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(!Ie.current){Ie.current=!0;try{const L=await gt(w.id);Y(L),he(L),["running","canceling"].includes(L.status)||(q("done"),await Ne(),await u())}catch(L){console.error("刷新批量铺货进度失败:",L)}finally{Ie.current=!1}}},3e3);return()=>{window.clearInterval(n)}},[O,w==null?void 0:w.id,w==null?void 0:w.status]);const C=async()=>{if(!$)return alert("请先选择账号");H(!0);try{const n=await lr($);await Ne(),alert((n==null?void 0:n.message)||"商品同步完成")}catch(n){console.error("同步商品失败:",n),alert((n==null?void 0:n.message)||"同步失败,请重试")}finally{H(!1)}},T=n=>{d(n),p({...n}),G(!0)},F=async()=>{if(fe)try{await ur(fe.cookie_id,fe.item_id,{item_title:k.item_title||"",item_description:k.item_description||"",item_category:k.item_category||"",item_price:k.item_price||"",item_detail:k.item_detail||fe.item_detail||""}),await Ne(),await u(),G(!1),d(null)}catch(n){console.error("更新商品失败:",n),alert("更新失败,请重试")}},ve=async n=>{if(confirm(`确认删除商品"${n.item_title}"吗?`))try{await rr(n.cookie_id,n.item_id),l(L=>L.filter(re=>!(re.cookie_id===n.cookie_id&&re.item_id===n.item_id)))}catch(L){console.error("删除商品失败:",L),alert("删除失败,请重试")}},Ee=async()=>{try{if(!c.cookie_id||!c.item_id){alert("请选择账号并填写商品ID");return}await nr(c.cookie_id,{item_id:c.item_id,item_title:c.item_title,item_price:c.item_price,item_detail:c.item_image?JSON.stringify({item_image:c.item_image}):""}),await Ne(),W(!1),_({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""})}catch(n){console.error("添加商品失败:",n),alert("添加失败,请重试")}},we=async()=>{if(!R.cookie_id)return alert("请选择发布账号");if(!R.title.trim())return alert("请填写商品标题");if(!R.price.trim())return alert("请填写商品价格");if(!R.quantity||Number(R.quantity)<=0)return alert("库存数量必须大于 0");if(R.images.length===0)return alert("至少上传 1 张商品图片");if(R.postage_mode==="fixe Line truncated
`),Ve=new Blob(["\uFEFF"+re],{type:"text/csv;charset=utf-8"}),Je=URL.createObjectURL(Ve),qe=document.createElement("a");qe.href=Je,qe.download="批量铺货模板.csv",document.body.appendChild(qe),qe.click(),qe.remove(),URL.revokeObjectURL(Je)},Oe=()=>{_(n=>({...n,cookie_id:$||n.cookie_id})),W(!0)},Ye=()=>{U(n=>({...n,cookie_id:$||n.cookie_id})),ue(!0)},st=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),Xe=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||"-"}},ze=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"}},We=r.useMemo(()=>new Map(v.map(n=>[n.id,n])),[v]),ct=r.useMemo(()=>I?s.filter(n=>n.cookie_id===I):s,[I,s]),Ge=n=>{const L=We.get(n),re=(L==null?void 0:L.remark)||(L==null?void 0:L.nickname);return re?`${re} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},dt=n=>{const L=We.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(Ga,{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:I,onChange:n=>y(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ge(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(ot,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:$,onChange:n=>f(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),v.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:C,disabled:J||!$,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(Be,{className:`w-4 h-4 ${J?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Oe,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(tt,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:Ye,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-600 text-white hover:bg-emerald-700 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Gt,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Pe(),className:"px-5 py-3 rounded-2xl font-bold bg-blue-600 text-white hover:bg-blue-700 transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Dt,{className:"w-4 h-4"}),oe&&["running","canceling"].includes(oe.status)?"继续批量任务":"批量铺货"]}),oe&&!["running","canceling"].includes(oe.status)&&e.jsx("button",{onClick:()=>void Te(),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:[ct.map(n=>{const L=st(n),re=L.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group r Line truncated
+2 -2
View File
@@ -6,12 +6,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ydisks闲鱼助手 - 自动发货与管家系统</title>
<meta name="description" content="Ydisks闲鱼助手 - 自动回复、自动发货、订单管理、AI智能议价一体化解决方案" />
<script type="module" crossorigin src="/static/assets/index-BIyp4is6.js"></script>
<script type="module" crossorigin src="/static/assets/index-XoQGZsB5.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">
<link rel="modulepreload" crossorigin href="/static/assets/charts-vendor-BxxJOyEX.js">
<link rel="stylesheet" crossorigin href="/static/assets/index-DtBcYu3b.css">
<link rel="stylesheet" crossorigin href="/static/assets/index-DPhnB9W9.css">
</head>
<body>
<div id="root"></div>