style(admin): 京东数据库页两颗下拉换 el-select——弹层圆角与亚马逊面统一(2026-11-17 用户口径「和亚马逊不统一」):分组下拉带搜索(admin-filter 同壳 42px/9px),分类筛选保留「全部分类」行同语义;删原生 select 死样式,工具栏位宽 200px 由页内钉;挂载测试换「点开→点选项」真实交互+组件树读选项(35 例全绿,vue-tsc 0 错,node --test 1922/1924 唯一红=date-range-order 在册环境红与本次无关)
This commit is contained in:
@@ -358,16 +358,20 @@ onMounted(async () => {
|
||||
<label>分组</label>
|
||||
<!-- 当前分组(V203):能看多组的人(平台超管/公司超管)下拉切换;只有一组时锁定显示组名。
|
||||
2026-11-16 用户口径「做成分组」:从工具栏裸下拉上移进筛选行,做成带标签的表单控件
|
||||
(与其他筛选同壳同圆角)。分组是分类列/分类筛选/分类管理的作用域,不是筛选条件
|
||||
⇒ 放在筛选行也只是占位,「重置」不清它(挂载测试钉住)。 -->
|
||||
<select
|
||||
(与其他筛选同壳同圆角)。2026-11-17 用户口径「和亚马逊不统一」:原生 <select> 的
|
||||
弹层是浏览器直角原生物,换 el-select(同亚马逊面 admin-filter 同壳),组多时可搜索。
|
||||
分组是分类列/分类筛选/分类管理的作用域,不是筛选条件 ⇒ 放在筛选行也只是占位,
|
||||
「重置」不清它(挂载测试钉住)。 -->
|
||||
<el-select
|
||||
v-if="canSwitchGroup"
|
||||
:value="ownerGroupId"
|
||||
:model-value="ownerGroupId"
|
||||
class="admin-filter"
|
||||
filterable
|
||||
aria-label="当前分组"
|
||||
@change="changeOwnerGroup(Number(($event.target as HTMLSelectElement).value))"
|
||||
@change="changeOwnerGroup"
|
||||
>
|
||||
<option v-for="group in categoryScope" :key="group.id" :value="group.id">{{ group.label }}</option>
|
||||
</select>
|
||||
<el-option v-for="group in categoryScope" :key="group.id" :value="group.id" :label="group.label" />
|
||||
</el-select>
|
||||
<span v-else class="jd-group-locked" title="你的数据权限内只有这一个分组">{{ currentGroupName }}</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -400,10 +404,19 @@ onMounted(async () => {
|
||||
<!-- 商品行写只对平台超管;分类写由当前分组 editable 决定(本组管理员/公司超管/平台超管)。
|
||||
非超管看到只读提示,分类维护入口=工具栏「分类管理」(只读可看,写控件按 editable 分档)。 -->
|
||||
<span v-if="!isSuperAdmin" class="jd-readonly-tip">只读:编辑/删除仅超级管理员可用;分类在本页「分类管理」查看与维护</span>
|
||||
<select v-model="filter.groupId" aria-label="筛选店铺分类" @change="apply">
|
||||
<option value="">全部分类</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
<!-- 分类筛选(2026-11-17 与分组同刀换 el-select,弹层圆角与亚马逊统一):保留显式
|
||||
「全部分类」行(value='',与旧原生下拉同语义——列表里永远有回全量的出口),
|
||||
选中它/重置回 '' 时闭壳显示同文案占位。 -->
|
||||
<el-select
|
||||
v-model="filter.groupId"
|
||||
class="admin-filter"
|
||||
placeholder="全部分类"
|
||||
aria-label="筛选店铺分类"
|
||||
@change="apply"
|
||||
>
|
||||
<el-option label="全部分类" value="" />
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.name" :value="String(group.id)" />
|
||||
</el-select>
|
||||
<!-- 分类管理(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里」):V204 独立
|
||||
子菜单页整体并入本对话框(搜索+新建+改名+删除)。入口对所有人渲染(同组普通号
|
||||
只读可看,V203),写控件由对话框按当前分组 editable 分档。 -->
|
||||
|
||||
@@ -62,8 +62,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -77,12 +76,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
@@ -131,38 +128,12 @@ h3 {
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
/* 工具栏里的下拉与按钮统一 42px 外壳(2026-11-16 用户口径「样式要统一」):
|
||||
这一行此前只有 .btn 有壳,原生 <select> 落成 28px 灰框、字号也不跟,
|
||||
与旁边按钮同排时高矮不齐(分组下拉同日上移进筛选行,本行只剩分类筛选一颗)。
|
||||
数值与 .form-group select / .btn 同一套(42px 高、
|
||||
9px 圆角、#cbd9e6 描边、#f8fbfd 底),箭头用内联 SVG 自绘,避免各浏览器原生
|
||||
箭头粗细不一(appearance:none 后必须补 padding-right 给箭头留位)。 */
|
||||
.jd-toolbar select {
|
||||
min-height: 42px;
|
||||
max-width: 220px;
|
||||
padding: 0 34px 0 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background-color: #f8fbfd;
|
||||
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%235b6f83' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 12px center;
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
color: #24384d;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.jd-toolbar select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.jd-toolbar select:focus {
|
||||
background-color: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
/* 工具栏分类筛选(2026-11-17 用户口径「和亚马逊不统一」起换 el-select):42px 外壳、
|
||||
9px 圆角、#cbd9e6 描边、#f8fbfd 浅底与 focus ring 都由全局 .el-select.admin-filter
|
||||
皮肤(main.css)出——与亚马逊面同一套,弹层不再是浏览器原生直角列表。
|
||||
这里只钉工具栏位宽(admin-filter 出厂 width:100%,进 flex 工具栏会横涨)。 */
|
||||
.jd-toolbar .el-select.admin-filter {
|
||||
width: 200px;
|
||||
}
|
||||
/* 危险动作(删除勾选)推到行尾:留在「批量编辑分类/分类筛选」旁边会被读成同一组动作。 */
|
||||
.jd-delete-btn {
|
||||
@@ -194,7 +165,7 @@ h3 {
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* 只有一个可见分组时锁定的组名(不可切):筛选行「分组」标签下的静态芯片(2026-11-16 用户口径
|
||||
「做成分组」把下拉从工具栏上移进筛选行后跟着搬),与同排 select 同高同壳(42px/9px 圆角),
|
||||
「做成分组」把下拉从工具栏上移进筛选行后跟着搬),与同排 el-select 同高同壳(42px/9px 圆角),
|
||||
"一组锁定"和"多组下拉"两种形态占位一致;组名超宽省略号收口,不把筛选行撑破。 */
|
||||
.jd-group-locked {
|
||||
display: flex;
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
* 跑法:`npx vitest run tests/mount/jd-database-page.mount.test.ts`
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
@@ -107,12 +108,44 @@ beforeEach(() => {
|
||||
|
||||
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||||
jdApi.fetchJdProductList.mockImplementation(() => Promise.resolve(payload))
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia] } })
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
// ---------------- el-select 交互助手(2026-11-17 两颗下拉换 el-select,与亚马逊面统一) ----------------
|
||||
// aria-label 经 EP 的 ariaLabel prop 落在内层 combobox input 上;选项弹层 teleport 到 body,
|
||||
// 但 ElOption/ElSelect 组件仍在挂载树里 ⇒ 选项清单走组件树读,点选走「点开→点选项」真实路径。
|
||||
|
||||
/** 按 aria-label 找对应的 ElSelect 组件实例(页面有两颗下拉,靠内层 input 的 aria-label 区分)。 */
|
||||
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
|
||||
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
|
||||
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
|
||||
return found!
|
||||
}
|
||||
|
||||
/** 读某颗下拉的全部选项文案(label prop;组件树查询不受弹层 teleport 影响)。 */
|
||||
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
|
||||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
|
||||
}
|
||||
|
||||
/** 点开指定下拉并点选目标文案的选项(触发 update:modelValue + change,与真实用户一致)。
|
||||
* 面板按内层 input 的 aria-controls 圈定,避免另一颗(可能仍挂着的)弹层串台。 */
|
||||
async function pickSelectOption(wrapper: VueWrapper<Element>, label: string, optionText: string): Promise<void> {
|
||||
const input = wrapper.get(`[aria-label="${label}"]`)
|
||||
await input.trigger('click')
|
||||
await flushPromises()
|
||||
const contentId = input.attributes('aria-controls')
|
||||
const scope = (contentId && document.getElementById(contentId)) ?? document.body
|
||||
const items = [...scope.querySelectorAll('.el-select-dropdown__item')]
|
||||
.filter((el) => !el.classList.contains('is-hidden'))
|
||||
const target = items.find((el) => (el.textContent ?? '').trim() === optionText)
|
||||
expect(target, `下拉应弹出「${optionText}」选项`).toBeTruthy()
|
||||
await new DOMWrapper(target as Element).trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 批量编辑分类(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」):
|
||||
* 勾选跨页累计记忆(翻页/重取不清)→ 对话框选目标分类归入或移出 → 按 (ids, groupId,
|
||||
* ownerGroupId) 提交;成功后清勾选并重取。旧弹窗的「勾选翻页即清」口径同日废止。 */
|
||||
@@ -121,7 +154,7 @@ describe('批量编辑分类(店铺分类弹窗 2026-11-17 下线后的替代
|
||||
jdApi.fetchJdProductList
|
||||
.mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 40, page: 1, pageSize: 20 }))
|
||||
.mockImplementation(() => Promise.resolve({ items: [item(2)], total: 40, page: 2, pageSize: 20 }))
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia] } })
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
const deleteBtn = () => wrapper.get('.jd-delete-btn')
|
||||
@@ -264,7 +297,7 @@ describe('分类管理入口(V204 独立页并入京东数据库页)', () =>
|
||||
: Promise.resolve([{ id: 8, name: '裤装', sortOrder: 1, productCount: 1 }])
|
||||
})
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
expect(wrapper.get('[aria-label="筛选店铺分类"]').text()).toContain('裙装', '首屏下拉含首取分类')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')).toContain('裙装', '首屏下拉含首取分类')
|
||||
|
||||
await wrapper.findAll('button').find((b) => b.text() === '分类管理')!.trigger('click')
|
||||
await flushPromises()
|
||||
@@ -276,9 +309,8 @@ describe('分类管理入口(V204 独立页并入京东数据库页)', () =>
|
||||
await flushPromises()
|
||||
expect(jdApi.deleteJdProductGroup, '删除按钮属于当前列表行').toHaveBeenCalledWith(8)
|
||||
// changed → 父页 loadGroupOptions:下拉按新列表重取(最后一次调用拿到删后列表)。
|
||||
const select = wrapper.get('[aria-label="筛选店铺分类"]')
|
||||
expect(select.text()).toContain('裤装', '下拉刷新出新一轮分类')
|
||||
expect(select.text()).not.toContain('裙装', '删掉的分类不再出现在筛选下拉')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')).toContain('裤装', '下拉刷新出新一轮分类')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')).not.toContain('裙装', '删掉的分类不再出现在筛选下拉')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
@@ -418,7 +450,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(textInputs).toHaveLength(2, '商品编码+标题关键字两个文本筛选框(店铺/商品状态已下线)')
|
||||
await textInputs[0].setValue('JD-1001')
|
||||
await textInputs[1].setValue('保温杯')
|
||||
await wrapper.get('[aria-label="筛选店铺分类"]').setValue('7')
|
||||
await pickSelectOption(wrapper, '筛选店铺分类', '甲组')
|
||||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||||
await dateInputs[0].setValue('2026-11-01')
|
||||
await dateInputs[1].setValue('2026-11-09')
|
||||
@@ -541,9 +573,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
it('重置把筛选面回空并回第一页重取', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const select = wrapper.get('[aria-label="筛选店铺分类"]')
|
||||
expect(select.text()).toContain('全部分类')
|
||||
await select.setValue('7')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')[0]).toBe('全部分类', '「全部分类」常驻列表首位(与旧原生下拉同语义)')
|
||||
await pickSelectOption(wrapper, '筛选店铺分类', '甲组')
|
||||
await wrapper.get('.cat-trigger').trigger('click')
|
||||
await wrapper.get('.cat-search').setValue('艺考')
|
||||
await wrapper.get('.cat-col-search .cat-row').trigger('click')
|
||||
@@ -558,7 +589,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore)
|
||||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(last).toMatchObject({ productCode: '', titleKeyword: '', groupId: '', category: '', page: 1 }, '重置后筛选全空、回第一页')
|
||||
expect((select.element as HTMLSelectElement).value).toBe('')
|
||||
expect(selectByLabel(wrapper, '筛选店铺分类').props('modelValue')).toBe('', '重置后分类筛选回「全部分类」')
|
||||
})
|
||||
|
||||
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
|
||||
@@ -845,12 +876,12 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||||
const picker = wrapper.get('[aria-label="当前分组"]')
|
||||
// 2026-11-16 用户口径「做成分组」:分组在筛选行里是带标签的表单控件(与其他筛选同壳同圆角),
|
||||
// 不再是工具栏裸下拉——钉住形状,防止搬回工具栏或丢标签。
|
||||
const groupField = (picker.element as HTMLSelectElement).closest('.form-group')
|
||||
const groupField = picker.element.closest('.form-group')
|
||||
expect(groupField?.querySelector('label')?.textContent).toBe('分组')
|
||||
expect(picker.findAll('option').map((o) => o.text())).toEqual(['甲公司 / A组', '甲公司 / B组'],
|
||||
expect(optionLabels(wrapper, '当前分组')).toEqual(['甲公司 / A组', '甲公司 / B组'],
|
||||
'跨公司组名由后端拼进 label,前端不解析公司字段')
|
||||
|
||||
await picker.setValue('12')
|
||||
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(12)
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12, page: 1 },
|
||||
@@ -876,13 +907,12 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||||
],
|
||||
})
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const picker = wrapper.get('[aria-label="当前分组"]')
|
||||
await picker.setValue('12')
|
||||
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect((picker.element as HTMLSelectElement).value).toBe('12', '重置不清当前分组(作用域语义,搬进筛选行也不变)')
|
||||
expect(selectByLabel(wrapper, '当前分组').props('modelValue')).toBe(12, '重置不清当前分组(作用域语义,搬进筛选行也不变)')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 },
|
||||
'重置后的重取仍带当前分组')
|
||||
wrapper.unmount()
|
||||
@@ -893,7 +923,7 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||||
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 })
|
||||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false)
|
||||
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有分组就没有可锁定的组名')
|
||||
expect(wrapper.find('[aria-label="筛选店铺分类"]').text()).toContain('全部分类', '分类筛选只剩「全部分类」')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')).toEqual(['全部分类'], '分类筛选只剩「全部分类」')
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')[1].text()).toBe('未分类')
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '没有分组就没有可写的分类面')
|
||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||
|
||||
Reference in New Issue
Block a user