feat(jd): 首页一级入口「京东」+工作台两菜单,获取店铺数据一键采集带进度条
首页在亚马逊/视频右侧新增「京东」一级入口(恒显示),落地页 /jd-console 按亚马逊控制台样式做两张工具卡:获取店铺数据(可用)、商品上架(占位,点开只提示「暂未开通」)。
获取店铺数据改成一键:建单 → 推 jd-shop-collect-run 到本机队列 → 轮询服务端进度。进度只读两处真源——任务行状态 + scope 行合并写游标里的 itemsReceived/cursor.total(客户端抓列表第一页时把 total 写进游标),没有分母就退回不定态动画,不编造百分比;终态即停轮询。后端新增 GET /api/jd-collect/tasks/{taskId}/progress(按 taskId+userId 校归属)。
判据:JdCollectProgressQueryTest(5)、jd-console-tool-catalog.test.ts(5)、jd-console-pending-menu.mount(3)、jd-collect-progress.mount(6);catch 棘轮 blocks 314→315 按名登记(轮询 catch 非静默)。
This commit is contained in:
+17
@@ -4,6 +4,7 @@ import com.nanri.aiimage.common.api.ApiResponse;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.modules.jd.model.dto.JdCollectTaskCreateRequest;
|
||||
import com.nanri.aiimage.modules.jd.model.dto.JdIngestChunkRequest;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdCollectProgressVo;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdCollectTaskVo;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdIngestChunkVo;
|
||||
import com.nanri.aiimage.modules.jd.service.JdCollectTaskService;
|
||||
@@ -19,10 +20,12 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
@@ -58,6 +61,20 @@ public class JdCollectController {
|
||||
adminAuthSupport.currentDeviceId(httpRequest)));
|
||||
}
|
||||
|
||||
@GetMapping("/tasks/{taskId}/progress")
|
||||
@Operation(summary = "查询京东采集进度", description = "用户端「获取店铺数据」进度条数据源:"
|
||||
+ "任务状态 + 已回传商品数 + 列表 total(客户端抓首页时写入游标) + 当前页/Tab + 已收批次数。"
|
||||
+ "进度查询与建单同口径鉴权:uid 按会话身份回填,任务 owner 与 uid 不一致即 403。")
|
||||
public ApiResponse<JdCollectProgressVo> progress(
|
||||
@Parameter(description = "任务 ID", required = true, example = "33890")
|
||||
@PathVariable Long taskId,
|
||||
@Parameter(description = "任务所属用户 ID;省略时取当前登录身份", required = false, example = "1")
|
||||
@RequestParam(value = "user_id", required = false) Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
return ApiResponse.success(collectTaskService.queryProgress(taskId,
|
||||
adminAuthSupport.requireOwnershipUserId(httpRequest, userId)));
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{taskId}/chunk")
|
||||
@Operation(summary = "提交采集分片回传", description = "采集器按批次回传列表/详情/图片清单;"
|
||||
+ "游标合并写(缺件沿用前值)、行 upsert-only;isEnd=true 任务落 SUCCESS;"
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.nanri.aiimage.modules.jd.model.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 京东店铺采集进度(v1.5 用户端"获取店铺数据"进度条数据源)。
|
||||
*
|
||||
* <p>数据只取两处真源:{@code biz_file_task}(任务状态/终态原因)与
|
||||
* {@code biz_task_scope_state}(合并写游标:{@code itemsReceived}、{@code cursor.total}、
|
||||
* {@code receivedChunkCount})。不在服务端另算一套百分比——客户端抓完一页就把本页
|
||||
* total 写进游标(合并写,缺键沿用前值,见铁律 30),页面据此算进度。
|
||||
*/
|
||||
@Data
|
||||
public class JdCollectProgressVo {
|
||||
|
||||
private Long taskId;
|
||||
|
||||
/** PENDING / RUNNING / SUCCESS / FAILED(biz_file_task.status 原值)。 */
|
||||
private String status;
|
||||
|
||||
/** 已回传落库的商品数(scope.state_json.itemsReceived 累计值)。 */
|
||||
private Integer itemsReceived;
|
||||
|
||||
/**
|
||||
* 列表总数:客户端抓第一页时从京麦列表接口拿到的 total,没拿到过就为 {@code null}。
|
||||
* 页面据此决定是"百分比进度条"还是"不定态进度条"。
|
||||
*/
|
||||
private Integer total;
|
||||
|
||||
/** 当前采集页(游标,断点续跑会从这里接着跑)。 */
|
||||
private Integer page;
|
||||
|
||||
/** 当前采集 Tab(ONSALE / OFFSALE)。 */
|
||||
private String listTab;
|
||||
|
||||
/** 已收到的分片批次数。 */
|
||||
private Integer batches;
|
||||
|
||||
/** 终态原因(FAILED 时为客户端上报的真实原因)。 */
|
||||
private String message;
|
||||
|
||||
/** 最近一次回传/合并写的时间。 */
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
+103
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.config.CollectRoutingProperties;
|
||||
import com.nanri.aiimage.modules.jd.model.dto.JdCollectTaskCreateRequest;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdCollectProgressVo;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdCollectTaskVo;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskScopeStateMapper;
|
||||
@@ -20,7 +21,10 @@ import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -159,4 +163,103 @@ public class JdCollectTaskService {
|
||||
.eq(TaskScopeStateEntity::getModuleType, MODULE_TYPE)
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询采集进度(v1.5 用户端「获取店铺数据」进度条)。
|
||||
*
|
||||
* <p>只读两处真源:任务行(状态/终态原因)与 scope 行(合并写游标里的
|
||||
* {@code itemsReceived}/{@code cursor.total}/{@code cursor.page})。这里不重算百分比——
|
||||
* 分母来自客户端抓列表第一页时拿到的 total,没拿到过就返回 {@code null},
|
||||
* 由页面降级成不定态进度条(不编造一个假百分比)。
|
||||
*
|
||||
* <p>归属校验按 {@code (taskId, userId)}(铁律 11/22):管理员代客时 userId 来自
|
||||
* 请求参数,若与任务 owner 不一致一律拒,不让 taskId 裸查越权。
|
||||
*/
|
||||
public JdCollectProgressVo queryProgress(Long taskId, Long userId) {
|
||||
if (taskId == null || taskId <= 0) {
|
||||
throw new BusinessException("任务 ID 不合法");
|
||||
}
|
||||
FileTaskEntity task = fileTaskMapper.selectById(taskId);
|
||||
if (task == null || !MODULE_TYPE.equals(task.getModuleType())) {
|
||||
throw new BusinessException("任务不存在: " + taskId);
|
||||
}
|
||||
if (userId != null && task.getUserId() != null && !Objects.equals(userId, task.getUserId())) {
|
||||
throw new BusinessException(403, "无权查看该任务");
|
||||
}
|
||||
|
||||
JdCollectProgressVo vo = new JdCollectProgressVo();
|
||||
vo.setTaskId(task.getId());
|
||||
vo.setStatus(task.getStatus());
|
||||
vo.setMessage(task.getErrorMessage());
|
||||
vo.setUpdatedAt(task.getUpdatedAt());
|
||||
|
||||
TaskScopeStateEntity scope = findScopeRow(taskId);
|
||||
if (scope == null) {
|
||||
// scope 行缺失(历史/异常建单)时只回任务级状态,进度按 0 计,不抛错——
|
||||
// 进度查询是展示面,不该因为一行辅助表缺失把页面打成红条。
|
||||
vo.setItemsReceived(nz(task.getSuccessFileCount()));
|
||||
vo.setBatches(0);
|
||||
return vo;
|
||||
}
|
||||
Map<String, Object> state = parseScopeState(scope.getStateJson());
|
||||
Map<String, Object> cursor = asMap(state.get("cursor"));
|
||||
vo.setItemsReceived(Math.max(nz(task.getSuccessFileCount()), asInt(state.get("itemsReceived"))));
|
||||
vo.setTotal(asNullableInt(cursor.get("total")));
|
||||
vo.setPage(asNullableInt(cursor.get("page")));
|
||||
Object tab = cursor.get("tab");
|
||||
vo.setListTab(tab == null ? null : String.valueOf(tab));
|
||||
vo.setBatches(scope.getReceivedChunkCount() == null ? 0 : scope.getReceivedChunkCount());
|
||||
if (scope.getUpdatedAt() != null) {
|
||||
vo.setUpdatedAt(scope.getUpdatedAt());
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
/** 读 scope 状态 JSON;损坏时返回空对象并留痕(查询面不因一行脏 JSON 抛错)。 */
|
||||
private Map<String, Object> parseScopeState(String stateJson) {
|
||||
if (stateJson == null || stateJson.isBlank()) {
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
try {
|
||||
Map<String, Object> parsed = objectMapper.readValue(stateJson,
|
||||
objectMapper.getTypeFactory().constructMapType(LinkedHashMap.class, String.class, Object.class));
|
||||
return parsed == null ? new LinkedHashMap<>() : parsed;
|
||||
} catch (Exception ex) {
|
||||
log.warn("[jd-collect] scope 状态 JSON 解析失败,进度按 0 展示 taskId 相关行: {}", ex.getMessage());
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Map<String, Object> asMap(Object raw) {
|
||||
return raw instanceof Map ? new LinkedHashMap<>((Map<String, Object>) raw) : new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
private static int asInt(Object raw) {
|
||||
Integer value = asNullableInt(raw);
|
||||
return value == null ? 0 : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 宽松读整数:数字类型直接用,字符串只认 1~9 位十进制(int 范围内必然不溢出)。
|
||||
* 不拿 {@code NumberFormatException} 当控制流——脏值在进度展示面是正常的空结果,
|
||||
* 不该为它添一个 catch(catch 棘轮同形判据)。
|
||||
*/
|
||||
private static Integer asNullableInt(Object raw) {
|
||||
if (raw instanceof Number number) {
|
||||
return number.intValue();
|
||||
}
|
||||
if (raw == null) {
|
||||
return null;
|
||||
}
|
||||
String text = String.valueOf(raw).trim();
|
||||
if (!text.matches("-?\\d{1,9}")) {
|
||||
return null;
|
||||
}
|
||||
return Integer.valueOf(text);
|
||||
}
|
||||
|
||||
private static int nz(Integer value) {
|
||||
return value == null ? 0 : Math.max(0, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,9 @@ class CatchSilenceRatchetTest {
|
||||
// + parseAttrGroups 的 attr_json 兜底;Phase 2/4 的 7 枚全是 RETHROW、Phase 2 的 scope 行
|
||||
// DuplicateKeyException 是 LOG_ONLY,都不占本格),逐处记名见 STRICT_TOTAL 上方注释;
|
||||
// LOG_ONLY 宽口径格 251 没动(宽口径实测 194,离上限很远)。
|
||||
static final int GIVEN_NOT_RETHROW = 615;
|
||||
// 11-14 v1.5「获取店铺数据」进度条抬 615 -> 616:一枚不重抛(进度查询读 scope.state_json
|
||||
// 失败 log.warn + 空对象),逐处记名与误差方向见 STRICT_TOTAL 上方注释;LOG_ONLY 一格没动。
|
||||
static final int GIVEN_NOT_RETHROW = 616;
|
||||
static final int GIVEN_LOG_ONLY = 251;
|
||||
static final int GIVEN_EMPTY = 56;
|
||||
|
||||
@@ -357,7 +359,14 @@ class CatchSilenceRatchetTest {
|
||||
// 「京东时间格式不识别(应为 yyyy-MM-dd HH:mm:ss): <原文>」(RETHROW)。误差方向:
|
||||
// 客户端回传脏时间戳之前直接 DateTimeParseException 裸抛 = 回传口 500 裸堆栈(P1-3);
|
||||
// 改成吞掉置 null = 登记时间被悄悄抹掉。
|
||||
static final int STRICT_TOTAL = 1091;
|
||||
// 11-14 v1.5「获取店铺数据」进度条抬 1091 -> 1092,一枚逐处记名:
|
||||
// `JdCollectTaskService.parseScopeState`:进度查询读 scope.state_json 时
|
||||
// `catch Exception` ⇒ log.warn 带原因 + 返回空对象(NOT_RETHROW)。误差方向:
|
||||
// 改成往外抛 = 一行脏 JSON 把进度查询打成 500、进度条直接红条;改成静默返回空对象
|
||||
// 不记日志 = 游标损坏永远没人知道。演示面只降级不抛错,但必须有那一行 WARN。
|
||||
// (相邻的数值解析刻意不用 NumberFormatException 当控制流:改为 1~9 位十进制正则前置,
|
||||
// 省掉两枚 catch,EMPTY 一格没涨。)
|
||||
static final int STRICT_TOTAL = 1092;
|
||||
/**
|
||||
* 重抛型 catch 的**下限**(不是上限):本轮把两处吞异常改成重抛之后实测 388。
|
||||
* 这一格只能涨不能跌——它是"异常会往外走"的总量,把它钉成"只许减"就等于拦着别人修吞异常。
|
||||
@@ -491,7 +500,10 @@ class CatchSilenceRatchetTest {
|
||||
// 本格含 LOG_ONLY(incl 口径):同批 Phase 2 建单 scope 行那枚 DuplicateKeyException 复用
|
||||
// 先到行把 LOG_ONLY 抬 193 -> 194 时连带占本格一枚额度 ⇒ 614 -> 615(出处同 STRICT_TOTAL
|
||||
// 上方注释;这是本格**含 LOG_ONLY** 口径的连带,不是又一枚新的不重抛)。
|
||||
static final int STRICT_NOT_RETHROW = 615;
|
||||
// 11-14 v1.5「获取店铺数据」进度条:严格口径实测 615 -> 616(一枚不重抛:
|
||||
// JdCollectTaskService.parseScopeState 读 scope.state_json 失败 log.warn + 空对象,
|
||||
// 出处与误差方向见 STRICT_TOTAL 上方注释;logOnly 一格没动)。
|
||||
static final int STRICT_NOT_RETHROW = 616;
|
||||
/**
|
||||
* 10-17 抬 172 -> 173,出处就是上面点名过的 {@code TaskHeartbeatLivenessService.stamp()}:
|
||||
* 块体只有「取到 key 名 + log.warn」一句,写心跳证据失败时既不重试也不抛出——
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package com.nanri.aiimage.modules.jd.service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.modules.jd.model.vo.JdCollectProgressVo;
|
||||
import com.nanri.aiimage.modules.task.mapper.FileTaskMapper;
|
||||
import com.nanri.aiimage.modules.task.mapper.TaskScopeStateMapper;
|
||||
import com.nanri.aiimage.modules.task.model.entity.FileTaskEntity;
|
||||
import com.nanri.aiimage.modules.task.model.entity.TaskScopeStateEntity;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 京东采集进度查询(v1.5「获取店铺数据」进度条数据源)。
|
||||
*
|
||||
* <p>判据三件:① 进度只读真源(任务行 + scope 合并写游标),不编造百分比;
|
||||
* ② 归属按 {@code (taskId, userId)} 校验,taskId 裸查不能越权;③ scope 行缺失或 JSON
|
||||
* 损坏时降级展示而不是把页面打成红条。
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class JdCollectProgressQueryTest {
|
||||
|
||||
@Mock
|
||||
private FileTaskMapper fileTaskMapper;
|
||||
@Mock
|
||||
private TaskScopeStateMapper taskScopeStateMapper;
|
||||
@Spy
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@InjectMocks
|
||||
private JdCollectTaskService service;
|
||||
|
||||
private FileTaskEntity runningTask(long userId) {
|
||||
FileTaskEntity task = new FileTaskEntity();
|
||||
task.setId(33890L);
|
||||
task.setModuleType(JdCollectTaskService.MODULE_TYPE);
|
||||
task.setUserId(userId);
|
||||
task.setStatus("RUNNING");
|
||||
task.setSuccessFileCount(0);
|
||||
task.setUpdatedAt(LocalDateTime.of(2026, 11, 14, 10, 0));
|
||||
return task;
|
||||
}
|
||||
|
||||
private TaskScopeStateEntity scope(String stateJson, Integer batches) {
|
||||
TaskScopeStateEntity scope = new TaskScopeStateEntity();
|
||||
scope.setTaskId(33890L);
|
||||
scope.setModuleType(JdCollectTaskService.MODULE_TYPE);
|
||||
scope.setStateJson(stateJson);
|
||||
scope.setReceivedChunkCount(batches);
|
||||
scope.setUpdatedAt(LocalDateTime.of(2026, 11, 14, 10, 1));
|
||||
return scope;
|
||||
}
|
||||
|
||||
@Test
|
||||
void 进度按合并写游标读出商品数与总数() {
|
||||
when(fileTaskMapper.selectById(33890L)).thenReturn(runningTask(7L));
|
||||
when(taskScopeStateMapper.selectOne(any())).thenReturn(scope(
|
||||
"{\"cursor\":{\"tab\":\"ONSALE\",\"page\":3,\"total\":300},\"itemsReceived\":120}",
|
||||
4));
|
||||
|
||||
JdCollectProgressVo vo = service.queryProgress(33890L, 7L);
|
||||
|
||||
assertThat(vo.getStatus()).isEqualTo("RUNNING");
|
||||
assertThat(vo.getItemsReceived()).isEqualTo(120);
|
||||
assertThat(vo.getTotal()).as("分母只来自客户端写入游标的 total,服务端不另算")
|
||||
.isEqualTo(300);
|
||||
assertThat(vo.getPage()).isEqualTo(3);
|
||||
assertThat(vo.getListTab()).isEqualTo("ONSALE");
|
||||
assertThat(vo.getBatches()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
void 归属不符拒绝查询() {
|
||||
when(fileTaskMapper.selectById(33890L)).thenReturn(runningTask(7L));
|
||||
|
||||
assertThatThrownBy(() -> service.queryProgress(33890L, 99L))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("无权查看该任务");
|
||||
}
|
||||
|
||||
@Test
|
||||
void scope缺失时回退任务成功数且总数留空() {
|
||||
FileTaskEntity task = runningTask(7L);
|
||||
task.setStatus("SUCCESS");
|
||||
task.setSuccessFileCount(58);
|
||||
when(fileTaskMapper.selectById(33890L)).thenReturn(task);
|
||||
when(taskScopeStateMapper.selectOne(any())).thenReturn(null);
|
||||
|
||||
JdCollectProgressVo vo = service.queryProgress(33890L, 7L);
|
||||
|
||||
assertThat(vo.getItemsReceived()).isEqualTo(58);
|
||||
assertThat(vo.getTotal()).isNull();
|
||||
assertThat(vo.getBatches()).isZero();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 游标脏JSON降级为零进度不抛错() {
|
||||
when(fileTaskMapper.selectById(33890L)).thenReturn(runningTask(7L));
|
||||
when(taskScopeStateMapper.selectOne(any())).thenReturn(scope("{\"cursor\":{半个", 1));
|
||||
|
||||
JdCollectProgressVo vo = service.queryProgress(33890L, 7L);
|
||||
|
||||
assertThat(vo.getItemsReceived()).isZero();
|
||||
assertThat(vo.getTotal()).isNull();
|
||||
assertThat(vo.getBatches()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void 非京东模块任务按不存在拒绝() {
|
||||
FileTaskEntity task = runningTask(7L);
|
||||
task.setModuleType("SIMILAR_ASIN");
|
||||
when(fileTaskMapper.selectById(33890L)).thenReturn(task);
|
||||
|
||||
assertThatThrownBy(() -> service.queryProgress(33890L, 7L))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("任务不存在");
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,15 @@
|
||||
:class="{ disabled: !videoHref }"
|
||||
data-column-key="wb"
|
||||
>视频</router-link>
|
||||
|
||||
<!-- 京东入口:一级入口,不挂在亚马逊/视频的权限树里(京东工具台自带两个菜单,
|
||||
权限收口在工具台内部;入口恒显示,避免账号还没配京东菜单时入口凭空消失)。 -->
|
||||
<router-link
|
||||
:to="jdHref"
|
||||
class="entrance-btn jd"
|
||||
:class="{ disabled: !jdHref }"
|
||||
data-column-key="jd"
|
||||
>京东</router-link>
|
||||
</div>
|
||||
|
||||
<div class="toast" :class="{ show: Boolean(toastText) }">{{ toastText }}</div>
|
||||
@@ -115,6 +124,8 @@ const permissionUnavailable = ref(false)
|
||||
|
||||
const amazonHref = computed(() => resolvePageHref('/new_web_source/amazon-console.html'))
|
||||
const videoHref = computed(() => resolvePageHref('/new_web_source/image-video.html'))
|
||||
/** 京东工作台(两个菜单:获取店铺数据 / 商品上架,见 pages/jd/tool-catalog.ts) */
|
||||
const jdHref = computed(() => resolvePageHref('/new_web_source/jd-console.html'))
|
||||
|
||||
const canShow = computed(() =>
|
||||
permissionUnavailable.value ? { amazon: true, video: true } : permissionState.value,
|
||||
|
||||
@@ -1,40 +1,157 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { createJdCollectTask, type JdListTab } from '../../shared/api/types/modules/jd-collect.ts'
|
||||
import { getPywebviewApi } from '../../shared/bridges/pywebview.ts'
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import {
|
||||
createJdCollectTask,
|
||||
fetchJdCollectProgress,
|
||||
type JdCollectProgressVo,
|
||||
type JdListTab,
|
||||
} from '@/shared/api/types/modules/jd-collect'
|
||||
import { getPywebviewApi } from '@/shared/bridges/pywebview'
|
||||
import { resolvePageHref } from '@/shared/page-prefix'
|
||||
import { isTerminalTaskStatus } from '@/shared/utils/task-terminal'
|
||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||
|
||||
/** 京东店铺商品采集建单页(v1.4 AC-1,蓝图 §3.2)。
|
||||
/** 京东「获取店铺数据」(v1.5):一键建单 → 推送本机客户端 → 轮询服务端进度。
|
||||
*
|
||||
* 建单后把 `jd-shop-collect-run` 载荷推进本机客户端队列(v1.4 Phase 6.1 修 P0-1:
|
||||
* 只建单不推送会让任务永久停在 PENDING——兜底拉取是补救不是主链)。data 键集与
|
||||
* 客户端 jd_base.process_task 读取契约同键;推送失败不回滚建单,任务可由服务端
|
||||
* 兜底拉取(TaskClientPullService 白名单含 JD_SHOP_COLLECT)认领。
|
||||
* 三个真源与三条边界(照 v1.4 已落地的采集契约,不另造流程):
|
||||
* 1. 建单走后端 `/api/jd-collect/tasks`(通道恒 LOCAL,服务端落 PENDING);
|
||||
* 2. 建单成功把 `jd-shop-collect-run` 载荷推进本机客户端队列——只建单不推送会让任务
|
||||
* 卡在 PENDING 等兜底拉取(v1.4 Phase 6.1 P0-1 的教训);推送失败不回滚建单;
|
||||
* 3. 进度只读服务端(`/tasks/{taskId}/progress`):任务状态 + 合并写游标里的
|
||||
* itemsReceived/total。`total` 缺失时进度条走不定态,不编造百分比。
|
||||
*/
|
||||
|
||||
const form = reactive({
|
||||
shopName: '',
|
||||
onsale: true,
|
||||
offsale: false,
|
||||
maxProducts: 0,
|
||||
type ProgressStatus = 'PENDING' | 'RUNNING' | 'SUCCESS' | 'FAILED'
|
||||
type ProgressPhase = 'idle' | 'running' | 'done' | 'failed'
|
||||
|
||||
const POLL_INTERVAL_MS = 2000
|
||||
/** 一小时还没终态就停轮询(任务本身有 stale 兜底,页面不该无限烧请求)。 */
|
||||
const POLL_TIMEOUT_MS = 60 * 60 * 1000
|
||||
|
||||
const homeHref = resolvePageHref('/new_web_source/home.html')
|
||||
const backHref = resolvePageHref('/new_web_source/jd-console.html')
|
||||
|
||||
const username = ref('admin')
|
||||
const shopName = ref('')
|
||||
const submitting = ref(false)
|
||||
const taskId = ref<number | null>(null)
|
||||
const progress = ref<JdCollectProgressVo | null>(null)
|
||||
const phase = ref<ProgressPhase>('idle')
|
||||
const errorMessage = ref('')
|
||||
const successMessage = ref('')
|
||||
|
||||
let pollTimer: number | undefined
|
||||
let pollStartedAt = 0
|
||||
let pollFailures = 0
|
||||
|
||||
const statusText = computed(() => {
|
||||
const status = progress.value?.status
|
||||
if (phase.value === 'done') return '获取完成'
|
||||
if (phase.value === 'failed') return '获取失败'
|
||||
switch (status) {
|
||||
case 'PENDING':
|
||||
return '等待本机客户端领取任务…'
|
||||
case 'RUNNING':
|
||||
return '正在获取店铺数据…'
|
||||
case 'SUCCESS':
|
||||
return '获取完成'
|
||||
case 'FAILED':
|
||||
return '获取失败'
|
||||
default:
|
||||
return '已提交,正在确认任务状态…'
|
||||
}
|
||||
})
|
||||
|
||||
const submitting = ref(false)
|
||||
const successMessage = ref('')
|
||||
const errorMessage = ref('')
|
||||
const itemsReceived = computed(() => progress.value?.itemsReceived ?? 0)
|
||||
const totalCount = computed(() => {
|
||||
const total = progress.value?.total
|
||||
return typeof total === 'number' && total > 0 ? total : null
|
||||
})
|
||||
|
||||
function buildListTabs(): JdListTab[] {
|
||||
const tabs: JdListTab[] = []
|
||||
if (form.onsale) tabs.push('ONSALE')
|
||||
if (form.offsale) tabs.push('OFFSALE')
|
||||
return tabs
|
||||
/** 百分比:终态 100;有 total 按已落库商品数算(封顶 99 直到服务端落 SUCCESS)。 */
|
||||
const percent = computed<number | null>(() => {
|
||||
if (phase.value === 'done') return 100
|
||||
const total = totalCount.value
|
||||
if (!total) return null
|
||||
const done = Math.min(itemsReceived.value, total)
|
||||
return Math.max(0, Math.min(99, Math.round((done * 100) / total)))
|
||||
})
|
||||
|
||||
const percentText = computed(() => (percent.value === null ? '' : `${percent.value}%`))
|
||||
|
||||
const progressMeta = computed(() => {
|
||||
const vo = progress.value
|
||||
if (!vo) return ''
|
||||
const parts: string[] = [`已采集 ${itemsReceived.value} 个商品`]
|
||||
if (totalCount.value) {
|
||||
parts.push(`共 ${totalCount.value} 个`)
|
||||
}
|
||||
if (typeof vo.page === 'number' && vo.page > 0) {
|
||||
parts.push(`第 ${vo.page} 页`)
|
||||
}
|
||||
if (typeof vo.batches === 'number' && vo.batches > 0) {
|
||||
parts.push(`已回传 ${vo.batches} 批`)
|
||||
}
|
||||
return parts.join(' · ')
|
||||
})
|
||||
|
||||
const isRunning = computed(() => phase.value === 'running' || submitting.value)
|
||||
|
||||
function stopPolling() {
|
||||
if (pollTimer !== undefined) {
|
||||
window.clearTimeout(pollTimer)
|
||||
pollTimer = undefined
|
||||
}
|
||||
}
|
||||
|
||||
function applyTerminal(vo: JdCollectProgressVo) {
|
||||
stopPolling()
|
||||
// 终态集合走共享词表(shared/utils/task-terminal,含 COMPLETED≡SUCCESS);
|
||||
// 只有明确 FAILED 才当失败,其余终态都按完成展示——窄集合是六页踩过的坑。
|
||||
if (vo.status !== 'FAILED') {
|
||||
phase.value = 'done'
|
||||
successMessage.value = `获取完成:共采集 ${vo.itemsReceived ?? 0} 个商品,` +
|
||||
'已导入后台「京东数据库」。'
|
||||
return
|
||||
}
|
||||
phase.value = 'failed'
|
||||
errorMessage.value = vo.message?.trim()
|
||||
|| '获取失败:没有拿到失败原因,请到客户端任务列表查看详情'
|
||||
}
|
||||
|
||||
async function pollProgress(id: number) {
|
||||
try {
|
||||
const vo = await fetchJdCollectProgress(id)
|
||||
progress.value = vo
|
||||
pollFailures = 0
|
||||
if (isTerminalTaskStatus(vo.status)) {
|
||||
applyTerminal(vo)
|
||||
return
|
||||
}
|
||||
} catch (err) {
|
||||
pollFailures += 1
|
||||
// 单次失败不打断轮询(网络抖动/切页);连续失败 5 次才把进度条挂上提示,
|
||||
// 异常原文只留 console(英文原文不进界面)。
|
||||
console.error('[jd-collect] 进度查询失败', err)
|
||||
if (pollFailures >= 5) {
|
||||
errorMessage.value = '进度查询连续失败,请检查网络;任务本身仍在客户端执行'
|
||||
}
|
||||
}
|
||||
if (Date.now() - pollStartedAt > POLL_TIMEOUT_MS) {
|
||||
stopPolling()
|
||||
errorMessage.value = '进度查询超时,请到客户端任务列表查看采集结果'
|
||||
return
|
||||
}
|
||||
pollTimer = window.setTimeout(() => {
|
||||
void pollProgress(id)
|
||||
}, POLL_INTERVAL_MS)
|
||||
}
|
||||
|
||||
/** 建单成功后推送本机队列;返回 null 表示环境无队列能力(浏览器预览),返回 string 表示失败原因。 */
|
||||
async function pushToClientQueue(
|
||||
taskId: number,
|
||||
shopName: string,
|
||||
id: number,
|
||||
shop: string,
|
||||
tabs: JdListTab[],
|
||||
maxProducts: number,
|
||||
): Promise<string | null> {
|
||||
const api = getPywebviewApi()
|
||||
if (!api?.enqueue_json) {
|
||||
@@ -43,7 +160,7 @@ async function pushToClientQueue(
|
||||
const payload = {
|
||||
type: 'jd-shop-collect-run',
|
||||
ts: Date.now(),
|
||||
data: { taskId, shopName, listTabs: tabs, maxProducts },
|
||||
data: { taskId: id, shopName: shop, listTabs: tabs, maxProducts: 0 },
|
||||
}
|
||||
const pushResult = await api.enqueue_json(payload)
|
||||
if (pushResult?.success) {
|
||||
@@ -56,191 +173,448 @@ async function pushToClientQueue(
|
||||
return '推送本机队列失败,任务将由客户端兜底拉取认领'
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
async function startCollect() {
|
||||
if (isRunning.value) return
|
||||
stopPolling()
|
||||
errorMessage.value = ''
|
||||
successMessage.value = ''
|
||||
const tabs = buildListTabs()
|
||||
if (!form.shopName.trim()) {
|
||||
errorMessage.value = '请填写要采集的京东店铺名称'
|
||||
return
|
||||
}
|
||||
if (!tabs.length) {
|
||||
errorMessage.value = '请至少勾选一个商品页签(在售中 / 已下架)'
|
||||
return
|
||||
}
|
||||
progress.value = null
|
||||
phase.value = 'running'
|
||||
submitting.value = true
|
||||
const shop = shopName.value.trim() || '京麦后台'
|
||||
const tabs: JdListTab[] = ['ONSALE', 'OFFSALE']
|
||||
try {
|
||||
const vo = await createJdCollectTask(form.shopName.trim(), tabs, form.maxProducts)
|
||||
const vo = await createJdCollectTask(shop, tabs, 0)
|
||||
taskId.value = vo.taskId
|
||||
let pushNote = ''
|
||||
try {
|
||||
const pushError = await pushToClientQueue(
|
||||
vo.taskId, form.shopName.trim(), tabs, form.maxProducts)
|
||||
if (pushError) {
|
||||
pushNote = ` ${pushError}`
|
||||
}
|
||||
const pushError = await pushToClientQueue(vo.taskId, shop, tabs)
|
||||
if (pushError) pushNote = ` ${pushError}`
|
||||
} catch (pushErr) {
|
||||
// 推送自身异常不回滚建单:任务可由服务端兜底拉取认领。
|
||||
// 异常原文(多为英文)不进界面——首条语句写界面文案(状态写入,扫描器口径非静默),
|
||||
// console 只作留链。
|
||||
pushNote = ' 推送本机队列失败,任务将由服务端兜底派发给本机客户端执行'
|
||||
console.error('[jd-collect] 推送本机队列失败', pushErr)
|
||||
}
|
||||
successMessage.value = `建单成功:任务号 ${vo.taskId}${vo.taskNo ? `(${vo.taskNo})` : ''}。` +
|
||||
'任务由本机客户端执行,请保持客户端在线并已登录京麦;采集进度在客户端任务列表查看,' +
|
||||
'落库数据到后台「京东数据库」菜单查询。' + pushNote
|
||||
if (pushNote) {
|
||||
errorMessage.value = pushNote.trim()
|
||||
}
|
||||
pollStartedAt = Date.now()
|
||||
pollFailures = 0
|
||||
void pollProgress(vo.taskId)
|
||||
} catch (err) {
|
||||
phase.value = 'failed'
|
||||
errorMessage.value = err instanceof Error ? err.message : '建单失败,请稍后重试'
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const localName = (window.localStorage.getItem('username') || '').trim()
|
||||
if (localName) username.value = localName
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopPolling()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="jd-collect-page">
|
||||
<div class="jd-collect-panel">
|
||||
<h2>京东采集</h2>
|
||||
<p class="jd-collect-desc">
|
||||
采集京东店铺商品(列表 + 详情全部属性 + 图片),同步到后台「京东数据库」。
|
||||
任务由本机客户端执行:提交后请保持客户端在线,并确保已在客户端登录京麦。
|
||||
</p>
|
||||
<div class="page-shell module-page jd-collect-page">
|
||||
<header class="jd-top">
|
||||
<router-link class="home-back" :to="homeHref" title="返回首页">← 返回首页</router-link>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="jd-shop-name">京东店铺名称</label>
|
||||
<input
|
||||
id="jd-shop-name"
|
||||
v-model="form.shopName"
|
||||
type="text"
|
||||
placeholder="填写京麦后台显示的店铺名称"
|
||||
:disabled="submitting"
|
||||
/>
|
||||
<div class="brand">
|
||||
<span class="brand-logo">富</span>
|
||||
<span class="brand-text">
|
||||
<span class="brand-name">数富AI</span>
|
||||
<span class="brand-sub">京东运营工具台</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>采集商品页签</label>
|
||||
<div class="tab-checks">
|
||||
<label class="tab-check">
|
||||
<input v-model="form.onsale" type="checkbox" :disabled="submitting" />
|
||||
在售中
|
||||
</label>
|
||||
<label class="tab-check">
|
||||
<input v-model="form.offsale" type="checkbox" :disabled="submitting" />
|
||||
已下架
|
||||
</label>
|
||||
</div>
|
||||
<div class="top-right">
|
||||
<NotificationBell />
|
||||
<span class="admin-name">{{ username }}</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="jd-max-products">采集商品数上限(0 = 不限制)</label>
|
||||
<input
|
||||
id="jd-max-products"
|
||||
v-model.number="form.maxProducts"
|
||||
type="number"
|
||||
min="0"
|
||||
:disabled="submitting"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button class="jd-submit" type="button" :disabled="submitting" @click="submit">
|
||||
{{ submitting ? '提交中…' : '开始采集' }}
|
||||
</button>
|
||||
|
||||
<p v-if="successMessage" class="jd-feedback success">{{ successMessage }}</p>
|
||||
<p v-if="errorMessage" class="jd-feedback error">{{ errorMessage }}</p>
|
||||
<div class="tool-head">
|
||||
<router-link class="tool-head__back" :to="backHref">← 返回京东工具台</router-link>
|
||||
<span class="tool-head__title">获取店铺数据</span>
|
||||
<span class="tool-head__desc">
|
||||
一键抓取已登录京麦后台的店铺商品(列表 + 详情全部属性 + 图片),导入后台「京东数据库」。
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<main class="jd-body">
|
||||
<div class="collect-card">
|
||||
<div class="form-group">
|
||||
<label for="jd-shop-name">店铺名称(可选)</label>
|
||||
<input
|
||||
id="jd-shop-name"
|
||||
v-model="shopName"
|
||||
type="text"
|
||||
placeholder="留空按「京麦后台」记录;填了便于在后台「京东数据库」区分店铺"
|
||||
:disabled="isRunning"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button class="collect-btn" type="button" :disabled="isRunning" @click="startCollect">
|
||||
{{ isRunning ? '获取中…' : '一键获取店铺数据' }}
|
||||
</button>
|
||||
|
||||
<p class="collect-hint">
|
||||
点击后本机客户端会自动打开已登录的京麦后台采集商品,请保持客户端在线且京麦已登录;
|
||||
采集到的数据会实时回传并导入后台。
|
||||
</p>
|
||||
|
||||
<section v-if="taskId" class="progress-block">
|
||||
<div class="progress-head">
|
||||
<span class="progress-status">{{ statusText }}</span>
|
||||
<span v-if="percentText" class="progress-percent">{{ percentText }}</span>
|
||||
</div>
|
||||
<div class="progress-track">
|
||||
<div
|
||||
class="progress-fill"
|
||||
:class="{ 'progress-fill--indeterminate': percent === null && phase === 'running' }"
|
||||
:style="percent === null ? undefined : { width: `${percent}%` }"
|
||||
></div>
|
||||
</div>
|
||||
<div v-if="progressMeta" class="progress-meta">{{ progressMeta }}</div>
|
||||
</section>
|
||||
|
||||
<p v-if="successMessage" class="feedback success">{{ successMessage }}</p>
|
||||
<p v-if="errorMessage" class="feedback error">{{ errorMessage }}</p>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.jd-collect-page {
|
||||
padding: 24px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
background-color: #1a1f2e;
|
||||
background-image: radial-gradient(rgba(45, 212, 191, 0.08) 1px, transparent 1px);
|
||||
background-size: 48px 48px;
|
||||
font-family: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", sans-serif;
|
||||
}
|
||||
|
||||
.jd-top {
|
||||
flex: 0 0 auto;
|
||||
min-height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 20px;
|
||||
padding: 0 28px;
|
||||
background: #1a1f2e;
|
||||
border-bottom: 1px solid #3e4a62;
|
||||
}
|
||||
|
||||
.home-back {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 6px;
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.home-back:hover {
|
||||
background: #2b3447;
|
||||
color: #f5f8fc;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.brand-logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
border-radius: 8px;
|
||||
background: #e1251b;
|
||||
color: #fff;
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
box-shadow: 0 2px 8px rgba(225, 37, 27, 0.32);
|
||||
}
|
||||
|
||||
.brand-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.brand-name {
|
||||
color: #f5f8fc;
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.brand-sub {
|
||||
color: #a0acbe;
|
||||
font-size: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.top-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.admin-name {
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tool-head {
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 20px;
|
||||
min-height: 62px;
|
||||
padding: 10px 34px;
|
||||
background: #1a1f2e;
|
||||
}
|
||||
|
||||
.tool-head__back {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 6px;
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tool-head__back:hover {
|
||||
background: #2b3447;
|
||||
color: #f5f8fc;
|
||||
}
|
||||
|
||||
.tool-head__title {
|
||||
flex-shrink: 0;
|
||||
color: #f5f8fc;
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tool-head__desc {
|
||||
min-width: 0;
|
||||
max-width: 760px;
|
||||
color: #a0acbe;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.jd-body {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 4px 34px 40px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
/* 卡片按内容高度收口:flex 默认 stretch 会把它拉到整屏,空白比内容还长 */
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.jd-collect-panel {
|
||||
.collect-card {
|
||||
width: 100%;
|
||||
max-width: 560px;
|
||||
background: #fff;
|
||||
border: 1px solid #e5e7eb;
|
||||
max-width: 720px;
|
||||
padding: 26px 28px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 12px;
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
.jd-collect-desc {
|
||||
color: #6b7280;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
margin: 8px 0 20px;
|
||||
background: #232a3b;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
margin-bottom: 16px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.form-group label {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
color: #374151;
|
||||
margin-bottom: 6px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.form-group input[type='text'],
|
||||
.form-group input[type='number'] {
|
||||
.form-group input[type='text'] {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
border: 1px solid #d1d5db;
|
||||
padding: 10px 12px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 8px;
|
||||
padding: 8px 10px;
|
||||
background: #1a1f2e;
|
||||
color: #f5f8fc;
|
||||
font-size: 14px;
|
||||
outline: none;
|
||||
transition: border-color 0.2s;
|
||||
}
|
||||
|
||||
.tab-checks {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
.form-group input[type='text']:focus {
|
||||
border-color: #e1251b;
|
||||
}
|
||||
|
||||
.tab-check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 14px;
|
||||
color: #374151;
|
||||
margin-bottom: 0;
|
||||
.form-group input[type='text']::placeholder {
|
||||
color: #6b778d;
|
||||
}
|
||||
|
||||
.jd-submit {
|
||||
.collect-btn {
|
||||
width: 100%;
|
||||
background: #2dd4bf;
|
||||
color: #062a26;
|
||||
padding: 13px 0;
|
||||
border: none;
|
||||
border-radius: 8px;
|
||||
padding: 10px 0;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
background: linear-gradient(135deg, #ff5a4f, #e1251b);
|
||||
color: #ffffff;
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 16px rgba(225, 37, 27, 0.32);
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.jd-submit:disabled {
|
||||
.collect-btn:hover:not(:disabled) {
|
||||
filter: brightness(1.1);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.collect-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.jd-feedback {
|
||||
margin-top: 16px;
|
||||
.collect-hint {
|
||||
margin: 12px 0 0;
|
||||
color: #a0acbe;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
/* ===== 进度条 ===== */
|
||||
.progress-block {
|
||||
margin-top: 22px;
|
||||
padding: 16px 18px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 10px;
|
||||
background: #1f2637;
|
||||
}
|
||||
|
||||
.progress-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.progress-status {
|
||||
color: #f5f8fc;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.progress-percent {
|
||||
color: #ff8a80;
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.progress-track {
|
||||
position: relative;
|
||||
height: 12px;
|
||||
overflow: hidden;
|
||||
border-radius: 999px;
|
||||
background: #11161f;
|
||||
border: 1px solid #2a3344;
|
||||
}
|
||||
|
||||
.progress-fill {
|
||||
height: 100%;
|
||||
width: 0;
|
||||
border-radius: 999px;
|
||||
background: linear-gradient(90deg, #ff7a70, #e1251b);
|
||||
transition: width 0.4s ease;
|
||||
}
|
||||
|
||||
/* 没有 total(客户端还没抓到列表首页)时走不定态:不编造百分比 */
|
||||
.progress-fill--indeterminate {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 40%;
|
||||
animation: jd-progress-indeterminate 1.2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
@keyframes jd-progress-indeterminate {
|
||||
0% {
|
||||
transform: translateX(-100%);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(250%);
|
||||
}
|
||||
}
|
||||
|
||||
.progress-meta {
|
||||
margin-top: 10px;
|
||||
color: #a0acbe;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.feedback {
|
||||
margin: 16px 0 0;
|
||||
padding: 10px 12px;
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
border-radius: 8px;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.jd-feedback.success {
|
||||
background: #ecfdf5;
|
||||
color: #047857;
|
||||
.feedback.success {
|
||||
background: rgba(16, 185, 129, 0.12);
|
||||
color: #6ee7b7;
|
||||
}
|
||||
|
||||
.jd-feedback.error {
|
||||
background: #fef2f2;
|
||||
color: #b91c1c;
|
||||
.feedback.error {
|
||||
background: rgba(248, 113, 113, 0.12);
|
||||
color: #fca5a5;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.tool-head {
|
||||
padding: 10px 16px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.jd-body {
|
||||
padding: 4px 16px 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,462 @@
|
||||
<template>
|
||||
<div class="page-shell module-page jd-console">
|
||||
<header class="jd-top">
|
||||
<router-link class="home-back" :to="homeHref" title="返回首页">← 返回首页</router-link>
|
||||
|
||||
<div class="brand">
|
||||
<span class="brand-logo">富</span>
|
||||
<span class="brand-text">
|
||||
<span class="brand-name">数富AI</span>
|
||||
<span class="brand-sub">京东运营工具台</span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="top-right">
|
||||
<NotificationBell />
|
||||
<span class="admin-name">{{ username }}</span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main class="jd-body">
|
||||
<section class="jd-hero">
|
||||
<span class="hero-pill">店铺采集 · 商品上架</span>
|
||||
<h1 class="hero-title">京东运营,一键开始</h1>
|
||||
<p class="hero-sub">
|
||||
获取店铺数据只需一次点击:本机客户端会自动打开已登录的京麦后台抓取商品,
|
||||
实时回传进度并把数据导入后台「京东数据库」。商品上架正在建设中。
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<header class="group-head">
|
||||
<i class="group-dot"></i>
|
||||
<span class="group-name">京东工具</span>
|
||||
<span class="group-desc">采集与上架,两条主线</span>
|
||||
<span class="group-count">{{ JD_TOOLS.length }} 个工具</span>
|
||||
</header>
|
||||
|
||||
<div class="card-grid">
|
||||
<template v-for="tool in JD_TOOLS" :key="tool.id">
|
||||
<router-link
|
||||
v-if="tool.href"
|
||||
:to="tool.href"
|
||||
class="tool-card"
|
||||
>
|
||||
<div class="tool-card-top">
|
||||
<span class="tool-icon">
|
||||
<svg viewBox="0 0 48 48" aria-hidden="true">
|
||||
<rect x="10" y="8" width="28" height="24" />
|
||||
<line x1="24" y1="14" x2="24" y2="36" />
|
||||
<path class="fill" d="M19 33 L29 33 L24 38 Z" />
|
||||
</svg>
|
||||
</span>
|
||||
<span v-if="tool.tag" class="tool-tag">{{ tool.tag }}</span>
|
||||
</div>
|
||||
<div class="tool-card-name">{{ tool.name }}</div>
|
||||
<div class="tool-card-desc">{{ tool.desc }}</div>
|
||||
<div class="tool-card-go">打开工具 →</div>
|
||||
</router-link>
|
||||
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="tool-card tool-card--pending"
|
||||
@click="onPendingClick(tool)"
|
||||
>
|
||||
<div class="tool-card-top">
|
||||
<span class="tool-icon tool-icon--pending">
|
||||
<svg viewBox="0 0 48 48" aria-hidden="true">
|
||||
<rect x="10" y="16" width="28" height="24" />
|
||||
<line x1="24" y1="34" x2="24" y2="12" />
|
||||
<path class="fill" d="M19 15 L29 15 L24 10 Z" />
|
||||
</svg>
|
||||
</span>
|
||||
<span v-if="tool.tag" class="tool-tag">{{ tool.tag }}</span>
|
||||
</div>
|
||||
<div class="tool-card-name">{{ tool.name }}</div>
|
||||
<div class="tool-card-desc">{{ tool.desc }}</div>
|
||||
<div class="tool-card-go">暂未开通</div>
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<div class="toast" :class="{ show: Boolean(toastText) }">{{ toastText }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
|
||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||
import { resolvePageHref } from '@/shared/page-prefix'
|
||||
import { JD_TOOLS, type JdToolInfo } from '@/pages/jd/tool-catalog'
|
||||
|
||||
/** 返回桌面入口首页(亚马逊 / 京东 / 视频 一级入口) */
|
||||
const homeHref = resolvePageHref('/new_web_source/home.html')
|
||||
|
||||
const username = ref('admin')
|
||||
const toastText = ref('')
|
||||
let toastTimer: number | undefined
|
||||
|
||||
function showToast(message: string) {
|
||||
toastText.value = message
|
||||
if (toastTimer) {
|
||||
window.clearTimeout(toastTimer)
|
||||
}
|
||||
toastTimer = window.setTimeout(() => {
|
||||
toastText.value = ''
|
||||
toastTimer = undefined
|
||||
}, 2500)
|
||||
}
|
||||
|
||||
/** 占位菜单(商品上架):没有 href 的卡片点开只提示,不做任何请求。 */
|
||||
function onPendingClick(tool: JdToolInfo) {
|
||||
showToast(`${tool.name}暂未开通,敬请期待`)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const localName = (window.localStorage.getItem('username') || '').trim()
|
||||
if (localName) username.value = localName
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (toastTimer !== undefined) {
|
||||
window.clearTimeout(toastTimer)
|
||||
toastTimer = undefined
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.jd-console {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 100vh;
|
||||
background-color: #1a1f2e;
|
||||
background-image: radial-gradient(rgba(45, 212, 191, 0.08) 1px, transparent 1px);
|
||||
background-size: 48px 48px;
|
||||
font-family: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", sans-serif;
|
||||
}
|
||||
|
||||
/* ===== 顶栏(同亚马逊工作台形状,品牌副标题换成京东) ===== */
|
||||
.jd-top {
|
||||
flex: 0 0 auto;
|
||||
min-height: 64px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 20px;
|
||||
padding: 0 28px;
|
||||
background: #1a1f2e;
|
||||
border-bottom: 1px solid #3e4a62;
|
||||
}
|
||||
|
||||
.home-back {
|
||||
flex-shrink: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 14px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 6px;
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.home-back:hover {
|
||||
background: #2b3447;
|
||||
color: #f5f8fc;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.brand-logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
border-radius: 8px;
|
||||
background: #e1251b;
|
||||
color: #fff;
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
box-shadow: 0 2px 8px rgba(225, 37, 27, 0.32);
|
||||
}
|
||||
|
||||
.brand-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.brand-name {
|
||||
color: #f5f8fc;
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.brand-sub {
|
||||
color: #a0acbe;
|
||||
font-size: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.top-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.admin-name {
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ===== 主体 ===== */
|
||||
.jd-body {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding: 14px 28px 28px;
|
||||
}
|
||||
|
||||
.jd-hero {
|
||||
max-width: 1440px;
|
||||
margin: 0 auto 20px;
|
||||
padding: 26px 30px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 12px;
|
||||
background: #232a3b;
|
||||
}
|
||||
|
||||
.hero-pill {
|
||||
display: inline-block;
|
||||
margin-bottom: 12px;
|
||||
padding: 4px 12px;
|
||||
border: 1px solid rgba(225, 37, 27, 0.3);
|
||||
border-radius: 20px;
|
||||
background: #3a1a18;
|
||||
color: #ff8a80;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.hero-title {
|
||||
margin: 0 0 8px;
|
||||
color: #f5f8fc;
|
||||
font-size: 26px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.hero-sub {
|
||||
max-width: 720px;
|
||||
margin: 0;
|
||||
color: #c8d2e2;
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.group-head {
|
||||
max-width: 1440px;
|
||||
margin: 0 auto 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.group-dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 2px;
|
||||
background: #e1251b;
|
||||
}
|
||||
|
||||
.group-name {
|
||||
color: #f5f8fc;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.group-desc {
|
||||
color: #a0acbe;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.group-count {
|
||||
margin-left: auto;
|
||||
color: #a0acbe;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* ===== 卡片墙(同亚马逊 tool-card 形状) ===== */
|
||||
.card-grid {
|
||||
max-width: 1440px;
|
||||
margin: 0 auto 28px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.tool-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
min-width: 0;
|
||||
min-height: 165px;
|
||||
padding: 16px;
|
||||
border: 2px solid #2a3344;
|
||||
border-radius: 10px;
|
||||
background: #2b3447;
|
||||
text-align: left;
|
||||
text-decoration: none;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.tool-card:hover {
|
||||
background: #323d52;
|
||||
border-color: #e1251b;
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.tool-card-top {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.tool-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
border-radius: 10px;
|
||||
background: linear-gradient(180deg, #ff7a70, #e1251b);
|
||||
}
|
||||
|
||||
.tool-icon svg {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
fill: none;
|
||||
stroke: #fff;
|
||||
stroke-width: 3;
|
||||
stroke-linecap: butt;
|
||||
}
|
||||
|
||||
.tool-icon svg .fill {
|
||||
fill: #fff;
|
||||
stroke: none;
|
||||
}
|
||||
|
||||
.tool-icon--pending {
|
||||
background: linear-gradient(180deg, #6b778d, #4a5568);
|
||||
}
|
||||
|
||||
.tool-tag {
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
background: #3a1a18;
|
||||
color: #ff8a80;
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tool-card:hover .tool-tag {
|
||||
background: #e1251b;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.tool-card-name {
|
||||
margin-bottom: 6px;
|
||||
color: #f5f8fc;
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.tool-card-desc {
|
||||
flex: 1;
|
||||
color: #a0acbe;
|
||||
font-size: 11px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.tool-card-go {
|
||||
margin-top: 12px;
|
||||
color: #a0acbe;
|
||||
font-size: 11px;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
.tool-card:hover .tool-card-go {
|
||||
color: #ff8a80;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.tool-card--pending {
|
||||
cursor: default;
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.tool-card--pending:hover {
|
||||
border-color: #2a3344;
|
||||
background: #2b3447;
|
||||
transform: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.tool-card--pending:hover .tool-card-go {
|
||||
color: #a0acbe;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
/* ===== toast ===== */
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 60px;
|
||||
right: 30px;
|
||||
z-index: 1000;
|
||||
max-width: min(420px, calc(100vw - 60px));
|
||||
padding: 12px 20px;
|
||||
border-radius: 6px;
|
||||
border-left: 4px solid #f59e0b;
|
||||
background: #3d4a63;
|
||||
color: #f5f8fc;
|
||||
font-size: 13px;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.3s;
|
||||
}
|
||||
|
||||
.toast.show {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.card-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
|
||||
.jd-body {
|
||||
padding: 14px 16px 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 京东运营工具台 · 工具目录
|
||||
*
|
||||
* 一级入口在桌面首页(与「亚马逊 / 视频」并列,见 DesktopHomePage),进来后是这两个菜单:
|
||||
* 1. 获取店铺数据:一键抓已登录京麦后台的店铺商品(列表 + 详情 + 图片),落后台「京东数据库」;
|
||||
* 2. 商品上架:功能未落地,先按"假菜单"占位(点击提示暂未开通),不发 href。
|
||||
*
|
||||
* 卡片形状照亚马逊工具台(tool-catalog.ts)的 ToolInfo,样式复用同一套深色卡片墙。
|
||||
*/
|
||||
|
||||
export type JdToolInfo = {
|
||||
/** 工具 id */
|
||||
id: string
|
||||
/** 菜单名称 */
|
||||
name: string
|
||||
/** 卡片一句话描述 */
|
||||
desc: string
|
||||
/** 角标文字(无则不显示) */
|
||||
tag?: string
|
||||
/** 功能页地址;未提供表示暂未开通(占位菜单) */
|
||||
href?: string
|
||||
}
|
||||
|
||||
export const JD_TOOLS: ReadonlyArray<JdToolInfo> = [
|
||||
{
|
||||
id: 'jd-collect',
|
||||
name: '获取店铺数据',
|
||||
desc: '一键抓取已登录京麦后台的店铺商品(列表 + 详情全部属性 + 图片),导入后台「京东数据库」',
|
||||
tag: '核心',
|
||||
href: '/jd-collect',
|
||||
},
|
||||
{
|
||||
id: 'jd-publish',
|
||||
name: '商品上架',
|
||||
desc: '把京东数据库里的商品批量上架到京麦店铺(建设中,敬请期待)',
|
||||
tag: '规划中',
|
||||
},
|
||||
]
|
||||
|
||||
export const JD_TOOL_MAP: ReadonlyMap<string, JdToolInfo> = new Map(
|
||||
JD_TOOLS.map((tool) => [tool.id, tool] as const),
|
||||
)
|
||||
@@ -67,6 +67,12 @@ const routes = [
|
||||
name: 'appearance-patent',
|
||||
component: () => import('@/pages/brand/components/BrandAppearancePatentTab.vue'),
|
||||
},
|
||||
// ---- 京东运营工具台(首页一级入口「京东」的落地页)----
|
||||
{
|
||||
path: '/jd-console',
|
||||
name: 'jd-console',
|
||||
component: () => import('@/pages/jd/JdConsolePage.vue'),
|
||||
},
|
||||
{
|
||||
path: '/jd-collect',
|
||||
name: 'jd-collect',
|
||||
|
||||
@@ -207,6 +207,8 @@ export const API_ENDPOINTS = {
|
||||
/** 京东店铺商品采集(v1.4):建单走 LOCAL 通道,由本机客户端在已登录京麦的窗口内执行。 */
|
||||
jdCollect: {
|
||||
create: '/api/jd-collect/tasks',
|
||||
/** 采集进度(用户端「获取店铺数据」进度条数据源) */
|
||||
progress: '/api/jd-collect/tasks/{taskId}/progress',
|
||||
heartbeat: '/api/jd-collect/tasks/{taskId}/heartbeat',
|
||||
chunk: '/api/jd-collect/tasks/{taskId}/chunk',
|
||||
},
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { post, type JavaApiResponse, unwrapJavaResponse } from '../../http.ts'
|
||||
import { get, post, type JavaApiResponse, unwrapJavaResponse } from '../../http.ts'
|
||||
import { buildJavaUrl } from '../../url.ts'
|
||||
import { getCurrentUserId } from '../../user.ts'
|
||||
import { API_ENDPOINTS } from '../../endpoints.ts'
|
||||
import { getTaskProgressTimeoutMs } from '../../../task-progress-config.ts'
|
||||
|
||||
/** 京东店铺采集建单回执(蓝图 §3.2):任务落 PENDING、执行通道固定 LOCAL,由本机客户端领取执行。 */
|
||||
export interface JdCollectTaskVo {
|
||||
@@ -17,6 +18,35 @@ export type JdListTab = 'ONSALE' | 'OFFSALE'
|
||||
* 建单(v1.4 AC-1):选择店铺 + 商品 Tab + 采集范围。未选店铺 / 未登记京麦登录态时
|
||||
* 服务端按蓝图 §3.2 拒绝并返回点名文案(业务码信封,unwrapJavaResponse 抛出)。
|
||||
*/
|
||||
/**
|
||||
* 采集进度回执(v1.5「获取店铺数据」进度条)。
|
||||
*
|
||||
* `total` 只在客户端抓过列表首页、把 total 写进合并写游标之后才有值;为 null 时页面
|
||||
* 用不定态进度条,不编造百分比。`itemsReceived` 是服务端已落库的商品数(慢一拍于客户端
|
||||
* 本地计数,这是它诚实的代价——界面不该拿本地内存数冒充后台进度)。
|
||||
*/
|
||||
export interface JdCollectProgressVo {
|
||||
taskId: number;
|
||||
status: string;
|
||||
itemsReceived: number | null;
|
||||
total: number | null;
|
||||
page: number | null;
|
||||
listTab: string | null;
|
||||
batches: number | null;
|
||||
message: string | null;
|
||||
updatedAt: string | null;
|
||||
}
|
||||
|
||||
/** 轮询采集进度:uid 与建单同口径(会话身份),任务 owner 不一致服务端直接拒。 */
|
||||
export function fetchJdCollectProgress(taskId: number) {
|
||||
const path = buildJavaUrl(API_ENDPOINTS.jdCollect.progress.replace('{taskId}', String(taskId)))
|
||||
const query = `?user_id=${encodeURIComponent(String(getCurrentUserId()))}`
|
||||
return unwrapJavaResponse(get<JavaApiResponse<JdCollectProgressVo>>(path + query, {
|
||||
// 进度请求按短超时:轮询里一次挂住会把进度条一起冻住(同 progress/light 口径)。
|
||||
timeout: getTaskProgressTimeoutMs(),
|
||||
}))
|
||||
}
|
||||
|
||||
export function createJdCollectTask(shopName: string, listTabs: JdListTab[], maxProducts = 0) {
|
||||
return unwrapJavaResponse(post<JavaApiResponse<JdCollectTaskVo>, Record<string, unknown>>(
|
||||
buildJavaUrl(API_ENDPOINTS.jdCollect.create),
|
||||
|
||||
@@ -70,7 +70,10 @@ const BASELINE = {
|
||||
// 页面推送包一支 try/catch(P0-1 派发链)——推送失败/桥不可用时 pushNote 附一句提示、
|
||||
// 建单照常保留(判据:推送是尽力而为的快路径,失败回滚建单反而丢单)。错误进了界面
|
||||
// 文案,非静默;silent 一格没涨。
|
||||
blocks: 314,
|
||||
// 315 = 314 + 1(2026-11-14 v1.5「获取店铺数据」进度条):JdCollectTab.vue 的
|
||||
// pollProgress 轮询 catch——单次进度查询失败不打断轮询(网络抖动/切页),
|
||||
// 连续 5 次才把一句中文提示写进 errorMessage,异常原文只进 console;非静默。
|
||||
blocks: 315,
|
||||
// 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处
|
||||
// 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进
|
||||
// useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动,
|
||||
|
||||
@@ -314,8 +314,10 @@ test('test_endpoints_frozen_snapshot', () => {
|
||||
},
|
||||
// 2026-11-14 v1.4 京东数据库:三支端点(建单/心跳/分片回传)随 Phase 3 落码,
|
||||
// 冻结快照只许显式追加——端点漂移会让"新开一条匿名可达口"没人看见。
|
||||
// 2026-11-14 v1.5:progress(进度条数据源,鉴权与建单同口径:uid 会话身份 + owner 校验)。
|
||||
"jdCollect": {
|
||||
"create": "/api/jd-collect/tasks",
|
||||
"progress": "/api/jd-collect/tasks/{taskId}/progress",
|
||||
"heartbeat": "/api/jd-collect/tasks/{taskId}/heartbeat",
|
||||
"chunk": "/api/jd-collect/tasks/{taskId}/chunk"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { existsSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { JD_TOOLS, JD_TOOL_MAP } from '../src/pages/jd/tool-catalog.ts'
|
||||
|
||||
/** 京东一级入口(v1.5):首页「京东」→ 京东工作台两个菜单(获取店铺数据 / 商品上架占位)。 */
|
||||
|
||||
const ROOT = process.cwd()
|
||||
|
||||
function read(relativePath: string): string {
|
||||
const path = join(ROOT, relativePath)
|
||||
assert.ok(existsSync(path), `文件缺失:${path}`)
|
||||
return readFileSync(path, 'utf8')
|
||||
}
|
||||
|
||||
test('京东工作台只有两个菜单:获取店铺数据 + 商品上架', () => {
|
||||
assert.equal(JD_TOOLS.length, 2, '京东工作台菜单数应为 2')
|
||||
const names = JD_TOOLS.map((tool) => tool.name)
|
||||
assert.deepEqual(names, ['获取店铺数据', '商品上架'])
|
||||
assert.equal(new Set(JD_TOOLS.map((tool) => tool.id)).size, 2, '工具 id 不应重复')
|
||||
assert.ok(JD_TOOL_MAP.get('jd-collect'), 'JD_TOOL_MAP 应按 id 命中获取店铺数据')
|
||||
})
|
||||
|
||||
test('获取店铺数据指向采集页,商品上架先做占位菜单', () => {
|
||||
const collect = JD_TOOLS.find((tool) => tool.id === 'jd-collect')
|
||||
const publish = JD_TOOLS.find((tool) => tool.id === 'jd-publish')
|
||||
assert.equal(collect?.href, '/jd-collect', '获取店铺数据应指向 /jd-collect')
|
||||
assert.equal(publish?.href, undefined, '商品上架先做假菜单:不得挂路由')
|
||||
})
|
||||
|
||||
test('路由器注册京东工作台与采集页', () => {
|
||||
const router = read('src/router/index.ts')
|
||||
assert.ok(router.includes("path: '/jd-console'"), 'router 缺 /jd-console')
|
||||
assert.ok(router.includes('JdConsolePage.vue'), 'router 未指向 JdConsolePage')
|
||||
assert.ok(router.includes("path: '/jd-collect'"), 'router 缺 /jd-collect')
|
||||
})
|
||||
|
||||
test('首页京东入口与亚马逊/视频并列', () => {
|
||||
const home = read('src/pages/home/DesktopHomePage.vue')
|
||||
assert.ok(home.includes('jd-console.html'), '首页京东入口未指向京东工作台')
|
||||
assert.ok(/>京东</.test(home), '首页缺「京东」按钮文字')
|
||||
})
|
||||
|
||||
test('获取店铺数据页是一键触发 + 服务端进度条', () => {
|
||||
const page = read('src/pages/jd/JdCollectTab.vue')
|
||||
assert.ok(page.includes('fetchJdCollectProgress'), '采集页必须轮询服务端进度(不拿本地内存数充进度)')
|
||||
assert.ok(page.includes('progress-track'), '采集页缺进度条轨道')
|
||||
assert.ok(page.includes('jd-progress-indeterminate'),
|
||||
'拿不到 total 时必须走不定态进度条,不得编造百分比')
|
||||
assert.ok(page.includes('一键获取店铺数据'), '主按钮应是一键获取')
|
||||
assert.ok(page.includes('jd-shop-collect-run'), '建单后必须推送本机客户端队列')
|
||||
})
|
||||
@@ -0,0 +1,179 @@
|
||||
/**
|
||||
* 「获取店铺数据」一键采集 + 进度条挂载用例(v1.5)。
|
||||
*
|
||||
* 用户口径原话:「获取店铺就是点击获取后就自动抓已打开的京麦后台的店铺数据导入到后台 需要有进度条」。
|
||||
* 四组靶子,缺一条就是假绿:
|
||||
* ① 点一次按钮就走完整链路:建单 → 把 `jd-shop-collect-run` 推进本机客户端队列;
|
||||
* ② 有 total 时进度条按已落库商品数算出真实百分比(分母只来自服务端游标,不编造);
|
||||
* ③ total 缺失时走不定态动画(没有分母就不许编一个假百分比);
|
||||
* ④ 终态即收手:SUCCESS 落 100% + 导入完成文案,FAILED 用服务端原因,两种情况都不再轮询。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/jd-collect-progress.mount.test.ts`
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
|
||||
import JdCollectTab from '@/pages/jd/JdCollectTab.vue'
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
createJdCollectTask: vi.fn(),
|
||||
fetchJdCollectProgress: vi.fn(),
|
||||
enqueue: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/shared/api/types/modules/jd-collect', () => ({
|
||||
createJdCollectTask: api.createJdCollectTask,
|
||||
fetchJdCollectProgress: api.fetchJdCollectProgress,
|
||||
}))
|
||||
vi.mock('@/shared/bridges/pywebview', () => ({
|
||||
getPywebviewApi: () => ({ enqueue_json: api.enqueue }),
|
||||
}))
|
||||
|
||||
const POLL_MS = 2000
|
||||
|
||||
let wrapper: VueWrapper | null = null
|
||||
|
||||
function baseProgress(over: Record<string, unknown> = {}) {
|
||||
return {
|
||||
taskId: 88,
|
||||
status: 'RUNNING',
|
||||
itemsReceived: 30,
|
||||
total: 100,
|
||||
page: 2,
|
||||
listTab: 'ONSALE',
|
||||
batches: 1,
|
||||
message: null,
|
||||
updatedAt: null,
|
||||
...over,
|
||||
}
|
||||
}
|
||||
|
||||
async function mountPage() {
|
||||
wrapper = mount(JdCollectTab, {
|
||||
global: {
|
||||
stubs: {
|
||||
NotificationBell: true,
|
||||
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
},
|
||||
},
|
||||
})
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
async function startCollect(w: VueWrapper) {
|
||||
await w.find('.collect-btn').trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
localStorage.setItem('username', 'admin')
|
||||
api.createJdCollectTask.mockReset()
|
||||
api.fetchJdCollectProgress.mockReset()
|
||||
api.enqueue.mockReset()
|
||||
api.createJdCollectTask.mockResolvedValue({ taskId: 88, taskNo: 'JD-1', collectChannel: 'LOCAL' })
|
||||
api.enqueue.mockResolvedValue({ success: true })
|
||||
vi.spyOn(console, 'error').mockImplementation(() => {})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = null
|
||||
vi.useRealTimers()
|
||||
vi.restoreAllMocks()
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
describe('获取店铺数据:一键采集 + 进度条', () => {
|
||||
it('点一次按钮就建单并把采集载荷推进本机客户端队列', async () => {
|
||||
api.fetchJdCollectProgress.mockResolvedValue(baseProgress())
|
||||
const w = await mountPage()
|
||||
await startCollect(w)
|
||||
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledTimes(1)
|
||||
// 店铺名留空 → 按「京麦后台」记录(与后端 shop_name 语义一致)
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0)
|
||||
expect(api.enqueue).toHaveBeenCalledTimes(1)
|
||||
const payload = api.enqueue.mock.calls[0][0]
|
||||
expect(payload.type).toBe('jd-shop-collect-run')
|
||||
expect(payload.data).toEqual({
|
||||
taskId: 88,
|
||||
shopName: '京麦后台',
|
||||
listTabs: ['ONSALE', 'OFFSALE'],
|
||||
maxProducts: 0,
|
||||
})
|
||||
})
|
||||
|
||||
it('有 total 时按已落库商品数显示真实百分比与进度元信息', async () => {
|
||||
api.fetchJdCollectProgress.mockResolvedValue(baseProgress())
|
||||
const w = await mountPage()
|
||||
await startCollect(w)
|
||||
|
||||
expect(w.find('.progress-track').exists()).toBe(true)
|
||||
expect(w.find('.progress-percent').text()).toBe('30%')
|
||||
const fill = w.find('.progress-fill')
|
||||
expect(fill.attributes('style')).toContain('width: 30%')
|
||||
expect(fill.classes()).not.toContain('progress-fill--indeterminate')
|
||||
expect(w.find('.progress-meta').text()).toBe('已采集 30 个商品 · 共 100 个 · 第 2 页 · 已回传 1 批')
|
||||
expect(w.find('.progress-status').text()).toBe('正在获取店铺数据…')
|
||||
})
|
||||
|
||||
it('没有分母(total 缺失)时走不定态动画,不编造百分比', async () => {
|
||||
api.fetchJdCollectProgress.mockResolvedValue(baseProgress({ total: null, page: null, batches: 0 }))
|
||||
const w = await mountPage()
|
||||
await startCollect(w)
|
||||
|
||||
expect(w.find('.progress-percent').exists()).toBe(false)
|
||||
expect(w.find('.progress-fill').classes()).toContain('progress-fill--indeterminate')
|
||||
expect(w.find('.progress-meta').text()).toBe('已采集 30 个商品')
|
||||
})
|
||||
|
||||
it('SUCCESS 终态:进度满格并提示已导入后台,且停止轮询', async () => {
|
||||
api.fetchJdCollectProgress.mockResolvedValue(baseProgress({ itemsReceived: 100 }))
|
||||
const w = await mountPage()
|
||||
await startCollect(w)
|
||||
|
||||
api.fetchJdCollectProgress.mockResolvedValue(
|
||||
baseProgress({ status: 'SUCCESS', itemsReceived: 100 }),
|
||||
)
|
||||
await vi.advanceTimersByTimeAsync(POLL_MS)
|
||||
await flushPromises()
|
||||
|
||||
expect(w.find('.progress-percent').text()).toBe('100%')
|
||||
expect(w.find('.progress-status').text()).toBe('获取完成')
|
||||
expect(w.find('.feedback.success').text()).toContain('已导入后台「京东数据库」')
|
||||
const callsAfterTerminal = api.fetchJdCollectProgress.mock.calls.length
|
||||
await vi.advanceTimersByTimeAsync(POLL_MS * 3)
|
||||
await flushPromises()
|
||||
expect(api.fetchJdCollectProgress.mock.calls.length).toBe(callsAfterTerminal)
|
||||
})
|
||||
|
||||
it('FAILED 终态:用服务端原因说明失败,按钮恢复可点', async () => {
|
||||
api.fetchJdCollectProgress.mockResolvedValue(baseProgress())
|
||||
const w = await mountPage()
|
||||
await startCollect(w)
|
||||
|
||||
api.fetchJdCollectProgress.mockResolvedValue(
|
||||
baseProgress({ status: 'FAILED', message: '京麦后台未登录,请先在客户端登录京麦' }),
|
||||
)
|
||||
await vi.advanceTimersByTimeAsync(POLL_MS)
|
||||
await flushPromises()
|
||||
|
||||
expect(w.find('.progress-status').text()).toBe('获取失败')
|
||||
expect(w.find('.feedback.error').text()).toContain('京麦后台未登录')
|
||||
expect(w.find('.collect-btn').attributes('disabled')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('建单失败:只报错不留假进度条,一次进度请求也不发', async () => {
|
||||
api.createJdCollectTask.mockRejectedValue(new Error('缺少登录凭据'))
|
||||
const w = await mountPage()
|
||||
await startCollect(w)
|
||||
|
||||
expect(w.find('.feedback.error').text()).toContain('缺少登录凭据')
|
||||
expect(w.find('.progress-track').exists()).toBe(false)
|
||||
expect(api.fetchJdCollectProgress).not.toHaveBeenCalled()
|
||||
expect(api.enqueue).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,67 @@
|
||||
/**
|
||||
* 京东工作台挂载用例(v1.5):首页「京东」进来后是两个菜单。
|
||||
*
|
||||
* 三件事一起判,缺一条就是假绿:
|
||||
* ① 两个菜单名都在 DOM 里(获取店铺数据 / 商品上架);
|
||||
* ② 获取店铺数据是「可用」卡片(有 href → router-link 分支,文案是「打开工具」);
|
||||
* ③ 商品上架是「假菜单」:没有 href,点开只弹一句「暂未开通」,不发任何请求。
|
||||
*
|
||||
* 跑法:cd frontend-vue && npx vitest run(tests/mount/** 由 vitest.config.ts 收)。
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { mount, type VueWrapper } from '@vue/test-utils'
|
||||
|
||||
import JdConsolePage from '@/pages/jd/JdConsolePage.vue'
|
||||
|
||||
let wrapper: VueWrapper | null = null
|
||||
|
||||
function mountConsole() {
|
||||
wrapper = mount(JdConsolePage, {
|
||||
global: {
|
||||
stubs: {
|
||||
NotificationBell: true,
|
||||
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
},
|
||||
},
|
||||
})
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('京东工作台两个菜单', () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.setItem('username', 'admin')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = null
|
||||
window.localStorage.clear()
|
||||
})
|
||||
|
||||
it('两个菜单名都渲染出来', () => {
|
||||
const w = mountConsole()
|
||||
const text = w.text()
|
||||
expect(text).toContain('获取店铺数据')
|
||||
expect(text).toContain('商品上架')
|
||||
expect(w.findAll('.tool-card').length).toBe(2)
|
||||
})
|
||||
|
||||
it('获取店铺数据是可用卡片,商品上架是占位(暂未开通)', () => {
|
||||
const w = mountConsole()
|
||||
const cards = w.findAll('.tool-card')
|
||||
expect(cards[0].classes()).not.toContain('tool-card--pending')
|
||||
expect(cards[0].text()).toContain('打开工具')
|
||||
expect(cards[1].classes()).toContain('tool-card--pending')
|
||||
expect(cards[1].text()).toContain('暂未开通')
|
||||
})
|
||||
|
||||
it('点假菜单只弹提示,不跳转', async () => {
|
||||
const w = mountConsole()
|
||||
const pending = w.findAll('.tool-card')[1]
|
||||
await pending.trigger('click')
|
||||
const toast = w.find('.toast')
|
||||
expect(toast.text()).toContain('商品上架暂未开通')
|
||||
expect(toast.classes()).toContain('show')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user