fix(前端): 京东上架在架面板只留余量统计数——商品数据收进「管理」小入口(2026-11-28 客户口径「只要个统计数,不需要显示上架的数据」)

- 面板默认只显「当前在架 N/上限 M」一行,挂载即取数;「展开在架商品」「刷新」两按钮删
- 商品数据与「标记已下架」收进「管理」小入口,点开重取(读数与列表都新鲜),再点收起
- 「标记已下架」保留:它是腾额度的唯一界面出口(京麦人工下架系统感知不到),不能随列表一起删
- 满额琥珀提醒改经 quotaFullWarning 单出口,点名「管理」入口不再提「本列表」
- 判据:纯函数 9 支+mount 8 支全绿(含取数失败透出原文新格);反向验证两向(旧文案回流绊线红/数据默认常驻行为红)当场红逐字节复原
- 台账无涉:catch blocks 仍 339(两支 catch 形状未动)、JdOnShelfPanel 不在可读基线点名册
This commit is contained in:
2026-11-28 01:53:48 +08:00
parent 10dec12ec0
commit 2ab740c529
4 changed files with 107 additions and 44 deletions
+18 -12
View File
@@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { onMounted, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus' import { ElMessage, ElMessageBox } from 'element-plus'
import { import {
fetchJdOnShelf, fetchJdOnShelf,
@@ -9,20 +9,25 @@ import {
} from '@/shared/api/types/modules/jd-publish' } from '@/shared/api/types/modules/jd-publish'
import { import {
clampPageSize, clampPageSize,
manageButtonLabel,
markButtonLabel, markButtonLabel,
markDelistedNotice, markDelistedNotice,
onShelfEmptyText, onShelfEmptyText,
quotaFullWarning,
quotaNearLimit, quotaNearLimit,
quotaReadoutText, quotaReadoutText,
} from './jd-on-shelf' } from './jd-on-shelf'
import { formatDateTime } from '@/shared/utils/datetime' import { formatDateTime } from '@/shared/utils/datetime'
/** /**
* 在架商品面板(2026-11-25 客户口径「上限=同时在架商品数,下架 10 个就能再上 10 个」)。 * 在架余量面板(2026-11-25 客户口径「上限=同时在架商品数,下架 10 个就能再上 10 个」;
* 2026-11-28 客户口径「只要个统计数,不需要显示上架的数据」——默认只显余量读数一行,
* 商品数据与「标记已下架」收进「管理」小入口,点开才见;「标记已下架」仍是腾额度的
* 唯一界面出口,不能随列表一起删)。
* *
* 京麦人工下架系统感知不到,本面板是「标记已下架腾额度」的唯一界面出口; * 余量读数 used/limit 与建单配额闸同一正本(服务端 JdPublishQuotaService),这里看到
* 余量读数 used/limit 与建单配额闸同一正本(服务端 JdPublishQuotaService), * 的和建单被拦的是同一个数;挂载即取数,点「管理」重取一遍(读数与列表都新鲜)。
* 这里看到的和建单被拦的是同一个数。文案单出口在 jd-on-shelf.ts(判据同读)。 * 文案单出口在 jd-on-shelf.ts(判据同读)。
* 团队口径:管理员=本人+名下员工(管理员可替员工标记),员工=所属管理员团队。 * 团队口径:管理员=本人+名下员工(管理员可替员工标记),员工=所属管理员团队。
*/ */
@@ -33,6 +38,8 @@ const loading = ref(false)
const page = ref(1) const page = ref(1)
const vo = ref<JdOnShelfPageVo | null>(null) const vo = ref<JdOnShelfPageVo | null>(null)
onMounted(() => { void load() })
async function load() { async function load() {
loading.value = true loading.value = true
try { try {
@@ -47,7 +54,7 @@ async function load() {
function togglePanel() { function togglePanel() {
open.value = !open.value open.value = !open.value
if (open.value && !vo.value) void load() if (open.value) void load()
} }
async function changePage(next: number) { async function changePage(next: number) {
@@ -80,14 +87,13 @@ async function markDelisted(item: JdOnShelfItemVo) {
<template> <template>
<section class="on-shelf" v-loading="loading"> <section class="on-shelf" v-loading="loading">
<div class="on-shelf-head"> <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> <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> <button class="on-shelf-manage" type="button" :aria-expanded="open" @click="togglePanel">
{{ manageButtonLabel(open) }}
</button>
</div> </div>
<p v-if="vo && quotaNearLimit(vo.used, vo.limit, vo.unlimited)" class="on-shelf-warn"> <p v-if="vo && quotaNearLimit(vo.used, vo.limit, vo.unlimited)" class="on-shelf-warn">
额度已满:请先在京麦下架商品,并到本列表「标记已下架」腾出额度后再建单。 {{ quotaFullWarning() }}
</p> </p>
<div v-if="open" class="on-shelf-body"> <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-if="vo && !vo.items.length" class="on-shelf-empty">{{ onShelfEmptyText(vo.unlimited, vo.used) }}</div>
@@ -113,7 +119,7 @@ async function markDelisted(item: JdOnShelfItemVo) {
<style scoped> <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 { 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-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-manage { 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-quota { color: #e6edf7; font-size: 13px; }
.on-shelf-warn { margin: 8px 0 0; color: #e6a23c; font-size: 12px; } .on-shelf-warn { margin: 8px 0 0; color: #e6a23c; font-size: 12px; }
.on-shelf-body { margin-top: 10px; } .on-shelf-body { margin-top: 10px; }
+16 -4
View File
@@ -1,9 +1,11 @@
/** /**
* 在架商品面板的纯函数层(2026-11-25 客户口径「上限=同时在架商品数,下架腾额度」)。 * 在架面板的纯函数层(2026-11-25 客户口径「上限=同时在架商品数,下架腾额度」;
* 2026-11-28 客户口径「只要个统计数,不需要显示上架的数据」——面板默认只显余量
* 读数,商品数据与「标记已下架」收进「管理」小入口,点开才见)。
* *
* 文案单出口纪律:余量读数、空态、标记按钮文案只在这里拼——面板与判据读同一份, * 文案单出口纪律:余量读数、空态、管理入口、满额提醒、标记按钮文案只在这里拼——
* 回退(比如把「不限」拼成「0」)当场红。服务端 used/limit 与建单配额闸同一正本, * 面板与判据读同一份,回退(比如把「不限」拼成「0」)当场红。服务端 used/limit 与
* 本层只做展示换算,不做任何二次判定。 * 建单配额闸同一正本,本层只做展示换算,不做任何二次判定。
*/ */
/** 余量读数:limit≤0(0=不限)显「不限」,绝不显「/0」这种像坏数的数字。 */ /** 余量读数:limit≤0(0=不限)显「不限」,绝不显「/0」这种像坏数的数字。 */
@@ -32,6 +34,16 @@ export function markButtonLabel(): string {
return '标记已下架'; return '标记已下架';
} }
/** 管理入口按钮文案:收起态是「管理」(小入口,不抢余量读数的视线),展开态「收起」。 */
export function manageButtonLabel(open: boolean): string {
return open ? '收起' : '管理'
}
/** 额度到顶提醒句:点名「管理」入口与腾额度动作(2026-11-28 起列表收进管理入口,不再说「本列表」)。 */
export function quotaFullWarning(): string {
return '额度已满:请先在京麦下架商品,再点「管理」标记已下架腾出额度。'
}
/** 分页大小钳制:与后端 MAX_PAGE_SIZE=100 同口径,超了按 100 请求。 */ /** 分页大小钳制:与后端 MAX_PAGE_SIZE=100 同口径,超了按 100 请求。 */
export function clampPageSize(pageSize: number): number { export function clampPageSize(pageSize: number): number {
if (!Number.isFinite(pageSize) || pageSize <= 0) return 20; if (!Number.isFinite(pageSize) || pageSize <= 0) return 20;
+21 -4
View File
@@ -5,20 +5,24 @@ import { join } from 'node:path'
import { import {
clampPageSize, clampPageSize,
manageButtonLabel,
markButtonLabel, markButtonLabel,
markDelistedNotice, markDelistedNotice,
onShelfEmptyText, onShelfEmptyText,
quotaFullWarning,
quotaNearLimit, quotaNearLimit,
quotaReadoutText, quotaReadoutText,
} from '../src/pages/jd/jd-on-shelf.ts' } from '../src/pages/jd/jd-on-shelf.ts'
/** /**
* 在架商品面板纯函数与接线绊线(2026-11-25 客户口径「上限=同时在架商品数, * 在架面板纯函数与接线绊线(2026-11-25 客户口径「上限=同时在架商品数,
* 下架 10 个就能再上 10 个换着卖」)。 * 下架 10 个就能再上 10 个换着卖」;2026-11-28 客户口径「只要个统计数,
* 不需要显示上架的数据」——商品数据收进「管理」小入口,点开才见)。
* *
* 绊线盯的是「安静地不做」类回退:面板绕过 api 模块裸拼 URL(落点台账失效)、 * 绊线盯的是「安静地不做」类回退:面板绕过 api 模块裸拼 URL(落点台账失效)、
* 文案在组件里硬拼(单出口失效)、JdPublishTab 不挂面板(功能整面失踪)—— * 文案在组件里硬拼(单出口失效)、旧「展开在架商品」大按钮回流(数据展示
* 行为测试全绿也拦不住,只有源码绊线拦得住。 * 重新常驻界面)、JdPublishTab 不挂面板(功能整面失踪)——行为测试全绿也
* 拦不住,只有源码绊线拦得住。
*/ */
const ROOT = process.cwd() const ROOT = process.cwd()
@@ -68,6 +72,15 @@ test('标记回执点名商品编码与确认义务,不写「操作成功」
assert.equal(markButtonLabel(), '标记已下架') assert.equal(markButtonLabel(), '标记已下架')
}) })
test('管理入口与满额提醒文案(2026-11-28 精简口径):入口只说「管理」,提醒点名「管理」不再提「本列表」', () => {
assert.equal(manageButtonLabel(false), '管理')
assert.equal(manageButtonLabel(true), '收起')
assert.match(quotaFullWarning(), /额度已满/)
assert.match(quotaFullWarning(), /「管理」/)
assert.match(quotaFullWarning(), /标记已下架/)
assert.ok(!quotaFullWarning().includes('本列表'), '列表已收进管理入口,「本列表」指路不得回流')
})
// ---------------------------------------------------------- 源码绊线:接线与单出口 // ---------------------------------------------------------- 源码绊线:接线与单出口
test('绊线:在架端点只在 endpoints.ts 登记一处,面板必须走 api 模块出口', () => { test('绊线:在架端点只在 endpoints.ts 登记一处,面板必须走 api 模块出口', () => {
@@ -91,6 +104,10 @@ test('绊线:面板文案单出口——组件不硬拼「当前在架」,
assert.match(panel, /quotaReadoutText/) assert.match(panel, /quotaReadoutText/)
assert.match(panel, /onShelfEmptyText/) assert.match(panel, /onShelfEmptyText/)
assert.match(panel, /markDelistedNotice/) assert.match(panel, /markDelistedNotice/)
assert.match(panel, /manageButtonLabel/)
assert.match(panel, /quotaFullWarning/)
assert.doesNotMatch(panel, /展开在架商品/, '2026-11-28 精简口径:旧「展开在架商品」数据展示入口不得回流')
assert.doesNotMatch(panel, /on-shelf-refresh/, '独立「刷新」按钮已删,余量随挂载与点开管理重取')
}) })
test('绊线:JdPublishTab 必须挂上在架面板(功能整面失踪类回退)', () => { test('绊线:JdPublishTab 必须挂上在架面板(功能整面失踪类回退)', () => {
@@ -3,9 +3,10 @@ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import JdOnShelfPanel from '@/pages/jd/JdOnShelfPanel.vue' import JdOnShelfPanel from '@/pages/jd/JdOnShelfPanel.vue'
/** /**
* 在架商品面板 mount 判据(2026-11-25 额度改口径):余量读数、展开取数、 * 在架余量面板 mount 判据(2026-11-28 客户口径「只要个统计数,不需要显示上架的数据」):
* 标记已下架走确认框两臂+成功回执+重取列表。api 模块整体 mock—— * 挂载即取数只显余量读数一行,商品数据与「标记已下架」默认不显、点「管理」才见;
* 面板必须经 fetchJdOnShelf/markJdItemDelisted 出口(裸 URL 回退当场红)。 * 标记已下架走确认框两臂+成功回执+重取列表。api 模块整体 mock——面板必须经
* fetchJdOnShelf/markJdItemDelisted 出口(裸 URL 回退当场红)。
*/ */
const api = vi.hoisted(() => ({ const api = vi.hoisted(() => ({
@@ -57,48 +58,78 @@ async function mountPanel() {
return wrapper return wrapper
} }
it('默认收起不取数;展开后拉第一页并显余量读数', async () => { /** 展开管理小入口(列表唯一入口,2026-11-28 起数据默认不显)。 */
async function openManage(w: VueWrapper) {
await w.get('.on-shelf-manage').trigger('click')
await flushPromises()
}
it('挂载即取数,只显余量读数一行;商品数据默认不显', async () => {
api.onShelf.mockResolvedValue(pageVo()) api.onShelf.mockResolvedValue(pageVo())
const w = await mountPanel() 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).toHaveBeenCalledTimes(1)
expect(api.onShelf.mock.calls[0][0]).toBe(1) expect(api.onShelf.mock.calls[0][0]).toBe(1)
expect(api.onShelf.mock.calls[0][1]).toBe(20) expect(api.onShelf.mock.calls[0][1]).toBe(20)
expect(w.text()).toContain('当前在架 2/5000') expect(w.text()).toContain('当前在架 2/5000')
expect(w.findAll('.on-shelf-row')).toHaveLength(2) // 数据展示默认收起:没有商品行,也没有「展开在架商品」这类按钮
expect(w.text()).toContain('收纳盒A') expect(w.find('.on-shelf-row').exists()).toBe(false)
expect(w.text()).not.toContain('收纳盒A')
expect(w.find('.on-shelf-manage').text()).toBe('管理')
}) })
it('不限档显「不限」,绝不显「/0」坏数', async () => { it('不限档显「不限」,绝不显「/0」坏数;空态在管理里显一句', async () => {
api.onShelf.mockResolvedValue(pageVo({ used: 0, limit: 0, unlimited: true, total: 0, items: [] })) api.onShelf.mockResolvedValue(pageVo({ used: 0, limit: 0, unlimited: true, total: 0, items: [] }))
const w = await mountPanel() const w = await mountPanel()
await w.get('.on-shelf-toggle').trigger('click')
await flushPromises()
expect(w.text()).toContain('当前在架 0/不限') expect(w.text()).toContain('当前在架 0/不限')
expect(w.text()).not.toContain('/0') expect(w.text()).not.toContain('/0')
await openManage(w)
expect(w.text()).toContain('当前没有已上架商品') expect(w.text()).toContain('当前没有已上架商品')
}) })
it('额度到顶出琥珀提醒句', async () => { it('点「管理」才显商品数据与标记按钮;再点收起', async () => {
api.onShelf.mockResolvedValue(pageVo())
const w = await mountPanel()
await openManage(w)
// 点开管理重取一遍(读数与列表都新鲜)
expect(api.onShelf).toHaveBeenCalledTimes(2)
expect(w.findAll('.on-shelf-row')).toHaveLength(2)
expect(w.text()).toContain('收纳盒A')
expect(w.find('.on-shelf-manage').text()).toBe('收起')
await w.get('.on-shelf-manage').trigger('click')
await flushPromises()
expect(w.find('.on-shelf-row').exists()).toBe(false)
})
it('额度到顶出琥珀提醒句,点名「管理」入口', async () => {
api.onShelf.mockResolvedValue(pageVo({ used: 5000, total: 5000 })) api.onShelf.mockResolvedValue(pageVo({ used: 5000, total: 5000 }))
const w = await mountPanel() 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('额度已满')
expect(w.find('.on-shelf-warn').text()).toContain('「管理」')
expect(w.find('.on-shelf-warn').text()).toContain('标记已下架') expect(w.find('.on-shelf-warn').text()).toContain('标记已下架')
}) })
it('取数失败透出错误原文,余量读数不留旧数也不显坏数', async () => {
api.onShelf.mockRejectedValue(new Error('服务暂时不可用'))
const w = await mountPanel()
await flushPromises()
expect(api.error).toHaveBeenCalledTimes(1)
expect(String(api.error.mock.calls[0][0])).toContain('服务暂时不可用')
expect(w.text()).toContain('余量读取中…')
expect(w.text()).not.toContain('当前在架')
})
it('标记已下架:确认→调 api(itemId,true)→回执点名编码→重取列表', async () => { it('标记已下架:确认→调 api(itemId,true)→回执点名编码→重取列表', async () => {
api.onShelf.mockResolvedValue(pageVo()) api.onShelf.mockResolvedValue(pageVo())
api.confirm.mockResolvedValue(true) api.confirm.mockResolvedValue(true)
api.markDelisted.mockResolvedValue(null) api.markDelisted.mockResolvedValue(null)
const w = await mountPanel() const w = await mountPanel()
await w.get('.on-shelf-toggle').trigger('click') await openManage(w)
await flushPromises()
await w.findAll('.on-shelf-mark')[0].trigger('click') await w.findAll('.on-shelf-mark')[0].trigger('click')
await flushPromises() await flushPromises()
@@ -107,21 +138,19 @@ it('标记已下架:确认→调 api(itemId,true)→回执点名编码→重
expect(api.success).toHaveBeenCalledTimes(1) expect(api.success).toHaveBeenCalledTimes(1)
expect(String(api.success.mock.calls[0][0])).toContain('100365361600') expect(String(api.success.mock.calls[0][0])).toContain('100365361600')
// 标记成功后重取(腾额度读数当场回跳) // 标记成功后重取(腾额度读数当场回跳)
expect(api.onShelf).toHaveBeenCalledTimes(2) expect(api.onShelf).toHaveBeenCalledTimes(3)
}) })
it('确认框取消(reject 臂)不发起标记', async () => { it('确认框取消(reject 臂)不发起标记', async () => {
api.onShelf.mockResolvedValue(pageVo()) api.onShelf.mockResolvedValue(pageVo())
api.confirm.mockRejectedValue('cancel') api.confirm.mockRejectedValue('cancel')
const w = await mountPanel() const w = await mountPanel()
await w.get('.on-shelf-toggle').trigger('click') await openManage(w)
await flushPromises()
await w.findAll('.on-shelf-mark')[1].trigger('click') await w.findAll('.on-shelf-mark')[1].trigger('click')
await flushPromises() await flushPromises()
expect(api.markDelisted).not.toHaveBeenCalled() expect(api.markDelisted).not.toHaveBeenCalled()
expect(api.onShelf).toHaveBeenCalledTimes(1)
}) })
it('标记失败透出服务端原文(跨团队 403 等)', async () => { it('标记失败透出服务端原文(跨团队 403 等)', async () => {
@@ -129,8 +158,7 @@ it('标记失败透出服务端原文(跨团队 403 等)', async () => {
api.confirm.mockResolvedValue(true) api.confirm.mockResolvedValue(true)
api.markDelisted.mockRejectedValue(new Error('只能标记本团队(管理员及其名下员工)的上架商品')) api.markDelisted.mockRejectedValue(new Error('只能标记本团队(管理员及其名下员工)的上架商品'))
const w = await mountPanel() const w = await mountPanel()
await w.get('.on-shelf-toggle').trigger('click') await openManage(w)
await flushPromises()
await w.findAll('.on-shelf-mark')[0].trigger('click') await w.findAll('.on-shelf-mark')[0].trigger('click')
await flushPromises() await flushPromises()