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:
@@ -16,11 +16,18 @@ import {
|
||||
fetchJdPublishHistory,
|
||||
fetchJdPublishProducts,
|
||||
fetchJdPublishTaskProgressBatch,
|
||||
fetchJdShopBrands,
|
||||
interruptJdPublishTask,
|
||||
retryJdPublishBrand,
|
||||
type JdPublishHistoryItemVo,
|
||||
type JdPublishProductVo,
|
||||
} from '@/shared/api/types/modules/jd-publish'
|
||||
import {
|
||||
brandOptionsFromRows,
|
||||
brandOptionsHint,
|
||||
filterBrandOptions,
|
||||
type JdShopBrandOption,
|
||||
} from '@/pages/jd/jd-brand-options'
|
||||
import { retryClientTask } from '@/shared/api/task-retry'
|
||||
import { getPywebviewApi } from '@/shared/bridges/pywebview'
|
||||
import { ensureJdLogin, markJdLoginExpired } from '@/shared/stores/jd-login-autoflow'
|
||||
@@ -170,6 +177,56 @@ function isValidBrand(name: string) {
|
||||
return name.length > 0 && name.length <= TARGET_BRAND_MAX
|
||||
}
|
||||
|
||||
// ---- 目标品牌候选(2026-11-28 客户口径「品牌看看能不能获取下来,也可以支持自己输入」)----
|
||||
/** 候选来自客户端在发布表单里抓到的真名品牌(服务端 `biz_jd_shop_brand` 增量积累)。
|
||||
* 京麦品牌只能按关键词远程搜索,没有全量清单,所以这里展示的是「本店见过的」那批;
|
||||
* **手输始终保留**——列表空、读取失败都不拦建单(品牌是否可用由客户端回读校验兜底)。 */
|
||||
const BRAND_OPTIONS_LIMIT = 200
|
||||
const brandOptions = ref<JdShopBrandOption[]>([])
|
||||
const brandOptionsLoading = ref(false)
|
||||
const brandOptionsFailed = ref(false)
|
||||
|
||||
/** 候选归属店铺:优先京麦当前登录店(真正的发布目标),其次来源店(单店克隆的上架目标)。 */
|
||||
const brandShopId = computed(() => {
|
||||
const guard = shopGuard.value
|
||||
const target = guard.state === 'cross' || guard.state === 'multi' ? guard.target : null
|
||||
const fromGuard = guard.state === 'undetected' || guard.state === 'match' ? guard.expected.shopId : ''
|
||||
return currentShop.value?.shopId || target?.shopId || fromGuard || ''
|
||||
})
|
||||
|
||||
const brandHint = computed(() => brandOptionsHint({
|
||||
loading: brandOptionsLoading.value,
|
||||
failed: brandOptionsFailed.value,
|
||||
count: brandOptions.value.length,
|
||||
}))
|
||||
|
||||
async function loadBrandOptions(shopId: string) {
|
||||
if (!shopId) {
|
||||
brandOptions.value = []
|
||||
brandOptionsFailed.value = false
|
||||
return
|
||||
}
|
||||
brandOptionsLoading.value = true
|
||||
brandOptionsFailed.value = false
|
||||
try {
|
||||
const vo = await fetchJdShopBrands(shopId, undefined, BRAND_OPTIONS_LIMIT)
|
||||
brandOptions.value = brandOptionsFromRows(vo?.items)
|
||||
} catch (error) {
|
||||
// 候选只是输入便利:读不到就落一句灰字让客户直接手输,绝不拦建单。
|
||||
brandOptions.value = []
|
||||
brandOptionsFailed.value = true
|
||||
console.warn('[jd-publish] 读取本店品牌候选失败:%s',
|
||||
error instanceof Error ? error.message : String(error))
|
||||
} finally {
|
||||
brandOptionsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 联想候选:本地过滤(候选是本店已积累的小集合,逐字符发请求只会让列表抖动)。 */
|
||||
function queryBrandOptions(query: string, callback: (items: JdShopBrandOption[]) => void) {
|
||||
callback(filterBrandOptions(brandOptions.value, query))
|
||||
}
|
||||
|
||||
const priceValueMissing = computed(() => priceMode.value !== 'none' && (priceValue.value == null || priceValue.value < 0))
|
||||
|
||||
// ---- 本次上架到哪家店(2026-11-24 客户口径「软件怎么知道要上架哪一家店铺」)----
|
||||
@@ -789,6 +846,10 @@ async function startPublish() {
|
||||
}
|
||||
}
|
||||
|
||||
// 目标品牌候选随「发布到哪家店」变:选分类/检测到京麦店后按店铺 id 拉一次本店历史品牌
|
||||
// (挂载时可能还不知道店,watch 一拿到 id 就补拉;换店铺重新拉,旧店候选不许留在下拉里)。
|
||||
watch(brandShopId, (shopId) => { void loadBrandOptions(shopId) }, { immediate: true })
|
||||
|
||||
onMounted(async () => {
|
||||
const localName = (window.localStorage.getItem('username') || '').trim()
|
||||
if (localName) username.value = localName
|
||||
@@ -910,10 +971,19 @@ onUnmounted(() => {
|
||||
|
||||
<div class="category-block">
|
||||
<label class="category-label" for="jd-publish-target-brand">目标品牌名称(必填)</label>
|
||||
<input id="jd-publish-target-brand" v-model="targetBrandInput" class="target-brand-input" type="text"
|
||||
required :aria-invalid="Boolean(targetBrandInput && !isValidBrand(targetBrandName))"
|
||||
aria-describedby="jd-publish-brand-hint" placeholder="输入当前京麦店铺可用的品牌名称" />
|
||||
<p id="jd-publish-brand-hint" class="category-hint">本次选中的商品统一使用此品牌。</p>
|
||||
<!-- 2026-11-28 客户口径「品牌看看能不能获取下来,也可以支持自己输入」:联想列表给
|
||||
客户端抓到过的本店真名品牌,**输入框照样能手输**(autocomplete 不拦自由文本)。 -->
|
||||
<el-autocomplete id="jd-publish-target-brand" v-model="targetBrandInput"
|
||||
:class="['target-brand-input', { 'target-brand-invalid': Boolean(targetBrandInput && !isValidBrand(targetBrandName)) }]"
|
||||
:fetch-suggestions="queryBrandOptions" :trigger-on-focus="true" :debounce="0" value-key="brandName"
|
||||
clearable required :aria-invalid="Boolean(targetBrandInput && !isValidBrand(targetBrandName))"
|
||||
aria-describedby="jd-publish-brand-hint" placeholder="输入或选择当前京麦店铺可用的品牌名称">
|
||||
<template #default="{ item }">
|
||||
<span class="brand-option-name">{{ item.brandName }}</span>
|
||||
<span v-if="item.companySuffix" class="brand-option-company">{{ item.companySuffix }}</span>
|
||||
</template>
|
||||
</el-autocomplete>
|
||||
<p id="jd-publish-brand-hint" class="category-hint">本次选中的商品统一使用此品牌。{{ brandHint }}</p>
|
||||
</div>
|
||||
|
||||
<button class="collect-btn" type="button" :disabled="submitDisabled" @click="startPublish">
|
||||
@@ -1015,8 +1085,14 @@ onUnmounted(() => {
|
||||
.product-head { display: flex; align-items: center; justify-content: space-between; }
|
||||
.product-head .category-label { margin-bottom: 8px; }
|
||||
.product-empty { padding: 18px 0; color: #5f6c85; font-size: 12px; text-align: center; }
|
||||
.target-brand-input { box-sizing: border-box; width: 100%; padding: 8px 10px; border: 1px solid #3e4a62; border-radius: 6px; background: #232b3d; color: #c8d2e2; font: inherit; }
|
||||
.target-brand-input[aria-invalid="true"] { border-color: #fca5a5; }
|
||||
/* 目标品牌改成 el-autocomplete(2026-11-28):底色/边框落在 el-input 外壳上,
|
||||
沿用改价输入框的深色口径;无效品牌名只在有输入时标红(空值是另一句错误)。 */
|
||||
.target-brand-input { display: block; width: 100%; }
|
||||
.target-brand-input :deep(.el-input__wrapper) { background-color: #232b3d; box-shadow: 0 0 0 1px #3e4a62 inset; }
|
||||
.target-brand-input :deep(.el-input__inner) { color: #c8d2e2; }
|
||||
.target-brand-invalid :deep(.el-input__wrapper) { box-shadow: 0 0 0 1px #fca5a5 inset; }
|
||||
.brand-option-name { margin-right: 8px; }
|
||||
.brand-option-company { color: #8b97a9; font-size: 12px; }
|
||||
.price-input { width: 100%; margin-top: 8px; }
|
||||
.price-input :deep(.el-input__wrapper) { background-color: #232b3d; box-shadow: 0 0 0 1px #3e4a62 inset; }
|
||||
.price-input :deep(.el-input__inner) { color: #c8d2e2; }
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/**
|
||||
* 目标品牌候选(2026-11-28 客户口径「品牌看看能不能获取下来,也可以支持自己输入」)。
|
||||
*
|
||||
* 京麦品牌是**按关键词远程搜索**的(输入才出候选),没有可离线拉取的全量清单:客户端每次
|
||||
* 在发布表单的品牌面板里看到真实候选(文本形状 `品牌名[品牌id]-公司名`)就增量上报
|
||||
* `/api/jd-shop-brands`,本页把这些真名候选做成目标品牌输入的联想列表。
|
||||
*
|
||||
* 三条边界:
|
||||
* 1. **手输始终保留**:候选只是便利通道,列表空/读不到都不影响建单(品牌是否可用最终由
|
||||
* 客户端在京麦表单里回读校验,不是靠这份缓存);
|
||||
* 2. **只展示品牌名**:京麦 id(可为负,「无品牌」=-1)只用于服务端去重,不上屏、不进建单
|
||||
* 载荷(建单要的是 `targetBrandName`);
|
||||
* 3. 同名不同公司靠 `companySuffix` 区分,展示成副标题而不是品牌名的一部分。
|
||||
*
|
||||
* 本文件是纯函数(node --test 直测):只产选项与中文文案,取数/渲染由页面做。
|
||||
*/
|
||||
|
||||
/** 下拉选项(服务端 `JdShopBrandVo.items` 裁剪后的形状)。 */
|
||||
export interface JdShopBrandOption {
|
||||
brandId: string;
|
||||
brandName: string;
|
||||
companySuffix: string;
|
||||
lastSeenAt: string;
|
||||
}
|
||||
|
||||
/** 服务端候选行的最小子集(页面直接传 VO 进 normalized 即可)。 */
|
||||
export interface JdShopBrandSource {
|
||||
brandId?: string;
|
||||
brandName?: string;
|
||||
companySuffix?: string;
|
||||
lastSeenAt?: string;
|
||||
}
|
||||
|
||||
/** 候选读取的状态文案:加载中 / 有候选 / 还没抓到过 / 读取失败。 */
|
||||
export const BRAND_OPTIONS_LOADING_HINT = '正在读取本店历史品牌…';
|
||||
export const BRAND_OPTIONS_READY_HINT = '可直接从本店历史品牌里选,也可以手动输入品牌名。';
|
||||
export const BRAND_OPTIONS_EMPTY_HINT =
|
||||
'本店还没有历史品牌记录(客户端成功发布过一次后会自动积累),请直接手动输入京麦里的品牌名称。';
|
||||
export const BRAND_OPTIONS_UNAVAILABLE_HINT = '暂时读不到本店历史品牌,请直接手动输入京麦里的品牌名称。';
|
||||
|
||||
function text(value: unknown): string {
|
||||
return String(value ?? '').trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 服务端行 → 选项:丢掉没有品牌名的行(名字是唯一可展示、可手输对齐的字段),
|
||||
* 按 `brandId`(缺 id 时按品牌名)去重,保留服务端给的顺序(=最近看到时间倒序)。
|
||||
*/
|
||||
export function brandOptionsFromRows(rows: JdShopBrandSource[] | null | undefined): JdShopBrandOption[] {
|
||||
const seen = new Set<string>();
|
||||
const options: JdShopBrandOption[] = [];
|
||||
for (const raw of rows ?? []) {
|
||||
const brandName = text(raw?.brandName);
|
||||
if (!brandName) continue;
|
||||
const brandId = text(raw?.brandId);
|
||||
const key = brandId || `name:${brandName}`;
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
options.push({
|
||||
brandId,
|
||||
brandName,
|
||||
companySuffix: text(raw?.companySuffix),
|
||||
lastSeenAt: text(raw?.lastSeenAt),
|
||||
});
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键词过滤(空关键词=全量):品牌名与公司名都参与匹配,大小写不敏感。
|
||||
* 本地过滤而不是远程搜索——候选是本店已积累的小集合(服务端上限 200 条),
|
||||
* 输入时逐字符发请求只会让联想列表抖动。
|
||||
*/
|
||||
export function filterBrandOptions(
|
||||
options: JdShopBrandOption[] | null | undefined,
|
||||
keyword: string | null | undefined,
|
||||
): JdShopBrandOption[] {
|
||||
const rows = options ?? [];
|
||||
const needle = text(keyword).toLowerCase();
|
||||
if (!needle) return rows;
|
||||
return rows.filter((option) => option.brandName.toLowerCase().includes(needle)
|
||||
|| option.companySuffix.toLowerCase().includes(needle));
|
||||
}
|
||||
|
||||
/** 下拉行主文案:品牌名;有公司名时补一行副标题(同名不同公司靠它区分)。 */
|
||||
export function brandOptionLabel(option: JdShopBrandOption): string {
|
||||
return option.companySuffix ? `${option.brandName} · ${option.companySuffix}` : option.brandName;
|
||||
}
|
||||
|
||||
/** 输入框下方那句灰字:四种状态各一句,切状态不出现空串(空串会让客户以为功能没做)。 */
|
||||
export function brandOptionsHint(input: {
|
||||
loading?: boolean;
|
||||
failed?: boolean;
|
||||
count?: number;
|
||||
}): string {
|
||||
if (input.failed) return BRAND_OPTIONS_UNAVAILABLE_HINT;
|
||||
if (input.loading) return BRAND_OPTIONS_LOADING_HINT;
|
||||
return (input.count ?? 0) > 0 ? BRAND_OPTIONS_READY_HINT : BRAND_OPTIONS_EMPTY_HINT;
|
||||
}
|
||||
@@ -250,6 +250,10 @@ export const API_ENDPOINTS = {
|
||||
onShelf: '/api/jd-publish/on-shelf',
|
||||
/** 标记/取消标记已下架(按商品整组腾额度) */
|
||||
markDelisted: '/api/jd-publish/items/{itemId}/delisted',
|
||||
/** 京麦店铺品牌候选(2026-11-28 客户口径「品牌看看能不能获取下来,也可以支持自己输入」):
|
||||
* 客户端在发布表单的品牌面板里抓到真名候选就增量上报,用户端目标品牌输入框读它做联想;
|
||||
* 京麦品牌只能按关键词远程搜索,没有可离线拉取的全量清单。 */
|
||||
shopBrands: '/api/jd-shop-brands',
|
||||
},
|
||||
userSecret: {
|
||||
bundle: '/api/user-secrets',
|
||||
|
||||
@@ -73,6 +73,41 @@ export function retryJdPublishBrand(taskId: number, targetBrandName: string, res
|
||||
))
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 目标品牌候选(2026-11-28 客户口径「品牌看看能不能获取下来,也可以支持自己输入」):
|
||||
// 京麦品牌只能按关键词远程搜索、没有全量清单,所以候选由客户端在发布表单里抓到后增量上报
|
||||
// (`POST /api/jd-shop-brands`,shop_id+brand_id 幂等 upsert);本页只读它做输入联想,
|
||||
// 手输始终保留——列表空/读不到都不影响建单。
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** 候选行:`brandId` 是京麦 id(可为负,「无品牌」=-1;手输品牌记作 `name:<品牌名>`),只用于去重。 */
|
||||
export interface JdShopBrandItemVo {
|
||||
brandId?: string;
|
||||
brandName?: string;
|
||||
companySuffix?: string;
|
||||
lastSeenAt?: string;
|
||||
}
|
||||
|
||||
export interface JdShopBrandListVo {
|
||||
items?: JdShopBrandItemVo[];
|
||||
total?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取某店铺已积累的品牌候选(按最近看到时间倒序;keyword 走品牌名模糊)。
|
||||
* 空列表只表示「这家店还没抓到过候选」,调用方必须仍允许手输。
|
||||
*/
|
||||
export function fetchJdShopBrands(shopId: string, keyword?: string, limit = 200) {
|
||||
const params: Record<string, unknown> = { shopId, limit };
|
||||
if (keyword) params.keyword = keyword;
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<JdShopBrandListVo>>(
|
||||
buildJavaUrl(API_ENDPOINTS.jdPublish.shopBrands),
|
||||
{ params },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 选品分页(2026-11-25 作用域):服务端回归本账号可见数据权限分组下的分类归属商品行
|
||||
// (同组同事采集的也在内;跨公司/跨组不可见——与分类下拉/徽标同源)。
|
||||
|
||||
Reference in New Issue
Block a user