阶段七:完成OrderList React feature化与导入刷新边界
This commit is contained in:
1 parent
66ac84b32d
commit
b128ce60db
20 files changed
+1454
-1366
No files matched your search
+601
-1003
File diff suppressed because it is too large.
Load diff
@@ -173,7 +173,8 @@ app shell / routes
|
||||
- 已完成阶段 7 第二个 PR 切片“React ItemList feature 化与批量发布行为边界”:按 `app/features/items` 提取商品/批量 API 适配层、批量任务类型、批量 Hook 和阶段指示器组件;批量预检、任务恢复、轮询取消、失败重试和过期响应均由 feature 状态边界负责;行为测试覆盖预检门禁、取消状态、失败重试、历史任务筛选和过期轮询响应;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
|
||||
- 已完成阶段 7 第三个 PR 切片“React AccountList feature 化与账号运行状态行为边界”:按 `app/features/accounts` 提取账号 API 适配层、账号数据与运行状态 Hook、运行状态展示模型、账号编辑弹窗和登录/暂停状态模型;账号加载与运行状态轮询支持取消和请求代次门禁,密码登录响应按账号与代次隔离,旧组件入口保留兼容转发;行为测试覆盖账号切换、暂停/恢复、凭证失败、风控验证和过期响应;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
|
||||
- 已完成阶段 7 第四个 PR 切片“React CardList feature 化与卡密库存/批量追加行为边界”:按 `app/features/cards` 提取卡密 API 适配层、库存数据 Hook、批量导入/追加状态 Hook 和弹窗组件;卡密筛选、追加预览、提交取消、失败重试与账号切换过期响应均由 feature 状态边界负责,保留旧组件入口和 API 路径;新增状态模型测试并通过前端类型检查、全量测试、注释检查和构建门禁,合并为一个可回滚提交;
|
||||
- 阶段 7 下一 PR 切片为“React OrderList feature 化与订单导入/刷新行为边界”:提取订单 API、导入/刷新 Hook 和订单筛选组件,补充导入预检、刷新取消、失败重试和过期响应测试;
|
||||
- 已完成阶段 7 第五个 PR 切片“React OrderList feature 化与订单导入/刷新行为边界”:按 `app/features/orders` 提取订单 API 适配层、查询/分页 Hook、导入 Hook、筛选栏和导入弹窗;订单查询与辅助数据支持并行加载、取消和代次门禁,导入支持文件预检、取消、失败重试和导入后刷新;新增筛选、导入归一化、API 取消信号和过期响应测试,保留旧组件入口和 API 路径;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
|
||||
- 阶段 7 下一 PR 切片为“React Notifications feature 化与渠道/事件绑定行为边界”:提取通知 API、渠道数据 Hook 和通知绑定组件,补充渠道校验、保存取消、失败重试和过期响应测试;
|
||||
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
|
||||
|
||||
## 6. 阶段 0:治理文档与强约束
|
||||
@@ -596,3 +597,4 @@ npm --prefix frontend run build
|
||||
| 2026-08-14 | 完成阶段 7 第二个 PR 切片“React ItemList feature 化与批量发布行为边界” | 新增 `app/features/items` 的 API 适配层、批量任务类型、批量 Hook、批量状态模型和阶段指示器组件;批量预检、任务恢复、轮询过期响应、安全取消和失败重试均有独立状态边界;行为测试覆盖预检门禁、取消状态、失败重试、历史任务筛选和过期轮询响应;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React AccountList feature 化与账号运行状态行为边界 |
|
||||
| 2026-08-15 | 完成阶段 7 第三个 PR 切片“React AccountList feature 化与账号运行状态行为边界” | 新增 `app/features/accounts` 的 API 适配层、账号数据与运行状态 Hook、账号编辑弹窗、登录/暂停状态模型;账号加载和运行状态轮询具备取消与代次门禁,密码登录响应按账号与代次隔离,兼容入口保留;行为测试覆盖账号切换、暂停/恢复、凭证失败、风控验证和过期响应;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React CardList feature 化与卡密库存/批量追加行为边界 |
|
||||
| 2026-08-15 | 完成阶段 7 第四个 PR 切片“React CardList feature 化与卡密库存/批量追加行为边界” | 按 `app/features/cards` 提取卡密 API 适配层、库存数据 Hook、批量导入/追加状态 Hook 和弹窗组件;卡密筛选、追加预览、提交取消、失败重试与账号切换过期响应均由 feature 状态边界负责,保留旧组件入口和 API 路径;新增状态模型测试并通过前端类型检查、全量测试、注释检查和构建门禁,合并为一个可回滚提交 | 阶段 7:React OrderList feature 化与订单导入/刷新行为边界 |
|
||||
| 2026-08-15 | 完成阶段 7 第五个 PR 切片“React OrderList feature 化与订单导入/刷新行为边界” | 按 `app/features/orders` 提取订单 API 适配层、查询/分页 Hook、导入 Hook、筛选栏和导入弹窗;订单查询与辅助数据支持并行加载、取消和代次门禁,导入支持文件预检、取消、失败重试和导入后刷新;新增筛选、导入归一化、API 取消信号和过期响应测试,保留旧组件入口和 API 路径;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React Notifications feature 化与渠道/事件绑定行为边界 |
|
||||
@@ -0,0 +1,13 @@
|
||||
export {
|
||||
deleteOrder,
|
||||
getAccountDetails,
|
||||
getItems,
|
||||
getOrders,
|
||||
importOrders,
|
||||
manualShipOrder,
|
||||
syncOrders,
|
||||
syncSingleOrder,
|
||||
updateOrder,
|
||||
} from '../../../services/api';
|
||||
|
||||
// 订单 feature 通过本文件声明服务 API 来源,页面不再直接依赖通用 API 模块。
|
||||
@@ -0,0 +1,90 @@
|
||||
import React from 'react';
|
||||
import { Search, User as UserIcon } from 'lucide-react';
|
||||
import type { AccountDetail } from '../../../../types';
|
||||
import { orderStatusOptions } from '../state';
|
||||
|
||||
// OrderFilterBarProps 描述订单状态、账号和文本筛选所需的页面状态。
|
||||
export interface OrderFilterBarProps {
|
||||
// filter 是当前订单状态筛选值。
|
||||
filter: string;
|
||||
// onFilterChange 响应订单状态筛选切换。
|
||||
onFilterChange: (value: string) => void;
|
||||
// accountFilter 是当前账号筛选值。
|
||||
accountFilter: string;
|
||||
// onAccountFilterChange 响应账号筛选切换。
|
||||
onAccountFilterChange: (value: string) => void;
|
||||
// accounts 是账号下拉框的数据源。
|
||||
accounts: AccountDetail[];
|
||||
// accountName 将账号 ID 转换为展示名称。
|
||||
accountName: (cookieId: string) => string;
|
||||
// searchText 是搜索框当前输入值。
|
||||
searchText: string;
|
||||
// onSearchChange 响应订单搜索输入。
|
||||
onSearchChange: (value: string) => void;
|
||||
}
|
||||
|
||||
// OrderFilterBar 渲染订单状态、账号和关键词筛选工具栏。
|
||||
export const OrderFilterBar: React.FC<OrderFilterBarProps> = ({
|
||||
filter,
|
||||
onFilterChange,
|
||||
accountFilter,
|
||||
onAccountFilterChange,
|
||||
accounts,
|
||||
accountName,
|
||||
searchText,
|
||||
onSearchChange,
|
||||
}) => {
|
||||
// handleStatusClick 将用户选择的状态传回订单页面。
|
||||
const handleStatusClick = (event: React.MouseEvent<HTMLButtonElement>) => onFilterChange(event.currentTarget.dataset.status || 'all');
|
||||
// handleAccountChange 将用户选择的账号传回订单页面。
|
||||
const handleAccountChange = (event: React.ChangeEvent<HTMLSelectElement>) => onAccountFilterChange(event.target.value);
|
||||
// handleSearchChange 将用户输入传回订单页面。
|
||||
const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => onSearchChange(event.target.value);
|
||||
|
||||
return (
|
||||
<div className="p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted">
|
||||
<div className="flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full">
|
||||
{orderStatusOptions.map(
|
||||
// option 是当前订单状态筛选标签配置。
|
||||
option => (
|
||||
<button
|
||||
key={option.key}
|
||||
data-status={option.key}
|
||||
onClick={handleStatusClick}
|
||||
className={`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${filter === option.key ? 'bg-white text-black shadow-sm' : 'text-gray-500 hover:text-gray-700'}`}
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
<div className="flex w-full md:w-auto flex-col sm:flex-row gap-3">
|
||||
<div className="relative">
|
||||
<UserIcon className="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none" />
|
||||
<select
|
||||
aria-label="按账号筛选订单"
|
||||
value={accountFilter}
|
||||
onChange={handleAccountChange}
|
||||
className="ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm"
|
||||
>
|
||||
<option value="">全部账号</option>
|
||||
{accounts.map(
|
||||
// account 是当前账号筛选下拉项。
|
||||
account => <option key={account.id} value={account.id}>{accountName(account.id)}</option>,
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
<div className="relative group">
|
||||
<Search className="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="搜索订单号/商品/买家..."
|
||||
value={searchText}
|
||||
onChange={handleSearchChange}
|
||||
className="ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,94 @@
|
||||
import React from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Upload, X } from 'lucide-react';
|
||||
import { failedOrderImportRows } from '../state';
|
||||
import type { OrderImportState } from '../types';
|
||||
|
||||
// OrderImportModalProps 描述订单导入弹窗所需的状态和事件。
|
||||
export type OrderImportModalProps = OrderImportState;
|
||||
|
||||
// OrderImportModal 渲染订单文件选择、结果展示和重试操作。
|
||||
export const OrderImportModal: React.FC<OrderImportModalProps> = (state) => {
|
||||
// handleFileChange 保存用户选择的订单文件并清理旧错误。
|
||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
state.setImportFile(event.target.files?.[0] || null);
|
||||
};
|
||||
// handleClose 关闭订单导入弹窗。
|
||||
const handleClose = () => state.closeImportModal();
|
||||
// handleSubmit 提交当前订单导入文件。
|
||||
const handleSubmit = () => void state.handleImportOrders();
|
||||
// handleRetry 重试最近一次失败的订单导入。
|
||||
const handleRetry = () => void state.handleRetryImport();
|
||||
|
||||
if (!state.showImportModal) return null;
|
||||
|
||||
return createPortal(
|
||||
<div className="modal-overlay-centered">
|
||||
<div className="modal-container">
|
||||
<div className="modal-header">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<h3 className="text-2xl font-extrabold text-gray-900">插入订单</h3>
|
||||
<button onClick={handleClose} className="p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors">
|
||||
<X className="w-5 h-5 text-gray-600" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="modal-body space-y-5">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-2">选择Excel文件</label>
|
||||
<input type="file" accept=".xlsx,.csv,.tsv,.json" onChange={handleFileChange} className="w-full ios-input px-4 py-3 rounded-xl text-sm" />
|
||||
<p className="text-xs text-gray-500 mt-2">支持 .xlsx、.csv、.tsv、.json 格式</p>
|
||||
</div>
|
||||
{state.importFile && (
|
||||
<div className="p-3 bg-blue-50 rounded-xl">
|
||||
<div className="flex items-center gap-2">
|
||||
<Upload className="w-4 h-4 text-blue-600" />
|
||||
<span className="text-sm font-medium text-blue-900">{state.importFile.name}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{state.importError && (
|
||||
<div className="rounded-xl bg-red-50 border border-red-100 p-3 text-sm text-red-700 flex items-center justify-between gap-3">
|
||||
<span>{state.importError}</span>
|
||||
<button type="button" onClick={handleRetry} disabled={state.importing || !state.importFile} className="font-bold whitespace-nowrap">重试</button>
|
||||
</div>
|
||||
)}
|
||||
{state.importResult && state.importResult.failed_count > 0 && (
|
||||
<div className="space-y-3">
|
||||
<div className="rounded-xl bg-amber-50 border border-amber-100 p-3 text-sm font-bold text-amber-800">
|
||||
导入完成:成功 {state.importResult.success_count} 条,失败 {state.importResult.failed_count} 条
|
||||
</div>
|
||||
<div className="max-h-64 overflow-y-auto rounded-xl border border-gray-100">
|
||||
<table className="w-full text-left text-xs">
|
||||
<thead className="sticky top-0 bg-gray-50 text-gray-500">
|
||||
<tr><th className="px-3 py-2">订单ID</th><th className="px-3 py-2">失败原因</th></tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
{failedOrderImportRows(state.importResult).map(
|
||||
// row 是需要展示失败原因的导入结果行。
|
||||
(row, index) => (
|
||||
<tr key={`${row.order_id}-${index}`}>
|
||||
<td className="px-3 py-2 font-mono">{row.order_id}</td>
|
||||
<td className="px-3 py-2 text-red-600">{row.message || '导入失败'}</td>
|
||||
</tr>
|
||||
),
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
<div className="flex gap-3 w-full">
|
||||
<button onClick={handleClose} className="flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors">取消</button>
|
||||
<button onClick={handleSubmit} disabled={!state.importFile || state.importing} className="flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50">
|
||||
{state.importing ? '正在导入…' : '导入订单'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,349 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type Dispatch, type SetStateAction } from 'react';
|
||||
import type { AccountDetail, Item, Order } from '../../../types';
|
||||
import { getAccountDetails, getItems, getOrders, importOrders } from './api';
|
||||
import { canSubmitOrderImport, isCurrentOrderRequest, normalizeOrderImportResult, orderErrorMessage, validateOrderImportFile } from './state';
|
||||
import type { OrderImportState, OrderQueryState } from './types';
|
||||
|
||||
// OrderQueryOptions 描述订单查询 Hook 的固定分页参数。
|
||||
interface OrderQueryOptions {
|
||||
// pageSize 是每页请求的订单数量。
|
||||
pageSize: number;
|
||||
}
|
||||
|
||||
// useOrderQuery 统一管理订单列表加载、筛选、防抖和过期响应保护。
|
||||
export const useOrderQuery = (options: OrderQueryOptions = { pageSize: 20 }): OrderQueryState => {
|
||||
// orders 保存当前页订单。
|
||||
const [orders, setOrders] = useState<Order[]>([]);
|
||||
// items 保存用于补充订单商品名称的商品列表。
|
||||
const [items, setItems] = useState<Item[]>([]);
|
||||
// accounts 保存订单账号筛选下拉框的数据。
|
||||
const [accounts, setAccounts] = useState<AccountDetail[]>([]);
|
||||
// filter 保存订单状态筛选值。
|
||||
const [filter, setFilter] = useState('all');
|
||||
// accountFilter 保存账号筛选值。
|
||||
const [accountFilter, setAccountFilter] = useState('');
|
||||
// searchText 保存搜索框实时输入值。
|
||||
const [searchText, setSearchText] = useState('');
|
||||
// debouncedSearch 保存防抖后的服务端搜索值。
|
||||
const [debouncedSearch, setDebouncedSearch] = useState('');
|
||||
// page 保存当前分页页码。
|
||||
const [page, setPage] = useState(1);
|
||||
// totalPages 保存服务端返回的总页数。
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
// loading 表示当前订单查询是否正在执行。
|
||||
const [loading, setLoading] = useState(false);
|
||||
// orderGeneration 隔离筛选变化和手动刷新的旧订单响应。
|
||||
const orderGeneration = useRef(0);
|
||||
// orderAbort 保存当前订单查询的取消控制器。
|
||||
const orderAbort = useRef<AbortController | null>(null);
|
||||
// auxiliaryAbort 保存账号和商品辅助数据请求的取消控制器。
|
||||
const auxiliaryAbort = useRef<AbortController | null>(null);
|
||||
|
||||
// loadOrders 按当前筛选条件加载订单并取消上一轮请求。
|
||||
const loadOrders = useCallback(
|
||||
// 订单加载回调读取当前筛选条件并更新列表。
|
||||
async () => {
|
||||
// generation 标记本次订单查询请求的代次。
|
||||
const generation = ++orderGeneration.current;
|
||||
orderAbort.current?.abort();
|
||||
// controller 允许筛选条件变化时取消旧查询。
|
||||
const controller = new AbortController();
|
||||
orderAbort.current = controller;
|
||||
setLoading(true);
|
||||
try {
|
||||
// result 是当前筛选条件下的分页订单结果。
|
||||
const result = await getOrders(accountFilter || undefined, filter, page, options.pageSize, debouncedSearch, { signal: controller.signal });
|
||||
if (!isCurrentOrderRequest(generation, orderGeneration.current)) return;
|
||||
setOrders(result.data);
|
||||
setTotalPages(result.total_pages);
|
||||
} catch (error /* 订单查询异常 */) {
|
||||
if (isCurrentOrderRequest(generation, orderGeneration.current) && !controller.signal.aborted) {
|
||||
console.error('加载订单失败:', error);
|
||||
}
|
||||
} finally {
|
||||
if (isCurrentOrderRequest(generation, orderGeneration.current)) setLoading(false);
|
||||
}
|
||||
},
|
||||
[accountFilter, debouncedSearch, filter, options.pageSize, page],
|
||||
);
|
||||
|
||||
// useEffect 防抖搜索输入,避免每次键入都立即请求服务端。
|
||||
useEffect(
|
||||
// 搜索防抖副作用延迟提交用户输入。
|
||||
() => {
|
||||
// timer 是当前搜索输入对应的防抖定时器。
|
||||
const timer = window.setTimeout(
|
||||
// 防抖定时器回调提交标准化搜索文本。
|
||||
() => {
|
||||
setPage(1);
|
||||
setDebouncedSearch(searchText.trim());
|
||||
},
|
||||
300,
|
||||
);
|
||||
return (
|
||||
// 防抖清理回调取消上一次搜索定时器。
|
||||
() => window.clearTimeout(timer)
|
||||
);
|
||||
},
|
||||
[searchText],
|
||||
);
|
||||
|
||||
// useEffect 在筛选条件变化时加载订单,并在离开页面时取消请求。
|
||||
useEffect(
|
||||
// 订单查询副作用响应筛选变化并在卸载时取消请求。
|
||||
() => {
|
||||
void loadOrders();
|
||||
return (
|
||||
// 订单查询清理回调使旧请求代次失效并取消网络请求。
|
||||
() => {
|
||||
orderGeneration.current += 1;
|
||||
orderAbort.current?.abort();
|
||||
}
|
||||
);
|
||||
},
|
||||
[loadOrders],
|
||||
);
|
||||
|
||||
// useEffect 加载订单展示所需的账号和商品辅助数据。
|
||||
useEffect(
|
||||
// 辅助数据副作用并行读取账号和商品列表。
|
||||
() => {
|
||||
// controller 允许页面卸载时取消辅助数据请求。
|
||||
const controller = new AbortController();
|
||||
auxiliaryAbort.current?.abort();
|
||||
auxiliaryAbort.current = controller;
|
||||
void Promise.all([
|
||||
getAccountDetails({ signal: controller.signal }),
|
||||
getItems(undefined, { signal: controller.signal }),
|
||||
]).then(
|
||||
// 辅助数据成功回调只接受尚未取消的响应。
|
||||
([accountList, itemsList]) => {
|
||||
if (controller.signal.aborted) return;
|
||||
setAccounts(accountList);
|
||||
setItems(itemsList);
|
||||
},
|
||||
).catch(
|
||||
// 辅助数据失败回调忽略主动取消产生的异常。
|
||||
(error: unknown) => {
|
||||
if (!controller.signal.aborted) console.error('加载订单辅助数据失败:', error);
|
||||
},
|
||||
);
|
||||
return (
|
||||
// 辅助数据清理回调取消账号和商品请求。
|
||||
() => controller.abort()
|
||||
);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// accountMap 将账号 ID 映射为账号详情,避免订单列表重复线性查找。
|
||||
const accountMap = useMemo(
|
||||
// 账号索引回调构建稳定的 ID 到详情映射。
|
||||
() => new Map(accounts.map(
|
||||
// account 是当前账号详情。
|
||||
account => [account.id, account],
|
||||
)),
|
||||
[accounts],
|
||||
);
|
||||
// itemNames 将商品 ID 映射为商品标题,供订单行快速读取。
|
||||
const itemNames = useMemo(
|
||||
// 商品索引回调构建稳定的商品 ID 到标题映射。
|
||||
() => {
|
||||
// namesMap 是商品名称索引的可变构建结果。
|
||||
const namesMap: Record<string, string> = {};
|
||||
items.forEach(
|
||||
// item 是当前商品列表项。
|
||||
item => {
|
||||
if (item.item_id) namesMap[`${item.cookie_id}:${item.item_id}`] = item.item_title || item.item_id;
|
||||
},
|
||||
);
|
||||
return namesMap;
|
||||
},
|
||||
[items],
|
||||
);
|
||||
|
||||
// accountName 将账号 ID 格式化为筛选下拉框名称。
|
||||
const accountName = useCallback(
|
||||
// 账号名称回调格式化筛选下拉框文本。
|
||||
(cookieId: string): string => {
|
||||
// account 是当前订单所属账号详情。
|
||||
const account = accountMap.get(cookieId);
|
||||
// name 是优先使用备注或昵称的展示名称。
|
||||
const name = account?.remark || account?.nickname;
|
||||
return name ? `${name} · ${cookieId.slice(0, 6)}` : `账号 ${cookieId.slice(0, 8)}`;
|
||||
},
|
||||
[accountMap],
|
||||
);
|
||||
|
||||
// accountNickname 将账号 ID 格式化为订单行中的短名称。
|
||||
const accountNickname = useCallback(
|
||||
// 账号昵称回调格式化订单行文本。
|
||||
(cookieId: string): string => {
|
||||
// account 是当前订单所属账号详情。
|
||||
const account = accountMap.get(cookieId);
|
||||
return account?.remark || account?.nickname || '未命名账号';
|
||||
},
|
||||
[accountMap],
|
||||
);
|
||||
|
||||
// getItemNameById 按订单标题、商品索引和相似标题依次解析商品名称。
|
||||
const getItemNameById = useCallback(
|
||||
// 商品名称回调按订单信息解析展示标题。
|
||||
(cookieId: string, itemId: string, orderItemTitle?: string): string => {
|
||||
if (orderItemTitle?.trim()) return orderItemTitle;
|
||||
// mappedName 是商品索引中直接命中的标题。
|
||||
const mappedName = itemNames[`${cookieId}:${itemId}`];
|
||||
if (mappedName) return mappedName;
|
||||
// matchingItem 是标题相似度匹配到的商品。
|
||||
const matchingItem = items.find(
|
||||
// item 是参与标题相似度匹配的商品。
|
||||
item => {
|
||||
if (!orderItemTitle || !item.item_title) return false;
|
||||
// orderTitleLower 是订单标题的标准化小写文本。
|
||||
const orderTitleLower = orderItemTitle.toLowerCase();
|
||||
// itemTitleLower 是商品标题的标准化小写文本。
|
||||
const itemTitleLower = item.item_title.toLowerCase();
|
||||
return itemTitleLower.includes(orderTitleLower) || orderTitleLower.includes(itemTitleLower);
|
||||
},
|
||||
);
|
||||
return matchingItem?.item_title || '未知商品';
|
||||
},
|
||||
[itemNames, items],
|
||||
);
|
||||
|
||||
return {
|
||||
orders,
|
||||
items,
|
||||
accounts,
|
||||
filter,
|
||||
setFilter,
|
||||
accountFilter,
|
||||
setAccountFilter,
|
||||
searchText,
|
||||
setSearchText,
|
||||
page,
|
||||
setPage,
|
||||
totalPages,
|
||||
loading,
|
||||
loadOrders,
|
||||
accountName,
|
||||
accountNickname,
|
||||
getItemNameById,
|
||||
};
|
||||
};
|
||||
|
||||
// useOrderImport 统一管理订单导入文件、取消、重试和导入后刷新。
|
||||
export const useOrderImport = (loadOrders: () => Promise<void>): OrderImportState => {
|
||||
// showImportModal 表示订单导入弹窗是否打开。
|
||||
const [showImportModal, setShowImportModal] = useState(false);
|
||||
// importFile 保存当前选择的导入文件。
|
||||
const [importFile, setImportFile] = useState<File | null>(null);
|
||||
// importResult 保存最近一次导入的逐行结果。
|
||||
const [importResult, setImportResult] = useState<ReturnType<typeof normalizeOrderImportResult> | null>(null);
|
||||
// importing 表示导入请求是否正在执行。
|
||||
const [importing, setImporting] = useState(false);
|
||||
// importError 保存导入失败后的可重试错误。
|
||||
const [importError, setImportError] = useState('');
|
||||
// importGeneration 隔离关闭弹窗后的旧导入响应。
|
||||
const importGeneration = useRef(0);
|
||||
// importAbort 保存当前导入请求的取消控制器。
|
||||
const importAbort = useRef<AbortController | null>(null);
|
||||
|
||||
// openImportModal 打开订单导入弹窗并重置上一次结果。
|
||||
const openImportModal = useCallback(
|
||||
// 打开弹窗回调清理上一次导入状态。
|
||||
() => {
|
||||
setImportFile(null);
|
||||
setImportResult(null);
|
||||
setImportError('');
|
||||
setShowImportModal(true);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// closeImportModal 关闭弹窗并取消未完成的导入请求。
|
||||
const closeImportModal = useCallback(
|
||||
// 关闭弹窗回调取消上传并使旧响应失效。
|
||||
() => {
|
||||
importGeneration.current += 1;
|
||||
importAbort.current?.abort();
|
||||
setImporting(false);
|
||||
setShowImportModal(false);
|
||||
setImportFile(null);
|
||||
setImportResult(null);
|
||||
setImportError('');
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// handleImportOrders 提交文件,刷新列表并保留失败文件供重试。
|
||||
const handleImportOrders = useCallback(
|
||||
// 订单导入回调执行预检、上传和列表刷新。
|
||||
async () => {
|
||||
if (!canSubmitOrderImport(importFile, importing)) return;
|
||||
// file 是经过提交门禁确认存在的本次上传文件。
|
||||
const file = importFile;
|
||||
if (!file) return;
|
||||
// validationError 是文件预检失败时展示给用户的说明。
|
||||
const validationError = validateOrderImportFile(file);
|
||||
if (validationError) {
|
||||
setImportError(validationError);
|
||||
return;
|
||||
}
|
||||
// generation 标记当前订单导入请求的代次。
|
||||
const generation = ++importGeneration.current;
|
||||
importAbort.current?.abort();
|
||||
// controller 允许关闭弹窗时取消文件上传。
|
||||
const controller = new AbortController();
|
||||
importAbort.current = controller;
|
||||
setImporting(true);
|
||||
setImportResult(null);
|
||||
setImportError('');
|
||||
try {
|
||||
// formData 是上传订单文件的 multipart 请求体。
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
// result 是后端返回的订单导入统计。
|
||||
const result = normalizeOrderImportResult(await importOrders(formData, { signal: controller.signal }));
|
||||
if (!isCurrentOrderRequest(generation, importGeneration.current)) return;
|
||||
setImportResult(result);
|
||||
setImportFile(null);
|
||||
await loadOrders();
|
||||
if (result.failed_count === 0 && isCurrentOrderRequest(generation, importGeneration.current)) {
|
||||
alert(`订单导入成功,共 ${result.success_count} 条`);
|
||||
setShowImportModal(false);
|
||||
setImportResult(null);
|
||||
}
|
||||
} catch (error: unknown /* 订单导入异常 */) {
|
||||
if (isCurrentOrderRequest(generation, importGeneration.current) && !controller.signal.aborted) {
|
||||
setImportError(orderErrorMessage(error, '导入失败,请检查文件格式'));
|
||||
}
|
||||
} finally {
|
||||
if (isCurrentOrderRequest(generation, importGeneration.current)) setImporting(false);
|
||||
}
|
||||
},
|
||||
[importFile, importing, loadOrders],
|
||||
);
|
||||
|
||||
// handleRetryImport 复用当前文件重试最近一次失败的导入。
|
||||
const handleRetryImport = useCallback(
|
||||
// 导入重试回调复用当前文件和请求边界。
|
||||
async () => {
|
||||
await handleImportOrders();
|
||||
},
|
||||
[handleImportOrders],
|
||||
);
|
||||
|
||||
return {
|
||||
showImportModal,
|
||||
importFile,
|
||||
setImportFile,
|
||||
importResult,
|
||||
importing,
|
||||
importError,
|
||||
openImportModal,
|
||||
closeImportModal,
|
||||
handleImportOrders,
|
||||
handleRetryImport,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import {
|
||||
canSubmitOrderImport,
|
||||
failedOrderImportRows,
|
||||
isCurrentOrderRequest,
|
||||
normalizeOrderImportResult,
|
||||
orderStatusOptions,
|
||||
validateOrderImportFile,
|
||||
} from './state';
|
||||
|
||||
// createFile 创建订单导入预检使用的最小浏览器文件对象。
|
||||
const createFile = (name: string): File => new File(['order'], name, { type: 'text/plain' });
|
||||
|
||||
test('订单导入响应归一化并保留失败行详情',
|
||||
// 导入结果测试验证汇总字段和失败行展示数据。
|
||||
() => {
|
||||
// result 是包含成功和失败行的后端兼容响应。
|
||||
const result = normalizeOrderImportResult({
|
||||
total: 2,
|
||||
success_count: 1,
|
||||
failed_count: 1,
|
||||
results: [
|
||||
{ order_id: 'ok', success: true, message: '订单已导入' },
|
||||
{ order_id: 'bad', success: false, message: '不支持的订单状态' },
|
||||
],
|
||||
});
|
||||
expect(result.failed_count).toBe(1);
|
||||
expect(failedOrderImportRows(result)).toEqual([
|
||||
{ order_id: 'bad', success: false, message: '不支持的订单状态' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('订单导入预检阻止重复提交和不支持的文件格式',
|
||||
// 导入预检测试验证文件格式和重复提交门禁。
|
||||
() => {
|
||||
expect(canSubmitOrderImport(createFile('orders.csv'), false)).toBe(true);
|
||||
expect(canSubmitOrderImport(createFile('orders.csv'), true)).toBe(false);
|
||||
expect(validateOrderImportFile(createFile('orders.xlsx'))).toBe('');
|
||||
expect(validateOrderImportFile(createFile('orders.exe'))).toContain('仅支持');
|
||||
expect(validateOrderImportFile(null)).toBe('请选择订单文件');
|
||||
});
|
||||
|
||||
test('订单请求代次和筛选标签保持稳定边界',
|
||||
// 查询边界测试验证旧响应隔离和筛选项顺序。
|
||||
() => {
|
||||
expect(isCurrentOrderRequest(4, 4)).toBe(true);
|
||||
expect(isCurrentOrderRequest(3, 4)).toBe(false);
|
||||
expect(orderStatusOptions.map(
|
||||
// option 是待验证顺序的筛选配置。
|
||||
option => option.key,
|
||||
)).toEqual([
|
||||
'all', 'processing', 'shipped', 'pending_ship', 'completed', 'cancelled', 'refunding',
|
||||
]);
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
import type { OrderImportResult, OrderImportRowResult } from './types';
|
||||
|
||||
// orderStatusOptions 是订单状态筛选标签的稳定配置。
|
||||
export const orderStatusOptions = [
|
||||
{ key: 'all', label: '全部' },
|
||||
{ key: 'processing', label: '处理中' },
|
||||
{ key: 'shipped', label: '已发货' },
|
||||
{ key: 'pending_ship', label: '待发货' },
|
||||
{ key: 'completed', label: '已完成' },
|
||||
{ key: 'cancelled', label: '已取消' },
|
||||
{ key: 'refunding', label: '退款中' },
|
||||
] as const;
|
||||
|
||||
// normalizeOrderImportResult 将后端兼容响应归一化为稳定的导入结果。
|
||||
export const normalizeOrderImportResult = (value: unknown): OrderImportResult => {
|
||||
// payload 是待读取字段的未知响应对象。
|
||||
const payload = typeof value === 'object' && value !== null ? value as Record<string, unknown> : {};
|
||||
// rawResults 是后端返回的逐行结果数组。
|
||||
const rawResults = Array.isArray(payload.results) ? payload.results : [];
|
||||
return {
|
||||
total: Number(payload.total || 0),
|
||||
success_count: Number(payload.success_count || 0),
|
||||
failed_count: Number(payload.failed_count || 0),
|
||||
results: rawResults.map(normalizeOrderImportRow),
|
||||
};
|
||||
};
|
||||
|
||||
// normalizeOrderImportRow 将单行未知响应转换为导入结果行。
|
||||
const normalizeOrderImportRow = (value: unknown): OrderImportRowResult => {
|
||||
// row 是待归一化的单行未知对象。
|
||||
const row = typeof value === 'object' && value !== null ? value as Record<string, unknown> : {};
|
||||
return {
|
||||
order_id: String(row.order_id || 'unknown'),
|
||||
success: row.success === true,
|
||||
message: String(row.message || ''),
|
||||
};
|
||||
};
|
||||
|
||||
// failedOrderImportRows 筛出需要在导入弹窗中展示的失败行。
|
||||
export const failedOrderImportRows = (result: OrderImportResult | null): OrderImportRowResult[] =>
|
||||
result?.results.filter(isFailedOrderImportRow) || [];
|
||||
|
||||
// isFailedOrderImportRow 判断导入结果行是否失败。
|
||||
const isFailedOrderImportRow = (row: OrderImportRowResult): boolean => !row.success;
|
||||
|
||||
// canSubmitOrderImport 检查订单导入是否具备文件且没有重复提交。
|
||||
export const canSubmitOrderImport = (file: File | null, importing: boolean): boolean =>
|
||||
file !== null && !importing;
|
||||
|
||||
// validateOrderImportFile 检查订单导入文件是否使用支持的扩展名。
|
||||
export const validateOrderImportFile = (file: File | null): string => {
|
||||
if (!file) return '请选择订单文件';
|
||||
// extension 是文件名中最后一个点号后的标准化扩展名。
|
||||
const extension = file.name.toLowerCase().split('.').pop() || '';
|
||||
return ['xlsx', 'csv', 'tsv', 'json'].includes(extension) ? '' : '仅支持 .xlsx、.csv、.tsv、.json 格式';
|
||||
};
|
||||
|
||||
// isCurrentOrderRequest 判断异步订单请求响应是否仍属于当前代次。
|
||||
export const isCurrentOrderRequest = (generation: number, currentGeneration: number): boolean =>
|
||||
generation === currentGeneration;
|
||||
|
||||
// orderErrorMessage 将未知异常提取为稳定的用户可见说明。
|
||||
export const orderErrorMessage = (error: unknown, fallback: string): string =>
|
||||
error instanceof Error && error.message ? error.message : fallback;
|
||||
@@ -0,0 +1,96 @@
|
||||
import type { Dispatch, SetStateAction } from 'react';
|
||||
import type { AccountDetail, Item, Order, OrderStatus } from '../../../types';
|
||||
|
||||
// OrderImportRowResult 描述订单导入接口返回的单行处理结果。
|
||||
export interface OrderImportRowResult {
|
||||
// order_id 是当前导入行对应的订单号。
|
||||
order_id: string;
|
||||
// success 表示当前订单是否导入成功。
|
||||
success: boolean;
|
||||
// message 是当前订单的成功或失败说明。
|
||||
message: string;
|
||||
}
|
||||
|
||||
// OrderImportResult 描述订单导入接口返回的汇总结果。
|
||||
export interface OrderImportResult {
|
||||
// total 是本次提交的订单总数。
|
||||
total: number;
|
||||
// success_count 是成功导入的订单数。
|
||||
success_count: number;
|
||||
// failed_count 是失败订单数。
|
||||
failed_count: number;
|
||||
// results 保存每一行的处理详情。
|
||||
results: OrderImportRowResult[];
|
||||
}
|
||||
|
||||
// OrderQueryState 暴露订单列表的查询数据、筛选条件和展示辅助方法。
|
||||
export interface OrderQueryState {
|
||||
// orders 是当前页的订单列表。
|
||||
orders: Order[];
|
||||
// items 是用于补充商品标题的商品列表。
|
||||
items: Item[];
|
||||
// accounts 是订单账号筛选下拉框的数据源。
|
||||
accounts: AccountDetail[];
|
||||
// filter 是当前订单状态筛选条件。
|
||||
filter: string;
|
||||
// setFilter 更新订单状态筛选条件。
|
||||
setFilter: Dispatch<SetStateAction<string>>;
|
||||
// accountFilter 是当前账号筛选条件。
|
||||
accountFilter: string;
|
||||
// setAccountFilter 更新账号筛选条件。
|
||||
setAccountFilter: Dispatch<SetStateAction<string>>;
|
||||
// searchText 是搜索框当前输入值。
|
||||
searchText: string;
|
||||
// setSearchText 更新搜索框当前输入值。
|
||||
setSearchText: Dispatch<SetStateAction<string>>;
|
||||
// page 是当前分页页码。
|
||||
page: number;
|
||||
// setPage 更新当前分页页码。
|
||||
setPage: Dispatch<SetStateAction<number>>;
|
||||
// totalPages 是服务端返回的总页数。
|
||||
totalPages: number;
|
||||
// loading 表示订单列表或刷新请求是否正在执行。
|
||||
loading: boolean;
|
||||
// loadOrders 刷新当前筛选条件下的订单列表。
|
||||
loadOrders: () => Promise<void>;
|
||||
// accountName 将账号 ID 转换为筛选下拉框展示名称。
|
||||
accountName: (cookieId: string) => string;
|
||||
// accountNickname 将账号 ID 转换为订单行展示名称。
|
||||
accountNickname: (cookieId: string) => string;
|
||||
// getItemNameById 根据订单信息解析商品展示名称。
|
||||
getItemNameById: (cookieId: string, itemId: string, orderItemTitle?: string) => string;
|
||||
}
|
||||
|
||||
// OrderImportState 暴露订单导入弹窗的状态和事件处理函数。
|
||||
export interface OrderImportState {
|
||||
// showImportModal 表示导入弹窗是否打开。
|
||||
showImportModal: boolean;
|
||||
// importFile 是当前待提交的订单文件。
|
||||
importFile: File | null;
|
||||
// setImportFile 更新当前待提交的订单文件。
|
||||
setImportFile: Dispatch<SetStateAction<File | null>>;
|
||||
// importResult 保存最近一次导入的逐行结果。
|
||||
importResult: OrderImportResult | null;
|
||||
// importing 表示订单导入请求是否正在执行。
|
||||
importing: boolean;
|
||||
// importError 保存最近一次导入请求的错误说明。
|
||||
importError: string;
|
||||
// openImportModal 打开弹窗并清理上一次导入状态。
|
||||
openImportModal: () => void;
|
||||
// closeImportModal 关闭弹窗并取消当前导入请求。
|
||||
closeImportModal: () => void;
|
||||
// handleImportOrders 提交当前文件并刷新订单列表。
|
||||
handleImportOrders: () => Promise<void>;
|
||||
// handleRetryImport 重试最近一次失败的导入请求。
|
||||
handleRetryImport: () => Promise<void>;
|
||||
}
|
||||
|
||||
// OrderStatusOption 描述订单状态筛选标签的显示配置。
|
||||
export interface OrderStatusOption {
|
||||
// key 是传给订单查询接口的状态值。
|
||||
key: string;
|
||||
// label 是筛选标签的中文名称。
|
||||
label: string;
|
||||
// status 是可选的强类型订单状态。
|
||||
status?: OrderStatus;
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { AccountDetail, Order, OrderStatus, Item } from '../types';
|
||||
import { getOrders, syncOrders, syncSingleOrder, manualShipOrder, updateOrder, deleteOrder, importOrders, getItems, getAccountDetails } from '../services/api';
|
||||
import { Search, MoreHorizontal, Truck, RefreshCw, Copy, ChevronLeft, ChevronRight, PackageCheck, Edit, Eye, Plus, Save, X, User as UserIcon, Phone, MapPin, Upload, ExternalLink, Trash2 } from 'lucide-react';
|
||||
import { failedOrderImportRows, normalizeOrderImportResult, OrderImportResult } from './orderImportState';
|
||||
import type { Order, OrderStatus } from '../types';
|
||||
import { deleteOrder, manualShipOrder, syncOrders, syncSingleOrder, updateOrder } from '../app/features/orders/api';
|
||||
import { OrderFilterBar } from '../app/features/orders/components/OrderFilterBar';
|
||||
import { OrderImportModal } from '../app/features/orders/components/OrderImportModal';
|
||||
import { useOrderImport, useOrderQuery } from '../app/features/orders/hooks';
|
||||
import { Truck, RefreshCw, ChevronLeft, ChevronRight, PackageCheck, Edit, Eye, Plus, Save, X, User as UserIcon, ExternalLink, Trash2 } from 'lucide-react';
|
||||
import { formatLocalDateTime } from '../dateTime';
|
||||
|
||||
const StatusBadge: React.FC<{ status: OrderStatus }> = ({ status }) => {
|
||||
@@ -35,142 +37,40 @@ const StatusBadge: React.FC<{ status: OrderStatus }> = ({ status }) => {
|
||||
};
|
||||
|
||||
const OrderList: React.FC = () => {
|
||||
const [orders, setOrders] = useState<Order[]>([]);
|
||||
const [items, setItems] = useState<Item[]>([]);
|
||||
const [accounts, setAccounts] = useState<AccountDetail[]>([]);
|
||||
const [itemNames, setItemNames] = useState<Record<string, string>>({});
|
||||
const [filter, setFilter] = useState('all');
|
||||
const [accountFilter, setAccountFilter] = useState('');
|
||||
const [searchText, setSearchText] = useState(''); // 搜索文本
|
||||
const [debouncedSearch, setDebouncedSearch] = useState('');
|
||||
const requestSequence = useRef(0);
|
||||
const [page, setPage] = useState(1);
|
||||
const [totalPages, setTotalPages] = useState(1);
|
||||
const [loading, setLoading] = useState(false);
|
||||
// orderQuery 负责订单查询、筛选、分页和展示辅助数据。
|
||||
const orderQuery = useOrderQuery();
|
||||
// importState 负责订单导入弹窗、上传取消和失败重试。
|
||||
const importState = useOrderImport(orderQuery.loadOrders);
|
||||
const { orders, accounts, filter, setFilter, accountFilter, setAccountFilter, searchText, setSearchText, page, setPage, totalPages, loading, loadOrders, accountName, accountNickname, getItemNameById } = orderQuery;
|
||||
const [showDetailModal, setShowDetailModal] = useState(false);
|
||||
const [showEditModal, setShowEditModal] = useState(false);
|
||||
const [showImportModal, setShowImportModal] = useState(false);
|
||||
const [selectedOrder, setSelectedOrder] = useState<Order | null>(null);
|
||||
const [editingOrder, setEditingOrder] = useState<Partial<Order> | null>(null);
|
||||
const [editForm, setEditForm] = useState<Partial<Order>>({});
|
||||
const [showShipModal, setShowShipModal] = useState(false);
|
||||
const [shipOrderId, setShipOrderId] = useState<string>('');
|
||||
const [shipLoading, setShipLoading] = useState(false);
|
||||
const [shipResult, setShipResult] = useState<{success: boolean; message: string} | null>(null);
|
||||
const [importFile, setImportFile] = useState<File | null>(null);
|
||||
const [importResult, setImportResult] = useState<OrderImportResult | null>(null);
|
||||
const [importing, setImporting] = useState(false);
|
||||
const [syncingOrderId, setSyncingOrderId] = useState<string | null>(null);
|
||||
const [deletingOrderId, setDeletingOrderId] = useState<string | null>(null);
|
||||
|
||||
const loadOrders = async () => {
|
||||
const sequence = ++requestSequence.current;
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
const res = await getOrders(accountFilter || undefined, filter, page, 20, debouncedSearch);
|
||||
if (sequence !== requestSequence.current) return;
|
||||
setOrders(res.data);
|
||||
setTotalPages(res.total_pages);
|
||||
} catch (e) {
|
||||
console.error('加载订单失败:', e);
|
||||
} finally {
|
||||
if (sequence === requestSequence.current) setLoading(false);
|
||||
}
|
||||
// handleFilterChange 切换订单状态筛选并回到第一页。
|
||||
const handleFilterChange = (value: string) => {
|
||||
setFilter(value);
|
||||
setPage(1);
|
||||
setSearchText('');
|
||||
};
|
||||
|
||||
// 从订单的 item_id 查找对应的商品名称(通过标题匹配)
|
||||
const getItemNameById = (cookieId: string, orderId: string, orderItemTitle?: string): string => {
|
||||
// 如果订单有 item_title,优先使用
|
||||
if (orderItemTitle && orderItemTitle.trim()) {
|
||||
return orderItemTitle;
|
||||
}
|
||||
|
||||
// 尝试通过 item_id 直接匹配
|
||||
if (itemNames[`${cookieId}:${orderId}`]) {
|
||||
return itemNames[`${cookieId}:${orderId}`];
|
||||
}
|
||||
|
||||
// 尝试在商品列表中查找相似标题的商品
|
||||
const matchingItem = items.find(item => {
|
||||
// 如果订单有标题,尝试匹配商品标题
|
||||
if (orderItemTitle && item.item_title) {
|
||||
// 检查是否包含关键词
|
||||
const orderTitleLower = orderItemTitle.toLowerCase();
|
||||
const itemTitleLower = item.item_title.toLowerCase();
|
||||
return itemTitleLower.includes(orderTitleLower) || orderTitleLower.includes(itemTitleLower);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (matchingItem?.item_title) {
|
||||
return matchingItem.item_title;
|
||||
}
|
||||
|
||||
return '未知商品';
|
||||
// handleAccountFilterChange 切换账号筛选并回到第一页。
|
||||
const handleAccountFilterChange = (value: string) => {
|
||||
setAccountFilter(value);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
// 从商品列表构建商品ID到商品名的映射
|
||||
const buildItemNamesMap = () => {
|
||||
const namesMap: Record<string, string> = {};
|
||||
items.forEach(item => {
|
||||
// 使用 item_id 作为键,商品标题作为值
|
||||
if (item.item_id) {
|
||||
namesMap[`${item.cookie_id}:${item.item_id}`] = item.item_title || item.item_id;
|
||||
}
|
||||
});
|
||||
setItemNames(namesMap);
|
||||
};
|
||||
|
||||
const buildItemNamesMapFrom = (itemsList: Item[]) => {
|
||||
const namesMap: Record<string, string> = {};
|
||||
itemsList.forEach(item => {
|
||||
if (item.item_id) {
|
||||
namesMap[`${item.cookie_id}:${item.item_id}`] = item.item_title || item.item_id;
|
||||
}
|
||||
});
|
||||
setItemNames(namesMap);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => {
|
||||
setPage(1);
|
||||
setDebouncedSearch(searchText.trim());
|
||||
}, 300);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [searchText]);
|
||||
|
||||
useEffect(() => {
|
||||
loadOrders();
|
||||
}, [accountFilter, filter, page, debouncedSearch]);
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all([getAccountDetails(), getItems()]).then(([accountList, itemsList]) => {
|
||||
setAccounts(accountList);
|
||||
setItems(itemsList);
|
||||
buildItemNamesMapFrom(itemsList);
|
||||
}).catch((e) => {
|
||||
console.error('加载商品列表失败:', e);
|
||||
});
|
||||
}, []);
|
||||
|
||||
const accountMap = useMemo(
|
||||
() => new Map(accounts.map(account => [account.id, account])),
|
||||
[accounts],
|
||||
);
|
||||
|
||||
const accountName = (cookieId: string) => {
|
||||
const account = accountMap.get(cookieId);
|
||||
const name = account?.remark || account?.nickname;
|
||||
return name ? `${name} · ${cookieId.slice(0, 6)}` : `账号 ${cookieId.slice(0, 8)}`;
|
||||
};
|
||||
const accountNickname = (cookieId: string) => {
|
||||
const account = accountMap.get(cookieId);
|
||||
return account?.remark || account?.nickname || '未命名账号';
|
||||
// handleSearchChange 更新订单搜索文本并回到第一页。
|
||||
const handleSearchChange = (value: string) => {
|
||||
setSearchText(value);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
const handleSync = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await syncOrders(accountFilter || undefined, filter);
|
||||
await loadOrders();
|
||||
@@ -180,8 +80,6 @@ const OrderList: React.FC = () => {
|
||||
} catch (error: any) {
|
||||
console.error('同步订单失败:', error);
|
||||
alert(error?.message || '同步失败,请重试');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -264,35 +162,6 @@ const OrderList: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleImportOrders = async () => {
|
||||
if (!importFile) return;
|
||||
setImporting(true);
|
||||
try {
|
||||
const formData = new FormData();
|
||||
formData.append('file', importFile);
|
||||
const result = normalizeOrderImportResult(await importOrders(formData));
|
||||
setImportResult(result);
|
||||
setImportFile(null);
|
||||
await loadOrders();
|
||||
if (result.failed_count === 0) {
|
||||
setShowImportModal(false);
|
||||
setImportResult(null);
|
||||
alert(`订单导入成功,共 ${result.success_count} 条`);
|
||||
}
|
||||
} catch (error: any) {
|
||||
alert(error?.message || '导入失败,请检查文件格式');
|
||||
} finally {
|
||||
setImporting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const closeImportModal = () => {
|
||||
if (importing) return;
|
||||
setShowImportModal(false);
|
||||
setImportFile(null);
|
||||
setImportResult(null);
|
||||
};
|
||||
|
||||
const handleSyncSingle = async (orderId: string) => {
|
||||
setSyncingOrderId(orderId);
|
||||
try {
|
||||
@@ -341,7 +210,7 @@ const OrderList: React.FC = () => {
|
||||
<RefreshCw className={`w-5 h-5 ${loading ? 'animate-spin' : ''}`} />
|
||||
</button>
|
||||
<button
|
||||
onClick={() => { setImportResult(null); setShowImportModal(true); }}
|
||||
onClick={importState.openImportModal}
|
||||
className="px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors text-sm flex items-center gap-2 shadow-lg"
|
||||
>
|
||||
<Plus className="w-4 h-4" />
|
||||
@@ -355,54 +224,16 @@ const OrderList: React.FC = () => {
|
||||
</div>
|
||||
|
||||
<div className="ios-card rounded-xl overflow-hidden shadow-lg border-0 bg-white">
|
||||
{/* Toolbar */}
|
||||
<div className="p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted">
|
||||
<div className="flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full">
|
||||
{[
|
||||
{k:'all', v:'全部'},
|
||||
{k:'processing', v:'处理中'},
|
||||
{k:'shipped', v:'已发货'},
|
||||
{k:'pending_ship', v:'待发货'},
|
||||
{k:'completed', v:'已完成'},
|
||||
{k:'cancelled', v:'已取消'},
|
||||
{k:'refunding', v:'退款中'}
|
||||
].map(opt => (
|
||||
<button
|
||||
key={opt.k}
|
||||
onClick={() => { setFilter(opt.k); setPage(1); setSearchText(''); }}
|
||||
className={`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${filter === opt.k ? 'bg-white text-black shadow-sm' : 'text-gray-500 hover:text-gray-700'}`}
|
||||
>
|
||||
{opt.v}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex w-full md:w-auto flex-col sm:flex-row gap-3">
|
||||
<div className="relative">
|
||||
<UserIcon className="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none" />
|
||||
<select
|
||||
aria-label="按账号筛选订单"
|
||||
value={accountFilter}
|
||||
onChange={(event) => { setAccountFilter(event.target.value); setPage(1); }}
|
||||
className="ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm"
|
||||
>
|
||||
<option value="">全部账号</option>
|
||||
{accounts.map(account => (
|
||||
<option key={account.id} value={account.id}>{accountName(account.id)}</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="relative group">
|
||||
<Search className="w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors" />
|
||||
<input
|
||||
type="text"
|
||||
placeholder="搜索订单号/商品/买家..."
|
||||
value={searchText}
|
||||
onChange={(e) => { setSearchText(e.target.value); setPage(1); }}
|
||||
className="ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<OrderFilterBar
|
||||
filter={filter}
|
||||
onFilterChange={handleFilterChange}
|
||||
accountFilter={accountFilter}
|
||||
onAccountFilterChange={handleAccountFilterChange}
|
||||
accounts={accounts}
|
||||
accountName={accountName}
|
||||
searchText={searchText}
|
||||
onSearchChange={handleSearchChange}
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
<div className="overflow-x-auto min-h-[400px]">
|
||||
@@ -673,89 +504,7 @@ const OrderList: React.FC = () => {
|
||||
document.body
|
||||
)}
|
||||
|
||||
{/* Import Modal - 使用 Portal */}
|
||||
{showImportModal && createPortal(
|
||||
<div className="modal-overlay-centered">
|
||||
<div className="modal-container">
|
||||
<div className="modal-header">
|
||||
<div className="flex items-center justify-between w-full">
|
||||
<h3 className="text-2xl font-extrabold text-gray-900">插入订单</h3>
|
||||
<button
|
||||
onClick={closeImportModal}
|
||||
className="p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors"
|
||||
>
|
||||
<X className="w-5 h-5 text-gray-600" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="modal-body space-y-5">
|
||||
<div>
|
||||
<label className="block text-sm font-bold text-gray-700 mb-2">选择Excel文件</label>
|
||||
<input
|
||||
type="file"
|
||||
accept=".xlsx,.csv,.tsv,.json"
|
||||
onChange={(e) => setImportFile(e.target.files?.[0] || null)}
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
/>
|
||||
<p className="text-xs text-gray-500 mt-2">支持 .xlsx、.csv、.tsv、.json 格式</p>
|
||||
</div>
|
||||
|
||||
{importFile && (
|
||||
<div className="p-3 bg-blue-50 rounded-xl">
|
||||
<div className="flex items-center gap-2">
|
||||
<Upload className="w-4 h-4 text-blue-600" />
|
||||
<span className="text-sm font-medium text-blue-900">{importFile.name}</span>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{importResult && importResult.failed_count > 0 && (
|
||||
<div className="space-y-3">
|
||||
<div className="rounded-xl bg-amber-50 border border-amber-100 p-3 text-sm font-bold text-amber-800">
|
||||
导入完成:成功 {importResult.success_count} 条,失败 {importResult.failed_count} 条
|
||||
</div>
|
||||
<div className="max-h-64 overflow-y-auto rounded-xl border border-gray-100">
|
||||
<table className="w-full text-left text-xs">
|
||||
<thead className="sticky top-0 bg-gray-50 text-gray-500">
|
||||
<tr><th className="px-3 py-2">订单ID</th><th className="px-3 py-2">失败原因</th></tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-gray-100">
|
||||
{failedOrderImportRows(importResult).map((row, index) => (
|
||||
<tr key={`${row.order_id}-${index}`}>
|
||||
<td className="px-3 py-2 font-mono">{row.order_id}</td>
|
||||
<td className="px-3 py-2 text-red-600">{row.message || '导入失败'}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="modal-footer">
|
||||
<div className="flex gap-3 w-full">
|
||||
<button
|
||||
onClick={closeImportModal}
|
||||
disabled={importing}
|
||||
className="flex-1 px-6 py-3 rounded-xl bg-gray-100 hover:bg-gray-200 text-gray-800 font-bold transition-colors"
|
||||
>
|
||||
取消
|
||||
</button>
|
||||
<button
|
||||
onClick={handleImportOrders}
|
||||
disabled={!importFile || importing}
|
||||
className="flex-1 px-6 py-3 rounded-xl ios-btn-primary font-bold shadow-lg shadow-blue-200 disabled:opacity-50"
|
||||
>
|
||||
{importing ? '正在导入…' : '导入订单'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body
|
||||
)}
|
||||
<OrderImportModal {...importState} />
|
||||
|
||||
{/* Ship Modal - 发货方式选择 */}
|
||||
{showShipModal && createPortal(
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import { failedOrderImportRows, normalizeOrderImportResult } from './orderImportState';
|
||||
|
||||
test('order import state preserves row-level failure details for display', () => {
|
||||
const result = normalizeOrderImportResult({
|
||||
total: 2,
|
||||
success_count: 1,
|
||||
failed_count: 1,
|
||||
results: [
|
||||
{ order_id: 'ok', success: true, message: '订单已导入' },
|
||||
{ order_id: 'bad', success: false, message: '不支持的订单状态' },
|
||||
],
|
||||
});
|
||||
expect(result.failed_count).toBe(1);
|
||||
expect(failedOrderImportRows(result)).toEqual([
|
||||
{ order_id: 'bad', success: false, message: '不支持的订单状态' },
|
||||
]);
|
||||
});
|
||||
@@ -1,26 +1,8 @@
|
||||
export interface OrderImportRowResult {
|
||||
order_id: string;
|
||||
success: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface OrderImportResult {
|
||||
total: number;
|
||||
success_count: number;
|
||||
failed_count: number;
|
||||
results: OrderImportRowResult[];
|
||||
}
|
||||
|
||||
export const normalizeOrderImportResult = (value: any): OrderImportResult => ({
|
||||
total: Number(value?.total || 0),
|
||||
success_count: Number(value?.success_count || 0),
|
||||
failed_count: Number(value?.failed_count || 0),
|
||||
results: Array.isArray(value?.results) ? value.results.map((row: any) => ({
|
||||
order_id: String(row?.order_id || 'unknown'),
|
||||
success: row?.success === true,
|
||||
message: String(row?.message || ''),
|
||||
})) : [],
|
||||
});
|
||||
|
||||
export const failedOrderImportRows = (result: OrderImportResult | null): OrderImportRowResult[] =>
|
||||
result?.results.filter(row => !row.success) || [];
|
||||
export {
|
||||
failedOrderImportRows,
|
||||
normalizeOrderImportResult,
|
||||
} from '../app/features/orders/state';
|
||||
export type {
|
||||
OrderImportResult,
|
||||
OrderImportRowResult,
|
||||
} from '../app/features/orders/types';
|
||||
@@ -146,6 +146,20 @@ test('getOrders maps unsupported backend statuses to unknown', async () => {
|
||||
expect(result.data[0].status).toBe('unknown');
|
||||
});
|
||||
|
||||
test('订单查询和导入 API 转发外部取消信号', async () => {
|
||||
// fetchMock 是同时验证订单查询和文件上传请求控制参数的替身。
|
||||
const fetchMock = vi.fn()
|
||||
.mockResolvedValueOnce(jsonResponse({ data: [], total_pages: 1 }))
|
||||
.mockResolvedValueOnce(jsonResponse({ success_count: 1, failed_count: 0, results: [] }));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
// controller 是 feature Hook 传入 API 的取消控制器。
|
||||
const controller = new AbortController();
|
||||
await getOrders(undefined, 'all', 1, 20, '', { signal: controller.signal });
|
||||
await importOrders(new FormData(), { signal: controller.signal });
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/orders?page=1&page_size=20', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/orders/import', expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
|
||||
test('getShippingRulesPage sends filters and preserves pagination metadata', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({
|
||||
data: [{ id: 7, name: '付款规则', trigger_type: 'order_paid', enabled: false, actions: [] }],
|
||||
|
||||
@@ -308,13 +308,14 @@ export const getOrders = async (
|
||||
page: number = 1,
|
||||
pageSize: number = 20,
|
||||
search?: string,
|
||||
options?: RequestControlOptions,
|
||||
): Promise<PaginatedResponse<Order>> => {
|
||||
const params: any = { page, page_size: pageSize };
|
||||
if (cookieId) params.cookie_id = cookieId;
|
||||
if (status && status !== 'all') params.status = status;
|
||||
if (search?.trim()) params.search = search.trim();
|
||||
|
||||
const res = await get<PaginatedResponse<Order> & { orders?: Order[] /* 后端兼容的订单列表字段。 */ }>('/api/v1/orders', params);
|
||||
const res = await get<PaginatedResponse<Order> & { orders?: Order[] /* 后端兼容的订单列表字段。 */ }>('/api/v1/orders', params, options);
|
||||
|
||||
// Handle backend response variations
|
||||
const rawOrders = res.orders || res.data || [];
|
||||
@@ -369,9 +370,9 @@ export const manualShipOrder = async (orderIds: string[], shipMode: 'status_only
|
||||
});
|
||||
}
|
||||
|
||||
export const importOrders = async (data: Partial<Order>[] | FormData): Promise<OrderBatchResponse> => {
|
||||
export const importOrders = async (data: Partial<Order>[] | FormData, options?: RequestControlOptions): Promise<OrderBatchResponse> => {
|
||||
const isFormData = data instanceof FormData;
|
||||
return isFormData ? postForm('/api/v1/orders/import', data) : post('/api/v1/orders/import', data);
|
||||
return isFormData ? postForm('/api/v1/orders/import', data, options) : post('/api/v1/orders/import', data, options);
|
||||
}
|
||||
|
||||
// Stats
|
||||
@@ -493,8 +494,8 @@ export const appendCardData = async (cardId: string | number, content: string, o
|
||||
const normalizeBooleanFlag = (value: unknown): boolean =>
|
||||
value === true || value === 1 || value === '1';
|
||||
|
||||
export const getItems = async (cookieId?: string): Promise<Item[]> => {
|
||||
const res = await get<Item[] | ItemListEnvelope>('/api/v1/items', cookieId ? { cookie_id: cookieId } : undefined);
|
||||
export const getItems = async (cookieId?: string, options?: RequestControlOptions): Promise<Item[]> => {
|
||||
const res = await get<Item[] | ItemListEnvelope>('/api/v1/items', cookieId ? { cookie_id: cookieId } : undefined, options);
|
||||
const items = Array.isArray(res) ? res : (res.items || []);
|
||||
return items.map((item: any) => ({
|
||||
...item,
|
||||
|
||||
+1
-1
@@ -413,4 +413,4 @@ import{r as h}from"./react-vendor-C_od1ZSF.js";/**
|
||||
*
|
||||
* This source code is licensed under the ISC license.
|
||||
* See the LICENSE file in the root directory of this source tree.
|
||||
*/const F1=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],_0=e("zap",F1);export{k2 as $,O1 as A,Q1 as B,i2 as C,r2 as D,l2 as E,s0 as F,u2 as G,K2 as H,c0 as I,d0 as J,f2 as K,z2 as L,P2 as M,q2 as N,x2 as O,D2 as P,I2 as Q,O2 as R,X2 as S,y0 as T,i0 as U,n2 as V,N2 as W,M0 as X,v2 as Y,_0 as Z,e0 as _,K1 as a,m2 as a0,B2 as a1,d2 as a2,o2 as a3,y2 as a4,b2 as a5,Z1 as a6,j2 as a7,p2 as a8,e2 as a9,J2 as aa,A2 as ab,n0 as ac,h2 as ad,g2 as ae,w2 as af,G2 as ag,L2 as ah,p0 as ai,l0 as aj,r0 as ak,X1 as al,a0 as am,$2 as an,H2 as ao,Q2 as b,t2 as c,a2 as d,V2 as e,c2 as f,Y2 as g,E2 as h,h0 as i,C2 as j,U2 as k,T2 as l,t0 as m,J1 as n,Z2 as o,Y1 as p,s2 as q,M2 as r,_2 as s,k0 as t,G1 as u,S2 as v,R2 as w,F2 as x,o0 as y,W2 as z};
|
||||
*/const F1=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],_0=e("zap",F1);export{k2 as $,O1 as A,Q1 as B,i2 as C,r2 as D,l2 as E,d0 as F,u2 as G,W2 as H,s0 as I,c0 as J,f2 as K,z2 as L,P2 as M,q2 as N,x2 as O,D2 as P,I2 as Q,O2 as R,X2 as S,y0 as T,i0 as U,n2 as V,N2 as W,M0 as X,v2 as Y,_0 as Z,e0 as _,K1 as a,m2 as a0,B2 as a1,d2 as a2,o2 as a3,y2 as a4,b2 as a5,Z1 as a6,j2 as a7,p2 as a8,e2 as a9,J2 as aa,A2 as ab,n0 as ac,h2 as ad,g2 as ae,w2 as af,G2 as ag,L2 as ah,p0 as ai,l0 as aj,r0 as ak,X1 as al,a0 as am,$2 as an,H2 as ao,Q2 as b,t2 as c,a2 as d,V2 as e,c2 as f,Y2 as g,E2 as h,h0 as i,C2 as j,U2 as k,T2 as l,t0 as m,J1 as n,Z2 as o,Y1 as p,s2 as q,M2 as r,_2 as s,k0 as t,G1 as u,S2 as v,R2 as w,F2 as x,o0 as y,K2 as z};
|
||||
@@ -0,0 +1,20 @@
|
||||
import{j as e,r as l,c as Ns,b as Oe,d as Ga}from"./react-vendor-C_od1ZSF.js";import{L as Qa,U as ma,M as cs,C as _s,B as ua,S as pa,Z as ds,a as ft,b as vs,G as Is,c as ws,d as ks,e as Va,f as at,A as Os,D as Ka,g as Rs,P as ha,h as Et,E as ga,T as Ha,i as Za,j as we,X as Le,k as Ya,l as Xa,m as Cs,n as ba,o as Ye,p as Ve,q as ya,K as el,r as nt,s as st,Q as Ht,t as ot,u as yt,v as Rt,R as Ue,w as fa,x as tl,y as Qe,z as Nt,F as Pt,H as Xe,I as Ps,J as jt,N as sl,O as al,V as ll,W as ja,Y as Na,_ as _a,$ as rl,a0 as nl,a1 as Zt,a2 as Mt,a3 as xs,a4 as il,a5 as ol,a6 as ms,a7 as $s,a8 as cl,a9 as dl,aa as $t,ab as Es,ac as Jt,ad as va,ae as xl,af as ml,ag as Vt,ah as wa,ai as ul,aj as pl,ak as hl,al as gl,am as bl,an as yl,ao as Ts}from"./icons-vendor-BJ6r5aOc.js";import{R as Bt,B as fl,X as Ds,Y as Ms,T as qt,a as jl,C as Yt,A as Nl,b as _l,c as vl,P as Bs,d as qs,L as wl}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 r of document.querySelectorAll('link[rel="modulepreload"]'))n(r);new MutationObserver(r=>{for(const f of r)if(f.type==="childList")for(const p of f.addedNodes)p.tagName==="LINK"&&p.rel==="modulepreload"&&n(p)}).observe(document,{childList:!0,subtree:!0});function a(r){const f={};return r.integrity&&(f.integrity=r.integrity),r.referrerPolicy&&(f.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?f.credentials="include":r.crossOrigin==="anonymous"?f.credentials="omit":f.credentials="same-origin",f}function n(r){if(r.ep)return;r.ep=!0;const f=a(r);fetch(r.href,f)}})();const kl=({className:t="w-full h-full text-white"})=>e.jsx("svg",{className:t,viewBox:"0 0 256 256","aria-hidden":"true",children:e.jsx("g",{stroke:"none",fill:"none",fillRule:"evenodd",children:e.jsx("path",{d:"M121.73,57.0003 C138.901,57.0003 154.897,65.5053 164.52,79.7493 C166.029,81.9823 165.441,85.0143 163.209,86.5233 C160.976,88.0323 157.944,87.4433 156.436,85.2113 C148.629,73.6553 135.655,66.7563 121.73,66.7563 C104.076789,66.7563 88.6201962,77.6596007 82.5581814,93.8184545 C83.9120803,93.7133631 85.2800264,93.66 86.6602,93.66 C111.537727,93.66 132.442611,110.997575 137.926382,134.224255 L162.5425,92.109 L162.615557,91.9879406 L162.756884,91.77367 L162.911804,91.5639102 L162.98657,91.4716759 C163.351845,91.025169 163.786059,90.6571744 164.264191,90.3738733 L164.550153,90.2178351 L164.729252,90.1315693 L164.989203,90.021723 L165.230265,89.9354653 L165.542393,89.8445739 C165.666021,89.8126706 165.790834,89.7857324 165.916565,89.7637431 L166.116517,89.7342499 C166.29505,89.7098142 166.475001,89.6957386 166.655596,89.6918808 L166.7539,89.693 C196.8909,89.693 221.4079,114.21 221.4079,144.347 C221.4079,174.482 196.8909,199 166.7539,199 L125.0869,199 C122.3919,199 120.2079,196.815 120.2079,194.122 C120.2079,191.429 122.3919,189.244 125.0869,189.244 L166.7539,189.244 C191.5109,189.244 211.6519,169.104 211.6519,144.347 C211.6519,120.513406 192.985349,100.957891 169.504046,99.5322548 L112.7745,196.584 C111.8995,198.08 110.2965,199 108.5635,199 L86.6602,199 C57.6182,199 33.9902,175.373 33.9902,146.33 C33.9902,122.475163 49.9316132,102.273061 71.7206298,95.817503 L71.9446339,94.967678 C78.0600632,72.5405324 98.33054,57.0003 121.73,57.0003 Z M86.6602,103.417 C62.9972,103.417 43.7462,122.667 43.7462,146.33 C43.7462,169.992 62.9972,189.244 86.6602,189.244 L105.7645,189.244 L129.869462,148.004782 C129.678439,147.482425 129.5742,146.918336 129.5742,146.33 C129.5742,122.667 110.3232,103.417 86.6602,103.417 Z",fill:"currentColor"})})}),us=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52Line truncated
|
||||
|
||||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(vs,{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:qe,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:le,children:"取消"}),e.jsxs("button",{onClick:c,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:le,children:[le?e.jsx(we,{className:"w-4 h-4 animate-spin"}):e.jsx(Ye,{className:"w-4 h-4"}),le?"保存中...":"保存"]})]})})]})}),document.body)]})},pn=[{key:"all",label:"全部"},{key:"processing",label:"处理中"},{key:"shipped",label:"已发货"},{key:"pending_ship",label:"待发货"},{key:"completed",label:"已完成"},{key:"cancelled",label:"已取消"},{key:"refunding",label:"退款中"}],hn=t=>{const s=typeof t=="object"&&t!==null?t:{},a=Array.isArray(s.results)?s.results:[];return{total:Number(s.total||0),success_count:Number(s.success_count||0),failed_count:Number(s.failed_count||0),results:a.map(gn)}},gn=t=>{const s=typeof t=="object"&&t!==null?t:{};return{order_id:String(s.order_id||"unknown"),success:s.success===!0,message:String(s.message||"")}},bn=t=>(t==null?void 0:t.results.filter(yn))||[],yn=t=>!t.success,fn=(t,s)=>t!==null&&!s,jn=t=>{if(!t)return"请选择订单文件";const s=t.name.toLowerCase().split(".").pop()||"";return["xlsx","csv","tsv","json"].includes(s)?"":"仅支持 .xlsx、.csv、.tsv、.json 格式"},it=(t,s)=>t===s,Nn=(t,s)=>t instanceof Error&&t.message?t.message:s,_n=({filter:t,onFilterChange:s,accountFilter:a,onAccountFilterChange:n,accounts:r,accountName:f,searchText:p,onSearchChange:w})=>{const m=C=>s(C.currentTarget.dataset.status||"all"),k=C=>n(C.target.value),u=C=>w(C.target.value);return e.jsxs("div",{className:"p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full",children:pn.map(C=>e.jsx("button",{"data-status":C.key,onClick:m,className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${t===C.key?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:C.label},C.key))}),e.jsxs("div",{className:"flex w-full md:w-auto flex-col sm:flex-row gap-3",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",{"aria-label":"按账号筛选订单",value:a,onChange:k,className:"ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm",children:[e.jsx("option",{value:"",children:"全部账号"}),r.map(C=>e.jsx("option",{value:C.id,children:f(C.id)},C.id))]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(Nt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:p,onChange:u,className:"ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"})]})]})]})},vn=t=>{const s=f=>{var p;t.setImportFile(((p=f.target.files)==null?void 0:p[0])||null)},a=()=>t.closeImportModal(),n=()=>void t.handleImportOrders(),r=()=>void t.handleRetryImport();return t.showImportModal?Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"插入订单"}),e.jsx("button",{onClick:a,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(Le,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"选择Excel文件"}),e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv,.json",onChange:s,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持 .xl
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.jsxs("p",{className:"text-xs text-gray-500",children:["预览:",a.appendPreview.length," 个有效卡密,空行自动忽略。"]})]}),a.appendError&&e.jsxs("div",{className:"rounded-xl bg-red-50 border border-red-200 p-3 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:a.appendError}),e.jsx("button",{type:"button",onClick:u,disabled:a.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),a.appendResult&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",a.appendResult.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:p,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),a.batchTab==="create"?e.jsxs("button",{onClick:K,disabled:!a.batchFile||a.batchBusy,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(we,{className:"w-4 h-4 animate-spin"}):e.jsx(Pt,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:W,disabled:!a.appendTargetId||a.appendPreview.length===0||a.batchBusy||t.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(we,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},Ln=({type:t})=>{switch(t){case"text":return e.jsx(Na,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(ja,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(ll,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(_s,{className:"w-5 h-5 text-gray-500"})}},An=(t,s,a)=>{const n=a.trim().toLocaleLowerCase();return t.filter(r=>(!s||r.type===s)&&(!n||r.name.toLocaleLowerCase().includes(n)))},Ma=t=>t.split(`
|
||||
`).map(s=>s.trim()).filter(Boolean),In=(t,s,a)=>!!(t&&Ma(s).length>0&&!a),gt=(t,s,a,n)=>t===s&&a===n,On=()=>{const[t,s]=l.useState([]),[a,n]=l.useState(!0),r=l.useRef(0),f=l.useRef(null),p=l.useCallback(async()=>{var k;const w=++r.current;(k=f.current)==null||k.abort();const m=new AbortController;f.current=m,n(!0);try{const u=await Ls({signal:m.signal});if(w!==r.current)return;s(u)}catch(u){w===r.current&&!m.signal.aborted&&console.error("加载卡密库存失败:",u)}finally{w===r.current&&n(!1)}},[]);return l.useEffect(()=>(p(),()=>{var m;r.current+=1,(m=f.current)==null||m.abort()}),[p]),{cards:t,setCards:s,loading:a,loadCards:p}},Rn=t=>{const s=t.dataCards,a=t.loadCards,[n,r]=l.useState(!1),[f,p]=l.useState("create"),[w,m]=l.useState(null),[k,u]=l.useState(null),[C,M]=l.useState(!1),[K,W]=l.useState(""),[j,R]=l.useState(""),[T,X]=l.useState(null),[V,se]=l.useState(""),Z=l.useRef(0),F=l.useRef(null),S=l.useRef(""),P=l.useMemo(()=>Ma(j),[j]),ee=l.useCallback(()=>{var L;p("create"),m(null),u(null),W((L=s[0])!=null&&L.id?String(s[0].id):""),R(""),X(null),se(""),r(!0)},[s]),d=l.useCallback(()=>{var L;Z.current+=1,(L=F.current)==null||L.abort(),M(!1),r(!1)},[]),G=l.useCallback(async()=>{var I;if(!w||C)return;const L=++Z.current;(I=F.current)==null||I.abort();const q=new AbortController;F.current=q,M(!0),u(null);try{const B=await hr(w,{signal:q.signal});if(!gt(L,Z.current,"",""))return;u(B),B.created>0&&await a()}catch(B){if(!gt(L,Z.current,"",""))return;u({error:(B==null?void 0:B.message)||"上传失败"})}finally{gt(L,Z.current,"","")&&M(!1)}},[C,w,a]),U=l.useCallback(async()=>{var B;if(!In(K,j,C))return;const L=K,q=++Z.current;S.current=L,(B=F.current)==null||B.abort();const I=new AbortController;F.current=I,M(!0),X(null),se("");try{const $=await gr(L,j,{signal:I.signal});if(!gt(q,Z.current,L,K))return;X({added:$.added}),R(""),await a()}catch($){if(!gt(q,Z.current,L,K))return;se(($==null?void 0:$.message)||"追加失败")}finally{gt(q,Z.current,L,K)&&M(!1)}},[j,K,C,a]),E=l.useCallback(async()=>{await G()},[G]),A=l.useCallback(async()=>{S.current&&K!==S.current||await U()},[K,U]);return{showBatchModal:n,setShowBatchModal:r,batchTab:f,setBatchTab:p,batchFile:w,setBatchFile:m,batchResult:k,batchBusy:C,appendTargetId:K,setAppendTargetId:W,appendContent:j,setAppendContent:R,appendResult:T,appendError:V,appendPreview:P,openBatchModal:ee,closeBatchModal:d,handleBatchCreate:G,handleBatchAppend:U,handleRetryBatchCreate:E,handleRetryBatchAppend:A}},Zs=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),Pn=()=>{const{cards:t,loadCards:s}=On(),[a,n]=l.useState(!1),[r,f]=l.useState(!1),[p,w]=l.useState(null),[m,k]=l.useState({}),[u,C]=l.useState(Zs),[M,K]=l.useState(""),[W,j]=l.useState(""),R=l.useMemo(()=>t.filter(d=>d.type==="data"),[t]),T=Rn({dataCards:R,loadCards:s}),X=d=>{var G,U,E,A,L;w(d),k({id:d.id,name:d.name||"",type:d.type||"text",api_url:((G=d.api_config)==null?void 0:G.url)||"",api_method:((U=d.api_config)==null?void 0:U.method)||"GET",api_timeout:((E=d.api_config)==null?void 0:E.timeout)||10,api_headers:((A=d.api_config)==null?void 0:A.headers)||"",api_params:((L=d.api_config)==null?void 0:L.params)||"",text_content:d.text_content||"",data_content:d.data_content||"",image_url:d.image_url||"",delay_seconds:d.delay_seconds||0,description:d.description||"",enabled:d.enabled}),n(!0)},V=async()=>{var d,G,U,E,A,L,q,I;if(p){if(!((d=m.name)!=null&&d.trim())){alert("请输入卡密名称");return}if(!m.type){alert("请选择卡密类型");return}try{const B={name:m.name.trim(),type:m.type,description:(G=m.description)==null?void 0:G.trim(),delay_seconds:m.delay_seconds||0,enabled:m.enabled??!0};m.type==="api"?B.api_config={url:((U=m.api_url)==null?void 0:U.trim())||"",method:m.api_method,timeout:m.api_timeout||10,headers:((E=m.api_headers)==null?void 0:E.trim())||void 0,params:((A=m.api_params)==null?void 0:A.trim())||void 0}:m.type==="text"?B.text_content=((L=m.text_content)==null?void 0:L.trim())||"":m.type==="data"?B.data_content=((q=m.data_content)==null?void 0:q.trim())||"":m.type==="image"&&(B.image_url=((I=m.image_url)==null?void 0:I.trim())||""),await Js(p.id,B),n(!1),await s()}catch(B){console.error("更新卡密失败:",B),alert("更新失败,请重试")}}},se=async d=>{if(confirm("确认删除该卡密吗?"))try{await pr(d),await s()}catch(G){console.error("删除卡密失败:",G),alert("删除失败,请重试")}},Z=async()=>{if(!u.name.trim()){alert("请输入卡密名称");return}if(!u.content.trim()){alert(u.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const d={name:u.name.trim(),type:u.type,description:u.description.trim(),enabled:u.enabled,delay_seconds:u.delay_seconds};u.type==="text"&&(d.text_content=u.content.trim()),u.type==="data"&&(d.data_content=u.content.trim()),u.type==="image"&&(d.image_url=u.content.trim()),u.type==="api"&&(d.api_config={url:u.content.trim(),method:u
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(q=>q.map(I=>`"${String(I).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),E=new Blob(["\uFEFF"+U],{type:"text/csv;charset=utf-8"}),A=URL.createObjectURL(E),L=document.createElement("a");L.href=A,L.download="卡密组批量导入模板.csv",document.body.appendChild(L),L.click(),L.remove(),URL.revokeObjectURL(A)};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:T.openBatchModal,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(Pt,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>f(!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(Xe,{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:M,onChange:d=>K(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(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:W,onChange:d=>j(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",P.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:P.map(d=>{let G="";return d.type==="data"&&d.data_content?G=`库存: ${d.data_content.split(`
|
||||
`).filter(E=>E.trim()).length} 条`:d.type==="text"&&d.text_content?G=d.text_content:d.type==="api"&&d.api_config?G=d.api_config.url:d.type==="image"&&d.image_url&&(G="图片链接"),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(Ln,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>S(d.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(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 ${d.type==="text"?"bg-blue-50 text-blue-600":d.type==="data"?"bg-purple-50 text-purple-600":d.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:d.type==="text"?"文本":d.type==="data"?"批量":d.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:G,children:G})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:d.description||"-",children:d.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>F(d),className:`w-12 h-8 rounded-full relative transition-colors ${d.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${d.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>X(d),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(jt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>se(d.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Qe,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),P.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ha,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&p&&Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>n(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Le,{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:m.name||"",onChange:d=>k({...m,name:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:m.type||"text",onChange:d=>k({...m,type:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(p==null?void 0:p.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),m.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:m.api_url||"",onChange:d=>k({...m,api_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxLine truncated
|
||||
卡号1:密码1
|
||||
卡号2:密码2
|
||||
或者
|
||||
兑换码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:m.data_content?m.data_content.split(`
|
||||
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),m.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:m.image_url||"",onChange:d=>k({...m,image_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),m.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:m.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:d=>{d.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:m.delay_seconds||0,onChange:d=>k({...m,delay_seconds:parseInt(d.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:m.description||"",onChange:d=>k({...m,description:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>k({...m,enabled:!m.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${m.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 ${m.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>n(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:V,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),r&&Oe.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:()=>f(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(Le,{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:u.name,onChange:d=>C({...u,name:d.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>C({...u,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${u.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(_s,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>C({...u,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${u.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Na,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>C({...u,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${u.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:
Line truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),u.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:u.content.split(`
|
||||
`).filter(d=>d.trim()).length})," 条"]})]}),u.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:u.api_method,onChange:d=>C({...u,api_method:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:u.api_timeout,onChange:d=>C({...u,api_timeout:parseInt(d.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:u.api_headers,onChange:d=>C({...u,api_headers:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:u.api_params,onChange:d=>C({...u,api_params:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:u.description,onChange:d=>C({...u,description:d.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:u.delay_seconds,onChange:d=>C({...u,delay_seconds:parseInt(d.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>f(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:Z,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Xe,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),e.jsx(Sn,{dataCards:R,downloadCardTemplate:ee,...T})]})},Ys="ydisks-amap-js-api",$n="c9b68d4ce9a2a97f22a4a439404488ca";let Lt=null;const En=()=>$n,Tn=()=>window.AMap?Promise.resolve(window.AMap):Lt||(Lt=new Promise((t,s)=>{const a=document.getElementById(Ys),n=a||document.createElement("script"),r=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(p)},f=()=>{window.AMap?(r(),t(window.AMap)):(r(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},p=window.setTimeout(()=>{r(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=f,n.id=Ys,n.async=!0,n.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(En())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,n.onerror=()=>{r(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(n)}).catch(t=>{throw Lt=null,t}),Lt),Qt=t=>Number.isFinite(t)&&t!==0,Dn=t=>{var r,f;const s=Number((r=t.location)==null?void 0:r.lng),a=Number((f=t.location)==null?void 0:f.lat),n={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:a,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!n.division_id||!n.province||!n.city||!n.poi_id||!n.poi_name||!Qt(s)||!Qt(a)||s<-180||s>180||a<-90||a>90?null:n},Mn=async(t,s)=>{if(!Qt(t)||!Qt(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await Tn();return new Promise((n,r)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(p,w)=>{var k;if(p!=="complete"){if(p==="no_data"){n([]);return}r(new Error("高德地图附近地址查询失败,请稍后重试"));return}const m=(((k=w==null?void 0:w.poiList)==null?void 0:k.pois)||[]).map(Dn).filter(u=>u!==null);n(m)})})},Bn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),fs=t=>t==="running"||t==="canceling",qn=t=>!!(t!=null&&t.prev
Line truncated
|
||||
`),Ie=new Blob(["\uFEFF"+me],{type:"text/csv;charset=utf-8"}),Ge=URL.createObjectURL(Ie),qe=document.createElement("a");qe.href=Ge,qe.download="批量铺货模板.csv",document.body.appendChild(qe),qe.click(),qe.remove(),URL.revokeObjectURL(Ge)},kt=()=>{q(c=>({...c,cookie_id:w||c.cookie_id})),X(!0)},ct=()=>{B(c=>({...c,cookie_id:w||c.cookie_id})),se(!0)},dt=async c=>{if(!(c?w:I.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");F(!0),navigator.geolocation.getCurrentPosition(async me=>{try{const Ie=await Mn(me.coords.longitude,me.coords.latitude);if(!Ie.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");c?(_(Ie),O(Ie[0])):(P(Ie),d(Ie[0]))}catch(Ie){alert((Ie==null?void 0:Ie.message)||"获取发货地失败")}finally{F(!1)}},me=>{F(!1),alert(me.code===me.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},Ct=c=>n.filter(z=>z.cookie_id===c.cookie_id&&z.item_id===c.item_id).length>0?n.filter(z=>z.cookie_id===c.cookie_id&&z.item_id===c.item_id):n.filter(z=>z.cookie_id===c.cookie_id&&!z.item_id),xt=l.useMemo(()=>new Map(f.map(c=>[c.id,c])),[f]),mt=l.useMemo(()=>k?s.filter(c=>c.cookie_id===k):s,[k,s]),He=c=>{const z=xt.get(c),me=(z==null?void 0:z.remark)||(z==null?void 0:z.nickname);return me?`${me} · ${c.slice(0,6)}`:`账号 ${c.slice(0,8)}`},ut=c=>{const z=xt.get(c);return(z==null?void 0:z.remark)||(z==null?void 0:z.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(nl,{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:k,onChange:c=>u(c.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),f.map(c=>e.jsx("option",{value:c.id,children:He(c.id)},c.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(ot,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:w,onChange:c=>m(c.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),f.map(c=>e.jsx("option",{value:c.id,children:He(c.id)},c.id))]})]})]}),e.jsxs("button",{onClick:ke,disabled:C||!w,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Ue,{className:`w-4 h-4 ${C?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:kt,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(Xe,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:ct,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Zt,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Y(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Mt,{className:"w-4 h-4"}),re&&["running","canceling"].includes(re.status)?"继续批量任务":"批量铺货"]}),re&&!["running","canceling"].includes(re.status)&&e.jsx("button",{onClick:()=>void ve(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[mt.map(c=>{const z=Ct(c),me=z.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex flex
Line truncated
|
||||
@@ -0,0 +1 @@
|
||||
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:6Line truncated
|
||||
@@ -1 +0,0 @@
|
||||
*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(147 197 253 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:rgb(var(--color-neutral-200) / 1)}:before,:after{--tw-content: ""}html,:host{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:-apple-system,BlinkMacSystemFont,PingFang SC,Hiragino Sans GB,Microsoft YaHei,Helvetica Neue,Helvetica,Arial,sans-serif;font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-feature-settings:normal;font-variation-settings:normal;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-feature-settings:inherit;font-variation-settings:inherit;font-size:100%;font-weight:inherit;line-height:inherit;letter-spacing:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,input:where([type=button]),input:where([type=reset]),input:where([type=submit]){-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}dialog{padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}input::placeholder,textarea::placeholder{opacity:1;color:rgb(var(--color-neutral-400) / 1)}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]:where(:not([hidden=until-found])){display:none}.\!container{width:100%!important}.container{width:100%}@media(min-width:640px){.\!container{max-width:640px!important}.container{max-width:6Line truncated
|
||||
@@ -1,20 +0,0 @@
|
||||
import{j as e,r as l,c as js,b as Me,d as Ja}from"./react-vendor-C_od1ZSF.js";import{L as Ga,U as xa,M as os,C as Ns,B as ma,S as ua,Z as cs,a as ft,b as _s,G as As,c as vs,d as ws,e as Va,f as lt,A as Is,D as Qa,g as Os,P as pa,h as $t,E as ha,T as Ka,i as Ha,j as Se,X as Oe,k as Za,l as Ya,m as ks,n as ga,o as Xe,p as Qe,q as ba,K as Xa,r as nt,s as at,Q as Kt,t as it,u as bt,v as Ot,R as Je,w as fa,x as el,y as Ve,z as et,F as Rs,H as jt,I as yt,J as Rt,N as tl,O as sl,V as al,W as ya,Y as ja,_ as Na,$ as ll,a0 as rl,a1 as Ht,a2 as Dt,a3 as ds,a4 as nl,a5 as il,a6 as xs,a7 as Ps,a8 as ol,a9 as cl,aa as Pt,ab as $s,ac as Wt,ad as _a,ae as dl,af as xl,ag as Vt,ah as va,ai as ml,aj as ul,ak as pl,al as hl,am as gl,an as bl,ao as Ts}from"./icons-vendor-BFpWAqQX.js";import{R as Mt,B as fl,X as Es,Y as Ds,T as Bt,a as yl,C as Zt,A as jl,b as Nl,c as _l,P as Ms,d as Bs,L as vl}from"./charts-vendor-BxxJOyEX.js";import"./vendor-D-Edl3pr.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))n(i);new MutationObserver(i=>{for(const _ of i)if(_.type==="childList")for(const j of _.addedNodes)j.tagName==="LINK"&&j.rel==="modulepreload"&&n(j)}).observe(document,{childList:!0,subtree:!0});function a(i){const _={};return i.integrity&&(_.integrity=i.integrity),i.referrerPolicy&&(_.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?_.credentials="include":i.crossOrigin==="anonymous"?_.credentials="omit":_.credentials="same-origin",_}function n(i){if(i.ep)return;i.ep=!0;const _=a(i);fetch(i.href,_)}})();const wl=({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:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52Line truncated
|
||||
|
||||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(_s,{className:"w-4 h-4"}),"AI如何工作"]}),e.jsxs("ul",{className:"text-xs text-blue-800 space-y-1",children:[e.jsx("li",{children:"• 自动识别买家的砍价请求"}),e.jsx("li",{children:"• 根据设定的策略智能回复"}),e.jsx("li",{children:"• 在合理范围内同意降价或礼貌拒绝"}),e.jsx("li",{children:"• 保持专业友好的沟通风格"})]})]})]}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:Fe,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:ce,children:"取消"}),e.jsxs("button",{onClick:c,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:ce,children:[ce?e.jsx(Se,{className:"w-4 h-4 animate-spin"}):e.jsx(Xe,{className:"w-4 h-4"}),ce?"保存中...":"保存"]})]})})]})}),document.body)]})},un=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))||[],Ks=({status:t})=>{const s={processing:"bg-blue-100 text-blue-800",pending_ship:"bg-brand text-white",shipped:"bg-blue-100 text-blue-700",completed:"bg-green-100 text-green-700",cancelled:"bg-gray-100 text-gray-500",refunding:"bg-red-100 text-red-600",unknown:"bg-gray-100 text-gray-500"},a={processing:"处理中",pending_ship:"待发货",shipped:"已发货",completed:"已完成",cancelled:"已取消",refunding:"退款中",unknown:"未知"};return e.jsx("span",{className:`px-3 py-1.5 rounded-lg text-xs font-bold ${s[t]||s.cancelled}`,children:a[t]||t})},hn=()=>{const[t,s]=l.useState([]),[a,n]=l.useState([]),[i,_]=l.useState([]),[j,S]=l.useState({}),[u,w]=l.useState("all"),[g,I]=l.useState(""),[M,H]=l.useState(""),[Z,N]=l.useState(""),$=l.useRef(0),[E,V]=l.useState(1),[Y,ae]=l.useState(1),[se,oe]=l.useState(!1),[L,ee]=l.useState(!1),[le,d]=l.useState(!1),[J,F]=l.useState(!1),[C,B]=l.useState(null),[k,Q]=l.useState(null),[O,z]=l.useState({}),[R,x]=l.useState(!1),[b,G]=l.useState(""),[v,U]=l.useState(!1),[ne,ie]=l.useState(null),[_e,Ae]=l.useState(null),[Pe,Ee]=l.useState(null),[Be,h]=l.useState(!1),[X,pe]=l.useState(null),[y,ce]=l.useState(null),D=async()=>{const m=++$.current;oe(!0);try{const T=await sr(g||void 0,u,E,20,Z);if(m!==$.current)return;s(T.data),ae(T.total_pages)}catch(T){console.error("加载订单失败:",T)}finally{m===$.current&&oe(!1)}},xe=(m,T,me)=>{if(me&&me.trim())return me;if(j[`${m}:${T}`])return j[`${m}:${T}`];const Ne=a.find(Ke=>{if(me&&Ke.item_title){const Ue=me.toLowerCase(),We=Ke.item_title.toLowerCase();return We.includes(Ue)||Ue.includes(We)}return!1});return Ne!=null&&Ne.item_title?Ne.item_title:"未知商品"},te=m=>{const T={};m.forEach(me=>{me.item_id&&(T[`${me.cookie_id}:${me.item_id}`]=me.item_title||me.item_id)}),S(T)};l.useEffect(()=>{const m=window.setTimeout(()=>{V(1),N(M.trim())},300);return()=>window.clearTimeout(m)},[M]),l.useEffect(()=>{D()},[g,u,E,Z]),l.useEffect(()=>{Promise.all([Tt(),Nt()]).then(([m,T])=>{_(m),n(T),te(T)}).catch(m=>{console.error("加载商品列表失败:",m)})},[]);const $e=l.useMemo(()=>new Map(i.map(m=>[m.id,m])),[i]),Le=m=>{const T=$e.get(m),me=(T==null?void 0:T.remark)||(T==null?void 0:T.nickname);return me?`${me} · ${m.slice(0,6)}`:`账号 ${m.slice(0,8)}`},De=m=>{const T=$e.get(m);return(T==null?void 0:T.remark)||(T==null?void 0:T.nickname)||"未命名账号"},f=async()=>{oe(!0);try{const m=await rr(g||void 0,u);await D(),m!=null&&m.message&&alert(m.message)}catch(m){console.error("同步订单失败:",m),alert((m==null?void 0:m.message)||"同步失败,请重试")}finally{oe(!1)}},A=m=>{G(m),ie(null),x(!0)},W=async m=>{var T;U(!0),ie(null);try{const me=await ir([b],m),Ne=(T=me==null?void 0:me.results)==null?void 0:T[0];Ne!=null&&Ne.success?(ie({success:!0,message:Ne.message}),D()):ie({success:!1,message:(Ne==null?void 0:Ne.message)||"发货失败"})}catch(me){ie({success:!1,message:(me==null?void 0:me.message)||"请求失败"})}finally{U(!1)}},K=m=>{B(m),ee(!0)},ke=m=>{Q({...m}),d(!0)},je=async()=>{if(!(!k||!k.order_id))try{const m={};k.status!==void 0&&(m.order_status=k.status),k.buyer_id!==void 0&&(m.buyer_id=k.buyer_id),k.amount!==void 0&&(m.amount=k.amount),k.receiver_name!==void 0&&(m.receiver_name=k.receiver_name),k.receiver_phone!==voi
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.jsxs("p",{className:"text-xs text-gray-500",children:["预览:",a.appendPreview.length," 个有效卡密,空行自动忽略。"]})]}),a.appendError&&e.jsxs("div",{className:"rounded-xl bg-red-50 border border-red-200 p-3 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:a.appendError}),e.jsx("button",{type:"button",onClick:g,disabled:a.batchBusy,className:"font-bold whitespace-nowrap",children:"重试"})]}),a.appendResult&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",a.appendResult.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:j,className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),a.batchTab==="create"?e.jsxs("button",{onClick:H,disabled:!a.batchFile||a.batchBusy,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(Se,{className:"w-4 h-4 animate-spin"}):e.jsx(Rt,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:Z,disabled:!a.appendTargetId||a.appendPreview.length===0||a.batchBusy||t.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[a.batchBusy?e.jsx(Se,{className:"w-4 h-4 animate-spin"}):e.jsx(et,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},bn=({type:t})=>{switch(t){case"text":return e.jsx(ja,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(ya,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(al,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(Ns,{className:"w-5 h-5 text-gray-500"})}},fn=(t,s,a)=>{const n=a.trim().toLocaleLowerCase();return t.filter(i=>(!s||i.type===s)&&(!n||i.name.toLocaleLowerCase().includes(n)))},Da=t=>t.split(`
|
||||
`).map(s=>s.trim()).filter(Boolean),yn=(t,s,a)=>!!(t&&Da(s).length>0&&!a),ht=(t,s,a,n)=>t===s&&a===n,jn=()=>{const[t,s]=l.useState([]),[a,n]=l.useState(!0),i=l.useRef(0),_=l.useRef(null),j=l.useCallback(async()=>{var w;const S=++i.current;(w=_.current)==null||w.abort();const u=new AbortController;_.current=u,n(!0);try{const g=await Ss({signal:u.signal});if(S!==i.current)return;s(g)}catch(g){S===i.current&&!u.signal.aborted&&console.error("加载卡密库存失败:",g)}finally{S===i.current&&n(!1)}},[]);return l.useEffect(()=>(j(),()=>{var u;i.current+=1,(u=_.current)==null||u.abort()}),[j]),{cards:t,setCards:s,loading:a,loadCards:j}},Nn=t=>{const s=t.dataCards,a=t.loadCards,[n,i]=l.useState(!1),[_,j]=l.useState("create"),[S,u]=l.useState(null),[w,g]=l.useState(null),[I,M]=l.useState(!1),[H,Z]=l.useState(""),[N,$]=l.useState(""),[E,V]=l.useState(null),[Y,ae]=l.useState(""),se=l.useRef(0),oe=l.useRef(null),L=l.useRef(""),ee=l.useMemo(()=>Da(N),[N]),le=l.useCallback(()=>{var k;j("create"),u(null),g(null),Z((k=s[0])!=null&&k.id?String(s[0].id):""),$(""),V(null),ae(""),i(!0)},[s]),d=l.useCallback(()=>{var k;se.current+=1,(k=oe.current)==null||k.abort(),M(!1),i(!1)},[]),J=l.useCallback(async()=>{var O;if(!S||I)return;const k=++se.current;(O=oe.current)==null||O.abort();const Q=new AbortController;oe.current=Q,M(!0),g(null);try{const z=await pr(S,{signal:Q.signal});if(!ht(k,se.current,"",""))return;g(z),z.created>0&&await a()}catch(z){if(!ht(k,se.current,"",""))return;g({error:(z==null?void 0:z.message)||"上传失败"})}finally{ht(k,se.current,"","")&&M(!1)}},[I,S,a]),F=l.useCallback(async()=>{var z;if(!yn(H,N,I))return;const k=H,Q=++se.current;L.current=k,(z=oe.current)==null||z.abort();const O=new AbortController;oe.current=O,M(!0),V(null),ae("");try{const R=await hr(k,N,{signal:O.signal});if(!ht(Q,se.current,k,H))return;V({added:R.added}),$(""),await a()}catch(R){if(!ht(Q,se.current,k,H))return;ae((R==null?void 0:R.message)||"追加失败")}finally{ht(Q,se.current,k,H)&&M(!1)}},[N,H,I,a]),C=l.useCallback(async()=>{await J()},[J]),B=l.useCallback(async()=>{L.current&&H!==L.current||await F()},[H,F]);return{showBatchModal:n,setShowBatchModal:i,batchTab:_,setBatchTab:j,batchFile:S,setBatchFile:u,batchResult:w,batchBusy:I,appendTargetId:H,setAppendTargetId:Z,appendContent:N,setAppendContent:$,appendResult:E,appendError:Y,appendPreview:ee,openBatchModal:le,closeBatchModal:d,handleBatchCreate:J,handleBatchAppend:F,handleRetryBatchCreate:C,handleRetryBatchAppend:B}},Hs=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),_n=()=>{const{cards:t,loadCards:s}=jn(),[a,n]=l.useState(!1),[i,_]=l.useState(!1),[j,S]=l.useState(null),[u,w]=l.useState({}),[g,I]=l.useState(Hs),[M,H]=l.useState(""),[Z,N]=l.useState(""),$=l.useMemo(()=>t.filter(d=>d.type==="data"),[t]),E=Nn({dataCards:$,loadCards:s}),V=d=>{var J,F,C,B,k;S(d),w({id:d.id,name:d.name||"",type:d.type||"text",api_url:((J=d.api_config)==null?void 0:J.url)||"",api_method:((F=d.api_config)==null?void 0:F.method)||"GET",api_timeout:((C=d.api_config)==null?void 0:C.timeout)||10,api_headers:((B=d.api_config)==null?void 0:B.headers)||"",api_params:((k=d.api_config)==null?void 0:k.params)||"",text_content:d.text_content||"",data_content:d.data_content||"",image_url:d.image_url||"",delay_seconds:d.delay_seconds||0,description:d.description||"",enabled:d.enabled}),n(!0)},Y=async()=>{var d,J,F,C,B,k,Q,O;if(j){if(!((d=u.name)!=null&&d.trim())){alert("请输入卡密名称");return}if(!u.type){alert("请选择卡密类型");return}try{const z={name:u.name.trim(),type:u.type,description:(J=u.description)==null?void 0:J.trim(),delay_seconds:u.delay_seconds||0,enabled:u.enabled??!0};u.type==="api"?z.api_config={url:((F=u.api_url)==null?void 0:F.trim())||"",method:u.api_method,timeout:u.api_timeout||10,headers:((C=u.api_headers)==null?void 0:C.trim())||void 0,params:((B=u.api_params)==null?void 0:B.trim())||void 0}:u.type==="text"?z.text_content=((k=u.text_content)==null?void 0:k.trim())||"":u.type==="data"?z.data_content=((Q=u.data_content)==null?void 0:Q.trim())||"":u.type==="image"&&(z.image_url=((O=u.image_url)==null?void 0:O.trim())||""),await Ws(j.id,z),n(!1),await s()}catch(z){console.error("更新卡密失败:",z),alert("更新失败,请重试")}}},ae=async d=>{if(confirm("确认删除该卡密吗?"))try{await ur(d),await s()}catch(J){console.error("删除卡密失败:",J),alert("删除失败,请重试")}},se=async()=>{if(!g.name.trim()){alert("请输入卡密名称");return}if(!g.content.trim()){alert(g.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const d={name:g.name.trim(),type:g.type,description:g.description.trim(),enabled:g.enabled,delay_seconds:g.delay_seconds};g.type==="text"&&(d.text_content=g.content.trim()),g.type==="data"&&(d.data_content=g.content.trim()),g.type==="image"&&(d.image_url=g.content.trim()),g.type==="api"&&(d.api_config={url:g.cont
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(Q=>Q.map(O=>`"${String(O).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),C=new Blob(["\uFEFF"+F],{type:"text/csv;charset=utf-8"}),B=URL.createObjectURL(C),k=document.createElement("a");k.href=B,k.download="卡密组批量导入模板.csv",document.body.appendChild(k),k.click(),k.remove(),URL.revokeObjectURL(B)};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:E.openBatchModal,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(Rt,{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(Na,{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:M,onChange:d=>H(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-9 text-sm shadow-sm",children:[e.jsx("option",{value:"",children:"全部类型"}),e.jsx("option",{value:"data",children:"批量卡密"}),e.jsx("option",{value:"text",children:"文本"}),e.jsx("option",{value:"api",children:"API"}),e.jsx("option",{value:"image",children:"图片"})]})]}),e.jsxs("div",{className:"relative w-full sm:max-w-sm",children:[e.jsx(jt,{className:"pointer-events-none absolute left-4 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400"}),e.jsx("input",{type:"search","aria-label":"按卡密名称搜索",placeholder:"搜索卡密名称...",value:Z,onChange:d=>N(d.target.value),className:"ios-input w-full rounded-xl border-none bg-white py-2.5 pl-10 pr-4 text-sm shadow-sm"})]})]}),e.jsxs("div",{className:"whitespace-nowrap px-1 text-xs font-bold text-gray-400",children:["显示 ",ee.length," / ",t.length," 组"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full table-fixed text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-white text-gray-400 text-xs font-bold uppercase tracking-wider border-b border-gray-50",children:[e.jsx("th",{className:"w-[23%] px-5 py-5",children:"卡密名称"}),e.jsx("th",{className:"w-[8%] px-3 py-5",children:"卡密组ID"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"类型"}),e.jsx("th",{className:"w-[27%] px-5 py-5",children:"内容/库存"}),e.jsx("th",{className:"w-[19%] px-5 py-5",children:"描述"}),e.jsx("th",{className:"w-[7%] px-2 py-5",children:"状态"}),e.jsx("th",{className:"w-[9%] px-3 py-5 text-right",children:"操作"})]})}),e.jsx("tbody",{className:"divide-y divide-gray-50",children:ee.map(d=>{let J="";return d.type==="data"&&d.data_content?J=`库存: ${d.data_content.split(`
|
||||
`).filter(C=>C.trim()).length} 条`:d.type==="text"&&d.text_content?J=d.text_content:d.type==="api"&&d.api_config?J=d.api_config.url:d.type==="image"&&d.image_url&&(J="图片链接"),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(bn,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:()=>L(d.id),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(ll,{className:"h-3 w-3 shrink-0"})]})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("span",{className:`inline-flex rounded-md px-2 py-1 text-[11px] font-bold ${d.type==="text"?"bg-blue-50 text-blue-600":d.type==="data"?"bg-purple-50 text-purple-600":d.type==="api"?"bg-blue-50 text-blue-600":"bg-pink-50 text-pink-600"}`,children:d.type==="text"?"文本":d.type==="data"?"批量":d.type==="api"?"API":"图片"})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"line-clamp-3 break-all font-mono text-sm leading-5 text-gray-600",title:J,children:J})}),e.jsx("td",{className:"px-5 py-5",children:e.jsx("span",{className:"block truncate text-sm text-gray-500",title:d.description||"-",children:d.description||"-"})}),e.jsx("td",{className:"px-2 py-5",children:e.jsx("button",{onClick:()=>oe(d),className:`w-12 h-8 rounded-full relative transition-colors ${d.enabled?"bg-green-500":"bg-gray-300"}`,children:e.jsx("div",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-sm transition-transform ${d.enabled?"left-5":"left-1"}`})})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("div",{className:"flex items-center justify-end gap-0.5",children:[e.jsx("button",{onClick:()=>V(d),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(yt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>ae(d.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Ve,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),ee.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(pa,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&j&&Me.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>n(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(Oe,{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:u.name||"",onChange:d=>w({...u,name:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:u.type||"text",onChange:d=>w({...u,type:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(j==null?void 0:j.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),u.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:u.api_url||"",onChange:d=>w({...u,api_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jLine 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:u.data_content?u.data_content.split(`
|
||||
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),u.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:u.image_url||"",onChange:d=>w({...u,image_url:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),u.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:u.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:d=>{d.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:u.delay_seconds||0,onChange:d=>w({...u,delay_seconds:parseInt(d.target.value)||0}),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:u.description||"",onChange:d=>w({...u,description:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:()=>w({...u,enabled:!u.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${u.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 ${u.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>n(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:Y,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(Xe,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),i&&Me.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(Oe,{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:g.name,onChange:d=>I({...g,name:d.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>I({...g,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${g.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(Ns,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>I({...g,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${g.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(ja,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>I({...g,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${g.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:
Line truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),g.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:g.content.split(`
|
||||
`).filter(d=>d.trim()).length})," 条"]})]}),g.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:g.api_method,onChange:d=>I({...g,api_method:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:g.api_timeout,onChange:d=>I({...g,api_timeout:parseInt(d.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:g.api_headers,onChange:d=>I({...g,api_headers:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:g.api_params,onChange:d=>I({...g,api_params:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:g.description,onChange:d=>I({...g,description:d.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:g.delay_seconds,onChange:d=>I({...g,delay_seconds:parseInt(d.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>_(!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:se,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),e.jsx(gn,{dataCards:$,downloadCardTemplate:le,...E})]})},Zs="ydisks-amap-js-api",vn="c9b68d4ce9a2a97f22a4a439404488ca";let St=null;const wn=()=>vn,kn=()=>window.AMap?Promise.resolve(window.AMap):St||(St=new Promise((t,s)=>{const a=document.getElementById(Zs),n=a||document.createElement("script"),i=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(j)},_=()=>{window.AMap?(i(),t(window.AMap)):(i(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},j=window.setTimeout(()=>{i(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=_,n.id=Zs,n.async=!0,n.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(wn())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,n.onerror=()=>{i(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(n)}).catch(t=>{throw St=null,t}),St),Gt=t=>Number.isFinite(t)&&t!==0,Cn=t=>{var i,_;const s=Number((i=t.location)==null?void 0:i.lng),a=Number((_=t.location)==null?void 0:_.lat),n={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:s,latitude:a,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!n.division_id||!n.province||!n.city||!n.poi_id||!n.poi_name||!Gt(s)||!Gt(a)||s<-180||s>180||a<-90||a>90?null:n},Sn=async(t,s)=>{if(!Gt(t)||!Gt(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await kn();return new Promise((n,i)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(j,S)=>{var w;if(j!=="complete"){if(j==="no_data"){n([]);return}i(new Error("高德地图附近地址查询失败,请稍后重试"));return}const u=(((w=S==null?void 0:S.poiList)==null?void 0:w.pois)||[]).map(Cn).filter(g=>g!==null);n(u)})})},Ln=t=>t.find(s=>s.status==="running"||s.status==="canceling"),fs=t=>t==="running"||t==="canceling",An=t=>!!(t!=null&&t.pre
Line truncated
|
||||
`),Re=new Blob(["\uFEFF"+ge],{type:"text/csv;charset=utf-8"}),Ge=URL.createObjectURL(Re),Fe=document.createElement("a");Fe.href=Ge,Fe.download="批量铺货模板.csv",document.body.appendChild(Fe),Fe.click(),Fe.remove(),URL.revokeObjectURL(Ge)},wt=()=>{Q(c=>({...c,cookie_id:S||c.cookie_id})),V(!0)},ot=()=>{z(c=>({...c,cookie_id:S||c.cookie_id})),ae(!0)},ct=async c=>{if(!(c?S:O.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");oe(!0),navigator.geolocation.getCurrentPosition(async ge=>{try{const Re=await Sn(ge.coords.longitude,ge.coords.latitude);if(!Re.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");c?(f(Re),A(Re[0])):(ee(Re),d(Re[0]))}catch(Re){alert((Re==null?void 0:Re.message)||"获取发货地失败")}finally{oe(!1)}},ge=>{oe(!1),alert(ge.code===ge.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},kt=c=>n.filter(q=>q.cookie_id===c.cookie_id&&q.item_id===c.item_id).length>0?n.filter(q=>q.cookie_id===c.cookie_id&&q.item_id===c.item_id):n.filter(q=>q.cookie_id===c.cookie_id&&!q.item_id),dt=l.useMemo(()=>new Map(_.map(c=>[c.id,c])),[_]),xt=l.useMemo(()=>w?s.filter(c=>c.cookie_id===w):s,[w,s]),Ze=c=>{const q=dt.get(c),ge=(q==null?void 0:q.remark)||(q==null?void 0:q.nickname);return ge?`${ge} · ${c.slice(0,6)}`:`账号 ${c.slice(0,8)}`},mt=c=>{const q=dt.get(c);return(q==null?void 0:q.remark)||(q==null?void 0:q.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(rl,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:w,onChange:c=>g(c.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),_.map(c=>e.jsx("option",{value:c.id,children:Ze(c.id)},c.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(it,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:S,onChange:c=>u(c.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),_.map(c=>e.jsx("option",{value:c.id,children:Ze(c.id)},c.id))]})]})]}),e.jsxs("button",{onClick:T,disabled:I||!S,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(Je,{className:`w-4 h-4 ${I?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:wt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(et,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:ot,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(Ht,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void W(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white hover:bg-brand-highlight transition-colors flex items-center gap-2 shadow-lg shadow-blue-100",children:[e.jsx(Dt,{className:"w-4 h-4"}),te&&["running","canceling"].includes(te.status)?"继续批量任务":"批量铺货"]}),te&&!["running","canceling"].includes(te.status)&&e.jsx("button",{onClick:()=>void ke(),className:"px-4 py-3 rounded-2xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"最近批次结果"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-4",children:[xt.map(c=>{const q=kt(c),ge=q.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex f
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-D_XA_mO5.js"></script>
|
||||
<script type="module" crossorigin src="/static/assets/index-7zzRZ1Ef.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-C_od1ZSF.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-BFpWAqQX.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-BJ6r5aOc.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-DFTgpFf2.css">
|
||||
<link rel="stylesheet" crossorigin href="/static/assets/index-DBrkfYTo.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
Reference in new issue
Block a user