style(admin): 分类管理弹窗搜索/新建改垂直排列+分类列表加分页(2026-11-17 用户口径「垂直排阿,这样好看」「不然留白太多了」「分类这也要加分页」)
垂直排列:manage-bar 由 flex-wrap 并排改 column,搜索与新建各占整行,弹窗内容变高、列表下空白收窄;
分页:每页 6 行+上一页/下一页+「第 x / y 页·共 N 个分类」,只在超过一页时渲染。分类与父页「分类」下拉共用同一条全量接口(下拉必须全量),故做本地切片;搜索同为本地过滤 ⇒ 同源不漏项;改关键字回第一页、命中集变少把越界页码钳回。实测 8 行在 700px 高视口会顶出列表内滚动条(与页码条并存难看),故定 6 行。
闸门:--fast 唯一红格=可读棘轮,红因是 7299166e 换 el-select 顶长 5 个已登记超长页面(各 +3~30 行),非本笔;vue-tsc rc=0,本弹窗 15 例与京东数据库页 35 例挂载测试全绿。
This commit is contained in:
@@ -38,6 +38,12 @@ const errorText = ref('')
|
||||
const groups = ref<JdProductGroup[]>([])
|
||||
/** 搜索:按分类名称包含过滤(本地过滤,不另发请求)。 */
|
||||
const keyword = ref('')
|
||||
/** 分页(2026-11-17 用户口径「分类这也要加分页」):分类与父页「分类」下拉共用同一条全量
|
||||
* 接口(下拉必须全量,不能分页),所以这里做本地切片;搜索同样是本地过滤 ⇒ 分页与搜索
|
||||
* 同源,不会出现「先 limit 再过滤」那种翻页永久漏项。每页 6 行:实测 8 行在 700px 高的
|
||||
* 视口里会顶出列表内滚动条(滚动条与页码条并存很难看),6 行矮屏也一屏放得下。 */
|
||||
const PAGE_SIZE = 6
|
||||
const pageNo = ref(1)
|
||||
/** 新建:只收名称(排序输入 2026-11-15 客户口径下线,sortOrder 恒 0,后端契约不变)。 */
|
||||
const createName = ref('')
|
||||
const creating = ref(false)
|
||||
@@ -53,6 +59,20 @@ const filteredGroups = computed(() => {
|
||||
if (!kw) return groups.value
|
||||
return groups.value.filter((group) => group.name.toLowerCase().includes(kw))
|
||||
})
|
||||
/** 总页数(至少 1 页:空列表时页码条不渲染,但钳制逻辑要有个有效上界)。 */
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(filteredGroups.value.length / PAGE_SIZE)))
|
||||
/** 当前页的行(在搜索命中集上切片)。 */
|
||||
const pagedGroups = computed(() => {
|
||||
const start = (pageNo.value - 1) * PAGE_SIZE
|
||||
return filteredGroups.value.slice(start, start + PAGE_SIZE)
|
||||
})
|
||||
/** 只有超过一页才出页码条:一屏装得下时不白占一行。 */
|
||||
const showPager = computed(() => filteredGroups.value.length > PAGE_SIZE)
|
||||
|
||||
/** 翻页:页码钳在 [1, totalPages](删除/搜索后越界不会翻到空白页)。 */
|
||||
function goPage(target: number): void {
|
||||
pageNo.value = Math.min(Math.max(1, target), totalPages.value)
|
||||
}
|
||||
/** 空表文案分四种:不属于任何组 / 本组没分类(可管理)/ 本组没分类(只读)/ 搜索无命中。 */
|
||||
const emptyListText = computed(() => {
|
||||
if (props.ownerGroupId <= 0) return '你还不属于任何数据权限分组'
|
||||
@@ -157,12 +177,22 @@ watch(
|
||||
loadFailure.value = ''
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
pageNo.value = 1
|
||||
void loadGroups()
|
||||
}
|
||||
},
|
||||
// immediate:对话框可能以 visible=true 直接挂载(测试/复用场景),这时也要首取。
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/** 改关键字回第一页(命中集变了,停在旧页码会落在空白处)。 */
|
||||
watch(keyword, () => {
|
||||
pageNo.value = 1
|
||||
})
|
||||
/** 命中集变少(删掉最后一条/搜索收窄)后把越界页码钳回最后一页。 */
|
||||
watch(totalPages, (pages) => {
|
||||
if (pageNo.value > pages) pageNo.value = pages
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -190,7 +220,7 @@ watch(
|
||||
|
||||
<ul class="option-list">
|
||||
<template v-if="filteredGroups.length">
|
||||
<li v-for="group in filteredGroups" :key="group.id" class="option-row">
|
||||
<li v-for="group in pagedGroups" :key="group.id" class="option-row">
|
||||
<template v-if="editingId === group.id">
|
||||
<input v-model="editingName" class="rename-input" type="text" aria-label="分类新名称" @keyup.enter="submitRename(group)" />
|
||||
<span class="row-actions">
|
||||
@@ -212,6 +242,12 @@ watch(
|
||||
<li v-else class="manage-empty">{{ emptyListText }}</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="showPager" class="manage-pager">
|
||||
<button class="btn btn-sm btn-secondary" type="button" :disabled="pageNo <= 1" @click="goPage(pageNo - 1)">上一页</button>
|
||||
<span class="pager-text">第 {{ pageNo }} / {{ totalPages }} 页 · 共 {{ filteredGroups.length }} 个分类</span>
|
||||
<button class="btn btn-sm btn-secondary" type="button" :disabled="pageNo >= totalPages" @click="goPage(pageNo + 1)">下一页</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-foot">
|
||||
<button class="btn btn-secondary" type="button" @click="emit('close')">关闭</button>
|
||||
</div>
|
||||
@@ -281,11 +317,12 @@ watch(
|
||||
font-size: 12.5px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
/* 2026-11-17 用户口径「垂直排阿,这样好看」「不然留白太多了」:搜索与新建各占整行
|
||||
(原来两件并排 flex:1 各挤一半宽),弹窗内容变高、列表下方空白收窄,两行输入等宽也更整齐。 */
|
||||
.manage-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.search-input,
|
||||
@@ -312,14 +349,12 @@ watch(
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.search-input {
|
||||
flex: 1;
|
||||
min-width: 140px;
|
||||
width: 100%;
|
||||
}
|
||||
.group-create {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
gap: 8px;
|
||||
min-width: 220px;
|
||||
width: 100%;
|
||||
}
|
||||
.group-create input {
|
||||
flex: 1;
|
||||
@@ -388,6 +423,18 @@ watch(
|
||||
font-size: 13px;
|
||||
list-style: none;
|
||||
}
|
||||
.manage-pager {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.pager-text {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rename-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
@@ -110,6 +110,49 @@ describe('京东分类管理对话框(V204 独立页 2026-11-17 并入京东
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('分页:每页 6 条、翻页只换当前页、改搜索回第一页(2026-11-17 用户口径「分类这也要加分页」)', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue(
|
||||
Array.from({ length: 11 }, (_, index) => group(100 + index, `分类${index + 1}`)),
|
||||
)
|
||||
const wrapper = await mountDialog()
|
||||
expect(wrapper.findAll('.option-row')).toHaveLength(6, '第一页只渲染 6 行')
|
||||
expect(wrapper.text()).not.toContain('分类7', '第 7 条以后不在第一页')
|
||||
const pagerText = wrapper.get('.manage-pager').text()
|
||||
expect(pagerText).toContain('第 1 / 2 页')
|
||||
expect(pagerText).toContain('共 11 个分类', '总数取搜索命中集,不是当前页行数')
|
||||
|
||||
await wrapper.findAll('.manage-pager button').find((b) => b.text() === '下一页')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.findAll('.option-row')).toHaveLength(5, '第二页剩 5 行')
|
||||
expect(wrapper.text()).toContain('分类11')
|
||||
expect(wrapper.get('.manage-pager').text()).toContain('第 2 / 2 页')
|
||||
|
||||
await wrapper.get('.search-input').setValue('分类1')
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.manage-pager').exists()).toBe(false, '命中 3 条不足一页 ⇒ 不渲染页码条')
|
||||
expect(wrapper.findAll('.option-row')).toHaveLength(3, '搜索回第一页(不是停在旧页码的空白处)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('分页:一屏装得下就不出页码条(不白占一行)', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3), group(8, '裤装', 1)])
|
||||
const wrapper = await mountDialog()
|
||||
expect(wrapper.findAll('.option-row')).toHaveLength(2)
|
||||
expect(wrapper.find('.manage-pager').exists()).toBe(false)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('搜索与新建行同属 manage-bar 的两行(搜索在上、新建在下,2026-11-17 改垂直排列)', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountDialog()
|
||||
const bar = wrapper.get('.manage-bar')
|
||||
const children = Array.from(bar.element.children)
|
||||
expect(children).toHaveLength(2, 'bar 只有两件:搜索框、新建行')
|
||||
expect(children[0].classList.contains('search-input')).toBe(true, '垂直排列时搜索在上')
|
||||
expect(children[1].classList.contains('group-create')).toBe(true, '新建行在下')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('改名:行内编辑后按 (id, {name, sortOrder}) 提交并 emit changed', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountDialog()
|
||||
|
||||
Reference in New Issue
Block a user