完成审计重开与敏感设置脱敏切片
重开阶段2、4、5、8、9、10的完成状态,明确测试通过不等于架构完成。 管理端系统设置不再返回敏感明文,支持敏感配置保留与显式清除;dbverify仅输出Cookie长度和指纹;同步前端脱敏状态、回归测试和嵌入资源。 验证:make check;npm test --prefix frontend;npm run typecheck --prefix frontend。
This commit is contained in:
1 parent
5d4f2d3a5f
commit
0a45fd4a8b
17 files changed
+289
-36
No files matched your search
@@ -14,6 +14,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -112,7 +113,9 @@ func main() {
|
||||
}
|
||||
// v 保存v,供当前处理流程使用
|
||||
v, _ := store.Cookies.GetValue(ctx, accountID)
|
||||
fmt.Printf("✅ cookie upsert 成功,value=%s\n", v)
|
||||
// fingerprint 是 Cookie 的不可逆校验指纹,仅用于验证 upsert 结果。
|
||||
fingerprint := sha256.Sum256([]byte(v))
|
||||
fmt.Printf("✅ cookie upsert 成功,length=%d fingerprint=%x\n", len(v), fingerprint[:8])
|
||||
|
||||
// 3) 系统设置 upsert(dialectUpsert + key 保留字引用)
|
||||
if err := store.Settings.Set(ctx, "theme_color", "blue"); err != nil {
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
- server 测试重复执行全量 SQLite 迁移,使完整 race 测试耗时过高;
|
||||
- 历史代码尚未满足全函数、全变量准确中文注释要求。
|
||||
|
||||
审计重开基线(2026-08-15):此前将测试覆盖率收口误判为目标架构完成,现已撤销该判断。当前仍存在敏感设置明文进入前端、Server 持有基础设施编排、Port 泄露 `sql.Tx`/`db.*`、凭证锁覆盖慢速外部 I/O、外部成功后本地状态缺少统一补偿、N+1 同步、关闭游离 goroutine、大型页面同步加载和模板化注释假阴性等问题。覆盖率、lint、race 通过只能证明当前行为可验证,不能替代分层和状态正确性完成条件。
|
||||
|
||||
## 3. 不变量与成功标准
|
||||
|
||||
重构期间必须持续满足以下不变量:
|
||||
@@ -91,19 +93,19 @@ app shell / routes
|
||||
| --- | --- | --- | --- |
|
||||
| 0. 治理文档与强约束 | 已完成 | 总计划、依赖规则、注释规范、AGENTS 门禁、注释检查器 | 文档、门禁规则、Go/TypeScript 检查器和历史基线已落盘 |
|
||||
| 1. PR CI 与测试基础 | 已完成 | 独立 CI、测试 DB 模板、可执行 race | CI、独立模板、server smoke race 和完整 race 均有验证 |
|
||||
| 2. 敏感数据访问边界 | 已完成 | 摘要、凭证、登录秘密分离 | 生产完整详情白名单、所有权/凭证锁审计、SQLite/MySQL/Postgres 窄查询回归和全量门禁已完成 |
|
||||
| 2. 敏感数据访问边界 | 进行中 | 摘要、凭证、登录秘密和系统设置分离 | Cookie/平台运行视图已收口;待完成系统设置脱敏读写、运维输出脱敏、敏感字段访问审计和三库回归 |
|
||||
| 3. HTTP API 契约 | 已完成 | 统一错误、具名 DTO、版本化路径 | 统一错误 DTO、具名成功 DTO、所有前端业务调用方版本化、旧路径兼容和最终审计均已完成 |
|
||||
| 4. Server 应用服务 | 已完成 | 订单、发布、登录、聊天纵向抽取 | 应用服务、事务边界、后台生命周期和 Server 查询依赖均已收口,handler 不再直接访问数据库 |
|
||||
| 5. 应用生命周期装配 | 已完成 | 消除必需依赖 setter 回填 | 构造验证与幂等关闭测试 |
|
||||
| 4. Server 应用服务 | 进行中 | 订单、发布、登录、聊天纵向抽取 | 已完成文件级服务拆分;待完成应用 Port 独立包、Server 不持有业务服务定位器、handler 不依赖 db/xianyu/browser |
|
||||
| 5. 应用生命周期装配 | 进行中 | 消除必需依赖 setter 回填并统一关闭边界 | 已有 Server 自有 worker 等待;待完成 Context-aware Stop、账号 StopAll 超时、删除任务登记和统一生命周期清单 |
|
||||
| 6. Engine 与 Automation | 已完成 | facade + 独立状态组件 | Engine/Automation 组件边界、race、生命周期与冻结规范测试均已通过 |
|
||||
| 7. React Feature 化 | 已完成 | 页面、Hook、API、类型按领域拆分 | 领域 feature、行为测试、依赖门禁和构建门禁已完成 |
|
||||
| 8. DB 与事务治理 | 已完成 | 窄接口、事务执行器、方言门禁 | Chat、Automation、通知、分析、订单、发布、登录和事务边界已通过窄 repository 收口并完成 Server race |
|
||||
| 9. 架构门禁与兼容清理 | 已完成 | 自动依赖规则、删除到期兼容层 | Go 低层依赖、Server 事务边界、React 版本化调用和旧入口保留条件均已有自动检查或审计清单 |
|
||||
| 10. 注释基线清零 | 已完成 | 全仓严格中文注释检查 | Go/React 注释基线已删除;无基线严格门禁通过;冻结 CAPTCHA 文件由显式边界规则保护 |
|
||||
| 8. DB 与事务治理 | 进行中 | 窄接口、事务执行器、方言门禁 | 已有部分 repository;待完成禁止 `sql.Tx`/`db.*` 泄露、UoW 在基础设施适配器实现、批量读写和补偿记录 |
|
||||
| 9. 架构门禁与兼容清理 | 进行中 | 允许依赖图、临时例外、兼容路径退场 | 当前门禁只覆盖低层反向依赖;待完成 Server/application 允许边、Port 类型扫描、旧 API 遥测与 Sunset 条件 |
|
||||
| 10. 注释基线清零 | 进行中 | 全仓准确中文注释检查 | 已有字符级/AST 门禁;待完成模板短语黑名单、业务语义抽查、复杂度门禁和冻结文件精确例外 |
|
||||
|
||||
### 当前执行入口
|
||||
|
||||
- 当前阶段:全部重构计划已完成;阶段 10 注释基线清零与严格门禁、阶段 9 架构依赖与兼容清理、阶段 7 React Feature 化、阶段 8 DB 与事务治理,以及此前各阶段均已完成切片收口并通过最终审计;
|
||||
- 当前阶段:审计重开后的过渡架构治理;不得使用“全部完成”表述。当前先执行 P0 敏感设置边界,再执行应用 Port、生命周期、补偿模型、批量同步和前端页面性能切片;每个 PR 必须同时更新完成证据和剩余风险;
|
||||
- 已完成:总计划、依赖规则、中文注释规范、`AGENTS.md` 强约束,以及 Go/TypeScript AST 注释检查器和历史基线;
|
||||
- 阶段 1 已完成:server 测试模板预置管理员和账号 cookie,普通测试约 21.3 秒,完整 server race 约 194.3 秒通过;
|
||||
- 已完成阶段 2 逻辑切片一“Repository 敏感数据边界”:建立 `CookieSummary`、`ListOwnedIDs`、`ExistsOwned`、`GetOwnerID`、`GetSummaryOwned` 和原子 `GetValueOwned`,覆盖跨用户、无效 user ID 及无效密文回归;
|
||||
@@ -692,3 +694,26 @@ npm --prefix frontend run build
|
||||
| 2026-08-15 | 完成业务测试覆盖切片“通知与批量任务过期响应并发” | 补充通知渠道刷新丢弃旧响应、批量轮询防并发和关闭后旧响应失效,以及普通请求纯文本错误读取失败测试;验证请求代次和轮询保护,不触发真实推送、商品或平台服务;前端注释门禁、定向测试和类型检查通过 | 下一步:执行全量回归、覆盖率终审并记录仍需真实取消时序或不可达代码分支 |
|
||||
| 2026-08-15 | 完成业务测试覆盖切片“卡密、仪表盘、设置与订单过期响应” | 补充卡密库存刷新、仪表盘经营数据、系统设置和订单查询的重复请求旧响应隔离测试;前端全量覆盖率达到语句 98.00%、函数 100%、行 99.86%,分支 79.82%;剩余未覆盖主要为取消/卸载时序保护、订单相似标题不可达分支和防御性条件组合 | 下一步:执行最终全量回归并形成业务覆盖率验收与跳过项清单 |
|
||||
| 2026-08-15 | 完成阶段性业务覆盖率终审 | 前端 50 个测试文件、312 个用例通过;业务代码覆盖率为语句 98.00%(2500/2551)、函数 100%(547/547)、行 99.86%(2178/2181)、分支 79.82%(1385/1735);所有业务函数均有测试入口。剩余分支集中在请求取消/卸载后旧响应保护的极端时序、真实账号或外部平台会话生命周期,以及订单相似标题判断中被前置标题返回遮蔽的不可达路径;纯 UI 组件按约束排除 | 下一步:后续新增业务函数必须同步测试与中文注释,若改变取消时序或外部依赖契约需重新审计覆盖率 |
|
||||
|
||||
## 11. 审计重开后的执行切片
|
||||
|
||||
以下切片是当前唯一有效的后续入口。每个切片完成后必须:更新本表、补齐针对性测试、运行适用门禁,并创建一个中文提交;未满足“完成条件”不得标记为已完成。
|
||||
|
||||
| 优先级 | PR 切片 | 主要范围 | 完成条件 |
|
||||
| --- | --- | --- | --- |
|
||||
| P0 | 敏感系统设置与运维输出脱敏 | `SystemSettings.Redacted`、敏感值 retain/replace/clear、管理端响应、dbverify 指纹输出、前端敏感字段状态 | HTTP 响应和 React 状态不出现秘密;空值显式清除、缺省值保留;Go/React 回归覆盖;三库迁移测试通过 |
|
||||
| P1 | 应用 Port 与架构允许边 | `internal/application/orders`、订单命令/结果 DTO、基础设施适配器、`architecturecheck` | Server 不再创建或持有订单应用实现;Port 不出现 `sql.Tx`、`db.*`、HTTP 类型;架构门禁能主动拒绝违规 |
|
||||
| P1 | 凭证快照与账号操作协调器 | 凭证版本、短锁快照、外部调用重试/合并、每账号有界协调、锁指标和锁 Map 回收 | 慢速外部调用不持有共享凭证锁;并发更新有版本冲突测试;锁等待和队列可观测 |
|
||||
| P1 | 生命周期与删除 fencing | `Server.Stop(ctx)`、`Manager.Stop(ctx)`、StopAll 并发收束、账号删除任务登记和状态 fencing | 所有等待受关闭 Context 限制;删除接口不会产生游离 Stop goroutine;超时有明确错误和可追踪任务 |
|
||||
| P1 | 外部动作补偿与 reconciliation | 手动发货、本地订单状态、自动化准备检查点、reconciliation/outbox 表和重试 worker | 外部成功/本地失败统一返回三态结果;不会重复执行不可逆动作;补偿记录可恢复、可审计 |
|
||||
| P2 | 商品/订单批量同步 | 用户范围 Join、游标分页、批量 Upsert、规格探测缓存和受限并发 | 消除逐账号/逐订单 N+1;错误不再被忽略;SQLite/MySQL/Postgres 查询计划和大数据量测试有证据 |
|
||||
| P2 | HTTP 契约与兼容退场 | 批量 DTO、错误字段统一、旧路由使用量、Deprecation/Sunset 和删除版本 | 新增接口不使用匿名动态结果;旧入口有遥测、期限和兼容测试 |
|
||||
| P2 | React 页面边界与初始包体 | 页面迁移到 feature、路由懒加载、Provider/路由壳、bundle budget | App 不同步加载全部页面;首屏预算门禁通过;遵循并行请求、动态导入和避免重复渲染规范 |
|
||||
| P2 | 复杂度与注释真实性 | 长函数拆分、复杂度门禁、模板注释黑名单、冻结文件精确例外 | 新增/修改函数和变量有准确中文语义注释;模板注释不得通过门禁;冻结 CAPTCHA 仅按文件例外 |
|
||||
|
||||
### 11.1 当前切片完成记录
|
||||
|
||||
| 日期 | 切片 | 状态 | 证据 |
|
||||
| --- | --- | --- | --- |
|
||||
| 2026-08-15 | 审计重开与完成条件纠偏 | 已完成 | 已将阶段 2、4、5、8、9、10 从“已完成”改为“进行中”,建立九个可回滚 PR 切片,并明确“测试通过不等于架构完成”的新验收规则 |
|
||||
| 2026-08-15 | P0 敏感系统设置与运维输出脱敏 | 已完成 | 新增 `SystemSettings.Redacted`;管理端不再返回 `ai_api_key`、SMTP 密码和验证码密钥明文;敏感设置缺省保留、显式空值清除;dbverify 改为长度+指纹;Go/React 回归、类型检查、前端构建和 `make check` 通过。阶段 2 仍保持“进行中”,因为凭证锁审计、访问审计和三库回归尚未全部完成 |
|
||||
@@ -78,7 +78,7 @@ export const NotificationSmtpSettings: React.FC<NotificationSmtpSettingsProps> =
|
||||
<div className="space-y-2">
|
||||
<label className="block text-sm font-bold text-gray-800">邮箱密码 / 授权码</label>
|
||||
<div className="relative">
|
||||
<input type={showPassword ? 'text' : 'password'} value={smtp.smtp_password || ''} onChange={handlePasswordChange} placeholder="输入密码或授权码" className="w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm" />
|
||||
<input type={showPassword ? 'text' : 'password'} value={smtp.smtp_password || ''} onChange={handlePasswordChange} placeholder={smtp.smtp_password_configured ? '已配置,如需替换请输入新密码' : '输入密码或授权码'} className="w-full ios-input px-4 py-3 pr-12 rounded-xl text-sm" />
|
||||
<button type="button" onClick={handleTogglePassword} className="absolute right-3 top-1/2 -translate-y-1/2 p-2 text-gray-400 hover:text-gray-600 transition-colors">{showPassword ? <EyeOff className="w-4 h-4" /> : <Eye className="w-4 h-4" />}</button>
|
||||
</div>
|
||||
<p className="text-xs text-gray-500">QQ 邮箱需使用授权码(QQ 邮箱设置 → 账号 → 开启 SMTP → 生成授权码)</p>
|
||||
|
||||
@@ -94,6 +94,24 @@ describe('useNotifications', /* 当前回调处理通知渠道、SMTP 和动作
|
||||
expect(updateSmtpMock).toHaveBeenCalledWith(expect.objectContaining({ smtp_port: 587 }), expect.objectContaining({ signal: expect.any(AbortSignal) }));
|
||||
});
|
||||
|
||||
// 脱敏 SMTP 配置保存测试验证缺省密码不会被意外清空。
|
||||
test('脱敏 SMTP 配置保存时不会意外清空服务端密码', /* 当前回调验证敏感字段保留语义。 */ async () => {
|
||||
getSmtpMock.mockResolvedValueOnce({
|
||||
smtp_server: 'smtp.example.com', smtp_port: 587, smtp_user: 'sender@example.com', smtp_password_configured: true,
|
||||
});
|
||||
// hook 是脱敏 SMTP 配置场景下的通知 Hook 渲染结果。
|
||||
const hook = renderHook(/* hookFactory 创建管理员通知 Hook。 */ () => useNotifications(true));
|
||||
// loadingAssertion 等待脱敏 SMTP 配置加载完成。
|
||||
await waitFor(/* loadingAssertion 检查异步加载状态。 */ () => expect(hook.result.current.loading).toBe(false));
|
||||
|
||||
// saveAction 提交未修改密码的 SMTP 配置。
|
||||
await act(/* saveAction 执行 SMTP 保存动作。 */ async () => hook.result.current.handleSaveSmtp());
|
||||
// payload 是发送给服务端的 SMTP 配置载荷。
|
||||
const payload = updateSmtpMock.mock.calls.at(-1)?.[0] as SystemSettings;
|
||||
expect(payload.smtp_password).toBeUndefined();
|
||||
expect(payload.smtp_server).toBe('smtp.example.com');
|
||||
});
|
||||
|
||||
test('渠道校验失败和删除成功都保持明确状态', /* 当前回调验证通知 Hook 的校验与删除路径。 */ async () => {
|
||||
// hook 是渠道校验和删除场景下的通知 Hook 渲染结果。
|
||||
const hook = renderHook(
|
||||
|
||||
@@ -317,12 +317,17 @@ export const useNotifications = (isAdmin: boolean): NotificationState => {
|
||||
smtpAbort.current = controller;
|
||||
setSmtpSaving(true);
|
||||
try {
|
||||
await updateSystemSettings({
|
||||
const payload: SystemSettings = {
|
||||
smtp_server: smtp.smtp_server || '', smtp_port: smtp.smtp_port || 587, smtp_user: smtp.smtp_user || '',
|
||||
smtp_password: smtp.smtp_password || '', smtp_from_name: smtp.smtp_from_name || '',
|
||||
smtp_from_name: smtp.smtp_from_name || '',
|
||||
smtp_from_address: smtp.smtp_from_address || smtp.smtp_user || '', smtp_use_tls: smtp.smtp_use_tls !== false,
|
||||
smtp_use_ssl: smtp.smtp_use_ssl === true,
|
||||
}, { signal: controller.signal });
|
||||
};
|
||||
// 仅在管理员主动编辑过密码字段时提交,避免加载配置后意外清空服务端秘密。
|
||||
if (Object.prototype.hasOwnProperty.call(smtp, 'smtp_password')) {
|
||||
payload.smtp_password = smtp.smtp_password;
|
||||
}
|
||||
await updateSystemSettings(payload, { signal: controller.signal });
|
||||
if (isCurrentNotificationRequest(generation, smtpGeneration.current)) showToast('success', 'SMTP 配置已保存');
|
||||
} catch (error: unknown /* SMTP 保存异常 */) {
|
||||
if (isCurrentNotificationRequest(generation, smtpGeneration.current) && !controller.signal.aborted) {
|
||||
|
||||
@@ -11,6 +11,10 @@ export const LOG_LEVELS = [
|
||||
|
||||
/** 不应通过系统配置批量保存的兼容字段集合。 */
|
||||
export const SETTINGS_SAVE_OMIT_KEYS = new Set([
|
||||
'ai_api_key_configured',
|
||||
'smtp_password_configured',
|
||||
'qq_reply_secret_key_configured',
|
||||
'captcha.remote_secret_key_configured',
|
||||
'smtp_server',
|
||||
'smtp_port',
|
||||
'smtp_user',
|
||||
|
||||
@@ -151,7 +151,7 @@ const Settings: React.FC = () => {
|
||||
value={settings.ai_api_key || ''}
|
||||
onChange={/* 当前回调处理用户交互或异步状态变化。 */ e => setSettings({...settings, ai_api_key: e.target.value})}
|
||||
className="w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm"
|
||||
placeholder="sk-..."
|
||||
placeholder={settings.ai_api_key_configured ? '已配置,如需替换请输入新密钥' : 'sk-...'}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
@@ -274,6 +274,7 @@ const Settings: React.FC = () => {
|
||||
onChange={/* 当前回调处理用户交互或异步状态变化。 */ event => setSettings({...settings, 'captcha.remote_secret_key': event.target.value})}
|
||||
className="w-full ios-input px-4 py-3 pr-12 rounded-xl font-mono text-sm"
|
||||
autoComplete="off"
|
||||
placeholder={settings['captcha.remote_secret_key_configured'] ? '已配置,如需替换请输入新密钥' : '请输入服务秘钥'}
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -442,6 +442,21 @@ test('getSystemSettings normalizes numeric renewal retention', async () => {
|
||||
expect(settings.renewal_log_retention_days).toBe(10);
|
||||
} /* 回调函数负责当前业务流程。 */);
|
||||
|
||||
// getSystemSettings 脱敏响应测试验证客户端只接收敏感配置状态。
|
||||
test('getSystemSettings keeps only sensitive configuration markers', /* 当前回调验证脱敏设置归一化。 */ async () => {
|
||||
// fetchMock 返回服务端的脱敏设置视图,不包含任何敏感明文。
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse({
|
||||
ai_api_key_configured: 'true',
|
||||
smtp_password_configured: 'false',
|
||||
})));
|
||||
|
||||
// settings 是客户端归一化后的脱敏设置对象。
|
||||
const settings = await getSystemSettings();
|
||||
expect(settings.ai_api_key).toBeUndefined();
|
||||
expect(settings.ai_api_key_configured).toBe(true);
|
||||
expect(settings.smtp_password_configured).toBe(false);
|
||||
});
|
||||
|
||||
test('logout calls backend session invalidation route', async () => {
|
||||
const fetchMock = vi.fn().mockResolvedValue(jsonResponse({ success: true })); /* fetchMock 表示fetchMock。 */
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
@@ -12,6 +12,15 @@ import { formatLocalDate } from '../dateRange';
|
||||
const normalizeSettings = (settings: Record<string, any>): SystemSettings => {
|
||||
// out 配置副本,用于当前 API 处理流程。
|
||||
const out: Record<string, any> = { ...settings };
|
||||
// sensitiveKey 是后端只返回配置状态、不返回明文的敏感配置键。
|
||||
const sensitiveKeys = ['ai_api_key', 'smtp_password', 'qq_reply_secret_key', 'captcha.remote_secret_key'];
|
||||
for (const sensitiveKey /* sensitiveKey 表示当前处理的敏感配置键。 */ of sensitiveKeys) {
|
||||
// configuredKey 是敏感配置是否已设置的状态字段。
|
||||
const configuredKey = `${sensitiveKey}_configured`;
|
||||
if (configuredKey in out) {
|
||||
out[configuredKey] = out[configuredKey] === true || out[configuredKey] === 'true';
|
||||
}
|
||||
}
|
||||
if ('renewal_log_retention_days' in out) {
|
||||
// parsed 转换后的数值,用于当前 API 处理流程。
|
||||
const parsed = Number(out.renewal_log_retention_days);
|
||||
|
||||
@@ -477,6 +477,8 @@ export interface SystemSettings {
|
||||
ai_model?: string;
|
||||
/** 全局 AI API 密钥。 */
|
||||
ai_api_key?: string;
|
||||
/** 全局 AI API 密钥是否已在服务端配置。 */
|
||||
ai_api_key_configured?: boolean;
|
||||
/** 全局 AI API 地址。 */
|
||||
ai_api_url?: string;
|
||||
/** 全局 AI 基础地址。 */
|
||||
@@ -487,6 +489,8 @@ export interface SystemSettings {
|
||||
registration_enabled?: boolean;
|
||||
/** 系统 SMTP 服务器地址。 */
|
||||
smtp_server?: string;
|
||||
/** 系统 SMTP 密码是否已在服务端配置。 */
|
||||
smtp_password_configured?: boolean;
|
||||
/** 服务端日志级别。 */
|
||||
log_level?: 'debug' | 'info' | 'warn' | 'error' | string;
|
||||
/** 服务端日志格式。 */
|
||||
@@ -497,6 +501,8 @@ export interface SystemSettings {
|
||||
'captcha.remote_service_url'?: string;
|
||||
/** 远程验证码服务密钥。 */
|
||||
'captcha.remote_secret_key'?: string;
|
||||
/** 远程验证码服务密钥是否已在服务端配置。 */
|
||||
'captcha.remote_secret_key_configured'?: boolean;
|
||||
/** 远程验证码服务 Cookie 配置。 */
|
||||
'captcha.remote_pass_cookies'?: boolean | string;
|
||||
/** 兼容未来配置键的扩展字段。 */
|
||||
|
||||
+46
-1
@@ -513,6 +513,13 @@ func (s *SystemSettings) All(ctx context.Context) (map[string]string, error) {
|
||||
// Set 设置单项。
|
||||
func (s *SystemSettings) Set(ctx context.Context, key, value string) error {
|
||||
if isSensitiveSettingKey(key) {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
// keyCol 是当前数据库方言下的设置键列名。
|
||||
keyCol := dialectQuote(s.Dialect, "key")
|
||||
// err 是删除敏感设置时返回的数据库错误。
|
||||
_, err := s.DB.ExecContext(ctx, `DELETE FROM system_settings WHERE `+keyCol+`=?`, key)
|
||||
return err
|
||||
}
|
||||
// encrypted、err 保存encrypted、err,供当前处理流程使用
|
||||
encrypted, err := s.codec.encrypt("system-setting", key, value)
|
||||
if err != nil {
|
||||
@@ -551,6 +558,13 @@ func (s *SystemSettings) SetMany(ctx context.Context, values map[string]string)
|
||||
// key、value 表示当前遍历过程中的key、value
|
||||
for key, value := range values {
|
||||
if isSensitiveSettingKey(key) {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
// err 保存敏感设置清除操作的数据库错误。
|
||||
if _, err := tx.ExecContext(ctx, `DELETE FROM system_settings WHERE `+keyCol+`=?`, key); err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
// encrypted、err 保存encrypted、err,供当前处理流程使用
|
||||
encrypted, err := s.codec.encrypt("system-setting", key, value)
|
||||
if err != nil {
|
||||
@@ -566,6 +580,37 @@ func (s *SystemSettings) SetMany(ctx context.Context, values map[string]string)
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// Redacted 返回可供管理端展示的系统设置,并以 *_configured 标记敏感值是否已配置。
|
||||
// 该方法只读取数据库中的原始值,不解密敏感配置,确保秘密不会进入 HTTP 响应或前端状态。
|
||||
func (s *SystemSettings) Redacted(ctx context.Context) (map[string]string, error) {
|
||||
// keyCol 是当前数据库方言下的设置键列名。
|
||||
keyCol := dialectQuote(s.Dialect, "key")
|
||||
// rows 是系统设置原始值查询结果集。
|
||||
rows, err := s.DB.QueryContext(ctx, `SELECT `+keyCol+`, value FROM system_settings`)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
// result 是不含敏感明文的管理端设置响应。
|
||||
result := make(map[string]string)
|
||||
for rows.Next() {
|
||||
// key、value 是数据库返回的设置键和值。
|
||||
var key, value string
|
||||
// err 是扫描设置行时返回的数据库错误。
|
||||
if err := rows.Scan(&key, &value); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isSensitiveSettingKey(key) {
|
||||
if strings.TrimSpace(value) != "" {
|
||||
result[key+"_configured"] = "true"
|
||||
}
|
||||
continue
|
||||
}
|
||||
result[key] = value
|
||||
}
|
||||
return result, rows.Err()
|
||||
}
|
||||
|
||||
// PublicSystemKeys 是公开设置键白名单(前端登录页等无需登录可读)。
|
||||
var PublicSystemKeys = map[string]bool{
|
||||
"theme_color": true,
|
||||
@@ -574,7 +619,7 @@ var PublicSystemKeys = map[string]bool{
|
||||
// Public 取公开设置子集。
|
||||
func (s *SystemSettings) Public(ctx context.Context) (map[string]string, error) {
|
||||
// all、err 保存all、err,供当前处理流程使用
|
||||
all, err := s.All(ctx)
|
||||
all, err := s.Redacted(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -105,6 +105,77 @@ func TestSensitiveRepositoriesEncryptAtRestAndDecryptOnRead(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestSystemSettingsRedactedNeverReturnsSensitivePlaintext 验证管理端设置视图只返回敏感配置状态。
|
||||
func TestSystemSettingsRedactedNeverReturnsSensitivePlaintext(t *testing.T) {
|
||||
t.Setenv("XIANYU_DATA_KEY", "redacted-test-key")
|
||||
// store、cleanup 是测试数据库及其清理函数。
|
||||
store, cleanup := newTestDB(t)
|
||||
defer cleanup()
|
||||
// ctx 是当前测试使用的请求上下文。
|
||||
ctx := context.Background()
|
||||
// err 是批量保存设置时返回的错误。
|
||||
if err := store.Settings.SetMany(ctx, map[string]string{
|
||||
"theme_color": "blue",
|
||||
"ai_api_key": "sk-never-return",
|
||||
"smtp_password": "smtp-never-return",
|
||||
"captcha.remote_secret_key": "captcha-never-return",
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// redacted、err 是脱敏设置视图及其读取错误。
|
||||
redacted, err := store.Settings.Redacted(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if redacted["theme_color"] != "blue" {
|
||||
t.Fatalf("普通配置未返回: %#v", redacted)
|
||||
}
|
||||
for _, secret := range []string{"ai_api_key", "smtp_password", "captcha.remote_secret_key"} { // secret 是待验证的敏感配置键。
|
||||
// ok 表示脱敏响应是否意外包含敏感键。
|
||||
if _, ok := redacted[secret]; ok {
|
||||
t.Fatalf("敏感配置明文不应返回: key=%s value=%q", secret, redacted[secret])
|
||||
}
|
||||
if redacted[secret+"_configured"] != "true" {
|
||||
t.Fatalf("敏感配置状态缺失: key=%s response=%#v", secret, redacted)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestSensitiveSettingEmptyValueClearsSecret 验证敏感设置显式提交空值时会删除密文。
|
||||
func TestSensitiveSettingEmptyValueClearsSecret(t *testing.T) {
|
||||
t.Setenv("XIANYU_DATA_KEY", "clear-test-key")
|
||||
// store、cleanup 是测试数据库及其清理函数。
|
||||
store, cleanup := newTestDB(t)
|
||||
defer cleanup()
|
||||
// ctx 是当前测试使用的请求上下文。
|
||||
ctx := context.Background()
|
||||
// err 是首次写入敏感设置时返回的错误。
|
||||
if err := store.Settings.Set(ctx, "ai_api_key", "sk-to-clear"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// err 是显式清除敏感设置时返回的错误。
|
||||
if err := store.Settings.Set(ctx, "ai_api_key", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// value、err 是读取已清除敏感设置的结果。
|
||||
value, err := store.Settings.Get(ctx, "ai_api_key")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if value != "" {
|
||||
t.Fatalf("敏感设置未清除: %q", value)
|
||||
}
|
||||
// redacted、err 是清除后的脱敏视图及其读取错误。
|
||||
redacted, err := store.Settings.Redacted(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if redacted["ai_api_key_configured"] != "" {
|
||||
t.Fatalf("清除后仍报告已配置: %#v", redacted)
|
||||
}
|
||||
}
|
||||
|
||||
// TestSecretCodecReadsLegacyPlaintextAndRejectsWrongKey 负责TestSecretCodecReadsLegacyPlaintextAndRejectsWrongKey相关处理。
|
||||
func TestSecretCodecReadsLegacyPlaintextAndRejectsWrongKey(t *testing.T) {
|
||||
// codec 保存codec,供当前处理流程使用
|
||||
|
||||
@@ -501,3 +501,54 @@ func TestFetchOpenAIModelsEmptyBaseURL(t *testing.T) {
|
||||
t.Fatal("空地址应报错")
|
||||
}
|
||||
}
|
||||
|
||||
// TestSystemSettingsEndpointRedactsSensitiveValues 验证管理员设置接口不会返回敏感配置明文。
|
||||
func TestSystemSettingsEndpointRedactsSensitiveValues(t *testing.T) {
|
||||
t.Setenv("XIANYU_DATA_KEY", "server-redacted-test-key")
|
||||
// srv、store、cleanup 是测试服务、数据库及其清理函数。
|
||||
srv, store, cleanup := newTestServer(t)
|
||||
defer cleanup()
|
||||
// ctx 是当前测试使用的请求上下文。
|
||||
ctx := context.Background()
|
||||
// err 是写入脱敏测试秘密时返回的错误。
|
||||
if err := store.Settings.SetMany(ctx, map[string]string{
|
||||
"ai_api_key": "sk-server-secret",
|
||||
"smtp_password": "smtp-server-secret",
|
||||
"captcha.remote_secret_key": "captcha-server-secret",
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// h 是当前测试服务的 HTTP 路由器。
|
||||
h := srv.Router()
|
||||
// cookie 是管理员登录后得到的会话 Cookie。
|
||||
cookie := loginHelper(t, h)
|
||||
// req 是读取管理员系统设置的 HTTP 请求。
|
||||
req := httptest.NewRequest(http.MethodGet, "/system-settings", nil)
|
||||
req.AddCookie(cookie)
|
||||
// rec 是捕获设置响应的 HTTP 记录器。
|
||||
rec := httptest.NewRecorder()
|
||||
h.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("settings status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
// response 是管理员系统设置的脱敏响应。
|
||||
var response map[string]string
|
||||
// err 是解析设置响应时返回的 JSON 错误。
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &response); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, secret := range []string{"sk-server-secret", "smtp-server-secret", "captcha-server-secret"} { // secret 是不应出现在响应中的敏感明文。
|
||||
if strings.Contains(rec.Body.String(), secret) {
|
||||
t.Fatalf("settings response leaked secret %q: %s", secret, rec.Body.String())
|
||||
}
|
||||
}
|
||||
for _, key := range []string{"ai_api_key", "smtp_password", "captcha.remote_secret_key"} { // key 是待验证的敏感配置键。
|
||||
// ok 表示脱敏响应是否意外包含敏感键。
|
||||
if _, ok := response[key]; ok {
|
||||
t.Fatalf("settings response contains sensitive key %q: %#v", key, response)
|
||||
}
|
||||
if response[key+"_configured"] != "true" {
|
||||
t.Fatalf("settings response misses configured marker %q: %#v", key, response)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func (s *Server) publicSettings(w http.ResponseWriter, r *http.Request) {
|
||||
// allSettings 负责all设置相关处理。
|
||||
func (s *Server) allSettings(w http.ResponseWriter, r *http.Request) {
|
||||
// m、err 保存m、err,供当前处理流程使用
|
||||
m, err := s.Store.Settings.All(r.Context())
|
||||
m, err := s.Store.Settings.Redacted(r.Context())
|
||||
if err != nil {
|
||||
writeErr(w, http.StatusInternalServerError, "查询失败")
|
||||
return
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import{j as e,r,c as Is,b as Oe,d as ir}from"./react-vendor-C_od1ZSF.js";import{L as or,U as Na,M as ys,C as Os,B as va,S as _a,Z as js,a as Rt,b as Ps,G as Bs,c as Ts,d as Es,e as cr,f as wa,g as ut,A as Fs,D as dr,P as ka,h as Bt,E as Ca,T as xr,i as mr,j as _e,X as ke,k as ur,l as pr,m as Ds,n as Sa,o as lt,p as Ye,q as La,K as hr,r as bt,s as mt,Q as rs,t as yt,u as wt,v as $t,R as We,w as Ra,x as gr,y as Ze,z as St,F as Mt,H as nt,I as zs,J as kt,N as br,O as fr,V as yr,W as Aa,Y as Ia,_ as Oa,$ as jr,a0 as Nr,a1 as ls,a2 as Wt,a3 as Ns,a4 as vr,a5 as _r,a6 as vs,a7 as Us,a8 as wr,a9 as kr,aa as qt,ab as Ws,ac as Zt,ad as Pa,ae as Cr,af as Sr,ag as ss,ah as Ta,ai as Lr,aj as Rr,ak as Ar,al as Ir,am as Or,an as Pr,ao as Js}from"./icons-vendor-i_74xDZy.js";import{R as Yt,B as Tr,X as Gs,Y as Vs,T as Xt,a as Er,C as _s,A as Dr,b as $r,c as Mr,P as Qs,d as Ks,L as qr}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 n of document.querySelectorAll('link[rel="modulepreload"]'))l(n);new MutationObserver(n=>{for(const c of n)if(c.type==="childList")for(const u of c.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&l(u)}).observe(document,{childList:!0,subtree:!0});function a(n){const c={};return n.integrity&&(c.integrity=n.integrity),n.referrerPolicy&&(c.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?c.credentials="include":n.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function l(n){if(n.ep)return;n.ep=!0;const c=a(n);fetch(n.href,c)}})();const Br=({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"})})}),ws=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23Line truncated
|
||||
|
||||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(Ps,{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:g,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:Q,children:"取消"}),e.jsxs("button",{onClick:de,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:Q,children:[Q?e.jsx(_e,{className:"w-4 h-4 animate-spin"}):e.jsx(lt,{className:"w-4 h-4"}),Q?"保存中...":"保存"]})]})})]})}),document.body)]})},Fn=[{key:"all",label:"全部"},{key:"processing",label:"处理中"},{key:"shipped",label:"已发货"},{key:"pending_ship",label:"待发货"},{key:"completed",label:"已完成"},{key:"cancelled",label:"已取消"},{key:"refunding",label:"退款中"}],zn=t=>{const s=typeof t=="object"&&t!==null?t:{},a=Array.isArray(s.results)?s.results:[];return{total:Number(s.total||0),success_count:Number(s.success_count||0),failed_count:Number(s.failed_count||0),results:a.map(Un)}},Un=t=>{const s=typeof t=="object"&&t!==null?t:{};return{order_id:String(s.order_id||"unknown"),success:s.success===!0,message:String(s.message||"")}},Wn=t=>(t==null?void 0:t.results.filter(Jn))||[],Jn=t=>!t.success,Gn=(t,s)=>t!==null&&!s,Vn=t=>{if(!t)return"请选择订单文件";const s=t.name.toLowerCase().split(".").pop()||"";return["xlsx","csv","tsv","json"].includes(s)?"":"仅支持 .xlsx、.csv、.tsv、.json 格式"},ft=(t,s)=>t===s,Qn=(t,s)=>t instanceof Error&&t.message?t.message:s,Kn=({filter:t,onFilterChange:s,accountFilter:a,onAccountFilterChange:l,accounts:n,accountName:c,searchText:u,onSearchChange:h})=>{const m=p=>s(p.currentTarget.dataset.status||"all"),j=p=>l(p.target.value),x=p=>h(p.target.value);return e.jsxs("div",{className:"p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full",children:Fn.map(p=>e.jsx("button",{"data-status":p.key,onClick:m,className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${t===p.key?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:p.label},p.key))}),e.jsxs("div",{className:"flex w-full md:w-auto flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(yt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{"aria-label":"按账号筛选订单",value:a,onChange:j,className:"ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm",children:[e.jsx("option",{value:"",children:"全部账号"}),n.map(p=>e.jsx("option",{value:p.id,children:c(p.id)},p.id))]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(St,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:u,onChange:x,className:"ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"})]})]})]})},Hn=t=>{const s=c=>{var u;t.setImportFile(((u=c.target.files)==null?void 0:u[0])||null)},a=()=>t.closeImportModal(),l=()=>void t.handleImportOrders(),n=()=>void t.handleRetryImport();return t.showImportModal?Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"插入订单"}),e.jsx("button",{onClick:a,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"选择Excel文件"}),e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv,.json",onChange:s,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持 .xlsx
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:x,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:u,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:S,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(_e,{className:"w-4 h-4 animate-spin"}):e.jsx(Mt,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:q,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(_e,{className:"w-4 h-4 animate-spin"}):e.jsx(nt,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},ti=({type:t})=>{switch(t){case"text":return e.jsx(Ia,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(Aa,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(yr,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(Os,{className:"w-5 h-5 text-gray-500"})}},si=(t,s,a)=>{const l=a.trim().toLocaleLowerCase();return t.filter(n=>(!s||n.type===s)&&(!l||n.name.toLocaleLowerCase().includes(l)))},Ka=t=>t.split(`
|
||||
`).map(s=>s.trim()).filter(Boolean),ai=(t,s,a)=>!!(t&&Ka(s).length>0&&!a),vt=(t,s,a,l)=>t===s&&a===l,ri=()=>{const[t,s]=r.useState([]),[a,l]=r.useState(!0),n=r.useRef(0),c=r.useRef(null),u=r.useCallback(async()=>{var j;const h=++n.current;(j=c.current)==null||j.abort();const m=new AbortController;c.current=m,l(!0);try{const x=await Ms({signal:m.signal});if(h!==n.current)return;s(x)}catch(x){h===n.current&&!m.signal.aborted&&console.error("加载卡密库存失败:",x)}finally{h===n.current&&l(!1)}},[]);return r.useEffect(()=>(u(),()=>{var m;n.current+=1,(m=c.current)==null||m.abort()}),[u]),{cards:t,setCards:s,loading:a,loadCards:u}},li=t=>{const s=t.dataCards,a=t.loadCards,[l,n]=r.useState(!1),[c,u]=r.useState("create"),[h,m]=r.useState(null),[j,x]=r.useState(null),[p,_]=r.useState(!1),[S,q]=r.useState(""),[w,P]=r.useState(""),[A,G]=r.useState(null),[H,X]=r.useState(""),f=r.useRef(0),y=r.useRef(null),z=r.useRef(""),O=r.useMemo(()=>Ka(w),[w]),F=r.useCallback(()=>{var k;u("create"),m(null),x(null),q((k=s[0])!=null&&k.id?String(s[0].id):""),P(""),G(null),X(""),n(!0)},[s]),d=r.useCallback(()=>{var k;f.current+=1,(k=y.current)==null||k.abort(),_(!1),n(!1)},[]),B=r.useCallback(async()=>{var C;if(!h||p)return;const k=++f.current;(C=y.current)==null||C.abort();const D=new AbortController;y.current=D,_(!0),x(null);try{const W=await Ll(h,{signal:D.signal});if(!vt(k,f.current,"",""))return;x(W),W.created>0&&await a()}catch(W){if(!vt(k,f.current,"",""))return;x({error:(W==null?void 0:W.message)||"上传失败"})}finally{vt(k,f.current,"","")&&_(!1)}},[p,h,a]),Z=r.useCallback(async()=>{var W;if(!ai(S,w,p))return;const k=S,D=++f.current;z.current=k,(W=y.current)==null||W.abort();const C=new AbortController;y.current=C,_(!0),G(null),X("");try{const V=await Rl(k,w,{signal:C.signal});if(!vt(D,f.current,k,S))return;G({added:V.added}),P(""),await a()}catch(V){if(!vt(D,f.current,k,S))return;X((V==null?void 0:V.message)||"追加失败")}finally{vt(D,f.current,k,S)&&_(!1)}},[w,S,p,a]),M=r.useCallback(async()=>{await B()},[B]),b=r.useCallback(async()=>{z.current&&S!==z.current||await Z()},[S,Z]);return{showBatchModal:l,setShowBatchModal:n,batchTab:c,setBatchTab:u,batchFile:h,setBatchFile:m,batchResult:j,batchBusy:p,appendTargetId:S,setAppendTargetId:q,appendContent:w,setAppendContent:P,appendResult:A,appendError:H,appendPreview:O,openBatchModal:F,closeBatchModal:d,handleBatchCreate:B,handleBatchAppend:Z,handleRetryBatchCreate:M,handleRetryBatchAppend:b}},xa=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),ni=()=>{const{cards:t,loadCards:s}=ri(),[a,l]=r.useState(!1),[n,c]=r.useState(!1),[u,h]=r.useState(null),[m,j]=r.useState({}),[x,p]=r.useState(xa),[_,S]=r.useState(""),[q,w]=r.useState(""),P=r.useMemo(()=>t.filter(d=>d.type==="data"),[t]),A=li({dataCards:P,loadCards:s}),G=d=>{var B,Z,M,b,k;h(d),j({id:d.id,name:d.name||"",type:d.type||"text",api_url:((B=d.api_config)==null?void 0:B.url)||"",api_method:((Z=d.api_config)==null?void 0:Z.method)||"GET",api_timeout:((M=d.api_config)==null?void 0:M.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}),l(!0)},H=async()=>{var d,B,Z,M,b,k,D,C;if(u){if(!((d=m.name)!=null&&d.trim())){alert("请输入卡密名称");return}if(!m.type){alert("请选择卡密类型");return}try{const W={name:m.name.trim(),type:m.type,description:(B=m.description)==null?void 0:B.trim(),delay_seconds:m.delay_seconds||0,enabled:m.enabled??!0};m.type==="api"?W.api_config={url:((Z=m.api_url)==null?void 0:Z.trim())||"",method:m.api_method,timeout:m.api_timeout||10,headers:((M=m.api_headers)==null?void 0:M.trim())||void 0,params:((b=m.api_params)==null?void 0:b.trim())||void 0}:m.type==="text"?W.text_content=((k=m.text_content)==null?void 0:k.trim())||"":m.type==="data"?W.data_content=((D=m.data_content)==null?void 0:D.trim())||"":m.type==="image"&&(W.image_url=((C=m.image_url)==null?void 0:C.trim())||""),await ta(u.id,W),l(!1),await s()}catch(W){console.error("更新卡密失败:",W),alert("更新失败,请重试")}}},X=async d=>{if(confirm("确认删除该卡密吗?"))try{await Sl(d),await s()}catch(B){console.error("删除卡密失败:",B),alert("删除失败,请重试")}},f=async()=>{if(!x.name.trim()){alert("请输入卡密名称");return}if(!x.content.trim()){alert(x.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const d={name:x.name.trim(),type:x.type,description:x.description.trim(),enabled:x.enabled,delay_seconds:x.delay_seconds};x.type==="text"&&(d.text_content=x.content.trim()),x.type==="data"&&(d.data_content=x.content.trim()),x.type==="image"&&(d.image_url=x.content.trim()),x.type==="api"&&(d.api_config={url:x.content.trim(),method:x.api_me
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(D=>D.map(C=>`"${String(C).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),M=new Blob(["\uFEFF"+Z],{type:"text/csv;charset=utf-8"}),b=URL.createObjectURL(M),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:A.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(Mt,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:(()=>c(!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(nt,{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(Oa,{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:_,onChange:(d=>S(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(St,{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=>w(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:["显示 ",O.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:O.map(d=>{let B="";return d.type==="data"&&d.data_content?B=`库存: ${d.data_content.split(`
|
||||
`).filter(M=>M.trim()).length} 条`:d.type==="text"&&d.text_content?B=d.text_content:d.type==="api"&&d.api_config?B=d.api_config.url:d.type==="image"&&d.image_url&&(B="图片链接"),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(ti,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:(()=>z(d.id)),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(jr,{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:B,children:B})}),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:(()=>y(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:(()=>G(d)),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(kt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>X(d.id)),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Ze,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),O.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ka,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&u&&Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:(()=>l(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(ke,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:m.name||"",onChange:(d=>j({...m,name:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:m.type||"text",onChange:(d=>j({...m,type:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(u==null?void 0:u.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),m.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:m.api_url||"",onChange:(d=>j({...m,api_url:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",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:m.data_content?m.data_content.split(`
|
||||
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),m.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:m.image_url||"",onChange:(d=>j({...m,image_url:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),m.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:m.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:(d=>{d.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:m.delay_seconds||0,onChange:(d=>j({...m,delay_seconds:parseInt(d.target.value)||0})),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:m.description||"",onChange:(d=>j({...m,description:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:(()=>j({...m,enabled:!m.enabled})),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${m.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${m.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:(()=>l(!1)),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:H,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(lt,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),n&&Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:(()=>c(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(ke,{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:x.name,onChange:(d=>p({...x,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:(()=>p({...x,type:"data",content:""})),className:`p-3 rounded-xl font-bold transition-all ${x.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(Os,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:(()=>p({...x,type:"text",content:""})),className:`p-3 rounded-xl font-bold transition-all ${x.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Ia,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:(()=>p({...x,type:"image",content:""})),className:`p-3 rounded-xl font-bold transition-all ${x.type==="image"?"bg-brand text-white":"bg-gray-100 textLine truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),x.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:x.content.split(`
|
||||
`).filter(d=>d.trim()).length})," 条"]})]}),x.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:x.api_method,onChange:(d=>p({...x,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:x.api_timeout,onChange:(d=>p({...x,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:x.api_headers,onChange:(d=>p({...x,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:x.api_params,onChange:(d=>p({...x,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:x.description,onChange:(d=>p({...x,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:x.delay_seconds,onChange:(d=>p({...x,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:(()=>c(!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:f,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(nt,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),e.jsx(ei,{dataCards:P,downloadCardTemplate:F,...A})]})},ma="ydisks-amap-js-api",ii="c9b68d4ce9a2a97f22a4a439404488ca";let Ot=null;const oi=()=>ii,ci=()=>window.AMap?Promise.resolve(window.AMap):Ot||(Ot=new Promise((t,s)=>{const a=document.getElementById(ma),l=a||document.createElement("script"),n=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(u)},c=()=>{window.AMap?(n(),t(window.AMap)):(n(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},u=window.setTimeout(()=>{n(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=c,l.id=ma,l.async=!0,l.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(oi())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,l.onerror=()=>{n(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(l)}).catch(t=>{throw Ot=null,t}),Ot),ts=t=>Number.isFinite(t)&&t!==0,di=t=>{var n,c;const s=Number((n=t.location)==null?void 0:n.lng),a=Number((c=t.location)==null?void 0:c.lat),l={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!l.division_id||!l.province||!l.city||!l.poi_id||!l.poi_name||!ts(s)||!ts(a)||s<-180||s>180||a<-90||a>90?null:l},xi=async(t,s)=>{if(!ts(t)||!ts(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await ci();return new Promise((l,n)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(u,h)=>{var j;if(u!=="complete"){if(u==="no_data"){l([]);return}n(new Error("高德地图附近地址查询失败,请稍后重试"));return}const m=(((j=h==null?void 0:h.poiList)==null?void 0:j.pois)||[]).map(di).filter(x=>x!==null);l(m)})})},mi=t=>t.find(s=>s.status==="running"||s.status==="canceling"),Rs=t=>t==="running"||t==="canceling",ui=t=>!!(t!
Line truncated
|
||||
`),Le=new Blob(["\uFEFF"+xe],{type:"text/csv;charset=utf-8"}),st=URL.createObjectURL(Le),Ke=document.createElement("a");Ke.href=st,Ke.download="批量铺货模板.csv",document.body.appendChild(Ke),Ke.click(),Ke.remove(),URL.revokeObjectURL(st)},E=()=>{D(o=>({...o,cookie_id:h||o.cookie_id})),G(!0)},se=()=>{W(o=>({...o,cookie_id:h||o.cookie_id})),X(!0)},ce=async o=>{if(!(o?h:C.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");y(!0),navigator.geolocation.getCurrentPosition(async xe=>{try{const Le=await xi(xe.coords.longitude,xe.coords.latitude);if(!Le.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");o?(Ue(Le),Me(Le[0])):(O(Le),d(Le[0]))}catch(Le){alert((Le==null?void 0:Le.message)||"获取发货地失败")}finally{y(!1)}},xe=>{y(!1),alert(xe.code===xe.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},fe=o=>l.filter(K=>K.cookie_id===o.cookie_id&&K.item_id===o.item_id).length>0?l.filter(K=>K.cookie_id===o.cookie_id&&K.item_id===o.item_id):l.filter(K=>K.cookie_id===o.cookie_id&&!K.item_id),De=r.useMemo(()=>new Map(c.map(o=>[o.id,o])),[c]),ve=r.useMemo(()=>j?s.filter(o=>o.cookie_id===j):s,[j,s]),Pe=o=>{const K=De.get(o),xe=(K==null?void 0:K.remark)||(K==null?void 0:K.nickname);return xe?`${xe} · ${o.slice(0,6)}`:`账号 ${o.slice(0,8)}`},me=o=>{const K=De.get(o);return(K==null?void 0:K.remark)||(K==null?void 0:K.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(Nr,{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:j,onChange:(o=>x(o.target.value)),children:[e.jsx("option",{value:"",children:"全部账号"}),c.map(o=>e.jsx("option",{value:o.id,children:Pe(o.id)},o.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(yt,{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:h,onChange:(o=>m(o.target.value)),children:[e.jsx("option",{value:"",children:"请选择账号"}),c.map(o=>e.jsx("option",{value:o.id,children:Pe(o.id)},o.id))]})]})]}),e.jsxs("button",{onClick:Ge,disabled:p||!h,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(We,{className:`w-4 h-4 ${p?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:E,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(nt,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:se,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(ls,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:(()=>void Be()),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(Wt,{className:"w-4 h-4"}),de&&["running","canceling"].includes(de.status)?"继续批量任务":"批量铺货"]}),de&&!["running","canceling"].includes(de.status)&&e.jsx("button",{onClick:(()=>void He()),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:[ve.map(o=>{const K=fe(o),xe=K.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative f
Line truncated
|
||||
@@ -0,0 +1,20 @@
|
||||
import{j as e,r,c as Is,b as Oe,d as ir}from"./react-vendor-C_od1ZSF.js";import{L as or,U as Na,M as ys,C as Os,B as va,S as _a,Z as js,a as Rt,b as Ps,G as Bs,c as Ts,d as Es,e as cr,f as wa,g as ut,A as Fs,D as dr,P as ka,h as Bt,E as Ca,T as xr,i as mr,j as _e,X as ke,k as ur,l as pr,m as Ds,n as Sa,o as lt,p as Ye,q as La,K as hr,r as bt,s as mt,Q as rs,t as yt,u as wt,v as $t,R as We,w as Ra,x as gr,y as Ze,z as St,F as Mt,H as nt,I as zs,J as kt,N as br,O as fr,V as yr,W as Aa,Y as Ia,_ as Oa,$ as jr,a0 as Nr,a1 as ls,a2 as Wt,a3 as Ns,a4 as vr,a5 as _r,a6 as vs,a7 as Us,a8 as wr,a9 as kr,aa as qt,ab as Ws,ac as Zt,ad as Pa,ae as Cr,af as Sr,ag as ss,ah as Ta,ai as Lr,aj as Rr,ak as Ar,al as Ir,am as Or,an as Pr,ao as Js}from"./icons-vendor-i_74xDZy.js";import{R as Yt,B as Tr,X as Gs,Y as Ks,T as Xt,a as Er,C as _s,A as Dr,b as $r,c as Mr,P as Vs,d as Qs,L as qr}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 n of document.querySelectorAll('link[rel="modulepreload"]'))l(n);new MutationObserver(n=>{for(const c of n)if(c.type==="childList")for(const u of c.addedNodes)u.tagName==="LINK"&&u.rel==="modulepreload"&&l(u)}).observe(document,{childList:!0,subtree:!0});function a(n){const c={};return n.integrity&&(c.integrity=n.integrity),n.referrerPolicy&&(c.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?c.credentials="include":n.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function l(n){if(n.ep)return;n.ep=!0;const c=a(n);fetch(n.href,c)}})();const Br=({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"})})}),ws=({sizeClass:t="w-12 h-12",logoClassName:s="w-full h-full text-white"})=>e.jsxs("div",{className:"relative z-10 flex items-center justify-center",children:[e.jsx("div",{className:"absolute -inset-1 bg-blue-500/20 rounded-xl blur opacity-25"}),e.jsxs("div",{className:`relative ${t} rounded-xl flex items-center justify-center group-hover:scale-105 transition-transform duration-300`,children:[e.jsxs("svg",{className:"absolute inset-0 w-full h-full",viewBox:"0 0 120 120","aria-hidden":"true",children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"login-squircle-gradient",x1:"0",y1:"0",x2:"1",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"rgb(var(--color-brand))"}),e.jsx("stop",{offset:"100%",stopColor:"rgb(var(--color-brand-light))"})]})}),e.jsx("path",{d:"M 114.00 60.00 L 113.83 71.48 L 113.31 78.16 L 112.44 83.67 L 111.22 88.46 L 109.66 92.71 L 107.75 96.49 L 105.48 99.87 L 102.86 102.86 L 99.87 105.48 L 96.49 107.75 L 92.71 109.66 L 88.46 111.22 L 83.67 112.44 L 78.16 113.31 L 71.48 113.83 L 60.00 114.00 L 48.52 113.83 L 41.84 113.31 L 36.33 112.44 L 31.54 111.22 L 27.29 109.66 L 23.51 107.75 L 20.13 105.48 L 17.14 102.86 L 14.52 99.87 L 12.25 96.49 L 10.34 92.71 L 8.78 88.46 L 7.56 83.67 L 6.69 78.16 L 6.17 71.48 L 6.00 60.00 L 6.17 48.52 L 6.69 41.84 L 7.56 36.33 L 8.78 31.54 L 10.34 27.29 L 12.25 23.51 L 14.52 20.13 L 17.14 17.14 L 20.13 14.52 L 23Line truncated
|
||||
|
||||
例如:回复时保持礼貌专业、使用简洁的语言、强调产品质量等`,className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none"})]}),e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl p-4",children:[e.jsxs("h4",{className:"font-bold text-blue-900 mb-2 flex items-center gap-2",children:[e.jsx(Ps,{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:g,className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",disabled:V,children:"取消"}),e.jsxs("button",{onClick:de,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",disabled:V,children:[V?e.jsx(_e,{className:"w-4 h-4 animate-spin"}):e.jsx(lt,{className:"w-4 h-4"}),V?"保存中...":"保存"]})]})})]})}),document.body)]})},Fn=[{key:"all",label:"全部"},{key:"processing",label:"处理中"},{key:"shipped",label:"已发货"},{key:"pending_ship",label:"待发货"},{key:"completed",label:"已完成"},{key:"cancelled",label:"已取消"},{key:"refunding",label:"退款中"}],zn=t=>{const s=typeof t=="object"&&t!==null?t:{},a=Array.isArray(s.results)?s.results:[];return{total:Number(s.total||0),success_count:Number(s.success_count||0),failed_count:Number(s.failed_count||0),results:a.map(Un)}},Un=t=>{const s=typeof t=="object"&&t!==null?t:{};return{order_id:String(s.order_id||"unknown"),success:s.success===!0,message:String(s.message||"")}},Wn=t=>(t==null?void 0:t.results.filter(Jn))||[],Jn=t=>!t.success,Gn=(t,s)=>t!==null&&!s,Kn=t=>{if(!t)return"请选择订单文件";const s=t.name.toLowerCase().split(".").pop()||"";return["xlsx","csv","tsv","json"].includes(s)?"":"仅支持 .xlsx、.csv、.tsv、.json 格式"},ft=(t,s)=>t===s,Vn=(t,s)=>t instanceof Error&&t.message?t.message:s,Qn=({filter:t,onFilterChange:s,accountFilter:a,onAccountFilterChange:l,accounts:n,accountName:c,searchText:u,onSearchChange:h})=>{const m=p=>s(p.currentTarget.dataset.status||"all"),j=p=>l(p.target.value),x=p=>h(p.target.value);return e.jsxs("div",{className:"p-4 border-b border-gray-50 flex flex-col md:flex-row gap-4 justify-between items-center bg-surface-muted",children:[e.jsx("div",{className:"flex gap-1 p-1 bg-gray-200/50 rounded-xl overflow-x-auto max-w-full",children:Fn.map(p=>e.jsx("button",{"data-status":p.key,onClick:m,className:`px-5 py-2 rounded-lg text-sm font-bold transition-all whitespace-nowrap ${t===p.key?"bg-white text-black shadow-sm":"text-gray-500 hover:text-gray-700"}`,children:p.label},p.key))}),e.jsxs("div",{className:"flex w-full md:w-auto flex-col sm:flex-row gap-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(yt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{"aria-label":"按账号筛选订单",value:a,onChange:j,className:"ios-input pl-10 pr-9 py-2.5 rounded-xl w-full sm:w-56 bg-white border-none shadow-sm",children:[e.jsx("option",{value:"",children:"全部账号"}),n.map(p=>e.jsx("option",{value:p.id,children:c(p.id)},p.id))]})]}),e.jsxs("div",{className:"relative group",children:[e.jsx(St,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 group-focus-within:text-brand transition-colors"}),e.jsx("input",{type:"text",placeholder:"搜索订单号/商品/买家...",value:u,onChange:x,className:"ios-input pl-10 pr-4 py-2.5 rounded-xl w-64 bg-white border-none shadow-sm focus:ring-0"})]})]})]})},Hn=t=>{const s=c=>{var u;t.setImportFile(((u=c.target.files)==null?void 0:u[0])||null)},a=()=>t.closeImportModal(),l=()=>void t.handleImportOrders(),n=()=>void t.handleRetryImport();return t.showImportModal?Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsx("div",{className:"modal-header",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"插入订单"}),e.jsx("button",{onClick:a,className:"p-2 bg-gray-100 rounded-full hover:bg-gray-200 transition-colors",children:e.jsx(ke,{className:"w-5 h-5 text-gray-600"})})]})}),e.jsxs("div",{className:"modal-body space-y-5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"选择Excel文件"}),e.jsx("input",{type:"file",accept:".xlsx,.csv,.tsv,.json",onChange:s,className:"w-full ios-input px-4 py-3 rounded-xl text-sm"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"支持 .xlsx
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:x,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:u,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:S,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(_e,{className:"w-4 h-4 animate-spin"}):e.jsx(Mt,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:q,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(_e,{className:"w-4 h-4 animate-spin"}):e.jsx(nt,{className:"w-4 h-4"}),a.batchBusy?"处理中...":"追加卡密"]})]})]})}),document.body):null},ti=({type:t})=>{switch(t){case"text":return e.jsx(Ia,{className:"w-5 h-5 text-blue-500"});case"image":return e.jsx(Aa,{className:"w-5 h-5 text-purple-500"});case"api":return e.jsx(yr,{className:"w-5 h-5 text-blue-500"});default:return e.jsx(Os,{className:"w-5 h-5 text-gray-500"})}},si=(t,s,a)=>{const l=a.trim().toLocaleLowerCase();return t.filter(n=>(!s||n.type===s)&&(!l||n.name.toLocaleLowerCase().includes(l)))},Qa=t=>t.split(`
|
||||
`).map(s=>s.trim()).filter(Boolean),ai=(t,s,a)=>!!(t&&Qa(s).length>0&&!a),vt=(t,s,a,l)=>t===s&&a===l,ri=()=>{const[t,s]=r.useState([]),[a,l]=r.useState(!0),n=r.useRef(0),c=r.useRef(null),u=r.useCallback(async()=>{var j;const h=++n.current;(j=c.current)==null||j.abort();const m=new AbortController;c.current=m,l(!0);try{const x=await Ms({signal:m.signal});if(h!==n.current)return;s(x)}catch(x){h===n.current&&!m.signal.aborted&&console.error("加载卡密库存失败:",x)}finally{h===n.current&&l(!1)}},[]);return r.useEffect(()=>(u(),()=>{var m;n.current+=1,(m=c.current)==null||m.abort()}),[u]),{cards:t,setCards:s,loading:a,loadCards:u}},li=t=>{const s=t.dataCards,a=t.loadCards,[l,n]=r.useState(!1),[c,u]=r.useState("create"),[h,m]=r.useState(null),[j,x]=r.useState(null),[p,_]=r.useState(!1),[S,q]=r.useState(""),[w,O]=r.useState(""),[P,G]=r.useState(null),[H,X]=r.useState(""),f=r.useRef(0),y=r.useRef(null),z=r.useRef(""),I=r.useMemo(()=>Qa(w),[w]),F=r.useCallback(()=>{var k;u("create"),m(null),x(null),q((k=s[0])!=null&&k.id?String(s[0].id):""),O(""),G(null),X(""),n(!0)},[s]),d=r.useCallback(()=>{var k;f.current+=1,(k=y.current)==null||k.abort(),_(!1),n(!1)},[]),B=r.useCallback(async()=>{var C;if(!h||p)return;const k=++f.current;(C=y.current)==null||C.abort();const D=new AbortController;y.current=D,_(!0),x(null);try{const W=await Ll(h,{signal:D.signal});if(!vt(k,f.current,"",""))return;x(W),W.created>0&&await a()}catch(W){if(!vt(k,f.current,"",""))return;x({error:(W==null?void 0:W.message)||"上传失败"})}finally{vt(k,f.current,"","")&&_(!1)}},[p,h,a]),Z=r.useCallback(async()=>{var W;if(!ai(S,w,p))return;const k=S,D=++f.current;z.current=k,(W=y.current)==null||W.abort();const C=new AbortController;y.current=C,_(!0),G(null),X("");try{const K=await Rl(k,w,{signal:C.signal});if(!vt(D,f.current,k,S))return;G({added:K.added}),O(""),await a()}catch(K){if(!vt(D,f.current,k,S))return;X((K==null?void 0:K.message)||"追加失败")}finally{vt(D,f.current,k,S)&&_(!1)}},[w,S,p,a]),M=r.useCallback(async()=>{await B()},[B]),b=r.useCallback(async()=>{z.current&&S!==z.current||await Z()},[S,Z]);return{showBatchModal:l,setShowBatchModal:n,batchTab:c,setBatchTab:u,batchFile:h,setBatchFile:m,batchResult:j,batchBusy:p,appendTargetId:S,setAppendTargetId:q,appendContent:w,setAppendContent:O,appendResult:P,appendError:H,appendPreview:I,openBatchModal:F,closeBatchModal:d,handleBatchCreate:B,handleBatchAppend:Z,handleRetryBatchCreate:M,handleRetryBatchAppend:b}},xa=()=>({name:"",type:"data",content:"",description:"",enabled:!0,delay_seconds:0,api_method:"GET",api_timeout:10,api_headers:"",api_params:""}),ni=()=>{const{cards:t,loadCards:s}=ri(),[a,l]=r.useState(!1),[n,c]=r.useState(!1),[u,h]=r.useState(null),[m,j]=r.useState({}),[x,p]=r.useState(xa),[_,S]=r.useState(""),[q,w]=r.useState(""),O=r.useMemo(()=>t.filter(d=>d.type==="data"),[t]),P=li({dataCards:O,loadCards:s}),G=d=>{var B,Z,M,b,k;h(d),j({id:d.id,name:d.name||"",type:d.type||"text",api_url:((B=d.api_config)==null?void 0:B.url)||"",api_method:((Z=d.api_config)==null?void 0:Z.method)||"GET",api_timeout:((M=d.api_config)==null?void 0:M.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}),l(!0)},H=async()=>{var d,B,Z,M,b,k,D,C;if(u){if(!((d=m.name)!=null&&d.trim())){alert("请输入卡密名称");return}if(!m.type){alert("请选择卡密类型");return}try{const W={name:m.name.trim(),type:m.type,description:(B=m.description)==null?void 0:B.trim(),delay_seconds:m.delay_seconds||0,enabled:m.enabled??!0};m.type==="api"?W.api_config={url:((Z=m.api_url)==null?void 0:Z.trim())||"",method:m.api_method,timeout:m.api_timeout||10,headers:((M=m.api_headers)==null?void 0:M.trim())||void 0,params:((b=m.api_params)==null?void 0:b.trim())||void 0}:m.type==="text"?W.text_content=((k=m.text_content)==null?void 0:k.trim())||"":m.type==="data"?W.data_content=((D=m.data_content)==null?void 0:D.trim())||"":m.type==="image"&&(W.image_url=((C=m.image_url)==null?void 0:C.trim())||""),await ta(u.id,W),l(!1),await s()}catch(W){console.error("更新卡密失败:",W),alert("更新失败,请重试")}}},X=async d=>{if(confirm("确认删除该卡密吗?"))try{await Sl(d),await s()}catch(B){console.error("删除卡密失败:",B),alert("删除失败,请重试")}},f=async()=>{if(!x.name.trim()){alert("请输入卡密名称");return}if(!x.content.trim()){alert(x.type==="api"?"请输入 API 地址":"请输入卡密内容");return}try{const d={name:x.name.trim(),type:x.type,description:x.description.trim(),enabled:x.enabled,delay_seconds:x.delay_seconds};x.type==="text"&&(d.text_content=x.content.trim()),x.type==="data"&&(d.data_content=x.content.trim()),x.type==="image"&&(d.image_url=x.content.trim()),x.type==="api"&&(d.api_config={url:x.content.trim(),method:x.api_me
Line truncated
|
||||
VIP-MONTH-002
|
||||
VIP-MONTH-003`,"按行消费的卡密队列","是","0","否","",""],["感谢文案","text","感谢购买,如有问题联系客服~","固定文本","是","0","否","",""],["教程图","image","https://cdn.example.com/tutorial.jpg","图片URL","是","0","否","",""]]].map(D=>D.map(C=>`"${String(C).replace(/"/g,'""')}"`).join(",")).join(`
|
||||
`),M=new Blob(["\uFEFF"+Z],{type:"text/csv;charset=utf-8"}),b=URL.createObjectURL(M),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:P.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(Mt,{className:"w-5 h-5"}),"批量导入"]}),e.jsxs("button",{onClick:(()=>c(!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(nt,{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(Oa,{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:_,onChange:(d=>S(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(St,{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=>w(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:["显示 ",I.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:I.map(d=>{let B="";return d.type==="data"&&d.data_content?B=`库存: ${d.data_content.split(`
|
||||
`).filter(M=>M.trim()).length} 条`:d.type==="text"&&d.text_content?B=d.text_content:d.type==="api"&&d.api_config?B=d.api_config.url:d.type==="image"&&d.image_url&&(B="图片链接"),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(ti,{type:d.type})}),e.jsx("span",{className:"line-clamp-3 min-w-0 text-[13px] font-bold leading-5 text-gray-900",title:d.name,children:d.name})]})}),e.jsx("td",{className:"px-3 py-5",children:e.jsxs("button",{onClick:(()=>z(d.id)),className:"inline-flex max-w-full items-center gap-1 rounded-lg bg-gray-100 px-2 py-1.5 font-mono text-[11px] font-extrabold text-gray-700 transition-colors hover:bg-gray-200",title:"复制卡密组ID,用于批量铺货表格",children:[e.jsx("span",{className:"truncate",children:d.id}),e.jsx(jr,{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:B,children:B})}),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:(()=>y(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:(()=>G(d)),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-gray-100 hover:text-black",title:"编辑",children:e.jsx(kt,{className:"w-4 h-4"})}),e.jsx("button",{onClick:(()=>X(d.id)),className:"rounded-lg p-1.5 text-gray-400 transition-colors hover:bg-red-50 hover:text-red-500",children:e.jsx(Ze,{className:"h-4 w-4"})})]})})]},d.id)})})]})}),I.length===0&&e.jsxs("div",{className:"py-20 text-center text-gray-400",children:[e.jsx(ka,{className:"w-12 h-12 mx-auto mb-4 opacity-30"}),e.jsx("p",{children:t.length===0?"暂无卡密配置,请点击右上角添加。":"没有符合当前筛选条件的卡密组。"})]})]}),a&&u&&Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"编辑卡密"}),e.jsx("button",{onClick:(()=>l(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors",children:e.jsx(ke,{className:"w-5 h-5 text-gray-500"})})]}),e.jsx("div",{className:"modal-body",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:["卡密名称 ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsx("input",{type:"text",value:m.name||"",onChange:(d=>j({...m,name:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",placeholder:"例如:游戏点卡、会员卡等"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"卡券类型"}),e.jsxs("select",{value:m.type||"text",onChange:(d=>j({...m,type:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"",children:"请选择类型"}),e.jsx("option",{value:"text",children:"固定文字"}),e.jsx("option",{value:"data",children:"批量数据"}),(u==null?void 0:u.type)==="api"&&e.jsx("option",{value:"api",children:"API接口(仅保留现有配置)"}),e.jsx("option",{value:"image",children:"图片"})]})]})]}),m.type==="api"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 space-y-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900",children:"API 配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"API 地址"}),e.jsx("input",{type:"url",value:m.api_url||"",onChange:(d=>j({...m,api_url:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://api.example.com/get-card"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",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:m.data_content?m.data_content.split(`
|
||||
`).filter(d=>d.trim()).length:0})," 条"]})]})]}),m.type==="image"&&e.jsxs("div",{className:"border border-gray-200 rounded-xl p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-bold text-gray-900 mb-3",children:"图片配置"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片 URL"}),e.jsx("input",{type:"url",value:m.image_url||"",onChange:(d=>j({...m,image_url:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl font-mono text-sm",placeholder:"https://example.com/image.png"}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:"输入图片卡密的 URL 地址"})]}),m.image_url&&e.jsxs("div",{className:"mt-3",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"图片预览"}),e.jsx("img",{src:m.image_url,alt:"预览",className:"max-w-full max-h-48 rounded-xl border border-gray-200",onError:(d=>{d.currentTarget.src="https://via.placeholder.com/400x200?text=图片加载失败"})})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"延时发货时间(秒)"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"number",value:m.delay_seconds||0,onChange:(d=>j({...m,delay_seconds:parseInt(d.target.value)||0})),className:"flex-1 ios-input px-4 py-3 rounded-xl",min:"0",max:"3600",placeholder:"0"}),e.jsx("span",{className:"text-sm text-gray-500 whitespace-nowrap",children:"秒"})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-1",children:"0表示立即发货,最大3600秒(1小时)"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700 mb-2",children:"备注信息"}),e.jsx("textarea",{value:m.description||"",onChange:(d=>j({...m,description:d.target.value})),className:"w-full ios-input px-4 py-3 rounded-xl h-40 resize-none",placeholder:"可选的备注信息"})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 bg-gray-50 rounded-xl",children:[e.jsx("span",{className:"font-bold text-gray-900",children:"启用状态"}),e.jsx("button",{type:"button",onClick:(()=>j({...m,enabled:!m.enabled})),className:`w-14 h-8 rounded-full transition-colors duration-300 relative ${m.enabled?"bg-brand":"bg-gray-300"}`,children:e.jsx("span",{className:`absolute top-1 w-6 h-6 bg-white rounded-full shadow-md transition-transform duration-300 block ${m.enabled?"translate-x-7":"translate-x-1"}`})})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:(()=>l(!1)),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:H,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(lt,{className:"w-4 h-4"}),"保存更改"]})]})})]})}),document.body),n&&Oe.createPortal(e.jsx("div",{className:"modal-overlay-centered",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"780px"},children:[e.jsxs("div",{className:"modal-header flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-2xl font-extrabold text-gray-900",children:"添加新卡密"}),e.jsx("p",{className:"text-sm text-gray-500 mt-1",children:"选择交付方式并录入自动发货内容"})]}),e.jsx("button",{onClick:(()=>c(!1)),className:"p-2 rounded-xl hover:bg-gray-100 transition-colors flex-shrink-0",title:"关闭",children:e.jsx(ke,{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:x.name,onChange:(d=>p({...x,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:(()=>p({...x,type:"data",content:""})),className:`p-3 rounded-xl font-bold transition-all ${x.type==="data"?"bg-brand text-white":"bg-gray-100 text-gray-600 hover:bg-gray-200"}`,children:[e.jsx(Os,{className:"w-5 h-5 mx-auto mb-1"}),"批量库存"]}),e.jsxs("button",{type:"button",onClick:(()=>p({...x,type:"text",content:""})),className:`p-3 rounded-xl font-bold transition-all ${x.type==="text"?"bg-brand text-white":"bg-gray-100 text-gray-600"}`,children:[e.jsx(Ia,{className:"w-5 h-5 mx-auto mb-1"}),"文本"]}),e.jsxs("button",{type:"button",onClick:(()=>p({...x,type:"image",content:""})),className:`p-3 rounded-xl font-bold transition-all ${x.type==="image"?"bg-brand text-white":"bg-gray-100 textLine truncated
|
||||
CODE-789012
|
||||
...`:"请输入每次发货时发送的固定文字"}),x.type==="data"&&e.jsxs("p",{className:"text-xs text-gray-500",children:["当前库存:",e.jsx("span",{className:"font-bold text-brand",children:x.content.split(`
|
||||
`).filter(d=>d.trim()).length})," 条"]})]}),x.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:x.api_method,onChange:(d=>p({...x,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:x.api_timeout,onChange:(d=>p({...x,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:x.api_headers,onChange:(d=>p({...x,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:x.api_params,onChange:(d=>p({...x,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:x.description,onChange:(d=>p({...x,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:x.delay_seconds,onChange:(d=>p({...x,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:(()=>c(!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:f,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(nt,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),e.jsx(ei,{dataCards:O,downloadCardTemplate:F,...P})]})},ma="ydisks-amap-js-api",ii="c9b68d4ce9a2a97f22a4a439404488ca";let Ot=null;const oi=()=>ii,ci=()=>window.AMap?Promise.resolve(window.AMap):Ot||(Ot=new Promise((t,s)=>{const a=document.getElementById(ma),l=a||document.createElement("script"),n=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(u)},c=()=>{window.AMap?(n(),t(window.AMap)):(n(),s(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},u=window.setTimeout(()=>{n(),s(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=c,l.id=ma,l.async=!0,l.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(oi())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,l.onerror=()=>{n(),s(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},a||document.head.appendChild(l)}).catch(t=>{throw Ot=null,t}),Ot),ts=t=>Number.isFinite(t)&&t!==0,di=t=>{var n,c;const s=Number((n=t.location)==null?void 0:n.lng),a=Number((c=t.location)==null?void 0:c.lat),l={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!l.division_id||!l.province||!l.city||!l.poi_id||!l.poi_name||!ts(s)||!ts(a)||s<-180||s>180||a<-90||a>90?null:l},xi=async(t,s)=>{if(!ts(t)||!ts(s)||t<-180||t>180||s<-90||s>90)throw new Error("经纬度无效");const a=await ci();return new Promise((l,n)=>{new a.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,s],1e3,(u,h)=>{var j;if(u!=="complete"){if(u==="no_data"){l([]);return}n(new Error("高德地图附近地址查询失败,请稍后重试"));return}const m=(((j=h==null?void 0:h.poiList)==null?void 0:j.pois)||[]).map(di).filter(x=>x!==null);l(m)})})},mi=t=>t.find(s=>s.status==="running"||s.status==="canceling"),Rs=t=>t==="running"||t==="canceling",ui=t=>!!(t!
Line truncated
|
||||
`),Le=new Blob(["\uFEFF"+xe],{type:"text/csv;charset=utf-8"}),st=URL.createObjectURL(Le),Qe=document.createElement("a");Qe.href=st,Qe.download="批量铺货模板.csv",document.body.appendChild(Qe),Qe.click(),Qe.remove(),URL.revokeObjectURL(st)},E=()=>{D(o=>({...o,cookie_id:h||o.cookie_id})),G(!0)},ae=()=>{W(o=>({...o,cookie_id:h||o.cookie_id})),X(!0)},ce=async o=>{if(!(o?h:C.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");y(!0),navigator.geolocation.getCurrentPosition(async xe=>{try{const Le=await xi(xe.coords.longitude,xe.coords.latitude);if(!Le.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");o?(Ue(Le),Me(Le[0])):(I(Le),d(Le[0]))}catch(Le){alert((Le==null?void 0:Le.message)||"获取发货地失败")}finally{y(!1)}},xe=>{y(!1),alert(xe.code===xe.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},fe=o=>l.filter(Q=>Q.cookie_id===o.cookie_id&&Q.item_id===o.item_id).length>0?l.filter(Q=>Q.cookie_id===o.cookie_id&&Q.item_id===o.item_id):l.filter(Q=>Q.cookie_id===o.cookie_id&&!Q.item_id),De=r.useMemo(()=>new Map(c.map(o=>[o.id,o])),[c]),ve=r.useMemo(()=>j?s.filter(o=>o.cookie_id===j):s,[j,s]),Pe=o=>{const Q=De.get(o),xe=(Q==null?void 0:Q.remark)||(Q==null?void 0:Q.nickname);return xe?`${xe} · ${o.slice(0,6)}`:`账号 ${o.slice(0,8)}`},me=o=>{const Q=De.get(o);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(Nr,{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:j,onChange:(o=>x(o.target.value)),children:[e.jsx("option",{value:"",children:"全部账号"}),c.map(o=>e.jsx("option",{value:o.id,children:Pe(o.id)},o.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(yt,{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:h,onChange:(o=>m(o.target.value)),children:[e.jsx("option",{value:"",children:"请选择账号"}),c.map(o=>e.jsx("option",{value:o.id,children:Pe(o.id)},o.id))]})]})]}),e.jsxs("button",{onClick:Ge,disabled:p||!h,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(We,{className:`w-4 h-4 ${p?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:E,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(nt,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:ae,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(ls,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:(()=>void Be()),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(Wt,{className:"w-4 h-4"}),de&&["running","canceling"].includes(de.status)?"继续批量任务":"批量铺货"]}),de&&!["running","canceling"].includes(de.status)&&e.jsx("button",{onClick:(()=>void He()),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:[ve.map(o=>{const Q=fe(o),xe=Q.length>0;return e.jsxs("div",{className:"ios-card p-3 rounded-2xl hover:shadow-lg transition-all group relative f
Line truncated
|
||||
@@ -6,7 +6,7 @@
|
||||
<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-B1zvnIP1.js"></script>
|
||||
<script type="module" crossorigin src="/static/assets/index-CXhOC0DI.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-C_od1ZSF.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-i_74xDZy.js">
|
||||
<link rel="modulepreload" crossorigin href="/static/assets/vendor-D-Edl3pr.js">
|
||||
|
||||
Reference in new issue
Block a user