阶段七:完成CardList React feature化与批量追加边界
This commit is contained in:
1 parent
03f108639d
commit
66ac84b32d
18 files changed
+1105
-975
No files matched your search
+412
-694
File diff suppressed because it is too large.
Load diff
@@ -172,7 +172,8 @@ app shell / routes
|
||||
- 已完成阶段 7 第一个 PR 切片“React Rules feature 化与 API/行为测试边界”:按 `app/features/rules` 提取 Rules API 适配层、领域类型、数据 Hook、异常面板和交互状态模型;规则页通过 Hook 管理服务端数据与请求代次,保留旧组件入口和现有 API 路径;行为测试覆盖成功、失败、重复提交、过期响应和页签切换;前端类型检查、全量测试、注释检查和构建门禁通过,合并为一个可回滚提交;
|
||||
- 已完成阶段 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 化与卡密库存/批量追加行为边界”:提取卡密 API、库存 Hook 和批量追加组件,补充卡密筛选、追加预览、提交取消、失败重试和账号切换过期响应测试;
|
||||
- 已完成阶段 7 第四个 PR 切片“React CardList feature 化与卡密库存/批量追加行为边界”:按 `app/features/cards` 提取卡密 API 适配层、库存数据 Hook、批量导入/追加状态 Hook 和弹窗组件;卡密筛选、追加预览、提交取消、失败重试与账号切换过期响应均由 feature 状态边界负责,保留旧组件入口和 API 路径;新增状态模型测试并通过前端类型检查、全量测试、注释检查和构建门禁,合并为一个可回滚提交;
|
||||
- 阶段 7 下一 PR 切片为“React OrderList feature 化与订单导入/刷新行为边界”:提取订单 API、导入/刷新 Hook 和订单筛选组件,补充导入预检、刷新取消、失败重试和过期响应测试;
|
||||
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
|
||||
|
||||
## 6. 阶段 0:治理文档与强约束
|
||||
@@ -594,3 +595,4 @@ npm --prefix frontend run build
|
||||
| 2026-08-14 | 完成阶段 7 第一个 PR 切片“React Rules feature 化与 API/行为测试边界” | 新增 `app/features/rules` 的 API 适配层、领域类型、数据 Hook、异常面板和交互状态模型;规则请求支持并行加载与请求代次门禁,保存动作阻断重复提交;行为测试覆盖成功、失败、重复提交、过期响应和页签切换;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React ItemList feature 化与批量发布行为边界 |
|
||||
| 2026-08-14 | 完成阶段 7 第二个 PR 切片“React ItemList feature 化与批量发布行为边界” | 新增 `app/features/items` 的 API 适配层、批量任务类型、批量 Hook、批量状态模型和阶段指示器组件;批量预检、任务恢复、轮询过期响应、安全取消和失败重试均有独立状态边界;行为测试覆盖预检门禁、取消状态、失败重试、历史任务筛选和过期轮询响应;前端类型检查、全量测试、注释检查和构建门禁通过并合并为一个可回滚提交 | 阶段 7:React AccountList feature 化与账号运行状态行为边界 |
|
||||
| 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 化与订单导入/刷新行为边界 |
|
||||
@@ -0,0 +1,12 @@
|
||||
// 卡密 feature 只通过本适配层访问库存和批量接口,页面不直接依赖共享 API 文件。
|
||||
export {
|
||||
appendCardData,
|
||||
batchCreateCards,
|
||||
createCard,
|
||||
deleteCard,
|
||||
getCards,
|
||||
updateCard,
|
||||
} from '../../../services/api';
|
||||
|
||||
// 卡密 feature 重新导出接口响应类型,保持批量结果契约稳定。
|
||||
export type { CardAppendResponse, CardBatchResponse } from '../../../types';
|
||||
@@ -0,0 +1,34 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import type { Card } from '../../../types';
|
||||
import { canSubmitAppend, filterCards, isCurrentCardRequest, previewAppendContent } from './batchState';
|
||||
|
||||
// cards 是卡密筛选测试使用的最小卡密组列表。
|
||||
const cards = [
|
||||
{ id: 1, name: '年终总结 PPT', type: 'text', enabled: true },
|
||||
{ id: 2, name: '年终总结兑换码', type: 'data', enabled: true },
|
||||
{ id: 3, name: '产品介绍 PPT', type: 'text', enabled: false },
|
||||
] as Card[];
|
||||
|
||||
test('卡密筛选同时满足类型和名称条件',
|
||||
// 类型和名称筛选必须使用 AND 语义,避免展示无关库存。
|
||||
() => {
|
||||
expect(filterCards(cards, 'text', '年终')).toEqual([cards[0]]);
|
||||
expect(filterCards(cards, '', ' ppt ')).toEqual([cards[0], cards[2]]);
|
||||
});
|
||||
|
||||
test('追加预览会去除空行并裁剪每行空白',
|
||||
// 预览数量与最终提交内容共用同一套规范化规则。
|
||||
() => {
|
||||
expect(previewAppendContent(' VIP-001\n\nVIP-002 \n ')).toEqual(['VIP-001', 'VIP-002']);
|
||||
expect(canSubmitAppend('2', ' VIP-001\n', false)).toBe(true);
|
||||
expect(canSubmitAppend('2', '\n', false)).toBe(false);
|
||||
expect(canSubmitAppend('2', 'VIP-001', true)).toBe(false);
|
||||
});
|
||||
|
||||
test('追加目标切换后拒绝旧请求响应和旧代次响应',
|
||||
// 用户切换卡密组或关闭弹窗后,旧追加请求不能覆盖当前状态。
|
||||
() => {
|
||||
expect(isCurrentCardRequest(3, 3, '2', '2')).toBe(true);
|
||||
expect(isCurrentCardRequest(2, 3, '2', '2')).toBe(false);
|
||||
expect(isCurrentCardRequest(3, 3, '2', '3')).toBe(false);
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { Card } from '../../../types';
|
||||
|
||||
// filterCards 按类型和名称筛选卡密组,两个条件同时满足才保留。
|
||||
export const filterCards = (
|
||||
cards: Card[],
|
||||
typeFilter: Card['type'] | '',
|
||||
nameSearch: string,
|
||||
): Card[] => {
|
||||
// keyword 是去除首尾空格并转为小写的名称搜索词。
|
||||
const keyword = nameSearch.trim().toLocaleLowerCase();
|
||||
return cards.filter(
|
||||
// card 是待判断是否符合筛选条件的卡密组。
|
||||
card => (
|
||||
(!typeFilter || card.type === typeFilter)
|
||||
&& (!keyword || card.name.toLocaleLowerCase().includes(keyword))
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
// previewAppendContent 将追加文本转换为去除空行后的卡密预览列表。
|
||||
export const previewAppendContent = (content: string): string[] => content
|
||||
.split('\n')
|
||||
.map(
|
||||
// line 是追加文本中的单行原始内容。
|
||||
line => line.trim(),
|
||||
)
|
||||
.filter(Boolean);
|
||||
|
||||
// canSubmitAppend 判断当前追加表单是否具备目标卡密组和有效内容。
|
||||
export const canSubmitAppend = (targetId: string, content: string, busy: boolean): boolean => Boolean(
|
||||
targetId && previewAppendContent(content).length > 0 && !busy,
|
||||
);
|
||||
|
||||
// isCurrentCardRequest 判断卡密目标切换后响应是否仍属于当前请求。
|
||||
export const isCurrentCardRequest = (
|
||||
requestGeneration: number,
|
||||
currentGeneration: number,
|
||||
requestTargetId: string,
|
||||
currentTargetId: string,
|
||||
): boolean => requestGeneration === currentGeneration && requestTargetId === currentTargetId;
|
||||
@@ -0,0 +1,152 @@
|
||||
import React from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { FileDown, ListPlus, Loader2, Plus, Upload, X } from 'lucide-react';
|
||||
import type { Card } from '../../../../types';
|
||||
import type { CardBatchModalProps } from '../types';
|
||||
|
||||
// BatchCardImportModal 负责卡密批量创建和单组库存追加的交互界面。
|
||||
export const BatchCardImportModal: React.FC<CardBatchModalProps> = ({
|
||||
dataCards,
|
||||
downloadCardTemplate,
|
||||
...state
|
||||
}) => {
|
||||
// handleFileChange 保存用户选择的批量导入文件。
|
||||
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
state.setBatchFile(event.target.files?.[0] || null);
|
||||
};
|
||||
// handleAppendContentChange 更新追加文本并保留原始换行,预览由 Hook 派生。
|
||||
const handleAppendContentChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
||||
state.setAppendContent(event.target.value);
|
||||
};
|
||||
// handleTargetChange 切换追加库存目标卡密组。
|
||||
const handleTargetChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
||||
state.setAppendTargetId(event.target.value);
|
||||
};
|
||||
// handleClose 关闭弹窗并取消当前批量请求。
|
||||
const handleClose = () => state.closeBatchModal();
|
||||
// handleCreateTab 切换到批量创建页签。
|
||||
const handleCreateTab = () => state.setBatchTab('create');
|
||||
// handleAppendTab 切换到库存追加页签。
|
||||
const handleAppendTab = () => state.setBatchTab('append');
|
||||
// handleRetryCreate 重试最近一次批量创建。
|
||||
const handleRetryCreate = () => void state.handleRetryBatchCreate();
|
||||
// handleRetryAppend 重试最近一次库存追加。
|
||||
const handleRetryAppend = () => void state.handleRetryBatchAppend();
|
||||
// completedBatchResult 只保留包含逐行统计的成功批量结果。
|
||||
const completedBatchResult = state.batchResult && 'rows' in state.batchResult ? state.batchResult : null;
|
||||
// renderCardOption 渲染追加目标卡密组的下拉选项。
|
||||
const renderCardOption = (card: Card) => <option key={card.id} value={String(card.id)}>{card.name}(ID: {card.id})</option>;
|
||||
// handleSubmitCreate 提交批量创建请求。
|
||||
const handleSubmitCreate = () => void state.handleBatchCreate();
|
||||
// handleSubmitAppend 提交批量追加请求。
|
||||
const handleSubmitAppend = () => void state.handleBatchAppend();
|
||||
|
||||
if (!state.showBatchModal) return null;
|
||||
|
||||
return createPortal(
|
||||
<div className="modal-overlay">
|
||||
<div className="modal-container" style={{ maxWidth: '40rem' }}>
|
||||
<div className="px-6 py-5 border-b border-gray-100 flex items-center justify-between">
|
||||
<h3 className="text-xl font-extrabold text-gray-900">批量导入卡密</h3>
|
||||
<button onClick={handleClose} className="w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center">
|
||||
<X className="w-5 h-5 text-gray-600" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="px-6 py-5 space-y-5">
|
||||
<div className="flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl">
|
||||
<button onClick={handleCreateTab} className={`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${state.batchTab === 'create' ? 'bg-brand text-white shadow-md' : 'bg-white text-gray-600 hover:bg-gray-50'}`}>
|
||||
<ListPlus className="w-4 h-4" />批量创建卡密组
|
||||
</button>
|
||||
<button onClick={handleAppendTab} className={`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${state.batchTab === 'append' ? 'bg-brand text-white shadow-md' : 'bg-white text-gray-600 hover:bg-gray-50'}`}>
|
||||
<Upload className="w-4 h-4" />往单个组充卡密
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{state.batchTab === 'create' ? (
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5">
|
||||
上传表格,每行一个卡密组。表头:<code className="bg-blue-100/70 px-1.5 py-0.5 rounded">名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值</code>。
|
||||
类型填 text/data/image;data 类型的“内容”按行存卡密(CSV 单元格内换行需用引号包裹)。
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<button onClick={downloadCardTemplate} className="px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transition-colors">
|
||||
<FileDown className="w-4 h-4" />下载模板
|
||||
</button>
|
||||
<label className="flex-1 px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm cursor-pointer transition-colors">
|
||||
<Upload className="w-4 h-4" />{state.batchFile ? state.batchFile.name : '选择 .xlsx / .csv / .tsv'}
|
||||
<input type="file" accept=".xlsx,.csv,.tsv" className="hidden" onChange={handleFileChange} />
|
||||
</label>
|
||||
</div>
|
||||
{state.batchResult?.error && (
|
||||
<div className="rounded-xl border border-red-200 bg-red-50 p-4 text-sm text-red-700 flex items-center justify-between gap-3">
|
||||
<span>{state.batchResult.error}</span>
|
||||
<button type="button" onClick={handleRetryCreate} disabled={!state.batchFile || state.batchBusy} className="font-bold whitespace-nowrap">重试</button>
|
||||
</div>
|
||||
)}
|
||||
{completedBatchResult && (
|
||||
<div className="rounded-xl border border-gray-200 p-4 space-y-2">
|
||||
<div className="text-sm font-bold text-gray-900">共 {completedBatchResult.total} 行 · 成功 {completedBatchResult.created} · 失败 {completedBatchResult.failed}</div>
|
||||
{completedBatchResult.failed > 0 && (
|
||||
<div className="max-h-48 overflow-y-auto space-y-1">
|
||||
{completedBatchResult.rows.filter(
|
||||
// row 是批量结果中的单行处理记录。
|
||||
row => !row.success,
|
||||
).map(
|
||||
// row 是待展示失败说明的单行结果。
|
||||
row => (
|
||||
<div key={row.row_no} className="text-xs text-red-600">第 {row.row_no} 行「{row.name}」:{row.error}</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{dataCards.length === 0 ? (
|
||||
<div className="rounded-xl bg-amber-50 border border-amber-200 p-4 text-sm text-amber-800">暂无 data(批量卡密)类型的卡密组,请先创建一个再充卡密。</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">选择卡密组</label>
|
||||
<select value={state.appendTargetId} onChange={handleTargetChange} className="w-full ios-input px-4 py-3 rounded-xl text-sm">
|
||||
{dataCards.map(renderCardOption)}
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">卡密号(每行一个)</label>
|
||||
<textarea value={state.appendContent} onChange={handleAppendContentChange} placeholder={'VIP-001\nVIP-002\nVIP-003'} className="w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y" />
|
||||
<p className="text-xs text-gray-500">预览:{state.appendPreview.length} 个有效卡密,空行自动忽略。</p>
|
||||
</div>
|
||||
{state.appendError && (
|
||||
<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">
|
||||
<span>{state.appendError}</span>
|
||||
<button type="button" onClick={handleRetryAppend} disabled={state.batchBusy} className="font-bold whitespace-nowrap">重试</button>
|
||||
</div>
|
||||
)}
|
||||
{state.appendResult && <div className="rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold">已追加 {state.appendResult.added} 个卡密</div>}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3">
|
||||
<button onClick={handleClose} className="px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors">关闭</button>
|
||||
{state.batchTab === 'create' ? (
|
||||
<button onClick={handleSubmitCreate} disabled={!state.batchFile || state.batchBusy} className="ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50">
|
||||
{state.batchBusy ? <Loader2 className="w-4 h-4 animate-spin" /> : <Upload className="w-4 h-4" />}{state.batchBusy ? '处理中...' : '上传创建'}
|
||||
</button>
|
||||
) : (
|
||||
<button onClick={handleSubmitAppend} disabled={!state.appendTargetId || state.appendPreview.length === 0 || state.batchBusy || dataCards.length === 0} className="ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50">
|
||||
{state.batchBusy ? <Loader2 className="w-4 h-4 animate-spin" /> : <Plus className="w-4 h-4" />}{state.batchBusy ? '处理中...' : '追加卡密'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body,
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import { Code, CreditCard, FileText, Image as ImageIcon } from 'lucide-react';
|
||||
import type { Card } from '../../../../types';
|
||||
|
||||
// CardIconProps 描述库存图标所需的卡密类型参数。
|
||||
interface CardIconProps {
|
||||
// type 是当前卡密组的交付类型。
|
||||
type: Card['type'];
|
||||
}
|
||||
|
||||
// CardIcon 根据卡密类型渲染稳定的库存图标,避免在列表组件内声明子组件。
|
||||
export const CardIcon: React.FC<CardIconProps> = ({ type }) => {
|
||||
switch (type) {
|
||||
case 'text':
|
||||
return <FileText className="w-5 h-5 text-blue-500" />;
|
||||
case 'image':
|
||||
return <ImageIcon className="w-5 h-5 text-purple-500" />;
|
||||
case 'api':
|
||||
return <Code className="w-5 h-5 text-blue-500" />;
|
||||
default:
|
||||
return <CreditCard className="w-5 h-5 text-gray-500" />;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,253 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type Dispatch, type SetStateAction } from 'react';
|
||||
import { appendCardData, batchCreateCards, getCards } from './api';
|
||||
import type { Card } from '../../../types';
|
||||
import { canSubmitAppend, isCurrentCardRequest, previewAppendContent } from './batchState';
|
||||
import type { CardBatchState } from './types';
|
||||
|
||||
// CardsDataResult 暴露卡密库存、加载状态和可复用刷新动作。
|
||||
export interface CardsDataResult {
|
||||
// cards 是当前库存中的全部卡密组。
|
||||
cards: Card[];
|
||||
// setCards 允许页面在编辑、删除和批量操作后局部更新库存。
|
||||
setCards: Dispatch<SetStateAction<Card[]>>;
|
||||
// loading 表示卡密库存是否正在加载。
|
||||
loading: boolean;
|
||||
// loadCards 刷新卡密库存并丢弃旧请求响应。
|
||||
loadCards: () => Promise<void>;
|
||||
}
|
||||
|
||||
// CardBatchOptions 描述批量操作 Hook 所需的库存数据和刷新回调。
|
||||
export interface CardBatchOptions {
|
||||
// dataCards 是可用于追加库存的 data 类型卡密组。
|
||||
dataCards: Card[];
|
||||
// loadCards 在批量操作完成后刷新库存。
|
||||
loadCards: () => Promise<void>;
|
||||
}
|
||||
|
||||
// useCardsData 统一管理卡密库存首次加载、刷新、取消和请求代次。
|
||||
export const useCardsData = (): CardsDataResult => {
|
||||
// cards 保存当前卡密组列表。
|
||||
const [cards, setCards] = useState<Card[]>([]);
|
||||
// loading 表示库存加载状态。
|
||||
const [loading, setLoading] = useState(true);
|
||||
// loadGeneration 用于隔离连续刷新产生的旧响应。
|
||||
const loadGeneration = useRef(0);
|
||||
// loadAbort 保存当前库存请求的取消控制器。
|
||||
const loadAbort = useRef<AbortController | null>(null);
|
||||
|
||||
// loadCards 并行无依赖请求只有一个,但通过代次和 AbortController 保证刷新安全。
|
||||
const loadCards = useCallback(
|
||||
// 货架加载回调读取最新卡密库存。
|
||||
async () => {
|
||||
// generation 标记本次库存加载请求。
|
||||
const generation = ++loadGeneration.current;
|
||||
loadAbort.current?.abort();
|
||||
// controller 允许新刷新取消旧的网络请求。
|
||||
const controller = new AbortController();
|
||||
loadAbort.current = controller;
|
||||
setLoading(true);
|
||||
try {
|
||||
// result 是当前请求返回的规范化卡密列表。
|
||||
const result = await getCards({ signal: controller.signal });
|
||||
if (generation !== loadGeneration.current) return;
|
||||
setCards(result);
|
||||
} catch (error /* 卡密库存加载错误 */) {
|
||||
if (generation === loadGeneration.current && !controller.signal.aborted) {
|
||||
console.error('加载卡密库存失败:', error);
|
||||
}
|
||||
} finally {
|
||||
if (generation === loadGeneration.current) setLoading(false);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(
|
||||
// 库存副作用负责首次加载,并在组件卸载时取消请求。
|
||||
() => {
|
||||
void loadCards();
|
||||
// cleanup 在库存页面卸载时终止当前请求。
|
||||
const cleanup = () => {
|
||||
loadGeneration.current += 1;
|
||||
loadAbort.current?.abort();
|
||||
};
|
||||
return cleanup;
|
||||
},
|
||||
[loadCards],
|
||||
);
|
||||
|
||||
return { cards, setCards, loading, loadCards };
|
||||
};
|
||||
|
||||
// useCardBatchActions 统一管理批量创建、追加、取消和失败重试状态。
|
||||
export const useCardBatchActions = (options: CardBatchOptions): CardBatchState => {
|
||||
// dataCards 是当前可用于追加库存的 data 类型卡密组。
|
||||
const dataCards = options.dataCards;
|
||||
// loadCards 是批量操作完成后的库存刷新动作。
|
||||
const loadCards = options.loadCards;
|
||||
// showBatchModal 表示批量导入弹窗是否打开。
|
||||
const [showBatchModal, setShowBatchModal] = useState(false);
|
||||
// batchTab 保存当前批量操作页签。
|
||||
const [batchTab, setBatchTab] = useState<'create' | 'append'>('create');
|
||||
// batchFile 保存最近一次选择的批量文件。
|
||||
const [batchFile, setBatchFile] = useState<File | null>(null);
|
||||
// batchResult 保存批量创建成功或失败结果。
|
||||
const [batchResult, setBatchResult] = useState<CardBatchState['batchResult']>(null);
|
||||
// batchBusy 表示批量请求正在执行。
|
||||
const [batchBusy, setBatchBusy] = useState(false);
|
||||
// appendTargetId 保存当前追加目标卡密组。
|
||||
const [appendTargetId, setAppendTargetId] = useState('');
|
||||
// appendContent 保存待追加的原始卡密文本。
|
||||
const [appendContent, setAppendContent] = useState('');
|
||||
// appendResult 保存追加成功数量。
|
||||
const [appendResult, setAppendResult] = useState<CardBatchState['appendResult']>(null);
|
||||
// appendError 保存追加失败说明。
|
||||
const [appendError, setAppendError] = useState('');
|
||||
// requestGeneration 让关闭弹窗或切换目标后旧响应失效。
|
||||
const requestGeneration = useRef(0);
|
||||
// requestAbort 取消当前批量创建或追加请求。
|
||||
const requestAbort = useRef<AbortController | null>(null);
|
||||
// lastAppendTarget 保存最近一次提交追加的目标 ID,供失败重试使用。
|
||||
const lastAppendTarget = useRef('');
|
||||
|
||||
// appendPreview 按行派生追加预览,不重复存储派生状态。
|
||||
const appendPreview = useMemo(
|
||||
// 追加预览回调根据当前文本派生有效卡密行。
|
||||
() => previewAppendContent(appendContent),
|
||||
[appendContent],
|
||||
);
|
||||
|
||||
// openBatchModal 重置批量表单,并默认选择第一个 data 卡密组。
|
||||
const openBatchModal = useCallback(
|
||||
// 批量弹窗打开回调重置上一次操作的短暂状态。
|
||||
() => {
|
||||
setBatchTab('create');
|
||||
setBatchFile(null);
|
||||
setBatchResult(null);
|
||||
setAppendTargetId(dataCards[0]?.id ? String(dataCards[0].id) : '');
|
||||
setAppendContent('');
|
||||
setAppendResult(null);
|
||||
setAppendError('');
|
||||
setShowBatchModal(true);
|
||||
},
|
||||
[dataCards],
|
||||
);
|
||||
|
||||
// closeBatchModal 使当前请求失效并关闭批量操作弹窗。
|
||||
const closeBatchModal = useCallback(
|
||||
// 批量弹窗关闭回调取消网络请求并使旧响应失效。
|
||||
() => {
|
||||
requestGeneration.current += 1;
|
||||
requestAbort.current?.abort();
|
||||
setBatchBusy(false);
|
||||
setShowBatchModal(false);
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
// handleBatchCreate 执行批量创建并在成功后刷新库存。
|
||||
const handleBatchCreate = useCallback(
|
||||
// 批量创建回调上传文件并刷新库存。
|
||||
async () => {
|
||||
if (!batchFile || batchBusy) return;
|
||||
// generation 标记当前批量创建请求的代次。
|
||||
const generation = ++requestGeneration.current;
|
||||
requestAbort.current?.abort();
|
||||
// controller 取消上一轮批量创建请求。
|
||||
const controller = new AbortController();
|
||||
requestAbort.current = controller;
|
||||
setBatchBusy(true);
|
||||
setBatchResult(null);
|
||||
try {
|
||||
// result 是批量创建接口返回的逐行统计结果。
|
||||
const result = await batchCreateCards(batchFile, { signal: controller.signal });
|
||||
if (!isCurrentCardRequest(generation, requestGeneration.current, '', '')) return;
|
||||
setBatchResult(result);
|
||||
if (result.created > 0) await loadCards();
|
||||
} catch (error: any /* 批量创建错误 */) {
|
||||
if (!isCurrentCardRequest(generation, requestGeneration.current, '', '')) return;
|
||||
setBatchResult({ error: error?.message || '上传失败' });
|
||||
} finally {
|
||||
if (isCurrentCardRequest(generation, requestGeneration.current, '', '')) setBatchBusy(false);
|
||||
}
|
||||
},
|
||||
[batchBusy, batchFile, loadCards],
|
||||
);
|
||||
|
||||
// handleBatchAppend 预览并提交当前卡密组的追加内容。
|
||||
const handleBatchAppend = useCallback(
|
||||
// 批量追加回调提交当前目标卡密组的有效行。
|
||||
async () => {
|
||||
if (!canSubmitAppend(appendTargetId, appendContent, batchBusy)) return;
|
||||
// targetId 保存提交时的目标卡密组,防止切换目标后误写状态。
|
||||
const targetId = appendTargetId;
|
||||
// generation 标记当前追加请求的代次。
|
||||
const generation = ++requestGeneration.current;
|
||||
lastAppendTarget.current = targetId;
|
||||
requestAbort.current?.abort();
|
||||
// controller 取消上一轮追加库存请求。
|
||||
const controller = new AbortController();
|
||||
requestAbort.current = controller;
|
||||
setBatchBusy(true);
|
||||
setAppendResult(null);
|
||||
setAppendError('');
|
||||
try {
|
||||
// result 是当前卡密组追加成功的数量。
|
||||
const result = await appendCardData(targetId, appendContent, { signal: controller.signal });
|
||||
if (!isCurrentCardRequest(generation, requestGeneration.current, targetId, appendTargetId)) return;
|
||||
setAppendResult({ added: result.added });
|
||||
setAppendContent('');
|
||||
await loadCards();
|
||||
} catch (error: any /* 追加库存错误 */) {
|
||||
if (!isCurrentCardRequest(generation, requestGeneration.current, targetId, appendTargetId)) return;
|
||||
setAppendError(error?.message || '追加失败');
|
||||
} finally {
|
||||
if (isCurrentCardRequest(generation, requestGeneration.current, targetId, appendTargetId)) setBatchBusy(false);
|
||||
}
|
||||
},
|
||||
[appendContent, appendTargetId, batchBusy, loadCards],
|
||||
);
|
||||
|
||||
// handleRetryBatchCreate 重试仍然保留在表单中的批量文件。
|
||||
const handleRetryBatchCreate = useCallback(
|
||||
// 批量创建重试回调复用当前文件。
|
||||
async () => {
|
||||
await handleBatchCreate();
|
||||
},
|
||||
[handleBatchCreate],
|
||||
);
|
||||
|
||||
// handleRetryBatchAppend 重试最近一次追加目标的当前内容。
|
||||
const handleRetryBatchAppend = useCallback(
|
||||
// 追加重试回调只允许重试仍处于当前目标的请求。
|
||||
async () => {
|
||||
if (lastAppendTarget.current && appendTargetId !== lastAppendTarget.current) return;
|
||||
await handleBatchAppend();
|
||||
},
|
||||
[appendTargetId, handleBatchAppend],
|
||||
);
|
||||
|
||||
return {
|
||||
showBatchModal,
|
||||
setShowBatchModal,
|
||||
batchTab,
|
||||
setBatchTab,
|
||||
batchFile,
|
||||
setBatchFile,
|
||||
batchResult,
|
||||
batchBusy,
|
||||
appendTargetId,
|
||||
setAppendTargetId,
|
||||
appendContent,
|
||||
setAppendContent,
|
||||
appendResult,
|
||||
appendError,
|
||||
appendPreview,
|
||||
openBatchModal,
|
||||
closeBatchModal,
|
||||
handleBatchCreate,
|
||||
handleBatchAppend,
|
||||
handleRetryBatchCreate,
|
||||
handleRetryBatchAppend,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,115 @@
|
||||
import type { Dispatch, SetStateAction } from 'react';
|
||||
import type { Card, CardAppendResponse, CardBatchResponse } from '../../../types';
|
||||
|
||||
// AddCardForm 描述新增卡密组弹窗中的可编辑字段。
|
||||
export interface AddCardForm {
|
||||
// name 是卡密组名称。
|
||||
name: string;
|
||||
// type 是卡密交付类型。
|
||||
type: Card['type'];
|
||||
// content 是当前类型对应的主要内容。
|
||||
content: string;
|
||||
// description 是卡密组说明。
|
||||
description: string;
|
||||
// enabled 表示新建后是否启用。
|
||||
enabled: boolean;
|
||||
// delay_seconds 是自动发货延迟秒数。
|
||||
delay_seconds: number;
|
||||
// api_method 是 API 卡密请求方法。
|
||||
api_method: 'GET' | 'POST';
|
||||
// api_timeout 是 API 请求超时时间。
|
||||
api_timeout: number;
|
||||
// api_headers 是 API 请求头 JSON 文本。
|
||||
api_headers: string;
|
||||
// api_params 是 API 请求参数 JSON 文本。
|
||||
api_params: string;
|
||||
}
|
||||
|
||||
// EditCardForm 描述编辑卡密组时的表单字段和 API 扩展字段。
|
||||
export type EditCardForm = Partial<Card> & {
|
||||
// api_url 是编辑中的 API 地址。
|
||||
api_url?: string;
|
||||
// api_method 是编辑中的 API 请求方法。
|
||||
api_method?: 'GET' | 'POST';
|
||||
// api_timeout 是编辑中的 API 超时时间。
|
||||
api_timeout?: number;
|
||||
// api_headers 是编辑中的 API 请求头 JSON 文本。
|
||||
api_headers?: string;
|
||||
// api_params 是编辑中的 API 请求参数 JSON 文本。
|
||||
api_params?: string;
|
||||
};
|
||||
|
||||
// CardBatchTab 表示批量导入弹窗当前展示的操作页签。
|
||||
export type CardBatchTab = 'create' | 'append';
|
||||
|
||||
// CardBatchResponseResult 保存包含逐行统计的批量创建响应和可选错误说明。
|
||||
export interface CardBatchResponseResult extends CardBatchResponse {
|
||||
// error 是批量请求失败时的用户可见说明。
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// CardBatchError 保存没有统计数据时的批量创建错误。
|
||||
export interface CardBatchError {
|
||||
// error 是批量请求失败时的用户可见说明。
|
||||
error: string;
|
||||
}
|
||||
|
||||
// CardBatchResult 保存批量创建接口返回的成功、失败统计或错误说明。
|
||||
export type CardBatchResult = CardBatchResponseResult | CardBatchError | null;
|
||||
|
||||
// CardAppendResult 保存批量追加接口返回的新增数量。
|
||||
export type CardAppendResult = Pick<CardAppendResponse, 'added'> | null;
|
||||
|
||||
// CardBatchState 描述批量创建和追加弹窗的全部短暂 UI 状态。
|
||||
export interface CardBatchState {
|
||||
// showBatchModal 表示批量操作弹窗是否打开。
|
||||
showBatchModal: boolean;
|
||||
// setShowBatchModal 更新弹窗展示状态。
|
||||
setShowBatchModal: Dispatch<SetStateAction<boolean>>;
|
||||
// batchTab 表示当前是批量创建还是追加库存。
|
||||
batchTab: CardBatchTab;
|
||||
// setBatchTab 切换批量操作页签。
|
||||
setBatchTab: Dispatch<SetStateAction<CardBatchTab>>;
|
||||
// batchFile 是待上传的批量文件。
|
||||
batchFile: File | null;
|
||||
// setBatchFile 更新待上传文件。
|
||||
setBatchFile: Dispatch<SetStateAction<File | null>>;
|
||||
// batchResult 保存最近一次批量创建结果。
|
||||
batchResult: CardBatchResult;
|
||||
// batchBusy 表示批量创建或追加请求正在执行。
|
||||
batchBusy: boolean;
|
||||
// appendTargetId 是当前追加库存目标卡密组 ID。
|
||||
appendTargetId: string;
|
||||
// setAppendTargetId 切换追加库存目标卡密组。
|
||||
setAppendTargetId: Dispatch<SetStateAction<string>>;
|
||||
// appendContent 是待追加的原始卡密文本。
|
||||
appendContent: string;
|
||||
// setAppendContent 更新待追加卡密文本。
|
||||
setAppendContent: Dispatch<SetStateAction<string>>;
|
||||
// appendResult 保存最近一次追加成功的数量。
|
||||
appendResult: CardAppendResult;
|
||||
// appendError 保存追加失败说明,供用户重试。
|
||||
appendError: string;
|
||||
// appendPreview 是按行过滤空白后的追加预览。
|
||||
appendPreview: string[];
|
||||
// openBatchModal 重置批量状态并打开弹窗。
|
||||
openBatchModal: () => void;
|
||||
// closeBatchModal 关闭弹窗并取消未完成的批量请求。
|
||||
closeBatchModal: () => void;
|
||||
// handleBatchCreate 执行批量创建请求。
|
||||
handleBatchCreate: () => Promise<void>;
|
||||
// handleBatchAppend 执行批量追加请求。
|
||||
handleBatchAppend: () => Promise<void>;
|
||||
// handleRetryBatchCreate 重试最近一次批量创建请求。
|
||||
handleRetryBatchCreate: () => Promise<void>;
|
||||
// handleRetryBatchAppend 重试最近一次追加请求。
|
||||
handleRetryBatchAppend: () => Promise<void>;
|
||||
}
|
||||
|
||||
// CardBatchModalProps 描述批量导入/追加组件的状态和动作边界。
|
||||
export interface CardBatchModalProps extends CardBatchState {
|
||||
// dataCards 是可追加库存的 data 类型卡密组。
|
||||
dataCards: Card[];
|
||||
// downloadCardTemplate 下载批量创建模板。
|
||||
downloadCardTemplate: () => void;
|
||||
}
|
||||
@@ -1,30 +1,13 @@
|
||||
import React, { useEffect, useMemo, useState } from 'react';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Card } from '../types';
|
||||
import { getCards, createCard, updateCard, deleteCard, batchCreateCards, appendCardData } from '../services/api';
|
||||
import { Plus, CreditCard, Clock, FileText, Image as ImageIcon, Code, Edit, Trash2, Save, X, Eye, EyeOff, Package, Copy, Upload, Loader2, FileDown, ListPlus, Search, SlidersHorizontal } from 'lucide-react';
|
||||
import { filterCards } from './cardListState';
|
||||
|
||||
type AddCardForm = {
|
||||
name: string;
|
||||
type: Card['type'];
|
||||
content: string;
|
||||
description: string;
|
||||
enabled: boolean;
|
||||
delay_seconds: number;
|
||||
api_method: 'GET' | 'POST';
|
||||
api_timeout: number;
|
||||
api_headers: string;
|
||||
api_params: string;
|
||||
};
|
||||
|
||||
type EditCardForm = Partial<Card> & {
|
||||
api_url?: string;
|
||||
api_method?: 'GET' | 'POST';
|
||||
api_timeout?: number;
|
||||
api_headers?: string;
|
||||
api_params?: string;
|
||||
};
|
||||
import { createCard, deleteCard, updateCard } from '../app/features/cards/api';
|
||||
import { Plus, CreditCard, FileText, Image as ImageIcon, Edit, Trash2, Save, X, Eye, EyeOff, Package, Copy, Upload, Loader2, Search, SlidersHorizontal } from 'lucide-react';
|
||||
import { BatchCardImportModal } from '../app/features/cards/components/BatchCardImportModal';
|
||||
import { CardIcon } from '../app/features/cards/components/CardIcon';
|
||||
import { useCardBatchActions, useCardsData } from '../app/features/cards/hooks';
|
||||
import { filterCards } from '../app/features/cards/batchState';
|
||||
import type { AddCardForm, EditCardForm } from '../app/features/cards/types';
|
||||
|
||||
const emptyAddForm = (): AddCardForm => ({
|
||||
name: '',
|
||||
@@ -40,37 +23,18 @@ const emptyAddForm = (): AddCardForm => ({
|
||||
});
|
||||
|
||||
const CardList: React.FC = () => {
|
||||
const [cards, setCards] = useState<Card[]>([]);
|
||||
const { cards, loadCards } = useCardsData();
|
||||
const [showEditModal, setShowEditModal] = useState(false);
|
||||
const [showAddModal, setShowAddModal] = useState(false);
|
||||
const [selectedCard, setSelectedCard] = useState<Card | null>(null);
|
||||
const [editForm, setEditForm] = useState<EditCardForm>({});
|
||||
const [addForm, setAddForm] = useState<AddCardForm>(emptyAddForm);
|
||||
|
||||
// 批量导入
|
||||
const [showBatchModal, setShowBatchModal] = useState(false);
|
||||
const [batchTab, setBatchTab] = useState<'create' | 'append'>('create');
|
||||
const [batchFile, setBatchFile] = useState<File | null>(null);
|
||||
const [batchResult, setBatchResult] = useState<any>(null);
|
||||
const [batchBusy, setBatchBusy] = useState(false);
|
||||
const [appendTargetId, setAppendTargetId] = useState<string>('');
|
||||
const [appendContent, setAppendContent] = useState('');
|
||||
const [appendResult, setAppendResult] = useState<{ added: number } | null>(null);
|
||||
const [typeFilter, setTypeFilter] = useState<Card['type'] | ''>('');
|
||||
const [nameSearch, setNameSearch] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
getCards().then(setCards);
|
||||
}, []);
|
||||
|
||||
const CardIcon = ({ type }: { type: string }) => {
|
||||
switch(type) {
|
||||
case 'text': return <FileText className="w-5 h-5 text-blue-500" />;
|
||||
case 'image': return <ImageIcon className="w-5 h-5 text-purple-500" />;
|
||||
case 'api': return <Code className="w-5 h-5 text-blue-500" />;
|
||||
default: return <CreditCard className="w-5 h-5 text-gray-500" />;
|
||||
}
|
||||
};
|
||||
// dataCards 只保留可追加库存的卡密组,并在卡密数据未变化时保持引用稳定。
|
||||
const dataCards = useMemo(() => cards.filter(card => card.type === 'data'), [cards]);
|
||||
const batchState = useCardBatchActions({ dataCards, loadCards });
|
||||
|
||||
const handleEdit = (card: Card) => {
|
||||
setSelectedCard(card);
|
||||
@@ -139,7 +103,7 @@ const CardList: React.FC = () => {
|
||||
|
||||
await updateCard(selectedCard.id, updateData);
|
||||
setShowEditModal(false);
|
||||
getCards().then(setCards);
|
||||
await loadCards();
|
||||
} catch (error) {
|
||||
console.error('更新卡密失败:', error);
|
||||
alert('更新失败,请重试');
|
||||
@@ -150,7 +114,7 @@ const CardList: React.FC = () => {
|
||||
if (confirm('确认删除该卡密吗?')) {
|
||||
try {
|
||||
await deleteCard(id);
|
||||
getCards().then(setCards);
|
||||
await loadCards();
|
||||
} catch (error) {
|
||||
console.error('删除卡密失败:', error);
|
||||
alert('删除失败,请重试');
|
||||
@@ -190,7 +154,7 @@ const CardList: React.FC = () => {
|
||||
await createCard(payload);
|
||||
setShowAddModal(false);
|
||||
setAddForm(emptyAddForm());
|
||||
getCards().then(setCards);
|
||||
await loadCards();
|
||||
} catch (error) {
|
||||
console.error('添加卡密失败:', error);
|
||||
alert('添加失败,请重试');
|
||||
@@ -200,7 +164,7 @@ const CardList: React.FC = () => {
|
||||
const toggleCardStatus = async (card: Card) => {
|
||||
try {
|
||||
await updateCard(card.id, { ...card, enabled: !card.enabled });
|
||||
getCards().then(setCards);
|
||||
await loadCards();
|
||||
} catch (error) {
|
||||
console.error('切换状态失败:', error);
|
||||
}
|
||||
@@ -215,7 +179,6 @@ const CardList: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const dataCards = cards.filter(c => c.type === 'data');
|
||||
const filteredCards = useMemo(
|
||||
() => filterCards(cards, typeFilter, nameSearch),
|
||||
[cards, nameSearch, typeFilter],
|
||||
@@ -242,51 +205,6 @@ const CardList: React.FC = () => {
|
||||
URL.revokeObjectURL(url);
|
||||
};
|
||||
|
||||
const handleBatchCreate = async () => {
|
||||
if (!batchFile) return;
|
||||
setBatchBusy(true);
|
||||
setBatchResult(null);
|
||||
try {
|
||||
const res = await batchCreateCards(batchFile);
|
||||
setBatchResult(res);
|
||||
if (res.created > 0) {
|
||||
const fresh = await getCards();
|
||||
setCards(fresh);
|
||||
}
|
||||
} catch (e: any) {
|
||||
setBatchResult({ error: e?.message || '上传失败' });
|
||||
} finally {
|
||||
setBatchBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleBatchAppend = async () => {
|
||||
if (!appendTargetId || !appendContent.trim()) return;
|
||||
setBatchBusy(true);
|
||||
setAppendResult(null);
|
||||
try {
|
||||
const res = await appendCardData(appendTargetId, appendContent);
|
||||
setAppendResult({ added: res.added });
|
||||
setAppendContent('');
|
||||
const fresh = await getCards();
|
||||
setCards(fresh);
|
||||
} catch (e: any) {
|
||||
alert('追加失败:' + (e?.message || '未知错误'));
|
||||
} finally {
|
||||
setBatchBusy(false);
|
||||
}
|
||||
};
|
||||
|
||||
const openBatchModal = () => {
|
||||
setBatchTab('create');
|
||||
setBatchFile(null);
|
||||
setBatchResult(null);
|
||||
setAppendTargetId(dataCards[0]?.id ? String(dataCards[0].id) : '');
|
||||
setAppendContent('');
|
||||
setAppendResult(null);
|
||||
setShowBatchModal(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6 animate-fade-in">
|
||||
<div className="flex flex-col md:flex-row justify-between md:items-end gap-4">
|
||||
@@ -296,7 +214,7 @@ const CardList: React.FC = () => {
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={openBatchModal}
|
||||
onClick={batchState.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"
|
||||
>
|
||||
<Upload className="w-5 h-5" />
|
||||
@@ -860,146 +778,14 @@ const CardList: React.FC = () => {
|
||||
document.body
|
||||
)}
|
||||
|
||||
{/* 批量导入弹窗 */}
|
||||
{showBatchModal && createPortal(
|
||||
<div className="modal-overlay">
|
||||
<div className="modal-container" style={{ maxWidth: '40rem' }}>
|
||||
<div className="px-6 py-5 border-b border-gray-100 flex items-center justify-between">
|
||||
<h3 className="text-xl font-extrabold text-gray-900">批量导入卡密</h3>
|
||||
<button
|
||||
onClick={() => setShowBatchModal(false)}
|
||||
className="w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center"
|
||||
>
|
||||
<X className="w-5 h-5 text-gray-600" />
|
||||
</button>
|
||||
</div>
|
||||
{/* 批量导入弹窗由 cards feature 组件负责渲染和请求边界。 */}
|
||||
<BatchCardImportModal
|
||||
dataCards={dataCards}
|
||||
downloadCardTemplate={downloadCardTemplate}
|
||||
{...batchState}
|
||||
/>
|
||||
|
||||
<div className="px-6 py-5 space-y-5">
|
||||
{/* Tab 切换 */}
|
||||
<div className="flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl">
|
||||
<button
|
||||
onClick={() => setBatchTab('create')}
|
||||
className={`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${batchTab === 'create' ? 'bg-brand text-white shadow-md' : 'bg-white text-gray-600 hover:bg-gray-50'}`}
|
||||
>
|
||||
<ListPlus className="w-4 h-4" />
|
||||
批量创建卡密组
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setBatchTab('append')}
|
||||
className={`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${batchTab === 'append' ? 'bg-brand text-white shadow-md' : 'bg-white text-gray-600 hover:bg-gray-50'}`}
|
||||
>
|
||||
<Upload className="w-4 h-4" />
|
||||
往单个组充卡密
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{batchTab === 'create' ? (
|
||||
<div className="space-y-4">
|
||||
<div className="rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5">
|
||||
上传表格,每行一个卡密组。表头:<code className="bg-blue-100/70 px-1.5 py-0.5 rounded">名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值</code>。
|
||||
类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={downloadCardTemplate}
|
||||
className="px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transition-colors"
|
||||
>
|
||||
<FileDown className="w-4 h-4" />
|
||||
下载模板
|
||||
</button>
|
||||
<label className="flex-1 px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm cursor-pointer transition-colors">
|
||||
<Upload className="w-4 h-4" />
|
||||
{batchFile ? batchFile.name : '选择 .xlsx / .csv / .tsv'}
|
||||
<input type="file" accept=".xlsx,.csv,.tsv" className="hidden" onChange={e => setBatchFile(e.target.files?.[0] || null)} />
|
||||
</label>
|
||||
</div>
|
||||
{batchResult && !batchResult.error && (
|
||||
<div className="rounded-xl border border-gray-200 p-4 space-y-2">
|
||||
<div className="text-sm font-bold text-gray-900">
|
||||
共 {batchResult.total} 行 · 成功 {batchResult.created} · 失败 {batchResult.failed}
|
||||
</div>
|
||||
{batchResult.failed > 0 && (
|
||||
<div className="max-h-48 overflow-y-auto space-y-1">
|
||||
{batchResult.rows.filter((r: any) => !r.success).map((r: any) => (
|
||||
<div key={r.row_no} className="text-xs text-red-600">第 {r.row_no} 行「{r.name}」:{r.error}</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
{dataCards.length === 0 ? (
|
||||
<div className="rounded-xl bg-amber-50 border border-amber-200 p-4 text-sm text-amber-800">
|
||||
暂无 data(批量卡密)类型的卡密组,请先创建一个再充卡密。
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">选择卡密组</label>
|
||||
<select
|
||||
value={appendTargetId}
|
||||
onChange={e => setAppendTargetId(e.target.value)}
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm"
|
||||
>
|
||||
{dataCards.map(c => (
|
||||
<option key={c.id} value={String(c.id)}>{c.name}(ID: {c.id})</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">卡密号(每行一个)</label>
|
||||
<textarea
|
||||
value={appendContent}
|
||||
onChange={e => setAppendContent(e.target.value)}
|
||||
placeholder={'VIP-001\nVIP-002\nVIP-003'}
|
||||
className="w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"
|
||||
/>
|
||||
<p className="text-xs text-gray-500">一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。</p>
|
||||
</div>
|
||||
{appendResult && (
|
||||
<div className="rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold">
|
||||
已追加 {appendResult.added} 个卡密
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3">
|
||||
<button
|
||||
onClick={() => setShowBatchModal(false)}
|
||||
className="px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors"
|
||||
>
|
||||
关闭
|
||||
</button>
|
||||
{batchTab === 'create' ? (
|
||||
<button
|
||||
onClick={handleBatchCreate}
|
||||
disabled={!batchFile || batchBusy}
|
||||
className="ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50"
|
||||
>
|
||||
{batchBusy ? <Loader2 className="w-4 h-4 animate-spin" /> : <Upload className="w-4 h-4" />}
|
||||
{batchBusy ? '处理中...' : '上传创建'}
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
onClick={handleBatchAppend}
|
||||
disabled={!appendTargetId || !appendContent.trim() || batchBusy || dataCards.length === 0}
|
||||
className="ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50"
|
||||
>
|
||||
{batchBusy ? <Loader2 className="w-4 h-4 animate-spin" /> : <Plus className="w-4 h-4" />}
|
||||
{batchBusy ? '处理中...' : '追加卡密'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>,
|
||||
document.body
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import type { Card } from '../types';
|
||||
|
||||
export const filterCards = (
|
||||
cards: Card[],
|
||||
typeFilter: Card['type'] | '',
|
||||
nameSearch: string,
|
||||
): Card[] => {
|
||||
const keyword = nameSearch.trim().toLocaleLowerCase();
|
||||
return cards.filter(card => (
|
||||
(!typeFilter || card.type === typeFilter)
|
||||
&& (!keyword || card.name.toLocaleLowerCase().includes(keyword))
|
||||
));
|
||||
};
|
||||
// 旧目录保留兼容入口,实际卡密筛选和批量状态逻辑已归入 cards feature。
|
||||
export {
|
||||
canSubmitAppend,
|
||||
filterCards,
|
||||
isCurrentCardRequest,
|
||||
previewAppendContent,
|
||||
} from '../app/features/cards/batchState';
|
||||
@@ -448,8 +448,8 @@ const cardPayload = (data: Partial<Card>): Record<string, unknown> => ({
|
||||
api_config: data.api_config ? JSON.stringify(data.api_config) : '',
|
||||
});
|
||||
|
||||
export const getCards = async (): Promise<Card[]> => {
|
||||
const res = await get<Card[] | CardListResponse>('/api/v1/cards');
|
||||
export const getCards = async (options?: RequestControlOptions): Promise<Card[]> => {
|
||||
const res = await get<Card[] | CardListResponse>('/api/v1/cards', undefined, options);
|
||||
const cards = Array.isArray(res) ? res : (res.cards || []);
|
||||
return cards.map(normalizeCard);
|
||||
};
|
||||
@@ -472,7 +472,7 @@ export const getCardDetails = async (cardId: string | number): Promise<Card> =>
|
||||
};
|
||||
|
||||
// 批量创建卡密组(上传表格)
|
||||
export const batchCreateCards = async (file: File): Promise<CardBatchResponse> => {
|
||||
export const batchCreateCards = async (file: File, options?: RequestControlOptions): Promise<CardBatchResponse> => {
|
||||
// 批量创建接口返回总行数、成功数、失败数和逐行结果。
|
||||
// CardBatchResponse 保留旧字段名称,调用方无需转换统计字段。
|
||||
// rows 中的 id 只在创建成功时返回。
|
||||
@@ -481,12 +481,12 @@ export const batchCreateCards = async (file: File): Promise<CardBatchResponse> =
|
||||
// 此处只收紧 TypeScript 响应契约。
|
||||
const body = new FormData();
|
||||
body.append('file', file);
|
||||
return postForm('/api/v1/cards/batch', body);
|
||||
return postForm('/api/v1/cards/batch', body, options);
|
||||
};
|
||||
|
||||
// 往 data 类型卡密组批量追加卡密号
|
||||
export const appendCardData = async (cardId: string | number, content: string): Promise<CardAppendResponse> => {
|
||||
return post(`/api/v1/cards/${cardId}/append-data`, { content });
|
||||
export const appendCardData = async (cardId: string | number, content: string, options?: RequestControlOptions): Promise<CardAppendResponse> => {
|
||||
return post(`/api/v1/cards/${cardId}/append-data`, { content }, options);
|
||||
};
|
||||
|
||||
// Items
|
||||
|
||||
+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{n2 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,e0 as N,k2 as O,D2 as P,I2 as Q,O2 as R,X2 as S,y0 as T,i0 as U,v2 as V,N2 as W,M0 as X,q2 as Y,_0 as Z,x2 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,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};
|
||||
@@ -1,19 +0,0 @@
|
||||
import{j as e,r as l,c as Ns,b as qe,d as Ua}from"./react-vendor-C_od1ZSF.js";import{L as Wa,U as ma,M as os,C as cs,B as ua,S as pa,Z as ds,a as ft,b as _s,G as Ls,c as vs,d as ws,e as Ja,f as rt,A as As,D as Va,g as Is,P as ha,h as $t,E as ga,T as Ga,i as Qa,j as Oe,X as $e,k as Ka,l as Ha,m as ks,n as ba,o as tt,p as Qe,q as fa,K as Za,r as it,s as lt,Q as Kt,t as ot,u as bt,v as Rt,R as Je,w as ya,x as Ya,y as Ge,z as et,F as Os,H as jt,I as yt,J as Ot,N as ja,O as Xa,V as Rs,W as Ps,Y as el,_ as tl,$ as sl,a0 as al,a1 as Ht,a2 as Dt,a3 as xs,a4 as ll,a5 as rl,a6 as ms,a7 as $s,a8 as nl,a9 as il,aa as Pt,ab as Es,ac as Wt,ad as Na,ae as ol,af as cl,ag as Gt,ah as _a,ai as dl,aj as xl,ak as ml,al as ul,am as pl,an as hl,ao as Ts}from"./icons-vendor-C73Tbcy8.js";import{R as Mt,B as gl,X as Ds,Y as Ms,T as qt,a as bl,C as Zt,A as fl,b as yl,c as jl,P as qs,d as Bs,L as Nl}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 o of document.querySelectorAll('link[rel="modulepreload"]'))i(o);new MutationObserver(o=>{for(const v of o)if(v.type==="childList")for(const N of v.addedNodes)N.tagName==="LINK"&&N.rel==="modulepreload"&&i(N)}).observe(document,{childList:!0,subtree:!0});function a(o){const v={};return o.integrity&&(v.integrity=o.integrity),o.referrerPolicy&&(v.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?v.credentials="include":o.crossOrigin==="anonymous"?v.credentials="omit":v.credentials="same-origin",v}function i(o){if(o.ep)return;o.ep=!0;const v=a(o);fetch(o.href,v)}})();const _l=({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(_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: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(Oe,{className:"w-4 h-4 animate-spin"}):e.jsx(tt,{className:"w-4 h-4"}),le?"保存中...":"保存"]})]})})]})}),document.body)]})},xn=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)||"")})):[]}),mn=t=>(t==null?void 0:t.results.filter(s=>!s.success))||[],Hs=({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})},un=()=>{const[t,s]=l.useState([]),[a,i]=l.useState([]),[o,v]=l.useState([]),[N,S]=l.useState({}),[p,w]=l.useState("all"),[y,$]=l.useState(""),[B,ee]=l.useState(""),[H,_]=l.useState(""),F=l.useRef(0),[T,J]=l.useState(1),[K,ae]=l.useState(1),[me,ue]=l.useState(!1),[k,Y]=l.useState(!1),[re,z]=l.useState(!1),[de,V]=l.useState(!1),[C,q]=l.useState(null),[A,X]=l.useState(null),[E,Z]=l.useState({}),[R,x]=l.useState(!1),[g,U]=l.useState(""),[j,M]=l.useState(!1),[ne,ce]=l.useState(null),[_e,Ie]=l.useState(null),[d,ie]=l.useState(null),[Se,u]=l.useState(!1),[G,se]=l.useState(null),[b,le]=l.useState(null),I=async()=>{const m=++F.current;ue(!0);try{const P=await er(y||void 0,p,T,20,H);if(m!==F.current)return;s(P.data),ae(P.total_pages)}catch(P){console.error("加载订单失败:",P)}finally{m===F.current&&ue(!1)}},pe=(m,P,he)=>{if(he&&he.trim())return he;if(N[`${m}:${P}`])return N[`${m}:${P}`];const we=a.find(Ke=>{if(he&&Ke.item_title){const Ue=he.toLowerCase(),We=Ke.item_title.toLowerCase();return We.includes(Ue)||Ue.includes(We)}return!1});return we!=null&&we.item_title?we.item_title:"未知商品"},te=m=>{const P={};m.forEach(he=>{he.item_id&&(P[`${he.cookie_id}:${he.item_id}`]=he.item_title||he.item_id)}),S(P)};l.useEffect(()=>{const m=window.setTimeout(()=>{J(1),_(B.trim())},300);return()=>window.clearTimeout(m)},[B]),l.useEffect(()=>{I()},[y,p,T,H]),l.useEffect(()=>{Promise.all([Et(),Nt()]).then(([m,P])=>{v(m),i(P),te(P)}).catch(m=>{console.error("加载商品列表失败:",m)})},[]);const Te=l.useMemo(()=>new Map(o.map(m=>[m.id,m])),[o]),Re=m=>{const P=Te.get(m),he=(P==null?void 0:P.remark)||(P==null?void 0:P.nickname);return he?`${he} · ${m.slice(0,6)}`:`账号 ${m.slice(0,8)}`},Me=m=>{const P=Te.get(m);return(P==null?void 0:P.remark)||(P==null?void 0:P.nickname)||"未命名账号"},f=async()=>{ue(!0);try{const m=await ar(y||void 0,p);await I(),m!=null&&m.message&&alert(m.message)}catch(m){console.error("同步订单失败:",m),alert((m==null?void 0:m.message)||"同步失败,请重试")}finally{ue(!1)}},L=m=>{U(m),ce(null),x(!0)},W=async m=>{var P;M(!0),ce(null);try{const he=await rr([g],m),we=(P=he==null?void 0:he.results)==null?void 0:P[0];we!=null&&we.success?(ce({success:!0,message:we.message}),I()):ce({success:!1,message:(we==null?void 0:we.message)||"发货失败"})}catch(he){ce({success:!1,message:(he==null?void 0:he.message)||"请求失败"})}finally{M(!1)}},Q=m=>{q(m),Y(!0)},Le=m=>{X({...m}),z(!0)},ve=async()=>{if(!(!A||!A.order_id))try{const m={};A.status!==void 0&&(m.order_status=A.status),A.buyer_id!==void 0&&(m.buyer_id=A.buyer_id),A.amount!==void 0&&(m.amount=A.amount),A.receiver_name!==void 0&&(m.receiver_name=A.receiver_name),A.receiver_phone!==void
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(b=>b.map(le=>`"${String(le).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),u=new Blob(["\uFEFF"+Se],{type:"text/csv;charset=utf-8"}),G=URL.createObjectURL(u),se=document.createElement("a");se.href=G,se.download="卡密组批量导入模板.csv",document.body.appendChild(se),se.click(),se.remove(),URL.revokeObjectURL(G)},ce=async()=>{if(F){me(!0),K(null);try{const d=await mr(F);if(K(d),d.created>0){const ie=await Xe();s(ie)}}catch(d){K({error:(d==null?void 0:d.message)||"上传失败"})}finally{me(!1)}}},_e=async()=>{if(!(!ue||!Y.trim())){me(!0),de(null);try{const d=await ur(ue,Y);de({added:d.added}),re("");const ie=await Xe();s(ie)}catch(d){alert("追加失败:"+((d==null?void 0:d.message)||"未知错误"))}finally{me(!1)}}},Ie=()=>{var d;_("create"),T(null),K(null),k((d=j[0])!=null&&d.id?String(j[0].id):""),re(""),de(null),ee(!0)};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between md:items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-4xl font-extrabold text-gray-900 tracking-tight",children:"卡密库存"}),e.jsx("p",{className:"text-gray-500 mt-2 font-medium",children:"管理自动发货的卡密、链接或图片资源。"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:Ie,className:"px-4 py-3 bg-gray-100 hover:bg-gray-200 rounded-2xl font-bold text-gray-700 flex items-center gap-2 transition-colors",children:[e.jsx(Ot,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:()=>v(!0),className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 transition-transform hover:scale-105 active:scale-95",children:[e.jsx(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(ja,{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:V,onChange:d=>C(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:q,onChange:d=>A(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:["显示 ",M.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:M.map(d=>{let ie="";return d.type==="data"&&d.data_content?ie=`库存: ${d.data_content.split(`
|
||||
`).filter(u=>u.trim()).length} 条`:d.type==="text"&&d.text_content?ie=d.text_content:d.type==="api"&&d.api_config?ie=d.api_config.url:d.type==="image"&&d.image_url&&(ie="图片链接"),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(X,{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:()=>U(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(Xa,{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:ie,children:ie})}),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:()=>g(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:()=>E(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:()=>R(d.id),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Ge,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),M.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&&N&&qe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:()=>i(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx($e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:p.name||"",onChange:d=>w({...p,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:p.type||"text",onChange:d=>w({...p,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:"批量数据"}),(N==null?void 0:N.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),p.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:p.api_url||"",onChange:d=>w({...p,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.Line 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:p.data_content?p.data_content.split(`
|
||||
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),p.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:p.image_url||"",onChange:d=>w({...p,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 地址"})]}),p.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:p.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:p.delay_seconds||0,onChange:d=>w({...p,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:p.description||"",onChange:d=>w({...p,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({...p,enabled:!p.enabled}),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${p.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 ${p.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>i(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick: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(tt,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),o&&qe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:()=>v(!1),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx($e,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡密名称"}),e.jsx("input",{type:"text",value:y.name,onChange:d=>$({...y,name:d.target.value}),placeholder:"例如:VIP会员卡密",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"类型"}),e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>$({...y,type:"data",content:""}),className:`p-3 rounded-xl font-bold transition-all ${y.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(cs,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:()=>$({...y,type:"text",content:""}),className:`p-3 rounded-xl font-bold transition-all ${y.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Rs,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:()=>$({...y,type:"image",content:""}),className:`p-3 rounded-xl font-bold transition-all ${y.type==="image"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:
Line truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),y.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:y.content.split(`
|
||||
`).filter(d=>d.trim()).length})," 条"]})]}),y.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:y.api_method,onChange:d=>$({...y,api_method:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:y.api_timeout,onChange:d=>$({...y,api_timeout:parseInt(d.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:y.api_headers,onChange:d=>$({...y,api_headers:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:y.api_params,onChange:d=>$({...y,api_params:d.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:y.description,onChange:d=>$({...y,description:d.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:y.delay_seconds,onChange:d=>$({...y,delay_seconds:parseInt(d.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>v(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:x,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(et,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),B&&qe.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>ee(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx($e,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>_("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${H==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(el,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>_("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${H==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Ot,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),H==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),'。 类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:ne,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm transit
Line truncated
|
||||
VIP-002
|
||||
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),z&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",z.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>ee(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),H==="create"?e.jsxs("button",{onClick:ce,disabled:!F||ae,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[ae?e.jsx(Oe,{className:"w-4 h-4 animate-spin"}):e.jsx(Ot,{className:"w-4 h-4"}),ae?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:_e,disabled:!ue||!Y.trim()||ae||j.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[ae?e.jsx(Oe,{className:"w-4 h-4 animate-spin"}):e.jsx(et,{className:"w-4 h-4"}),ae?"处理中...":"追加卡密"]})]})]})}),document.body)]})},Ys="ydisks-amap-js-api",gn="c9b68d4ce9a2a97f22a4a439404488ca";let St=null;const bn=()=>gn,fn=()=>window.AMap?Promise.resolve(window.AMap):St||(St=new Promise((t,s)=>{const a=document.getElementById(Ys),i=a||document.createElement("script"),o=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(N)},v=()=>{window.AMap?(o(),t(window.AMap)):(o(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},N=window.setTimeout(()=>{o(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=v,i.id=Ys,i.async=!0,i.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(bn())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,i.onerror=()=>{o(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(i)}).catch(t=>{throw St=null,t}),St),Vt=t=>Number.isFinite(t)&&t!==0,yn=t=>{var o,v;const s=Number((o=t.location)==null?void 0:o.lng),a=Number((v=t.location)==null?void 0:v.lat),i={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!i.division_id||!i.province||!i.city||!i.poi_id||!i.poi_name||!Vt(s)||!Vt(a)||s<-180||s>180||a<-90||a>90?null:i},jn=async(t,s)=>{if(!Vt(t)||!Vt(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await fn();return new Promise((i,o)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(N,S)=>{var w;if(N!=="complete"){if(N==="no_data"){i([]);return}o(new Error("高德地图附近地址查询失败,请稍后重试"));return}const p=(((w=S==null?void 0:S.poiList)==null?void 0:w.pois)||[]).map(yn).filter(y=>y!==null);i(p)})})},Nn=t=>t.find(s=>s.status==="running"||s.status==="canceling"),ys=t=>t==="running"||t==="canceling",_n=t=>!!(t!=null&&t.preview_id&&Number(t.valid||0)>0),vn=t=>!!(t!=null&&t.id&&Number(t.retryable||0)>0&&!ys(t.status)),wn=(t,s)=>t===s,Xs=t=>{switch(t){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return t||"-"}},ea=t=>{switch(t){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},kn=t=>{const[s,a]=l.useState(!1),[i,o]=l.useState("upload"),[v,N]=l.useState(null),[S,p]=l.useState(null),[w,y]=l.useState(""),[$,B]=l.useState(!1),[ee,H]=l.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[_,F]=l.useState(null),[T,J]=l.useState(null),[K,ae]=l.useState(null),[me,ue]=l.useState([]),[k,Y]=l.useState(null),[re,z]=l.useState(!1),de=l.useRef(!1),V=l.useRef(0),C=l.useCallback(async()=>{o("upload"),F(null),J(null),N(null),p(null),y(""),H({catId:"",catName:"",channelCatId:"",tbCatId:""}),ue([]),Y(null),a(!0),z(!0);try{const j=await Aa(20),M=Nn(j);if(M!=null&&M.id){const ne=await ht(M.id);ae(ne),J(ne),o(["running","canceling"].includes(ne.status)?"running":"done")}}catch(j){console.error("恢复最近批量铺货任务失败:",j)}finally{z(!1)}},[]),q=l.useCallback(async()=>{const j=w.trim();if(!t.selectedAccount){alert("请先选择默认发布账号");retu
Line truncated
|
||||
`),Ee=new Blob(["\uFEFF"+fe],{type:"text/csv;charset=utf-8"}),Ve=URL.createObjectURL(Ee),Fe=document.createElement("a");Fe.href=Ve,Fe.download="批量铺货模板.csv",document.body.appendChild(Fe),Fe.click(),Fe.remove(),URL.revokeObjectURL(Ve)},wt=()=>{X(c=>({...c,cookie_id:S||c.cookie_id})),J(!0)},ct=()=>{Z(c=>({...c,cookie_id:S||c.cookie_id})),ae(!0)},dt=async c=>{if(!(c?S:E.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");ue(!0),navigator.geolocation.getCurrentPosition(async fe=>{try{const Ee=await jn(fe.coords.longitude,fe.coords.latitude);if(!Ee.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");c?(f(Ee),L(Ee[0])):(Y(Ee),z(Ee[0]))}catch(Ee){alert((Ee==null?void 0:Ee.message)||"获取发货地失败")}finally{ue(!1)}},fe=>{ue(!1),alert(fe.code===fe.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},kt=c=>i.filter(D=>D.cookie_id===c.cookie_id&&D.item_id===c.item_id).length>0?i.filter(D=>D.cookie_id===c.cookie_id&&D.item_id===c.item_id):i.filter(D=>D.cookie_id===c.cookie_id&&!D.item_id),xt=l.useMemo(()=>new Map(v.map(c=>[c.id,c])),[v]),mt=l.useMemo(()=>w?s.filter(c=>c.cookie_id===w):s,[w,s]),Ze=c=>{const D=xt.get(c),fe=(D==null?void 0:D.remark)||(D==null?void 0:D.nickname);return fe?`${fe} · ${c.slice(0,6)}`:`账号 ${c.slice(0,8)}`},ut=c=>{const D=xt.get(c);return(D==null?void 0:D.remark)||(D==null?void 0:D.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(al,{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=>y(c.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),v.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(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:S,onChange:c=>p(c.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),v.map(c=>e.jsx("option",{value:c.id,children:Ze(c.id)},c.id))]})]})]}),e.jsxs("button",{onClick:P,disabled:$||!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 ${$?"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: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(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 Le(),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 D=kt(c),fe=D.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative flex fl
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
|
||||
@@ -0,0 +1,20 @@
|
||||
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-B6IVu2Jz.js"></script>
|
||||
<script type="module" crossorigin src="/static/assets/index-D_XA_mO5.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-C_od1ZSF.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-C73Tbcy8.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-BFpWAqQX.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-DHTuTnpg.css">
|
||||
<link rel="stylesheet" crossorigin href="/static/assets/index-DFTgpFf2.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
Reference in new issue
Block a user