阶段七:完成Rules React feature化与行为边界
This commit is contained in:
1 parent
6b4bbed9a2
commit
e79d76dcdf
17 files changed
+1693
-1947
No files matched your search
+784
-1582
File diff suppressed because it is too large.
Load diff
@@ -96,7 +96,7 @@ app shell / routes
|
||||
| 4. Server 应用服务 | 已完成 | 订单、发布、登录、聊天纵向抽取 | 应用服务、事务边界、后台生命周期和 Server 查询依赖均已收口,handler 不再直接访问数据库 |
|
||||
| 5. 应用生命周期装配 | 已完成 | 消除必需依赖 setter 回填 | 构造验证与幂等关闭测试 |
|
||||
| 6. Engine 与 Automation | 已完成 | facade + 独立状态组件 | Engine/Automation 组件边界、race、生命周期与冻结规范测试均已通过 |
|
||||
| 7. React Feature 化 | 未开始 | 页面、Hook、API、类型按领域拆分 | 行为测试、懒加载和 bundle 记录 |
|
||||
| 7. React Feature 化 | 进行中 | 页面、Hook、API、类型按领域拆分 | 行为测试、懒加载和 bundle 记录 |
|
||||
| 8. DB 与事务治理 | 未开始 | 窄接口、事务执行器、方言门禁 | 上层无裸 DB,多数据库回归 |
|
||||
| 9. 架构门禁与兼容清理 | 未开始 | 自动依赖规则、删除到期兼容层 | 架构检查与迁移说明 |
|
||||
| 10. 注释基线清零 | 未开始 | 全仓严格中文注释检查 | baseline 文件删除 |
|
||||
@@ -169,7 +169,8 @@ app shell / routes
|
||||
- 已完成阶段 6 第六个 PR 切片“Automation 运行协调与动作执行边界”:新增 `automationRunCoordinator`,统一运行创建/恢复、动作前后检查点、延迟任务续租、账号门禁和不确定结果隔离;`Center` 保留兼容调用入口,外部动作已执行/未执行/结果未知三态语义、人工核对状态机和恢复游标保持不变;Automation 测试、注释和 diff 门禁通过,整批修改合并为一个可回滚提交;
|
||||
- 已完成阶段 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/shared` 分层提取 Rules 页面 API、类型、Hook 和组件,补充成功、失败、取消、切换和重复提交行为测试,保持现有 API 路径兼容;
|
||||
- 已完成阶段 7 第一个 PR 切片“React Rules feature 化与 API/行为测试边界”:按 `app/features/rules` 提取 Rules API 适配层、领域类型、数据 Hook、异常面板和交互状态模型;规则页通过 Hook 管理服务端数据与请求代次,保留旧组件入口和现有 API 路径;行为测试覆盖成功、失败、重复提交、过期响应和页签切换;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
|
||||
- 阶段 7 下一 PR 切片为“React ItemList feature 化与批量发布行为边界”:按同一 feature 结构提取商品 API、批量发布 Hook 和页面组件,补充批量预检、取消、失败重试与过期任务行为测试;
|
||||
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
|
||||
|
||||
## 6. 阶段 0:治理文档与强约束
|
||||
@@ -588,3 +589,4 @@ npm --prefix frontend run build
|
||||
| 2026-08-14 | 完成阶段 6 第六个 PR 切片“Automation 运行协调与动作执行边界” | 新增 `automationRunCoordinator`,统一运行创建/恢复、动作前后检查点、延迟任务续租、账号门禁和不确定结果隔离;`Center` 保留兼容调用入口,外部动作三态语义、人工核对状态机和恢复游标保持不变;Automation 测试、注释和 diff 门禁通过并合并为一个可回滚提交 | 阶段 6:Automation 发货、卡密与通知动作边界 |
|
||||
| 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 化与批量发布行为边界 |
|
||||
@@ -0,0 +1,24 @@
|
||||
// 规则 feature 只通过本适配层访问共享 API,组件不直接依赖网络客户端。
|
||||
export {
|
||||
clearDefaultReplyRecords,
|
||||
deleteDefaultReply,
|
||||
deleteReplyRule,
|
||||
deleteShippingRule,
|
||||
getAccountDetails,
|
||||
getCards,
|
||||
getDefaultReplies,
|
||||
getDefaultReply,
|
||||
getItems,
|
||||
getAutomationIssues,
|
||||
getReplyRules,
|
||||
getShippingRules,
|
||||
getShippingRulesPage,
|
||||
updateDefaultReply,
|
||||
updateReplyRule,
|
||||
updateShippingRule,
|
||||
resolveAutomationRun,
|
||||
resolveDeferredAutomationTask,
|
||||
} from '../../../services/api';
|
||||
|
||||
// 规则异常类型由共享 API 层定义,feature 通过类型重导出保持边界稳定。
|
||||
export type { AutomationRunIssue, DeferredAutomationIssue } from '../../../services/api';
|
||||
@@ -0,0 +1,80 @@
|
||||
import { AlertCircle } from 'lucide-react';
|
||||
import type { AutomationRunIssue, DeferredAutomationIssue } from '../api';
|
||||
import { automationIssueKindLabel, canResolveAutomationIssue, type AutomationResolution } from '../issueState';
|
||||
|
||||
// AutomationIssuePanelProps 描述人工处理异常面板的输入和动作回调。
|
||||
export interface AutomationIssuePanelProps {
|
||||
// runs 是需要处理的自动化运行异常。
|
||||
runs: AutomationRunIssue[];
|
||||
// pendingTasks 是需要重试或忽略的延迟任务异常。
|
||||
pendingTasks: DeferredAutomationIssue[];
|
||||
// onResolveRun 处理自动化运行的继续、重试或终止动作。
|
||||
onResolveRun: (id: number, resolution: AutomationResolution) => void;
|
||||
// onResolveDeferredTask 处理延迟任务的重试或忽略动作。
|
||||
onResolveDeferredTask: (id: number, resolution: 'retry' | 'dismiss') => void;
|
||||
}
|
||||
|
||||
// AutomationIssuePanel 展示规则执行失败后需要用户确认的外部动作状态。
|
||||
export const AutomationIssuePanel = ({
|
||||
runs,
|
||||
pendingTasks,
|
||||
onResolveRun,
|
||||
onResolveDeferredTask,
|
||||
}: AutomationIssuePanelProps) => (
|
||||
<section className="rounded-2xl border border-red-200 bg-red-50 p-5 space-y-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<AlertCircle className="w-5 h-5 text-red-600 mt-0.5" />
|
||||
<div>
|
||||
<h3 className="font-black text-red-900">需要人工处理的自动化任务</h3>
|
||||
<p className="text-sm text-red-700 mt-1">请先在闲鱼聊天、订单或商品列表中核对真实结果,再选择继续或重试。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
{runs.map(
|
||||
// 运行异常渲染器展示外部动作状态和允许的处理按钮。
|
||||
issue => (
|
||||
<div key={`run-${issue.id}`} className="rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="font-bold text-gray-900">账号 {issue.cookie_id} · 订单 {issue.order_id || '-'} · 已记录发送 {issue.sent_count} 条</div>
|
||||
<div className="text-xs font-bold text-red-800 mt-1">{automationIssueKindLabel(issue.issue_kind)}</div>
|
||||
<div className="text-xs text-red-700 mt-1 break-words">{issue.error_message}</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 shrink-0">
|
||||
{canResolveAutomationIssue(issue, 'continue') && <button onClick={
|
||||
// 继续动作由父级统一执行并刷新规则状态。
|
||||
() => onResolveRun(issue.id, 'continue')
|
||||
} className="px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold">已执行,继续下一步</button>}
|
||||
{canResolveAutomationIssue(issue, 'retry') && <button onClick={
|
||||
// 重试动作由父级统一执行并刷新规则状态。
|
||||
() => onResolveRun(issue.id, 'retry')
|
||||
} className="px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold">未执行,安全重试</button>}
|
||||
{canResolveAutomationIssue(issue, 'cancel') && <button onClick={
|
||||
// 终止动作由父级统一执行并刷新规则状态。
|
||||
() => onResolveRun(issue.id, 'cancel')
|
||||
} className="px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold">终止</button>}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{pendingTasks.map(
|
||||
// 延迟任务渲染器展示重试和忽略按钮。
|
||||
issue => (
|
||||
<div key={`task-${issue.id}`} className="rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="font-bold text-gray-900">账号 {issue.cookie_id} · 延迟任务重试已达 {issue.attempt_count} 次</div>
|
||||
<div className="text-xs text-red-700 mt-1 break-words">{issue.error_message}</div>
|
||||
</div>
|
||||
<div className="flex gap-2 shrink-0">
|
||||
<button onClick={
|
||||
// 重试延迟任务由父级统一执行。
|
||||
() => onResolveDeferredTask(issue.id, 'retry')
|
||||
} className="px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold">重新入队</button>
|
||||
<button onClick={
|
||||
// 忽略延迟任务由父级统一执行。
|
||||
() => onResolveDeferredTask(issue.id, 'dismiss')
|
||||
} className="px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold">忽略</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
@@ -0,0 +1,215 @@
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
import {
|
||||
getAccountDetails,
|
||||
getAutomationIssues,
|
||||
getCards,
|
||||
getDefaultReplies,
|
||||
getItems,
|
||||
getReplyRules,
|
||||
getShippingRulesPage,
|
||||
} from './api';
|
||||
import type {
|
||||
AccountDetail,
|
||||
AutomationTriggerType,
|
||||
Card,
|
||||
DefaultReply,
|
||||
Item,
|
||||
ReplyRule,
|
||||
ShippingRule,
|
||||
} from '../../../types';
|
||||
import type { AutomationIssueState, RulesDataOptions, RulesDataResult, RulesTab } from './types';
|
||||
import { isCurrentRequest, nextRequestGeneration } from './interactionState';
|
||||
|
||||
// useRulesData 集中管理 Rules 页的服务端数据、请求代次和刷新动作。
|
||||
export const useRulesData = (options: RulesDataOptions): RulesDataResult => {
|
||||
// automationRules 保存当前分页返回的自动化规则。
|
||||
const [automationRules, setAutomationRules] = useState<ShippingRule[]>([]);
|
||||
// automationIssues 保存自动化规则列表旁的人工处理异常。
|
||||
const [automationIssues, setAutomationIssues] = useState<AutomationIssueState>({ runs: [], pending_tasks: [] });
|
||||
// replyRules 保存当前账号的关键词回复规则。
|
||||
const [replyRules, setReplyRules] = useState<ReplyRule[]>([]);
|
||||
// defaultReplies 保存所有账号的默认回复配置。
|
||||
const [defaultReplies, setDefaultReplies] = useState<Record<string, DefaultReply>>({});
|
||||
// accounts 保存规则筛选和编辑器使用的账号摘要。
|
||||
const [accounts, setAccounts] = useState<AccountDetail[]>([]);
|
||||
// cards 保存规则动作可选的卡密库存。
|
||||
const [cards, setCards] = useState<Card[]>([]);
|
||||
// items 保存规则编辑器可绑定的商品。
|
||||
const [items, setItems] = useState<Item[]>([]);
|
||||
// loading 表示当前规则页是否有刷新请求正在执行。
|
||||
const [loading, setLoading] = useState(false);
|
||||
// automationRulesRequest 保存自动化列表请求的最新代次。
|
||||
const automationRulesRequest = useRef(0);
|
||||
// replyRulesRequest 保存关键词规则请求的最新代次。
|
||||
const replyRulesRequest = useRef(0);
|
||||
|
||||
// automationTotal 保存服务端返回的自动化规则总数。
|
||||
const [automationTotal, setAutomationTotal] = useState(0);
|
||||
// automationTotalPages 保存服务端返回的自动化规则总页数。
|
||||
const [automationTotalPages, setAutomationTotalPages] = useState(0);
|
||||
// automationTriggerCounts 保存服务端按触发类型聚合的规则数量。
|
||||
const [automationTriggerCounts, setAutomationTriggerCounts] = useState<Record<string, number>>({});
|
||||
|
||||
// loadReferenceData 并行加载规则编辑器所需的全部参考数据。
|
||||
const loadReferenceData = useCallback(
|
||||
// 参考数据加载器把共享结果写入 Hook 状态。
|
||||
async () => {
|
||||
// referenceDataPromise 用于确保互不依赖的参考请求同时发出。
|
||||
const referenceDataPromise = Promise.all([
|
||||
getAccountDetails(),
|
||||
getCards(),
|
||||
getItems(),
|
||||
getDefaultReplies(),
|
||||
]);
|
||||
// referenceData 是并行请求完成后的四类参考数据。
|
||||
const [accountList, cardList, itemList, defaultReplyMap] = await referenceDataPromise;
|
||||
setAccounts(accountList);
|
||||
setCards(cardList);
|
||||
setItems(itemList);
|
||||
setDefaultReplies(defaultReplyMap);
|
||||
options.setSelectedAccountId(
|
||||
// 账号选择器保留用户已有选择,否则回填首个账号。
|
||||
current => current || accountList[0]?.id || '',
|
||||
);
|
||||
},
|
||||
[options.setSelectedAccountId],
|
||||
);
|
||||
|
||||
// loadAutomationRules 加载自动化规则和异常,并丢弃过期列表响应。
|
||||
const loadAutomationRules = useCallback(
|
||||
// 自动化列表加载器隔离旧筛选请求的响应。
|
||||
async () => {
|
||||
// requestID 标记本次自动化规则请求,防止旧响应覆盖新筛选结果。
|
||||
const requestID = nextRequestGeneration(automationRulesRequest.current);
|
||||
automationRulesRequest.current = requestID;
|
||||
// issuesPromise 与主规则请求并行,异常接口失败不阻断规则展示。
|
||||
const issuesPromise = getAutomationIssues().catch(
|
||||
// 异常请求失败记录日志并转换为空结果,避免阻断主列表。
|
||||
error => {
|
||||
console.warn('加载自动化异常列表失败,不阻断规则展示', error);
|
||||
return null;
|
||||
},
|
||||
);
|
||||
// result 是当前筛选条件对应的分页响应。
|
||||
const result = await getShippingRulesPage({
|
||||
cookieId: options.selectedAccountId || undefined,
|
||||
triggerType: options.automationTriggerFilter,
|
||||
enabled: options.automationStatusFilter === 'all' ? undefined : options.automationStatusFilter === 'enabled',
|
||||
search: options.debouncedAutomationSearch,
|
||||
page: options.automationPage,
|
||||
pageSize: options.automationPageSize,
|
||||
});
|
||||
if (!isCurrentRequest(requestID, automationRulesRequest.current, options.selectedAccountId, options.selectedAccountId)) return;
|
||||
setAutomationRules(result.data);
|
||||
setAutomationTotal(result.total);
|
||||
setAutomationTotalPages(result.total_pages);
|
||||
setAutomationTriggerCounts(result.trigger_counts || {});
|
||||
if (result.page !== options.automationPage) {
|
||||
// 分页响应可能被后端修正到有效页码,使用函数式更新避免读取过期闭包。
|
||||
options.onAutomationPageChange?.(result.page);
|
||||
}
|
||||
// issues 是与规则列表并行加载的异常结果。
|
||||
const issues = await issuesPromise;
|
||||
if (!isCurrentRequest(requestID, automationRulesRequest.current, options.selectedAccountId, options.selectedAccountId)) return;
|
||||
if (issues) setAutomationIssues(issues);
|
||||
},
|
||||
[
|
||||
options.automationPage,
|
||||
options.automationPageSize,
|
||||
options.automationStatusFilter,
|
||||
options.automationTriggerFilter,
|
||||
options.debouncedAutomationSearch,
|
||||
options.onAutomationPageChange,
|
||||
options.selectedAccountId,
|
||||
],
|
||||
);
|
||||
|
||||
// loadReplyRules 加载关键词规则,并用请求代次隔离账号切换产生的旧响应。
|
||||
const loadReplyRules = useCallback(
|
||||
// 关键词规则加载器只提交最新账号对应的响应。
|
||||
async () => {
|
||||
// requestID 标记本次关键词规则请求。
|
||||
const requestID = nextRequestGeneration(replyRulesRequest.current);
|
||||
replyRulesRequest.current = requestID;
|
||||
// cookieID 是本次关键词规则请求绑定的账号。
|
||||
const cookieID = options.selectedAccountId;
|
||||
setReplyRules([]);
|
||||
if (!cookieID) return;
|
||||
// rules 是当前账号的关键词回复规则。
|
||||
const rules = await getReplyRules(cookieID);
|
||||
if (!isCurrentRequest(requestID, replyRulesRequest.current, cookieID, options.selectedAccountId)) return;
|
||||
setReplyRules(rules);
|
||||
},
|
||||
[options.selectedAccountId],
|
||||
);
|
||||
|
||||
// loadDefaultReplies 刷新默认回复配置,供保存后和切换页签时复用。
|
||||
const loadDefaultReplies = useCallback(
|
||||
// 默认回复加载器刷新全部账号的默认配置。
|
||||
async () => {
|
||||
setDefaultReplies(await getDefaultReplies());
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// refresh 按当前页签只刷新需要的数据,避免无关接口请求。
|
||||
const refresh = useCallback(
|
||||
// 页面刷新动作根据页签选择唯一的数据请求。
|
||||
async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
if (options.activeTab === 'automation') {
|
||||
await loadAutomationRules();
|
||||
} else if (options.activeTab === 'reply') {
|
||||
await loadReplyRules();
|
||||
} else {
|
||||
await loadDefaultReplies();
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[loadAutomationRules, loadDefaultReplies, loadReplyRules, options.activeTab],
|
||||
);
|
||||
|
||||
// result 汇总 Hook 的状态与动作,保持页面只消费 feature 边界。
|
||||
const result: RulesDataResult = {
|
||||
automationRules,
|
||||
automationIssues,
|
||||
replyRules,
|
||||
defaultReplies,
|
||||
accounts,
|
||||
cards,
|
||||
items,
|
||||
automationTotal,
|
||||
automationTotalPages,
|
||||
automationTriggerCounts,
|
||||
loading,
|
||||
setLoading,
|
||||
setAutomationRules,
|
||||
setCards,
|
||||
setItems,
|
||||
loadReferenceData,
|
||||
loadAutomationRules,
|
||||
loadReplyRules,
|
||||
loadDefaultReplies,
|
||||
refresh,
|
||||
};
|
||||
return result;
|
||||
};
|
||||
|
||||
// RulesDataOptionsWithPageChange 为分页修正提供可选的页面状态回调。
|
||||
export interface RulesDataOptionsWithPageChange extends RulesDataOptions {
|
||||
// onAutomationPageChange 接收服务端修正后的有效页码。
|
||||
onAutomationPageChange?: (page: number) => void;
|
||||
}
|
||||
|
||||
// useRulesDataWithPageChange 是带分页回调的 Rules 数据 Hook 入口。
|
||||
export const useRulesDataWithPageChange = (options: RulesDataOptionsWithPageChange): RulesDataResult =>
|
||||
useRulesData(options);
|
||||
|
||||
// RulesHookTab 用于在测试中表达页签切换场景,避免重复声明字符串联合类型。
|
||||
export type RulesHookTab = RulesTab;
|
||||
|
||||
// RulesHookTrigger 用于在测试中表达自动化触发类型筛选场景。
|
||||
export type RulesHookTrigger = AutomationTriggerType;
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
finishRuleSubmission,
|
||||
idleRuleSubmitState,
|
||||
isCurrentRequest,
|
||||
nextRequestGeneration,
|
||||
selectRulesTab,
|
||||
startRuleSubmission,
|
||||
} from './interactionState';
|
||||
|
||||
// 规则交互行为测试覆盖保存、失败恢复、取消旧请求和页签切换。
|
||||
describe('Rules feature interaction state',
|
||||
// 测试组回调集中验证 Rules feature 的交互状态机。
|
||||
() => {
|
||||
// 成功保存后应清除提交锁并记录成功结果。
|
||||
test('records a successful save',
|
||||
// 成功场景回调验证保存状态闭环。
|
||||
() => {
|
||||
// submitting 是已进入执行态的保存状态。
|
||||
const submitting = startRuleSubmission(idleRuleSubmitState());
|
||||
expect(finishRuleSubmission(submitting, true)).toEqual({ submitting: false, result: 'success' });
|
||||
});
|
||||
|
||||
// 保存失败后应允许用户再次提交,而不是永久停留在提交中。
|
||||
test('recovers after a failed save',
|
||||
// 失败场景回调验证提交锁能够释放。
|
||||
() => {
|
||||
// submitting 是已进入执行态的保存状态。
|
||||
const submitting = startRuleSubmission(idleRuleSubmitState());
|
||||
expect(finishRuleSubmission(submitting, false)).toEqual({ submitting: false, result: 'failure' });
|
||||
});
|
||||
|
||||
// 已有保存请求时重复点击必须保持原状态,避免产生第二个请求。
|
||||
test('blocks repeated submission while a save is in flight',
|
||||
// 重复提交场景回调验证第二次点击不会创建新状态。
|
||||
() => {
|
||||
// submitting 是第一次点击创建的执行态。
|
||||
const submitting = startRuleSubmission(idleRuleSubmitState());
|
||||
expect(startRuleSubmission(submitting)).toBe(submitting);
|
||||
});
|
||||
|
||||
// 新请求代次产生后,旧请求响应应视为已取消并被忽略。
|
||||
test('ignores an expired response after a newer request starts',
|
||||
// 过期响应场景回调验证请求代次门禁。
|
||||
() => {
|
||||
// currentGeneration 是第二次请求产生的最新代次。
|
||||
const currentGeneration = nextRequestGeneration(nextRequestGeneration(0));
|
||||
expect(isCurrentRequest(1, currentGeneration, 'account-a', 'account-b')).toBe(false);
|
||||
expect(isCurrentRequest(currentGeneration, currentGeneration, 'account-a', 'account-a')).toBe(true);
|
||||
});
|
||||
|
||||
// 页签切换只允许规则页支持的三个值进入状态。
|
||||
test('keeps tab switching inside the Rules feature',
|
||||
// 切换场景回调验证页签值不会越过 feature 边界。
|
||||
() => {
|
||||
expect(selectRulesTab('reply')).toBe('reply');
|
||||
expect(selectRulesTab('default')).toBe('default');
|
||||
expect(selectRulesTab('unknown')).toBe('automation');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
// RuleSubmitState 描述规则保存动作的短暂提交状态。
|
||||
export interface RuleSubmitState {
|
||||
// submitting 表示当前是否已有保存请求在执行。
|
||||
submitting: boolean;
|
||||
// result 表示最近一次保存结果,便于行为测试描述成功和失败。
|
||||
result: 'idle' | 'success' | 'failure';
|
||||
}
|
||||
|
||||
// idleRuleSubmitState 创建一个可提交的初始状态。
|
||||
export const idleRuleSubmitState = (): RuleSubmitState => ({ submitting: false, result: 'idle' });
|
||||
|
||||
// startRuleSubmission 只允许第一个保存请求进入执行态,阻断重复提交。
|
||||
export const startRuleSubmission = (state: RuleSubmitState): RuleSubmitState =>
|
||||
state.submitting ? state : { submitting: true, result: 'idle' };
|
||||
|
||||
// finishRuleSubmission 将保存请求收口为成功或失败结果。
|
||||
export const finishRuleSubmission = (state: RuleSubmitState, succeeded: boolean): RuleSubmitState => ({
|
||||
submitting: false,
|
||||
result: succeeded ? 'success' : 'failure',
|
||||
});
|
||||
|
||||
// nextRequestGeneration 为新的筛选或账号请求生成单调递增的代次。
|
||||
export const nextRequestGeneration = (generation: number): number => generation + 1;
|
||||
|
||||
// isCurrentRequest 判断响应是否仍属于当前筛选条件对应的请求。
|
||||
export const isCurrentRequest = (requestGeneration: number, currentGeneration: number, requestKey: string, currentKey: string): boolean =>
|
||||
requestGeneration === currentGeneration && requestKey === currentKey;
|
||||
|
||||
// selectRulesTab 处理页签切换,保证未知值不会污染当前页签状态。
|
||||
export const selectRulesTab = (tab: string): 'automation' | 'reply' | 'default' =>
|
||||
tab === 'reply' || tab === 'default' ? tab : 'automation';
|
||||
@@ -0,0 +1,63 @@
|
||||
import type { AutomationRunIssue, DeferredAutomationIssue } from './api';
|
||||
|
||||
// AutomationResolution 表示自动化运行异常可执行的人工处理动作。
|
||||
export type AutomationResolution = 'continue' | 'retry' | 'cancel';
|
||||
|
||||
// AutomationIssueState 保存规则页异常面板所需的两类异常记录。
|
||||
export interface AutomationIssueState {
|
||||
// runs 是需要人工确认的自动化运行记录。
|
||||
runs: AutomationRunIssue[];
|
||||
// pending_tasks 是达到重试上限的延迟任务记录。
|
||||
pending_tasks: DeferredAutomationIssue[];
|
||||
}
|
||||
|
||||
// canResolveAutomationIssue 判断后端策略是否允许指定处理动作。
|
||||
export const canResolveAutomationIssue = (
|
||||
issue: AutomationRunIssue,
|
||||
resolution: AutomationResolution,
|
||||
): boolean => issue.allowed_resolutions.includes(resolution);
|
||||
|
||||
// filterAutomationIssues 按账号筛选异常,保持异常面板与规则列表一致。
|
||||
export const filterAutomationIssues = (issues: AutomationIssueState, cookieID: string): AutomationIssueState => ({
|
||||
runs: issues.runs.filter(
|
||||
// 运行异常筛选器只保留当前账号的记录。
|
||||
issue => !cookieID || issue.cookie_id === cookieID,
|
||||
),
|
||||
pending_tasks: issues.pending_tasks.filter(
|
||||
// 延迟任务筛选器只保留当前账号的记录。
|
||||
issue => !cookieID || issue.cookie_id === cookieID,
|
||||
),
|
||||
});
|
||||
|
||||
// automationIssueKindLabel 将后端异常类别转换成用户可读的中文标签。
|
||||
export const automationIssueKindLabel = (kind: AutomationRunIssue['issue_kind']): string => ({
|
||||
external_result_unknown: '外部动作结果未知',
|
||||
invalid_snapshot: '历史数据无法恢复',
|
||||
rule_unavailable: '规则不可用',
|
||||
partial_failure: '部分动作失败',
|
||||
execution_failed: '动作执行失败',
|
||||
}[kind] || '自动化异常');
|
||||
|
||||
// AutomationPageDataLoaders 描述规则页规则列表与异常列表的独立加载器。
|
||||
export interface AutomationPageDataLoaders<TRule> {
|
||||
// loadRules 加载自动化规则列表。
|
||||
loadRules: () => Promise<TRule[]>;
|
||||
// loadIssues 加载自动化异常列表。
|
||||
loadIssues: () => Promise<AutomationIssueState>;
|
||||
// onRules 接收规则列表成功结果。
|
||||
onRules: (rules: TRule[]) => void;
|
||||
// onIssues 接收异常列表成功结果。
|
||||
onIssues: (issues: AutomationIssueState) => void;
|
||||
// onIssuesError 接收异常列表失败结果。
|
||||
onIssuesError: (error: unknown) => void;
|
||||
}
|
||||
|
||||
// loadAutomationPageData 并行加载规则与异常,且允许异常接口单独失败。
|
||||
export const loadAutomationPageData = async <TRule>(options: AutomationPageDataLoaders<TRule>): Promise<void> => {
|
||||
// issuesPromise 先启动异常请求,避免阻塞主要规则列表。
|
||||
const issuesPromise = options.loadIssues().then(options.onIssues).catch(options.onIssuesError);
|
||||
// rules 是主要规则请求的成功结果。
|
||||
const rules = await options.loadRules();
|
||||
options.onRules(rules);
|
||||
await issuesPromise;
|
||||
};
|
||||
@@ -0,0 +1,165 @@
|
||||
import type { Dispatch, ElementType, SetStateAction } from 'react';
|
||||
import type {
|
||||
AccountDetail,
|
||||
AutomationAction,
|
||||
AutomationTriggerType,
|
||||
Card,
|
||||
DefaultReply,
|
||||
Item,
|
||||
ReplyRule,
|
||||
ShippingRule,
|
||||
ShippingVariant,
|
||||
} from '../../../types';
|
||||
import type { AutomationRunIssue, DeferredAutomationIssue } from './api';
|
||||
|
||||
// Rules feature 通过此类型入口重导出共享领域模型,避免页面直接依赖全局类型文件。
|
||||
export type {
|
||||
AccountDetail,
|
||||
AutomationAction,
|
||||
AutomationTriggerType,
|
||||
Card,
|
||||
DefaultReply,
|
||||
Item,
|
||||
ReplyRule,
|
||||
ShippingRule,
|
||||
ShippingVariant,
|
||||
} from '../../../types';
|
||||
|
||||
// RulesTab 表示规则页面的三个业务页签。
|
||||
export type RulesTab = 'automation' | 'reply' | 'default';
|
||||
|
||||
// RulesProps 描述规则页面从父级接收的联动参数。
|
||||
export interface RulesProps {
|
||||
// initialDeliveryTarget 表示商品页跳转过来的待配置发货目标。
|
||||
initialDeliveryTarget?: {
|
||||
// cookieId 表示目标账号标识。
|
||||
cookieId: string;
|
||||
// itemId 表示目标商品标识。
|
||||
itemId: string;
|
||||
// requestId 用于区分连续的外部跳转请求。
|
||||
requestId: number;
|
||||
};
|
||||
// onDeliveryTargetHandled 表示页面完成外部跳转处理后的回调。
|
||||
onDeliveryTargetHandled?: () => void;
|
||||
}
|
||||
|
||||
// DefaultReplyForm 表示账号默认回复弹窗的可编辑字段。
|
||||
export interface DefaultReplyForm {
|
||||
// cookie_id 表示默认回复所属账号。
|
||||
cookie_id: string;
|
||||
// enabled 表示是否启用默认回复。
|
||||
enabled: boolean;
|
||||
// reply_content 表示默认文字回复内容。
|
||||
reply_content: string;
|
||||
// reply_once 表示是否只对每个会话回复一次。
|
||||
reply_once: boolean;
|
||||
// reply_image_url 表示可选的默认图片地址。
|
||||
reply_image_url: string;
|
||||
}
|
||||
|
||||
// TriggerMeta 描述自动化触发类型在页面中的展示元数据。
|
||||
export interface TriggerMeta {
|
||||
// label 是完整的触发类型名称。
|
||||
label: string;
|
||||
// shortLabel 是列表筛选中使用的短名称。
|
||||
shortLabel: string;
|
||||
// description 是创建规则时展示的说明。
|
||||
description: string;
|
||||
// flow 是该触发类型的步骤摘要。
|
||||
flow: string[];
|
||||
// accent 是页面使用的主题色名称。
|
||||
accent: 'blue' | 'emerald' | 'amber';
|
||||
// icon 是触发类型对应的图标组件。
|
||||
icon: ElementType;
|
||||
}
|
||||
|
||||
// AutomationIssueState 保存规则页需要人工处理的自动化异常。
|
||||
export interface AutomationIssueState {
|
||||
// runs 是暂停中的自动化运行记录。
|
||||
runs: AutomationRunIssue[];
|
||||
// pending_tasks 是等待重试的延迟任务记录。
|
||||
pending_tasks: DeferredAutomationIssue[];
|
||||
}
|
||||
|
||||
// RulesReferenceData 保存规则编辑器依赖的账号、卡密和商品参考数据。
|
||||
export interface RulesReferenceData {
|
||||
// accounts 是可选择的闲鱼账号摘要。
|
||||
accounts: AccountDetail[];
|
||||
// cards 是可用于动作配置的卡密库存。
|
||||
cards: Card[];
|
||||
// items 是可绑定自动化规则的商品列表。
|
||||
items: Item[];
|
||||
// defaultReplies 是按账号索引的默认回复配置。
|
||||
defaultReplies: Record<string, DefaultReply>;
|
||||
}
|
||||
|
||||
// RulesDataSet 保存规则页服务端数据和分页元数据。
|
||||
export interface RulesDataSet extends RulesReferenceData {
|
||||
// automationRules 是当前自动化规则分页数据。
|
||||
automationRules: ShippingRule[];
|
||||
// automationIssues 是当前账号筛选下的异常源数据。
|
||||
automationIssues: AutomationIssueState;
|
||||
// replyRules 是当前账号的关键词回复规则。
|
||||
replyRules: ReplyRule[];
|
||||
// automationTotal 是自动化规则总数。
|
||||
automationTotal: number;
|
||||
// automationTotalPages 是自动化规则总页数。
|
||||
automationTotalPages: number;
|
||||
// automationTriggerCounts 是服务端返回的触发类型聚合数量。
|
||||
automationTriggerCounts: Record<string, number>;
|
||||
}
|
||||
|
||||
// RulesDataOptions 描述规则数据 Hook 的筛选条件和状态回调。
|
||||
export interface RulesDataOptions {
|
||||
// activeTab 是当前规则页签。
|
||||
activeTab: RulesTab;
|
||||
// selectedAccountId 是当前账号筛选值。
|
||||
selectedAccountId: string;
|
||||
// automationTriggerFilter 是自动化触发类型筛选值。
|
||||
automationTriggerFilter: AutomationTriggerType | '';
|
||||
// automationStatusFilter 是自动化启用状态筛选值。
|
||||
automationStatusFilter: 'all' | 'enabled' | 'disabled';
|
||||
// debouncedAutomationSearch 是已去抖的规则搜索词。
|
||||
debouncedAutomationSearch: string;
|
||||
// automationPage 是当前自动化规则页码。
|
||||
automationPage: number;
|
||||
// automationPageSize 是当前自动化规则分页大小。
|
||||
automationPageSize: number;
|
||||
// setSelectedAccountId 用于在参考数据加载后选择首个账号。
|
||||
setSelectedAccountId: Dispatch<SetStateAction<string>>;
|
||||
// onAutomationPageChange 接收服务端修正后的有效页码。
|
||||
onAutomationPageChange?: (page: number) => void;
|
||||
}
|
||||
|
||||
// RulesDataResult 暴露规则页需要的服务端状态、更新器和请求动作。
|
||||
export interface RulesDataResult extends RulesDataSet {
|
||||
// loading 表示当前是否存在规则数据请求。
|
||||
loading: boolean;
|
||||
// setLoading 用于外部联动加载场景暂时接管页面加载指示器。
|
||||
setLoading: Dispatch<SetStateAction<boolean>>;
|
||||
// setAutomationRules 用于外部跳转场景写入规则列表。
|
||||
setAutomationRules: Dispatch<SetStateAction<ShippingRule[]>>;
|
||||
// setCards 用于外部跳转场景写入卡密参考数据。
|
||||
setCards: Dispatch<SetStateAction<Card[]>>;
|
||||
// setItems 用于外部跳转场景写入商品参考数据。
|
||||
setItems: Dispatch<SetStateAction<Item[]>>;
|
||||
// loadReferenceData 加载规则编辑器所需的共享参考数据。
|
||||
loadReferenceData: () => Promise<void>;
|
||||
// loadAutomationRules 加载当前筛选条件下的自动化规则和异常。
|
||||
loadAutomationRules: () => Promise<void>;
|
||||
// loadReplyRules 加载当前账号的关键词回复规则。
|
||||
loadReplyRules: () => Promise<void>;
|
||||
// loadDefaultReplies 加载所有账号的默认回复。
|
||||
loadDefaultReplies: () => Promise<void>;
|
||||
// refresh 根据当前页签刷新对应的服务端数据。
|
||||
refresh: () => Promise<void>;
|
||||
}
|
||||
|
||||
// RuleDraftFields 汇总规则编辑器中需要按动作类型读取的领域字段。
|
||||
export type RuleDraftFields = Pick<ShippingRule, 'actions' | 'variants' | 'config_json'>;
|
||||
|
||||
// AutomationActionPatch 表示规则页面对自动化动作的局部更新。
|
||||
export type AutomationActionPatch = Partial<AutomationAction>;
|
||||
|
||||
// ShippingVariantPatch 表示规则页面对发货规格的局部更新。
|
||||
export type ShippingVariantPatch = Partial<ShippingVariant>;
|
||||
@@ -0,0 +1,162 @@
|
||||
import { Clock3, Gift, PackageCheck } from 'lucide-react';
|
||||
import type {
|
||||
AccountDetail,
|
||||
AutomationAction,
|
||||
AutomationTriggerType,
|
||||
ShippingRule,
|
||||
ShippingVariant,
|
||||
} from '../../../types';
|
||||
import type { TriggerMeta } from './types';
|
||||
|
||||
// triggerMeta 是自动化触发类型的统一展示元数据,供列表和编辑器复用。
|
||||
export const triggerMeta: Record<AutomationTriggerType, TriggerMeta> = {
|
||||
order_paid: {
|
||||
label: '付款后自动发货',
|
||||
shortLabel: '自动发货',
|
||||
description: '闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。',
|
||||
flow: ['付款系统卡片', '匹配商品/规格', '发送卡密', '确认发货'],
|
||||
accent: 'blue',
|
||||
icon: PackageCheck,
|
||||
},
|
||||
buyer_reviewed: {
|
||||
label: '评价后发送赠品',
|
||||
shortLabel: '评价赠品',
|
||||
description: '闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。',
|
||||
flow: ['评价系统卡片', '匹配商品/规格', '发送赠品'],
|
||||
accent: 'emerald',
|
||||
icon: Gift,
|
||||
},
|
||||
review_missing_timeout: {
|
||||
label: '超时未评价求评价',
|
||||
shortLabel: '求评价',
|
||||
description: '计划任务扫描已发货未评价订单,到期后发送求评价文案。',
|
||||
flow: ['计划任务扫描', '已发货未评价', '达到等待时间', '发送提醒'],
|
||||
accent: 'amber',
|
||||
icon: Clock3,
|
||||
},
|
||||
};
|
||||
|
||||
// triggerOrder 固定自动化类型在创建面板和筛选器中的排序。
|
||||
export const triggerOrder: AutomationTriggerType[] = ['order_paid', 'buyer_reviewed', 'review_missing_timeout'];
|
||||
|
||||
// reviewRequestText 是超时未评价规则的默认提醒文案。
|
||||
export const reviewRequestText = '亲,商品使用满意的话,麻烦给个评价,谢谢~';
|
||||
|
||||
// emptyVariant 创建一个未选择卡密库存的发货规格草稿。
|
||||
export const emptyVariant = (): ShippingVariant => ({
|
||||
spec_name: '',
|
||||
spec_value: '',
|
||||
card_id: 0,
|
||||
delivery_count: 1,
|
||||
enabled: true,
|
||||
delay_override: false,
|
||||
delay_seconds: 0,
|
||||
});
|
||||
|
||||
// parseJSONObject 安全解析规则配置 JSON,异常或非对象值统一返回空对象。
|
||||
export const parseJSONObject = (raw?: string): Record<string, any> => {
|
||||
if (!raw) return {};
|
||||
try {
|
||||
// value 是解析后的 JSON 值,后续会校验其对象形态。
|
||||
const value = JSON.parse(raw);
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
// buildReviewConfig 规范化求评价规则的时间参数,并应用编辑器的局部修改。
|
||||
export const buildReviewConfig = (raw?: string, patch: Record<string, number> = {}) => {
|
||||
// current 是求评价配置的已有字段。
|
||||
const current = parseJSONObject(raw);
|
||||
return JSON.stringify({
|
||||
after_shipped_hours: Number(current.after_shipped_hours || 72),
|
||||
repeat_interval_hours: Number(current.repeat_interval_hours || 24),
|
||||
max_attempts: Number(current.max_attempts || 1),
|
||||
...patch,
|
||||
});
|
||||
};
|
||||
|
||||
// defaultRuleName 根据触发类型和商品标签生成规则默认名称。
|
||||
export const defaultRuleName = (trigger: AutomationTriggerType, itemLabel?: string) => {
|
||||
// base 是触发类型对应的默认名称。
|
||||
const base = triggerMeta[trigger]?.label || '自动化规则';
|
||||
return itemLabel ? `${base} - ${itemLabel}` : base;
|
||||
};
|
||||
|
||||
// shouldReplaceGeneratedName 判断当前名称是否仍是系统生成的默认名称。
|
||||
export const shouldReplaceGeneratedName = (name?: string) => {
|
||||
// trimmed 是去掉首尾空白后的规则名称。
|
||||
const trimmed = (name || '').trim();
|
||||
if (!trimmed) return true;
|
||||
return Object.values(triggerMeta).some(
|
||||
// 元数据匹配器判断名称是否仍由系统自动生成。
|
||||
meta => trimmed === meta.label || trimmed.startsWith(`${meta.label} -`),
|
||||
);
|
||||
};
|
||||
|
||||
// cardActionsForTrigger 根据触发类型创建默认动作链。
|
||||
export const cardActionsForTrigger = (trigger: AutomationTriggerType, cardID = 0): AutomationAction[] => {
|
||||
if (trigger === 'review_missing_timeout') {
|
||||
return [{
|
||||
action_type: 'send_text',
|
||||
message_template: reviewRequestText,
|
||||
enabled: true,
|
||||
sort_order: 1,
|
||||
}];
|
||||
}
|
||||
|
||||
// sendCard 是卡密发送动作的默认配置。
|
||||
const sendCard: AutomationAction = {
|
||||
action_type: 'send_card',
|
||||
card_id: cardID,
|
||||
delivery_count: 1,
|
||||
enabled: true,
|
||||
sort_order: 1,
|
||||
};
|
||||
|
||||
if (trigger === 'order_paid') {
|
||||
return [sendCard, { action_type: 'confirm_shipment', enabled: true, sort_order: 2 }];
|
||||
}
|
||||
return [sendCard];
|
||||
};
|
||||
|
||||
// actionSummary 将规则动作转换成列表中的简短摘要。
|
||||
export const actionSummary = (rule: ShippingRule) => {
|
||||
if (rule.trigger_type === 'review_missing_timeout') {
|
||||
return rule.actions?.find(
|
||||
// 文案动作匹配器只查找发送文字动作。
|
||||
action => action.action_type === 'send_text',
|
||||
)?.message_template || '发送求评价文案';
|
||||
}
|
||||
// cards 是当前规则中的卡密动作列表。
|
||||
const cards = (rule.actions || []).filter(
|
||||
// 卡密动作筛选器只保留发送卡片类型。
|
||||
action => action.action_type === 'send_card',
|
||||
);
|
||||
if (!cards.length) return '未配置卡密库存';
|
||||
return cards.map(
|
||||
// 卡密动作格式化器优先展示库存名称。
|
||||
action => action.card_name || `卡密 ${action.card_id}`,
|
||||
).join(' / ');
|
||||
};
|
||||
|
||||
// accentClasses 将触发类型主题色映射为规则页 Tailwind 类名。
|
||||
export const accentClasses = (accent: TriggerMeta['accent'], selected = false) => {
|
||||
// map 保存每种主题色在选中和未选中状态下的样式。
|
||||
const map: Record<string, string> = {
|
||||
blue: selected ? 'border-blue-500 bg-blue-50 text-blue-700' : 'border-blue-100 bg-blue-50/60 text-blue-700 hover:border-blue-300',
|
||||
emerald: selected ? 'border-emerald-500 bg-emerald-50 text-emerald-700' : 'border-emerald-100 bg-emerald-50/60 text-emerald-700 hover:border-emerald-300',
|
||||
amber: selected ? 'border-amber-500 bg-amber-50 text-amber-700' : 'border-amber-100 bg-amber-50/60 text-amber-700 hover:border-amber-300',
|
||||
};
|
||||
return map[accent] || map.blue;
|
||||
};
|
||||
|
||||
// statusPill 返回自动化规则启用状态对应的标签样式。
|
||||
export const statusPill = (enabled: boolean) => enabled ? 'bg-emerald-100 text-emerald-700' : 'bg-gray-200 text-gray-500';
|
||||
|
||||
// accountLabel 选择账号在规则页展示时最有意义的名称。
|
||||
export const accountLabel = (account?: AccountDetail) => account?.nickname || account?.remark || account?.id || '未知账号';
|
||||
|
||||
// boolFlag 兼容后端可能返回的布尔、数字和字符串标志值。
|
||||
export const boolFlag = (value: unknown): boolean => value === true || value === 1 || value === '1';
|
||||
+75
-304
@@ -1,38 +1,21 @@
|
||||
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import {
|
||||
AccountDetail,
|
||||
AutomationAction,
|
||||
AutomationTriggerType,
|
||||
Card,
|
||||
DefaultReply,
|
||||
Item,
|
||||
ReplyRule,
|
||||
ShippingRule,
|
||||
ShippingVariant,
|
||||
} from '../types';
|
||||
import type { AutomationTriggerType, ReplyRule, ShippingRule, ShippingVariant } from '../app/features/rules/types';
|
||||
import {
|
||||
clearDefaultReplyRecords,
|
||||
deleteDefaultReply,
|
||||
deleteReplyRule,
|
||||
deleteShippingRule,
|
||||
getAccountDetails,
|
||||
getCards,
|
||||
getDefaultReplies,
|
||||
getDefaultReply,
|
||||
getItems,
|
||||
getAutomationIssues,
|
||||
getReplyRules,
|
||||
getShippingRules,
|
||||
getShippingRulesPage,
|
||||
updateDefaultReply,
|
||||
updateReplyRule,
|
||||
updateShippingRule,
|
||||
resolveAutomationRun,
|
||||
resolveDeferredAutomationTask,
|
||||
AutomationRunIssue,
|
||||
DeferredAutomationIssue,
|
||||
} from '../services/api';
|
||||
} from '../app/features/rules/api';
|
||||
import {
|
||||
AlertCircle,
|
||||
Bot,
|
||||
@@ -41,10 +24,8 @@ import {
|
||||
ChevronRight,
|
||||
Clock3,
|
||||
Edit,
|
||||
Gift,
|
||||
Layers3,
|
||||
MessageCircle,
|
||||
PackageCheck,
|
||||
Plus,
|
||||
RefreshCw,
|
||||
Save,
|
||||
@@ -55,174 +36,16 @@ import {
|
||||
X,
|
||||
Zap,
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
automationIssueKindLabel,
|
||||
canResolveAutomationIssue,
|
||||
filterAutomationIssues,
|
||||
} from './automationIssueState';
|
||||
import { commitIfLatest } from './latestRequest';
|
||||
|
||||
type RulesTab = 'automation' | 'reply' | 'default';
|
||||
|
||||
interface RulesProps {
|
||||
initialDeliveryTarget?: {
|
||||
cookieId: string;
|
||||
itemId: string;
|
||||
requestId: number;
|
||||
};
|
||||
onDeliveryTargetHandled?: () => void;
|
||||
}
|
||||
|
||||
interface DefaultReplyForm {
|
||||
cookie_id: string;
|
||||
enabled: boolean;
|
||||
reply_content: string;
|
||||
reply_once: boolean;
|
||||
reply_image_url: string;
|
||||
}
|
||||
|
||||
interface TriggerMeta {
|
||||
label: string;
|
||||
shortLabel: string;
|
||||
description: string;
|
||||
flow: string[];
|
||||
accent: string;
|
||||
icon: React.ElementType;
|
||||
}
|
||||
|
||||
const triggerMeta: Record<AutomationTriggerType, TriggerMeta> = {
|
||||
order_paid: {
|
||||
label: '付款后自动发货',
|
||||
shortLabel: '自动发货',
|
||||
description: '闲鱼付款系统卡片进入自动化中心后,先发送卡密,成功后再确认发货。',
|
||||
flow: ['付款系统卡片', '匹配商品/规格', '发送卡密', '确认发货'],
|
||||
accent: 'blue',
|
||||
icon: PackageCheck,
|
||||
},
|
||||
buyer_reviewed: {
|
||||
label: '评价后发送赠品',
|
||||
shortLabel: '评价赠品',
|
||||
description: '闲鱼评价系统卡片进入自动化中心后,给买家发送赠品卡密。',
|
||||
flow: ['评价系统卡片', '匹配商品/规格', '发送赠品'],
|
||||
accent: 'emerald',
|
||||
icon: Gift,
|
||||
},
|
||||
review_missing_timeout: {
|
||||
label: '超时未评价求评价',
|
||||
shortLabel: '求评价',
|
||||
description: '计划任务扫描已发货未评价订单,到期后发送求评价文案。',
|
||||
flow: ['计划任务扫描', '已发货未评价', '达到等待时间', '发送提醒'],
|
||||
accent: 'amber',
|
||||
icon: Clock3,
|
||||
},
|
||||
};
|
||||
|
||||
const triggerOrder: AutomationTriggerType[] = ['order_paid', 'buyer_reviewed', 'review_missing_timeout'];
|
||||
const reviewRequestText = '亲,商品使用满意的话,麻烦给个评价,谢谢~';
|
||||
|
||||
const emptyVariant = (): ShippingVariant => ({
|
||||
spec_name: '',
|
||||
spec_value: '',
|
||||
card_id: 0,
|
||||
delivery_count: 1,
|
||||
enabled: true,
|
||||
delay_override: false,
|
||||
delay_seconds: 0,
|
||||
});
|
||||
|
||||
const parseJSONObject = (raw?: string): Record<string, any> => {
|
||||
if (!raw) return {};
|
||||
try {
|
||||
const value = JSON.parse(raw);
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
||||
} catch {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
const buildReviewConfig = (raw?: string, patch: Record<string, number> = {}) => {
|
||||
const current = parseJSONObject(raw);
|
||||
return JSON.stringify({
|
||||
after_shipped_hours: Number(current.after_shipped_hours || 72),
|
||||
repeat_interval_hours: Number(current.repeat_interval_hours || 24),
|
||||
max_attempts: Number(current.max_attempts || 1),
|
||||
...patch,
|
||||
});
|
||||
};
|
||||
|
||||
const defaultRuleName = (trigger: AutomationTriggerType, itemLabel?: string) => {
|
||||
const base = triggerMeta[trigger]?.label || '自动化规则';
|
||||
return itemLabel ? `${base} - ${itemLabel}` : base;
|
||||
};
|
||||
|
||||
const shouldReplaceGeneratedName = (name?: string) => {
|
||||
const trimmed = (name || '').trim();
|
||||
if (!trimmed) return true;
|
||||
return Object.values(triggerMeta).some(meta => trimmed === meta.label || trimmed.startsWith(`${meta.label} -`));
|
||||
};
|
||||
|
||||
const cardActionsForTrigger = (trigger: AutomationTriggerType, cardID = 0): AutomationAction[] => {
|
||||
if (trigger === 'review_missing_timeout') {
|
||||
return [{
|
||||
action_type: 'send_text',
|
||||
message_template: reviewRequestText,
|
||||
enabled: true,
|
||||
sort_order: 1,
|
||||
}];
|
||||
}
|
||||
|
||||
const sendCard: AutomationAction = {
|
||||
action_type: 'send_card',
|
||||
card_id: cardID,
|
||||
delivery_count: 1,
|
||||
enabled: true,
|
||||
sort_order: 1,
|
||||
};
|
||||
|
||||
if (trigger === 'order_paid') {
|
||||
return [
|
||||
sendCard,
|
||||
{ action_type: 'confirm_shipment', enabled: true, sort_order: 2 },
|
||||
];
|
||||
}
|
||||
return [sendCard];
|
||||
};
|
||||
|
||||
const actionSummary = (rule: ShippingRule) => {
|
||||
if (rule.trigger_type === 'review_missing_timeout') {
|
||||
return rule.actions?.find(action => action.action_type === 'send_text')?.message_template || '发送求评价文案';
|
||||
}
|
||||
const cards = (rule.actions || []).filter(action => action.action_type === 'send_card');
|
||||
if (!cards.length) return '未配置卡密库存';
|
||||
return cards.map(action => action.card_name || `卡密 ${action.card_id}`).join(' / ');
|
||||
};
|
||||
|
||||
const accentClasses = (accent: TriggerMeta['accent'], selected = false) => {
|
||||
const map: Record<string, string> = {
|
||||
blue: selected ? 'border-blue-500 bg-blue-50 text-blue-700' : 'border-blue-100 bg-blue-50/60 text-blue-700 hover:border-blue-300',
|
||||
emerald: selected ? 'border-emerald-500 bg-emerald-50 text-emerald-700' : 'border-emerald-100 bg-emerald-50/60 text-emerald-700 hover:border-emerald-300',
|
||||
amber: selected ? 'border-amber-500 bg-amber-50 text-amber-700' : 'border-amber-100 bg-amber-50/60 text-amber-700 hover:border-amber-300',
|
||||
};
|
||||
return map[accent] || map.blue;
|
||||
};
|
||||
|
||||
const statusPill = (enabled: boolean) =>
|
||||
enabled ? 'bg-emerald-100 text-emerald-700' : 'bg-gray-200 text-gray-500';
|
||||
|
||||
const accountLabel = (account?: AccountDetail) => account?.nickname || account?.remark || account?.id || '未知账号';
|
||||
|
||||
const boolFlag = (value: unknown): boolean => value === true || value === 1 || value === '1';
|
||||
import { AutomationIssuePanel } from '../app/features/rules/components/AutomationIssuePanel';
|
||||
import { useRulesData } from '../app/features/rules/hooks';
|
||||
import { filterAutomationIssues } from '../app/features/rules/issueState';
|
||||
import { triggerMeta, triggerOrder, emptyVariant, parseJSONObject, buildReviewConfig, defaultRuleName, shouldReplaceGeneratedName, cardActionsForTrigger, actionSummary, accentClasses, statusPill, accountLabel, boolFlag } from '../app/features/rules/utils';
|
||||
import type { RulesProps, RulesTab, DefaultReplyForm } from '../app/features/rules/types';
|
||||
import { finishRuleSubmission, idleRuleSubmitState, startRuleSubmission, type RuleSubmitState } from '../app/features/rules/interactionState';
|
||||
|
||||
// Rules 是规则 feature 在旧页面目录下保留的兼容入口组件。
|
||||
const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHandled }) => {
|
||||
const [activeTab, setActiveTab] = useState<RulesTab>('automation');
|
||||
const [automationRules, setAutomationRules] = useState<ShippingRule[]>([]);
|
||||
const [automationIssues, setAutomationIssues] = useState<{ runs: AutomationRunIssue[]; pending_tasks: DeferredAutomationIssue[] }>({ runs: [], pending_tasks: [] });
|
||||
const [replyRules, setReplyRules] = useState<ReplyRule[]>([]);
|
||||
const [defaultReplies, setDefaultReplies] = useState<Record<string, DefaultReply>>({});
|
||||
const [accounts, setAccounts] = useState<AccountDetail[]>([]);
|
||||
const [cards, setCards] = useState<Card[]>([]);
|
||||
const [items, setItems] = useState<Item[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [selectedAccountId, setSelectedAccountId] = useState('');
|
||||
const [automationSearch, setAutomationSearch] = useState('');
|
||||
const [debouncedAutomationSearch, setDebouncedAutomationSearch] = useState('');
|
||||
@@ -230,17 +53,50 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
const [automationStatusFilter, setAutomationStatusFilter] = useState<'all' | 'enabled' | 'disabled'>('all');
|
||||
const [automationPage, setAutomationPage] = useState(1);
|
||||
const [automationPageSize, setAutomationPageSize] = useState(10);
|
||||
const [automationTotal, setAutomationTotal] = useState(0);
|
||||
const [automationTotalPages, setAutomationTotalPages] = useState(0);
|
||||
const [automationTriggerCounts, setAutomationTriggerCounts] = useState<Record<string, number>>({});
|
||||
const automationRulesRequest = useRef(0);
|
||||
const replyRulesRequest = useRef(0);
|
||||
const selectedAccountRef = useRef('');
|
||||
selectedAccountRef.current = selectedAccountId;
|
||||
|
||||
const rulesData = useRulesData({
|
||||
activeTab,
|
||||
selectedAccountId,
|
||||
automationTriggerFilter,
|
||||
automationStatusFilter,
|
||||
debouncedAutomationSearch,
|
||||
automationPage,
|
||||
automationPageSize,
|
||||
setSelectedAccountId,
|
||||
onAutomationPageChange: setAutomationPage,
|
||||
});
|
||||
const {
|
||||
automationRules,
|
||||
automationIssues,
|
||||
replyRules,
|
||||
defaultReplies,
|
||||
accounts,
|
||||
cards,
|
||||
items,
|
||||
loading,
|
||||
setLoading,
|
||||
automationTotal,
|
||||
automationTotalPages,
|
||||
automationTriggerCounts,
|
||||
setAutomationRules,
|
||||
setCards,
|
||||
setItems,
|
||||
loadReferenceData,
|
||||
loadAutomationRules,
|
||||
loadReplyRules,
|
||||
loadDefaultReplies,
|
||||
refresh,
|
||||
} = rulesData;
|
||||
|
||||
const [showAutomationModal, setShowAutomationModal] = useState(false);
|
||||
const [showReplyModal, setShowReplyModal] = useState(false);
|
||||
const [showDefaultModal, setShowDefaultModal] = useState(false);
|
||||
// automationSubmitState 防止自动化规则保存按钮在请求期间重复提交。
|
||||
const [automationSubmitState, setAutomationSubmitState] = useState<RuleSubmitState>(idleRuleSubmitState);
|
||||
// replySubmitState 防止关键词回复保存按钮在请求期间重复提交。
|
||||
const [replySubmitState, setReplySubmitState] = useState<RuleSubmitState>(idleRuleSubmitState);
|
||||
// defaultReplySubmitState 防止默认回复保存按钮在请求期间重复提交。
|
||||
const [defaultReplySubmitState, setDefaultReplySubmitState] = useState<RuleSubmitState>(idleRuleSubmitState);
|
||||
const [editingAutomationRule, setEditingAutomationRule] = useState<Partial<ShippingRule> | null>(null);
|
||||
const [editingReplyRule, setEditingReplyRule] = useState<Partial<ReplyRule> | null>(null);
|
||||
const [defaultForm, setDefaultForm] = useState<DefaultReplyForm>({
|
||||
@@ -252,76 +108,6 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
});
|
||||
const selectedAccount = accounts.find(account => account.id === selectedAccountId);
|
||||
|
||||
const loadReferenceData = useCallback(async () => {
|
||||
const [accountList, cardList, itemList, defaultReplyMap] = await Promise.all([
|
||||
getAccountDetails(),
|
||||
getCards(),
|
||||
getItems(),
|
||||
getDefaultReplies(),
|
||||
]);
|
||||
setAccounts(accountList);
|
||||
setCards(cardList);
|
||||
setItems(itemList);
|
||||
setDefaultReplies(defaultReplyMap);
|
||||
setSelectedAccountId(current => current || accountList[0]?.id || '');
|
||||
}, []);
|
||||
|
||||
const loadAutomationRules = useCallback(async () => {
|
||||
const requestID = ++automationRulesRequest.current;
|
||||
const issuesPromise = getAutomationIssues().catch(error => {
|
||||
console.warn('加载自动化异常列表失败,不阻断规则展示', error);
|
||||
return null;
|
||||
});
|
||||
const result = await getShippingRulesPage({
|
||||
cookieId: selectedAccountId || undefined,
|
||||
triggerType: automationTriggerFilter,
|
||||
enabled: automationStatusFilter === 'all' ? undefined : automationStatusFilter === 'enabled',
|
||||
search: debouncedAutomationSearch,
|
||||
page: automationPage,
|
||||
pageSize: automationPageSize,
|
||||
});
|
||||
if (requestID !== automationRulesRequest.current) return;
|
||||
setAutomationRules(result.data);
|
||||
setAutomationTotal(result.total);
|
||||
setAutomationTotalPages(result.total_pages);
|
||||
setAutomationTriggerCounts(result.trigger_counts || {});
|
||||
if (result.page !== automationPage) setAutomationPage(result.page);
|
||||
const issues = await issuesPromise;
|
||||
if (requestID !== automationRulesRequest.current) return;
|
||||
if (issues) setAutomationIssues(issues);
|
||||
}, [automationPage, automationPageSize, automationStatusFilter, automationTriggerFilter, debouncedAutomationSearch, selectedAccountId]);
|
||||
|
||||
const loadReplyRules = useCallback(async () => {
|
||||
const cookieID = selectedAccountId;
|
||||
if (cookieID !== selectedAccountRef.current) return;
|
||||
const requestID = ++replyRulesRequest.current;
|
||||
setReplyRules([]);
|
||||
if (!cookieID) {
|
||||
return;
|
||||
}
|
||||
const rules = await getReplyRules(cookieID);
|
||||
commitIfLatest(requestID, replyRulesRequest.current, cookieID, selectedAccountRef.current, rules, setReplyRules);
|
||||
}, [selectedAccountId]);
|
||||
|
||||
const loadDefaultReplies = useCallback(async () => {
|
||||
setDefaultReplies(await getDefaultReplies());
|
||||
}, []);
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
if (activeTab === 'automation') {
|
||||
await loadAutomationRules();
|
||||
} else if (activeTab === 'reply') {
|
||||
await loadReplyRules();
|
||||
} else {
|
||||
await loadDefaultReplies();
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [activeTab, loadAutomationRules, loadDefaultReplies, loadReplyRules]);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => {
|
||||
setAutomationPage(1);
|
||||
@@ -561,7 +347,7 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
};
|
||||
|
||||
const handleSaveAutomationRule = async () => {
|
||||
if (!editingAutomationRule) return;
|
||||
if (!editingAutomationRule || automationSubmitState.submitting) return;
|
||||
const trigger = (editingAutomationRule.trigger_type || 'order_paid') as AutomationTriggerType;
|
||||
if (!editingAutomationRule.cookie_id) {
|
||||
alert('请选择账号');
|
||||
@@ -598,6 +384,8 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
enabled: variant.enabled !== false,
|
||||
}));
|
||||
|
||||
setAutomationSubmitState(startRuleSubmission(automationSubmitState));
|
||||
let succeeded = false;
|
||||
try {
|
||||
await updateShippingRule({
|
||||
...editingAutomationRule,
|
||||
@@ -615,9 +403,12 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
setShowAutomationModal(false);
|
||||
await Promise.all([loadAutomationRules(), loadReferenceData()]);
|
||||
alert('保存成功');
|
||||
succeeded = true;
|
||||
} catch (error) {
|
||||
console.error('保存自动化规则失败:', error);
|
||||
alert('保存失败:' + (error as Error).message);
|
||||
} finally {
|
||||
setAutomationSubmitState(current => finishRuleSubmission(current, succeeded));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -684,7 +475,7 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
};
|
||||
|
||||
const handleSaveReplyRule = async () => {
|
||||
if (!editingReplyRule || !selectedAccountId) return;
|
||||
if (!editingReplyRule || !selectedAccountId || replySubmitState.submitting) return;
|
||||
const hasReplyContent = editingReplyRule.type === 'image'
|
||||
? Boolean(editingReplyRule.image_url?.trim())
|
||||
: Boolean(editingReplyRule.reply_content?.trim());
|
||||
@@ -692,13 +483,18 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
alert('请填写关键词和回复内容');
|
||||
return;
|
||||
}
|
||||
setReplySubmitState(startRuleSubmission(replySubmitState));
|
||||
let succeeded = false;
|
||||
try {
|
||||
await updateReplyRule({ ...editingReplyRule, match_type: 'fuzzy', enabled: true }, selectedAccountId);
|
||||
setShowReplyModal(false);
|
||||
await loadReplyRules();
|
||||
alert('保存成功');
|
||||
succeeded = true;
|
||||
} catch (error) {
|
||||
alert('保存失败:' + (error as Error).message);
|
||||
} finally {
|
||||
setReplySubmitState(current => finishRuleSubmission(current, succeeded));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -740,6 +536,7 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
};
|
||||
|
||||
const handleSaveDefaultReply = async () => {
|
||||
if (defaultReplySubmitState.submitting) return;
|
||||
if (!defaultForm.cookie_id) {
|
||||
alert('请先选择账号');
|
||||
return;
|
||||
@@ -748,6 +545,8 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
alert('启用默认回复时,请填写回复内容或图片 URL');
|
||||
return;
|
||||
}
|
||||
setDefaultReplySubmitState(startRuleSubmission(defaultReplySubmitState));
|
||||
let succeeded = false;
|
||||
try {
|
||||
await updateDefaultReply(defaultForm.cookie_id, {
|
||||
enabled: defaultForm.enabled,
|
||||
@@ -758,8 +557,11 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
setShowDefaultModal(false);
|
||||
await loadDefaultReplies();
|
||||
alert('保存成功');
|
||||
succeeded = true;
|
||||
} catch (error) {
|
||||
alert('保存失败:' + (error as Error).message);
|
||||
} finally {
|
||||
setDefaultReplySubmitState(current => finishRuleSubmission(current, succeeded));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -854,44 +656,13 @@ const Rules: React.FC<RulesProps> = ({ initialDeliveryTarget, onDeliveryTargetHa
|
||||
</div>
|
||||
|
||||
{activeTab === 'automation' && (visibleAutomationIssues.runs.length > 0 || visibleAutomationIssues.pending_tasks.length > 0) && (
|
||||
<section className="rounded-2xl border border-red-200 bg-red-50 p-5 space-y-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<AlertCircle className="w-5 h-5 text-red-600 mt-0.5" />
|
||||
<div>
|
||||
<h3 className="font-black text-red-900">需要人工处理的自动化任务</h3>
|
||||
<p className="text-sm text-red-700 mt-1">请先在闲鱼聊天、订单或商品列表中核对真实结果,再选择继续或重试。</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
{visibleAutomationIssues.runs.map(issue => (
|
||||
<div key={`run-${issue.id}`} className="rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="font-bold text-gray-900">账号 {issue.cookie_id} · 订单 {issue.order_id || '-'} · 已记录发送 {issue.sent_count} 条</div>
|
||||
<div className="text-xs font-bold text-red-800 mt-1">{automationIssueKindLabel(issue.issue_kind)}</div>
|
||||
<div className="text-xs text-red-700 mt-1 break-words">{issue.error_message}</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 shrink-0">
|
||||
{canResolveAutomationIssue(issue, 'continue') && <button onClick={() => void handleResolveRunIssue(issue.id, 'continue')} className="px-3 py-2 rounded-lg bg-emerald-100 text-emerald-800 text-xs font-bold">已执行,继续下一步</button>}
|
||||
{canResolveAutomationIssue(issue, 'retry') && <button onClick={() => void handleResolveRunIssue(issue.id, 'retry')} className="px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold">未执行,安全重试</button>}
|
||||
{canResolveAutomationIssue(issue, 'cancel') && <button onClick={() => void handleResolveRunIssue(issue.id, 'cancel')} className="px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold">终止</button>}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{visibleAutomationIssues.pending_tasks.map(issue => (
|
||||
<div key={`task-${issue.id}`} className="rounded-xl border border-red-100 bg-white p-4 flex flex-col lg:flex-row lg:items-center justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<div className="font-bold text-gray-900">账号 {issue.cookie_id} · 延迟任务重试已达 {issue.attempt_count} 次</div>
|
||||
<div className="text-xs text-red-700 mt-1 break-words">{issue.error_message}</div>
|
||||
</div>
|
||||
<div className="flex gap-2 shrink-0">
|
||||
<button onClick={() => void handleResolveDeferredIssue(issue.id, 'retry')} className="px-3 py-2 rounded-lg bg-amber-100 text-amber-800 text-xs font-bold">重新入队</button>
|
||||
<button onClick={() => void handleResolveDeferredIssue(issue.id, 'dismiss')} className="px-3 py-2 rounded-lg bg-gray-100 text-gray-700 text-xs font-bold">忽略</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
)}
|
||||
<AutomationIssuePanel
|
||||
runs={visibleAutomationIssues.runs}
|
||||
pendingTasks={visibleAutomationIssues.pending_tasks}
|
||||
onResolveRun={(id, resolution) => void handleResolveRunIssue(id, resolution)}
|
||||
onResolveDeferredTask={(id, resolution) => void handleResolveDeferredIssue(id, resolution)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{activeTab === 'automation' && (
|
||||
<div className="grid min-w-0 grid-cols-1 gap-6 xl:grid-cols-[minmax(270px,0.72fr)_minmax(0,1.28fr)]">
|
||||
|
||||
@@ -1,37 +1,8 @@
|
||||
import type { AutomationRunIssue, DeferredAutomationIssue } from '../services/api';
|
||||
|
||||
export type AutomationResolution = 'continue' | 'retry' | 'cancel';
|
||||
|
||||
export const canResolveAutomationIssue = (
|
||||
issue: AutomationRunIssue,
|
||||
resolution: AutomationResolution,
|
||||
): boolean => issue.allowed_resolutions.includes(resolution);
|
||||
|
||||
export const filterAutomationIssues = (
|
||||
issues: { runs: AutomationRunIssue[]; pending_tasks: DeferredAutomationIssue[] },
|
||||
cookieID: string,
|
||||
) => ({
|
||||
runs: issues.runs.filter(issue => !cookieID || issue.cookie_id === cookieID),
|
||||
pending_tasks: issues.pending_tasks.filter(issue => !cookieID || issue.cookie_id === cookieID),
|
||||
});
|
||||
|
||||
export const automationIssueKindLabel = (kind: AutomationRunIssue['issue_kind']): string => ({
|
||||
external_result_unknown: '外部动作结果未知',
|
||||
invalid_snapshot: '历史数据无法恢复',
|
||||
rule_unavailable: '规则不可用',
|
||||
partial_failure: '部分动作失败',
|
||||
execution_failed: '动作执行失败',
|
||||
}[kind] || '自动化异常');
|
||||
|
||||
export const loadAutomationPageData = async <TRule>(options: {
|
||||
loadRules: () => Promise<TRule[]>;
|
||||
loadIssues: () => Promise<{ runs: AutomationRunIssue[]; pending_tasks: DeferredAutomationIssue[] }>;
|
||||
onRules: (rules: TRule[]) => void;
|
||||
onIssues: (issues: { runs: AutomationRunIssue[]; pending_tasks: DeferredAutomationIssue[] }) => void;
|
||||
onIssuesError: (error: unknown) => void;
|
||||
}): Promise<void> => {
|
||||
const issuesPromise = options.loadIssues().then(options.onIssues).catch(options.onIssuesError);
|
||||
const rules = await options.loadRules();
|
||||
options.onRules(rules);
|
||||
await issuesPromise;
|
||||
};
|
||||
// 旧目录保留兼容入口,实际实现统一归属 Rules feature。
|
||||
export {
|
||||
automationIssueKindLabel,
|
||||
canResolveAutomationIssue,
|
||||
filterAutomationIssues,
|
||||
loadAutomationPageData,
|
||||
} from '../app/features/rules/issueState';
|
||||
export type { AutomationResolution } from '../app/features/rules/issueState';
|
||||
@@ -1,19 +0,0 @@
|
||||
import{j as e,r,c as ys,b as qe,d as Wa}from"./react-vendor-C_od1ZSF.js";import{L as Ja,U as ha,M as is,C as os,B as ga,S as ba,Z as cs,a as jt,b as js,G as As,c as Ns,d as _s,e as Va,f as rt,A as $s,D as Qa,g as Ps,P as fa,h as qt,E as ya,T as Ga,i as Ka,j as Pe,X as Me,k as Ha,l as Za,m as vs,n as ja,o as He,Q as Xt,p as xt,q as Ke,r as yt,s as Tt,t as Rs,R as ze,u as Na,v as Ya,w as Qe,K as Xa,x as dt,y as lt,z as et,F as Es,H as _t,I as Nt,J as Dt,N as _a,O as el,V as Ds,W as Ts,Y as tl,_ as sl,$ as al,a0 as ll,a1 as es,a2 as Bt,a3 as ds,a4 as rl,a5 as nl,a6 as xs,a7 as Ms,a8 as il,a9 as ol,aa as Mt,ab as qs,ac as Gt,ad as va,ae as cl,af as dl,ag as Zt,ah as wa,ai as xl,aj as ml,ak as pl,al as ul,am as hl,an as gl,ao as Fs}from"./icons-vendor-BpMgNNfy.js";import{R as zt,B as bl,X as Bs,Y as zs,T as Ut,a as fl,C as ts,A as yl,b as jl,c as Nl,P as Us,d as Ws,L as _l}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";(function(){const a=document.createElement("link").relList;if(a&&a.supports&&a.supports("modulepreload"))return;for(const m of document.querySelectorAll('link[rel="modulepreload"]'))i(m);new MutationObserver(m=>{for(const _ of m)if(_.type==="childList")for(const N of _.addedNodes)N.tagName==="LINK"&&N.rel==="modulepreload"&&i(N)}).observe(document,{childList:!0,subtree:!0});function l(m){const _={};return m.integrity&&(_.integrity=m.integrity),m.referrerPolicy&&(_.referrerPolicy=m.referrerPolicy),m.crossOrigin==="use-credentials"?_.credentials="include":m.crossOrigin==="anonymous"?_.credentials="omit":_.credentials="same-origin",_}function i(m){if(m.ep)return;m.ep=!0;const _=l(m);fetch(m.href,_)}})();const vl=({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"})})}),ms=({sizeClass:t="w-12 h-12",logoClassName:a="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(js,{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:Y,children:"取消"}),e.jsxs("button",{onClick:ut,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:Y,children:[Y?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(He,{className:"w-4 h-4"}),Y?"保存中...":"保存"]})]})})]})}),document.body)]})},nn=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(a=>({order_id:String((a==null?void 0:a.order_id)||"unknown"),success:(a==null?void 0:a.success)===!0,message:String((a==null?void 0:a.message)||"")})):[]}),on=t=>(t==null?void 0:t.results.filter(a=>!a.success))||[],sa=({status:t})=>{const a={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 ${a[t]||a.cancelled}`,children:l[t]||t})},cn=()=>{const[t,a]=r.useState([]),[l,i]=r.useState([]),[m,_]=r.useState([]),[N,R]=r.useState({}),[g,C]=r.useState("all"),[j,F]=r.useState(""),[G,me]=r.useState(""),[oe,v]=r.useState(""),q=r.useRef(0),[ce,Q]=r.useState(1),[ee,B]=r.useState(1),[ge,ue]=r.useState(!1),[k,Z]=r.useState(!1),[se,K]=r.useState(!1),[ve,J]=r.useState(!1),[I,E]=r.useState(null),[$,be]=r.useState(null),[Re,ae]=r.useState({}),[T,p]=r.useState(!1),[b,U]=r.useState(""),[M,ne]=r.useState(!1),[he,ye]=r.useState(null),[Ee,ke]=r.useState(null),[x,V]=r.useState(null),[X,c]=r.useState(!1),[d,D]=r.useState(null),[S,Y]=r.useState(null),O=async()=>{const u=++q.current;ue(!0);try{const L=await tr(j||void 0,g,ce,20,oe);if(u!==q.current)return;a(L.data),B(L.total_pages)}catch(L){console.error("加载订单失败:",L)}finally{u===q.current&&ue(!1)}},de=(u,L,le)=>{if(le&&le.trim())return le;if(N[`${u}:${L}`])return N[`${u}:${L}`];const Ne=l.find(Ue=>{if(le&&Ue.item_title){const Fe=le.toLowerCase(),tt=Ue.item_title.toLowerCase();return tt.includes(Fe)||Fe.includes(tt)}return!1});return Ne!=null&&Ne.item_title?Ne.item_title:"未知商品"},Se=u=>{const L={};u.forEach(le=>{le.item_id&&(L[`${le.cookie_id}:${le.item_id}`]=le.item_title||le.item_id)}),R(L)};r.useEffect(()=>{const u=window.setTimeout(()=>{Q(1),v(G.trim())},300);return()=>window.clearTimeout(u)},[G]),r.useEffect(()=>{O()},[j,g,ce,oe]),r.useEffect(()=>{Promise.all([Ft(),vt()]).then(([u,L])=>{_(u),i(L),Se(L)}).catch(u=>{console.error("加载商品列表失败:",u)})},[]);const fe=r.useMemo(()=>new Map(m.map(u=>[u.id,u])),[m]),Oe=u=>{const L=fe.get(u),le=(L==null?void 0:L.remark)||(L==null?void 0:L.nickname);return le?`${le} · ${u.slice(0,6)}`:`账号 ${u.slice(0,8)}`},re=u=>{const L=fe.get(u);return(L==null?void 0:L.remark)||(L==null?void 0:L.nickname)||"未命名账号"},h=async()=>{ue(!0);try{const u=await lr(j||void 0,g);await O(),u!=null&&u.message&&alert(u.message)}catch(u){console.error("同步订单失败:",u),alert((u==null?void 0:u.message)||"同步失败,请重试")}finally{ue(!1)}},f=u=>{U(u),ye(null),p(!0)},P=async u=>{var L;ne(!0),ye(null);try{const le=await nr([b],u),Ne=(L=le==null?void 0:le.results)==null?void 0:L[0];Ne!=null&&Ne.success?(ye({success:!0,message:Ne.message}),O()):ye({success:!1,message:(Ne==null?void 0:Ne.message)||"发货失败"})}catch(le){ye({success:!1,message:(le==null?void 0:le.message)||"请求失败"})}finally{ne(!1)}},z=u=>{E(u),Z(!0)},Ie=u=>{be({...u}),K(!0)},Ae=async()=>{if(!(!$||!$.order_id))try{const u={};$.status!==void 0&&(u.order_status=$.status),$.buyer_id!==void 0&&(u.buyer_id=$.buyer_id),$.amount!==void 0&&(u.amount=$.amount),$.receiver_name!==void 0&&(u.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(S=>S.map(Y=>`"${String(Y).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),c=new Blob(["\uFEFF"+X],{type:"text/csv;charset=utf-8"}),d=URL.createObjectURL(c),D=document.createElement("a");D.href=d,D.download="卡密组批量导入模板.csv",document.body.appendChild(D),D.click(),D.remove(),URL.revokeObjectURL(d)},ye=async()=>{if(q){ge(!0),ee(null);try{const x=await pr(q);if(ee(x),x.created>0){const V=await Xe();a(V)}}catch(x){ee({error:(x==null?void 0:x.message)||"上传失败"})}finally{ge(!1)}}},Ee=async()=>{if(!(!ue||!Z.trim())){ge(!0),ve(null);try{const x=await ur(ue,Z);ve({added:x.added}),se("");const V=await Xe();a(V)}catch(x){alert("追加失败:"+((x==null?void 0:x.message)||"未知错误"))}finally{ge(!1)}}},ke=()=>{var x;v("create"),ce(null),ee(null),k((x=M[0])!=null&&x.id?String(M[0].id):""),se(""),ve(null),me(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:ke,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:()=>_(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(et,{className:"w-5 h-5"}),"添加新卡密"]})]})]}),e.jsxs("div",{className:"ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white",children:[e.jsxs("div",{className:"flex flex-col gap-3 border-b border-gray-50 bg-surface-muted p-4 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"flex flex-1 flex-col gap-3 sm:flex-row",children:[e.jsxs("div",{className:"relative sm:w-48",children:[e.jsx(_a,{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:J,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(_t,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:E,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:["显示 ",ne.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:ne.map(x=>{let V="";return x.type==="data"&&x.data_content?V=`库存: ${x.data_content.split(`
|
||||
`).filter(c=>c.trim()).length} 条`:x.type==="text"&&x.text_content?V=x.text_content:x.type==="api"&&x.api_config?V=x.api_config.url:x.type==="image"&&x.image_url&&(V="图片链接"),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(be,{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:()=>U(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(el,{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:V,children:V})}),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:()=>b(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:()=>Re(x),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(Nt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>T(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)})})]})}),ne.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(fa,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),l&&N&&qe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>i(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Me,{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=>C({...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=>C({...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:"批量数据"}),(N==null?void 0:N.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=>C({...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:[e.jsLine truncated
|
||||
卡号1:密码1
|
||||
卡号2:密码2
|
||||
或者
|
||||
兑换码1
|
||||
兑换码2`}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持格式:卡号:密码 或 单独的兑换码"}),e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-blue-600",children:g.data_content?g.data_content.split(`
|
||||
`).filter(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=>C({...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=>C({...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=>C({...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:()=>C({...g,enabled:!g.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${g.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${g.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>i(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:ae,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(He,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),m&&qe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>_(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(Me,{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=>F({...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:()=>F({...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(os,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>F({...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(Ds,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>F({...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=>F({...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=>F({...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=>F({...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=>F({...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=>F({...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=>F({...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:()=>_(!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:p,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(et,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),G&&qe.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>me(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(Me,{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 ${oe==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(tl,{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 ${oe==="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"}),"往单个组充卡密"]})]}),oe==="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:he,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm tran
Line truncated
|
||||
VIP-002
|
||||
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),K&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",K.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>me(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),oe==="create"?e.jsxs("button",{onClick:ye,disabled:!q||B,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[B?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(Dt,{className:"w-4 h-4"}),B?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:Ee,disabled:!ue||!Z.trim()||B||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:[B?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(et,{className:"w-4 h-4"}),B?"处理中...":"追加卡密"]})]})]})}),document.body)]})},mn=t=>t.find(a=>a.status==="running"||a.status==="canceling"),la="ydisks-amap-js-api",pn="c9b68d4ce9a2a97f22a4a439404488ca";let $t=null;const un=()=>pn,hn=()=>window.AMap?Promise.resolve(window.AMap):$t||($t=new Promise((t,a)=>{const l=document.getElementById(la),i=l||document.createElement("script"),m=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(N)},_=()=>{window.AMap?(m(),t(window.AMap)):(m(),a(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},N=window.setTimeout(()=>{m(),a(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=_,i.id=la,i.async=!0,i.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(un())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,i.onerror=()=>{m(),a(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},l||document.head.appendChild(i)}).catch(t=>{throw $t=null,t}),$t),Ht=t=>Number.isFinite(t)&&t!==0,gn=t=>{var m,_;const a=Number((m=t.location)==null?void 0:m.lng),l=Number((_=t.location)==null?void 0:_.lat),i={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:a,latitude:l,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!i.division_id||!i.province||!i.city||!i.poi_id||!i.poi_name||!Ht(a)||!Ht(l)||a<-180||a>180||l<-90||l>90?null:i},bn=async(t,a)=>{if(!Ht(t)||!Ht(a)||t<-180||t>180||a<-90||a>90)throw new Error("经纬度无效");const l=await hn();return new Promise((i,m)=>{new l.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,a],1e3,(N,R)=>{var C;if(N!=="complete"){if(N==="no_data"){i([]);return}m(new Error("高德地图附近地址查询失败,请稍后重试"));return}const g=(((C=R==null?void 0:R.poiList)==null?void 0:C.pois)||[]).map(gn).filter(j=>j!==null);i(g)})})},fn=t=>{const a=String(t||"").trim();return a?/^[¥¥]/.test(a)?a:`¥${a}`:"-"},yn=({onConfigureDelivery:t})=>{const[a,l]=r.useState([]),[i,m]=r.useState([]),[_,N]=r.useState([]),[R,g]=r.useState(""),[C,j]=r.useState(""),[F,G]=r.useState(!1),[me,oe]=r.useState(!1),[v,q]=r.useState(!1),[ce,Q]=r.useState(!1),[ee,B]=r.useState(!1),[ge,ue]=r.useState(!1),[k,Z]=r.useState(!1),[se,K]=r.useState("upload"),[ve,J]=r.useState(null),[I,E]=r.useState(null),[$,be]=r.useState(""),[Re,ae]=r.useState(!1),[T,p]=r.useState(!1),[b,U]=r.useState([]),[M,ne]=r.useState(null),[he,ye]=r.useState([]),[Ee,ke]=r.useState(null),[x,V]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[X,c]=r.useState(null),[d,D]=r.useState(null),[S,Y]=r.useState(null),O=r.useRef(!1),[de,Se]=r.useState(null),[fe,Oe]=r.useState({}),[re,h]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[f,P]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[z,Ie]=r.useState([]);r.useEffect(()=>{if(!ge||f.images.length===0){Ie([]);return}const n=f.images.map((w,H)=>({key:w.name+H,url:URL.createObjectURL(w)}));return Ie(n),()=>{n.forEach(w=>URL.revokeObjectURL(w.url))}},[ge,f.images]);const Ae=async()=>{const n=await vt();l(n)},we=async()=>{m(await gs())};r.useEffect(()=>{Promise.all([Ft(),vt(),gs(),Hs(20)]).then(([n,w,H,Te])=>{N(n),l(w),m(H);const s=Te.find(o=>["running","canceling"].includes(o.status))||Te.find(o=>o.status!=="preview");Y(s||null)}).catch(n=>console.error("加载商品配置失败:",n))},[]),r.useEffect(()=>{if(!k||!(d!=null&&d.id)||!["running","canceling"].includes(d.status))return;const n=window.setInterval(async()=>{if(!O.current){O.current=!0;try{const w=await bt(d.id);D(w),Y(w),[
Line truncated
|
||||
`),Te=new Blob(["\uFEFF"+H],{type:"text/csv;charset=utf-8"}),s=URL.createObjectURL(Te),o=document.createElement("a");o.href=s,o.download="批量铺货模板.csv",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(s)},Lt=()=>{h(n=>({...n,cookie_id:R||n.cookie_id})),B(!0)},nt=()=>{P(n=>({...n,cookie_id:R||n.cookie_id})),ue(!0)},it=async n=>{if(!(n?R:f.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");p(!0),navigator.geolocation.getCurrentPosition(async H=>{try{const Te=await bn(H.coords.longitude,H.coords.latitude);if(!Te.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");n?(ye(Te),ke(Te[0])):(U(Te),ne(Te[0]))}catch(Te){alert((Te==null?void 0:Te.message)||"获取发货地失败")}finally{p(!1)}},H=>{p(!1),alert(H.code===H.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},Ot=n=>i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id).length>0?i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id):i.filter(w=>w.cookie_id===n.cookie_id&&!w.item_id),pt=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||"-"}},ut=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"}},st=r.useMemo(()=>new Map(_.map(n=>[n.id,n])),[_]),ht=r.useMemo(()=>C?a.filter(n=>n.cookie_id===C):a,[C,a]),Ge=n=>{const w=st.get(n),H=(w==null?void 0:w.remark)||(w==null?void 0:w.nickname);return H?`${H} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},ot=n=>{const w=st.get(n);return(w==null?void 0:w.remark)||(w==null?void 0:w.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(ll,{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:C,onChange:n=>j(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{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:R,onChange:n=>g(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:De,disabled:F||!R,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 ${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(et,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:nt,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 Ne(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white
Line 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
|
||||
@@ -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
|
||||
@@ -0,0 +1,19 @@
|
||||
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
|
||||
@@ -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-BBbP32Ar.js"></script>
|
||||
<script type="module" crossorigin src="/static/assets/index-beu7QHqR.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-DVSGe2YH.css">
|
||||
<link rel="stylesheet" crossorigin href="/static/assets/index-LhxzNkZL.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
Reference in new issue
Block a user