Compare commits

...

3 Commits

Author SHA1 Message Date
huangzd1997 3bccc97698 feat(jd): 普通账号在京东侧可见管理员店铺分类(2026-11-16 客户口径「管理员弄了多少店铺分类 普通账户都能看到」)——服务端新增 GET /api/jd-collect/groups 只读端点(复用 JdProductGroupService.list,requireOwnershipUserId fail-closed,与 categories 同形,无公司维度:分类是平台级全集);用户端「获取店铺数据」页加载即拉取,只读 chips 展示分类名+商品数(title 带明细),空态点名「管理员在京东数据库→店铺分类建」,拉取失败 warning 不阻塞采集主路(catch 棘轮 318→319 逐条点名);endpoints 冻结快照随带 dated 追加。判据:mvn -o test JdCollectGroupsEndpointTest 2/2;vue-tsc rc=0;node --test 定向 21/21;vitest mount 11/11(+2:chips 渲染带 count/空态提示);fast 闸门 overall=pass 四面绿;JdCollectTab.vue 791<800 棘轮线。商品上架侧落地时消费同一端点(欠账入 ops BACKLOG B113) 2026-11-16 03:18:42 +08:00
huangzd1997 9b6f00a2dc feat(jd): 京东数据库工具栏加「移除分类」批量按钮(2026-11-16 用户截图反馈)——走 batch-assign-group 的 groupId=null 出口(与店铺分类弹窗「移出分类」同一后端语义,同置人工编辑锁);勾选里只算已分类行(未分类行没有分类可移,不白吃人工锁),按钮常显、全未分类时置灰带提示;确认弹窗点名数量与人工锁后果、danger:false(可恢复动作);删除/移除两流程互斥(deleting/removingGroup 交叉闸)。纯逻辑抽 jd-group-remove.ts(removableGroupPicks/removeGroupConfirmMessage,node --test 可直测)保 JdDatabasePage.vue 798<800 可读棘轮线。判据:vue-tsc 零错、vitest 京东页 29 例全绿(+3:计数只算已分类/取消不发/失败文案透出+danger:false 钉)、node --test 8 例全绿(+2)、confirm-exit-ledger 5/5(danger 键显式)、可读棘轮 10 passed、fast 闸门 overall=pass 四面绿 2026-11-16 02:44:27 +08:00
huangzd1997 301e3c5ecb fix(jd-collect): 建单页类目级联改 fixed 浮层——2026-11-16 形态核对实录(vite 5173 真页验收):建单页侧栏仅 ~370px,原 absolute+left:0/right:0 把三栏压到每栏 ~120px(一级名截成「服饰…」);首改容器溢出展开虽舒展,却把文档撑出横向滚动条(absolute 溢出必然进 scrollWidth)。终版按京麦本尊浮层形态:面板 fixed + toggle() 打开瞬间按触发框 getBoundingClientRect 定位(top=bottom+4、left 钳进视口,宽 min(652px, 100vw-16px),三栏 200+200+250 刚好舒展),fixed 不撑文档横向滚动——真页实测 docHScroll=false、面板 20/219/652、勾选 2 类目触发框「已选 2 个类目」+按钮「获取选中类目数据」、清空/搜索/空态文案全过。测试环境(happy-dom)rect 全 0,panelPos 落视口原点不影响 mount 断言。判据:npx vue-tsc --noEmit rc=0;catch-silence/endpoints/jd-collect-tab/jd-category-tree 22 绿;mount 9 绿 2026-11-16 02:38:31 +08:00
15 changed files with 416 additions and 12 deletions
@@ -15,7 +15,8 @@
* 的 JSON number 形状(生产库 273/273 行 price_min 全有值,jd-product-model.ts decimalText 收口);
* ③ 「上架时间 / 商品状态」合并列整列下线(「不需要采集」口径,jd_online_at/sale_status 仍收
* 详情抽屉),操作列随 2026-11-16「操作放最后一列」口径置末;④ 创建/修改两列同口径「不要」
* 下线(jd_created_at/jd_updated_at 仍收详情抽屉),列表时间列只剩同步时间收尾。
* 下线(jd_created_at/jd_updated_at 仍收详情抽屉),列表时间列只剩同步时间收尾;
* ⑤ 工具栏加「移除分类」批量按钮(batch-assign-group 的 groupId=null 口径,勾选里只算已分类行)。
* 骨架像素复刻「外观专利数据库」页(panel-box + LoadFailureBar + 自绘 table + 旧式分页);
* 超管切公司 tab = 清筛选重取(watch 体照外观专利页逐字形状);日期对护栏:起侧 max=止侧、
* 止侧 min=起侧、两侧 @change 用 orderedPair 把倒挂交换回来(clampJdSyncedRange 照 clampDatePair)。
@@ -23,6 +24,7 @@
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
import { computed, onMounted, reactive, ref, watch } from 'vue'
import {
batchAssignJdProductGroup,
deleteJdProducts,
fetchJdProductCategories,
fetchJdProductGroups,
@@ -33,6 +35,7 @@ import {
import type { JdProductItem } from './jd-product-model.ts'
import { jdPriceRange } from './jd-product-model.ts'
import { createJdProductFilterState } from './jd-product-filter.ts'
import { removableGroupPicks, removeGroupConfirmMessage } from './jd-group-remove.ts'
import JdProductDetailDrawer from './JdProductDetailDrawer.vue'
import JdProductEditDrawer from './JdProductEditDrawer.vue'
import JdProductGroupDialog from './JdProductGroupDialog.vue'
@@ -233,7 +236,7 @@ async function removeSelected(): Promise<void> {
/** 删除主流程:二次确认 → 先删桶、全成功才删库行(后端保证)→ 刷新列表并清勾选。 */
async function removeMany(picked: JdProductItem[], message: string): Promise<void> {
if (!picked.length || deleting.value) return
if (!picked.length || deleting.value || removingGroup.value) return
const ok = await openAdminConfirm({ title: '删除京东商品', message: `${message}删除后该商品的 SKU、图片登记与 jd-products 桶内图片文件一并删除(被其他商品共用的图片会保留);此操作不可恢复。`, confirmText: '确认删除', danger: true })
if (!ok) return
deleting.value = true
@@ -252,6 +255,29 @@ async function removeMany(picked: JdProductItem[], message: string): Promise<voi
}
}
// ---------------- 批量移除分类(2026-11-16 用户截图反馈):batch-assign-group 的 groupId=null 口径(与店铺分类弹窗「移出分类」同一出口,后端同置人工编辑锁) ----------------
const removingGroup = ref(false)
const removablePicked = computed(() => removableGroupPicks(rows.value, selectedIds.value))
/** 移除主流程:二次确认点名数量与人工锁后果 → (ids, null) → 刷新列表并清勾选。 */
async function removeSelectedGroup(): Promise<void> {
const picked = removablePicked.value
if (!picked.length || removingGroup.value || deleting.value) return
const ok = await openAdminConfirm({ title: '移除分类', message: removeGroupConfirmMessage(picked.length), confirmText: '确认移除', danger: false })
if (!ok) return
removingGroup.value = true
try {
const updated = await batchAssignJdProductGroup(picked.map((row) => row.id), null)
showAdminFeedback(`已把 ${updated} 个商品移出分类`, 'success')
selectedIds.value = new Set()
await load()
} catch (error) {
const text = error instanceof Error && error.message ? error.message : '移除分类失败,请稍后重试'
showAdminFeedback(text, 'error')
} finally {
removingGroup.value = false
}
}
// 超管切公司 tab = 重新取数:编码/关键字/类目/日期是按行集筛的自由值,在另一家的
// 行集里筛不出东西,必须一起清(分组与分类状态全平台一份,groupId/groupScope 与公司维度
// 正交、不清);类目选项与行集同源,按新 tab 重取;分组选项是全局的、进页取一次即可。
@@ -328,6 +354,14 @@ onMounted(() => {
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<div class="jd-toolbar">
<span class="jd-summary">共 {{ total }} 条京东商品</span>
<button
class="btn jd-remove-btn" type="button"
:disabled="removingGroup || !removablePicked.length"
:title="removablePicked.length ? `移出勾选的 ${removablePicked.length} 个已分类商品` : '勾选中没有已分类的商品'"
@click="removeSelectedGroup"
>
{{ removingGroup ? '移除中...' : `移除分类(${removablePicked.length})` }}
</button>
<!-- 批量删除 2026-11-16 客户口径「不要勾选后才显示」:常显,勾选 0 时置灰。 -->
<button
class="btn btn-danger jd-delete-btn"
@@ -557,8 +591,8 @@ h3 {
gap: 14px;
margin-bottom: 10px;
}
/* 删除按钮挂到工具栏右侧(scoped:分组弹窗那份 .btn-danger 借不过来)。 */
.jd-delete-btn {
/* 工具栏右侧两个批量按钮:推右的 margin 由移除分类带,删除跟排。 */
.jd-remove-btn {
margin-left: auto;
}
.btn-danger {
@@ -0,0 +1,16 @@
/** 批量移除分类的纯逻辑(2026-11-16 用户截图反馈):勾选中「已分类」的行才参与——未分类行
* 没有分类可移,参与只会白吃一次人工锁(manual_locked=1,价格/库存随锁停更,与编辑保存
* 同口径)。确认文案也在此出(点名数量与后果),页面只管确认弹窗、调用与刷新;
* 独立成件也让 JdDatabasePage.vue 守得住可读棘轮的 800 行报警线(AssignPane 同款理由)。
* node --test 可直测(零依赖、不碰 http/Pinia)。 */
import type { JdProductItem } from './jd-product-model.ts'
/** 勾选中「已分类」的行(groupName 非空=group_id 已挂分类)。 */
export function removableGroupPicks(rows: JdProductItem[], selectedIds: ReadonlySet<number>): JdProductItem[] {
return rows.filter((row) => selectedIds.has(row.id) && !!row.groupName)
}
/** 移除分类确认弹窗文案(点名数量与人工编辑锁后果,用户点确认前看得见代价)。 */
export function removeGroupConfirmMessage(count: number): string {
return `确定把勾选的 ${count} 个商品移出分类吗?移出后回到「未分类」;分类操作会置人工编辑锁,这些行的价格/库存不再随采集自动更新(与编辑保存同口径)。`
}
@@ -233,7 +233,8 @@ export async function deleteJdProductGroup(id: number): Promise<void> {
groupDataOf<unknown>(data)
}
/** 批量人工归类(店铺分类弹窗,2026-11-15):勾选商品行 → 归入指定分类或移出分类。
/** 批量人工归类(店铺分类弹窗 2026-11-15 + 京东数据库页工具栏「移除分类」2026-11-16):
* 勾选商品行 → 归入指定分类或移出分类。
* groupId 传 null=移出分类(后端把 group_id 置 NULL);返回实际更新的行数。
* 后端与单行编辑同口径置 manual_locked=1(归类即人工干预,采集不再覆盖/清理该行)。
* 业务失败(分类不存在等)把中文文案抛回,弹窗红条原样展示。公共库写侧无公司维度。 */
@@ -0,0 +1,25 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { removableGroupPicks, removeGroupConfirmMessage } from '../src/pages/jd/jd-group-remove.ts'
import { toJdProductItem } from '../src/pages/jd/jd-product-model.ts'
/** 「移除分类」纯逻辑契约(2026-11-16 页工具栏):勾选里只挑已分类行+确认文案点名后果。
* 挂载侧行为(按钮置灰/发送名单/清勾选)由 tests/mount/jd-database-page.mount.test.ts 钉。 */
function row(id: number, groupName: string | null) {
return toJdProductItem({ id, product_code: `JD-${id}`, group_name: groupName })!
}
test('removableGroupPicks 只挑勾选中已分类的行(未分类行没有分类可移,不参与=不白吃人工锁)', () => {
const rows = [row(1, '甲组'), row(2, null), row(3, '乙组'), row(4, '')]
const picks = removableGroupPicks(rows, new Set([2, 3, 4]))
assert.deepEqual(picks.map((r) => r.id), [3], '未分类(null/空名)行一律排除')
assert.deepEqual(removableGroupPicks(rows, new Set()).map((r) => r.id), [], '空勾选回空')
})
test('确认文案点名数量与人工编辑锁后果(用户点确认前看得见代价)', () => {
const message = removeGroupConfirmMessage(2)
assert.ok(message.includes('2 个商品'), '文案点名数量')
assert.ok(message.includes('人工编辑锁'), '文案点名人工锁后果')
assert.ok(message.includes('未分类'), '文案说明移出后的去向')
})
@@ -548,6 +548,70 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
})
it('移除分类(2026-11-16 页工具栏):计数只算勾选中已分类的行(未分类行不参与=不白吃人工锁)→ 确认点名数量与人工锁后果 → (ids, null) 调批量归类,成功后刷新并清勾选', async () => {
const wrapper = await mountWith({
items: [item(1), item(2, { groupId: null, groupName: '' }), item(3)],
total: 3, page: 1, pageSize: 20,
})
// 常显(同删除口径);未勾选时置灰。
const removeBtn = () => wrapper.find('.jd-remove-btn')
expect(removeBtn().exists()).toBe(true)
expect(removeBtn().attributes('disabled')).toBeDefined()
// 只勾未分类行:没有分类可移,按钮仍置灰(标题给原因,不靠猜)。
const boxes = wrapper.findAll('tbody input[type="checkbox"]')
await boxes[1].setValue(true)
expect(removeBtn().attributes('disabled')).toBeDefined()
expect(removeBtn().attributes('title')).toBe('勾选中没有已分类的商品')
// 勾选 1、3 两行已分类 → 计数=2 且可点(未分类的 2 号行不在发送名单里)。
await boxes[0].setValue(true)
await boxes[2].setValue(true)
expect(removeBtn().attributes('disabled')).toBeUndefined()
expect(removeBtn().text()).toContain('移除分类(2)')
jdApi.batchAssignJdProductGroup.mockResolvedValue(2)
await removeBtn().trigger('click')
await flushPromises()
await flushPromises()
expect(confirmMock).toHaveBeenCalledTimes(1)
const options = confirmMock.mock.calls[0][0]
expect(options.title).toBe('移除分类')
expect(options.message).toContain('确定把勾选的 2 个商品移出分类吗')
expect(options.message).toContain('人工编辑锁', '确认弹窗必须点名人工编辑锁后果(价格/库存随锁停更)')
expect(options.danger).toBe(false, '移除分类是可恢复动作,非 danger 形态(danger-exit-ledger 口径)')
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledTimes(1)
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1, 3], null)
expect(document.body.textContent).toContain('已把 2 个商品移出分类')
// 成功后重取列表并清勾选:按钮回到置灰。
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(1)
expect(removeBtn().attributes('disabled')).toBeDefined()
})
it('移除分类:确认弹窗点取消就不发请求(防误操作的第一道闸)', async () => {
confirmMock.mockResolvedValue(false)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
await wrapper.find('.jd-remove-btn').trigger('click')
await flushPromises()
expect(confirmMock).toHaveBeenCalledTimes(1)
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
})
it('移除分类失败把后端中文文案弹出来(勾选保留可重试)', async () => {
jdApi.batchAssignJdProductGroup.mockRejectedValue(new Error('分类不存在,请刷新分类后重试'))
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
await wrapper.findAll('tbody input[type="checkbox"]')[0].setValue(true)
await wrapper.find('.jd-remove-btn').trigger('click')
await flushPromises()
await flushPromises()
expect(document.body.textContent).toContain('分类不存在,请刷新分类后重试')
})
it('店铺分类弹窗(原「管理分组」):打开即拉分类列表与右栏商品行集,变更后刷新分类下拉与列表', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
@@ -13,8 +13,10 @@ import com.nanri.aiimage.modules.jd.model.vo.JdCollectTaskBatchVo;
import com.nanri.aiimage.modules.jd.model.vo.JdCollectTaskVo;
import com.nanri.aiimage.modules.jd.model.vo.JdIngestChunkVo;
import com.nanri.aiimage.modules.jd.model.vo.JdProductCategoryVo;
import com.nanri.aiimage.modules.jd.model.vo.JdProductGroupVo;
import com.nanri.aiimage.modules.jd.service.JdCollectBoardService;
import com.nanri.aiimage.modules.jd.service.JdCollectTaskService;
import com.nanri.aiimage.modules.jd.service.JdProductGroupService;
import com.nanri.aiimage.modules.jd.service.JdProductQueryService;
import com.nanri.aiimage.modules.jd.service.JdResultIngestService;
import com.nanri.aiimage.modules.task.model.dto.TaskHeartbeatRequest;
@@ -60,6 +62,7 @@ public class JdCollectController {
private final JdCollectBoardService boardService;
private final JdResultIngestService ingestService;
private final JdProductQueryService jdProductQueryService;
private final JdProductGroupService jdProductGroupService;
private final TaskHeartbeatService taskHeartbeatService;
private final TaskHeartbeatPositionService taskHeartbeatPositionService;
private final TaskProgressOwnershipSupport progressOwnershipSupport;
@@ -76,6 +79,18 @@ public class JdCollectController {
return ApiResponse.success(jdProductQueryService.categories(null));
}
@GetMapping("/groups")
@Operation(summary = "店铺分类列表(用户侧只读)", description = "2026-11-16 客户口径「管理员弄了多少"
+ "店铺分类 普通账户都能看到」:「获取店铺数据」页把管理员在后管京东数据库建的分类展示出来"
+ "(含组内商品数),普通账号登录即可见。与后管分组管理同一条读出口(JdProductGroupService.list,"
+ "分组 2026-11-15 起全平台一份、无公司维度);只读不写——分类的增删改仍只在后管。"
+ "「商品上架」未落地(jd-publish 占位),上架界面落地时消费同一端点。")
public ApiResponse<List<JdProductGroupVo>> groups(HttpServletRequest httpRequest) {
// 登录用户即可读(公共库口径):解析不出会话身份就 401(fail-closed,与 categories 同口径)。
adminAuthSupport.requireOwnershipUserId(httpRequest, null);
return ApiResponse.success(jdProductGroupService.list());
}
@GetMapping("/dashboard")
@Operation(summary = "查询京东采集任务总览", description = "当前用户的运行中、成功、失败任务数。"
+ "任务面板统计卡数据源,页面进入时请求一次即可,不需要持续轮询。")
@@ -0,0 +1,91 @@
package com.nanri.aiimage.modules.jd.controller;
import com.nanri.aiimage.common.api.ApiResponse;
import com.nanri.aiimage.common.security.AdminAuthSupport;
import com.nanri.aiimage.modules.jd.model.vo.JdProductGroupVo;
import com.nanri.aiimage.modules.jd.service.JdCollectBoardService;
import com.nanri.aiimage.modules.jd.service.JdCollectTaskService;
import com.nanri.aiimage.modules.jd.service.JdProductGroupService;
import com.nanri.aiimage.modules.jd.service.JdProductQueryService;
import com.nanri.aiimage.modules.jd.service.JdResultIngestService;
import com.nanri.aiimage.modules.task.service.TaskHeartbeatPositionService;
import com.nanri.aiimage.modules.task.service.TaskHeartbeatService;
import com.nanri.aiimage.modules.task.service.TaskProgressOwnershipSupport;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* 用户侧「店铺分类」只读端点(2026-11-16 客户口径「管理员弄了多少店铺分类 普通账户都能看到」)。
*
* <p>「获取店铺数据」页把管理员在后管京东数据库建的分类展示给普通账号:GET /api/jd-collect/groups,
* 与 categories 端点同形(登录用户即可读、fail-closed 401;分组全平台一份、无公司维度)。
* 只读不写——分类的增删改仍只在后管 AdminJdProductGroupController。结构判据(照
* {@code AdminJdProductControllerTest} 双形态的第一半)+行为样本(200 信封装 list、鉴权先过)。</p>
*/
class JdCollectGroupsEndpointTest {
private static final Path CONTROLLER = Path.of("").toAbsolutePath()
.resolve("src/main/java/com/nanri/aiimage/modules/jd/controller/JdCollectController.java");
@Test
void 结构判据_groups端点只读且复用分组服务公共口径() throws IOException {
assertTrue(Files.exists(CONTROLLER), "控制器必须落在 " + CONTROLLER);
String source = Files.readString(CONTROLLER);
assertTrue(source.contains("@GetMapping(\"/groups\")"),
"用户侧分类列表必须是 GET /groups(categories 同形)");
assertTrue(source.contains("jdProductGroupService.list()"),
"必须复用 JdProductGroupService.list()(与后管分组管理同一条读出口,不另造查询)");
assertTrue(source.contains("adminAuthSupport.requireOwnershipUserId(httpRequest, null)"),
"登录用户即可读但必须 fail-closed:解析不出会话身份就 401(与 categories 同口径)");
}
@Test
void 行为样本_鉴权先过且200信封装分组全量() {
JdProductGroupService groupService = mock(JdProductGroupService.class);
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
JdCollectController controller = new JdCollectController(
mock(JdCollectTaskService.class),
mock(JdCollectBoardService.class),
mock(JdResultIngestService.class),
mock(JdProductQueryService.class),
groupService,
mock(TaskHeartbeatService.class),
mock(TaskHeartbeatPositionService.class),
mock(TaskProgressOwnershipSupport.class),
authSupport);
HttpServletRequest request = mock(HttpServletRequest.class);
JdProductGroupVo vo = new JdProductGroupVo();
vo.setId(7L);
vo.setName("ASSS");
vo.setProductCount(20L);
when(authSupport.requireOwnershipUserId(same(request), isNull())).thenReturn(1L);
when(groupService.list()).thenReturn(List.of(vo));
ApiResponse<List<JdProductGroupVo>> response = controller.groups(request);
assertNotNull(response);
assertTrue(response.isSuccess(), "成功信封 success=true(B80-03:判据只认响应体,不认 HTTP 状态码)");
assertNotNull(response.getData());
assertEquals(1, response.getData().size());
assertEquals("ASSS", response.getData().get(0).getName());
assertEquals(20L, response.getData().get(0).getProductCount());
// 鉴权闸先行:解析不出会话身份就 401,读不到任何数据。
verify(authSupport).requireOwnershipUserId(same(request), isNull());
verify(groupService).list();
}
}
@@ -28,6 +28,10 @@ const emit = defineEmits<{ (event: 'change', value: string[]): void }>()
const open = ref(false)
const activeRoot = ref('')
const searchText = ref('')
/** 触发框元素:打开面板瞬间按它的实际位置给浮层定位(fixed 不撑文档横向滚动)。 */
const triggerRef = ref<HTMLElement | null>(null)
/** 面板浮层定位(fixed 的 top/left,px 字符串)。 */
const panelPos = ref({ top: '0px', left: '0px' })
const roots = jdCategoryNavRoots()
/** 第二栏=点亮一级的静态二级;无静态子级的一级不出第二栏。 */
@@ -55,6 +59,16 @@ function toggle(): void {
}
activeRoot.value = ''
searchText.value = ''
// 面板是 fixed 浮层(京麦本尊形态:窄触发框 + 视口级宽面板,不撑文档横向滚动条),
// 打开瞬间按触发框实际位置定位;测试环境无真实布局时 rect 全 0,top/left 落在视口原点即可。
const rect = triggerRef.value?.getBoundingClientRect()
if (rect) {
const width = Math.min(652, Math.max(320, window.innerWidth - 24))
panelPos.value = {
top: `${Math.round(rect.bottom + 4)}px`,
left: `${Math.round(Math.max(8, Math.min(rect.left, window.innerWidth - width - 8)))}px`,
}
}
open.value = true
}
@@ -88,6 +102,7 @@ function clear(): void {
<template>
<div class="cat-cascader">
<button
ref="triggerRef"
class="cat-trigger"
type="button"
:class="{ open, filled: modelValue.length > 0 }"
@@ -107,7 +122,7 @@ function clear(): void {
<!-- 面板外点透明遮罩关闭(零 document 监听器,无泄漏面)。 -->
<div v-if="open" class="cat-mask" @click="close"></div>
<div v-if="open" class="cat-panel">
<div v-if="open" class="cat-panel" :style="panelPos">
<!-- 第一栏:静态一级导航(radio 形状照京麦,点选只展开不落值)。 -->
<div class="cat-col">
<div
@@ -249,14 +264,14 @@ function clear(): void {
z-index: 2550;
}
.cat-panel {
position: absolute;
top: calc(100% + 4px);
left: 0;
right: 0;
/* fixed 浮层:位置由 toggle() 按触发框实际位置写 :style(top/left)。
* 建单页侧栏只有 ~370px,贴容器宽会把三栏压到每栏 ~120px(一级名截成「服饰…」);
* 三栏内容 200+200+250=650,宽度固定 652 向右展开,fixed 不撑文档横向滚动条。 */
position: fixed;
width: min(652px, calc(100vw - 16px));
z-index: 2560;
display: flex;
align-items: stretch;
max-width: min(720px, 90vw);
border: 1px solid #d8e3ee;
border-radius: 10px;
background: #ffffff;
@@ -9,10 +9,12 @@ import {
deleteJdCollectTask,
fetchJdCollectCategories,
fetchJdCollectDashboard,
fetchJdCollectGroups,
fetchJdCollectHistory,
fetchJdCollectTaskProgressBatch,
interruptJdCollectTask,
type JdCollectCategoryVo,
type JdCollectGroupVo,
type JdCollectHistoryItemVo,
type JdListTab,
} from '@/shared/api/types/modules/jd-collect'
@@ -37,6 +39,9 @@ import JdCategoryCascader from './JdCategoryCascader.vue'
* 卡片只显示已采集行数,不编造百分比;
* 4. 失败/中断任务「重试/继续」走通用原位复位(铁律 26,保留已收分片与断点游标),
* 复位后页面重新激活并推队列——同一份输入不再多出好几行结果。
*
* 2026-11-16 客户口径「管理员弄了多少店铺分类 普通账户都能看到」:左面板加只读「店铺分类」
* 块(GET /api/jd-collect/groups,管理员在后管京东数据库维护);「商品上架」落地后消费同一端点。
*/
/** 页面不再让用户填店铺名:店铺名称由客户端从京麦后台读,建单先按此占位记录。 */
@@ -76,6 +81,21 @@ function uidForStorage() {
return typeof window !== 'undefined' ? window.localStorage.getItem('uid') || '0' : '0'
}
// ---- 店铺分类(管理员在后管「京东数据库」维护,本页只读展示;2026-11-16 客户口径
// 「管理员弄了多少店铺分类 普通账户都能看到」——普通账号在「获取店铺数据」页就能看到
// 分类全集与各组商品数。分类的增删改仍只在后管;「商品上架」落地后消费同一端点。)----
const groupList = ref<JdCollectGroupVo[]>([])
async function loadGroups() {
try {
groupList.value = await fetchJdCollectGroups()
} catch (err) {
// 分类只是展示项:拉不到就保持空态文案,不把采集主路堵死(同 loadCategoryOptions 口径)。
console.error('[jd-collect] 店铺分类拉取失败', err)
ElMessage.warning('店铺分类加载失败,不影响采集')
}
}
// ---- 实时任务面板(与外观专利共用 useLiveTaskBoard 骨架;京东无结果文件,无下载层)----
const board = useLiveTaskBoard<JdCollectHistoryItemVo>({
scope: 'jd-collect',
@@ -366,6 +386,7 @@ onMounted(async () => {
board.loadDashboard().catch(() => undefined),
board.loadHistory().catch(() => undefined),
loadCategoryOptions(),
loadGroups(),
])
board.seedRunningTasksFromHistory()
board.seedPendingFileTasksFromHistory()
@@ -420,6 +441,19 @@ onUnmounted(() => {
</p>
</div>
<div class="category-block">
<span class="category-label">店铺分类(管理员维护,只读)</span>
<p v-if="groupList.length" class="group-chips">
<span v-for="group in groupList" :key="group.id" class="group-chip"
:title="`${group.name}:${group.productCount} 个商品`">
{{ group.name }}({{ group.productCount }})
</span>
</p>
<p v-else class="category-hint">
后台还没建店铺分类;管理员在「京东数据库 → 店铺分类」里建的会显示在这里。
</p>
</div>
<button class="collect-btn" type="button" :disabled="isRunning" @click="startCollect">
{{ isRunning ? '获取中…' : (selectedCategories.length ? `获取选中类目数据` : '一键获取店铺数据') }}
</button>
@@ -671,6 +705,26 @@ onUnmounted(() => {
line-height: 1.6;
}
/* 店铺分类只读块(2026-11-16 客户口径):label 复用 category-label,chips 深色卡片同色系。 */
.group-chips {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin: 8px 0 0;
}
.group-chip {
display: inline-flex;
align-items: center;
padding: 4px 10px;
border: 1px solid #3e4a62;
border-radius: 6px;
background: #232b3d;
color: #c8d2e2;
font-size: 12px;
white-space: nowrap;
}
.collect-btn:hover:not(:disabled) {
filter: brightness(1.1);
transform: translateY(-1px);
+2
View File
@@ -209,6 +209,8 @@ export const API_ENDPOINTS = {
create: '/api/jd-collect/tasks',
/** 采集类目下拉数据源(公共库已落库 category_path 全集,建单页多选面板用) */
categories: '/api/jd-collect/categories',
/** 店铺分类只读列表(管理员在后管京东数据库建的分类+组内商品数;2026-11-16 客户口径「普通账户都能看到」) */
groups: '/api/jd-collect/groups',
/** 激活(PENDING→RUNNING):推客户端队列**之前**必须调用,否则分片被拒、心跳要求客户端收手 */
activate: '/api/jd-collect/tasks/{taskId}/activate',
/** 采集进度(用户端「获取店铺数据」进度条数据源) */
@@ -80,6 +80,26 @@ export function fetchJdCollectCategories() {
);
}
/** 店铺分类行(GET /api/jd-collect/groups:管理员在后管京东数据库建的分类+组内商品数)。
* 2026-11-16 客户口径「管理员弄了多少店铺分类 普通账户都能看到」:只读展示,分类的
* 增删改仍只在后管;分组 2026-11-15 起全平台一份,无公司维度。 */
export interface JdCollectGroupVo {
id: number;
name: string;
sortOrder: number;
productCount: number;
}
/** 店铺分类只读列表(「获取店铺数据」页展示;「商品上架」落地后消费同一端点)。 */
export function fetchJdCollectGroups() {
return unwrapJavaResponse(
get<JavaApiResponse<JdCollectGroupVo[]>>(
buildJavaUrl(API_ENDPOINTS.jdCollect.groups),
{ params: { user_id: getCurrentUserId() } },
),
);
}
export function createJdCollectTask(
shopName: string,
listTabs: JdListTab[],
@@ -87,7 +87,11 @@ const BASELINE = {
// loadCategoryOptions catch——类目选项拉取失败不阻塞建单(不选类目=全店采集的
// 主路照常),失败 ElMessage.warning 当场说给用户、原文只进 console;非静默,
// silent 一格没涨,只进 blocks。
blocks: 318,
// 319 = 318 + 1(2026-11-16 店铺分类只读块,客户口径「管理员弄了多少店铺分类 普通账户
// 都能看到」):JdCollectTab.vue 的 loadGroups catch——分类只是展示项,拉取失败
// ElMessage.warning 当场说给用户、原文只进 console,采集主路照常;非静默,
// silent 一格没涨,只进 blocks。
blocks: 319,
// 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处
// 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进
// useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动,
+3
View File
@@ -321,9 +321,12 @@ test('test_endpoints_frozen_snapshot', () => {
// deleteTask(连带清理京东数据库该任务的行与断点游标,铁律 32 数据面)。
// 2026-11-16 类目多选:categories(公共库已落库 category_path 全集,建单页多选面板选项源,
// 鉴权照建单 requireOwnershipUserId fail-closed;后端 8b4f7a3a 同轮落)。
// 2026-11-16 店铺分类只读:groups(管理员在后管京东数据库建的分类+组内商品数,「获取店铺数据」
// 页展示给普通账号——客户口径「普通账户都能看到」;鉴权照 categories 同口径)。
"jdCollect": {
"create": "/api/jd-collect/tasks",
"categories": "/api/jd-collect/categories",
"groups": "/api/jd-collect/groups",
// activate 补录(存量漂移):8d8c88a5「补激活这一步」只改了常量表,快照没跟上,
// 本次任务面板改版全量跑才暴露(快照测试此前没在全量档里红过)。
"activate": "/api/jd-collect/tasks/{taskId}/activate",
+25
View File
@@ -48,6 +48,31 @@ test('endpoints 注册采集类目 categories 下拉端点', () => {
'endpoints.ts jdCollect 组缺 categories(建单页类目多选面板的选项源)')
})
/** 2026-11-16 客户口径「管理员弄了多少店铺分类 普通账户都能看到」:普通账号在
* 「获取店铺数据」页就能看到管理员在后管京东数据库建的分类全集与各组商品数;
* 本页只读——分类的增删改仍只在后管。「商品上架」落地后消费同一端点。 */
test('endpoints 注册店铺分类 groups 只读端点,页面加载并只读展示', () => {
const endpoints = readIfExists(ENDPOINTS, 'endpoints.ts')
assert.ok(endpoints.includes("groups: '/api/jd-collect/groups'"),
'endpoints.ts jdCollect 组缺 groups(店铺分类只读列表的选项源)')
const api = readIfExists(
join(process.cwd(), 'src', 'shared', 'api', 'types', 'modules', 'jd-collect.ts'),
'jd-collect.ts',
)
assert.ok(api.includes('export function fetchJdCollectGroups'),
'jd-collect.ts 缺 fetchJdCollectGroups(页面取分类列表的发送口)')
const page = readIfExists(
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
'JdCollectTab.vue',
)
assert.ok(page.includes('fetchJdCollectGroups'),
'JdCollectTab.vue 必须调 fetchJdCollectGroups(普通账号在这里看到管理员建的分类)')
assert.ok(page.includes('店铺分类(管理员维护,只读)'),
'JdCollectTab.vue 必须有「店铺分类」只读展示块(口径点名「管理员维护,只读」)')
})
test('建单请求体与推送载荷都带 categoryPaths', () => {
const api = readIfExists(
join(process.cwd(), 'src', 'shared', 'api', 'types', 'modules', 'jd-collect.ts'),
@@ -23,6 +23,7 @@ const api = vi.hoisted(() => ({
// undefined 调用、enqueue 永远不被调用(本文件当时没跟上,红在这里)。
activateJdCollectTask: vi.fn(),
fetchJdCollectCategories: vi.fn(),
fetchJdCollectGroups: vi.fn(),
fetchJdCollectDashboard: vi.fn(),
fetchJdCollectHistory: vi.fn(),
fetchJdCollectTaskProgressBatch: vi.fn(),
@@ -36,6 +37,7 @@ vi.mock('@/shared/api/types/modules/jd-collect', () => ({
createJdCollectTask: api.createJdCollectTask,
activateJdCollectTask: api.activateJdCollectTask,
fetchJdCollectCategories: api.fetchJdCollectCategories,
fetchJdCollectGroups: api.fetchJdCollectGroups,
fetchJdCollectProgress: vi.fn(),
fetchJdCollectDashboard: api.fetchJdCollectDashboard,
fetchJdCollectHistory: api.fetchJdCollectHistory,
@@ -125,6 +127,7 @@ beforeEach(() => {
api.createJdCollectTask.mockResolvedValue({ taskId: 88, taskNo: 'JD-1', collectChannel: 'LOCAL' })
api.activateJdCollectTask.mockResolvedValue(null)
api.fetchJdCollectCategories.mockResolvedValue([])
api.fetchJdCollectGroups.mockResolvedValue([])
api.enqueue.mockResolvedValue({ success: true })
api.fetchJdCollectDashboard.mockResolvedValue(EMPTY_DASHBOARD)
api.fetchJdCollectHistory.mockResolvedValue({ items: [] })
@@ -309,4 +312,36 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
categoryPaths: ['女装'],
})
})
it('店铺分类只读块:页面加载即拉取并把管理员建的分类与商品数展示出来', async () => {
// 2026-11-16 客户口径「管理员弄了多少店铺分类 普通账户都能看到」:普通账号在
// 「获取店铺数据」页就能看到后管京东数据库建的分类全集;本页只读,不提供增删改。
api.fetchJdCollectGroups.mockResolvedValue([
{ id: 1, name: 'ASSS', sortOrder: 0, productCount: 20 },
{ id: 2, name: '家居日用', sortOrder: 1, productCount: 7 },
])
const w = await mountPage()
expect(api.fetchJdCollectGroups).toHaveBeenCalledTimes(1)
const block = w.findAll('.category-block').find((el) => el.text().includes('店铺分类'))
expect(block, '必须有「店铺分类」展示块').toBeTruthy()
expect(block!.text()).toContain('店铺分类(管理员维护,只读)')
const chips = block!.findAll('.group-chip')
expect(chips.length).toBe(2)
expect(chips[0].text()).toContain('ASSS(20)')
expect(chips[1].text()).toContain('家居日用(7)')
expect(chips[0].attributes('title')).toContain('ASSS:20 个商品')
})
it('后台还没建分类:只读块落空态提示,采集主路照常', async () => {
const w = await mountPage()
const block = w.findAll('.category-block').find((el) => el.text().includes('店铺分类'))
expect(block, '空态也要有「店铺分类」块(不能整块消失让用户以为没这功能)').toBeTruthy()
expect(block!.text()).toContain('后台还没建店铺分类')
expect(block!.text()).toContain('管理员在「京东数据库 → 店铺分类」里建的会显示在这里')
expect(block!.find('.group-chip').exists()).toBe(false)
// 拉取失败只 warning、不影响建单主路(catch 口径见 catch-silence-ratchet 319)
expect(w.find('.collect-btn').exists()).toBe(true)
})
})