From f88b3d4622adc204ad5af640399daf47c56c8d21 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com>
Date: Thu, 26 Nov 2026 11:51:34 +0800
Subject: [PATCH] =?UTF-8?q?feat(=E4=BA=AC=E4=B8=9C=E8=B7=A8=E5=BA=97?=
=?UTF-8?q?=E4=B8=8A=E6=9E=B6):=20=E7=94=A8=E6=88=B7=E7=AB=AF=20cross=20?=
=?UTF-8?q?=E6=A1=A3=20+=20=E7=9B=AE=E6=A0=87=E5=BA=97=E4=BA=8C=E6=AC=A1?=
=?UTF-8?q?=E7=A1=AE=E8=AE=A4=20+=20=E5=8D=8F=E8=AE=AE=204=20=E9=97=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
客户口径「要跨店」:异店不再硬拦,改成显形目标店 + 风险确认后建单(客户端走京麦新增商品)。
- jd-publish-shop:evaluateShopGuard 加 cross 态(目标店=京麦当前登录店);
shopGuardBlocks/shopGuardMessage 接受 crossAllowed,协议 <4 时仍拦并给升级文案
- JdPublishTab:跨店显形「目标店(跨店)」行、琥珀风险句(会在目标店新建商品并过京东审核、
目标店须已授权该类目)、原生勾选二次确认作硬闸;按钮文案改「跨店上架 N 个商品到目标店」;
协议 >=4 才放行;建单请求带 targetShopId/targetShopName
- api:createJdPublishTask 增加可选 targetShop,body 按需带两个键
判据:jd-publish-shop.test.ts 17 支(cross 五态、跨店文案不写「稍后重试」、协议常量与源码绊线)、
mount 32 支(协议 3 只给升级提示不建单、协议 4 确认后带目标店建单);三次反向验证改坏即红。
node --test 1147/vitest 149/vue-tsc --noEmit rc=0;可读基线 JdPublishTab.vue 1014→1075 逐条点名。
---
frontend-vue/src/pages/jd/JdPublishTab.vue | 113 ++++++++++++++----
frontend-vue/src/pages/jd/jd-publish-shop.ts | 58 ++++++---
.../shared/api/types/modules/jd-publish.ts | 5 +
frontend-vue/tests/jd-publish-shop.test.ts | 72 ++++++++---
.../mount/jd-publish-dispatch.mount.test.ts | 53 ++++++--
5 files changed, 231 insertions(+), 70 deletions(-)
diff --git a/frontend-vue/src/pages/jd/JdPublishTab.vue b/frontend-vue/src/pages/jd/JdPublishTab.vue
index 9d97caee3..0d2a1bf96 100644
--- a/frontend-vue/src/pages/jd/JdPublishTab.vue
+++ b/frontend-vue/src/pages/jd/JdPublishTab.vue
@@ -25,8 +25,13 @@ import { retryClientTask } from '@/shared/api/task-retry'
import { getPywebviewApi } from '@/shared/bridges/pywebview'
import { ensureJdLogin, markJdLoginExpired } from '@/shared/stores/jd-login-autoflow'
import {
+ BRAND_UPGRADE_NOTICE,
+ CROSS_UPGRADE_NOTICE,
+ JD_PUBLISH_BRAND_PROTOCOL,
+ JD_PUBLISH_CROSS_PROTOCOL,
evaluateShopGuard,
shopGuardBlocks,
+ shopGuardMessage,
shopLabel,
type JdShopRef,
} from '@/pages/jd/jd-publish-shop'
@@ -199,6 +204,27 @@ const SHOP_DETECT_UNAVAILABLE =
const shopGuard = computed(() => evaluateShopGuard(selectedProductRows.value, currentShop.value))
+/** 本机发布协议代次(0=读不到/老客户端;品牌要 ≥3、跨店要 ≥4,见 jd-publish-shop 常量)。 */
+const localProtocol = ref(0)
+const crossSupported = computed(() => localProtocol.value >= JD_PUBLISH_CROSS_PROTOCOL)
+/** 异店=跨店上架:目标店就是京麦当前登录店(服务端据此算 publishMode=NEW)。 */
+const usesCrossShop = computed(() => shopGuard.value.state === 'cross')
+/** 跨店必须人工确认一次(会在目标店新建商品、要过京东审核),勾选或店铺变化即重置。 */
+const crossConfirmed = ref(false)
+watch(shopGuard, () => { crossConfirmed.value = false })
+
+async function readPublishProtocol(): Promise {
+ try {
+ const value = await getPywebviewApi()?.jd_publish_protocol?.()
+ return typeof value === 'number' && Number.isFinite(value) ? value : 0
+ } catch (error) {
+ // 桥拒绝/异常按「本机协议未知」处理:品牌与跨店两个调用方都会弹升级提示(用户可见出口)。
+ const detail = error instanceof Error ? error.message : String(error)
+ console.error('[jd-publish] 读取本机发布协议失败:%s', detail)
+ return 0
+ }
+}
+
/** 来源店铺文案:没取到/多家店/单店三档(多店由 shopGuard 直接拦)。 */
const sourceShopText = computed(() => {
const guard = shopGuard.value
@@ -207,6 +233,11 @@ const sourceShopText = computed(() => {
return shopLabel(guard.expected)
})
+/** 跨店档的目标店文案(同店/未检测档为空,模板按它决定是否显示目标店行)。 */
+const crossTargetText = computed(() => (usesCrossShop.value && shopGuard.value.state === 'cross'
+ ? shopLabel(shopGuard.value.target)
+ : ''))
+
const currentShopText = computed(() => (currentShop.value ? shopLabel(currentShop.value) : '未检测'))
/** 挂载时判可用性:老客户端没有 get_jd_shop_info ⇒ 检测按钮置灰(同「同步分类」口径)。 */
@@ -214,6 +245,11 @@ function refreshShopDetectability() {
canDetectShop.value = typeof getPywebviewApi()?.get_jd_shop_info === 'function'
}
+/** 挂载时读一次协议代次:跨店确认框与按钮禁用都按它算,读不到按 0(未支持)处理。 */
+async function refreshPublishProtocol() {
+ localProtocol.value = await readPublishProtocol()
+}
+
/**
* 点「检测当前京麦店铺」:桥现拉京麦首屏(会起客户端专用浏览器,秒级)。
* 失败按 code 分档——jd_busy 走 amber 说明、jd_login 走自动登录链路(登录成功后自动重测一次)、
@@ -270,41 +306,33 @@ async function detectShop(options?: { fromAutoLogin?: boolean }) {
}
/**
- * 建单前把店铺核一次:已检测且一致就不再开浏览器;命中不匹配/跨店直接给拦截文案。
+ * 建单前把店铺核一次:已检测且同店就不再开浏览器;跨店档要本机协议支持(≥4,否则升级提示)。
* 检测失败(页面结构变更、老客户端、京麦任务在跑)**不**拦创建——最终强拦截在客户端
* 执行器(先上报标记再中止)与服务端(命中即整单判死),页面这层只负责提前告知。
*/
async function ensureShopChecked(): Promise {
const guard = shopGuard.value
- if (shopGuardBlocks(guard)) return guard.message
+ const issue = shopGuardMessage(guard, crossSupported.value)
+ if (issue) return issue
if (guard.state !== 'undetected') return ''
await detectShop()
- const next = shopGuard.value
- return shopGuardBlocks(next) ? next.message : ''
+ return shopGuardMessage(shopGuard.value, crossSupported.value)
}
const submitDisabled = computed(() =>
submitting.value
|| detectingShop.value
- || shopGuardBlocks(shopGuard.value)
+ || shopGuardBlocks(shopGuard.value, crossSupported.value)
+ || (usesCrossShop.value && !crossConfirmed.value)
|| !selectedGroupId.value
|| !selectedProducts.value.size
|| !isValidBrand(targetBrandName.value)
|| priceValueMissing.value)
-// 此闸只约束京东品牌发布,不改变客户端其他功能的全局版本门槛。
-const JD_PUBLISH_PROTOCOL = 3
-const JD_UPGRADE_NOTICE = '请升级到支持目标品牌发布的数富AI客户端,并在客户端内打开本页。'
-
+// 此闸只约束京东品牌发布与跨店上架,不改变客户端其他功能的全局版本门槛(两档常量为单出口)。
async function supportsBrandPublishing() {
- try {
- return await getPywebviewApi()?.jd_publish_protocol?.() === JD_PUBLISH_PROTOCOL
- } catch (error) {
- // 桥拒绝/异常按「本机不支持目标品牌」处理,false 会让两个调用方弹升级提示(用户可见出口)。
- const detail = error instanceof Error ? error.message : String(error)
- console.error('[jd-publish] 读取本机发布协议失败:%s', detail)
- return false
- }
+ localProtocol.value = await readPublishProtocol()
+ return localProtocol.value >= JD_PUBLISH_BRAND_PROTOCOL
}
// 通用重试回执不带代数:旧代 + 1 只用作读侧下限,不生成任务或队列数据。
@@ -614,7 +642,7 @@ async function interruptTaskRecord(item: JdPublishHistoryItemVo | null | undefin
async function promptRetryBrand(): Promise {
if (!await supportsBrandPublishing()) {
- ElMessage.error(JD_UPGRADE_NOTICE)
+ ElMessage.error(BRAND_UPGRADE_NOTICE)
return null
}
const name = await ElMessageBox.prompt('请输入当前京麦店铺可用的目标品牌名称。', '修改品牌并重试', {
@@ -719,16 +747,26 @@ async function startPublish() {
const productIds = selectedProductIds.value
const brand = targetBrandName.value
if (!await supportsBrandPublishing()) {
- errorMessage.value = JD_UPGRADE_NOTICE
+ errorMessage.value = BRAND_UPGRADE_NOTICE
return
}
- // 店铺核对在建单之前:京麦登录的不是勾选商品那家店时一条都不发(客户口径「强拦截」)。
+ if (usesCrossShop.value && !crossSupported.value) {
+ errorMessage.value = CROSS_UPGRADE_NOTICE
+ return
+ }
+ // 店铺核对在建单之前:多店勾选、或本机不支持跨店时一条都不发;
+ // 异店(跨店)档由用户在上方勾选确认后才允许建单。
const shopIssue = await ensureShopChecked()
if (shopIssue) {
errorMessage.value = shopIssue
return
}
- const vo = await createJdPublishTask(categoryId, productIds, priceRule, brand)
+ const targetShop = shopGuard.value.state === 'cross'
+ ? { shopId: shopGuard.value.target.shopId, shopName: shopGuard.value.target.shopName }
+ : undefined
+ const vo = targetShop
+ ? await createJdPublishTask(categoryId, productIds, priceRule, brand, targetShop)
+ : await createJdPublishTask(categoryId, productIds, priceRule, brand)
board.addPollingTask(vo.taskId)
const pushNote = await pushToClientQueue(vo.queuePayload)
successMessage.value = pushNote
@@ -746,6 +784,7 @@ onMounted(async () => {
const localName = (window.localStorage.getItem('username') || '').trim()
if (localName) username.value = localName
refreshShopDetectability()
+ void refreshPublishProtocol()
board.loadPollingIds()
await Promise.all([
loadGroups().catch(() => undefined),
@@ -806,10 +845,21 @@ onUnmounted(() => {
{{ detectingShop ? '检测中…' : (currentShop ? '重新检测' : '检测京麦店铺') }}
- {{ shopError }}
-
- {{ shopGuard.message }}
+
+
+ 目标店(跨店)
+ {{ crossTargetText }}
+ {{ shopError }}
+ {{ shopGuard.message }}
+ {{ CROSS_UPGRADE_NOTICE }}
+
+ {{ shopGuard.message }}
+
+
店铺一致:商品会发布到「{{ shopLabel(shopGuard.expected) }}」。
@@ -888,11 +938,19 @@ onUnmounted(() => {
- 点击后本机客户端会逐个把商品发布到已登录的京麦店铺,请保持客户端在线且京麦已登录;发布进度逐行显示在右侧任务区。
+
+ 跨店档会在目标店按每个商品的类目新建商品(京麦「新增商品」路径),需目标店已授权该类目并过京东审核;
+ 发布进度逐行显示在右侧任务区。
+
+
+ 点击后本机客户端会逐个把商品发布到已登录的京麦店铺,请保持客户端在线且京麦已登录;发布进度逐行显示在右侧任务区。
+
{{ successMessage }}
@@ -967,6 +1025,9 @@ onUnmounted(() => {
.shop-detect-btn:hover:not(:disabled) { border-color: #6ea8ff; color: #f5f8fc; }
.shop-detect-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.shop-alert { margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; background: rgba(248, 113, 113, 0.12); color: #fca5a5; font-size: 12px; line-height: 1.6; }
+/* 跨店档是「可继续但要知道代价」:琥珀档(同 --bell-warning 口径),与红色硬拦截区分开。 */
+.shop-alert--cross { background: rgba(240, 187, 97, 0.12); color: #f0bb61; }
+.shop-cross-confirm { display: flex; align-items: flex-start; gap: 6px; margin: 6px 0 0; color: #c8d2e2; font-size: 12px; line-height: 1.6; cursor: pointer; }
.shop-ok { margin: 6px 0 0; color: #6ee7b7; font-size: 12px; }
.shop-cat-select { width: 100%; }
.shop-cat-select :deep(.el-select__wrapper) { background-color: #232b3d; box-shadow: 0 0 0 1px #3e4a62 inset; }
diff --git a/frontend-vue/src/pages/jd/jd-publish-shop.ts b/frontend-vue/src/pages/jd/jd-publish-shop.ts
index e973649c9..1e2a3751e 100644
--- a/frontend-vue/src/pages/jd/jd-publish-shop.ts
+++ b/frontend-vue/src/pages/jd/jd-publish-shop.ts
@@ -1,22 +1,33 @@
/**
* 京东上架「发到哪一家店」(2026-11-24 客户口径:「如果没有店铺登入情况 软件怎么知道我们要上架
- * 是哪一个店铺?」)。
+ * 是哪一个店铺?」;2026-11-26 客户口径「要跨店」后判据从「必须同店」改成「同店与跨店都行」)。
*
* 三份身份,各有唯一出处,三层同一标记:
* 1. **来源店铺**=所勾商品行的 `shopName/shopId`(京东数据库快照)。服务端建单时按它做
* 「一单只能发到一家店」校验(`JdPublishTaskService.resolveSingleShop`),并把它钉进
* 任务载荷与明细下发(`JdPublishItemsPageVo.shopId/shopName`);
* 2. **京麦当前登录店铺**=桥 `get_jd_shop_info` 现拉(客户端起有头浏览器读京麦首屏),
- * 不是页面缓存、也不是上次「同步分类」的残留;本页只拿它做提前告知;
- * 3. **最终强拦截**=客户端发布前用任务记录的店铺再核一次(`JdPublishPage.verify_shop`),
- * 不一致先上报标记再中止,服务端 `JdPublishStaleTaskService` 命中即整单判死——一条都不发。
+ * 不是页面缓存、也不是上次「同步分类」的残留;跨店时它就是**目标店**(服务端据此算
+ * `publishMode=NEW`,客户端走京麦「新增商品」路径);
+ * 3. **最终强拦截**=客户端发布前按模式再核一次(`JdPublishPage.verify_shop`:克隆对来源店、
+ * 新增对目标店),不一致先上报标记再中止,服务端 `JdPublishStaleTaskService` 命中即整单判死。
*
* 本文件是纯函数(node --test 直测):只产状态与中文文案,复选框禁用/错误条/提示色由调用方选。
*/
-/** 判据标记:客户端 `SHOP_MISMATCH_MARK`、服务端 `JdPublishStaleTaskService.SHOP_MISMATCH_MARK` 同值。 */
+/** 判据标记:客户端 `SHOP_MISMATCH_MARK`、服务端 `JdPublishStaleTaskService.SHOP_MISMATCH_MARK` 同值。
+ * 跨店后本页不再产生这句(异店=可跨店),但客户端/服务端的任务错误里仍会出现,界面按标记识别。 */
export const SHOP_MISMATCH_MARK = '京东店铺不匹配'
+/** 发布协议代次门槛(与客户端 `JD_PUBLISH_PROTOCOL`、服务端 `JdPublishProtocol` 同档)。 */
+export const JD_PUBLISH_BRAND_PROTOCOL = 3
+export const JD_PUBLISH_CROSS_PROTOCOL = 4
+
+/** 本机协议不够时的升级提示(品牌档/跨店档各一句,调用方原样弹给用户)。 */
+export const BRAND_UPGRADE_NOTICE = '请升级到支持目标品牌发布的数富AI客户端,并在客户端内打开本页。'
+export const CROSS_UPGRADE_NOTICE =
+ '请升级到支持跨店上架的数富AI客户端(5.1.0 及以上),并在客户端内打开本页。'
+
export interface JdShopRef {
shopId?: string
shopName?: string
@@ -34,7 +45,8 @@ export type JdShopGuard =
/** 有来源店铺、还没检测京麦 ⇒ 提示可检测(不拦) */
| { state: 'undetected'; expected: JdShopRef }
| { state: 'match'; expected: JdShopRef; actual: JdShopRef }
- | { state: 'mismatch'; expected: JdShopRef; actual: JdShopRef; message: string }
+ /** 京麦登录的不是来源店 ⇒ 跨店上架(目标店=京麦当前登录店,走新增商品路径) */
+ | { state: 'cross'; expected: JdShopRef; target: JdShopRef; message: string }
/** 勾选的商品来自多家店 ⇒ 服务端也会拒(按店分开勾) */
| { state: 'multi'; shops: JdShopRef[]; message: string }
@@ -83,11 +95,17 @@ export function sourceShopRefs(products: ReadonlyArray | null | un
return refs
}
-/** 不匹配整句:开头即标记,点名「勾选的店」与「京麦现在登的店」,给动作句(不写「稍后重试」)。 */
-export function shopMismatchMessage(expected: JdShopRef | null | undefined, actual: JdShopRef | null | undefined): string {
- const expectedLabel = shopLabel(expected)
- return (`${SHOP_MISMATCH_MARK}:本次勾选的商品来自「${expectedLabel}」,`
- + `当前京麦登录「${shopLabel(actual)}」;请先在京麦切换到「${expectedLabel}」再上架。`)
+/**
+ * 跨店整句:点名「采集店」与「目标店(京麦当前登录)」,说明三件客户要知道的事——
+ * 会在目标店**新建**商品(与来源店那件各自独立,wareId 不同)、要过京东审核、
+ * 目标店必须已授权该商品的类目。不写「稍后重试」(类目没授权是确定性失败)。
+ */
+export function crossShopMessage(source: JdShopRef | null | undefined, target: JdShopRef | null | undefined): string {
+ const sourceLabel = shopLabel(source)
+ const targetLabel = shopLabel(target)
+ return (`跨店上架:商品采集自「${sourceLabel}」,将在京麦当前登录的「${targetLabel}」新建为全新商品`
+ + '(与来源店那件各自独立,需京东审核通过后才上架);目标店须已授权该商品的类目,'
+ + '否则该商品会按「目标店没有授权类目」逐行失败。')
}
/** 跨店勾选整句(与服务端建单拒绝文案同口径:按店分开勾)。 */
@@ -118,10 +136,20 @@ export function evaluateShopGuard(
// 比不了(一边只有店名、另一边只有 id)不判不匹配:宁可留给客户端强拦截,也不误拦真实任务。
if (same === null) return { state: 'undetected', expected }
if (same) return { state: 'match', expected, actual }
- return { state: 'mismatch', expected, actual, message: shopMismatchMessage(expected, actual) }
+ return { state: 'cross', expected, target: actual, message: crossShopMessage(expected, actual) }
}
-/** UI 唯一处断:命中这两档才禁「上架」按钮(unknown/undetected 不拦)。 */
-export function shopGuardBlocks(guard: JdShopGuard): guard is Extract {
- return guard.state === 'mismatch' || guard.state === 'multi'
+/**
+ * UI 唯一处断:多店必拦;跨店档默认拦(本机不支持跨店=协议 < 4),
+ * ``crossAllowed`` 为真时放行(客户端会走新增商品路径)。
+ */
+export function shopGuardBlocks(guard: JdShopGuard, crossAllowed = false): boolean {
+ if (guard.state === 'cross') return !crossAllowed
+ return guard.state === 'multi'
+}
+
+/** 拦截文案(空串=可建单):跨店档在协议不够时给升级提示,见 ``CROSS_UPGRADE_NOTICE``。 */
+export function shopGuardMessage(guard: JdShopGuard, crossAllowed = false): string {
+ if (guard.state === 'cross') return crossAllowed ? '' : CROSS_UPGRADE_NOTICE
+ return guard.state === 'multi' ? guard.message : ''
}
\ No newline at end of file
diff --git a/frontend-vue/src/shared/api/types/modules/jd-publish.ts b/frontend-vue/src/shared/api/types/modules/jd-publish.ts
index 691e993de..3bd634bce 100644
--- a/frontend-vue/src/shared/api/types/modules/jd-publish.ts
+++ b/frontend-vue/src/shared/api/types/modules/jd-publish.ts
@@ -41,6 +41,7 @@ export function createJdPublishTask(
productIds: number[],
priceRule: JdPublishPriceRule,
targetBrandName: string,
+ targetShop?: { shopId?: string; shopName?: string },
) {
return unwrapJavaResponse(post, Record>(
buildJavaUrl(API_ENDPOINTS.jdPublish.createWithTargetBrand),
@@ -51,6 +52,10 @@ export function createJdPublishTask(
// mode=none 时不带 value(后端 normalizePriceRule 对 none 忽略 value)
priceRule: priceRule.mode === 'none' ? { mode: 'none' } : priceRule,
targetBrandName,
+ // 跨店(2026-11-26)才带目标店:服务端据此落 publishMode=NEW 与目标店快照;
+ // 不带=回落来源店走本店克隆,与 5.0.13 行为逐字一致。
+ ...(targetShop?.shopId ? { targetShopId: targetShop.shopId } : {}),
+ ...(targetShop?.shopName ? { targetShopName: targetShop.shopName } : {}),
},
))
}
diff --git a/frontend-vue/tests/jd-publish-shop.test.ts b/frontend-vue/tests/jd-publish-shop.test.ts
index 1ee6b07c0..46266dbb1 100644
--- a/frontend-vue/tests/jd-publish-shop.test.ts
+++ b/frontend-vue/tests/jd-publish-shop.test.ts
@@ -9,22 +9,28 @@ import {
resolveJdPublishAccess,
} from '../src/pages/jd/jd-publish-access.ts'
import {
+ CROSS_UPGRADE_NOTICE,
+ JD_PUBLISH_BRAND_PROTOCOL,
+ JD_PUBLISH_CROSS_PROTOCOL,
+ crossShopMessage,
evaluateShopGuard,
normalizeShopRef,
shopGuardBlocks,
+ shopGuardMessage,
shopLabel,
- shopMismatchMessage,
- SHOP_MISMATCH_MARK,
sourceShopRefs,
} from '../src/pages/jd/jd-publish-shop.ts'
/**
* 2026-11-24 客户口径两件(京东「商品上架」):
* 1. 「如果没有店铺登入情况 软件怎么知道我们要上架是哪一个店铺?」——页面必须显形
- * 来源店铺与京麦当前登录店铺,不一致强拦截;
+ * 来源店铺与京麦当前登录店铺;
* 2. 「上架的账户 我是这个权限不开给他的」——按账号授权:入口隐藏(卡片过滤)+
* 直达路由守卫+服务端 403 三层。
*
+ * 2026-11-26 客户口径「要跨店」:异店从「硬拦」改成「跨店档」——目标店=京麦当前登录店,
+ * 客户端走京麦「新增商品」路径;本机协议 < 4 时仍拦(老客户端没有新增路径)。
+ *
* 本文件管纯判据与源码绊线;页面接线由 tests/mount/jd-publish-dispatch.mount.test.ts 覆盖。
*/
@@ -67,37 +73,56 @@ test('店铺标签:名+id 全显示,缺一半只报有的那半,全空=
assert.equal(normalizeShopRef({ shopId: ' ' }), null)
})
-test('不匹配文案:标记开头、点名两家店、给动作句且不写「稍后重试」', () => {
- const message = shopMismatchMessage(
+test('跨店文案:点名来源店与目标店、说明会新建商品要过审、要求目标店已授权类目,不写「稍后重试」', () => {
+ const message = crossShopMessage(
+ { shopId: '148191738', shopName: '汽车用品数据库店' },
{ shopId: '228346061', shopName: '家居日用数据库店' },
- { shopId: '165515933', shopName: '花屿巷旗舰店' },
)
- assert.ok(message.startsWith(SHOP_MISMATCH_MARK))
+ assert.ok(message.startsWith('跨店上架'))
+ assert.ok(message.includes('汽车用品数据库店') && message.includes('148191738'))
assert.ok(message.includes('家居日用数据库店') && message.includes('228346061'))
- assert.ok(message.includes('花屿巷旗舰店') && message.includes('165515933'))
- assert.ok(message.includes('切换'))
+ assert.ok(message.includes('新建'), '必须说清跨店是在目标店新建商品')
+ assert.ok(message.includes('授权'), '必须点名目标店类目授权这个硬前提')
+ assert.ok(message.includes('审核'), '必须说清要过京东审核')
assert.ok(!message.includes('稍后重试'), '确定性失败不允许写「稍后重试」')
})
-test('判据四态:未勾选 unknown / 未检测 undetected / 同店 match / 异店 mismatch', () => {
+test('判据五态:未勾选 unknown / 未检测 undetected / 同店 match / 异店 cross / 多店 multi', () => {
assert.equal(evaluateShopGuard([], { shopId: '1' }).state, 'unknown')
assert.equal(evaluateShopGuard([{ shopId: '1' }], null).state, 'undetected')
const match = evaluateShopGuard([{ shopId: '1', shopName: '某店' }], { shopId: '1', shopName: '某店' })
assert.equal(match.state, 'match')
- const mismatch = evaluateShopGuard([{ shopId: '1', shopName: '某店' }], { shopId: '2', shopName: '别店' })
- assert.equal(mismatch.state, 'mismatch')
- assert.ok(shopGuardBlocks(mismatch))
+ const cross = evaluateShopGuard([{ shopId: '1', shopName: '甲店' }], { shopId: '2', shopName: '乙店' })
+ assert.equal(cross.state, 'cross')
+ if (cross.state === 'cross') {
+ assert.equal(cross.target.shopId, '2', '目标店=京麦当前登录店(不是来源店)')
+ assert.ok(cross.message.includes('乙店'))
+ }
assert.ok(!shopGuardBlocks(match) && !shopGuardBlocks(evaluateShopGuard([], null)))
})
-test('id 优先于店名:id 不同但同名也不放行', () => {
- const guard = evaluateShopGuard([{ shopId: '1', shopName: '同名店' }], { shopId: '2', shopName: '同名店' })
- assert.equal(guard.state, 'mismatch')
+test('跨店档默认拦(本机协议不够),显式允许后才放行;提示换升级文案', () => {
+ const cross = evaluateShopGuard([{ shopId: '1', shopName: '甲店' }], { shopId: '2', shopName: '乙店' })
+ assert.ok(shopGuardBlocks(cross), '默认(协议 < 4)必须拦,老客户端没有新增商品路径')
+ assert.equal(shopGuardMessage(cross), CROSS_UPGRADE_NOTICE)
+ assert.ok(shopGuardMessage(cross).includes('升级'))
+ assert.equal(shopGuardMessage(cross, true), '', '协议 ≥4 时跨店可建单')
+ assert.ok(!shopGuardBlocks(cross, true))
})
-test('只有店名时按店名比对;比不了(一边只有 id)按未检测处理,不误拦', () => {
+test('协议门槛常量与服务端/客户端代次同档(品牌 3、跨店 4)', () => {
+ assert.equal(JD_PUBLISH_BRAND_PROTOCOL, 3)
+ assert.equal(JD_PUBLISH_CROSS_PROTOCOL, 4)
+})
+
+test('id 优先于店名:id 不同但同名按跨店处理(不是同店)', () => {
+ const guard = evaluateShopGuard([{ shopId: '1', shopName: '同名店' }], { shopId: '2', shopName: '同名店' })
+ assert.equal(guard.state, 'cross')
+})
+
+test('只有店名时按店名比对;比不了(一边只有 id)按未检测处理,不误判跨店', () => {
assert.equal(evaluateShopGuard([{ shopName: '某店' }], { shopName: '某店' }).state, 'match')
- assert.equal(evaluateShopGuard([{ shopName: '某店' }], { shopName: '别店' }).state, 'mismatch')
+ assert.equal(evaluateShopGuard([{ shopName: '某店' }], { shopName: '别店' }).state, 'cross')
assert.equal(evaluateShopGuard([{ shopId: '1' }], { shopName: '某店' }).state, 'undetected')
})
@@ -148,6 +173,17 @@ test('上架页不得自己拼店铺身份(只用勾选商品快照 + 桥结
assert.ok(!tab.includes('jd-shop-info'), '页面不得自拼店铺读取 URL(唯一口是桥)')
})
+test('跨店接线:建单把目标店交给服务端、协议按最低档判定、二次确认是硬闸', () => {
+ const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
+ assert.ok(tab.includes('targetShop'), '跨店建单必须把目标店(京麦当前登录店)传给服务端')
+ assert.ok(tab.includes('JD_PUBLISH_CROSS_PROTOCOL'), '跨店协议闸必须引用常量单出口')
+ assert.ok(tab.includes('crossConfirmed'), '跨店必须人工二次确认(会在目标店新建商品并过审)')
+ assert.ok(!/jd_publish_protocol[^\n]*===\s*3/.test(tab), '协议判定不得再等值钉 3(v4 是 v3 的超集)')
+ const api = read('src/shared/api/types/modules/jd-publish.ts', 'jd-publish API')
+ assert.ok(api.includes('targetShopId') && api.includes('targetShopName'),
+ '建单请求体必须带 targetShopId/targetShopName 两个键(服务端据此算 publishMode)')
+})
+
test('/jd-publish 直达路由挂权限守卫,权限接口失败按放行处理', () => {
const router = read('src/router/index.ts', 'router/index.ts')
assert.ok(router.includes('resolveJdPublishAccess'), '路由必须用统一判据模块')
diff --git a/frontend-vue/tests/mount/jd-publish-dispatch.mount.test.ts b/frontend-vue/tests/mount/jd-publish-dispatch.mount.test.ts
index bf0036300..f0628a10a 100644
--- a/frontend-vue/tests/mount/jd-publish-dispatch.mount.test.ts
+++ b/frontend-vue/tests/mount/jd-publish-dispatch.mount.test.ts
@@ -117,12 +117,11 @@ it('建单只原样投递服务端载荷,网页不激活任务', async () => {
expect(api.activate).not.toHaveBeenCalled()
})
-it.each(['没有桥', '旧桥', '旧协议', '字符串协议', '未知协议', '协议异常'])('%s不允许建品牌单', async (failure) => {
+it.each(['没有桥', '旧桥', '旧协议', '字符串协议', '协议异常'])('%s不允许建品牌单', async (failure) => {
if (failure === '没有桥') api.bridge.mockReturnValue(undefined)
if (failure === '旧桥') api.bridge.mockReturnValue({ enqueue_json: api.enqueue })
if (failure === '旧协议') api.protocol.mockResolvedValue(2)
if (failure === '字符串协议') api.protocol.mockResolvedValue('3')
- if (failure === '未知协议') api.protocol.mockResolvedValue(4)
if (failure === '协议异常') api.protocol.mockRejectedValue(new Error('bridge unavailable'))
const page = await mountPage()
await startPublish(page)
@@ -359,8 +358,9 @@ it('源商品身份缺失形状已被客户端放行,提示维持换店或重
})
// ---- 店铺核对(2026-11-24 客户口径「软件怎么知道要上架哪一家店铺」)----
-// 桥 get_jd_shop_info 现拉京麦当前登录店铺;与勾选商品的来源店铺不一致 ⇒ 页面强拦截,一条都不建单。
-// 老客户端没有这个方法(默认替身就不带)⇒ 不拦,最终拦截由客户端执行器与服务端完成。
+// 桥 get_jd_shop_info 现拉京麦当前登录店铺:同店照常;异店=跨店档(2026-11-26 客户口径「要跨店」):
+// 协议 ≥4 时显形目标店+风险句+二次确认后建单(服务端算 publishMode=NEW),协议 3 的老客户端
+// 仍只给升级提示、一条都不建单。老客户端没有这个方法(默认替身就不带)⇒ 不拦,最终拦截在客户端执行器。
type ShopBridgeResult = {
success: boolean; shopId?: string; shopName?: string; code?: string; error?: string
@@ -373,27 +373,58 @@ function withShopBridge(result: ShopBridgeResult) {
api.shop.mockResolvedValue(result)
}
-it('京麦登录的不是勾选商品的店铺时不建单,并点名两家店', async () => {
+function crossShopProducts() {
api.products.mockResolvedValue({
- items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
+ items: [{ id: 23, title: '示例商品', shopId: '148191738', shopName: '汽车用品数据库店' }], total: 1,
})
- withShopBridge({ success: true, shopId: '165515933', shopName: '花屿巷旗舰店' })
+}
+
+it('协议 3 的本机遇跨店只给升级提示,一条都不建单', async () => {
+ crossShopProducts()
+ withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
+ api.protocol.mockResolvedValue(3)
const page = await mountPage()
await page.get('.target-brand-input').setValue('示例品牌')
await page.get('.product-check').setValue(true)
- // 勾选后不检测:按钮仍可点(未检测不拦),点下去才开始核对
+ // 勾选后未检测:不拦,点下去才开始核对
expect(page.get('.collect-btn').element.disabled).toBe(false)
await page.get('.collect-btn').trigger('click')
await flushPromises()
expect(api.shop).toHaveBeenCalledOnce()
expect(api.create).not.toHaveBeenCalled()
expect(api.enqueue).not.toHaveBeenCalled()
- expect(page.text()).toContain('京东店铺不匹配')
- expect(page.text()).toContain('家居日用数据库店')
- expect(page.text()).toContain('花屿巷旗舰店')
+ expect(page.text()).toContain('升级')
expect(page.get('.collect-btn').element.disabled).toBe(true)
})
+it('协议 4 跨店:显形目标店与风险句,确认后才建单并带目标店', async () => {
+ crossShopProducts()
+ withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
+ api.protocol.mockResolvedValue(4)
+ const page = await mountPage()
+ await page.get('.target-brand-input').setValue('示例品牌')
+ await page.get('.product-check').setValue(true)
+ await page.get('.shop-detect-btn').trigger('click')
+ await flushPromises()
+
+ expect(page.text()).toContain('跨店上架')
+ expect(page.text()).toContain('目标店(跨店)')
+ expect(page.text()).toContain('家居日用数据库店')
+ expect(page.text()).not.toContain('京东店铺不匹配')
+ // 二次确认是硬闸:没勾之前按钮禁用
+ expect(page.get('.collect-btn').element.disabled).toBe(true)
+ await page.get('.shop-cross-confirm input').setValue(true)
+ await flushPromises()
+ expect(page.get('.collect-btn').element.disabled).toBe(false)
+
+ await page.get('.collect-btn').trigger('click')
+ await flushPromises()
+ expect(api.shop).toHaveBeenCalledOnce() // 已检测过,不再重复起浏览器
+ expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23], { mode: 'none' }, '示例品牌',
+ { shopId: '228346061', shopName: '家居日用数据库店' })
+ expect(api.enqueue).toHaveBeenCalledOnce()
+})
+
it('京麦与来源店铺一致时照常建单', async () => {
api.products.mockResolvedValue({
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,