feat(jd-database): v1.7 卡片交互+CSV 导出恢复+已下载角标+类目树增强
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
* 计数聚合走 jdCategoryCountTree(v1.6 Phase 1):节点徽标=自身名+子树叶和(与
|
* 计数聚合走 jdCategoryCountTree(v1.6 Phase 1):节点徽标=自身名+子树叶和(与
|
||||||
* 「点节点 → 子树展开 IN 过滤」的命中集合同源),树上对不上的历史行归「树外兜底」组
|
* 「点节点 → 子树展开 IN 过滤」的命中集合同源),树上对不上的历史行归「树外兜底」组
|
||||||
* (点兜底行=单名等值旧形状,path 空数组交给页面回落)。 */
|
* (点兜底行=单名等值旧形状,path 空数组交给页面回落)。 */
|
||||||
import { computed, ref, watch } from 'vue'
|
import { computed, nextTick, ref, watch } from 'vue'
|
||||||
import {
|
import {
|
||||||
jdCategoryCountTree,
|
jdCategoryCountTree,
|
||||||
type JdCategoryCountedNode,
|
type JdCategoryCountedNode,
|
||||||
@@ -70,12 +70,58 @@ const counted = computed(() => jdCategoryCountTree(props.categoryOptions ?? []))
|
|||||||
const totalCount = computed(() =>
|
const totalCount = computed(() =>
|
||||||
(props.categoryOptions ?? []).reduce((sum, row) => sum + (row.productCount || 0), 0))
|
(props.categoryOptions ?? []).reduce((sum, row) => sum + (row.productCount || 0), 0))
|
||||||
|
|
||||||
/** 展开态:按路径串('/' 连接)记,含树外兜底组头。一级默认展开(二级可见)。 */
|
/** 展开态:按路径串('/' 连接)记,含树外兜底组头。出厂(无记忆)一级默认展开(二级可见);
|
||||||
const expanded = ref<Set<string>>(new Set())
|
* v1.7 树增强:展开态持久化 localStorage `jd_db_cat_expand`(切页/重进不丢),损坏/不存在
|
||||||
|
* =按出厂态(宁可重展一级也不冒充用户记忆)。 */
|
||||||
|
const EXPAND_STORAGE_KEY = 'jd_db_cat_expand'
|
||||||
|
|
||||||
|
/** 读展开记忆:合法字符串数组才采信;返回「键集+是否有记忆」两个值——空数组 `[]` 是
|
||||||
|
* 用户主动「全部收起」的合法记忆,不得与「没存过」混为一谈(混了=全收起被重置成
|
||||||
|
* 一级展开,用户意图被吞)。坏形状/不可读回无记忆。 */
|
||||||
|
function loadExpandedKeys(): { keys: Set<string>; stored: boolean } {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(EXPAND_STORAGE_KEY)
|
||||||
|
if (raw === null) return { keys: new Set(), stored: false }
|
||||||
|
const parsed: unknown = JSON.parse(raw)
|
||||||
|
if (!Array.isArray(parsed)) return { keys: new Set(), stored: false }
|
||||||
|
return { keys: new Set(parsed.filter((value): value is string => typeof value === 'string')), stored: true }
|
||||||
|
} catch {
|
||||||
|
return { keys: new Set(), stored: false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialExpand = loadExpandedKeys()
|
||||||
|
const expanded = ref<Set<string>>(initialExpand.keys)
|
||||||
const expandKey = (path: string[]): string => path.join('/')
|
const expandKey = (path: string[]): string => path.join('/')
|
||||||
|
|
||||||
// 一级默认展开:init 时把每个一级的 key 放进集合。
|
function persistExpanded(): void {
|
||||||
for (const root of counted.value.roots) expanded.value.add(expandKey([root.name]))
|
try {
|
||||||
|
localStorage.setItem(EXPAND_STORAGE_KEY, JSON.stringify([...expanded.value]))
|
||||||
|
} catch {
|
||||||
|
// 存储不可写(隐私模式/配额满)=展开态只活在本会话,树功能不受影响。
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 是否有持久化记忆:有(哪怕空集=全收起)=尊重记忆(不再补一级展开);无=树根到达时
|
||||||
|
* 补一级默认展开。注意 setup 时树数据通常还没到(页面先 scope 后列表),「一级默认展开」
|
||||||
|
* 必须挂树根 watch 而不是 init 直接遍历(旧写法 roots 为空什么也没加=默认展开从未真正生效)。 */
|
||||||
|
let hasStoredExpand = initialExpand.stored
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => counted.value.roots,
|
||||||
|
(roots) => {
|
||||||
|
if (hasStoredExpand) return
|
||||||
|
const next = new Set(expanded.value)
|
||||||
|
for (const root of roots) next.add(expandKey([root.name]))
|
||||||
|
// 补过一次就置位:之后类目重取不再补默认(用户中途收起的一级行不被重取展开回去)。
|
||||||
|
hasStoredExpand = true
|
||||||
|
if (next.size !== expanded.value.size) {
|
||||||
|
expanded.value = next
|
||||||
|
persistExpanded()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
)
|
||||||
|
|
||||||
// ---------------- 商品目录树:扁平渲染(深度缩进 + 祖先全展开才可见) ----------------
|
// ---------------- 商品目录树:扁平渲染(深度缩进 + 祖先全展开才可见) ----------------
|
||||||
|
|
||||||
@@ -106,6 +152,32 @@ function toggleExpand(path: string[]): void {
|
|||||||
if (next.has(key)) next.delete(key)
|
if (next.has(key)) next.delete(key)
|
||||||
else next.add(key)
|
else next.add(key)
|
||||||
expanded.value = next
|
expanded.value = next
|
||||||
|
persistExpanded()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 全部展开(v1.7 树增强):把每个有子级的节点 path 全收进展开集(深树一次到底)。 */
|
||||||
|
function expandAll(): void {
|
||||||
|
const next = new Set<string>()
|
||||||
|
const walk = (nodes: JdCategoryCountedNode[], prefix: string[]): void => {
|
||||||
|
for (const node of nodes) {
|
||||||
|
const path = [...prefix, node.name]
|
||||||
|
if (node.children.length) {
|
||||||
|
next.add(expandKey(path))
|
||||||
|
walk(node.children, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
walk(counted.value.roots, [])
|
||||||
|
expanded.value = next
|
||||||
|
hasStoredExpand = true
|
||||||
|
persistExpanded()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 全部收起:清空展开集(一级也收,用户主动点了收起就是要全收)。 */
|
||||||
|
function collapseAll(): void {
|
||||||
|
expanded.value = new Set()
|
||||||
|
hasStoredExpand = true
|
||||||
|
persistExpanded()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 点树行=选中即筛;非末级行顺手展开(下钻感,与京麦列表筛选器同形;收起走箭头)。 */
|
/** 点树行=选中即筛;非末级行顺手展开(下钻感,与京麦列表筛选器同形;收起走箭头)。 */
|
||||||
@@ -116,7 +188,8 @@ function pickNode(node: FlatNode): void {
|
|||||||
emit('select-category', { name: node.node.name, path: node.path })
|
emit('select-category', { name: node.node.name, path: node.path })
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 外部选中态(重置/清选/页面回显):展开选中节点的全部祖先,让它可见。
|
/** 外部选中态(重置/清选/页面回显):展开选中节点的全部祖先,让它可见,并把选中行
|
||||||
|
* 滚进视口(v1.7 树增强;jsdom 无 scrollIntoView 自动跳过——测试不需要真滚)。
|
||||||
* immediate=页面带着已激活的类目筛选挂载侧栏时(如切换回本页),选中路径直接展开到位。 */
|
* immediate=页面带着已激活的类目筛选挂载侧栏时(如切换回本页),选中路径直接展开到位。 */
|
||||||
watch(
|
watch(
|
||||||
() => props.selectedCategory,
|
() => props.selectedCategory,
|
||||||
@@ -126,7 +199,16 @@ watch(
|
|||||||
for (let i = 1; i < selected.path.length; i++) {
|
for (let i = 1; i < selected.path.length; i++) {
|
||||||
next.add(expandKey(selected.path.slice(0, i)))
|
next.add(expandKey(selected.path.slice(0, i)))
|
||||||
}
|
}
|
||||||
expanded.value = next
|
if (next.size !== expanded.value.size) {
|
||||||
|
expanded.value = next
|
||||||
|
persistExpanded()
|
||||||
|
}
|
||||||
|
void nextTick(() => {
|
||||||
|
const picked = document.querySelector('.jd-side-tree .jd-side-row.selected')
|
||||||
|
if (picked && typeof picked.scrollIntoView === 'function') {
|
||||||
|
picked.scrollIntoView({ block: 'nearest' })
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
{ immediate: true },
|
{ immediate: true },
|
||||||
)
|
)
|
||||||
@@ -280,6 +362,11 @@ function cancelShopRename(): void {
|
|||||||
<span class="jd-side-name">全部商品</span>
|
<span class="jd-side-name">全部商品</span>
|
||||||
<span class="jd-side-count">{{ totalCount }}</span>
|
<span class="jd-side-count">{{ totalCount }}</span>
|
||||||
</button>
|
</button>
|
||||||
|
<!-- 全部展开/收起(v1.7 树增强,对齐原型树控件):深树一次到底/一键收干净。 -->
|
||||||
|
<div v-if="flatTree.length" class="jd-side-tree-ops">
|
||||||
|
<button type="button" aria-label="展开全部类目" @click="expandAll">全部展开</button>
|
||||||
|
<button type="button" aria-label="收起全部类目" @click="collapseAll">全部收起</button>
|
||||||
|
</div>
|
||||||
<div class="jd-side-tree">
|
<div class="jd-side-tree">
|
||||||
<button
|
<button
|
||||||
v-for="flat in flatTree"
|
v-for="flat in flatTree"
|
||||||
@@ -589,6 +676,28 @@ function cancelShopRename(): void {
|
|||||||
background: #d9ecff;
|
background: #d9ecff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 树顶展开/收起操作行(v1.7 树增强):弱化小按钮,不与树行抢视觉。 */
|
||||||
|
.jd-side-tree-ops {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 0 4px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jd-side-tree-ops button {
|
||||||
|
padding: 2px 8px;
|
||||||
|
border: 1px solid #dcdfe6;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #fff;
|
||||||
|
color: #909399;
|
||||||
|
font-size: 12px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jd-side-tree-ops button:hover {
|
||||||
|
color: #409eff;
|
||||||
|
border-color: #c6e2ff;
|
||||||
|
}
|
||||||
|
|
||||||
.jd-side-extra {
|
.jd-side-extra {
|
||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
border-top: 1px dashed #e4e7ed;
|
border-top: 1px dashed #e4e7ed;
|
||||||
|
|||||||
@@ -14,13 +14,18 @@
|
|||||||
* ④ 顶部分页——「第 X/Y 页 · 共 N 条」+首页/上一页/刷新/下一页/末页+档位
|
* ④ 顶部分页——「第 X/Y 页 · 共 N 条」+首页/上一页/刷新/下一页/末页+档位
|
||||||
* 50/100/200/500/1000(与后端 MAX_PAGE_SIZE=1000 逐字同步),底部 OldPagination 从本页
|
* 50/100/200/500/1000(与后端 MAX_PAGE_SIZE=1000 逐字同步),底部 OldPagination 从本页
|
||||||
* 撤下(组件本体不动,他页在用);
|
* 撤下(组件本体不动,他页在用);
|
||||||
* ⑤ 底部已选条——主面板底部常驻「已选 N 件」悬浮条(能勾选的档才渲染)。 */
|
* ⑤ 底部已选条——主面板底部常驻「已选 N 件」悬浮条(能勾选的档才渲染);
|
||||||
|
* ⑥ CSV 导出+已下载角标(v1.7 Phase 4 对齐原型):工具栏「导出 CSV」(勾选≥1 可用,
|
||||||
|
* blob 下载;2026-11-15「导出也不用」口径随 v1.7 对齐原型拍板解除),导出成功的
|
||||||
|
* 商品记 downloadedIds(localStorage `jd_db_downloaded_ids`,并集合并写——铁律 30:
|
||||||
|
* 缺件不抹前值),卡片图片右上角出「已下载」角标。 */
|
||||||
import { computed, onMounted, reactive, ref } from 'vue'
|
import { computed, onMounted, reactive, ref } from 'vue'
|
||||||
import {
|
import {
|
||||||
batchAssignJdProductGroup,
|
batchAssignJdProductGroup,
|
||||||
createJdProductGroup,
|
createJdProductGroup,
|
||||||
deleteJdProductGroup,
|
deleteJdProductGroup,
|
||||||
deleteJdProducts,
|
deleteJdProducts,
|
||||||
|
exportJdProductsCsv,
|
||||||
fetchJdCategoryScope,
|
fetchJdCategoryScope,
|
||||||
fetchJdProductCategories,
|
fetchJdProductCategories,
|
||||||
fetchJdProductGroups,
|
fetchJdProductGroups,
|
||||||
@@ -600,6 +605,66 @@ async function removeMany(ids: number[], message: string): Promise<void> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------- CSV 导出+已下载记忆(v1.7 Phase 4 对齐原型) ----------------
|
||||||
|
|
||||||
|
/** 已下载记忆的 localStorage 键与上限。上限=防无限增长(每次导出 ≤1000 id,
|
||||||
|
* 5000 条足够近期记录可查;超出丢最早写入的一批,先到先得保留)。 */
|
||||||
|
const DOWNLOADED_STORAGE_KEY = 'jd_db_downloaded_ids'
|
||||||
|
const DOWNLOADED_MAX = 5000
|
||||||
|
|
||||||
|
/** 启动时从 localStorage 恢复已下载 id 集:形状坏(非数组/含非数)整份丢弃=
|
||||||
|
* 当作没下载过(宁可丢角标也不冒充「已下载过」),存储不可读同样回空。 */
|
||||||
|
function readDownloadedIds(): Set<number> {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem(DOWNLOADED_STORAGE_KEY)
|
||||||
|
if (!raw) return new Set()
|
||||||
|
const parsed: unknown = JSON.parse(raw)
|
||||||
|
if (!Array.isArray(parsed)) return new Set()
|
||||||
|
return new Set(parsed.filter((value): value is number => typeof value === 'number' && Number.isFinite(value)))
|
||||||
|
} catch {
|
||||||
|
return new Set()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 已下载 id 集(导出成功的商品):卡片角标读它,导出成功后并集合并写回(铁律 30——
|
||||||
|
* 不整份覆写,之前的记录不能被这一批抹掉)。 */
|
||||||
|
const downloadedIds = ref<Set<number>>(readDownloadedIds())
|
||||||
|
|
||||||
|
function persistDownloadedIds(): void {
|
||||||
|
try {
|
||||||
|
// 上限保护:超出丢最早进集的 id(Set 保插入序)。
|
||||||
|
const list = [...downloadedIds.value]
|
||||||
|
const trimmed = list.length > DOWNLOADED_MAX ? list.slice(list.length - DOWNLOADED_MAX) : list
|
||||||
|
localStorage.setItem(DOWNLOADED_STORAGE_KEY, JSON.stringify(trimmed))
|
||||||
|
} catch {
|
||||||
|
// 存储不可写(隐私模式/配额满)=角标只活在本会话,导出本身不受影响。
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 导出进行中(按钮防连点;与删除/归类互斥灯独立——导出是读行为,不互斥写动作)。 */
|
||||||
|
const exportingCsv = ref(false)
|
||||||
|
|
||||||
|
/** 工具栏「导出 CSV」:按累计勾选 id 导出(跨页的行也在内,后端上限 1000 同口径)。
|
||||||
|
* 成功后把本批 id 并进 downloadedIds(Set 并集=合并写,不抹之前的记录)并持久化。 */
|
||||||
|
async function onExportCsv(): Promise<void> {
|
||||||
|
const ids = [...selectedIds.value]
|
||||||
|
if (!ids.length || exportingCsv.value) return
|
||||||
|
exportingCsv.value = true
|
||||||
|
try {
|
||||||
|
await exportJdProductsCsv(ids)
|
||||||
|
const next = new Set(downloadedIds.value)
|
||||||
|
for (const id of ids) next.add(id)
|
||||||
|
downloadedIds.value = next
|
||||||
|
persistDownloadedIds()
|
||||||
|
showAdminFeedback(`已导出 ${ids.length} 个商品的 CSV`, 'success')
|
||||||
|
} catch (error) {
|
||||||
|
const text = error instanceof Error && error.message ? error.message : '导出失败,请稍后重试'
|
||||||
|
showAdminFeedback(text, 'error')
|
||||||
|
} finally {
|
||||||
|
exportingCsv.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 先解析作用域再取列表:首屏的 owner_group_id 必须与分类侧栏同一个组(铁律 30 同形——
|
// 先解析作用域再取列表:首屏的 owner_group_id 必须与分类侧栏同一个组(铁律 30 同形——
|
||||||
// 不要先发一条不带 owner_group_id 的列表请求再补,两次请求会落在不同默认组上)。
|
// 不要先发一条不带 owner_group_id 的列表请求再补,两次请求会落在不同默认组上)。
|
||||||
@@ -741,6 +806,16 @@ onMounted(async () => {
|
|||||||
<div v-if="hasSelection" class="jd-toolbar">
|
<div v-if="hasSelection" class="jd-toolbar">
|
||||||
<button class="btn btn-secondary" type="button" :disabled="!rows.length" @click="selectPage">全选本页</button>
|
<button class="btn btn-secondary" type="button" :disabled="!rows.length" @click="selectPage">全选本页</button>
|
||||||
<button class="btn btn-secondary" type="button" :disabled="!selectedCount" @click="unselectPage">取消本页</button>
|
<button class="btn btn-secondary" type="button" :disabled="!selectedCount" @click="unselectPage">取消本页</button>
|
||||||
|
<!-- 导出 CSV(v1.7 对齐原型,勾选≥1 可用):读行为,不要求行写权限(在勾选档内
|
||||||
|
即可);成功后本批 id 进已下载记忆,卡片出「已下载」角标。 -->
|
||||||
|
<button
|
||||||
|
class="btn btn-secondary"
|
||||||
|
type="button"
|
||||||
|
:disabled="exportingCsv || !selectedCount"
|
||||||
|
@click="onExportCsv"
|
||||||
|
>
|
||||||
|
{{ exportingCsv ? '导出中...' : `导出 CSV(${selectedCount})` }}
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="canWriteProducts"
|
v-if="canWriteProducts"
|
||||||
class="btn btn-danger jd-delete-btn"
|
class="btn btn-danger jd-delete-btn"
|
||||||
@@ -814,6 +889,7 @@ onMounted(async () => {
|
|||||||
:item="row"
|
:item="row"
|
||||||
:selected="selectedIds.has(row.id)"
|
:selected="selectedIds.has(row.id)"
|
||||||
:selectable="hasSelection"
|
:selectable="hasSelection"
|
||||||
|
:downloaded="downloadedIds.has(row.id)"
|
||||||
@toggle-select="(checked: boolean) => toggleSelect(row, checked)"
|
@toggle-select="(checked: boolean) => toggleSelect(row, checked)"
|
||||||
@open="openDetail(row)"
|
@open="openDetail(row)"
|
||||||
@copy="copyProductCode(row)"
|
@copy="copyProductCode(row)"
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
/** 京东商品卡片(v1.6 蓝图 Phase 3,additive——页面接线随 Phase 5):
|
/** 京东商品卡片(v1.6 蓝图 Phase 3;v1.7 Phase 4 对齐原型交互):
|
||||||
* 主图(无图占位)/店铺徽标/标题/价格区间/商品编码+复制/采集日期/勾选框,
|
* 主图(无图占位)/店铺徽标/标题/价格区间/商品编码+复制/采集日期/勾选框,
|
||||||
* 字段映射与现表格「商品信息」列逐字段同源(价格走 jdPriceRange、日期走 formatDateTime)。
|
* 字段映射与现表格「商品信息」列逐字段同源(价格走 jdPriceRange、日期走 formatDateTime)。
|
||||||
*
|
*
|
||||||
* 纯展示组件:入参=item+选中态+可勾选档;出事件=切换勾选、打开详情、复制编码。
|
* v1.7 交互增强(F7/F1):点图片区=切换勾选(可勾选档;不可勾选档点图照常开详情)、
|
||||||
* 卡片整体点击=开详情;勾选与复制 @click.stop 防冒泡(与现表格行 @click.stop 同形)。
|
* 图片 hover 出「点击选择/点击取消」提示胶囊、右上角「已下载」角标(CSV 导出成功后
|
||||||
* healthScore 徽标随图渲染(现表格同款「信息分」),null 不渲染。 */
|
* 页面记 downloadedIds,徽标与信息分同槽竖排堆叠)。
|
||||||
|
*
|
||||||
|
* 纯展示组件:入参=item+选中态+可勾选档+已下载态;出事件=切换勾选、打开详情、
|
||||||
|
* 复制编码。卡片整体点击=开详情;勾选与复制 @click.stop 防冒泡(与现表格行
|
||||||
|
* @click.stop 同形)。healthScore 徽标随图渲染(现表格同款「信息分」),null 不渲染。 */
|
||||||
import { formatDateTime } from '@/utils/datetime'
|
import { formatDateTime } from '@/utils/datetime'
|
||||||
import { jdPriceRange, type JdProductItem } from './jd-product-model.ts'
|
import { jdPriceRange, type JdProductItem } from './jd-product-model.ts'
|
||||||
|
|
||||||
@@ -16,10 +20,12 @@ const props = defineProps<{
|
|||||||
selected?: boolean
|
selected?: boolean
|
||||||
/** 可勾选档:管理员级/本组可写分类账号才渲染勾选框(页面按 canWriteProducts∨canManageCategories 投影)。 */
|
/** 可勾选档:管理员级/本组可写分类账号才渲染勾选框(页面按 canWriteProducts∨canManageCategories 投影)。 */
|
||||||
selectable?: boolean
|
selectable?: boolean
|
||||||
|
/** 已下载态(v1.7):本商品 CSV 导出过(页面 downloadedIds 记忆),图片右上角出角标。 */
|
||||||
|
downloaded?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
/** 勾选切换(checked 来自 checkbox 原生 change)。 */
|
/** 勾选切换(checked 来自 checkbox 原生 change 或点图片区)。 */
|
||||||
(event: 'toggle-select', checked: boolean): void
|
(event: 'toggle-select', checked: boolean): void
|
||||||
/** 打开详情(卡片整体点击;详情弹窗/抽屉由页面渲染)。 */
|
/** 打开详情(卡片整体点击;详情弹窗/抽屉由页面渲染)。 */
|
||||||
(event: 'open'): void
|
(event: 'open'): void
|
||||||
@@ -28,6 +34,14 @@ const emit = defineEmits<{
|
|||||||
}>()
|
}>()
|
||||||
|
|
||||||
const priceText = (): string => jdPriceRange(props.item) || '-'
|
const priceText = (): string => jdPriceRange(props.item) || '-'
|
||||||
|
|
||||||
|
/** 点图片区(v1.7 F7):可勾选档=切换勾选并阻止冒泡(点图不得误开详情);
|
||||||
|
* 不可勾选档不拦不停,click 冒泡到卡片整体=照常开详情。 */
|
||||||
|
function onFigureClick(event: MouseEvent): void {
|
||||||
|
if (!props.selectable) return
|
||||||
|
event.stopPropagation()
|
||||||
|
emit('toggle-select', !props.selected)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -40,10 +54,20 @@ const priceText = (): string => jdPriceRange(props.item) || '-'
|
|||||||
@change="emit('toggle-select', ($event.target as HTMLInputElement).checked)"
|
@change="emit('toggle-select', ($event.target as HTMLInputElement).checked)"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
<div class="jd-card-figure">
|
<div
|
||||||
|
class="jd-card-figure"
|
||||||
|
:class="{ 'jd-card-figure-pick': props.selectable }"
|
||||||
|
@click="onFigureClick"
|
||||||
|
>
|
||||||
<img v-if="props.item.mainImageUrl" class="jd-card-thumb" :src="props.item.mainImageUrl" alt="" loading="lazy" />
|
<img v-if="props.item.mainImageUrl" class="jd-card-thumb" :src="props.item.mainImageUrl" alt="" loading="lazy" />
|
||||||
<span v-else class="jd-card-thumb jd-card-thumb-empty">无图</span>
|
<span v-else class="jd-card-thumb jd-card-thumb-empty">无图</span>
|
||||||
<span v-if="props.item.healthScore !== null" class="jd-card-health">信息分 {{ props.item.healthScore }}</span>
|
<!-- 右上角徽标竖排:信息分(随图)+已下载角标(v1.7 导出记忆)。 -->
|
||||||
|
<span class="jd-card-badges">
|
||||||
|
<span v-if="props.item.healthScore !== null" class="jd-card-health">信息分 {{ props.item.healthScore }}</span>
|
||||||
|
<span v-if="props.downloaded" class="jd-card-downloaded">已下载</span>
|
||||||
|
</span>
|
||||||
|
<!-- hover 提示胶囊(v1.7):可勾选档才出,随选中态换文案。 -->
|
||||||
|
<span v-if="props.selectable" class="jd-card-hover-tip">{{ props.selected ? '点击取消' : '点击选择' }}</span>
|
||||||
<span v-if="props.item.shopName" class="jd-card-shop">{{ props.item.shopName }}</span>
|
<span v-if="props.item.shopName" class="jd-card-shop">{{ props.item.shopName }}</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="jd-card-body">
|
<div class="jd-card-body">
|
||||||
@@ -108,6 +132,11 @@ const priceText = (): string => jdPriceRange(props.item) || '-'
|
|||||||
background: #f5f7fa;
|
background: #f5f7fa;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 可勾选档的图片区才是「点图切换勾选」热区;不可勾选档不加该类(点图冒泡开详情)。 */
|
||||||
|
.jd-card-figure.jd-card-figure-pick {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.jd-card-thumb {
|
.jd-card-thumb {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -123,10 +152,19 @@ const priceText = (): string => jdPriceRange(props.item) || '-'
|
|||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.jd-card-health {
|
/* 右上角徽标竖排容器:信息分+已下载角标同槽堆叠(原信息分单徽标的 absolute 上移到容器)。 */
|
||||||
|
.jd-card-badges {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 8px;
|
top: 8px;
|
||||||
right: 8px;
|
right: 8px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 4px;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jd-card-health {
|
||||||
background: rgba(255, 255, 255, 0.92);
|
background: rgba(255, 255, 255, 0.92);
|
||||||
color: #e6a23c;
|
color: #e6a23c;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@@ -134,6 +172,34 @@ const priceText = (): string => jdPriceRange(props.item) || '-'
|
|||||||
padding: 1px 8px;
|
padding: 1px 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.jd-card-downloaded {
|
||||||
|
background: rgba(103, 194, 58, 0.94);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 1px 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* hover 提示胶囊:默认透明,图片区 hover 浮出(遮罩感=胶囊带半透明底)。 */
|
||||||
|
.jd-card-hover-tip {
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
padding: 4px 12px;
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgba(48, 49, 51, 0.66);
|
||||||
|
color: #fff;
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity 0.15s;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jd-card-figure-pick:hover .jd-card-hover-tip {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.jd-card-shop {
|
.jd-card-shop {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
|
|||||||
@@ -64,7 +64,8 @@ function rowByText(scope: VueWrapper<Element>, text: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// 纯展示组件无副作用;占位保持与页面 mount 测试同构。
|
// v1.7 起展开态持久化 localStorage:用例间清掉防串台(出厂态=无记忆)。
|
||||||
|
localStorage.removeItem('jd_db_cat_expand')
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('商品目录 Tab(京麦授权类目树+计数徽标)', () => {
|
describe('商品目录 Tab(京麦授权类目树+计数徽标)', () => {
|
||||||
@@ -137,6 +138,54 @@ describe('商品目录 Tab(京麦授权类目树+计数徽标)', () => {
|
|||||||
expect(wrapper.emitted('select-category')).toEqual([[null]], '点全部商品=清选')
|
expect(wrapper.emitted('select-category')).toEqual([[null]], '点全部商品=清选')
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('全部展开/收起(v1.7 树增强):收起后二级行隐藏、展开后末级行直接可见', async () => {
|
||||||
|
const wrapper = mountSidebar()
|
||||||
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
|
await catalog.get('[aria-label="收起全部类目"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('女装'))).toBe(false,
|
||||||
|
'全部收起=一级也收(用户点了就是要收干净)')
|
||||||
|
|
||||||
|
await catalog.get('[aria-label="展开全部类目"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(true,
|
||||||
|
'全部展开=末级行直接可见(一次到底)')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('展开态持久化:切换写入 localStorage `jd_db_cat_expand`;全收起存的是空数组(不是抹掉键)', async () => {
|
||||||
|
const wrapper = mountSidebar()
|
||||||
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
|
// 出厂态(一级默认展开)在树根到达时补齐并落盘。
|
||||||
|
const stored1 = JSON.parse(localStorage.getItem('jd_db_cat_expand') || 'null') as string[]
|
||||||
|
expect(Array.isArray(stored1)).toBe(true)
|
||||||
|
expect(stored1.length).toBeGreaterThan(0, '出厂一级展开态被记住')
|
||||||
|
|
||||||
|
await catalog.get('[aria-label="收起全部类目"]').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
expect(JSON.parse(localStorage.getItem('jd_db_cat_expand') || '"bad"')).toEqual([],
|
||||||
|
'全收起=空数组记忆(下次挂载不再补一级展开)')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('挂载读记忆:预置空数组记忆=出厂不补一级展开(用户上次全收起的意图不被吞)', () => {
|
||||||
|
localStorage.setItem('jd_db_cat_expand', '[]')
|
||||||
|
const wrapper = mountSidebar()
|
||||||
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
|
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('女装'))).toBe(false,
|
||||||
|
'有记忆(哪怕空)就尊重记忆,不再补一级默认展开')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('挂载读记忆:预置展开记忆=深路径直接展开到位(切页/重进不丢)', () => {
|
||||||
|
localStorage.setItem('jd_db_cat_expand', JSON.stringify(['运动户外', '运动户外/舞蹈体操鞋服/装备']))
|
||||||
|
const wrapper = mountSidebar()
|
||||||
|
const catalog = wrapper.get('.jd-side-catalog')
|
||||||
|
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(true,
|
||||||
|
'记忆里的展开键(含多级路径串)直接生效')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('树外兜底组(树上对不上的历史行,单名等值出口)', () => {
|
describe('树外兜底组(树上对不上的历史行,单名等值出口)', () => {
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ const jdApi = vi.hoisted(() => ({
|
|||||||
deleteJdProductGroup: vi.fn(),
|
deleteJdProductGroup: vi.fn(),
|
||||||
updateJdProduct: vi.fn(),
|
updateJdProduct: vi.fn(),
|
||||||
batchAssignJdProductGroup: vi.fn(),
|
batchAssignJdProductGroup: vi.fn(),
|
||||||
|
// v1.7 CSV 导出(Phase 4 对齐原型):工具栏导出按钮走它(blob 下载在 api 层,测试 mock 掉)。
|
||||||
|
exportJdProductsCsv: vi.fn(),
|
||||||
// v1.7 店铺名单(V214):侧栏名单交互与添加店铺弹窗的 API 面。
|
// v1.7 店铺名单(V214):侧栏名单交互与添加店铺弹窗的 API 面。
|
||||||
removeJdGroupShop: vi.fn(),
|
removeJdGroupShop: vi.fn(),
|
||||||
renameJdGroupShop: vi.fn(),
|
renameJdGroupShop: vi.fn(),
|
||||||
@@ -135,6 +137,9 @@ beforeEach(() => {
|
|||||||
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
|
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
|
||||||
jdApi.fetchJdAvailableShops.mockResolvedValue([])
|
jdApi.fetchJdAvailableShops.mockResolvedValue([])
|
||||||
jdApi.addJdGroupShops.mockResolvedValue(0)
|
jdApi.addJdGroupShops.mockResolvedValue(0)
|
||||||
|
// CSV 导出(v1.7)默认空回执:只有导出用例显式变形。
|
||||||
|
jdApi.exportJdProductsCsv.mockResolvedValue(undefined)
|
||||||
|
localStorage.removeItem('jd_db_downloaded_ids')
|
||||||
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
|
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
|
||||||
confirmMock.mockResolvedValue(true)
|
confirmMock.mockResolvedValue(true)
|
||||||
})
|
})
|
||||||
@@ -996,11 +1001,44 @@ describe('筛选与分页(v1.7:合并搜索+筛选弹层;AC-2/AC-4)',
|
|||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('导出按钮已下线:筛选行不再出现「导出」(2026-11-15 客户口径「导出也不用」)', async () => {
|
it('CSV 导出(v1.7 Phase 4 恢复,对齐原型):勾选后按钮可用并按累计 id 提交;成功出角标并入已下载记忆', async () => {
|
||||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 50 })
|
||||||
const btn = wrapper.findAll('button').find((b) => b.text() === '导出')
|
// 勾选前置灰(勾选 0 不给导出)。
|
||||||
expect(btn, '导出按钮必须已从前端移除').toBeUndefined()
|
const exportBtn = toolbarBtn(wrapper, '导出 CSV(0)')
|
||||||
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1, '下线导出不影响列表首屏')
|
expect(exportBtn.attributes('disabled')).toBeDefined()
|
||||||
|
|
||||||
|
// 勾选两张(跨页累计集的形状由既有用例管,这里只验导出链)。
|
||||||
|
await cardBoxes(wrapper)[0]!.setValue(true)
|
||||||
|
await cardBoxes(wrapper)[1]!.setValue(true)
|
||||||
|
await flushPromises()
|
||||||
|
const armed = toolbarBtn(wrapper, '导出 CSV(2)')
|
||||||
|
expect(armed.attributes('disabled')).toBeUndefined()
|
||||||
|
await armed.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.exportJdProductsCsv).toHaveBeenCalledTimes(1)
|
||||||
|
expect(jdApi.exportJdProductsCsv).toHaveBeenCalledWith([1, 2])
|
||||||
|
expect(document.body.textContent).toContain('已导出 2 个商品的 CSV')
|
||||||
|
|
||||||
|
// 成功后本批 id 进已下载记忆:卡片出「已下载」角标+localStorage 持久化。
|
||||||
|
expect(wrapper.findAll('.jd-card-downloaded')).toHaveLength(2, '导出成功的卡片出已下载角标')
|
||||||
|
const stored = JSON.parse(localStorage.getItem('jd_db_downloaded_ids') || '[]')
|
||||||
|
expect([...stored].sort()).toEqual([1, 2])
|
||||||
|
|
||||||
|
// 合并写(铁律 30):再导出另一行,之前的记录不被抹掉。
|
||||||
|
await cardBoxes(wrapper)[0]!.setValue(false)
|
||||||
|
await cardBoxes(wrapper)[1]!.setValue(false)
|
||||||
|
jdApi.fetchJdProductList.mockResolvedValue({ items: [item(3)], total: 3, page: 1, pageSize: 50 })
|
||||||
|
await wrapper.findAll('button').find((b) => b.text() === '刷新')!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await flushPromises()
|
||||||
|
await cardBoxes(wrapper)[0]!.setValue(true)
|
||||||
|
await toolbarBtn(wrapper, '导出 CSV(1)').trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.exportJdProductsCsv).toHaveBeenLastCalledWith([3])
|
||||||
|
const storedAfter = JSON.parse(localStorage.getItem('jd_db_downloaded_ids') || '[]')
|
||||||
|
expect([...storedAfter].sort()).toEqual([1, 2, 3], '并集合并写:本批不抹之前的记录')
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -112,3 +112,49 @@ describe('交互事件(防冒泡是行为红线)', () => {
|
|||||||
picked.unmount()
|
picked.unmount()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('v1.7 交互(点图切换勾选+hover 提示+已下载角标)', () => {
|
||||||
|
it('可勾选档点图片区=切换勾选且不冒泡开详情;未选发 true、已选发 false', async () => {
|
||||||
|
const wrapper = mount(JdProductCard, { props: { item: item(), selected: false, selectable: true } })
|
||||||
|
await wrapper.get('.jd-card-figure').trigger('click')
|
||||||
|
expect(wrapper.emitted('toggle-select')).toEqual([[true]], '未选点图=选中')
|
||||||
|
expect(wrapper.emitted('open'), '点图防冒泡:不得误开详情').toBeFalsy()
|
||||||
|
|
||||||
|
const picked = mount(JdProductCard, { props: { item: item(), selected: true, selectable: true } })
|
||||||
|
await picked.get('.jd-card-figure').trigger('click')
|
||||||
|
expect(picked.emitted('toggle-select')).toEqual([[false]], '已选点图=取消')
|
||||||
|
picked.unmount()
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('不可勾选档点图片区=冒泡到卡片整体开详情(点图不得吞掉详情入口)', async () => {
|
||||||
|
const wrapper = mount(JdProductCard, { props: { item: item() } })
|
||||||
|
await wrapper.get('.jd-card-figure').trigger('click')
|
||||||
|
expect(wrapper.emitted('open')).toHaveLength(1, '普通档点图照常开详情')
|
||||||
|
expect(wrapper.emitted('toggle-select')).toBeFalsy()
|
||||||
|
expect(wrapper.find('.jd-card-hover-tip').exists()).toBe(false, '不可勾选档不出提示胶囊')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('可勾选档出 hover 提示胶囊,文案随选中态换(未选「点击选择」/已选「点击取消」)', () => {
|
||||||
|
const fresh = mount(JdProductCard, { props: { item: item(), selected: false, selectable: true } })
|
||||||
|
expect(fresh.get('.jd-card-hover-tip').text()).toBe('点击选择')
|
||||||
|
fresh.unmount()
|
||||||
|
|
||||||
|
const picked = mount(JdProductCard, { props: { item: item(), selected: true, selectable: true } })
|
||||||
|
expect(picked.get('.jd-card-hover-tip').text()).toBe('点击取消')
|
||||||
|
picked.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('已下载角标(v1.7):downloaded=true 右上角出「已下载」,与信息分徽标同槽堆叠;false 不出', () => {
|
||||||
|
const plain = mount(JdProductCard, { props: { item: item(), downloaded: false } })
|
||||||
|
expect(plain.find('.jd-card-downloaded').exists()).toBe(false)
|
||||||
|
plain.unmount()
|
||||||
|
|
||||||
|
const done = mount(JdProductCard, { props: { item: item({ healthScore: 81 }), downloaded: true } })
|
||||||
|
expect(done.get('.jd-card-downloaded').text()).toBe('已下载')
|
||||||
|
expect(done.get('.jd-card-health').text()).toBe('信息分 81', '两个徽标共存(竖排堆叠)')
|
||||||
|
expect(done.get('.jd-card-badges').text()).toContain('信息分 81')
|
||||||
|
done.unmount()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user