feat(京东上架): 京麦品牌候选上报+用户端联想输入(V220)

- 后端:biz_jd_shop_brand(V220)+JdShopBrandService 增量 upsert/list/recordUsedTarget
  +POST/GET /api/jd-shop-brands(requireUserOrInternal,ApiGuard 覆盖登记)
- 用户端:endpoints.jdPublish.shopBrands+jd-brand-options 纯函数+JdPublishTab 目标品牌
  改 el-autocomplete(手输永远生效)
- 台账:TaskFailureCategoryGuardrailTest updateById 写点 164→165(JdShopBrandService.report,
  实体无 ALWAYS 列、row 为读回新鲜行,审过登记)

来源:2026-11-28 客户口径「品牌看看能不能获取下来,也可以支持自己输入」
未发版:V220 随 jar 迁移、app-web 需重发、客户端候选上报随 5.1.4
This commit is contained in:
2026-11-28 17:29:46 +08:00
parent d8a85e6ff5
commit 3de3e2e0ca
17 changed files with 1005 additions and 16 deletions
@@ -10,13 +10,14 @@ import {
const api = vi.hoisted(() => ({
create: vi.fn(), activate: vi.fn(), products: vi.fn(), groups: vi.fn(),
history: vi.fn(), progress: vi.fn(), dashboard: vi.fn(), retry: vi.fn(), enqueue: vi.fn(), bridge: vi.fn(),
protocol: vi.fn(), retryBrand: vi.fn(), alert: vi.fn(), prompt: vi.fn(), shop: vi.fn(),
protocol: vi.fn(), retryBrand: vi.fn(), alert: vi.fn(), prompt: vi.fn(), shop: vi.fn(), brands: vi.fn(),
}))
vi.mock('@/shared/api/types/modules/jd-collect', () => ({ fetchJdCollectGroups: api.groups }))
vi.mock('@/shared/api/types/modules/jd-publish', () => ({
createJdPublishTask: api.create,
retryJdPublishBrand: api.retryBrand,
fetchJdShopBrands: api.brands,
activateJdPublishTask: api.activate,
fetchJdPublishDashboard: api.dashboard,
fetchJdPublishHistory: api.history,
@@ -66,6 +67,13 @@ async function mountPage() {
ElSelect: { props: ['modelValue'], emits: ['update:modelValue', 'change'], template: '<div><slot /></div>' },
ElPagination: { emits: ['current-change'], template: '<div />' }, ElInputNumber: true,
ElDrawer: { props: ['modelValue'], template: '<div v-if="modelValue"><slot /></div>' },
// 目标品牌输入框是 el-autocomplete(2026-11-28 品牌候选联想):替身只要「真 input+
// v-model 双向」,联想列表本身由 jd-brand-options 纯函数用例与源码绊线覆盖。
ElAutocomplete: {
props: ['modelValue', 'fetchSuggestions', 'valueKey', 'triggerOnFocus', 'debounce', 'clearable'],
emits: ['update:modelValue'],
template: '<input :value="modelValue" @input="$emit(\'update:modelValue\', $event.target.value)" />',
},
},
directives: { loading: () => undefined },
},
@@ -76,7 +84,7 @@ async function mountPage() {
async function startPublish(page: VueWrapper, brand = ' 示例品牌 ') {
// 2026-11-26 晚客户口径「商品信息不要显示,选分类上架就行」:选中分类即整分类上架,无逐行勾选步骤。
await page.get('.target-brand-input').setValue(brand)
await page.get('#jd-publish-target-brand').setValue(brand)
await page.get('.collect-btn').trigger('click')
await flushPromises()
}
@@ -92,6 +100,7 @@ beforeEach(() => {
api.progress.mockResolvedValue(batch(row('PENDING', 0)))
api.bridge.mockReturnValue({ jd_publish_protocol: api.protocol, enqueue_json: api.enqueue })
api.protocol.mockResolvedValue(3)
api.brands.mockResolvedValue({ items: [], total: 0 })
api.alert.mockResolvedValue(undefined)
api.enqueue.mockResolvedValue({ success: true })
api.retry.mockResolvedValue(null)
@@ -184,7 +193,7 @@ it('选分类=自动分页拉全本分类全部商品并整批建单,商品
expect(page.find('.product-pager').exists()).toBe(false)
expect(page.find('.product-select-all').exists()).toBe(false)
expect(page.get('.collect-btn').text()).toContain('上架本分类 3 个商品')
await page.get('.target-brand-input').setValue('示例品牌')
await page.get('#jd-publish-target-brand').setValue('示例品牌')
await page.get('.collect-btn').trigger('click')
await flushPromises()
expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23, 24, 25], { mode: 'none' }, '示例品牌')
@@ -389,7 +398,7 @@ it('协议 3 的本机遇跨店只给升级提示,一条都不建单', async (
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
api.protocol.mockResolvedValue(3)
const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌')
await page.get('#jd-publish-target-brand').setValue('示例品牌')
// 挂载即自动检测(2026-11-28 口径):检测到异店=跨店档,协议 <4 按钮直接禁用+升级提示
await flushPromises()
expect(api.shop).toHaveBeenCalledOnce()
@@ -406,7 +415,7 @@ it('协议 4 跨店:挂载自动检测显形目标店与琥珀说明,直接
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
api.protocol.mockResolvedValue(4)
const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌')
await page.get('#jd-publish-target-brand').setValue('示例品牌')
await flushPromises()
expect(page.text()).toContain('跨店上架')
@@ -436,7 +445,7 @@ it('多店未检测京麦:不拦建单,带 targetFromLogin 且不带目标
api.bridge.mockReturnValue({ jd_publish_protocol: api.protocol, enqueue_json: api.enqueue })
api.protocol.mockResolvedValue(4)
const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌')
await page.get('#jd-publish-target-brand').setValue('示例品牌')
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(false)
// 2026-11-28 客户口径「不存在发错店的情况」:未检测档不再出琥珀警告小字(含「发错店判死」句)
expect(page.text()).not.toContain('将按京麦当前登录店铺新建上架')
@@ -456,7 +465,7 @@ it('多店未检测且协议 3:仍拦(NEW 任务只投给 v4+ 客户端,
api.bridge.mockReturnValue({ jd_publish_protocol: api.protocol, enqueue_json: api.enqueue })
api.protocol.mockResolvedValue(3)
const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌')
await page.get('#jd-publish-target-brand').setValue('示例品牌')
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(true)
expect(page.text()).toContain('升级')
await startPublish(page)
@@ -522,3 +531,55 @@ it('分类非空时不出空态告警(v-if 不成立),常驻解释句已
expect(page.text()).not.toContain('分类由管理员在后台「京东数据库」维护')
})
// ---- 目标品牌候选(2026-11-28 客户口径「品牌看看能不能获取下来,也可以支持自己输入」)----
// 候选=客户端在发布表单里抓到的本店真名品牌(服务端 biz_jd_shop_brand 增量积累);
// 输入框是联想(el-autocomplete),**手输始终保留**——候选空/读取失败都不拦建单。
it('检测到京麦店后按店铺 id 拉本店品牌候选,灰字点名可以选也可以手输', async () => {
api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
})
api.brands.mockResolvedValue({ items: [
{ brandId: '1343010', brandName: '无', companySuffix: '某某贸易有限公司', lastSeenAt: '2026-11-28 14:00:00' },
{ brandId: '-1', brandName: '无品牌', lastSeenAt: '2026-11-27 09:00:00' },
], total: 2 })
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
const page = await mountPage()
await flushPromises()
expect(api.brands).toHaveBeenCalledExactlyOnceWith('228346061', undefined, 200)
const hint = page.get('#jd-publish-brand-hint').text()
expect(hint).toContain('本次选中的商品统一使用此品牌')
expect(hint).toContain('可直接从本店历史品牌里选,也可以手动输入品牌名')
// 品牌 id 只用于服务端去重,不上屏(客户口径「shopId 啥的不要搞复杂」同款)。
expect(hint).not.toContain('1343010')
})
it('品牌候选读不到不拦建单:灰字点名手输,手输品牌原样进建单', async () => {
api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
})
api.brands.mockRejectedValue(new Error('网络断了'))
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
const page = await mountPage()
await flushPromises()
expect(page.get('#jd-publish-brand-hint').text()).toContain('请直接手动输入京麦里的品牌名称')
await startPublish(page, ' 无品牌 ')
expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23], { mode: 'none' }, '无品牌')
})
it('本店还没有候选时灰字点名「成功发布过一次后会自动积累」,手输照样可用', async () => {
api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
})
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
const page = await mountPage()
await flushPromises()
expect(page.get('#jd-publish-brand-hint').text())
.toContain('客户端成功发布过一次后会自动积累')
await startPublish(page, '无')
expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23], { mode: 'none' }, '无')
})