feat(jd): 京东数据库行级编辑与删除+人工编辑锁/删除忽略保护(V199,2026-11-15 用户口径「每条数据可以编辑/删除」)——主链:PUT /api/admin/jd-products/{id} 主字段全量提交即置 manual_locked=1(采集回传 upsert/purge 对锁定行跳过,XML 侧 AND manual_locked=0 铁律 20);attrGroups 只重建 attr_json 的 tabs 段保留其它顶层键(铁律 30),原文形状不识别拒绝;skus 按 (productId,skuId) 改价改库存缺失拒绝;deleteImageIds 先删桶(共用对象保留)计数按表实数刷;删除链成功后写 biz_jd_product_ignore 防重爬复活(幂等吞 DuplicateKey);采集回传 filterProtectedRows 跳过锁定/忽略行不登记子表。后管:列表 11 列操作列(编辑/删除,@click.stop 防冒泡)+ JdProductEditDrawer(主字段/属性键值行删/SKU 价格库存/图片标删,保存提示人工维护后果),updateJdProduct 带 company_id;company-tab-wiring SEND_POINTS 26→32(补详情/删除/分组/类目/删分组/编辑六口一函数一钉对平)。判据:JdProductUpdateServiceTest 8 例+SyncServiceTest 保护闸/绊线+DeleteServiceTest 忽略登记+mount 操作列防冒泡/编辑抽屉;后端整量 5,607 例、后管 vue-tsc+1903+113 全绿。同窗交织笔(另一路会话类目下拉已收尾,文件级无法拆分一并入库):selectProductCategories/GET /categories/JdProductCategoryVo 类目筛选下拉+MigratedSqlEquivalenceTest/SqlLayeringConventionTest 适配。图片上传/替换链路记 BACKLOG B109-01;RawExceptionMessageSinkGuard/CatchSilenceRatchet 随笔抬格逐处记名

