feat(jd额度): 上架额度改按在架商品数计+管理员向员工分配额度闸+在架商品面板
客户口径(2026-11-25):「上限=同时在架商品数,下架 10 个就能再上架 10 个换着卖」+
「管理员下的普通员工总和也不能超过这个上限」。
后端
- 计数正本从 biz_jd_product 占有行数迁到 biz_jd_publish_item:发布成功(SUCCESS)
且未标记下架(delisted_at IS NULL)的去重商品数(DISTINCT product_id,同商品跨任务
重复发布只占一位)。旧 JdProductMapper#countByUserIds 整条删除——口径源只能一份。
- V216 给发布明细加 delisted_at(NULL=在架);V217 把普通账号存量默认 5000 清 0
(0=未分配,分配闸上线的前置清账)。
- JdPublishQuotaService:quotaOf 读数换正本;assertWithinQuota 改收勾选商品集,
批内已在架的不双计(重复上架不重复占位)。
- 新增 JdPublishOnShelfService+/api/jd-publish/on-shelf(团队在架分页+余量,读数与
建单闸同一正本)与 /api/jd-publish/items/{itemId}/delisted(标记/撤销按商品整组回写,
跨团队 403;京麦下架执行链自动回流记欠账)。
- AdminUserService 新增分配闸:Σ(直接下属非零额度,被编辑账号取新值) ≤ 锚点额度;
站超管/锚点 0=不限放行;旧 400「只能为管理员设置额度」废止。新增
/api/admin/user/{uid}/jd-quota 只读快照(编辑弹窗展示「当前在架 X/上限 Y」)。
后管
- 编辑弹窗额度项改为「京东侧+操作者写权」即出(普通账号也可分配),带当前在架读数
(读不到只显一句失败话,不挡保存);列表「上架上限」列 0 按档显「不限」/「未分配」;
普通账号回填缺省 0(避免「打开就保存」凭空分配额度)。展示规则单出口 user-edit-model。
用户端
- 新增在架商品面板(JdOnShelfPanel):余量读数、空态、满额提醒、标记已下架确认与回执
文案单出口 jd-on-shelf.ts;endpoints 快照同步 onShelf/markDelisted。
判据
- 后端:JdPublishQuotaServiceTest 11、JdPublishOnShelfServiceTest 8、
JdPublishOnShelfSqlTest 3(三条 SQL 谓词逐字钉:SUCCESS+delisted_at IS NULL+DISTINCT)、
AdminUserServiceCompanySuperAdminTest +5(Σ 闸四态)、JdSchemaContractTest 钉 V216/V217、
两条 SQL 台账(XML_SELECT_TOTAL 109→111、XML_STATEMENT_TOTAL 156→158)逐条点名。
- 后管:jd-publish-quota-edit.test.ts 3(含 0 语义分档与「绝不拼/0」)、
platform-account-pages 源码钉子改钉新形状、source-pin 台账 cases 1867→1868 逐条点名。
- 用户端:jd-on-shelf.test.ts 纯函数+mount 面板判据;catch-silence 台账 blocks 336→338 点名。
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import {
|
||||
fetchJdOnShelf,
|
||||
markJdItemDelisted,
|
||||
type JdOnShelfItemVo,
|
||||
type JdOnShelfPageVo,
|
||||
} from '@/shared/api/types/modules/jd-publish'
|
||||
import {
|
||||
clampPageSize,
|
||||
markButtonLabel,
|
||||
markDelistedNotice,
|
||||
onShelfEmptyText,
|
||||
quotaNearLimit,
|
||||
quotaReadoutText,
|
||||
} from './jd-on-shelf'
|
||||
import { formatDateTime } from '@/shared/utils/datetime'
|
||||
|
||||
/**
|
||||
* 在架商品面板(2026-11-25 客户口径「上限=同时在架商品数,下架 10 个就能再上 10 个」)。
|
||||
*
|
||||
* 京麦人工下架系统感知不到,本面板是「标记已下架腾额度」的唯一界面出口;
|
||||
* 余量读数 used/limit 与建单配额闸同一正本(服务端 JdPublishQuotaService),
|
||||
* 这里看到的和建单被拦的是同一个数。文案单出口在 jd-on-shelf.ts(判据同读)。
|
||||
* 团队口径:管理员=本人+名下员工(管理员可替员工标记),员工=所属管理员团队。
|
||||
*/
|
||||
|
||||
const PAGE_SIZE = 20
|
||||
|
||||
const open = ref(false)
|
||||
const loading = ref(false)
|
||||
const page = ref(1)
|
||||
const vo = ref<JdOnShelfPageVo | null>(null)
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
try {
|
||||
vo.value = await fetchJdOnShelf(page.value, clampPageSize(PAGE_SIZE))
|
||||
} catch (error) {
|
||||
vo.value = null
|
||||
ElMessage.error(error instanceof Error ? error.message : '在架商品读取失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function togglePanel() {
|
||||
open.value = !open.value
|
||||
if (open.value && !vo.value) void load()
|
||||
}
|
||||
|
||||
async function changePage(next: number) {
|
||||
page.value = next
|
||||
await load()
|
||||
}
|
||||
|
||||
async function markDelisted(item: JdOnShelfItemVo) {
|
||||
// 确认框取消走 reject 两臂(与中断任务同口径,不新增 catch 块)
|
||||
const confirmed = await ElMessageBox.confirm(
|
||||
`确认把「${item.title || item.productCode || item.productId}」标记为已下架?`
|
||||
+ '标记后该商品不再占用上架额度;请确认它确已在京麦下架。',
|
||||
'标记已下架',
|
||||
{ type: 'warning', confirmButtonText: '标记已下架', cancelButtonText: '先不标记' },
|
||||
).then(
|
||||
() => true,
|
||||
() => false,
|
||||
)
|
||||
if (!confirmed) return
|
||||
try {
|
||||
await markJdItemDelisted(item.itemId, true)
|
||||
ElMessage.success(markDelistedNotice(item.productCode))
|
||||
await load()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '标记失败,请稍后重试')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="on-shelf" v-loading="loading">
|
||||
<div class="on-shelf-head">
|
||||
<button class="on-shelf-toggle" type="button" :aria-expanded="open" @click="togglePanel">
|
||||
{{ open ? '收起在架商品' : '展开在架商品' }}
|
||||
</button>
|
||||
<span class="on-shelf-quota">{{ vo ? quotaReadoutText(vo.used, vo.limit, vo.unlimited) : '余量读取中…' }}</span>
|
||||
<button class="on-shelf-refresh" type="button" :disabled="loading" @click="load()">刷新</button>
|
||||
</div>
|
||||
<p v-if="vo && quotaNearLimit(vo.used, vo.limit, vo.unlimited)" class="on-shelf-warn">
|
||||
额度已满:请先在京麦下架商品,并到本列表「标记已下架」腾出额度后再建单。
|
||||
</p>
|
||||
<div v-if="open" class="on-shelf-body">
|
||||
<div v-if="vo && !vo.items.length" class="on-shelf-empty">{{ onShelfEmptyText(vo.unlimited, vo.used) }}</div>
|
||||
<div v-for="item in vo?.items ?? []" :key="item.itemId" class="on-shelf-row">
|
||||
<img v-if="item.imageUrl" class="on-shelf-thumb" :src="item.imageUrl" alt="" loading="lazy" />
|
||||
<span v-else class="on-shelf-thumb on-shelf-thumb--empty">无图</span>
|
||||
<span class="on-shelf-info">
|
||||
<span class="on-shelf-title">{{ item.title || '(无标题快照)' }}</span>
|
||||
<span class="on-shelf-meta">
|
||||
<template v-if="item.productCode">编码 {{ item.productCode }} · </template>
|
||||
<template v-if="item.shopName">来源 {{ item.shopName }} · </template>
|
||||
上架 {{ item.listedAt ? formatDateTime(item.listedAt) : '-' }}
|
||||
</span>
|
||||
</span>
|
||||
<button class="on-shelf-mark" type="button" @click="markDelisted(item)">{{ markButtonLabel() }}</button>
|
||||
</div>
|
||||
<el-pagination v-if="vo && vo.total > PAGE_SIZE" class="on-shelf-pager" layout="prev, pager, next"
|
||||
:total="vo.total" :page-size="PAGE_SIZE" :current-page="page" @current-change="changePage" />
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.on-shelf { flex-shrink: 0; margin: 0 0 12px; padding: 10px 14px; border: 1px solid #2c3547; border-radius: 8px; background: #20283a; }
|
||||
.on-shelf-head { display: flex; align-items: center; gap: 12px; }
|
||||
.on-shelf-toggle, .on-shelf-refresh { padding: 4px 12px; border: 1px solid #3e4a62; border-radius: 6px; background: transparent; color: #c8d2e2; font-size: 12px; cursor: pointer; }
|
||||
.on-shelf-quota { color: #e6edf7; font-size: 13px; }
|
||||
.on-shelf-warn { margin: 8px 0 0; color: #e6a23c; font-size: 12px; }
|
||||
.on-shelf-body { margin-top: 10px; }
|
||||
.on-shelf-empty { padding: 12px; color: #8b98af; font-size: 12px; text-align: center; }
|
||||
.on-shelf-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 6px; border: 1px solid #2c3547; border-radius: 8px; background: #1a2130; }
|
||||
.on-shelf-thumb { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
|
||||
.on-shelf-thumb--empty { display: inline-flex; align-items: center; justify-content: center; color: #5f6c85; font-size: 11px; background: #232c3e; }
|
||||
.on-shelf-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
|
||||
.on-shelf-title { color: #e6edf7; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.on-shelf-meta { color: #8b98af; font-size: 11px; }
|
||||
.on-shelf-mark { padding: 4px 12px; border: 1px solid #b45454; border-radius: 6px; background: transparent; color: #e08a8a; font-size: 12px; cursor: pointer; flex-shrink: 0; }
|
||||
.on-shelf-pager { justify-content: center; margin-top: 8px; }
|
||||
</style>
|
||||
@@ -2,6 +2,7 @@
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import TaskCenterPanel from '@/shared/components/tasks/TaskCenterPanel.vue'
|
||||
import JdOnShelfPanel from '@/pages/jd/JdOnShelfPanel.vue'
|
||||
import type { TaskItemView, TaskStatCard } from '@/shared/components/tasks/types'
|
||||
import jdLogo from '@/pages/home/assets/jd-logo.png'
|
||||
import {
|
||||
@@ -899,6 +900,7 @@ onUnmounted(() => {
|
||||
</aside>
|
||||
|
||||
<section class="right-panel">
|
||||
<JdOnShelfPanel />
|
||||
<TaskCenterPanel
|
||||
:on-batch-delete="batchDeleteHistory"
|
||||
:on-refresh="refreshBoard"
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 在架商品面板的纯函数层(2026-11-25 客户口径「上限=同时在架商品数,下架腾额度」)。
|
||||
*
|
||||
* 文案单出口纪律:余量读数、空态、标记按钮文案只在这里拼——面板与判据读同一份,
|
||||
* 回退(比如把「不限」拼成「0」)当场红。服务端 used/limit 与建单配额闸同一正本,
|
||||
* 本层只做展示换算,不做任何二次判定。
|
||||
*/
|
||||
|
||||
/** 余量读数:limit≤0(0=不限)显「不限」,绝不显「/0」这种像坏数的数字。 */
|
||||
export function quotaReadoutText(used: number, limit: number, unlimited: boolean): string {
|
||||
const safeUsed = Number.isFinite(used) && used > 0 ? Math.floor(used) : 0;
|
||||
if (unlimited || !Number.isFinite(limit) || limit <= 0) {
|
||||
return `当前在架 ${safeUsed}/不限`;
|
||||
}
|
||||
return `当前在架 ${safeUsed}/${Math.floor(limit)}`;
|
||||
}
|
||||
|
||||
/** 余量是否已到顶(到顶给琥珀提醒句,不硬拦——硬闸在服务端建单口)。 */
|
||||
export function quotaNearLimit(used: number, limit: number, unlimited: boolean): boolean {
|
||||
if (unlimited || !Number.isFinite(limit) || limit <= 0) return false;
|
||||
return used >= limit;
|
||||
}
|
||||
|
||||
/** 面板空态:额度未用满与用满两种口径分开说,别让人以为面板坏了。 */
|
||||
export function onShelfEmptyText(unlimited: boolean, used: number): string {
|
||||
if (used > 0) return '本页暂无更多在架商品,可翻页查看';
|
||||
return unlimited
|
||||
? '当前没有已上架商品;上架成功后的商品会出现在这里,并计入额度'
|
||||
: '当前没有已上架商品;额度只在商品上架成功后占用,采集入库不占';
|
||||
}
|
||||
|
||||
/** 标记按钮文案:delisted 态在面板里恒为「未下架」(已下架的行不进在架列表),撤销口用此文案。 */
|
||||
export function markButtonLabel(): string {
|
||||
return '标记已下架';
|
||||
}
|
||||
|
||||
/** 分页大小钳制:与后端 MAX_PAGE_SIZE=100 同口径,超了按 100 请求。 */
|
||||
export function clampPageSize(pageSize: number): number {
|
||||
if (!Number.isFinite(pageSize) || pageSize <= 0) return 20;
|
||||
return Math.min(Math.floor(pageSize), 100);
|
||||
}
|
||||
|
||||
/** 标记成功后的回执文案(点名动作与后果,不写「操作成功」这种没有信息量的话)。
|
||||
* ⚠ 本窗不承诺「撤销标记」入口——已下架行不进在架列表,误标撤销口记 BACKLOG 欠账。 */
|
||||
export function markDelistedNotice(productCode?: string): string {
|
||||
const who = productCode ? `商品 ${productCode} ` : '';
|
||||
return `已标记${who}下架,额度已腾出;请确认该商品确已在京麦下架`;
|
||||
}
|
||||
@@ -246,6 +246,10 @@ export const API_ENDPOINTS = {
|
||||
progress: '/api/jd-publish/tasks/{taskId}/progress',
|
||||
/** 删除任务(连带清理该任务的发布明细快照行) */
|
||||
deleteTask: '/api/jd-publish/tasks/{taskId}',
|
||||
/** 在架商品分页+额度余量(2026-11-25 客户口径「上限=同时在架商品数」) */
|
||||
onShelf: '/api/jd-publish/on-shelf',
|
||||
/** 标记/取消标记已下架(按商品整组腾额度) */
|
||||
markDelisted: '/api/jd-publish/items/{itemId}/delisted',
|
||||
},
|
||||
userSecret: {
|
||||
bundle: '/api/user-secrets',
|
||||
|
||||
@@ -291,3 +291,49 @@ export function interruptJdPublishTask(taskId: number) {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// 在架商品面板(2026-11-25 客户口径「上限=同时在架商品数,下架 10 个就能再上 10 个」)。
|
||||
// 余量读数 used/limit 与建单配额闸同一正本(服务端 JdPublishQuotaService),
|
||||
// 面板看到的和建单被拦的是同一个数;京麦人工下架后在本面板「标记已下架」即腾额度。
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export interface JdOnShelfItemVo {
|
||||
itemId: number;
|
||||
productId: number;
|
||||
productCode?: string;
|
||||
title?: string;
|
||||
shopName?: string;
|
||||
jdWareId?: string;
|
||||
imageUrl?: string;
|
||||
listedAt?: string;
|
||||
operatorUserId?: number;
|
||||
}
|
||||
|
||||
export interface JdOnShelfPageVo {
|
||||
used: number;
|
||||
limit: number;
|
||||
unlimited: boolean;
|
||||
total: number;
|
||||
items: JdOnShelfItemVo[];
|
||||
}
|
||||
|
||||
/** 在架商品分页(团队口径:管理员含名下员工,员工=所属管理员团队)。 */
|
||||
export function fetchJdOnShelf(page: number, pageSize: number) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<JdOnShelfPageVo>>(
|
||||
buildJavaUrl(API_ENDPOINTS.jdPublish.onShelf),
|
||||
{ params: { user_id: getCurrentUserId(), page, page_size: pageSize } },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/** 标记/取消标记已下架:服务端按商品整组回写(同商品跨任务成功行一起落/一起回拨)。 */
|
||||
export function markJdItemDelisted(itemId: number, delisted: boolean) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<null>, { delisted: boolean }>(
|
||||
buildJavaUrl(API_ENDPOINTS.jdPublish.markDelisted.replace('{itemId}', String(itemId))),
|
||||
{ delisted },
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,11 @@ const BASELINE = {
|
||||
// 原文只进 console;「读不到权限」不等于「没权限」,把有权限的人锁在门外比放进去后被
|
||||
// 服务端 403 更难解释(与 JdConsolePage 的 permissionUnavailable 同口径)。非静默:
|
||||
// 首条语句是状态写入、不是 console.*,silent 一格没涨、perFile 无新增条目,只进 blocks。
|
||||
blocks: 336,
|
||||
// 338 = 336 + 2(2026-11-25 京东上架额度改口径「在架商品面板」):JdOnShelfPanel.vue 的
|
||||
// load(在架清单读取失败 → ElMessage.error 报原文,面板清空不显旧数)与 markDelisted
|
||||
// (标记失败 → ElMessage.error 透出服务端原文,跨团队 403 等;确认框取消走 reject 两臂
|
||||
// 不新增 catch)各一支,都有用户可见出口,silent 一格没涨、perFile 无新增条目,只进 blocks。
|
||||
blocks: 338,
|
||||
// 2026-10-30(ops Phase 6/可读棘轮):ApiSecretSettingsPanel.vue 1113→775 行,面板里那处
|
||||
// 静默 catch(余额查询失败只 console.warn、界面留空)随 loadBalance 整块搬进
|
||||
// useProxyPlan.ts。不是新增静默:面板 1→0、新文件记 1,silent 总数与 blocks 都一格没动,
|
||||
|
||||
@@ -349,7 +349,10 @@ test('test_endpoints_frozen_snapshot', () => {
|
||||
"history": "/api/jd-publish/history",
|
||||
"progressBatch": "/api/jd-publish/tasks/progress/batch",
|
||||
"progress": "/api/jd-publish/tasks/{taskId}/progress",
|
||||
"deleteTask": "/api/jd-publish/tasks/{taskId}"
|
||||
"deleteTask": "/api/jd-publish/tasks/{taskId}",
|
||||
// 2026-11-25 额度改口径:在架清单+标记已下架腾额度(JdOnShelfPanel 唯一落点)。
|
||||
"onShelf": "/api/jd-publish/on-shelf",
|
||||
"markDelisted": "/api/jd-publish/items/{itemId}/delisted"
|
||||
},
|
||||
"userSecret": {
|
||||
"bundle": "/api/user-secrets",
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
import { existsSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import {
|
||||
clampPageSize,
|
||||
markButtonLabel,
|
||||
markDelistedNotice,
|
||||
onShelfEmptyText,
|
||||
quotaNearLimit,
|
||||
quotaReadoutText,
|
||||
} from '../src/pages/jd/jd-on-shelf.ts'
|
||||
|
||||
/**
|
||||
* 在架商品面板纯函数与接线绊线(2026-11-25 客户口径「上限=同时在架商品数,
|
||||
* 下架 10 个就能再上 10 个换着卖」)。
|
||||
*
|
||||
* 绊线盯的是「安静地不做」类回退:面板绕过 api 模块裸拼 URL(落点台账失效)、
|
||||
* 文案在组件里硬拼(单出口失效)、JdPublishTab 不挂面板(功能整面失踪)——
|
||||
* 行为测试全绿也拦不住,只有源码绊线拦得住。
|
||||
*/
|
||||
|
||||
const ROOT = process.cwd()
|
||||
|
||||
function read(relativePath: string, what: string): string {
|
||||
const path = join(ROOT, relativePath)
|
||||
assert.ok(existsSync(path), `${what} 尚未落地:${path}`)
|
||||
return readFileSync(path, 'utf8')
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------- 纯函数:余量文案
|
||||
|
||||
test('余量读数:正常档显「在架 X/Y」,不限档绝不显「/0」', () => {
|
||||
assert.equal(quotaReadoutText(120, 5000, false), '当前在架 120/5000')
|
||||
assert.equal(quotaReadoutText(120, 0, true), '当前在架 120/不限')
|
||||
// limit≤0 但 unlimited 没带(防御:服务端两键同值,坏一个也不出「/0」坏数)
|
||||
assert.equal(quotaReadoutText(3, 0, false), '当前在架 3/不限')
|
||||
assert.equal(quotaReadoutText(Number.NaN, 5000, false), '当前在架 0/5000')
|
||||
assert.equal(quotaReadoutText(12.7, 5000.9, false), '当前在架 12/5000')
|
||||
})
|
||||
|
||||
test('到顶判据:used≥limit 才提醒;不限档永不提醒', () => {
|
||||
assert.equal(quotaNearLimit(5000, 5000, false), true)
|
||||
assert.equal(quotaNearLimit(5001, 5000, false), true)
|
||||
assert.equal(quotaNearLimit(4999, 5000, false), false)
|
||||
assert.equal(quotaNearLimit(999999, 0, true), false)
|
||||
})
|
||||
|
||||
test('空态文案:未占用点名「采集入库不占额度」,翻页态不冒充空账', () => {
|
||||
assert.match(onShelfEmptyText(false, 0), /采集入库不占/)
|
||||
assert.match(onShelfEmptyText(true, 0), /上架成功后.*计入额度/s)
|
||||
assert.equal(onShelfEmptyText(false, 25), '本页暂无更多在架商品,可翻页查看')
|
||||
})
|
||||
|
||||
test('分页钳制与服务端 MAX_PAGE_SIZE=100 同口径', () => {
|
||||
assert.equal(clampPageSize(9999), 100)
|
||||
assert.equal(clampPageSize(20), 20)
|
||||
assert.equal(clampPageSize(0), 20)
|
||||
assert.equal(clampPageSize(-1), 20)
|
||||
})
|
||||
|
||||
test('标记回执点名商品编码与确认义务,不写「操作成功」空话', () => {
|
||||
assert.match(markDelistedNotice('100365361600'), /商品 100365361600/)
|
||||
assert.match(markDelistedNotice('100365361600'), /额度已腾出/)
|
||||
assert.match(markDelistedNotice(), /已标记下架,额度已腾出/)
|
||||
assert.equal(markButtonLabel(), '标记已下架')
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------- 源码绊线:接线与单出口
|
||||
|
||||
test('绊线:在架端点只在 endpoints.ts 登记一处,面板必须走 api 模块出口', () => {
|
||||
const endpoints = read('src/shared/api/endpoints.ts', '端点表')
|
||||
assert.match(endpoints, /onShelf: '\/api\/jd-publish\/on-shelf'/)
|
||||
assert.match(endpoints, /markDelisted: '\/api\/jd-publish\/items\/\{itemId\}\/delisted'/)
|
||||
|
||||
const apiModule = read('src/shared/api/types/modules/jd-publish.ts', '上架 api 模块')
|
||||
assert.match(apiModule, /API_ENDPOINTS\.jdPublish\.onShelf/)
|
||||
assert.match(apiModule, /API_ENDPOINTS\.jdPublish\.markDelisted/)
|
||||
|
||||
const panel = read('src/pages/jd/JdOnShelfPanel.vue', '在架面板')
|
||||
assert.doesNotMatch(panel, /\/api\/jd-publish/, '面板不得裸拼后端 URL(落点必须走 api 模块)')
|
||||
assert.match(panel, /fetchJdOnShelf/)
|
||||
assert.match(panel, /markJdItemDelisted/)
|
||||
})
|
||||
|
||||
test('绊线:面板文案单出口——组件不硬拼「当前在架」,判据与界面读同一份', () => {
|
||||
const panel = read('src/pages/jd/JdOnShelfPanel.vue', '在架面板')
|
||||
assert.doesNotMatch(panel, /当前在架/, '余量文案必须经 quotaReadoutText 单出口')
|
||||
assert.match(panel, /quotaReadoutText/)
|
||||
assert.match(panel, /onShelfEmptyText/)
|
||||
assert.match(panel, /markDelistedNotice/)
|
||||
})
|
||||
|
||||
test('绊线:JdPublishTab 必须挂上在架面板(功能整面失踪类回退)', () => {
|
||||
const tab = read('src/pages/jd/JdPublishTab.vue', '上架页')
|
||||
assert.match(tab, /import JdOnShelfPanel from '@\/pages\/jd\/JdOnShelfPanel\.vue'/)
|
||||
assert.match(tab, /<JdOnShelfPanel \/>/)
|
||||
})
|
||||
@@ -0,0 +1,140 @@
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import JdOnShelfPanel from '@/pages/jd/JdOnShelfPanel.vue'
|
||||
|
||||
/**
|
||||
* 在架商品面板 mount 判据(2026-11-25 额度改口径):余量读数、展开取数、
|
||||
* 标记已下架走确认框两臂+成功回执+重取列表。api 模块整体 mock——
|
||||
* 面板必须经 fetchJdOnShelf/markJdItemDelisted 出口(裸 URL 回退当场红)。
|
||||
*/
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
onShelf: vi.fn(),
|
||||
markDelisted: vi.fn(),
|
||||
confirm: vi.fn(),
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/shared/api/types/modules/jd-publish', () => ({
|
||||
fetchJdOnShelf: api.onShelf,
|
||||
markJdItemDelisted: api.markDelisted,
|
||||
}))
|
||||
vi.mock('element-plus', async (importOriginal) => ({
|
||||
...await importOriginal<typeof import('element-plus')>(),
|
||||
ElMessage: { success: api.success, error: api.error },
|
||||
ElMessageBox: { confirm: api.confirm },
|
||||
}))
|
||||
|
||||
function pageVo(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
used: 2, limit: 5000, unlimited: false, total: 2,
|
||||
items: [
|
||||
{ itemId: 100, productId: 7, productCode: '100365361600', title: '收纳盒A', shopName: '家居日用数据库店', listedAt: '2026-11-23 20:30:04' },
|
||||
{ itemId: 101, productId: 8, productCode: '100365355826', title: '纸巾盒B', shopName: '家居日用数据库店', listedAt: '2026-11-23 20:21:29' },
|
||||
],
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
let wrapper: VueWrapper | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
})
|
||||
|
||||
async function mountPanel() {
|
||||
// 替身注册法与 jd-publish-dispatch.mount.test.ts 同族:分页替身+loading 指令空实现
|
||||
wrapper = mount(JdOnShelfPanel, {
|
||||
global: {
|
||||
stubs: { ElPagination: { emits: ['current-change'], template: '<div />' } },
|
||||
directives: { loading: () => undefined },
|
||||
},
|
||||
})
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
it('默认收起不取数;展开后拉第一页并显余量读数', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo())
|
||||
const w = await mountPanel()
|
||||
expect(api.onShelf).not.toHaveBeenCalled()
|
||||
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(api.onShelf).toHaveBeenCalledTimes(1)
|
||||
expect(api.onShelf.mock.calls[0][0]).toBe(1)
|
||||
expect(api.onShelf.mock.calls[0][1]).toBe(20)
|
||||
expect(w.text()).toContain('当前在架 2/5000')
|
||||
expect(w.findAll('.on-shelf-row')).toHaveLength(2)
|
||||
expect(w.text()).toContain('收纳盒A')
|
||||
})
|
||||
|
||||
it('不限档显「不限」,绝不显「/0」坏数', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo({ used: 0, limit: 0, unlimited: true, total: 0, items: [] }))
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
expect(w.text()).toContain('当前在架 0/不限')
|
||||
expect(w.text()).not.toContain('/0')
|
||||
expect(w.text()).toContain('上架成功后的商品会出现在这里')
|
||||
})
|
||||
|
||||
it('额度到顶出琥珀提醒句', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo({ used: 5000, total: 5000 }))
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
expect(w.find('.on-shelf-warn').text()).toContain('额度已满')
|
||||
expect(w.find('.on-shelf-warn').text()).toContain('标记已下架')
|
||||
})
|
||||
|
||||
it('标记已下架:确认→调 api(itemId,true)→回执点名编码→重取列表', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo())
|
||||
api.confirm.mockResolvedValue(true)
|
||||
api.markDelisted.mockResolvedValue(null)
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
await w.findAll('.on-shelf-mark')[0].trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(api.markDelisted).toHaveBeenCalledWith(100, true)
|
||||
expect(api.success).toHaveBeenCalledTimes(1)
|
||||
expect(String(api.success.mock.calls[0][0])).toContain('100365361600')
|
||||
// 标记成功后重取(腾额度读数当场回跳)
|
||||
expect(api.onShelf).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
|
||||
it('确认框取消(reject 臂)不发起标记', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo())
|
||||
api.confirm.mockRejectedValue('cancel')
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
await w.findAll('.on-shelf-mark')[1].trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(api.markDelisted).not.toHaveBeenCalled()
|
||||
expect(api.onShelf).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('标记失败透出服务端原文(跨团队 403 等)', async () => {
|
||||
api.onShelf.mockResolvedValue(pageVo())
|
||||
api.confirm.mockResolvedValue(true)
|
||||
api.markDelisted.mockRejectedValue(new Error('只能标记本团队(管理员及其名下员工)的上架商品'))
|
||||
const w = await mountPanel()
|
||||
await w.get('.on-shelf-toggle').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
await w.findAll('.on-shelf-mark')[0].trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(api.error).toHaveBeenCalledTimes(1)
|
||||
expect(String(api.error.mock.calls[0][0])).toContain('本团队')
|
||||
})
|
||||
Reference in New Issue
Block a user