feat(jd-database): v1.7 前端骨架——合并搜索+筛选弹层+回显条+自绘分页条+已选条

This commit is contained in:
2026-11-21 16:30:35 +08:00
parent 085c285446
commit 6685491fcb
6 changed files with 837 additions and 169 deletions
@@ -1,15 +1,20 @@
<script setup lang="ts">
/** 京东公共商品库(v1.6 蓝图 Phase 5 重写装配:侧栏+卡片网格+居中详情弹窗)。
* V203(2026-11-16 用户口径):分类按「数据权限分组」隔离——不同组看不到彼此的分类,
* 能看多组的人用筛选行「分组」下拉切换当前组(只有一组时锁定显示)。
* 能看多组的人用「分组」下拉切换当前组(只有一组时锁定显示)。
* 2026-11-17 用户口径:店铺分类弹窗下线,工具栏「归入分类」——勾选商品(翻页累计记忆)
* 后选目标分类归入或取消归属;建/改名/删分类收进侧栏「分类管理」对话框(带名称搜索)。
* v1.6 形态(2026-11-21 蓝图):类目筛选(京麦授权类目树+计数徽标+树外兜底)与店铺
* 分类平铺收进左侧栏 JdCategorySidebar;列表改卡片网格 JdProductCard(商城款式);
* 详情由侧滑抽屉改居中弹窗 JdProductDetailModal(Phase 4 壳,行级编辑/删除入口随
* 操作列下线收进弹窗顶部动作区)。旧表格/级联面板/详情抽屉三件随本 Phase 退役。
* 2026-11-21 用户口径「放到上面筛选框」红框整体上移:筛选行+批量按钮条离开主面板,
* 提到页面最顶(操作提示条正下方、通栏整行拉通);主面板只剩卡片网格与分页。 */
* v1.7(2026-11-21 对齐原型《商品数据商城》):
* ① 搜索合并——顶部单搜索框(商品编码 OR 标题,OR 语义在后端 SQL;旧两框退役),
* Enter 查询、× 清除即查;
* ② 筛选收弹层——「筛选」按钮下方浮层(价格区间+同步起止+重置/应用),分组下拉与
* 归属三档保留顶部(v1.6 用户口径的两件保留不动);
* ③ 筛选回显条——主面板顶部条件芯片(类目/分类/店铺/价格/同步区间+共 N 条+清除筛选,
* 清除保留分组作用域),无激活筛选不渲染;
* ④ 顶部分页——「第 X/Y 页 · 共 N 条」+首页/上一页/刷新/下一页/末页+档位
* 50/100/200/500/1000(与后端 MAX_PAGE_SIZE=1000 逐字同步),底部 OldPagination 从本页
* 撤下(组件本体不动,他页在用);
* ⑤ 底部已选条——主面板底部常驻「已选 N 件」悬浮条(能勾选的档才渲染)。 */
import { computed, onMounted, reactive, ref } from 'vue'
import {
batchAssignJdProductGroup,
@@ -23,7 +28,12 @@ import {
type JdProductCategoryOption,
type JdProductGroup,
} from './jd-product-api.ts'
import { createJdProductFilterState, JD_PRODUCT_PAGE_SIZE_OPTIONS } from './jd-product-filter.ts'
import {
createJdProductFilterState,
finitePriceOrNull,
jdProductFilterActive,
JD_PRODUCT_PAGE_SIZE_OPTIONS,
} from './jd-product-filter.ts'
import { JD_PRODUCT_DEFAULT_SIZE, type JdProductItem } from './jd-product-model.ts'
import JdCategorySidebar from './JdCategorySidebar.vue'
import JdProductCard from './JdProductCard.vue'
@@ -31,7 +41,6 @@ import JdProductDetailModal from './JdProductDetailModal.vue'
import JdProductEditDrawer from './JdProductEditDrawer.vue'
import JdBatchAssignDialog from './JdBatchAssignDialog.vue'
import JdCategoryManageDialog from './JdCategoryManageDialog.vue'
import OldPagination from '@/components/OldPagination.vue'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { openAdminConfirm } from '@/components/admin-confirm'
import { loadFailureMessage } from '@/components/load-failure-model'
@@ -46,7 +55,7 @@ import { orderedPair } from '@/utils/datetime'
* 由 scope 的每组 editable 决定(本组管理员/公司超管/平台超管),与本档无关。 */
const session = useAdminSessionStore()
const canWriteProducts = computed(() => isAdminRole(session.user?.role))
/** 分组筛选(同日用户口径「超管可以有分组筛选,管理员及以下则没有」):筛选行「分组」控件
/** 分组筛选(同日用户口径「超管可以有分组筛选,管理员及以下则没有」):顶部「分组」控件
* (下拉+单组锁定芯片)只对超管档(超级管理员/公司超级管理员)渲染;管理员及以下
* 不出现,其分类面固定落在作用域默认分组上。 */
const canFilterGroup = computed(() => session.isSuperAdmin || isCompanySuperAdminRole(session.user?.role))
@@ -56,7 +65,7 @@ const loadFailure = ref('')
const rows = ref<JdProductItem[]>([])
const total = ref(0)
const page = ref(1)
/** 每页条数默认 50(v1.6 Phase 1 新契约),档位 20/50/100 收敛在 filter 层单一出处。 */
/** 每页条数默认 50(v1.6 Phase 1 新契约),档位 50/100/200/500/1000(v1.7)收敛在 filter 层单一出处。 */
const pageSize = ref(JD_PRODUCT_DEFAULT_SIZE)
const filter = reactive(createJdProductFilterState())
/** 分类作用域(V203):可见分组 + 每组可写标记。失败静默回空作用域(分类面全空但商品照常)。 */
@@ -79,10 +88,13 @@ const batchEditVisible = ref(false)
/** 分类管理对话框(2026-11-17 第二刀:独立子菜单页并进来,建/改名/删+搜索)。 */
const manageVisible = ref(false)
/** 行级编辑抽屉(2026-11-15 用户口径「每一条数据后面 需要编辑或者删除」):入口随操作列
* 下线收进详情弹窗顶部动作区(Phase 4 Modal emit edit),删除走 removeOne 同一条链。 */
* 下线收进详情弹窗顶部动作区(Modal emit edit),删除走 removeOne 同一条链。 */
const editItem = ref<JdProductItem | null>(null)
const editVisible = ref(false)
/** 筛选弹层(v1.7 对齐原型):「筛选」按钮下方浮层,价格区间+同步起止+重置/应用。 */
const filterPopVisible = ref(false)
/** 当前分组的下拉项(带 editable)——分类写入口与侧栏新建分类行的可写档都读它。 */
const currentGroupOption = computed<JdCategoryGroupOption | null>(() =>
categoryScope.value.find((group) => group.id === ownerGroupId.value) || null)
@@ -104,6 +116,35 @@ const selectedGroupIdNum = computed(() => {
return Number.isFinite(id) && id > 0 ? id : null
})
/** 是否有任一激活筛选条件(回显条渲染判据;分组作用域不在判定里)。 */
const filterActive = computed(() => jdProductFilterActive(filter))
/** 回显条芯片(v1.7 对齐原型):类目/分类/店铺/价格区间/同步区间/归属档,各带人话前缀;
* 归属三档只回显偏离出厂默认(未分类)的档位——默认档不是激活筛选。 */
const activeFilterChips = computed(() => {
const chips: { key: string; label: string }[] = []
const keyword = (filter.keyword || '').trim()
if (keyword) chips.push({ key: 'keyword', label: `搜索:${keyword}` })
if ((filter.category || '').trim()) chips.push({ key: 'category', label: `类目:${filter.category}` })
const shopName = (filter.shopName || '').trim()
if (shopName) chips.push({ key: 'shop', label: `店铺:${shopName}` })
if ((filter.groupId || '').trim()) {
const group = groupOptions.value.find((option) => String(option.id) === filter.groupId)
chips.push({ key: 'group', label: `分类:${group?.name || filter.groupId}` })
}
if (filter.classified === 'classified') chips.push({ key: 'classified', label: '已分类' })
else if (filter.classified === '') chips.push({ key: 'classified', label: '全部分类状态' })
const minPrice = finitePriceOrNull(filter.minPrice)
const maxPrice = finitePriceOrNull(filter.maxPrice)
if (minPrice != null || maxPrice != null) {
chips.push({ key: 'price', label: `价格:${minPrice ?? ''} ~ ${maxPrice ?? ''}` })
}
if (filter.syncedFrom || filter.syncedTo) {
chips.push({ key: 'synced', label: `同步:${filter.syncedFrom || '…'} ~ ${filter.syncedTo || '…'}` })
}
return chips
})
/** 侧栏选类目:树内节点带完整路径(序列化按子树展开 IN 下发)、树外兜底名 path 空=
* 单名等值旧形状;null=「全部商品」清选重查。选中即查(回第一页)。 */
function onSelectCategory(value: { name: string; path: string[] } | null): void {
@@ -137,6 +178,35 @@ function clampJdSyncedRange(): void {
filter.syncedTo = e
}
function toggleFilterPopover(): void {
filterPopVisible.value = !filterPopVisible.value
}
/** 清除搜索词(× 即查):空词不重发(首屏没搜过就别白发一条)。 */
function clearKeyword(): void {
if (!filter.keyword) return
filter.keyword = ''
apply()
}
/** 弹层「应用」:价格倒挡先在门口挡住(后端同文案兜底),过了才关弹层查询。 */
function applyFromPopover(): void {
const minPrice = finitePriceOrNull(filter.minPrice)
const maxPrice = finitePriceOrNull(filter.maxPrice)
if (minPrice != null && maxPrice != null && minPrice > maxPrice) {
showAdminFeedback('价格区间最小值不能大于最大值', 'error')
return
}
filterPopVisible.value = false
apply()
}
/** 弹层「重置」:筛选面回出厂空态并查询(与回显条「清除筛选」同一条链,保留分组作用域)。 */
function resetFromPopover(): void {
filterPopVisible.value = false
reset()
}
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
/** 作用域 → 分组列表 → 该组分类:失败一律静默降级(分类只是筛选/归类面,不拦首屏行集)。 */
@@ -250,12 +320,14 @@ async function load(): Promise<void> {
const result = await fetchJdProductList({
page: page.value,
pageSize: pageSize.value,
productCode: filter.productCode,
titleKeyword: filter.titleKeyword,
keyword: filter.keyword,
category: filter.category,
categoryPath: filter.categoryPath,
shopName: filter.shopName,
groupId: filter.groupId,
classified: filter.classified,
minPrice: filter.minPrice,
maxPrice: filter.maxPrice,
ownerGroupId: ownerGroupId.value,
syncedFrom: filter.syncedFrom,
syncedTo: filter.syncedTo,
@@ -279,7 +351,9 @@ function apply(): void {
void load()
}
/** 重置:筛选面回出厂空态(类目/分类选中随 filter 回空=侧栏高亮自动清),回第一页重取。 */
/** 重置:筛选面回出厂空态(搜索词/类目/店铺/价格/日期随 filter 回空=侧栏高亮自动清,
* 归属三档回默认未分类档),回第一页重取;分组作用域(ownerGroupId)不在 filter 里,
* 天然保留(AC-4)。 */
function reset(): void {
Object.assign(filter, createJdProductFilterState())
page.value = 1
@@ -292,6 +366,15 @@ function changePage(next: number): void {
void load()
}
/** 顶部分页(v1.7 对齐原型):首/末页按钮复用 changePage 的边界检查(越界页码静默忽略)。 */
function goFirstPage(): void {
changePage(1)
}
function goLastPage(): void {
changePage(totalPages.value)
}
function changeSize(size: number) {
pageSize.value = size
page.value = 1
@@ -320,7 +403,7 @@ async function copyProductCode(row: JdProductItem): Promise<void> {
}
}
/** 详情弹窗顶部「编辑/删除」(Phase 4 emit):先关弹窗再走既有链,与旧操作列同源。 */
/** 详情弹窗顶部「编辑/删除」(Modal emit):先关弹窗再走既有链,与旧操作列同源。 */
function onDetailEdit(): void {
const item = detailItem.value
closeDetail()
@@ -422,18 +505,89 @@ onMounted(async () => {
<template>
<div class="jd-database-view">
<!-- 顶部通栏面板(2026-11-21 用户口径「放到上面筛选框」红框整体上移):筛选行+
批量按钮条离开右侧主面板,提到页面最顶(操作提示条正下方、通栏整行拉通)——
通栏宽度下字段不再折行,侧栏与卡片网格整排下移;主面板只剩网格与分页。 -->
<!-- 顶部通栏面板(2026-11-21 用户口径「放到上面筛选框」红框整体上移+同日 v1.7 对齐
原型):单搜索框+筛选弹层+分组下拉+归属三档住通栏整行;批量按钮条随筛选行
留在顶部通栏(红框上移口径不动)。主面板只剩回显条+卡片网格+分页条+已选条。 -->
<section class="panel-box jd-top-panel">
<div class="jd-filter-row">
<div class="form-group">
<label>商品编码</label>
<input v-model="filter.productCode" type="text" placeholder="输入商品编码" @keyup.enter="apply" />
<!-- 合并搜索(v1.7 对齐原型):一个框同时搜商品编码与标题(OR 语义在后端 SQL,
前端不拆词);Enter 查询;有词时出 × 清除按钮(清除即查)。 -->
<div class="jd-search-wrap">
<input
v-model="filter.keyword"
class="jd-search-input"
type="text"
placeholder="搜索商品编码或标题"
aria-label="搜索商品"
@keyup.enter="apply"
/>
<button
v-if="filter.keyword"
class="jd-search-clear"
type="button"
aria-label="清除搜索"
@click="clearKeyword"
>×</button>
</div>
<div class="form-group">
<label>标题关键字</label>
<input v-model="filter.titleKeyword" type="text" placeholder="输入标题关键字" @keyup.enter="apply" />
<!-- 筛选弹层(v1.7 对齐原型):低频条件(价格区间+同步起止)收进按钮下方浮层,
重置/应用在浮层底部;常驻的分组下拉与归属三档留在搜索行(v1.6 用户口径保留件)。 -->
<div class="jd-filter-anchor">
<button
class="btn btn-secondary"
type="button"
:class="{ 'jd-filter-open': filterPopVisible }"
@click="toggleFilterPopover"
>筛选</button>
<div v-if="filterPopVisible" class="jd-filter-popover">
<div class="jd-pop-row">
<label>价格区间</label>
<div class="jd-pop-fields">
<!-- 价格输入用 text+inputmode(不用 type=number):Vue 的 v-model 对
type=number 会 looseToNumber 把 state 写成数字,filter 契约(字符串
进、序列化层转 number)就断了;数字合法性由 finitePriceOrNull 在
序列化口收口,倒挡校验在「应用」门口。 -->
<input
v-model="filter.minPrice"
type="text"
inputmode="decimal"
placeholder="最低价"
aria-label="最低价格"
/>
<span class="jd-pop-sep">~</span>
<input
v-model="filter.maxPrice"
type="text"
inputmode="decimal"
placeholder="最高价"
aria-label="最高价格"
/>
</div>
</div>
<div class="jd-pop-row">
<label>同步日期</label>
<div class="jd-pop-fields">
<input
v-model="filter.syncedFrom"
type="date"
:max="filter.syncedTo"
aria-label="同步开始日期"
@change="clampJdSyncedRange"
/>
<span class="jd-pop-sep">~</span>
<input
v-model="filter.syncedTo"
type="date"
:min="filter.syncedFrom"
aria-label="同步结束日期"
@change="clampJdSyncedRange"
/>
</div>
</div>
<div class="jd-pop-actions">
<button class="btn btn-secondary" type="button" @click="resetFromPopover">重置</button>
<button class="btn" type="button" @click="applyFromPopover">应用</button>
</div>
</div>
</div>
<div v-if="canFilterGroup && categoryScope.length" class="form-group">
<label>分组</label>
@@ -454,18 +608,6 @@ onMounted(async () => {
</el-select>
<span v-else class="jd-group-locked" title="你的数据权限内只有这一个分组">{{ currentGroupName }}</span>
</div>
<div class="form-group">
<label>同步开始日期</label>
<input v-model="filter.syncedFrom" type="date" :max="filter.syncedTo" @change="clampJdSyncedRange" />
</div>
<div class="form-group">
<label>同步结束日期</label>
<input v-model="filter.syncedTo" type="date" :min="filter.syncedFrom" @change="clampJdSyncedRange" />
</div>
<div class="jd-filter-actions">
<button class="btn" type="button" @click="apply">查询</button>
<button class="btn btn-secondary" type="button" @click="reset">重置</button>
</div>
<!-- 归属三档快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」+同日收敛
「默认卡在未分类上就行」;2026-11-18 用户口径「加个全部选项」恢复全量档):
已分类=当前分组下有分类(V203 归属表,与侧栏分类选中同形);三档下拉、
@@ -541,6 +683,14 @@ onMounted(async () => {
<section class="panel-box jd-main-panel">
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<!-- 筛选回显条(v1.7 F5 对齐原型):有激活筛选才渲染;芯片按当前筛选态逐条回显,
「共 N 条」给行集规模,「清除筛选」回出厂空态(保留分组作用域,AC-4)。 -->
<div v-if="filterActive" class="jd-filter-chips">
<span v-for="chip in activeFilterChips" :key="chip.key" class="jd-chip">{{ chip.label }}</span>
<span class="jd-chip-total">共 {{ total }} 条</span>
<button class="jd-chip-clear" type="button" @click="reset">清除筛选</button>
</div>
<!-- 卡片网格(v1.6):商城款式;卡片整体点击=开详情弹窗,勾选/复制 @click.stop 防冒泡。 -->
<div class="jd-card-grid">
<template v-if="rows.length">
@@ -559,15 +709,36 @@ onMounted(async () => {
<div v-else class="jd-empty-tip">暂无京东商品数据</div>
</div>
<!-- 每页条数档位 20/50/100(v1.6 Phase 1 契约)随分页条下发。 -->
<OldPagination
:total="total"
:page="page"
:page-size="pageSize"
:sizes="[...JD_PRODUCT_PAGE_SIZE_OPTIONS]"
@change="changePage"
@size-change="changeSize"
/>
<!-- 顶部分页条(v1.7 F4 对齐原型):「第 X/Y 页 · 共 N 条」+首页/上一页/刷新/
下一页/末页+每页条数档位(50/100/200/500/1000,与后端上限逐字同步)。
本页底部 OldPagination 随 v1.7 撤下(组件本体不动,他页在用)。 -->
<div class="jd-page-bar">
<span class="jd-page-info">第 {{ page }} / {{ totalPages }} 页 · 共 {{ total }} 条</span>
<div class="jd-page-btns">
<button class="jd-page-btn" type="button" :disabled="page <= 1" @click="goFirstPage">首页</button>
<button class="jd-page-btn" type="button" :disabled="page <= 1" @click="changePage(page - 1)">上一页</button>
<button class="jd-page-btn" type="button" aria-label="刷新列表" @click="load">刷新</button>
<button class="jd-page-btn" type="button" :disabled="page >= totalPages" @click="changePage(page + 1)">下一页</button>
<button class="jd-page-btn" type="button" :disabled="page >= totalPages" @click="goLastPage">末页</button>
</div>
<el-select
class="page-size-select"
:model-value="pageSize"
aria-label="每页条数"
@change="changeSize"
>
<el-option
v-for="size in JD_PRODUCT_PAGE_SIZE_OPTIONS"
:key="size"
:value="size"
:label="`${size}条/页`"
/>
</el-select>
</div>
<!-- 底部已选条(v1.7 F7 骨架):常驻悬浮(不随勾选数显隐);只对有勾选面的档渲染
(普通员工没有勾选框,已选恒 0 无意义)。 -->
<div v-if="hasSelection" class="jd-select-bar">已选 {{ selectedCount }} 件</div>
</section>
</div>