This commit is contained in:
2026-11-15 18:38:27 +08:00
parent 7a117187b7
commit dea9891e19
30 changed files with 2449 additions and 517 deletions
@@ -1,9 +1,10 @@
/**
* 京东数据库页(v1.4 Phase 5)的挂载契约。
*
* 形态:panel-box + 筛选行(店铺/商品编码/标题关键字/商品状态/分组/同步起止 date 对)+
* 查询/导出/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination;
* 形态:panel-box + 筛选行(店铺/商品编码/标题关键字/分组/同步起止 date 对)+
* 查询/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination;
* 公司 tab 切换=清筛选重取(company-tab-wiring 同口径)。
* 商品状态筛选/列与导出按钮已随 2026-11-15 客户口径从前端下线(后端端点保留)。
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
*
* 跑法:`npx vitest run tests/mount/jd-database-page.mount.test.ts`
@@ -22,12 +23,13 @@ const jdApi = vi.hoisted(() => ({
JD_PRODUCT_GROUP_ENDPOINT: '/api/admin/jd-product-groups',
fetchJdProductList: vi.fn(),
fetchJdProductDetail: vi.fn(),
exportJdProductList: vi.fn(),
deleteJdProducts: vi.fn(),
fetchJdProductGroups: vi.fn(),
fetchJdProductCategories: vi.fn(),
createJdProductGroup: vi.fn(),
updateJdProductGroup: vi.fn(),
deleteJdProductGroup: vi.fn(),
updateJdProduct: vi.fn(),
}))
const confirmMock = vi.hoisted(() => vi.fn())
@@ -75,6 +77,7 @@ beforeEach(() => {
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
useCompanyTabStore().setActiveId(1)
jdApi.fetchJdProductGroups.mockResolvedValue([])
jdApi.fetchJdProductCategories.mockResolvedValue([])
confirmMock.mockResolvedValue(true)
})
@@ -98,34 +101,97 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(wrapper.find('.jd-summary').text()).toContain('共 42 条京东商品')
})
it('行内容按京麦商品列表样式(2026-11-15 用户口径):勾选/店铺/分组/商品信息(图+标题+编码+货号+SKU/信息分)/品牌/价格/库存/状态/同步(9 列),类目等其余收进详情抽屉', async () => {
it('行列字段与顺序对齐京麦(2026-11-15 用户口径):勾选/店铺/分组/商品信息(图+标题+编码+货号+品牌·类目+SKU/信息分)/总库存/价格/上架时间·商品状态/创建/修改/同步/操作(11 列)', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
const cells = wrapper.findAll('tbody tr')[0].findAll('td')
expect(cells).toHaveLength(9)
expect(cells).toHaveLength(11)
expect(cells[0].find('input[type="checkbox"]').exists()).toBe(true, '第 1 列是勾选框')
expect(cells[1].text()).toBe('旗舰自营店', '第 2 列=店铺(用户口径前置为第 1 数据列)')
expect(cells[2].text()).toBe('甲组', '第 3 列=分组')
// 商品信息列=京麦同款合并布局:主图+信息分+标题+商品编码+货号+SKU 标签。
expect(cells[1].text()).toBe('旗舰自营店', '第 2 列=店铺(admin 专属,置前)')
expect(cells[2].text()).toBe('甲组', '第 3 列=分组(admin 专属)')
// 商品信息列=京麦同款合并布局:主图+信息分+标题+商品编码+货号+品牌·类目行+SKU 标签。
const info = cells[3]
expect(info.find('.jd-thumb').exists()).toBe(true, '商品信息列含主图')
expect(info.text()).toContain('304不锈钢保温杯')
expect(info.text()).toContain('JD-1001', '商品编码并入商品信息列')
expect(info.text()).toContain('ITEM-1', '货号并入商品信息列')
expect(info.text()).toContain('锅宝', '品牌并入商品信息列(京麦品牌·类目行)')
expect(info.text()).toContain('家居 > 厨具 > 保温杯', '类目随品牌·类目行上列表(京麦同款)')
expect(info.text()).toContain('12个SKU')
expect(info.text()).toContain('信息分 81')
expect(cells[4].text()).toBe('锅宝')
expect(cells[5].text()).toBe('12.90 ~ 15.90', '价格区间=min ~ max')
expect(cells[6].text()).toBe('500', '总库存列')
expect(cells[7].text()).toBe('上架中')
expect(cells[8].text()).not.toBe('-', '同步时间格式化展示')
// 类目/上架时间/京东创建/修改时间仍收进详情抽屉(信息分/SKU 数 2026-11-15 起随京麦样式回列表)。
expect(cells[4].text()).toBe('500', '第 4 数据列=总库存(京麦第 2 列)')
expect(cells[5].text()).toBe('12.90 ~ 15.90', '第 5 数据列=价格(京麦第 3 列)')
expect(cells[6].text()).toContain('上架中', '第 6 数据列=上架时间/商品状态(京麦合并列)')
expect(cells[6].find('.jd-sale-dot').exists()).toBe(true, '状态带京麦同款圆点')
expect(cells[7].text()).not.toBe('-', '第 7 数据列=创建时间')
expect(cells[8].text()).not.toBe('-', '第 8 数据列=修改时间')
expect(cells[9].text()).not.toBe('-', '第 9 数据列=同步时间(admin 专属,置末)')
expect(cells[10].text()).toContain('编辑', '第 10 数据列=操作(编辑/删除)')
// 表头字段名与顺序与京麦一致;品牌/类目不再是独立列(收进商品信息)。
const headerText = wrapper.find('thead').text()
for (const gone of ['类目', '上架时间', '创建时间', '修改时间']) {
expect(headerText).not.toContain(gone, `${gone}列已收进详情抽屉,不再上列表`)
for (const gone of ['品牌', '类目']) {
expect(headerText).not.toContain(gone, `${gone}不再是独立列(京麦把它们收进商品信息)`)
}
for (const head of ['商品信息', '总库存', '价格', '上架时间 / 商品状态', '创建时间', '修改时间', '同步时间']) {
expect(headerText).toContain(head, `表头必须有「${head}」(京麦字段名)`)
}
expect(wrapper.find('.jd-thumb').exists()).toBe(true, '商品信息列渲染缩略图')
})
it('操作列删除按钮防冒泡且走确认弹窗:确认后调 deleteJdProducts,取消不动(2026-11-15 行级删除)', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
// beforeEach 默认 confirm=true;本例先翻回 false 验「取消不动」。
confirmMock.mockResolvedValue(false)
const opsCell = wrapper.findAll('tbody tr')[0].findAll('td')[10]
await opsCell.findAll('button').find((b) => b.text() === '删除')!.trigger('click')
await flushPromises()
// 防冒泡:点删除不得顺手打开详情抽屉(抽屉的可视判据=.drawer 出现)。
expect(wrapper.find('.drawer').exists()).toBe(false, '删除按钮 @click.stop,点它不开详情抽屉')
expect(confirmMock).toHaveBeenCalledTimes(1, '删除必须过二次确认')
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(0, '确认弹窗取消时不发删除请求')
// 确认后:deleteJdProducts 按公司 tab 下传(id, companyId)。
confirmMock.mockResolvedValue(true)
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
await wrapper.findAll('tbody tr')[0].findAll('td')[10].findAll('button').find((b) => b.text() === '删除')!.trigger('click')
await flushPromises()
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1], 1)
})
it('操作列编辑按钮防冒泡且打开编辑抽屉(抽屉自取详情回填,2026-11-15 行级编辑)', async () => {
// fetchJdProductDetail 的返回已由 parseJdProductDetail 归一成 {item, attrGroups, images, skus, attrJsonRaw}。
jdApi.fetchJdProductDetail.mockResolvedValue({
item: {
id: 1,
title: '304不锈钢保温杯大容量便携',
brand: '锅宝',
categoryPath: '家居 > 厨具 > 保温杯',
itemNum: 'ITEM-1',
priceMin: '12.90',
priceMax: '15.90',
stockTotal: 500,
saleStatus: '上架中',
groupId: 7,
groupName: '甲组',
productCode: 'JD-1001',
shopName: '旗舰自营店',
},
attrGroups: [],
images: [],
skus: [],
attrJsonRaw: '',
})
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
const opsCell = wrapper.findAll('tbody tr')[0].findAll('td')[10]
await opsCell.findAll('button').find((b) => b.text() === '编辑')!.trigger('click')
await flushPromises()
await flushPromises()
expect(wrapper.find('.drawer').exists()).toBe(true, '编辑抽屉打开')
expect(wrapper.text()).toContain('编辑商品', '抽屉标题点商品')
// 抽屉按 (id, companyId) 自取详情回填。
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1, 1)
// 编辑抽屉的保存提示文案点名人工编辑锁后果(用户保存前看得见「采集不再覆盖」)。
expect(wrapper.text()).toContain('人工维护', '保存后果提示常驻(V199 人工编辑锁)')
})
it('商品信息列:主图无 URL 显示「无图」占位、healthScore 为空不出信息分行、skuCount 为空不出 SKU 标签', async () => {
const wrapper = await mountWith({
items: [item(1), item(2, { mainImageUrl: '', healthScore: null, skuCount: null })],
@@ -153,16 +219,15 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(wrapper.findAll('tbody tr')[0].findAll('td')[2].text()).toBe('未分组')
})
it('筛选生效:店铺/编码/关键字/状态/分组/起止日期,查询回第一页重发', async () => {
it('筛选生效:店铺/编码/关键字/分组/起止日期,查询回第一页重发', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
const textInputs = wrapper.findAll('.form-group input[type="text"]')
expect(textInputs).toHaveLength(4, '店铺+商品编码+标题关键字+商品状态四个文本筛选框')
expect(textInputs).toHaveLength(3, '店铺+商品编码+标题关键字三个文本筛选框(商品状态已下线)')
await textInputs[0].setValue('旗舰自营店')
await textInputs[1].setValue('JD-1001')
await textInputs[2].setValue('保温杯')
await textInputs[3].setValue('上架中')
await wrapper.find('select').setValue('7')
const dateInputs = wrapper.findAll('input[type="date"]')
await dateInputs[0].setValue('2026-11-01')
@@ -175,13 +240,13 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
shopName: '旗舰自营店',
productCode: 'JD-1001',
titleKeyword: '保温杯',
saleStatus: '上架中',
groupId: '7',
syncedFrom: '2026-11-01',
syncedTo: '2026-11-09',
page: 1,
companyId: 1,
})
expect(last).not.toHaveProperty('saleStatus', '商品状态筛选已下线,入参不再带 saleStatus')
})
it('分组下拉选中即查', async () => {
@@ -204,6 +269,29 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
})
it('类目下拉:选项来自 GET /categories(带商品数),选中即查回第一页', async () => {
jdApi.fetchJdProductCategories.mockResolvedValue([
{ name: '服饰内衣', productCount: 120 },
{ name: '运动户外', productCount: 8 },
])
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1)
// 第 1 个 select = 分组(既有契约不动),类目下拉紧随其后
const selects = wrapper.findAll('.jd-filter-row select')
expect(selects).toHaveLength(2)
const categorySelect = selects[1]
const optionTexts = categorySelect.findAll('option').map((o) => o.text())
expect(optionTexts[0]).toBe('全部类目')
expect(optionTexts).toContain('服饰内衣(120)')
const callsBeforeSelect = jdApi.fetchJdProductList.mock.calls.length
await categorySelect.setValue('运动户外')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeSelect + 1, '选中类目必须立刻重查')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '运动户外', page: 1 })
})
it('重置把筛选面回空并回第一页重取', async () => {
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
const textInputs = wrapper.findAll('.form-group input[type="text"]')
@@ -235,48 +323,11 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(last.page).toBe(1, '改每页条数后回第一页')
})
it('导出=当前过滤面全量(含公司 tab 与分组),成功反馈点名落盘文件', async () => {
const createObjectURL = vi.fn(() => 'blob:mock-url')
const revokeObjectURL = vi.fn()
const urlRecord = URL as unknown as Record<string, unknown>
Object.defineProperty(URL, 'createObjectURL', { value: createObjectURL, configurable: true, writable: true })
Object.defineProperty(URL, 'revokeObjectURL', { value: revokeObjectURL, configurable: true, writable: true })
const clickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
jdApi.exportJdProductList.mockImplementation(() =>
Promise.resolve({ blob: new Blob(['xlsx']), filename: '京东数据库-20261114090000.xlsx' }),
)
try {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
const btn = wrapper.findAll('button').find((b) => b.text() === '导出')
expect(btn, '筛选行必须有「导出」按钮').toBeTruthy()
await btn!.trigger('click')
await flushPromises()
await flushPromises()
expect(jdApi.exportJdProductList).toHaveBeenCalledTimes(1)
const call = jdApi.exportJdProductList.mock.calls[0][0]
expect(call).toMatchObject({ shopName: '', groupId: '', companyId: 1 })
expect(createObjectURL).toHaveBeenCalledTimes(1)
expect(clickSpy).toHaveBeenCalled()
expect(document.body.textContent).toContain('已导出', '成功反馈点名落盘文件')
} finally {
Object.defineProperty(URL, 'createObjectURL', { value: undefined, configurable: true, writable: true })
Object.defineProperty(URL, 'revokeObjectURL', { value: undefined, configurable: true, writable: true })
clickSpy.mockRestore()
}
})
it('导出失败把服务端业务文案弹出来,不许静默;在途标记复位', async () => {
jdApi.exportJdProductList.mockImplementation(() => Promise.reject(new Error('京东商品共 80001 行,超过导出上限 50000 行,请缩小筛选范围后重试')))
it('导出按钮已下线:筛选行不再出现「导出」(2026-11-15 客户口径「导出也不用」)', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
await wrapper.findAll('button').find((b) => b.text() === '导出')!.trigger('click')
await flushPromises()
await flushPromises()
expect(document.body.textContent).toContain('超过导出上限')
const btn = wrapper.findAll('button').find((b) => b.text() === '导出')
expect(btn!.text()).toBe('导出', '失败后在途标记必须复位')
expect((btn!.element as HTMLButtonElement).disabled).toBe(false)
expect(btn, '导出按钮必须已从前端移除').toBeUndefined()
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1, '下线导出不影响列表首屏')
})
it('点行打开详情抽屉:按 (id, companyId) 取详情,attrGroups 分块渲染', async () => {
@@ -460,6 +511,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
expect(last.shopName).toBe('', '切公司必须清掉上一家的店铺名')
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
expect(last.groupId).toBe('', '切公司必须清掉上一家选的分组')
expect(last).not.toHaveProperty('category', '切公司必须清掉上一家选的类目')
expect(last.page).toBe(1)
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(2)
})