API版本化:完成旧调用方最终审计

This commit is contained in:
Christ committed 2026-08-14 18:49:24 +08:00
1 parent 8d103b1cc0
commit 1e6b0593b3
10 files changed
+31 -127

No files matched your search

-12
View File
@@ -16469,18 +16469,6 @@
"kind": "member",
"name": "unread_count"
},
{
"file": "vite.config.ts",
"line": 135,
"kind": "member",
"name": "manualChunks"
},
{
"file": "vite.config.ts",
"line": 136,
"kind": "variable",
"name": "modulePath"
},
{
"file": "viteConfig.test.ts",
"line": 5,
@@ -8,7 +8,7 @@
| --- | --- | --- | --- |
| 会话 | `/login`、`/initialize`、`/verify`、`/logout`、`/change-password`、`/account/credentials` | `/api/v1/session/login`、`/api/v1/session/initialize`、`/api/v1/session`、`/api/v1/session/logout`、`/api/v1/session/password`、`/api/v1/session/credentials` | React 会话、密码修改和登录凭证调用已迁移到版本化入口;旧路径保留并由同一 handler 提供 |
| 账号 | `/cookies`、`/cookies/details`、`/cookies/runtime-status`、`/cookies/{cid}/...` | `/api/v1/accounts`、`/api/v1/accounts/details`、`/api/v1/accounts/runtime-status`、`/api/v1/accounts/{cid}/...` | React 摘要、详情、运行状态、启停状态、设置、备注、暂停、自动确认、长登录、资料刷新、Cookie 更新、登录信息设置和删除调用已迁移;旧路径保留并由同一 handler 提供 |
| 商品 | `/items...` | `/api/v1/items...` | React 列表、详情、创建、发布、更新、删除、同步、类目推荐和批量发布调用已迁移;旧路径保留并由同一 handler 提供 |
| 商品 | `/items...` | `/api/v1/items...` | React 列表、按账号列表、详情、创建、发布、更新、删除、多规格/多数量设置、同步、类目推荐和批量发布调用已迁移;旧路径保留并由同一 handler 提供 |
| 商品批量 | `/items/publish-batches...` | `/api/v1/items/publish-batches...` | 旧路径保留,类目推荐/预检/任务 DTO 已落地 |
| 自动化 | `/automation-rules...`、`/automation-issues`、`/automation-runs...`、`/automation-pending-tasks...` | `/api/v1/automation-rules...`、`/api/v1/automation-issues`、`/api/v1/automation-runs...`、`/api/v1/automation-pending-tasks...` | React 规则分页、增删改、异常查询和异常处理调用已迁移;旧路径保留并由同一 handler 提供 |
| 订单 | `/api/orders...` | `/api/v1/orders...` | React 列表、详情、更新、删除、刷新、单订单刷新、手动发货和导入调用已迁移;旧路径保留并由同一 handler 提供 |
@@ -48,7 +48,7 @@
- 账号摘要、非敏感详情、运行状态、启停状态、设置、备注、暂停、自动确认、长登录、资料刷新、Cookie 更新和登录信息设置已由 React 请求层迁移到 `/api/v1/accounts...`;Go 契约测试确认账号详情与凭证变更响应不泄露 Cookie/密码,且旧详情、设置和登录信息入口仍可用。
- 订单列表、详情和更新已由 React 请求层迁移到 `/api/v1/orders...`;Go 契约测试确认版本化入口与旧更新入口共用 handler,订单归属校验和状态更新语义保持不变。
- 订单刷新、单订单刷新、手动发货和导入已由 React 请求层迁移到 `/api/v1/orders...`;Go 契约测试确认新旧批量入口保持状态码、具名响应和参数校验语义一致。
- 商品列表、详情、发布、更新和删除已由 React 请求层迁移到 `/api/v1/items...`;Go 契约测试确认新旧入口保持商品所有权校验、具名响应和持久化语义一致。
- 商品列表、按账号列表、详情、创建、发布、更新、删除、多规格/多数量设置已由版本化路由提供,React 请求层已迁移实际调用;Go 契约测试确认新旧入口保持商品所有权校验、具名响应和持久化语义一致。
- 商品同步、类目推荐、批量发布预检、任务查询、取消、重试和结果下载已由版本化路由提供;React 现有同步/批量发布调用已迁移,Go 契约测试确认新旧入口状态码和参数校验语义一致。
- 系统/用户/AI 设置、卡券 CRUD/批量/追加和通知渠道/消息/账号绑定已由版本化路由提供;React 设置、卡券和通知调用已迁移,Go 契约测试确认新旧入口权限、状态码和参数校验语义一致。
- 聊天会话、消息、图片、已读和 WebSocket,以及账号任务设置、运行记录和执行已由版本化路由提供;React REST/WebSocket 调用已迁移,Go 契约测试确认新旧入口权限、状态码和参数校验语义一致。
@@ -59,3 +59,4 @@
- 聊天会话、消息分页和发送结果使用独立 DTO,不直接暴露数据库模型。
- React `frontend/types.ts` 与 `frontend/services/api.ts` 已同步具名成功响应类型,同时保留旧字段归一逻辑。
- 会话、账号、订单、商品、自动化、设置、卡券、通知、聊天、账号任务、关键词、默认回复、管理员、统计、二维码登录和密码登录版本化入口已可用;旧路径继续保留。
- 最终调用方审计确认 React 生产请求、批量结果下载和 Vite 开发代理均不再使用业务旧路径;旧路径仅作为服务端兼容入口保留,后续删除必须遵循调用方、发布日期和回滚条件记录。
+6 -4
View File
@@ -92,8 +92,8 @@ app shell / routes
| 0. 治理文档与强约束 | 已完成 | 总计划、依赖规则、注释规范、AGENTS 门禁、注释检查器 | 文档、门禁规则、Go/TypeScript 检查器和历史基线已落盘 |
| 1. PR CI 与测试基础 | 已完成 | 独立 CI、测试 DB 模板、可执行 race | CI、独立模板、server smoke race 和完整 race 均有验证 |
| 2. 敏感数据访问边界 | 已完成 | 摘要、凭证、登录秘密分离 | 生产完整详情白名单、所有权/凭证锁审计、SQLite/MySQL/Postgres 窄查询回归和全量门禁已完成 |
| 3. HTTP API 契约 | 进行中 | 统一错误、具名 DTO、版本化路径 | 统一错误 DTO、认证/公共 API 错误迁移及契约测试已完成;继续迁移业务 API |
| 4. Server 应用服务 | 未开始 | 订单、发布、登录、聊天纵向抽取 | handler 不再直接编排基础设施 |
| 3. HTTP API 契约 | 已完成 | 统一错误、具名 DTO、版本化路径 | 统一错误 DTO、具名成功 DTO、所有前端业务调用方版本化、旧路径兼容和最终审计均已完成 |
| 4. Server 应用服务 | 进行中 | 订单、发布、登录、聊天纵向抽取 | 订单应用服务切片开始,目标是让 handler 不再直接编排基础设施 |
| 5. 应用生命周期装配 | 未开始 | 消除必需依赖 setter 回填 | 构造验证与幂等关闭测试 |
| 6. Engine 与 Automation | 未开始 | facade + 独立状态组件 | race、生命周期与冻结规范测试 |
| 7. React Feature 化 | 未开始 | 页面、Hook、API、类型按领域拆分 | 行为测试、懒加载和 bundle 记录 |
@@ -103,7 +103,7 @@ app shell / routes
### 当前执行入口
- 当前阶段:阶段 3“HTTP API 契约”(进行中);
- 当前阶段:阶段 4“Server 应用服务”(进行中);阶段 3 HTTP API 契约已完成最终审计;
- 已完成:总计划、依赖规则、中文注释规范、`AGENTS.md` 强约束,以及 Go/TypeScript AST 注释检查器和历史基线;
- 阶段 1 已完成:server 测试模板预置管理员和账号 cookie,普通测试约 21.3 秒,完整 server race 约 194.3 秒通过;
- 已完成阶段 2 逻辑切片一“Repository 敏感数据边界”:建立 `CookieSummary`、`ListOwnedIDs`、`ExistsOwned`、`GetOwnerID`、`GetSummaryOwned` 和原子 `GetValueOwned`,覆盖跨用户、无效 user ID 及无效密文回归;
@@ -152,7 +152,8 @@ app shell / routes
- 已完成阶段 3 第二十三个 PR 切片“管理员、仪表盘与订单分析 API 版本化兼容入口迁移”:新增管理员用户/账号/统计、仪表盘统计、订单分析和有效订单 `/api/v1/admin...`、`/api/v1/analytics...` 薄适配入口,复用既有管理员权限与统计 handler;React 管理员统计、仪表盘和订单分析调用已迁移,旧路径保留;新增管理员/统计契约测试并保持独立可回滚提交;
- 已完成阶段 3 第二十四个 PR 切片“二维码登录 API 版本化兼容入口迁移”:新增二维码生成、状态查询、状态持久化和验证完成 `/api/v1/qr-login...` 薄适配入口,复用既有认证、会话所有权和敏感字段过滤 handler;React 二维码生成、轮询和验证完成调用已迁移,旧路径保留;新增二维码新旧入口契约测试并保持独立可回滚提交;
- 已完成阶段 3 第二十五个 PR 切片“密码登录及剩余公共调用方 API 版本化兼容入口迁移”:新增会话密码/凭证、账号删除、密码登录禁用、自动化规则/异常处理、订单删除和商品创建 `/api/v1/...` 薄适配入口,复用既有认证、权限和业务 handler;React 对应调用已迁移,旧路径保留;新增剩余公共调用方 Go/React 契约测试并保持独立可回滚提交;
- 阶段 3 下一 PR 切片为“版本化入口最终审计与旧调用方清零”:扫描前端、Vite 代理、服务端路由和测试中的业务旧路径,补齐必要的版本化兼容入口与调用方迁移证据,确认阶段 3 完成条件后再进入阶段 4,不拆分单个 handler 提交;
- 已完成阶段 3 第二十六个 PR 切片“版本化入口最终审计与旧调用方清零”:前端生产调用和批量结果下载已无业务旧路径;Vite 代理收敛为 `/api` 与健康检查;服务端剩余商品兼容入口已补齐;新增旧代理别名和商品遗漏入口审计证据,阶段 3 完成条件满足并保持独立可回滚提交;
- 阶段 4 下一 PR 切片为“订单应用服务边界提取”:围绕订单列表、详情、更新、删除、刷新、导入和手动发货提取不依赖 `net/http` 的应用服务,保留 DTO/权限契约和事务不变量,不拆分单个 handler 提交;
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
## 6. 阶段 0:治理文档与强约束
@@ -554,3 +555,4 @@ npm --prefix frontend run build
| 2026-08-14 | 完成阶段 3 第二十三个 PR 切片“管理员、仪表盘与订单分析 API 版本化兼容入口迁移” | 新增管理员用户/账号/统计、仪表盘统计、订单分析和有效订单 `/api/v1/admin...`、`/api/v1/analytics...` 薄适配入口,复用既有权限边界与 handler;React 管理员统计、仪表盘和订单分析调用已迁移;Go/React 契约测试确认新旧入口兼容;全量门禁通过并合并为一个可回滚提交 | 阶段 3:二维码登录 API 版本化兼容入口迁移 |
| 2026-08-14 | 完成阶段 3 第二十四个 PR 切片“二维码登录 API 版本化兼容入口迁移” | 新增二维码生成、状态查询、状态持久化和验证完成 `/api/v1/qr-login...` 薄适配入口,复用既有认证、会话所有权和敏感字段过滤 handler;React 二维码生成、轮询和验证完成调用已迁移;Go/React 契约测试确认新旧入口兼容;全量门禁通过并合并为一个可回滚提交 | 阶段 3:密码登录及剩余公共调用方 API 版本化兼容入口迁移 |
| 2026-08-14 | 完成阶段 3 第二十五个 PR 切片“密码登录及剩余公共调用方 API 版本化兼容入口迁移” | 新增会话密码/凭证、账号删除、密码登录禁用、自动化规则/异常处理、订单删除和商品创建 `/api/v1/...` 薄适配入口,复用既有认证、权限和业务 handler;React 对应调用已迁移;Go/React 契约测试确认新旧入口兼容;全量门禁通过并合并为一个可回滚提交 | 阶段 3:版本化入口最终审计与旧调用方清零 |
| 2026-08-14 | 完成阶段 3 第二十六个 PR 切片“版本化入口最终审计与旧调用方清零” | 前端生产调用和批量结果下载已无业务旧路径;Vite 代理收敛为 `/api` 与健康检查;服务端补齐商品按账号列表、多规格和多数量兼容入口;Go/React/Vite 审计测试、全量测试、race、vet、lint、注释和构建门禁通过并合并为一个可回滚提交 | 阶段 4:订单应用服务边界提取 |
+1 -1
View File
@@ -1320,7 +1320,7 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
正在保存远端结果并安全取消…
</button>
) : (
<button onClick={() => window.open(`/items/publish-batches/${batchDetail.id}/result.csv`, '_blank')} className="flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold">
<button onClick={() => window.open(`/api/v1/items/publish-batches/${batchDetail.id}/result.csv`, '_blank')} className="flex-1 px-6 py-3.5 rounded-xl bg-gray-900 text-white hover:bg-black font-bold">
下载结果
</button>
)}
+2 -101
View File
@@ -14,107 +14,6 @@ export default defineConfig({
changeOrigin: true,
ws: true,
},
// 代理其他后端请求
'/cookies': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/account': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/qr-login': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/password-login': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/keywords': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/keywords-with-item-id': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/default-reply': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/items': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/cards': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/automation-rules': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/automation-issues': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/automation-runs': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/automation-pending-tasks': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/notification-channels': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/message-notifications': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/ai-reply-settings': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/ai-models': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/system-settings': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/user-settings': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/admin': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/analytics': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/login': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/verify': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/logout': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/change-password': {
target: 'http://localhost:59188',
changeOrigin: true,
},
'/health': {
target: 'http://localhost:59188',
changeOrigin: true,
@@ -132,7 +31,9 @@ export default defineConfig({
sourcemap: false,
rollupOptions: {
output: {
// manualChunks 按依赖领域拆分生产构建文件,控制首屏资源体积。
manualChunks(id) {
// modulePath 是统一分隔符后的模块绝对路径,用于稳定匹配依赖目录。
const modulePath = id.split(path.sep).join('/');
if (!modulePath.includes('/node_modules/')) {
return undefined;
+11 -5
View File
@@ -2,11 +2,17 @@ import { expect, test } from 'vitest';
import type { UserConfig } from 'vite';
import config from './vite.config';
test('development server proxies every automation API prefix', () => {
test('development server proxies versioned API and health checks', () => {
const proxy = (config as UserConfig).server?.proxy;
expect(proxy).toBeDefined();
expect(proxy).toHaveProperty('/automation-rules');
expect(proxy).toHaveProperty('/automation-issues');
expect(proxy).toHaveProperty('/automation-runs');
expect(proxy).toHaveProperty('/automation-pending-tasks');
expect(proxy).toHaveProperty('/api');
expect(proxy).toHaveProperty('/health');
expect(proxy).not.toHaveProperty('/automation-rules');
expect(proxy).not.toHaveProperty('/automation-issues');
expect(proxy).not.toHaveProperty('/automation-runs');
expect(proxy).not.toHaveProperty('/automation-pending-tasks');
expect(proxy).not.toHaveProperty('/password-login');
expect(proxy).not.toHaveProperty('/qr-login');
expect(proxy).not.toHaveProperty('/items');
expect(proxy).not.toHaveProperty('/cookies');
});
+3
View File
@@ -12,10 +12,13 @@ func (s *Server) mountVersionedItems(r chi.Router) {
r.Use(s.Auth.Middleware)
r.Use(auth.RequireAuth)
r.Get("/api/v1/items", s.listItems)
r.Get("/api/v1/items/cookie/{cookie_id}", s.listItemsByCookie)
r.Get("/api/v1/items/{cookie_id}/{item_id}", s.getItem)
r.Post("/api/v1/items/{cookie_id}", s.createItem)
r.Post("/api/v1/items/publish", s.publishItem)
r.Put("/api/v1/items/{cookie_id}/{item_id}", s.updateItem)
r.Delete("/api/v1/items/{cookie_id}/{item_id}", s.deleteItem)
r.Put("/api/v1/items/{cookie_id}/{item_id}/multi-spec", s.setItemMultiSpec)
r.Put("/api/v1/items/{cookie_id}/{item_id}/multi-quantity-delivery", s.setItemMultiQuantity)
})
}
@@ -59,6 +59,9 @@ func TestVersionedRemainingRoutesPreserveLegacyContracts(t *testing.T) {
{name: "automation-task-resolve", method: http.MethodPost, versionedPath: "/api/v1/automation-pending-tasks/invalid/resolve", legacyPath: "/automation-pending-tasks/invalid/resolve", body: `{}`, wantStatus: http.StatusBadRequest},
{name: "delete-order", method: http.MethodDelete, versionedPath: "/api/v1/orders/missing-order", legacyPath: "/api/orders/missing-order", wantStatus: http.StatusNotFound},
{name: "create-item", method: http.MethodPost, versionedPath: "/api/v1/items/missing-account", legacyPath: "/items/missing-account", body: `{}`, wantStatus: http.StatusNotFound},
{name: "list-items-by-cookie", method: http.MethodGet, versionedPath: "/api/v1/items/cookie/missing-account", legacyPath: "/items/cookie/missing-account", wantStatus: http.StatusNotFound},
{name: "set-item-multi-spec", method: http.MethodPut, versionedPath: "/api/v1/items/missing-account/item/multi-spec", legacyPath: "/items/missing-account/item/multi-spec", body: `{}`, wantStatus: http.StatusNotFound},
{name: "set-item-multi-quantity", method: http.MethodPut, versionedPath: "/api/v1/items/missing-account/item/multi-quantity-delivery", legacyPath: "/items/missing-account/item/multi-quantity-delivery", body: `{}`, wantStatus: http.StatusNotFound},
}
for _, routeCase := range cases { // routeCase 是当前正在执行的剩余公共路由样例。
// versionedStatus 是版本化入口实际返回的状态码。
@@ -16,4 +16,4 @@ CODE-789012
`).filter(x=>x.trim()).length})," 条"]})]}),j.type==="api"&&e.jsxs("div",{className:"border-t border-gray-100 pt-5 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求方法"}),e.jsxs("select",{value:j.api_method,onChange:x=>F({...j,api_method:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl",children:[e.jsx("option",{value:"GET",children:"GET"}),e.jsx("option",{value:"POST",children:"POST"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"超时时间(秒)"}),e.jsx("input",{type:"number",min:"1",max:"60",value:j.api_timeout,onChange:x=>F({...j,api_timeout:parseInt(x.target.value)||10}),className:"w-full ios-input px-4 py-3 rounded-xl"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求头(JSON)"}),e.jsx("textarea",{value:j.api_headers,onChange:x=>F({...j,api_headers:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"Authorization":"Bearer token"}'})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"请求参数(JSON)"}),e.jsx("textarea",{value:j.api_params,onChange:x=>F({...j,api_params:x.target.value}),className:"w-full ios-input px-4 py-3 rounded-xl h-24 resize-none font-mono text-xs",placeholder:'{"order_id":"{order_id}"}'})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_180px] gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"描述"}),e.jsx("input",{value:j.description,onChange:x=>F({...j,description:x.target.value}),placeholder:"卡密用途描述(可选)",className:"w-full ios-input px-4 py-3 rounded-xl"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"block text-sm font-bold text-gray-700",children:"延时发货(秒)"}),e.jsx("input",{type:"number",value:j.delay_seconds,onChange:x=>F({...j,delay_seconds:parseInt(x.target.value)||0}),className:"w-full ios-input px-4 py-3 rounded-xl",min:"0",max:"3600"})]})]})]})}),e.jsx("div",{className:"modal-footer",children:e.jsxs("div",{className:"flex gap-3 w-full",children:[e.jsx("button",{onClick:()=>_(!1),className:"flex-1 px-6 py-3 rounded-xl font-bold bg-gray-100 text-gray-700 hover:bg-gray-200 transition-colors",children:"取消"}),e.jsxs("button",{onClick:p,className:"flex-1 ios-btn-primary px-6 py-3 rounded-xl font-bold flex items-center justify-center gap-2",children:[e.jsx(et,{className:"w-4 h-4"}),"添加卡密"]})]})})]})}),document.body),G&&qe.createPortal(e.jsx("div",{className:"modal-overlay",children:e.jsxs("div",{className:"modal-container",style:{maxWidth:"40rem"},children:[e.jsxs("div",{className:"px-6 py-5 border-b border-gray-100 flex items-center justify-between",children:[e.jsx("h3",{className:"text-xl font-extrabold text-gray-900",children:"批量导入卡密"}),e.jsx("button",{onClick:()=>me(!1),className:"w-10 h-10 rounded-2xl bg-gray-100 hover:bg-gray-200 flex items-center justify-center",children:e.jsx(Me,{className:"w-5 h-5 text-gray-600"})})]}),e.jsxs("div",{className:"px-6 py-5 space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap gap-2 p-2 bg-gray-100/50 rounded-2xl",children:[e.jsxs("button",{onClick:()=>v("create"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${oe==="create"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(tl,{className:"w-4 h-4"}),"批量创建卡密组"]}),e.jsxs("button",{onClick:()=>v("append"),className:`flex-1 inline-flex items-center justify-center gap-2 px-4 py-2.5 rounded-xl text-sm font-bold transition-all ${oe==="append"?"bg-brand text-white shadow-md":"bg-white text-gray-600 hover:bg-gray-50"}`,children:[e.jsx(Dt,{className:"w-4 h-4"}),"往单个组充卡密"]})]}),oe==="create"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl bg-blue-50 border border-blue-100 p-4 text-xs text-blue-900 leading-5",children:["上传表格,每行一个卡密组。表头:",e.jsx("code",{className:"bg-blue-100/70 px-1.5 py-0.5 rounded",children:"名称,类型,内容,描述,启用,延迟秒,多规格,规格名,规格值"}),'。 类型填 text/data/image;data 类型的"内容"按行存卡密(CSV 单元格内换行需用引号包裹)。']}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:he,className:"px-4 py-2.5 bg-gray-100 hover:bg-gray-200 rounded-xl font-bold text-gray-700 flex items-center gap-2 text-sm tran Line truncated
VIP-002
VIP-003`,className:"w-full ios-input px-4 py-3 rounded-xl text-sm font-mono h-40 resize-y"}),e.jsx("p",{className:"text-xs text-gray-500",children:"一行一个卡密号,空行自动忽略。会追加到该组现有库存末尾。"})]}),K&&e.jsxs("div",{className:"rounded-xl bg-green-50 border border-green-200 p-3 text-sm text-green-700 font-bold",children:["已追加 ",K.added," 个卡密"]})]})})]}),e.jsxs("div",{className:"px-6 py-4 border-t border-gray-100 flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:()=>me(!1),className:"px-5 py-2.5 rounded-xl bg-gray-100 hover:bg-gray-200 font-bold text-gray-700 transition-colors",children:"关闭"}),oe==="create"?e.jsxs("button",{onClick:ye,disabled:!q||B,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[B?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(Dt,{className:"w-4 h-4"}),B?"处理中...":"上传创建"]}):e.jsxs("button",{onClick:Ee,disabled:!ue||!Z.trim()||B||M.length===0,className:"ios-btn-primary px-6 py-2.5 rounded-xl font-bold flex items-center gap-2 disabled:opacity-50",children:[B?e.jsx(Pe,{className:"w-4 h-4 animate-spin"}):e.jsx(et,{className:"w-4 h-4"}),B?"处理中...":"追加卡密"]})]})]})}),document.body)]})},mn=t=>t.find(a=>a.status==="running"||a.status==="canceling"),la="ydisks-amap-js-api",pn="c9b68d4ce9a2a97f22a4a439404488ca";let $t=null;const un=()=>pn,hn=()=>window.AMap?Promise.resolve(window.AMap):$t||($t=new Promise((t,a)=>{const l=document.getElementById(la),i=l||document.createElement("script"),m=()=>{window.__ydisksAmapLoaded=void 0,window.clearTimeout(N)},_=()=>{window.AMap?(m(),t(window.AMap)):(m(),a(new Error("高德地图 API 加载完成但未找到 AMap 对象")))},N=window.setTimeout(()=>{m(),a(new Error("高德地图 API 加载超时,请检查网络或 VITE_AMAP_JS_KEY 配置"))},15e3);window.__ydisksAmapLoaded=_,i.id=la,i.async=!0,i.src=`https://webapi.amap.com/maps?v=2.0&key=${encodeURIComponent(un())}&plugin=AMap.PlaceSearch&callback=__ydisksAmapLoaded`,i.onerror=()=>{m(),a(new Error("高德地图 API 加载失败,请检查网络或 VITE_AMAP_JS_KEY 配置"))},l||document.head.appendChild(i)}).catch(t=>{throw $t=null,t}),$t),Ht=t=>Number.isFinite(t)&&t!==0,gn=t=>{var m,_;const a=Number((m=t.location)==null?void 0:m.lng),l=Number((_=t.location)==null?void 0:_.lat),i={area:String(t.adname||"").trim(),city:String(t.cityname||"").trim(),division_id:String(t.adcode||"").trim(),longitude:a,latitude:l,poi_id:String(t.id||"").trim(),poi_name:String(t.name||"").trim(),province:String(t.pname||"").trim()};return!i.division_id||!i.province||!i.city||!i.poi_id||!i.poi_name||!Ht(a)||!Ht(l)||a<-180||a>180||l<-90||l>90?null:i},bn=async(t,a)=>{if(!Ht(t)||!Ht(a)||t<-180||t>180||a<-90||a>90)throw new Error("经纬度无效");const l=await hn();return new Promise((i,m)=>{new l.PlaceSearch({extensions:"all",pageSize:10}).searchNearBy("",[t,a],1e3,(N,R)=>{var C;if(N!=="complete"){if(N==="no_data"){i([]);return}m(new Error("高德地图附近地址查询失败,请稍后重试"));return}const g=(((C=R==null?void 0:R.poiList)==null?void 0:C.pois)||[]).map(gn).filter(j=>j!==null);i(g)})})},fn=t=>{const a=String(t||"").trim();return a?/^[¥¥]/.test(a)?a:`¥${a}`:"-"},yn=({onConfigureDelivery:t})=>{const[a,l]=r.useState([]),[i,m]=r.useState([]),[_,N]=r.useState([]),[R,g]=r.useState(""),[C,j]=r.useState(""),[F,G]=r.useState(!1),[me,oe]=r.useState(!1),[v,q]=r.useState(!1),[ce,Q]=r.useState(!1),[ee,B]=r.useState(!1),[ge,ue]=r.useState(!1),[k,Z]=r.useState(!1),[se,K]=r.useState("upload"),[ve,J]=r.useState(null),[I,E]=r.useState(null),[$,be]=r.useState(""),[Re,ae]=r.useState(!1),[T,p]=r.useState(!1),[b,U]=r.useState([]),[M,ne]=r.useState(null),[he,ye]=r.useState([]),[Ee,ke]=r.useState(null),[x,V]=r.useState({catId:"",catName:"",channelCatId:"",tbCatId:""}),[X,c]=r.useState(null),[d,D]=r.useState(null),[S,Y]=r.useState(null),O=r.useRef(!1),[de,Se]=r.useState(null),[fe,Oe]=r.useState({}),[re,h]=r.useState({cookie_id:"",item_id:"",item_title:"",item_price:"",item_image:""}),[f,P]=r.useState({cookie_id:"",title:"",description:"",price:"",original_price:"",quantity:"1",postage_mode:"free",postage:"",images:[]}),[z,Ie]=r.useState([]);r.useEffect(()=>{if(!ge||f.images.length===0){Ie([]);return}const n=f.images.map((w,H)=>({key:w.name+H,url:URL.createObjectURL(w)}));return Ie(n),()=>{n.forEach(w=>URL.revokeObjectURL(w.url))}},[ge,f.images]);const Ae=async()=>{const n=await vt();l(n)},we=async()=>{m(await gs())};r.useEffect(()=>{Promise.all([Ft(),vt(),gs(),Hs(20)]).then(([n,w,H,Te])=>{N(n),l(w),m(H);const s=Te.find(o=>["running","canceling"].includes(o.status))||Te.find(o=>o.status!=="preview");Y(s||null)}).catch(n=>console.error("加载商品配置失败:",n))},[]),r.useEffect(()=>{if(!k||!(d!=null&&d.id)||!["running","canceling"].includes(d.status))return;const n=window.setInterval(async()=>{if(!O.current){O.current=!0;try{const w=await bt(d.id);D(w),Y(w),[ Line truncated
`),Te=new Blob(["\uFEFF"+H],{type:"text/csv;charset=utf-8"}),s=URL.createObjectURL(Te),o=document.createElement("a");o.href=s,o.download="批量铺货模板.csv",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(s)},Lt=()=>{h(n=>({...n,cookie_id:R||n.cookie_id})),B(!0)},nt=()=>{P(n=>({...n,cookie_id:R||n.cookie_id})),ue(!0)},it=async n=>{if(!(n?R:f.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");p(!0),navigator.geolocation.getCurrentPosition(async H=>{try{const Te=await bn(H.coords.longitude,H.coords.latitude);if(!Te.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");n?(ye(Te),ke(Te[0])):(U(Te),ne(Te[0]))}catch(Te){alert((Te==null?void 0:Te.message)||"获取发货地失败")}finally{p(!1)}},H=>{p(!1),alert(H.code===H.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},Ot=n=>i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id).length>0?i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id):i.filter(w=>w.cookie_id===n.cookie_id&&!w.item_id),pt=n=>{switch(n){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return n||"-"}},ut=n=>{switch(n){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},st=r.useMemo(()=>new Map(_.map(n=>[n.id,n])),[_]),ht=r.useMemo(()=>C?a.filter(n=>n.cookie_id===C):a,[C,a]),Ge=n=>{const w=st.get(n),H=(w==null?void 0:w.remark)||(w==null?void 0:w.nickname);return H?`${H} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},ot=n=>{const w=st.get(n);return(w==null?void 0:w.remark)||(w==null?void 0:w.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(ll,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:C,onChange:n=>j(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:R,onChange:n=>g(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:De,disabled:F||!R,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(ze,{className:`w-4 h-4 ${F?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Lt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(et,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:nt,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(es,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Ne(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white Line truncated
`),Te=new Blob(["\uFEFF"+H],{type:"text/csv;charset=utf-8"}),s=URL.createObjectURL(Te),o=document.createElement("a");o.href=s,o.download="批量铺货模板.csv",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(s)},Lt=()=>{h(n=>({...n,cookie_id:R||n.cookie_id})),B(!0)},nt=()=>{P(n=>({...n,cookie_id:R||n.cookie_id})),ue(!0)},it=async n=>{if(!(n?R:f.cookie_id))return alert("请先选择发布账号");if(!navigator.geolocation)return alert("当前浏览器不支持定位");p(!0),navigator.geolocation.getCurrentPosition(async H=>{try{const Te=await bn(H.coords.longitude,H.coords.latitude);if(!Te.length)throw new Error("当前位置附近没有可用的高德发货地,请稍后重试");n?(ye(Te),ke(Te[0])):(U(Te),ne(Te[0]))}catch(Te){alert((Te==null?void 0:Te.message)||"获取发货地失败")}finally{p(!1)}},H=>{p(!1),alert(H.code===H.PERMISSION_DENIED?"定位权限被拒绝,请在浏览器设置中允许定位":"无法获取当前位置,请稍后重试")},{enableHighAccuracy:!0,timeout:15e3,maximumAge:6e4})},Ot=n=>i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id).length>0?i.filter(w=>w.cookie_id===n.cookie_id&&w.item_id===n.item_id):i.filter(w=>w.cookie_id===n.cookie_id&&!w.item_id),pt=n=>{switch(n){case"preview":return"待确认";case"pending":return"等待中";case"running":return"发布中";case"canceling":return"正在安全取消";case"success":return"成功";case"failed":return"失败";case"completed":return"已完成";case"partially_failed":return"部分失败";case"canceled":return"已取消";default:return n||"-"}},ut=n=>{switch(n){case"success":case"completed":return"bg-emerald-50 text-emerald-700 border-emerald-100";case"partially_failed":case"failed":return"bg-red-50 text-red-700 border-red-100";case"running":return"bg-blue-50 text-blue-700 border-blue-100";case"canceled":return"bg-gray-100 text-gray-600 border-gray-200";default:return"bg-amber-50 text-amber-700 border-amber-100"}},st=r.useMemo(()=>new Map(_.map(n=>[n.id,n])),[_]),ht=r.useMemo(()=>C?a.filter(n=>n.cookie_id===C):a,[C,a]),Ge=n=>{const w=st.get(n),H=(w==null?void 0:w.remark)||(w==null?void 0:w.nickname);return H?`${H} · ${n.slice(0,6)}`:`账号 ${n.slice(0,8)}`},ot=n=>{const w=st.get(n);return(w==null?void 0:w.remark)||(w==null?void 0:w.nickname)||"未命名账号"};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col xl:flex-row xl:justify-between xl:items-center gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:"商品管理"}),e.jsx("p",{className:"text-gray-500 mt-2 text-sm",children:"监控并管理所有账号下的闲鱼商品。"})]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-account-filter",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"商品列表筛选"}),e.jsxs("div",{className:"relative",children:[e.jsx(ll,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-account-filter","aria-label":"按账号筛选商品列表",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:C,onChange:n=>j(n.target.value),children:[e.jsx("option",{value:"",children:"全部账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("div",{className:"flex min-w-[200px] flex-col gap-1.5",children:[e.jsx("label",{htmlFor:"item-sync-account",className:"px-1 text-[11px] font-extrabold tracking-wide text-gray-500",children:"同步商品账号"}),e.jsxs("div",{className:"relative",children:[e.jsx(xt,{className:"w-4 h-4 absolute left-4 top-1/2 -translate-y-1/2 text-gray-400 pointer-events-none"}),e.jsxs("select",{id:"item-sync-account","aria-label":"选择要同步商品的账号",className:"ios-input w-full pl-10 pr-9 py-3 rounded-xl text-sm",value:R,onChange:n=>g(n.target.value),children:[e.jsx("option",{value:"",children:"请选择账号"}),_.map(n=>e.jsx("option",{value:n.id,children:Ge(n.id)},n.id))]})]})]}),e.jsxs("button",{onClick:De,disabled:F||!R,className:"ios-btn-primary flex items-center gap-2 px-6 py-3 rounded-2xl font-bold shadow-lg shadow-blue-200 disabled:opacity-50",children:[e.jsx(ze,{className:`w-4 h-4 ${F?"animate-spin":""}`}),"同步商品"]}),e.jsxs("button",{onClick:Lt,className:"px-5 py-3 rounded-2xl font-bold bg-gray-900 text-white hover:bg-gray-800 transition-colors flex items-center gap-2 shadow-lg",children:[e.jsx(et,{className:"w-4 h-4"}),"添加商品"]}),e.jsxs("button",{onClick:nt,className:"px-5 py-3 rounded-2xl font-bold bg-emerald-500 text-white hover:bg-emerald-600 transition-colors flex items-center gap-2 shadow-lg shadow-emerald-100",children:[e.jsx(es,{className:"w-4 h-4"}),"发布商品"]}),e.jsxs("button",{onClick:()=>void Ne(),className:"px-5 py-3 rounded-2xl font-bold bg-brand text-white Line truncated
+1 -1
View File
@@ -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-BN4uXegq.js"></script>
<script type="module" crossorigin src="/static/assets/index-BBbP32Ar.js"></script>
<link rel="modulepreload" crossorigin href="/static/assets/react-vendor-C_od1ZSF.js">
<link rel="modulepreload" crossorigin href="/static/assets/icons-vendor-BpMgNNfy.js">
<link rel="modulepreload" crossorigin href="/static/assets/vendor-D-Edl3pr.js">