阶段七:完成ItemList React feature化与批量发布边界

This commit is contained in:
Christ committed 2026-08-15 00:02:23 +08:00
1 parent e79d76dcdf
commit c7c7023ad4
15 files changed
+1356 -1443

No files matched your search

File diff suppressed because it is too large. Load diff
+3 -1
View File
@@ -170,7 +170,8 @@ app shell / routes
- 已完成阶段 6 第七个 PR 切片“Automation 发货、卡密与通知动作边界”:新增 `automationActionExecutor` 与 `deliveryNotifier`,统一确认发货、Cookie/Jar 合并、卡券锁与库存消费、消息错误三态分类和结果通知;`Center` 保留兼容入口,凭证锁、卡券库存、恢复唤醒和通知文案语义保持不变;新增动作执行器回归测试,Automation 测试、注释和 diff 门禁通过,整批修改合并为一个可回滚提交;
- 已完成阶段 6 第八个 PR 切片“Automation 账号任务与凭证门禁边界”:新增 `accountTaskCoordinator`,统一账号状态门禁、自动评价/商品擦亮调度、任务租约、Session 指纹阻断、凭证恢复和 Cookie 同步;`Center` 保留公开任务入口,Session 失效恢复、任务幂等、失败重试和账号暂停语义保持不变;Automation 测试、注释和 diff 门禁通过,整批修改合并为一个可回滚提交;阶段 6 完成;
- 已完成阶段 7 第一个 PR 切片“React Rules feature 化与 API/行为测试边界”:按 `app/features/rules` 提取 Rules API 适配层、领域类型、数据 Hook、异常面板和交互状态模型;规则页通过 Hook 管理服务端数据与请求代次,保留旧组件入口和现有 API 路径;行为测试覆盖成功、失败、重复提交、过期响应和页签切换;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
- 阶段 7 下一 PR 切片为“React ItemList feature 化与批量发布行为边界”:按同一 feature 结构提取商品 API、批量发布 Hook 和页面组件,补充批量预检、取消、失败重试与过期任务行为测试;
- 已完成阶段 7 第二个 PR 切片“React ItemList feature 化与批量发布行为边界”:按 `app/features/items` 提取商品/批量 API 适配层、批量任务类型、批量 Hook 和阶段指示器组件;批量预检、任务恢复、轮询取消、失败重试和过期响应均由 feature 状态边界负责;行为测试覆盖预检门禁、取消状态、失败重试、历史任务筛选和过期轮询响应;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
- 阶段 7 下一 PR 切片为“React AccountList feature 化与账号运行状态行为边界”:提取账号 API、运行状态 Hook 和账号编辑组件,补充账号切换、暂停/恢复、凭证失败和过期状态响应测试;
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
## 6. 阶段 0:治理文档与强约束
@@ -590,3 +591,4 @@ npm --prefix frontend run build
| 2026-08-14 | 完成阶段 6 第七个 PR 切片“Automation 发货、卡密与通知动作边界” | 新增 `automationActionExecutor` 与 `deliveryNotifier`,统一确认发货、Cookie/Jar 合并、卡券锁与库存消费、消息错误三态分类和结果通知;`Center` 保留兼容入口,凭证锁、卡券库存、恢复唤醒和通知文案语义保持不变;新增动作执行器回归测试;Automation 测试、注释和 diff 门禁通过并合并为一个可回滚提交 | 阶段 6:Automation 账号任务与凭证门禁边界 |
| 2026-08-14 | 完成阶段 6 第八个 PR 切片“Automation 账号任务与凭证门禁边界” | 新增 `accountTaskCoordinator`,统一账号状态门禁、自动评价/商品擦亮调度、任务租约、Session 指纹阻断、凭证恢复和 Cookie 同步;`Center` 保留公开任务入口,Session 失效恢复、任务幂等、失败重试和账号暂停语义保持不变;Automation 测试、注释和 diff 门禁通过并合并为一个可回滚提交 | 阶段 7:React Rules feature 化与 API/行为测试边界 |
| 2026-08-14 | 完成阶段 7 第一个 PR 切片“React Rules feature 化与 API/行为测试边界” | 新增 `app/features/rules` 的 API 适配层、领域类型、数据 Hook、异常面板和交互状态模型;规则请求支持并行加载与请求代次门禁,保存动作阻断重复提交;行为测试覆盖成功、失败、重复提交、过期响应和页签切换;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React ItemList feature 化与批量发布行为边界 |
| 2026-08-14 | 完成阶段 7 第二个 PR 切片“React ItemList feature 化与批量发布行为边界” | 新增 `app/features/items` 的 API 适配层、批量任务类型、批量 Hook、批量状态模型和阶段指示器组件;批量预检、任务恢复、轮询过期响应、安全取消和失败重试均有独立状态边界;行为测试覆盖预检门禁、取消状态、失败重试、历史任务筛选和过期轮询响应;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React AccountList feature 化与账号运行状态行为边界 |
+21
View File
@@ -0,0 +1,21 @@
// ItemList feature 通过本适配层访问商品、批量任务和发货地 API。
export {
getItems,
getAccountDetails,
syncItemsFromAccount,
createItem,
publishItem,
recommendPublishCategory,
previewItemPublishBatch,
startItemPublishBatch,
getItemPublishBatch,
getItemPublishBatches,
deleteItemPublishBatch,
cancelItemPublishBatch,
retryFailedItemPublishBatch,
updateItem,
deleteItem,
getShippingRules,
} from '../../../services/api';
export type { PublishLocation } from '../../../services/api';
export { getPublishLocations } from '../../../services/amapLocation';
@@ -0,0 +1,58 @@
import { describe, expect, test } from 'vitest';
import {
batchStatusText,
canRetryBatch,
canStartBatch,
isBatchInProgress,
isCurrentBatchRequest,
selectActivePublishBatch,
} from './batchState';
// ItemList 批量行为测试覆盖预检、取消、重试和过期任务响应。
describe('ItemList batch state',
// 测试组回调集中验证批量状态机的关键分支。
() => {
// 预检通过且存在有效行时才能启动批量任务。
test('starts only when the preview has publishable rows',
// 预检成功场景回调验证有效行门禁。
() => {
expect(canStartBatch({ preview_id: 'preview-1', valid: 2 })).toBe(true);
expect(canStartBatch({ preview_id: 'preview-1', valid: 0 })).toBe(false);
expect(canStartBatch(null)).toBe(false);
});
// 运行中和安全取消中的任务都必须继续轮询远端结果。
test('keeps polling running and canceling tasks',
// 轮询场景回调验证运行和取消中的任务状态。
() => {
expect(isBatchInProgress('running')).toBe(true);
expect(isBatchInProgress('canceling')).toBe(true);
expect(isBatchInProgress('completed')).toBe(false);
expect(batchStatusText('canceling')).toBe('正在安全取消');
});
// 只有非运行状态下仍有失败行的批次允许重试。
test('allows retry only for retryable completed failures',
// 重试场景回调验证失败行和状态门禁。
() => {
expect(canRetryBatch({ id: 'batch-1', retryable: 2, status: 'failed' })).toBe(true);
expect(canRetryBatch({ id: 'batch-1', retryable: 2, status: 'running' })).toBe(false);
expect(canRetryBatch({ id: 'batch-1', retryable: 0, status: 'failed' })).toBe(false);
});
// 新任务代次产生后,旧轮询响应必须被视为过期并丢弃。
test('rejects an expired polling response',
// 过期响应场景回调验证轮询代次门禁。
() => {
expect(isCurrentBatchRequest(1, 2)).toBe(false);
expect(isCurrentBatchRequest(2, 2)).toBe(true);
});
// 已完成历史不能覆盖新任务上传流程,运行任务仍可恢复。
test('selects only an active recoverable batch',
// 恢复场景回调验证完成历史不会覆盖新流程。
() => {
expect(selectActivePublishBatch([{ id: 'done', status: 'completed' }])).toBeUndefined();
expect(selectActivePublishBatch([{ id: 'done', status: 'completed' }, { id: 'active', status: 'running' }])?.id).toBe('active');
});
});
+81
View File
@@ -0,0 +1,81 @@
// PublishBatchSummary 是选择最近批量任务时所需的最小状态模型。
export interface PublishBatchSummary {
// id 是批量任务标识。
id?: string;
// status 是批量任务状态。
status?: string;
}
// selectActivePublishBatch 只选择仍可继续处理的运行中任务。
export const selectActivePublishBatch = <T extends PublishBatchSummary>(batches: T[]): T | undefined =>
batches.find(
// 活跃任务筛选器排除已完成历史,避免覆盖新的上传流程。
batch => batch.status === 'running' || batch.status === 'canceling',
);
// isBatchInProgress 判断批量任务是否仍需要继续轮询。
export const isBatchInProgress = (status?: string): boolean => status === 'running' || status === 'canceling';
// BatchPreviewGate 是判断预检是否可以启动任务的最小模型。
export interface BatchPreviewGate {
// preview_id 是预检任务标识。
preview_id?: string;
// valid 是可发布行数。
valid?: number;
}
// canStartBatch 判断预检结果是否包含可发布商品。
export const canStartBatch = (preview?: BatchPreviewGate | null): boolean =>
Boolean(preview?.preview_id && Number(preview.valid || 0) > 0);
// BatchRetryGate 是判断批量任务是否可重试的最小模型。
export interface BatchRetryGate {
// id 是批量任务标识。
id?: string;
// retryable 是可重试失败行数。
retryable?: number;
// status 是批量任务状态。
status?: string;
}
// canRetryBatch 判断批量任务是否存在可重试失败行。
export const canRetryBatch = (detail?: BatchRetryGate | null): boolean =>
Boolean(detail?.id && Number(detail.retryable || 0) > 0 && !isBatchInProgress(detail.status));
// isCurrentBatchRequest 判断轮询响应是否仍属于当前任务请求代次。
export const isCurrentBatchRequest = (requestGeneration: number, currentGeneration: number): boolean =>
requestGeneration === currentGeneration;
// batchStatusText 将后端批量状态转换为中文展示文本。
export const batchStatusText = (status?: string): string => {
switch (status) {
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 status || '-';
}
};
// batchStatusClass 返回批量状态对应的标签样式。
export const batchStatusClass = (status?: string): string => {
switch (status) {
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';
}
};
@@ -0,0 +1,30 @@
import type { BatchPhase } from '../types';
// BatchPhaseIndicatorProps 描述批量流程指示器的当前步骤。
export interface BatchPhaseIndicatorProps {
// phase 是当前批量流程步骤。
phase: BatchPhase;
}
// BatchPhaseIndicator 展示上传、预检、发布和结果四个批量阶段。
export const BatchPhaseIndicator = ({ phase }: BatchPhaseIndicatorProps) => {
// phases 是批量流程的固定步骤列表。
const phases: Array<[BatchPhase, string]> = [
['upload', '1 上传'],
['preview', '2 预检'],
['running', '3 发布'],
['done', '4 结果'],
];
return (
<div className="grid grid-cols-4 gap-2">
{phases.map(
// 阶段渲染器根据当前步骤切换高亮样式。
([phaseID, label]) => (
<div key={phaseID} className={`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${phase === phaseID ? 'bg-blue-600 text-white border-blue-600' : 'bg-gray-50 text-gray-500 border-gray-100'}`}>
{label}
</div>
),
)}
</div>
);
};
+362
View File
@@ -0,0 +1,362 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import {
cancelItemPublishBatch,
deleteItemPublishBatch,
getItemPublishBatch,
getItemPublishBatches,
recommendPublishCategory,
previewItemPublishBatch,
retryFailedItemPublishBatch,
startItemPublishBatch,
} from './api';
import { canRetryBatch, canStartBatch, isBatchInProgress, isCurrentBatchRequest, selectActivePublishBatch } from './batchState';
import type {
BatchFallbackCategory,
BatchPhase,
ItemPublishBatchOptions,
ItemPublishBatchState,
PublishBatchDetail,
PublishBatchPreview,
} from './types';
// useItemPublishBatch 集中管理批量铺货的表单、任务恢复、轮询和重试状态。
export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPublishBatchState => {
// showBatchModal 表示批量铺货弹窗是否打开。
const [showBatchModal, setShowBatchModal] = useState(false);
// batchPhase 表示批量流程当前所处步骤。
const [batchPhase, setBatchPhase] = useState<BatchPhase>('upload');
// batchFile 保存待预检的商品表格文件。
const [batchFile, setBatchFile] = useState<File | null>(null);
// batchImagesZip 保存可选的商品图片压缩包。
const [batchImagesZip, setBatchImagesZip] = useState<File | null>(null);
// batchCategoryKeyword 保存默认类目搜索词。
const [batchCategoryKeyword, setBatchCategoryKeyword] = useState('');
// batchCategoryLoading 表示默认类目推荐请求是否正在执行。
const [batchCategoryLoading, setBatchCategoryLoading] = useState(false);
// batchFallbackCategory 保存默认类目配置。
const [batchFallbackCategory, setBatchFallbackCategory] = useState<BatchFallbackCategory>({ catId: '', catName: '', channelCatId: '', tbCatId: '' });
// batchPreview 保存最近一次批量预检结果。
const [batchPreview, setBatchPreview] = useState<PublishBatchPreview | null>(null);
// batchDetail 保存当前批量任务的服务端详情。
const [batchDetail, setBatchDetail] = useState<PublishBatchDetail | null>(null);
// recentBatch 保存页面入口处展示的最近任务结果。
const [recentBatch, setRecentBatch] = useState<PublishBatchDetail | null>(null);
// batchLocations 保存批量任务可选的发货地列表。
const [batchLocations, setBatchLocations] = useState<NonNullable<ItemPublishBatchState['batchLocations']>>([]);
// batchLocation 保存批量任务当前选中的发货地。
const [batchLocation, setBatchLocation] = useState<ItemPublishBatchState['batchLocation']>(null);
// batchLoading 表示批量任务请求是否正在执行。
const [batchLoading, setBatchLoading] = useState(false);
// batchPollInFlight 防止同一批次的轮询请求重叠。
const batchPollInFlight = useRef(false);
// batchRequestGeneration 用于丢弃弹窗关闭后返回的过期轮询响应。
const batchRequestGeneration = useRef(0);
// openBatchModal 初始化上传表单,并恢复仍在执行的批量任务。
const openBatchModal = useCallback(
// 批量弹窗打开器负责初始化临时表单和恢复任务。
async () => {
setBatchPhase('upload');
setBatchPreview(null);
setBatchDetail(null);
setBatchFile(null);
setBatchImagesZip(null);
setBatchCategoryKeyword('');
setBatchFallbackCategory({ catId: '', catName: '', channelCatId: '', tbCatId: '' });
setBatchLocations([]);
setBatchLocation(null);
setShowBatchModal(true);
setBatchLoading(true);
try {
// batches 是最近批量任务摘要,用于寻找可恢复任务。
const batches = await getItemPublishBatches(20);
// recoverable 是仍处于运行或安全取消阶段的任务。
const recoverable = selectActivePublishBatch(batches);
if (recoverable?.id) {
// detail 是可恢复任务的完整详情。
const detail = await getItemPublishBatch(recoverable.id);
setRecentBatch(detail);
setBatchDetail(detail);
setBatchPhase(['running', 'canceling'].includes(detail.status) ? 'running' : 'done');
}
} catch (error /* 恢复任务错误 */) {
console.error('恢复最近批量铺货任务失败:', error);
} finally {
setBatchLoading(false);
}
},
[],
);
// handleRecommendBatchCategory 请求默认发布账号对应的推荐类目。
const handleRecommendBatchCategory = useCallback(
// 类目推荐动作响应用户点击或回车提交。
async () => {
// keyword 是去除空白后的类目搜索词。
const keyword = batchCategoryKeyword.trim();
if (!options.selectedAccount) {
alert('请先选择默认发布账号');
return;
}
if (!keyword) {
alert('请输入类目关键词');
return;
}
setBatchCategoryLoading(true);
try {
// result 是类目推荐接口返回的具名响应。
const result = await recommendPublishCategory(options.selectedAccount, keyword);
// category 是后端返回的推荐类目。
const category = result.category;
setBatchFallbackCategory({
catId: category.cat_id,
catName: category.cat_name,
channelCatId: category.channel_cat_id,
tbCatId: category.tb_cat_id || '',
});
} catch (error: any /* 推荐类目错误 */) {
console.error('获取推荐类目失败:', error);
alert(error?.message || '没有匹配到类目,请换一个更具体的关键词');
} finally {
setBatchCategoryLoading(false);
}
},
[batchCategoryKeyword, options.selectedAccount],
);
// openRecentBatchResult 加载最近批量任务详情并打开结果弹窗。
const openRecentBatchResult = useCallback(
// 最近结果打开器只读取已存在的批量任务。
async () => {
if (!recentBatch?.id) return;
setBatchLoading(true);
setShowBatchModal(true);
try {
// detail 是最近任务的最新服务端状态。
const detail = await getItemPublishBatch(recentBatch.id);
setBatchDetail(detail);
setBatchPhase(['running', 'canceling'].includes(detail.status) ? 'running' : 'done');
} catch (error /* 最近结果读取错误 */) {
console.error('加载最近批量铺货结果失败:', error);
} finally {
setBatchLoading(false);
}
},
[recentBatch?.id],
);
// handlePreviewBatch 上传表格并执行批量预检。
const handlePreviewBatch = useCallback(
// 批量预检动作提交上传文件和默认配置。
async () => {
if (!batchFile) {
alert('请先上传商品表格');
return;
}
if (!options.selectedAccount) {
alert('请先选择默认发布账号');
return;
}
setBatchLoading(true);
try {
// result 是批量预检接口返回的行级校验结果。
const result = await previewItemPublishBatch({
file: batchFile,
imagesZip: batchImagesZip,
defaultCookieId: options.selectedAccount,
fallbackCategory: batchFallbackCategory,
location: batchLocation || undefined,
});
setBatchPreview(result);
setBatchDetail(null);
setBatchPhase('preview');
} catch (error: any /* 预检失败错误 */) {
console.error('批量铺货预检失败:', error);
alert(error?.message || '预检失败,请检查表格和图片 zip');
} finally {
setBatchLoading(false);
}
},
[batchFallbackCategory, batchFile, batchImagesZip, batchLocation, options.selectedAccount],
);
// handleStartBatch 启动预检通过的批量任务并读取首个详情。
const handleStartBatch = useCallback(
// 批量启动动作只允许预检通过的有效行进入执行阶段。
async () => {
if (!batchPreview?.preview_id) return;
if (!canStartBatch(batchPreview)) {
alert('没有可发布的商品行');
return;
}
setBatchLoading(true);
try {
// started 是批量任务启动接口返回的任务标识。
const started = await startItemPublishBatch(batchPreview.preview_id);
// detail 是启动后用于驱动轮询的任务详情。
const detail = await getItemPublishBatch(started.batch_id || batchPreview.preview_id);
setBatchDetail(detail);
setRecentBatch(detail);
setBatchPhase(detail.status === 'running' ? 'running' : 'done');
} catch (error: any /* 启动失败错误 */) {
console.error('启动批量铺货失败:', error);
alert(error?.message || '启动发布任务失败');
} finally {
setBatchLoading(false);
}
},
[batchPreview],
);
// handleCancelBatch 请求安全取消当前批量任务,并保留远端收尾状态。
const handleCancelBatch = useCallback(
// 批量取消动作遵循后端的安全取消语义。
async () => {
if (!batchDetail?.id) return;
if (!confirm('确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。')) return;
setBatchLoading(true);
try {
// result 是取消请求返回的过渡状态。
const result = await cancelItemPublishBatch(batchDetail.id);
// detail 是取消请求后的最新任务状态。
const detail = await getItemPublishBatch(batchDetail.id);
setBatchDetail(detail);
setBatchPhase(result?.status === 'canceling' || detail.status === 'canceling' ? 'running' : 'done');
} catch (error: any /* 取消失败错误 */) {
alert(error?.message || '取消失败');
} finally {
setBatchLoading(false);
}
},
[batchDetail?.id],
);
// abandonBatchPreview 删除未启动的预检任务并恢复上传步骤。
const abandonBatchPreview = useCallback(
// 预检放弃动作删除未启动任务并恢复上传步骤。
async () => {
// previewId 是当前临时预检任务标识。
const previewId = batchPreview?.preview_id;
if (previewId && batchPhase === 'preview') {
try {
await deleteItemPublishBatch(previewId);
} catch (error /* 删除预检错误 */) {
console.error('清理批量铺货预检失败:', error);
}
}
setBatchPreview(null);
setBatchPhase('upload');
},
[batchPhase, batchPreview?.preview_id],
);
// closeBatchModal 清理临时预检后关闭批量弹窗。
const closeBatchModal = useCallback(
// 批量弹窗关闭动作先清理临时预检任务。
async () => {
await abandonBatchPreview();
setShowBatchModal(false);
},
[abandonBatchPreview],
);
// handleRetryBatchFailed 重新执行当前批次中可重试的失败行。
const handleRetryBatchFailed = useCallback(
// 失败重试动作只提交后端允许重试的行。
async () => {
if (!batchDetail?.id || !canRetryBatch(batchDetail)) return;
setBatchLoading(true);
try {
await retryFailedItemPublishBatch(batchDetail.id);
setBatchDetail(await getItemPublishBatch(batchDetail.id));
setBatchPhase('running');
} catch (error: any /* 重试失败错误 */) {
alert(error?.message || '重试失败');
} finally {
setBatchLoading(false);
}
},
[batchDetail?.id],
);
useEffect(
// 批量轮询副作用只在弹窗展示运行任务时启动。
() => {
if (!showBatchModal || !batchDetail?.id || !isBatchInProgress(batchDetail.status)) return;
// requestGeneration 标记本次轮询生命周期,弹窗关闭时会失效。
const requestGeneration = ++batchRequestGeneration.current;
// pollBatch 读取任务最新进度并在结束后刷新商品和规则列表。
const pollBatch = async () => {
if (batchPollInFlight.current) return;
batchPollInFlight.current = true;
try {
// detail 是轮询返回的最新任务详情。
const detail = await getItemPublishBatch(batchDetail.id);
if (!isCurrentBatchRequest(requestGeneration, batchRequestGeneration.current)) return;
setBatchDetail(detail);
setRecentBatch(detail);
if (!isBatchInProgress(detail.status)) {
setBatchPhase('done');
await Promise.all([options.loadItems(), options.loadShippingRules()]);
}
} catch (error /* 轮询读取错误 */) {
console.error('刷新批量铺货进度失败:', error);
} finally {
batchPollInFlight.current = false;
}
};
// timer 是当前批次的轮询计时器。
const timer = window.setInterval(
// 轮询回调异步读取任务进度。
() => void pollBatch(),
3000,
);
return (
// 轮询清理器停止计时器并使未完成响应失效。
() => {
window.clearInterval(timer);
batchRequestGeneration.current += 1;
}
);
},
[batchDetail?.id, batchDetail?.status, options.loadItems, options.loadShippingRules, showBatchModal],
);
// result 汇总批量状态、更新器和流程动作,保持页面只消费 feature 边界。
const result: ItemPublishBatchState = {
showBatchModal,
setShowBatchModal,
batchLoading,
batchPhase,
setBatchPhase,
batchFile,
setBatchFile,
batchImagesZip,
setBatchImagesZip,
batchCategoryKeyword,
setBatchCategoryKeyword,
batchCategoryLoading,
batchFallbackCategory,
setBatchFallbackCategory,
batchPreview,
setBatchPreview,
batchDetail,
setBatchDetail,
recentBatch,
setRecentBatch,
batchLocations,
batchLocation,
setBatchLocations,
setBatchLocation,
openBatchModal,
handleRecommendBatchCategory,
openRecentBatchResult,
handlePreviewBatch,
handleStartBatch,
handleCancelBatch,
abandonBatchPreview,
closeBatchModal,
handleRetryBatchFailed,
};
return result;
};
+216
View File
@@ -0,0 +1,216 @@
import type { Dispatch, SetStateAction } from 'react';
import type { Item, AccountDetail, ShippingRule } from '../../../types';
import type { PublishLocation } from './api';
// ItemListProps 描述商品页面从父级接收的规则配置回调。
export interface ItemListProps {
// onConfigureDelivery 打开指定商品的自动化发货规则编辑器。
onConfigureDelivery: (item: Item) => void;
}
// BatchPhase 表示批量铺货流程当前所在的步骤。
export type BatchPhase = 'upload' | 'preview' | 'running' | 'done';
// PublishCategory 表示批量铺货行使用的类目映射。
export interface PublishCategory {
// cat_id 是闲鱼类目标识。
cat_id: string;
// cat_name 是类目展示名称。
cat_name: string;
// channel_cat_id 是闲鱼频道类目标识。
channel_cat_id?: string;
// tb_cat_id 是可选的淘宝类目标识。
tb_cat_id?: string;
}
// PublishBatchPreviewRow 表示批量预检返回的一行商品。
export interface PublishBatchPreviewRow {
// row_no 是表格中的原始行号。
row_no: number;
// valid 表示该行是否可以进入发布阶段。
valid: boolean;
// errors 是该行的校验错误列表。
errors?: string[];
// cookie_id 是该行最终使用的账号标识。
cookie_id: string;
// title 是该行商品标题。
title: string;
// price 是该行商品价格。
price: string;
// quantity 是该行商品库存数量。
quantity: number;
// images 是该行解析出的图片地址。
images: string[];
// category 是该行最终采用的类目。
category: PublishCategory;
}
// PublishBatchDetailRow 表示批量任务中的单行执行结果。
export interface PublishBatchDetailRow {
// id 是持久化任务行标识。
id: number;
// row_no 是原始表格行号。
row_no: number;
// cookie_id 是该行使用的账号标识。
cookie_id: string;
// title 是该行商品标题。
title: string;
// price 是该行商品价格。
price: string;
// quantity 是该行商品库存数量。
quantity: number;
// status 是该行执行状态。
status: string;
// item_id 是发布成功后的商品标识。
item_id: string;
// item_url 是发布成功后的商品链接。
item_url: string;
// error_message 是该行失败原因。
error_message: string;
// failure_kind 是后端归类的失败类型。
failure_kind: string;
// images 是该行实际使用的图片地址。
images?: string[];
// category 是该行使用的类目。
category: PublishCategory;
}
// PublishBatchDetail 表示批量任务的汇总和逐行结果。
export interface PublishBatchDetail {
// id 是批量任务标识。
id: string;
// status 是批量任务当前状态。
status: string;
// filename 是上传的原始文件名。
filename: string;
// total 是任务总行数。
total: number;
// success 是成功行数。
success: number;
// failed 是失败行数。
failed: number;
// pending 是等待执行行数。
pending: number;
// running 是正在执行行数。
running: number;
// retryable 是可重试失败行数。
retryable: number;
// rows 是逐行执行结果。
rows: PublishBatchDetailRow[];
}
// PublishBatchPreview 表示批量预检的汇总和逐行结果。
export interface PublishBatchPreview {
// preview_id 是预检任务标识。
preview_id: string;
// total 是预检总行数。
total: number;
// valid 是可发布行数。
valid: number;
// invalid 是需要修正的行数。
invalid: number;
// rows 是逐行预检结果。
rows: PublishBatchPreviewRow[];
}
// BatchFallbackCategory 表示批量预检使用的默认类目。
export interface BatchFallbackCategory {
// catId 是默认类目 ID。
catId: string;
// catName 是默认类目名称。
catName: string;
// channelCatId 是默认频道类目 ID。
channelCatId: string;
// tbCatId 是默认淘宝类目 ID。
tbCatId: string;
}
// ItemPublishBatchState 描述批量铺货 Hook 暴露的服务端和表单状态。
export interface ItemPublishBatchState {
// showBatchModal 表示批量铺货弹窗是否打开。
showBatchModal: boolean;
// setShowBatchModal 控制批量铺货弹窗的显示状态。
setShowBatchModal: Dispatch<SetStateAction<boolean>>;
// batchLoading 表示批量任务请求是否正在执行。
batchLoading: boolean;
// batchPhase 是批量流程当前步骤。
batchPhase: BatchPhase;
// setBatchPhase 更新批量流程当前步骤。
setBatchPhase: Dispatch<SetStateAction<BatchPhase>>;
// batchFile 是待预检的商品表格文件。
batchFile: File | null;
// setBatchFile 更新待预检的商品表格。
setBatchFile: Dispatch<SetStateAction<File | null>>;
// batchImagesZip 是可选的商品图片压缩包。
batchImagesZip: File | null;
// setBatchImagesZip 更新可选的图片压缩包。
setBatchImagesZip: Dispatch<SetStateAction<File | null>>;
// batchCategoryKeyword 是默认类目搜索词。
batchCategoryKeyword: string;
// setBatchCategoryKeyword 更新默认类目搜索词。
setBatchCategoryKeyword: Dispatch<SetStateAction<string>>;
// batchCategoryLoading 表示默认类目推荐请求是否正在执行。
batchCategoryLoading: boolean;
// batchFallbackCategory 是默认类目配置。
batchFallbackCategory: BatchFallbackCategory;
// setBatchFallbackCategory 更新默认类目配置。
setBatchFallbackCategory: Dispatch<SetStateAction<BatchFallbackCategory>>;
// batchPreview 是最近一次预检结果。
batchPreview: PublishBatchPreview | null;
// setBatchPreview 更新最近一次预检结果。
setBatchPreview: Dispatch<SetStateAction<ItemPublishBatchState['batchPreview']>>;
// batchDetail 是当前批量任务详情。
batchDetail: PublishBatchDetail | null;
// setBatchDetail 更新当前批量任务详情。
setBatchDetail: Dispatch<SetStateAction<PublishBatchDetail | null>>;
// recentBatch 是页面入口处展示的最近任务。
recentBatch: PublishBatchDetail | null;
// setRecentBatch 更新页面入口处展示的最近任务。
setRecentBatch: Dispatch<SetStateAction<PublishBatchDetail | null>>;
// batchLocations 是批量任务可选的发货地列表。
batchLocations: PublishLocation[];
// batchLocation 是批量任务当前选择的发货地。
batchLocation: PublishLocation | null;
// setBatchLocations 更新批量发货地候选列表。
setBatchLocations: Dispatch<SetStateAction<PublishLocation[]>>;
// setBatchLocation 更新批量当前发货地。
setBatchLocation: Dispatch<SetStateAction<PublishLocation | null>>;
// openBatchModal 打开批量铺货流程并恢复可继续任务。
openBatchModal: () => Promise<void>;
// handleRecommendBatchCategory 请求默认类目推荐。
handleRecommendBatchCategory: () => Promise<void>;
// openRecentBatchResult 打开最近批量任务结果。
openRecentBatchResult: () => Promise<void>;
// handlePreviewBatch 提交文件并执行批量预检。
handlePreviewBatch: () => Promise<void>;
// handleStartBatch 启动预检通过的批量任务。
handleStartBatch: () => Promise<void>;
// handleCancelBatch 请求安全取消当前任务。
handleCancelBatch: () => Promise<void>;
// abandonBatchPreview 清理预检任务并回到上传步骤。
abandonBatchPreview: () => Promise<void>;
// closeBatchModal 关闭批量弹窗并清理临时预检任务。
closeBatchModal: () => Promise<void>;
// handleRetryBatchFailed 重试当前任务的失败行。
handleRetryBatchFailed: () => Promise<void>;
}
// ItemPublishBatchOptions 描述批量 Hook 依赖的页面上下文。
export interface ItemPublishBatchOptions {
// selectedAccount 是批量任务默认使用的账号。
selectedAccount: string;
// loadItems 刷新商品列表。
loadItems: () => Promise<void>;
// loadShippingRules 刷新商品关联规则。
loadShippingRules: () => Promise<void>;
}
// ItemReferenceState 描述商品页面 Hook 需要的共享列表状态。
export interface ItemReferenceState {
// items 是商品列表。
items: Item[];
// shippingRules 是商品关联的自动化规则。
shippingRules: ShippingRule[];
// accounts 是账号列表。
accounts: AccountDetail[];
}
+63 -328
View File
@@ -1,83 +1,28 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { createPortal } from 'react-dom';
import { selectActivePublishBatch } from './itemPublishBatchState';
import { Item, AccountDetail, ShippingRule } from '../types';
import type { Item } from '../types';
import {
getItems,
getAccountDetails,
syncItemsFromAccount,
createItem,
publishItem,
recommendPublishCategory,
previewItemPublishBatch,
startItemPublishBatch,
getItemPublishBatch,
getItemPublishBatches,
deleteItemPublishBatch,
cancelItemPublishBatch,
retryFailedItemPublishBatch,
updateItem,
deleteItem,
getShippingRules
} from '../services/api';
import type { PublishLocation } from '../services/api';
import { getPublishLocations } from '../services/amapLocation';
} from '../app/features/items/api';
import type { PublishLocation } from '../app/features/items/api';
import {
getItems,
getAccountDetails,
getShippingRules,
getItemPublishBatches,
getPublishLocations,
} from '../app/features/items/api';
import type { AccountDetail, ShippingRule } from '../types';
import type { ItemListProps } from '../app/features/items/types';
import { useItemPublishBatch } from '../app/features/items/hooks';
import { batchStatusClass, batchStatusText } from '../app/features/items/batchState';
import { BatchPhaseIndicator } from '../app/features/items/components/BatchPhaseIndicator';
import { ArrowRight, Box, CheckCircle2, CircleDashed, Edit, Filter, Link2, LocateFixed, PackagePlus, Plus, RefreshCw, Save, Search, ShoppingBag, Trash2, UploadCloud, User, X } from 'lucide-react';
interface ItemListProps {
onConfigureDelivery: (item: Item) => void;
}
type BatchPhase = 'upload' | 'preview' | 'running' | 'done';
interface PublishCategory {
cat_id: string;
cat_name: string;
channel_cat_id?: string;
tb_cat_id?: string;
}
interface PublishBatchPreviewRow {
row_no: number;
valid: boolean;
errors?: string[];
cookie_id: string;
title: string;
price: string;
quantity: number;
images: string[];
category: PublishCategory;
}
interface PublishBatchDetailRow {
id: number;
row_no: number;
cookie_id: string;
title: string;
price: string;
quantity: number;
status: string;
item_id: string;
item_url: string;
error_message: string;
failure_kind: string;
images?: string[];
category: PublishCategory;
}
interface PublishBatchDetail {
id: string;
status: string;
filename: string;
total: number;
success: number;
failed: number;
pending: number;
running: number;
retryable: number;
rows: PublishBatchDetailRow[];
}
const formatItemPrice = (price?: string) => {
const value = String(price || '').trim();
if (!value) return '-';
@@ -92,37 +37,12 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
const [accountFilter, setAccountFilter] = useState<string>('');
const [loading, setLoading] = useState(false);
const [publishing, setPublishing] = useState(false);
const [batchLoading, setBatchLoading] = useState(false);
const [showEditModal, setShowEditModal] = useState(false);
const [showAddModal, setShowAddModal] = useState(false);
const [showPublishModal, setShowPublishModal] = useState(false);
const [showBatchModal, setShowBatchModal] = useState(false);
const [batchPhase, setBatchPhase] = useState<BatchPhase>('upload');
const [batchFile, setBatchFile] = useState<File | null>(null);
const [batchImagesZip, setBatchImagesZip] = useState<File | null>(null);
const [batchCategoryKeyword, setBatchCategoryKeyword] = useState('');
const [batchCategoryLoading, setBatchCategoryLoading] = useState(false);
const [locationLoading, setLocationLoading] = useState(false);
const [publishLocations, setPublishLocations] = useState<PublishLocation[]>([]);
const [publishLocation, setPublishLocation] = useState<PublishLocation | null>(null);
const [batchLocations, setBatchLocations] = useState<PublishLocation[]>([]);
const [batchLocation, setBatchLocation] = useState<PublishLocation | null>(null);
const [batchFallbackCategory, setBatchFallbackCategory] = useState({
catId: '',
catName: '',
channelCatId: '',
tbCatId: '',
});
const [batchPreview, setBatchPreview] = useState<{
preview_id: string;
total: number;
valid: number;
invalid: number;
rows: PublishBatchPreviewRow[];
} | null>(null);
const [batchDetail, setBatchDetail] = useState<PublishBatchDetail | null>(null);
const [recentBatch, setRecentBatch] = useState<PublishBatchDetail | null>(null);
const batchPollInFlight = useRef(false);
const [selectedItem, setSelectedItem] = useState<Item | null>(null);
const [editForm, setEditForm] = useState<Partial<Item>>({});
const [addForm, setAddForm] = useState({
@@ -145,6 +65,52 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
});
const [publishImagePreviews, setPublishImagePreviews] = useState<{ key: string; url: string }[]>([]);
// loadItems 刷新商品列表,供普通操作和批量任务完成后复用。
const loadItems = useCallback(async () => {
const itemsList = await getItems();
setItems(itemsList);
}, []);
// loadShippingRules 刷新商品关联的自动化规则。
const loadShippingRules = useCallback(async () => {
setShippingRules(await getShippingRules());
}, []);
// batchState 是 ItemList feature 提供的批量铺货状态和动作边界。
const batchState = useItemPublishBatch({ selectedAccount, loadItems, loadShippingRules });
const {
showBatchModal,
setShowBatchModal,
batchLoading,
batchPhase,
batchFile,
setBatchFile,
batchImagesZip,
setBatchImagesZip,
batchCategoryKeyword,
setBatchCategoryKeyword,
batchCategoryLoading,
batchFallbackCategory,
setBatchFallbackCategory,
batchPreview,
batchDetail,
recentBatch,
setRecentBatch,
batchLocations,
batchLocation,
setBatchLocations,
setBatchLocation,
openBatchModal,
handleRecommendBatchCategory,
openRecentBatchResult,
handlePreviewBatch,
handleStartBatch,
handleCancelBatch,
abandonBatchPreview,
closeBatchModal,
handleRetryBatchFailed,
} = batchState;
useEffect(() => {
if (!showPublishModal || publishForm.images.length === 0) {
setPublishImagePreviews([]);
@@ -160,15 +126,6 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
};
}, [showPublishModal, publishForm.images]);
const loadItems = async () => {
const itemsList = await getItems();
setItems(itemsList);
};
const loadShippingRules = async () => {
setShippingRules(await getShippingRules());
};
useEffect(() => {
Promise.all([getAccountDetails(), getItems(), getShippingRules(), getItemPublishBatches(20)])
.then(([accountList, itemList, ruleList, batches]) => {
@@ -182,31 +139,6 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
.catch((e) => console.error('加载商品配置失败:', e));
}, []);
useEffect(() => {
if (!showBatchModal || !batchDetail?.id || !['running', 'canceling'].includes(batchDetail.status)) return;
const timer = window.setInterval(async () => {
if (batchPollInFlight.current) return;
batchPollInFlight.current = true;
try {
const detail = await getItemPublishBatch(batchDetail.id);
setBatchDetail(detail);
setRecentBatch(detail);
if (!['running', 'canceling'].includes(detail.status)) {
setBatchPhase('done');
await loadItems();
await loadShippingRules();
}
} catch (error) {
console.error('刷新批量铺货进度失败:', error);
} finally {
batchPollInFlight.current = false;
}
}, 3000);
return () => {
window.clearInterval(timer);
};
}, [showBatchModal, batchDetail?.id, batchDetail?.status]);
const handleSync = async () => {
if (!selectedAccount) return alert('请先选择账号');
setLoading(true);
@@ -340,160 +272,6 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
}
};
const openBatchModal = async () => {
setBatchPhase('upload');
setBatchPreview(null);
setBatchDetail(null);
setBatchFile(null);
setBatchImagesZip(null);
setBatchCategoryKeyword('');
setBatchFallbackCategory({ catId: '', catName: '', channelCatId: '', tbCatId: '' });
setBatchLocations([]);
setBatchLocation(null);
setShowBatchModal(true);
setBatchLoading(true);
try {
const batches = await getItemPublishBatches(20);
const recoverable = selectActivePublishBatch(batches);
if (recoverable?.id) {
const detail = await getItemPublishBatch(recoverable.id);
setRecentBatch(detail);
setBatchDetail(detail);
setBatchPhase(['running', 'canceling'].includes(detail.status) ? 'running' : 'done');
}
} catch (error) {
console.error('恢复最近批量铺货任务失败:', error);
} finally {
setBatchLoading(false);
}
};
const handleRecommendBatchCategory = async () => {
const keyword = batchCategoryKeyword.trim();
if (!selectedAccount) return alert('请先选择默认发布账号');
if (!keyword) return alert('请输入类目关键词');
setBatchCategoryLoading(true);
try {
const result = await recommendPublishCategory(selectedAccount, keyword);
const category = result.category;
setBatchFallbackCategory({
catId: category.cat_id,
catName: category.cat_name,
channelCatId: category.channel_cat_id,
tbCatId: category.tb_cat_id || '',
});
} catch (error: any) {
console.error('获取推荐类目失败:', error);
alert(error?.message || '没有匹配到类目,请换一个更具体的关键词');
} finally {
setBatchCategoryLoading(false);
}
};
const openRecentBatchResult = async () => {
if (!recentBatch?.id) return;
setBatchLoading(true);
setShowBatchModal(true);
try {
const detail = await getItemPublishBatch(recentBatch.id);
setBatchDetail(detail);
setBatchPhase(['running', 'canceling'].includes(detail.status) ? 'running' : 'done');
} catch (error) {
console.error('加载最近批量铺货结果失败:', error);
} finally {
setBatchLoading(false);
}
};
const handlePreviewBatch = async () => {
if (!batchFile) return alert('请先上传商品表格');
if (!selectedAccount) return alert('请先选择默认发布账号');
setBatchLoading(true);
try {
const result = await previewItemPublishBatch({
file: batchFile,
imagesZip: batchImagesZip,
defaultCookieId: selectedAccount,
fallbackCategory: batchFallbackCategory,
location: batchLocation || undefined,
});
setBatchPreview(result);
setBatchDetail(null);
setBatchPhase('preview');
} catch (error: any) {
console.error('批量铺货预检失败:', error);
alert(error?.message || '预检失败,请检查表格和图片 zip');
} finally {
setBatchLoading(false);
}
};
const handleStartBatch = async () => {
if (!batchPreview?.preview_id) return;
if (batchPreview.valid <= 0) return alert('没有可发布的商品行');
setBatchLoading(true);
try {
const started = await startItemPublishBatch(batchPreview.preview_id);
const detail = await getItemPublishBatch(started.batch_id || batchPreview.preview_id);
setBatchDetail(detail);
setRecentBatch(detail);
setBatchPhase(detail.status === 'running' ? 'running' : 'done');
} catch (error: any) {
console.error('启动批量铺货失败:', error);
alert(error?.message || '启动发布任务失败');
} finally {
setBatchLoading(false);
}
};
const handleCancelBatch = async () => {
if (!batchDetail?.id) return;
if (!confirm('确认取消当前批量铺货任务吗?正在发布的单个商品可能会继续完成。')) return;
setBatchLoading(true);
try {
const result = await cancelItemPublishBatch(batchDetail.id);
const detail = await getItemPublishBatch(batchDetail.id);
setBatchDetail(detail);
setBatchPhase(result?.status === 'canceling' || detail.status === 'canceling' ? 'running' : 'done');
} catch (error: any) {
alert(error?.message || '取消失败');
} finally {
setBatchLoading(false);
}
};
const abandonBatchPreview = async () => {
const previewId = batchPreview?.preview_id;
if (previewId && batchPhase === 'preview') {
try {
await deleteItemPublishBatch(previewId);
} catch (error) {
console.error('清理批量铺货预检失败:', error);
}
}
setBatchPreview(null);
setBatchPhase('upload');
};
const closeBatchModal = async () => {
await abandonBatchPreview();
setShowBatchModal(false);
};
const handleRetryBatchFailed = async () => {
if (!batchDetail?.id) return;
setBatchLoading(true);
try {
await retryFailedItemPublishBatch(batchDetail.id);
setBatchDetail(await getItemPublishBatch(batchDetail.id));
setBatchPhase('running');
} catch (error: any) {
alert(error?.message || '重试失败');
} finally {
setBatchLoading(false);
}
};
const downloadPublishTemplate = () => {
const headers = [
'账号ID', '标题', '描述', '价格', '原价', '库存', '邮费模式', '邮费', '图片',
@@ -555,38 +333,6 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
? shippingRules.filter(rule => rule.cookie_id === item.cookie_id && rule.item_id === item.item_id)
: shippingRules.filter(rule => rule.cookie_id === item.cookie_id && !rule.item_id);
const batchStatusText = (status?: string) => {
switch (status) {
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 status || '-';
}
};
const batchStatusClass = (status?: string) => {
switch (status) {
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';
}
};
const accountMap = useMemo(
() => new Map(accounts.map(account => [account.id, account])),
[accounts],
@@ -962,18 +708,7 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
</div>
<div className="modal-body space-y-5">
<div className="grid grid-cols-4 gap-2">
{[
['upload', '1 上传'],
['preview', '2 预检'],
['running', '3 发布'],
['done', '4 结果']
].map(([phase, label]) => (
<div key={phase} className={`rounded-xl px-3 py-2 text-center text-xs font-extrabold border ${batchPhase === phase ? 'bg-blue-600 text-white border-blue-600' : 'bg-gray-50 text-gray-500 border-gray-100'}`}>
{label}
</div>
))}
</div>
<BatchPhaseIndicator phase={batchPhase} />
{batchPhase === 'upload' && (
<div className="space-y-5">
+3 -7
View File
@@ -1,7 +1,3 @@
export interface PublishBatchSummary {
id?: string;
status?: string;
}
export const selectActivePublishBatch = <T extends PublishBatchSummary>(batches: T[]): T | undefined =>
batches.find(batch => batch.status === 'running' || batch.status === 'canceling');
// 旧目录保留兼容入口,实际批量状态模型统一归属 ItemList feature。
export { selectActivePublishBatch } from '../app/features/items/batchState';
export type { PublishBatchSummary } from '../app/features/items/batchState';
@@ -0,0 +1 @@
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:6Line truncated
@@ -1 +0,0 @@
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:6Line truncated
@@ -1,19 +0,0 @@
import{j as e,r,c as vs,b as Fe,d as Ka}from"./react-vendor-C_od1ZSF.js";import{L as Ha,U as ja,M as xs,C as ms,B as Na,S as _a,Z as ps,a as yt,b as ws,G as Es,c as ks,d as Cs,e as Za,f as st,A as Ds,D as Ya,g as Ts,P as va,h as Ft,E as wa,T as Xa,i as el,j as Re,X as De,k as tl,l as sl,m as Ss,n as ka,o as Ke,Q as Xt,p as ot,q as Ge,r as ft,s as Tt,t as Ms,R as ze,u as Ca,v as al,w as Qe,K as ll,x as it,y as tt,z as Ye,F as Fs,H as Nt,I as jt,J as Dt,N as Sa,O as rl,V as qs,W as Bs,Y as nl,_ as il,$ as ol,a0 as cl,a1 as es,a2 as Bt,a3 as us,a4 as dl,a5 as xl,a6 as hs,a7 as zs,a8 as ml,a9 as pl,aa as Mt,ab as Us,ac as Gt,ad as La,ae as ul,af as hl,ag as Zt,ah as Ia,ai as gl,aj as bl,ak as fl,al as yl,am as jl,an as Nl,ao as Ws}from"./icons-vendor-BpMgNNfy.js";import{R as zt,B as _l,X as Js,Y as Vs,T as Ut,a as vl,C as ts,A as wl,b as kl,c as Cl,P as Qs,d as Gs,L as Sl}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 c of document.querySelectorAll('link[rel="modulepreload"]'))o(c);new MutationObserver(c=>{for(const w of c)if(w.type==="childList")for(const _ of w.addedNodes)_.tagName==="LINK"&&_.rel==="modulepreload"&&o(_)}).observe(document,{childList:!0,subtree:!0});function l(c){const w={};return c.integrity&&(w.integrity=c.integrity),c.referrerPolicy&&(w.referrerPolicy=c.referrerPolicy),c.crossOrigin==="use-credentials"?w.credentials="include":c.crossOrigin==="anonymous"?w.credentials="omit":w.credentials="same-origin",w}function o(c){if(c.ep)return;c.ep=!0;const w=l(c);fetch(c.href,w)}})();const Ll=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),gs=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23Line 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(ws,{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:n,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:Q,children:"取消"}),e.jsxs("button",{onClick:pt,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:Q,children:[Q?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Ke,{className:"w-4 h-4"}),Q?"保存中...":"保存"]})]})})]})}),document.body)]})},mn=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)||"")})):[]}),pn=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],na=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},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})},un=()=>{const[t,s]=r.useState([]),[l,o]=r.useState([]),[c,w]=r.useState([]),[_,P]=r.useState({}),[b,L]=r.useState("all"),[j,T]=r.useState(""),[Z,xe]=r.useState(""),[Y,v]=r.useState(""),F=r.useRef(0),[le,G]=r.useState(1),[ae,fe]=r.useState(1),[ge,ye]=r.useState(!1),[C,te]=r.useState(!1),[K,J]=r.useState(!1),[he,W]=r.useState(!1),[I,q]=r.useState(null),[$,ie]=r.useState(null),[pe,X]=r.useState({}),[R,m]=r.useState(!1),[f,B]=r.useState(""),[M,re]=r.useState(!1),[je,be]=r.useState(null),[Ee,Ie]=r.useState(null),[x,H]=r.useState(null),[se,d]=r.useState(!1),[k,V]=r.useState(null),[h,Q]=r.useState(null),A=async()=>{const p=++F.current;ye(!0);try{const O=await nr(j||void 0,b,le,20,Y);if(p!==F.current)return;s(O.data),fe(O.total_pages)}catch(O){console.error("加载订单失败:",O)}finally{p===F.current&&ye(!1)}},me=(p,O,de)=>{if(de&&de.trim())return de;if(_[`${p}:${O}`])return _[`${p}:${O}`];const ke=l.find(We=>{if(de&&We.item_title){const Te=de.toLowerCase(),Ue=We.item_title.toLowerCase();return Ue.includes(Te)||Te.includes(Ue)}return!1});return ke!=null&&ke.item_title?ke.item_title:"未知商品"},ee=p=>{const O={};p.forEach(de=>{de.item_id&&(O[`${de.cookie_id}:${de.item_id}`]=de.item_title||de.item_id)}),P(O)};r.useEffect(()=>{const p=window.setTimeout(()=>{G(1),v(Z.trim())},300);return()=>window.clearTimeout(p)},[Z]),r.useEffect(()=>{A()},[j,b,le,Y]),r.useEffect(()=>{Promise.all([qt(),_t()]).then(([p,O])=>{w(p),o(O),ee(O)}).catch(p=>{console.error("加载商品列表失败:",p)})},[]);const Ne=r.useMemo(()=>new Map(c.map(p=>[p.id,p])),[c]),Ae=p=>{const O=Ne.get(p),de=(O==null?void 0:O.remark)||(O==null?void 0:O.nickname);return de?`${de} · ${p.slice(0,6)}`:`账号 ${p.slice(0,8)}`},ce=p=>{const O=Ne.get(p);return(O==null?void 0:O.remark)||(O==null?void 0:O.nickname)||"未命名账号"},g=async()=>{ye(!0);try{const p=await cr(j||void 0,b);await A(),p!=null&&p.message&&alert(p.message)}catch(p){console.error("同步订单失败:",p),alert((p==null?void 0:p.message)||"同步失败,请重试")}finally{ye(!1)}},y=p=>{B(p),be(null),m(!0)},E=async p=>{var O;re(!0),be(null);try{const de=await xr([f],p),ke=(O=de==null?void 0:de.results)==null?void 0:O[0];ke!=null&&ke.success?(be({success:!0,message:ke.message}),A()):be({success:!1,message:(ke==null?void 0:ke.message)||"发货失败"})}catch(de){be({success:!1,message:(de==null?void 0:de.message)||"请求失败"})}finally{re(!1)}},z=p=>{q(p),te(!0)},Oe=p=>{ie({...p}),J(!0)},ue=async()=>{if(!(!$||!$.order_id))try{const p={};$.status!==void 0&&(p.order_status=$.status),$.buyer_id!==void 0&&(p.buyer_id=$.buyer_id),$.amount!==void 0&&(p.amount=$.amount),$.receiver_name!==void 0&&(p.receiver_name=$.receiver_name),$.receiver_phone!== Line truncated
VIP-MONTH-002
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(h=>h.map(Q=>`"${String(Q).replace(/"/g,'""')}"`).join(",")).join(`
`),d=new Blob(["\uFEFF"+se],{type:"text/csv;charset=utf-8"}),k=URL.createObjectURL(d),V=document.createElement("a");V.href=k,V.download="卡密组批量导入模板.csv",document.body.appendChild(V),V.click(),V.remove(),URL.revokeObjectURL(k)},be=async()=>{if(F){ge(!0),ae(null);try{const x=await fr(F);if(ae(x),x.created>0){const H=await Ze();s(H)}}catch(x){ae({error:(x==null?void 0:x.message)||"上传失败"})}finally{ge(!1)}}},Ee=async()=>{if(!(!ye||!te.trim())){ge(!0),he(null);try{const x=await yr(ye,te);he({added:x.added}),K("");const H=await Ze();s(H)}catch(x){alert("追加失败:"+((x==null?void 0:x.message)||"未知错误"))}finally{ge(!1)}}},Ie=()=>{var x;v("create"),le(null),ae(null),C((x=M[0])!=null&&x.id?String(M[0].id):""),K(""),he(null),xe(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:Ie,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Dt,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>w(!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(Ye,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(Sa,{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:W,onChange:x=>I(x.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(Nt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:q,onChange:x=>$(x.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",re.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:re.map(x=>{let H="";return x.type==="data"&&x.data_content?H=`库存: ${x.data_content.split(`
`).filter(d=>d.trim()).length} 条`:x.type==="text"&&x.text_content?H=x.text_content:x.type==="api"&&x.api_config?H=x.api_config.url:x.type==="image"&&x.image_url&&(H="图片链接"),e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(ie,{type:x.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:x.name,children:x.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>B(x.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:x.id}),e.jsx(rl,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${x.type==="text"?"bg-blue-50 text-blue-600":x.type==="data"?"bg-purple-50 text-purple-600":x.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:x.type==="text"?"文本":x.type==="data"?"批量":x.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:H,children:H})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:x.description||"-",children:x.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>f(x),className:`w-12 h-8 rounded-full relative transition-colors ${x.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${x.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>pe(x),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:()=>R(x.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Qe,{className:"h-4 w-4"})})]})})]},x.id)})})]})}),re.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(va,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),l&&_&&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:()=>o(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(De,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:b.name||"",onChange:x=>L({...b,name:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:b.type||"text",onChange:x=>L({...b,type:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(_==null?void 0:_.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),b.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:b.api_url||"",onChange:x=>L({...b,api_url:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsLine truncated
卡号1:密码1
卡号2:密码2
或者
兑换码1
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:b.data_content?b.data_content.split(`
`).filter(x=>x.trim()).length:0})," 条"]})]})]}),b.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:b.image_url||"",onChange:x=>L({...b,image_url:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),b.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:b.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:x=>{x.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:b.delay_seconds||0,onChange:x=>L({...b,delay_seconds:parseInt(x.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:b.description||"",onChange:x=>L({...b,description:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>L({...b,enabled:!b.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${b.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${b.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:()=>o(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:X,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ke,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),c&&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:()=>w(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(De,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:j.name,onChange:x=>T({...j,name:x.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>T({...j,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${j.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(ms,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>T({...j,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${j.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(qs,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>T({...j,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${j.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children: Line truncated
CODE-789012
...`:"请输入每次发货时发送的固定文字"}),j.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:j.content.split(`
`).filter(x=>x.trim()).length})," 条"]})]}),j.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:j.api_method,onChange:x=>T({...j,api_method:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:j.api_timeout,onChange:x=>T({...j,api_timeout:parseInt(x.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:j.api_headers,onChange:x=>T({...j,api_headers:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:j.api_params,onChange:x=>T({...j,api_params:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:j.description,onChange:x=>T({...j,description:x.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:j.delay_seconds,onChange:x=>T({...j,delay_seconds:parseInt(x.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>w(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:m,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Ye,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),Z&&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:()=>xe(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(De,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>v("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 ${Y==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(nl,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>v("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 ${Y==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Dt,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),Y==="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:je,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transit Line truncated
VIP-002
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),J&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",J.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:()=>xe(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),Y==="create"?e.jsxs("button",{onClick:be,disabled:!F||fe,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[fe?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Dt,{className:"w-4 h-4"}),fe?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:Ee,disabled:!ye||!te.trim()||fe||M.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[fe?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Ye,{className:"w-4 h-4"}),fe?"处理中...":"追加卡密"]})]})]})}),document.body)]})},bn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),oa="ydisks-amap-js-api",fn="c9b68d4ce9a2a97f22a4a439404488ca";let Rt=null;const yn=()=>fn,jn=()=>window.AMap?Promise.resolve(window.AMap):Rt||(Rt=new Promise((t,s)=>{const l=document.getElementById(oa),o=l||document.createElement("script"),c=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(_)},w=()=>{window.AMap?(c(),t(window.AMap)):(c(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},_=window.setTimeout(()=>{c(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=w,o.id=oa,o.async=!0,o.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(yn())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,o.onerror=()=>{c(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},l||document.head.appendChild(o)}).catch(t=>{throw Rt=null,t}),Rt),Ht=t=>Number.isFinite(t)&&t!==0,Nn=t=>{var c,w;const s=Number((c=t.location)==null?void 0:c.lng),l=Number((w=t.location)==null?void 0:w.lat),o={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:l,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!o.division_id||!o.province||!o.city||!o.poi_id||!o.poi_name||!Ht(s)||!Ht(l)||s<-180||s>180||l<-90||l>90?null:o},_n=async(t,s)=>{if(!Ht(t)||!Ht(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const l=await jn();return new Promise((o,c)=>{new l.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(_,P)=>{var L;if(_!=="complete"){if(_==="no_data"){o([]);return}c(new Error("高德地图附近地址查询失败,请稍后重试"));return}const b=(((L=P==null?void 0:P.poiList)==null?void 0:L.pois)||[]).map(Nn).filter(j=>j!==null);o(b)})})},vn=t=>{const s=String(t||"").trim();return s?/^[¥¥]/.test(s)?s:`¥${s}`:"-"},wn=({onConfigureDelivery:t})=>{const[s,l]=r.useState([]),[o,c]=r.useState([]),[w,_]=r.useState([]),[P,b]=r.useState(""),[L,j]=r.useState(""),[T,Z]=r.useState(!1),[xe,Y]=r.useState(!1),[v,F]=r.useState(!1),[le,G]=r.useState(!1),[ae,fe]=r.useState(!1),[ge,ye]=r.useState(!1),[C,te]=r.useState(!1),[K,J]=r.useState("upload"),[he,W]=r.useState(null),[I,q]=r.useState(null),[$,ie]=r.useState(""),[pe,X]=r.useState(!1),[R,m]=r.useState(!1),[f,B]=r.useState([]),[M,re]=r.useState(null),[je,be]=r.useState([]),[Ee,Ie]=r.useState(null),[x,H]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[se,d]=r.useState(null),[k,V]=r.useState(null),[h,Q]=r.useState(null),A=r.useRef(!1),[me,ee]=r.useState(null),[Ne,Ae]=r.useState({}),[ce,g]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[y,E]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[z,Oe]=r.useState([]);r.useEffect(()=>{if(!ge||y.images.length===0){Oe([]);return}const n=y.images.map((a,u)=>({key:a.name+u,url:URL.createObjectURL(a)}));return Oe(n),()=>{n.forEach(a=>URL.revokeObjectURL(a.url))}},[ge,y.images]);const ue=async()=>{const n=await _t();l(n)},oe=async()=>{c(await js())};r.useEffect(()=>{Promise.all([qt(),_t(),js(),ea(20)]).then(([n,a,u,S])=>{_(n),l(a),c(u);const i=S.find(N=>["running","canceling"].includes(N.status))||S.find(N=>N.status!=="preview");Q(i||null)}).catch(n=>console.error("加载商品配置失败:",n))},[]),r.useEffect(()=>{if(!C||!(k!=null&&k.id)||!["running","canceling"].includes(k.status))return;const n=window.setInterval(async()=>{if(!A.current){A.current=!0;try{const a=await gt(k.id);V(a),Q(a Line truncated
`),S=new Blob(["\uFEFF"+u],{type:"text/csv;charset=utf-8"}),i=URL.createObjectURL(S),N=document.createElement("a");N.href=i,N.download="批量铺货模板.csv",document.body.appendChild(N),N.click(),N.remove(),URL.revokeObjectURL(i)},Lt=()=>{g(n=>({...n,cookie_id:P||n.cookie_id})),fe(!0)},It=()=>{E(n=>({...n,cookie_id:P||n.cookie_id})),ye(!0)},dt=async n=>{if(!(n?P:y.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");m(!0),navigator.geolocation.getCurrentPosition(async u=>{try{const S=await _n(u.coords.longitude,u.coords.latitude);if(!S.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");n?(be(S),Ie(S[0])):(B(S),re(S[0]))}catch(S){alert((S==null?void 0:S.message)||"获取发货地失败")}finally{m(!1)}},u=>{m(!1),alert(u.code===u.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},xt=n=>o.filter(a=>a.cookie_id===n.cookie_id&&a.item_id===n.item_id).length>0?o.filter(a=>a.cookie_id===n.cookie_id&&a.item_id===n.item_id):o.filter(a=>a.cookie_id===n.cookie_id&&!a.item_id),mt=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||"-"}},pt=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"}},lt=r.useMemo(()=>new Map(w.map(n=>[n.id,n])),[w]),ut=r.useMemo(()=>L?s.filter(n=>n.cookie_id===L):s,[L,s]),Je=n=>{const a=lt.get(n),u=(a==null?void 0:a.remark)||(a==null?void 0:a.nickname);return u?`${u} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},Xe=n=>{const a=lt.get(n);return(a==null?void 0:a.remark)||(a==null?void 0:a.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(cl,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:L,onChange:n=>j(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),w.map(n=>e.jsx("option",{value:n.id,children:Je(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:P,onChange:n=>b(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),w.map(n=>e.jsx("option",{value:n.id,children:Je(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:Ce,disabled:T||!P,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(ze,{className:`w-4 h-4 ${T?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Lt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(Ye,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:It,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(es,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void ke(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-b Line truncated
@@ -0,0 +1,19 @@
import{j as e,r as l,c as ws,b as ze,d as Ya}from"./react-vendor-C_od1ZSF.js";import{L as Xa,U as _a,M as xs,C as ms,B as va,S as wa,Z as us,a as _t,b as ks,G as Ds,c as Cs,d as Ss,e as el,f as nt,A as Ts,D as tl,g as Ms,P as ka,h as Ft,E as Ca,T as sl,i as al,j as Re,X as De,k as ll,l as rl,m as Ls,n as Sa,o as Xe,Q as Xt,p as ut,q as Ye,r as Nt,s as Tt,t as Fs,R as Ve,u as La,v as nl,w as He,K as il,x as mt,y as rt,z as at,F as qs,H as wt,I as vt,J as Dt,N as Ia,O as ol,V as Bs,W as zs,Y as cl,_ as dl,$ as xl,a0 as ml,a1 as es,a2 as Bt,a3 as ps,a4 as ul,a5 as pl,a6 as hs,a7 as Us,a8 as hl,a9 as gl,aa as Mt,ab as Ws,ac as Qt,ad as Aa,ae as bl,af as fl,ag as Zt,ah as Oa,ai as yl,aj as jl,ak as Nl,al as _l,am as vl,an as wl,ao as Js}from"./icons-vendor-BpMgNNfy.js";import{R as zt,B as kl,X as Vs,Y as Gs,T as Ut,a as Cl,C as ts,A as Sl,b as Ll,c as Il,P as Qs,d as Ks,L as Al}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const N of i)if(N.type==="childList")for(const j of N.addedNodes)j.tagName==="LINK"&&j.rel==="modulepreload"&&n(j)}).observe(document,{childList:!0,subtree:!0});function a(i){const N={};return i.integrity&&(N.integrity=i.integrity),i.referrerPolicy&&(N.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?N.credentials="include":i.crossOrigin==="anonymous"?N.credentials="omit":N.credentials="same-origin",N}function n(i){if(i.ep)return;i.ep=!0;const N=a(i);fetch(i.href,N)}})();const Ol=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),gs=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52Line truncated
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(ks,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:ct,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:te,children:"取消"}),e.jsxs("button",{onClick:ye,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:te,children:[te?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"}),te?"保存中...":"保存"]})]})})]})}),document.body)]})},hn=t=>({total:Number((t==null?void 0:t.total)||0),success_count:Number((t==null?void 0:t.success_count)||0),failed_count:Number((t==null?void 0:t.failed_count)||0),results:Array.isArray(t==null?void 0:t.results)?t.results.map(s=>({order_id:String((s==null?void 0:s.order_id)||"unknown"),success:(s==null?void 0:s.success)===!0,message:String((s==null?void 0:s.message)||"")})):[]}),gn=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],na=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},a={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${s[t]||s.cancelled}`,children:a[t]||t})},bn=()=>{const[t,s]=l.useState([]),[a,n]=l.useState([]),[i,N]=l.useState([]),[j,P]=l.useState({}),[g,L]=l.useState("all"),[f,F]=l.useState(""),[ee,de]=l.useState(""),[X,y]=l.useState(""),V=l.useRef(0),[D,G]=l.useState(1),[Y,he]=l.useState(1),[be,fe]=l.useState(!1),[k,ae]=l.useState(!1),[ce,z]=l.useState(!1),[ue,Q]=l.useState(!1),[S,B]=l.useState(null),[I,le]=l.useState(null),[$,K]=l.useState({}),[R,m]=l.useState(!1),[p,W]=l.useState(""),[w,J]=l.useState(!1),[xe,ie]=l.useState(null),[_e,Ae]=l.useState(null),[x,re]=l.useState(null),[Le,d]=l.useState(!1),[q,ne]=l.useState(null),[h,te]=l.useState(null),A=async()=>{const u=++V.current;fe(!0);try{const O=await cr(f||void 0,g,D,20,X);if(u!==V.current)return;s(O.data),he(O.total_pages)}catch(O){console.error("加载订单失败:",O)}finally{u===V.current&&fe(!1)}},oe=(u,O,pe)=>{if(pe&&pe.trim())return pe;if(j[`${u}:${O}`])return j[`${u}:${O}`];const ke=a.find(Ze=>{if(pe&&Ze.item_title){const qe=pe.toLowerCase(),Ge=Ze.item_title.toLowerCase();return Ge.includes(qe)||qe.includes(Ge)}return!1});return ke!=null&&ke.item_title?ke.item_title:"未知商品"},se=u=>{const O={};u.forEach(pe=>{pe.item_id&&(O[`${pe.cookie_id}:${pe.item_id}`]=pe.item_title||pe.item_id)}),P(O)};l.useEffect(()=>{const u=window.setTimeout(()=>{G(1),y(ee.trim())},300);return()=>window.clearTimeout(u)},[ee]),l.useEffect(()=>{A()},[f,g,D,X]),l.useEffect(()=>{Promise.all([qt(),kt()]).then(([u,O])=>{N(u),n(O),se(O)}).catch(u=>{console.error("加载商品列表失败:",u)})},[]);const Fe=l.useMemo(()=>new Map(i.map(u=>[u.id,u])),[i]),Pe=u=>{const O=Fe.get(u),pe=(O==null?void 0:O.remark)||(O==null?void 0:O.nickname);return pe?`${pe} · ${u.slice(0,6)}`:`账号 ${u.slice(0,8)}`},Te=u=>{const O=Fe.get(u);return(O==null?void 0:O.remark)||(O==null?void 0:O.nickname)||"未命名账号"},b=async()=>{fe(!0);try{const u=await mr(f||void 0,g);await A(),u!=null&&u.message&&alert(u.message)}catch(u){console.error("同步订单失败:",u),alert((u==null?void 0:u.message)||"同步失败,请重试")}finally{fe(!1)}},C=u=>{W(u),ie(null),m(!0)},U=async u=>{var O;J(!0),ie(null);try{const pe=await pr([p],u),ke=(O=pe==null?void 0:pe.results)==null?void 0:O[0];ke!=null&&ke.success?(ie({success:!0,message:ke.message}),A()):ie({success:!1,message:(ke==null?void 0:ke.message)||"发货失败"})}catch(pe){ie({success:!1,message:(pe==null?void 0:pe.message)||"请求失败"})}finally{J(!1)}},H=u=>{B(u),ae(!0)},Oe=u=>{le({...u}),z(!0)},ve=async()=>{if(!(!I||!I.order_id))try{const u={};I.status!==void 0&&(u.order_status=I.status),I.buyer_id!==void 0&&(u.buyer_id=I.buyer_id),I.amount!==void 0&&(u.amount=I.amount),I.receiver_name!==void 0&&(u.receiver_name=I.receiver_name),I.receiver_phon Line truncated
VIP-MONTH-002
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(h=>h.map(te=>`"${String(te).replace(/"/g,'""')}"`).join(",")).join(`
`),d=new Blob(["\uFEFF"+Le],{type:"text/csv;charset=utf-8"}),q=URL.createObjectURL(d),ne=document.createElement("a");ne.href=q,ne.download="卡密组批量导入模板.csv",document.body.appendChild(ne),ne.click(),ne.remove(),URL.revokeObjectURL(q)},ie=async()=>{if(V){be(!0),Y(null);try{const x=await Nr(V);if(Y(x),x.created>0){const re=await st();s(re)}}catch(x){Y({error:(x==null?void 0:x.message)||"上传失败"})}finally{be(!1)}}},_e=async()=>{if(!(!fe||!ae.trim())){be(!0),ue(null);try{const x=await _r(fe,ae);ue({added:x.added}),ce("");const re=await st();s(re)}catch(x){alert("追加失败:"+((x==null?void 0:x.message)||"未知错误"))}finally{be(!1)}}},Ae=()=>{var x;y("create"),D(null),Y(null),k((x=w[0])!=null&&x.id?String(w[0].id):""),ce(""),ue(null),de(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:Ae,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Dt,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>N(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(at,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(Ia,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsxs("select",{"aria-label":"按卡密类型筛选",value:Q,onChange:x=>S(x.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(wt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:B,onChange:x=>I(x.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",J.length," / ",t.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:J.map(x=>{let re="";return x.type==="data"&&x.data_content?re=`库存: ${x.data_content.split(`
`).filter(d=>d.trim()).length} 条`:x.type==="text"&&x.text_content?re=x.text_content:x.type==="api"&&x.api_config?re=x.api_config.url:x.type==="image"&&x.image_url&&(re="图片链接"),e.jsxs("tr",{className:"hover:bg-warning-50/50 transition-colors group",children:[e.jsx("td",{className:"px-5 py-5 align-middle",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:"shrink-0 rounded-xl bg-gray-50 p-2 transition-colors group-hover:bg-white",children:e.jsx(le,{type:x.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:x.name,children:x.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>W(x.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:x.id}),e.jsx(ol,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${x.type==="text"?"bg-blue-50 text-blue-600":x.type==="data"?"bg-purple-50 text-purple-600":x.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:x.type==="text"?"文本":x.type==="data"?"批量":x.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:re,children:re})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:x.description||"-",children:x.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>p(x),className:`w-12 h-8 rounded-full relative transition-colors ${x.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${x.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>$(x),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(vt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>R(x.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(He,{className:"h-4 w-4"})})]})})]},x.id)})})]})}),J.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ka,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&j&&ze.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>n(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(De,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:g.name||"",onChange:x=>L({...g,name:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:g.type||"text",onChange:x=>L({...g,type:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(j==null?void 0:j.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),g.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:g.api_url||"",onChange:x=>L({...g,api_url:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[eLine truncated
卡号1:密码1
卡号2:密码2
或者
兑换码1
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:g.data_content?g.data_content.split(`
`).filter(x=>x.trim()).length:0})," 条"]})]})]}),g.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:g.image_url||"",onChange:x=>L({...g,image_url:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),g.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:g.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:x=>{x.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:g.delay_seconds||0,onChange:x=>L({...g,delay_seconds:parseInt(x.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:g.description||"",onChange:x=>L({...g,description:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>L({...g,enabled:!g.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${g.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${g.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>n(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:K,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Xe,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),i&&ze.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>N(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(De,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:f.name,onChange:x=>F({...f,name:x.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>F({...f,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${f.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(ms,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>F({...f,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${f.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Bs,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>F({...f,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${f.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children: Line truncated
CODE-789012
...`:"请输入每次发货时发送的固定文字"}),f.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:f.content.split(`
`).filter(x=>x.trim()).length})," 条"]})]}),f.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:f.api_method,onChange:x=>F({...f,api_method:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:f.api_timeout,onChange:x=>F({...f,api_timeout:parseInt(x.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:f.api_headers,onChange:x=>F({...f,api_headers:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:f.api_params,onChange:x=>F({...f,api_params:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:f.description,onChange:x=>F({...f,description:x.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:f.delay_seconds,onChange:x=>F({...f,delay_seconds:parseInt(x.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>N(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:m,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(at,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),ee&&ze.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>de(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(De,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>y("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${X==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(cl,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>y("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${X==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Dt,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),X==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),'。 类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:xe,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transi Line truncated
VIP-002
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),z&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",z.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>de(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),X==="create"?e.jsxs("button",{onClick:ie,disabled:!V||he,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[he?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(Dt,{className:"w-4 h-4"}),he?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:_e,disabled:!fe||!ae.trim()||he||w.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[he?e.jsx(Re,{className:"w-4 h-4 animate-spin"}):e.jsx(at,{className:"w-4 h-4"}),he?"处理中...":"追加卡密"]})]})]})}),document.body)]})},oa="ydisks-amap-js-api",jn="c9b68d4ce9a2a97f22a4a439404488ca";let Rt=null;const Nn=()=>jn,_n=()=>window.AMap?Promise.resolve(window.AMap):Rt||(Rt=new Promise((t,s)=>{const a=document.getElementById(oa),n=a||document.createElement("script"),i=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(j)},N=()=>{window.AMap?(i(),t(window.AMap)):(i(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},j=window.setTimeout(()=>{i(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=N,n.id=oa,n.async=!0,n.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(Nn())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,n.onerror=()=>{i(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(n)}).catch(t=>{throw Rt=null,t}),Rt),Ht=t=>Number.isFinite(t)&&t!==0,vn=t=>{var i,N;const s=Number((i=t.location)==null?void 0:i.lng),a=Number((N=t.location)==null?void 0:N.lat),n={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:a,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!n.division_id||!n.province||!n.city||!n.poi_id||!n.poi_name||!Ht(s)||!Ht(a)||s<-180||s>180||a<-90||a>90?null:n},wn=async(t,s)=>{if(!Ht(t)||!Ht(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await _n();return new Promise((n,i)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(j,P)=>{var L;if(j!=="complete"){if(j==="no_data"){n([]);return}i(new Error("高德地图附近地址查询失败,请稍后重试"));return}const g=(((L=P==null?void 0:P.poiList)==null?void 0:L.pois)||[]).map(vn).filter(f=>f!==null);n(g)})})},kn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),_s=t=>t==="running"||t==="canceling",Cn=t=>!!(t!=null&&t.preview_id&&Number(t.valid||0)>0),Sn=t=>!!(t!=null&&t.id&&Number(t.retryable||0)>0&&!_s(t.status)),Ln=(t,s)=>t===s,ca=t=>{switch(t){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return t||"-"}},da=t=>{switch(t){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},In=t=>{const[s,a]=l.useState(!1),[n,i]=l.useState("upload"),[N,j]=l.useState(null),[P,g]=l.useState(null),[L,f]=l.useState(""),[F,ee]=l.useState(!1),[de,X]=l.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[y,V]=l.useState(null),[D,G]=l.useState(null),[Y,he]=l.useState(null),[be,fe]=l.useState([]),[k,ae]=l.useState(null),[ce,z]=l.useState(!1),ue=l.useRef(!1),Q=l.useRef(0),S=l.useCallback(async()=>{i("upload"),V(null),G(null),j(null),g(null),f(""),X({catId:"",catName:"",channelCatId:"",tbCatId:""}),fe([]),ae(null),a(!0),z(!0);try{const w=await Ma(20),J=kn(w);if(J!=null&&J.id){const xe=await yt(J.id);he(xe),G(xe),i(["running","canceling"].includes(xe.status)?"running":"done")}}catch(w){console.error("恢复最近批量铺货任务失败:",w)}finally{z(!1)}},[]),B=l.useCallback(async()=>{const w=L.trim();if(!t.selectedAccount){alert("请先选择默认发布账号"); Line truncated
`),Me=new Blob(["\uFEFF"+ye],{type:"text/csv;charset=utf-8"}),Qe=URL.createObjectURL(Me),We=document.createElement("a");We.href=Qe,We.download="批量铺货模板.csv",document.body.appendChild(We),We.click(),We.remove(),URL.revokeObjectURL(Qe)},Lt=()=>{le(c=>({...c,cookie_id:P||c.cookie_id})),G(!0)},pt=()=>{K(c=>({...c,cookie_id:P||c.cookie_id})),he(!0)},ht=async c=>{if(!(c?P:$.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");fe(!0),navigator.geolocation.getCurrentPosition(async ye=>{try{const Me=await wn(ye.coords.longitude,ye.coords.latitude);if(!Me.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");c?(b(Me),C(Me[0])):(ae(Me),z(Me[0]))}catch(Me){alert((Me==null?void 0:Me.message)||"获取发货地失败")}finally{fe(!1)}},ye=>{fe(!1),alert(ye.code===ye.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},It=c=>n.filter(T=>T.cookie_id===c.cookie_id&&T.item_id===c.item_id).length>0?n.filter(T=>T.cookie_id===c.cookie_id&&T.item_id===c.item_id):n.filter(T=>T.cookie_id===c.cookie_id&&!T.item_id),it=l.useMemo(()=>new Map(N.map(c=>[c.id,c])),[N]),gt=l.useMemo(()=>L?s.filter(c=>c.cookie_id===L):s,[L,s]),tt=c=>{const T=it.get(c),ye=(T==null?void 0:T.remark)||(T==null?void 0:T.nickname);return ye?`${ye} · ${c.slice(0,6)}`:`账号 ${c.slice(0,8)}`},bt=c=>{const T=it.get(c);return(T==null?void 0:T.remark)||(T==null?void 0:T.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(ml,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:L,onChange:c=>f(c.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),N.map(c=>e.jsx("option",{value:c.id,children:tt(c.id)},c.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(ut,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:P,onChange:c=>g(c.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),N.map(c=>e.jsx("option",{value:c.id,children:tt(c.id)},c.id))]})]})]}),e.jsxs("button",{onClick:O,disabled:F||!P,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Ve,{className:`w-4 h-4 ${F?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Lt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(at,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:pt,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(es,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void U(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Bt,{className:"w-4 h-4"}),se&&["running","canceling"].includes(se.status)?"继续批量任务":"批量铺货"]}),se&&!["running","canceling"].includes(se.status)&&e.jsx("button",{onClick:()=>void Oe(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[gt.map(c=>{const T=It(c),ye=T.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex Line truncated
+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-beu7QHqR.js"></script>
<script type="module" crossorigin src="/static/assets/index-cbea0zA7.js"></script>
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-C_od1ZSF.js">
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-BpMgNNfy.js">
<link rel="modulepreload" crossorigin href="/static/assets/vendor-D-Edl3pr.js">
<link rel="modulepreload" crossorigin href="/static/assets/charts-vendor-BxxJOyEX.js">
<link rel="stylesheet" crossorigin href="/static/assets/index-LhxzNkZL.css">
<link rel="stylesheet" crossorigin href="/static/assets/index-DMbguo3K.css">
</head>
<body>
<div id="root"></div>