Compare commits

78 Commits

Author SHA1 Message Date
huangzd1997 79b6f76654 fix(jd-database): 亚马逊侧分组下拉按平台归属过滤——京东档组不再漏进亚马逊侧(2026-11-22 用户口径「京东创建的分组就归属京东 下拉就只能显示京东分组管理的 亚马逊的也是同理」)
- shop-manage-api.ts::fetchShopManageGroups / dedupe-total-api.ts::fetchDedupeTotalGroups 恒带 platform=amazon(company_id 条件透传不变,后端 listGroups 本就支持该参数,零后端改动)——查询ASIN/跟价/去重/外观专利清理 4 个亚马逊域页面的分组下拉此前会把京东-团队/测试1111 等 jd 档组漏进来
- 京东侧无需改动:三条建组路径(分组管理页按平台 tab、京东分类弹窗直建恒 jd、后端缺省 amazon)打档正确,JdCategoryScopeService.retainJdPlatformGroups 平台闸已在线上(本轮云助手只读探针实证:测试1111=公司4阿华66 11-18 京东档建的合法工作组;admin 平台超管看所有、公司超管看公司下所有=现行口径,用户拍板维持)
- 测试:新增 tests/group-dropdown-platform-scope.test.ts(恒 amazon+company_id 透传不丢+分组管理页仍跟平台 tab 反向钉);company-tab-wiring.test.ts 精确行钉同步;source-pin-ledger.json 重生成(+1 文件/+2 例/+2 钉,delta 仅本窗)
- 验证:vue-tsc rc=0;后管全量 node --test 1959/1959 绿;fast 闸后管面 9 格全绿(分 8.8,账本 2026-11-22T16:1x);客户端/用户端红格为另窗在飞件非本笔
2026-11-22 16:19:43 +08:00
huangzd1997 9ce63ba351 chore(admin-vue): 逐文件台账基线回写——清两笔已提交欠账(随 66087460 一屏装配窗发版清账):①jd-product-group.test.ts 用例 8→10=64e426a9 归属按分类查询加用例未回写(加方向当场顶爆);②级联面板退役(a4744570 Phase 5)删 jd-category-cascader-position.test.ts 未回写(删除方向不红、基线一直虚松 4 用例,本次重生成同步收回 files 264→263/cases 1857→1855)。UPDATE_SOURCE_PIN_BASELINE=1 重生成,delta 仅上述两笔,无第三变化 2026-11-22 15:13:52 +08:00
huangzd1997 66087460ab fix(admin-vue): 京东数据库页一屏装配——左侧类目树超出滚动条、右侧卡片一屏后面板内滚(2026-11-22 用户口径「左侧菜单要超出变成滚动条,右侧一屏后也要滚动」):admin-content 经 :has() 转纵向 flex 只在本页挂载时生效(路由切走自动还原,其他页面零感知,不动 AdminLayout),.jd-database-view/.jd-body 吃通栏之下一屏两栏同高;侧栏树内部滚动带本就位,只是此前被主面板拉爆永不触发;主面板 overflow-y 滚动带与侧栏同款细带;窄屏(≤980px)撤装配回自然整页滚;浏览器实证外层不可滚/两栏独立滚/已选条粘底 2026-11-22 15:06:19 +08:00
huangzd1997 64e426a941 feat(jd-database): 归属筛选查询——归属下拉追加「按分类查询」组(2026-11-22 用户口径「还要加个归属筛选查询」,11-17 三档快筛升级):四类档位互斥单值(全部/已分类/未分类+当前分组分类项 cat:<id>),分类档走既有 group_id 归属表 EXISTS 下推与侧栏点分类同一条谓词=后端零改动;选分类清店铺孤儿谓词(侧栏同形);下拉值=filter 派生态单真源(jd-product-filter 纯函数 node --test 直测);el-option-group 按 EP 按需注册规矩补样式导入(perf 护栏钉住) 2026-11-22 02:53:21 +08:00
huangzd1997 19b32414ac fix(admin-vue): 京东侧栏店铺名单铺开+添加店铺常驻(对齐原型《商品数据商城》) 2026-11-22 02:02:43 +08:00
huangzd1997 f742df9f20 fix(jd-database): 归属快筛首屏文字改卡「全部」——placeholder 随默认档改词(2026-11-22 用户口径,补 0a769fa8 只改逻辑没改显示的漏改半边;el-select 对 '' 值显示 placeholder 故文案必须与默认档同词,挂载测试钉住灰字文案) 2026-11-22 01:55:04 +08:00
huangzd1997 fe479262e6 fix(jd): B188-02 直推载荷带 userId,客户端判定分层消每单误报 WARNING 2026-11-22 01:36:08 +08:00
huangzd1997 3184d6696d feat(jd-database): 工具栏「导出 CSV」按钮摘除(2026-11-21 用户拍板「删除掉」导出按钮) 2026-11-21 23:17:59 +08:00
huangzd1997 bbadc445af feat(jd-database): 卡片图底条店铺名→归属分类名(2026-11-21 客户口径「这边改成分类名称就可以 自己分类的那个名称就可以」)
JdProductCard 图底条从店铺名(shopName)改显 groupName(后端 fillGroupNames 按当前分组补,
前端 jd-product-model 既有解析零改),空时显「未分类」且条常驻渲染(原 v-if="shopName"
过滤退役);店铺名不再上卡(详情弹窗仍可看)。类名 .jd-card-shop→.jd-card-category(语义
归位);jd-product-api.ts 的 label 注释同步组长口径。

判据:jd-product-card.mount.test.ts 10 支(分类条/未分类例/.jd-card-shop 退役反钉)+
jd-database-page.mount.test.ts 卡片字段映射例同改;门禁 vue-tsc rc0/node --test 1955/
vitest 27 文件 244(+1 未分类例)/npm run build rc0。
⏳ 发版:随分组下拉组长前缀(后端 jar)同窗发后管。
2026-11-21 20:22:22 +08:00
huangzd1997 9991aaaf7d feat(jd-database): 分组下拉 label 前缀公司名→组长账号名(2026-11-21 用户口径「这里不是选公司 是选超管/管理员」)
平台超管跨组下拉前缀从「公司名 / 组名」(2026-11-16 口径,company 表)换成「组长账号名 / 组名」:
组长=biz_shop_manage_group.created_by_id 优先、user_id 兜底(selectLeaderIdsByMemberUserId 的
COALESCE 同形),显示名=users.username;触发规则镜像「跨多组长才加前缀」(2026-11-16
「单公司不啰嗦」规则同形),单组长/组长账号已删只显组名。companyNames()/CompanyMapper 注入
随之退役;2026-11-16 空 Map.get(null) NPE 线上实录的防线注释随 leaderNames() 平移。

判据:JdCategoryScopeServiceTest 18 支全绿(组长前缀四支:跨组长带/单组长不带/缺组长不带/
createdById 优先 userId 兜底;公司超管/admin 档不查组长表;mvn -o test-compile rc0)。
⏳ 发版:scope label 属后端改动,须发 jar(随卡片分类条同窗)。
2026-11-21 20:22:17 +08:00
huangzd1997 067e7e5ba3 test(jd-database): v1.7 发版窗 catch 棘轮补记——STRICT_TOTAL 1107→1110(净增4枚记名:JdSizeChartAiService 三枚 B184-05 他窗件+TaskClientPullService.buildQueuePushPayload 一枚 B184-01;c59296da 实测已落 1106 因午窗铁律32删级联净删1枚未回拨)+GIVEN/STRICT_NOT_RETHROW 625→626(四枚全在不重抛含log格);单跑9例全绿 2026-11-21 17:44:58 +08:00
huangzd1997 98476d0d47 test(jd-database): v1.7 台账补记——v1.7 两条新 XML 语句与名单改名 updateById 登记基线。XML_SELECT_TOTAL 106→107+XML_STATEMENT_TOTAL 150→152(selectDistinctShopNames+insertIgnoreBatch 进 NOT_MIGRATED)+REGISTERED_UPDATE_BY_ID_SITES 163→164(JdGroupShopService.renameShop,JdGroupShopEntity 无 ALWAYS 字段);该笔当时只点 jd 点名包没跑整仓整量,出包树整量抓到补记 2026-11-21 17:31:16 +08:00
huangzd1997 66946c2391 feat(jd-publish): 尺码表空格 AI 补值端点 POST /size-values(B184-05 拍板「必填项一定要填,采集没有的用 AI 生成」)——JdSizeChartAiService 按 外观专利→货源查询 模块顺序取用户登记为龙抬头渠道的 LLM 密钥代调 chat/completions(enable_thinking/thinking_budget 按 LlmChannel 登记,gm-3.1-flash-lite),密钥不出服务端;解析 choices[0].message.content 归一 行→列→值序列(inputCount 长度对齐、区间倒挂/非数值/超范围整格丢弃、字符串数值兼容、markdown 围栏剥离),任何故障 WARN+空映射不抛错(客户端按身高比例公式回退,LongtaitouBalanceClient 同形降级纪律);JdPublishController 端点带 requireSessionOwnerUserId 会话身份。判据 JdSizeChartAiServiceTest 12 支(解析直测不 mock HTTP,LongtaitouBalanceClientTest 同形),mvn -o test-compile rc=0 2026-11-21 17:16:25 +08:00
huangzd1997 0a769fa8d3 fix(jd-database): 归属三档默认改卡「全部」(2026-11-21 用户口径,推翻 11-17 默认未分类) 2026-11-21 17:11:01 +08:00
huangzd1997 b20f0bb44a feat(jd-database): v1.7 卡片交互+CSV 导出恢复+已下载角标+类目树增强 2026-11-21 16:53:05 +08:00
huangzd1997 08b1f3f7f8 feat(jd-database): v1.7 侧栏店铺名单——分类下挂店铺、点店铺过滤、行内改名/移除、添加店铺弹窗 2026-11-21 16:45:28 +08:00
huangzd1997 6685491fcb feat(jd-database): v1.7 前端骨架——合并搜索+筛选弹层+回显条+自绘分页条+已选条 2026-11-21 16:30:35 +08:00
huangzd1997 085c285446 feat(jd-database): v1.7 对齐原型后端半边——V214 店铺名单+合并搜索/价格区间/店铺谓词+CSV 导出 2026-11-21 16:30:21 +08:00
huangzd1997 9eb42fe16a fix(jd-database): 红框整体上移——筛选行+批量工具栏提到页面最顶通栏(他窗在飞件代提交);网络层失败显式中文提示 2026-11-21 15:33:18 +08:00
huangzd1997 0f81034eab fix(jd-publish): 删「未携带源商品身份」分档提示——该形状客户端已放行,分档文案断言的是已推翻口径 2026-11-21 14:40:33 +08:00
huangzd1997 4261103e31 fix(jd-publish): 重试复位后带回直推载荷+克隆缺源身份文案分档——35147 重试实录三件 2026-11-21 14:23:47 +08:00
huangzd1997 c59296da72 feat(jd-collect): 进度/历史透传轮次游标 shopCatName/shopCatMerged——任务卡显示「正在采集分类」(多轮页码归 1 消歧,2026-11-21 方案 C 客户端侧配套)
客户端多选店内分类改逐分类轮次采集后,游标新增两键。HistoryItemVo/ProgressVo 加字段(注释与建单多选集合 shopCategoryNames 明确区分:这是「当前正在采的那一个」);BoardService#fillProgress 与 TaskService#queryProgress 读侧白名单逐键取(shopCatMerged 宽松布尔:true 字符串也认)。前端 toJdTaskView extraLines 加「正在采集分类:X(合并兜底时缀 等(页面筛选未生效,兜底翻页中))」。判据:JdCollectBoardServiceTest 游标键透传两支(selectList mock 必须 ArrayList 包 List.of——history 服务原地排序,不可变列表打爆)+jd-collect-progress.mount.test.ts 两支+jd-collect-tab.test.ts 源码绊线;门禁 mvn -o test-compile rc0+目标 49 绿、vue-tsc rc0、node --test 15 绿、vitest 24 绿。
2026-11-21 12:07:05 +08:00
huangzd1997 a2aeae9974 fix(jd-database): 2026-11-21 用户口径三件——面板删标题行(筛选往上摆顶齐侧栏)、左右等高对齐(stretch+侧栏内部滚动、窄屏恢复上限)、新建分类/分类管理置顶贴 Tab 行;删除商品按钮按原型并入按钮组紧跟取消本页 2026-11-21 11:38:46 +08:00
huangzd1997 427f22e0b4 fix(jd-collect): 删任务与京东数据库解耦——只收 scope 行与任务行,商品/图片/SKU/归属行不再级联清除 2026-11-21 10:40:55 +08:00
huangzd1997 a4744570e1 feat(phase-5): 京东数据库页重写装配——侧栏+卡片网格+居中详情弹窗;级联面板/详情抽屉退役(AC-9 参数逐字等价) 2026-11-21 04:26:16 +08:00
huangzd1997 6034a7a961 feat(phase-4): 详情内容共享块+居中弹窗壳——抽屉薄壳化复用同一份实现(取数 watch immediate 钉死重挂载取数) 2026-11-21 04:08:14 +08:00
huangzd1997 b88432d8a9 feat(phase-3): 京东商品卡片组件——主图/店铺徽标/标题/价格/编码复制/采集日期/勾选(additive,防冒泡钉死) 2026-11-21 04:00:14 +08:00
huangzd1997 3702c83c60 feat(phase-2): 京东数据库侧栏组件——商品目录树计数徽标/树外兜底+店铺分类双 Tab(additive,页面 Phase 5 接线) 2026-11-21 03:56:11 +08:00
huangzd1997 380792aa82 feat(phase-1): 京东数据库 UI 改造蓝图 Phase 1——类目计数聚合纯函数+首屏默认档 50 2026-11-21 03:47:45 +08:00
huangzd1997 22771a7aea test(phase-0): 京东数据库 UI 改造蓝图 Phase 0——基线全绿锁定+补 5 条黄金测试(缺口①②③⑤⑥) 2026-11-21 03:18:04 +08:00
huangzd1997 2de2714d00 chore(fe): JdCollectTab 计数文案注释压 3 行——净增压到 +3 配合 ops 可读基线点名 1086→1089(2026-11-21 本窗:progressCountLabel 进行时档防误删) 2026-11-21 03:09:35 +08:00
huangzd1997 3a24674c9d fix(jd-collect): 进度条 0 行进行时文案——首批分片确认前不再挂「已采集 0 个商品」像卡死 2026-11-21 03:02:44 +08:00
huangzd1997 9999bba223 fix(jd): 三支 console-only catch 补「先算原因再留痕」形状——JdPublishTab 协议探测/推送兜底(false 与兜底提示仍交调用方弹给用户)+JdCollectTab 停本机 worker;catch 静默棘轮 blocks 327→332 逐条点名(4420bd1 2 支+acd61aa1 登录京麦+81869f75 停 worker+f96d5118 采集状态多选各 1 支,全部非静默、silent 一格没涨);可读基线点名 JdCollectTab 1084→1086(含本批形状修复 +2)。判据:catch-silence-ratchet 4/4、jd mount 49/49、vue-tsc rc0 2026-11-20 23:19:15 +08:00
huangzd1997 f96d5118da feat(jd-collect): 建单页采集状态多选(售卖中/已下架)
原实现写死 tabs=['ONSALE'],已下架商品(京麦「已下架」页签,productState=10)根本进不了任务体。改为按状态勾选:
2026-11-20 22:38:57 +08:00
huangzd1997 81869f75d0 fix(jd-collect): 删除任务先叫停本机 worker,不再等分片/心跳发现任务已删
- 删除回调先过桥 stop_task(客户端 4.0.12 起 expose,5.0.2 包内可用)再发物理删除;
  桥不可用/旧包吞错,回退服务端删除后「任务不存在」兜底,停止不得阻断删除。
- 先停再删:任务行一删就没有停止依据,子进程会一直占着京麦浏览器锁直到下一批分片。
- pywebview.ts 登记 stop_task 桥类型;新增 jd-collect-delete-stop.test.ts 三支判据。
2026-11-20 21:56:38 +08:00
huangzd1997 9b23b4934d feat(jd-publish): 目标品牌建单+校验失败整单判死+改品牌原位重试(桌面协议 v3 服务端半边)
- 建单必填目标品牌(1–120 字符单行),走 /tasks/target-brand 独占路径,旧后端不会静默丢参数

- 激活与明细下发带 jdPublishProtocol,协议 <3 直接 409 要求升级客户端;明细 VO 下发 targetBrandName

- 预检失败回执(SOURCE/BRAND)必须带一条失败明细,整单判 FAILED 并落分类前缀;通用重试/继续对品牌失败任务拒绝

- 新增 /tasks/{taskId}/retry-brand:只允许无成功、无待确认记录的品牌失败任务改品牌后原位重试(世代+1、明细复位、回执直推本机队列)

- 兜底拉取按协议过滤带 targetBrandName 的 JD 上架任务,认领 CAS 带 resumeAttempt 防跨代误领

- 用户端:目标品牌必填输入、协议探测挡旧客户端、品牌失败弹窗与「修改品牌并重试」按钮
2026-11-20 21:48:59 +08:00
huangzd1997 acd61aa1d2 feat(jd-collect): 建单页「登录京麦」独立入口 + jd_login 分档引导(桥 open_jd_login)
背景(2026-11-20 装机日志+截图两帧):京麦登录态失效后,采集专用浏览器
(19899/chrome_data_jd)的登录窗口只在任务失败那十几秒里"顺带"出现、随即被
任务 finally 关掉;用户在日常 Chrome 登京麦成功但采集连败 3 次——两套浏览器
登录态不共享,误登=白登。客户端侧执行体与桥见 app_client b2af332。

- JdCollectTab.vue:「同步分类」旁新增「登录京麦」按钮(老客户端桥无该方法
  ⇒ 置灰+升级指引,与「同步分类」同口径);openJdLogin 分档——成功走绿色
  success,busy/重入/超时/关窗走 amber notice(超时档客户端不关窗口,用户可
  继续登),仅 jd_page/未知走红色 error。
- 「同步分类」jd_login 档现在点名引导「登录京麦」按钮(旧文案只说"去采集
  浏览器登录",用户找不到窗口)。
- pywebview.ts 登记 open_jd_login 桥类型(本笔只含该 hunk,341/326 全文件
  diff 事故已纠正——工作树 CRLF、仓内 blob LF,构造件归一 LF 后 numstat 15/0;
  jd_publish_protocol 类型属发布窗在飞改动,未卷入)。
- tests/jd-collect-tab.test.ts:新增「登录京麦独立入口」源扫判据(按钮/桥类型/
  分档通道/jd_login 引导,改回即红);node --test 13 例全绿、vue-tsc rc=0。

未完项(BACKLOG B121-04):京东发布侧 JdPublishTab 失败弹窗未接新按钮(发布窗
在飞面上,下一窗接线);装机面生效前置=随下一版客户端出包+用户端发版。
2026-11-20 17:46:39 +08:00
huangzd1997 5bdc125b18 fix(admin): 统一后台筛选控件高度与对齐 2026-11-20 14:19:06 +08:00
huangzd1997 51c41b238a feat(admin): 为支持单删的管理列表补齐批量删除 2026-11-20 12:08:28 +08:00
huangzd1997 132c19d51f feat(home): 首页三入口官方 logo 化——亚马逊官方字标(Wikimedia Commons 官方 SVG)/京东官方 JOY 狗(官方 CDN favicon 96px)/视频手绘 SVG 播放钮(evenodd 镂空实心圆,用户定稿黑色实底「不要紫色」);页头补数富 logo(后台同款)与标题;背景卡白卡 hover 上浮;权限显隐与 href 逻辑不动,jd-console-tool-catalog 判据 11 绿 2026-11-20 02:10:12 +08:00
huangzd1997 e903bc1845 fix(jd-collect): groups 端点会话身份直取——requireOwnershipUserId(httpRequest,null) 对管理角色豁免原样返 null ⇒ 作用域空、管理员账号客户端分类下拉全空(2026-11-20 用户实录,普通号不受影响);改 requireSessionOwnerUserId(JdPublishController 同款既有方法),判据测试改端点级断言+反向绊线(退回即红)。jdcat 窗完成件随联验恢复窗提交发版;DesktopHomePage.vue 属该窗在飞工作未动 2026-11-20 02:05:28 +08:00
huangzd1997 d69780cbc1 chore(gitignore): 新增 /docs/ /reference/ 显式忽略——docs/reference 等非源码内容不入库(2026-11-19 用户拍板,取代 2026-10-04 规划文档入库口径) 2026-11-19 23:44:43 +08:00
huangzd1997 9220bbdc82 feat(jd-collect): 任务进度行已采计数取 max(itemsReceived, rowCount)——分片被拒时不再与行数行自相矛盾
34959 实录:8 行已落京东数据库、分片回传 500 ⇒ 服务端 itemsReceived=0、rowCount=8,卡片 extraLines 显示「已采集 8 个商品」而进度行显示「已采集 0 个商品」。rowCount 是落库真值,进度百分比与计数文案统一取两者大者;分母(cursor.total)口径不变——客户端筛选生效时会写真分母(app_client 123777d 同窗)。判据:jd-collect-progress.mount 新增两支(分片被拒显示 8/8 99%、无分母取 rowCount 真值)18/18 绿+jd-collect-tab 12/12+vue-tsc rc0
2026-11-19 23:35:29 +08:00
huangzd1997 c6f70a0b11 fix(jd-collect): 货号刷写的判重比较改 BINARY,消除真库 1267 排序规则混用
真机 34956 分片回传 500「服务器内部错误」,而 8 个商品其实已经 upsert 落库
(synced_at 有刷新)——卡在落库后的货号刷写这一句:
item_num != CONVERT(id, CHAR) 两侧都是 IMPLICIT 可强制的字符串,
CONVERT 取的是连接排序规则(库默认 utf8mb4_0900_ai_ci),item_num 列是建表时的
utf8mb4_unicode_ci ⇒ MySQL 报 1267 Illegal mix of collations for '<>',整批分片失败。

判据必须与排序规则无关:按字节比较(BINARY),不做任何 collation 协商。
真库对撞(A 机 java-server 账号,事务回滚):旧谓词 ERROR 1267 / 新谓词 touched=8,
回滚后货号仍为原值。

JdProductMapperSqlTest 用真 XMLMapperBuilder 渲染 BoundSql 钉形状:摘掉 BINARY
或改用 COLLATE 即红。
2026-11-19 22:42:01 +08:00
huangzd1997 ce3502be9a fix(jd-collect): 清缓存失败如实回 false,静默棘轮 blocks 按三支逐条登记
jd-category-cache.ts 的三支 try/catch(读/写/清)兜法都是把结果交给调用方,没有 console 糊过去;清缓存原先是空 catch(被 catch-silence-ratchet 判「新增静默 catch」),改成 return false 后静默数不动、只进 blocks 324→327。
2026-11-19 22:30:55 +08:00
huangzd1997 4f759b996c feat(jd-collect): 店内分类同步结果本机缓存,页面重开直接回填(客户口径「同步后就记住呀 别每次都同步」)
店内分类只能靠客户端起 Chrome 现拉(一次十几秒),页面每次重开都空着逼用户再点一次同步是白成本。新增 pages/jd/jd-category-cache.ts(零依赖纯逻辑):同步成功后把 shopName/shopId/categories/fetchedAt 落 localStorage(键 jd_shop_category_cache_v1),页面挂载即回填选项集,说明行标注「X 同步,点同步分类可刷新」。只回填选项集、不回填选中值——选中值决定这一单采哪些分类,跨次沿用它等于静默改采集范围。「同步分类」仍走现拉并覆盖缓存(商家在京麦改了分类可刷回来)。脏 JSON/空分类/配额失败一律读成 null 或静默跳过,不拿半张表填下拉。

判据:新 tests/jd-category-cache.test.ts 6 支(原样读回/脏 JSON 与空分类读 null/脏条目与重复 id 过滤/storage 不可用不抛/清缓存/预选值按现有 id 裁剪);jd-collect-tab/jd-console 既有 19 支全绿;vue-tsc --noEmit rc=0。
2026-11-19 22:09:53 +08:00
huangzd1997 8757fb21ad fix(jd-admin): 类目级联圆点填芯改整条选中链(2026-11-19 用户「怎么就最后一个才实心圆点阿」)——旧形状 isSelected 要全路径逐段相等才亮蓝芯,选中末级时路径上的母婴/童装/家居服全是空心、只有末级实心;新增 isOnSelectedPath(路径是 selectedPath 前缀即填芯),下钻态与搜索态圆点同判据,选中链各级一眼可见;行体蓝字 active 不动(仍只标真正选中的那一个+下钻点亮的路),两态不混。判据:新 mount 契约 tests/mount/jd-category-cascader.mount.test.ts 4/4(路径全亮+兄弟/叔叔空心+选中父级其子级不亮+未选只亮清选行+搜索态同判据;反向验证改回 isSelected 即 2 支红)+既有 jd-database-page.mount 44/44+vue-tsc rc0 2026-11-19 17:39:02 +08:00
huangzd1997 bcdf7faf13 merge: V211 让号退役登记入 master(472a7e00 MigrationInventoryTest RETIRED_HOLES)
# Conflicts:
#	backend-java/src/test/java/com/nanri/aiimage/config/MigrationInventoryTest.java
2026-11-19 14:55:45 +08:00
huangzd1997 aeaa7f64f4 fix(jd): 回传链两处 0 行判死——空完成不再落 SUCCESS、结构变更不再白等 60 分钟(2026-11-19 34900/34901/34902 实录,铁律 31) 2026-11-19 13:17:56 +08:00
huangzd1997 23e326df19 feat(jd): 采集分类改「同步分类」按店实时拉取+回补 4.0.78 窗用户端 amber notice 源码 2026-11-19 12:50:53 +08:00
huangzd1997 8453091630 fix(jd-admin): 类目面板重开自动展开到已选节点(2026-11-19 客户「选中没实心」追问)——选中后面板即收,旧形状重开只铺第一栏,实心圆点要手动下钻两级才看得见,第一眼只见「全部类目」空心像选中丢了;重开按 selectedPath 前缀铺栏、末级亮蓝芯直接可见(路径无效列算自然止步,树外兜底行不受影响)。判据:vue-tsc rc0+jd-database-page.mount 44/44(回显断言改钉「重开即两栏、女装圆点直接蓝芯」) 2026-11-19 10:24:31 +08:00
huangzd1997 b030ce392c fix(jd-admin): 类目级联圆点命中区外扩 6px(2026-11-19 客户「没选中效果吗」)——13px 圆点太难点准,偏一点落到行体变成下钻、看起来像没有选中效果;::after 撑大可点面积视觉零变化,行体下钻/圆点选中语义不动。判据:vue-tsc rc0+jd-database-page.mount 44/44(含二级圆点选中即查与蓝芯回显两支)+jd-database-page 7/7 绿 2026-11-19 10:02:58 +08:00
huangzd1997 77bfd4cf1b fix(phase-5): v1.5 CR 消项 JD-PUB-01~07 服务端半边(蓝图 docs/ITERATION_PLAN.md Phase 5)——①JD-PUB-01 发布端点收有效用户会话+任务归属闸(AdminAuthSupport 身份源收口,outlet 分母随行,RequestSuppliedIdentityOutletTest +1);②JD-PUB-02 建单/原位重试补事务边界防半截状态;③JD-PUB-03 回传校验执行代次与许可批次(V213__jd_publish_item_permit 两列 nullable 扩展,Expand-and-Contract;旧代不写新代、重复回执幂等、未处理明细不产 SUCCESS);④JD-PUB-04 入队不再等于认领(激活与桌面推送顺序,兜底保留);⑤JD-PUB-05 未知提交不自动重发;⑥JD-PUB-06 旧代终态不触发新代收尾或弹窗(credential-fatal 旧代隔离+京麦登录失效识别);⑦JD-PUB-07 选品切分类丢弃迟到响应、全选只影响本页;新增 mount 测试 jd-publish-dispatch。判据:后端点名 11 类 88 例+整量 mvn -o test 5,716 例 0 失败 0 错误 19 skip BUILD SUCCESS(00:07,7:12min);用户端 vue-tsc rc0+node --test 31+vitest mount 8 全绿;full 闸门 overall=pass 四面绿(2026-11-18 23:59:16);真机 AC-1~AC-9 联验与发版未做,Phase 5 保持未勾 2026-11-19 00:09:46 +08:00
huangzd1997 472a7e001b test(flyway): retire skipped migration version 211 2026-11-18 21:45:14 +08:00
huangzd1997 4de78adfc7 feat(jd-admin): 2026-11-18 客户三条反馈闭环——公司超管收窄到名下+京东类目一级/二级可选中(IN 下推)+级联触发框 34px 对齐
【一、用户管理:公司超管「各自看各自名下」(backend-java AdminUserService)】
客户口径(11-18 截图:阿华66 公司超管看到了 admin 直建的 ssss):平台超管看所有,
其余公司超管只看自己名下。读侧 listUsers 公司超管分支由「本公司全部(role≠super_admin)」
改为 company_id=本公司 AND (id=本人 OR created_by_id=本人)——与组长档同一形状;
自己那行永远可见(保证能改自己密码/额度)。写侧 updateUser/deleteUser 公司超管分支
在「同公司」闸之外加同形「目标 created_by_id=本人」谓词,不留「列表看不见、API 照样改」
的洞(停用/改密/额度全走这条闸)。createUser 不动(新建天然落本人名下)。
口径为直接下级:组长再建的普通号归组长看,不在公司超管列表(如需整棵下级树另拍板)。
判据:AdminUserServiceCompanySuperAdminTest 改 1 增 5(名下可见谓词/超管档反向不收窄/
写侧越权 403 两支+本人建的可编辑);其余 admin 测试类夹具全用超管/组长档,核过不受影响。

【二、京东类目一级/二级可选中(前端展开+后端 IN,零表结构变更,用户拍板路线)】
后端:AdminJdProductController.page 的 category 参数改 List<String>(重复 query key 绑定,
参数名不变、单值形状照常);JdProductQueryService.Filter 逐项 trim/去空白/去重、空集合归
null=不过滤;JdProductMapper.xml productConds 类目谓词 eq→IN+foreach(仍 SQL 侧下推,
铁律 20 同形)。落库仍只有末级类目名,无 schema/迁移改动。
前端:jd-category-tree.ts 新增 jdCategoryAllNodes/jdCategorySearchNodes(搜索铺全层级)
+jdCategoryNamesUnder(path)(选中节点→自身+全部后代类目名集合,含自身因实际末级可能
就在这一级;路径失效回 null 兜单名)。JdCategoryCascader.vue:非末级行圆点点击=选中
(emit change 带名称路径)、行体/箭头仍下钻;选中态按路径比对(同名跨支不串);搜索
结果含一级/二级行。JdDatabasePage/jd-product-filter/jd-product-api:categoryPath 入筛选态,
序列化按子树展开集合,axios paramsSerializer indexes:false 出重复 category= 参数。
已知代价(路线自带、用户已选):不同父级下同名末级会随展开集合一起命中(B112-05 同口径)。

【三、样式(JdCategoryCascader.vue)】
触发框 min-height 42→34px+padding 5x10:main.css:245-248 全局密度收口把相邻 input/
el-select/.btn 压到 34,自绘 button 不在收口清单里才显高;非末级圆点不再永远空心。

【台账】source-pin-ledger.json 重录(UPDATE_SOURCE_PIN_BASELINE=1 官方口):本笔
jd-category-tree.test.ts 用例 6→8;同时把 2a8bdd7d 已提交未记账的
user-menu-tree-platform-filter.test.ts(8 例 0 钉 0 读点)一并登记——基线在该窗陈旧,
此处为台账记账、非卷码。

【验证】mvn -o test-compile rc=0;定向 mvn -o test(AdminUserService* 七类+
AdminJdProductControllerTest)rc=0;admin vue-tsc rc=0;node --test jd-category-tree/
jd-database-page/jd-product-group/cascader-position 全绿;vitest mount jd-database-page
44/44(含本笔新增一级/二级选中用例);ops _push_gate.py --fast overall=pass 四面绿
(首轮后管 readSource 格红=本笔用例数,重录基线后复跑绿)。
发版未做:jar+后管随下一窗口走既有流程;full 闸门未跑(模式 D 口径)。
2026-11-18 16:53:36 +08:00
huangzd1997 96afb685c2 feat(brand): 品牌检测建单可选本机/线上采集(V212),默认本机+排队相位可见 2026-11-18 15:19:08 +08:00
zwork 83e9bbe71a fix(phase-5): AC-7 服务端半边——京东上架失败重试复位 biz_jd_publish_item 明细行(v1.5 蓝图 Phase 5 消欠账)——新增 TaskItemsResetSpi(modules/task/spi,task侧不import业务模块,依赖方向 jd→task 与 ClientTaskRetrySpi 同族),TaskInPlaceRetryService 在任务头 CAS 复位成功后按 moduleType 调用;JdPublishTaskItemsResetSpiImpl 把 FAILED/PUBLISHING 行复位 PENDING 并清旧 publish_error,SUCCESS 行不动(AC-4 已发布不重发,客户端断点 done 同口径);刻意不吞异常(半截状态纪律与 clearDeliveredResultUrl 同一);判据:JdPublishTaskItemsResetSpiImplTest 2(wrapper 形状探针:行状态谓词只认 FAILED/PUBLISHING、publish_error 清 NULL)+TaskInPlaceRetryServiceTest +4(复位被调/无匹配跳过/CAS失败不碰明细/复位失败响亮传播) 2026-11-18 14:04:51 +08:00
zwork 1524099d3b feat(admin): 分类管理弹窗列表加表头(2026-11-18 用户红框口径)——搜索行与分类列表之间加一行淡色列名「分类名称|商品数|操作」,与数据行同构对齐(同 gap/同左右内边距,商品数吃徽标同宽、操作同 margin-left:auto 靠右);只在列表有数据时渲染,空态/加载中不出;同组普通号只读口径行内无写按钮,操作列表头随之不渲染;表头在滚动列表外,翻页滚动固定。判据:vue-tsc rc0+jd-category-manage-dialog.mount 21/21 绿 2026-11-18 13:41:49 +08:00
zwork bd6f2cdc91 fix(ledger): PageDefaultsLedgerTest 补记 v1.5 Phase 4 三出站点(整量 mvn -o test 抓到,发版前必绿)——917884aa 的 JdPublishController 读侧新增 page=FIRST_PAGE+page_size=JD_PRODUCTS_PAGE_SIZE(products 选品分页)与 limit=DEFAULT_RESULT_LIMIT(history 任务历史)三处出站点,台账没随行:named ledger 59→62、page 口径 26→27、文案与注释同步;单跑 6/6 绿 2026-11-18 13:04:32 +08:00
zwork 84c664c795 feat(platform): 后管菜单平台隔离收窄+列表密度收口(2026-11-18 用户截图口径「密钥管理与密钥用量统计仅亚马逊侧;菜单配置展示树按当前平台先裁剪再展平分页」)——①双侧共用清单四件收窄:AdminMenuPlatformScope.BOTH_MENU_KEYS(后端唯一出处)与 admin platform-scope.ts BOTH_PLATFORM_MENU_KEYS 同源去掉 admin_user_secrets/admin_user_secret_usage,密钥两页京东侧不再下发也不可配;②菜单管理页:全树字典保留(授权数据不动),展示树与父级候选走 filterMenuTreeNodesByPlatform 先裁剪再展平分页,切平台清筛选回页1并关弹窗;③列表密度收口:顶栏 76→56、内容区留白 30/32→12/16、筛选行 flex 换行紧凑、表格行距 6px、按钮/输入 34px 同高,三档响应式断点(1440/820/560,窄屏菜单项不再整体隐藏);task-243 顶栏 56px 断言随行、task-244 新钉六条紧凑断言与「窄屏不许 display:none 菜单项」反向钉。判据:AdminMenuPlatformScopeTest 11+AdminConsoleCurrentUserMenusPlatformTest 3(后端点名绿)+vue-tsc rc0+node --test 35+npx vitest run 全量 188/188 rc0(新增 menu-manage-platform.mount 3 支:京东侧菜单配置页无亚马逊项、保留账号域四件与京东工具、密钥页归亚马逊)+快检 overall=pass 四面绿(2026-11-18 12:5x,Git PATH 前置壳) 2026-11-18 12:47:39 +08:00
zwork 917884aa6d feat(phase-4): 京东商品上架用户端页(v1.5 蓝图 docs/ITERATION_PLAN.md §4 Phase 4)——JdPublishTab(分类 jdCollect.groups 唯一源→选品分页 owner 过滤→跨页勾选→改价三档→建单 queuePayload 直推→useLiveTaskBoard 行级面板+credential-fatal 同形接入)+tool-catalog 占位卡转正式+router 注册;后端面板读侧 JdCollectController 同形五端点(products/dashboard/history/progressBatch/delete)+JdPublishBoardService(无 scope_state,进度真源=明细行级四档)+JdProductQueryService.pageForUser(归属表两步下推不夹原生 SQL);激活 Phase 0 预置 5 支 Pending 契约;判据:JdPublishBoardServiceTest 5+JdProductQueryServiceUserPageTest 4+outlet 分母 138/72(写+2 读+3 随面板端点)、endpoints 冻结快照+progress/batch 清单+1、终态窄集合台账+JdPublishTab 1、catch 块 319→324 全非静默、占位 mount 锁翻转两条断言;vue-tsc rc0、用户端 node --test 1078/1078+vitest mount 90/90、后端点名 6 类 41 例 BUILD SUCCESS、快检四面格(后端 9.5/客户端 10.0/用户端 9.6)绿,唯一红格=后管 mount 组件挂载格,甄别=他窗在飞 admin 件输出含 failed 子串触发 ruler vfail 脆弱判据(实跑 cmd /c npx vitest run RC=0、188/188 全过,本笔零后管文件) 2026-11-18 12:23:27 +08:00
huangzd1997 b5578561df fix(guardrails): 京东上架五守卫格整量补记(24272a91 点名 87 例没跑整量、两处账本与四个分母漏记,2026-11-18 发版前整量 5689 例抓到)——①TaskFailureCategoryGuardrail B51-R1:JdPublishIngestService.summarizeTerminal 文案先落局部变量 message 再配对写列(原来三元里各写各的表达式被「写的列与文案不是同一个来源」判红;CollectDataService failTask 正本形状同源);②ApiGuardCoverageAuditor PENDING_CONVERGENCE 登记 /api/jd-publish(与 /api/jd-collect 逐形状同族:建单等五端点 requireOwnershipUserId fail-closed、chunk 判死口凭据化 isTrustedInternalToken 匿名拒绝判死、JdPublishChunkRequest 不带 userId 不进身份扫描);③RequestSuppliedIdentityOutletTest 写类分母 133→136(建单 DTO 形+activate+heartbeat 三支)、读类 67→69(items+progress 两支),chunk 不计入(留痕注释);④MigratedSqlEquivalenceTest XML_SELECT_TOTAL 103→105+NOT_MIGRATED 点名 JdPublishItemMapper#selectPublishableItems/countByPublishStatus;⑤SqlLayeringConventionTest XML_STATEMENT_TOTAL 147→149。判据:点名 5 类 34/34 绿+整量 5689 例(0 失败/19 skip)BUILD SUCCESS 9:51min——修复 jar 与平台隔离 jar 同窗 2026-11-18 02:56:14 +08:00
huangzd1997 1105320354 fix(admin-shell): 壳层锁视口高——侧边栏固定、菜单区独立滚动条(2026-11-18 用户口径「菜单加个滚动条吧 不然滚动下来 又侧看不见了」)——根因=.admin-shell 用 min-height:100vh 让整条 flex 高度链失去确定性:.admin-menu-scroll(flex:1) 内的 el-scrollbar(内部 height:100% 需父级定高)与 .admin-content(现成 overflow:auto)双双失效、滚动回落整页滚,侧边栏顶部品牌区/平台 tab 被滚出视口;改 height:100vh+overflow:hidden 后侧边栏定视口高、菜单区自出滚动条、内容区独立滚动、顶栏固定(html/body/#app L33 已 height:100% 无需动;不删任何现有声明,task-243 钉的 sidebar 252px/topbar 76px/渐变全兼容)。判据:task-243 首用例新增三条绊线断言(.admin-shell 必须 height:100vh+overflow:hidden、不得回退 min-height:100vh,改回即红;在既有用例内加断言行不新增 test 块/read 点,source-pin 棘轮钉子=460/读点=658 与基线逐字同零台账变化);vue-tsc rc=0;node --test task-243/4/242/棘轮 30/30;快检 overall=pass 四面绿(后端 9.5/后管 8.8/客户端 10.0/用户端 9.6)。纯 CSS 改动随下一窗口后管发版生效,真机目检登录后滚动菜单即见 2026-11-18 02:17:18 +08:00
huangzd1997 8ac9fafb7b feat(jd-database): 分类状态快筛加「全部」档(2026-11-18 用户口径「加个全部选项」,默认仍卡未分类)——三档下拉(全部/已分类/未分类),「全部」value='' 选中即查当前分组全部商品:序列化层对 '' 天然不下发 classified 参数(jd-product-filter toJdProductFilterQuery 单一出口,''/缺省/脏值同走该兜底)=后端 required=false 收 null=JdProductMapper.xml <if test="classified != null"> 跳过谓词,后端零改动;出厂默认与「重置」仍卡「未分类」(11-17 用户口径不动,jdProductFilterActive 对 '' 仍按未激活处理);「全部」选项与「全部分类」下拉的 value='' 全量出口同形。判据:mount jd-database-page 三档断言(['全部','已分类','未分类'] 精确数组,改回两档即红)+新增「选全部→请求不带 classified 键」行为用例+重置仍回未分类;jd-product-group 纯测试形状不变仍绿;vue-tsc rc=0;node --test 14/14;vitest mount 43/43;快检 overall=pass 四面绿(后端 9.5/后管 8.8/客户端 9.8/用户端 9.6)。纯前端改动随下一窗口后管发版生效 2026-11-18 01:56:08 +08:00
huangzd1997 2a8bdd7d29 feat(platform): 后管与桌面端菜单按用户平台隔离(2026-11-18 用户口径「隔离下除 admin 外,京东用户只看京东菜单、亚马逊看不了」)——AdminMenuPlatformScope 成为菜单 key→平台归属唯一出处(京东独占 admin_jd_database+app 三件;双侧六件=账号域基础三页+本笔补侧的菜单权限配置/密钥管理/密钥用量统计;未知 key 默认 amazon 与前端 platform-scope 同形;platform null/空白归一 amazon=列 DEFAULT 同口径,不把「没带」读成京东侧全拦),filterMenuVosByPlatform 扁平过滤保留祖先链保组树完整、分组节点按存活子项去留(与前端 filterMenuTreeNodesByPlatform 同形);裁剪只挂三个下发出口(current-user/menus 非站点超管按 users.platform 收窄+登录 VO adminColumns/appColumns 双树=后管+桌面端一起)与逐页门(requireConsolePageAccess 平台门置于 isAdmin 直通之前,越侧 key 一律 403),红线=不动 getUserColumnPermissions 本体(授权编辑读接口与整树替换保存语义不变、授权行保留);current-user 增 platform 键;前端 allowedPlatformsForUser(超管随菜单树分布、其余锁 users.platform 侧、未知/缺省兜底 amazon、交集空仍锁死本人平台)+AdminLayout watch clamp(localStorage 残留另一侧自动归位、当前页在被禁侧跳回本人平台第一可见页、单侧时 tab 条整个隐藏)+platform-tab.syncToAllowed;app 树 37 key 全集核对无平台无关 key(withdraw=取款挂品牌运营工具、erp/purchase 挂后勤工具)。判据:AdminMenuPlatformScopeTest 11+ConsolePageTest +5 平台门+AdminConsoleCurrentUserMenusPlatformTest 3+AuthServicePlatformMenuTest 3+CompanyTest +1 platform 键=43 例绿;前端 platform-menu-filter 9/9(+2)、mount admin-layout-platform-lock 4/4、授权树过滤对齐扩双侧;vue-tsc rc=0;node --test 1937/1938(唯一红=在册 B116-03 ENOENT);vitest mount 184/184;mvn -o test-compile rc=0;快检后端 2 红格=环境假红(缺 Git 工具链 PATH,前置后 30/30 绿)、四面可读棘轮红=PermissionMenuService 1661→1676 行随本笔点名记账(ops 仓同窗);桌面端界面随 appColumns 下发生效,客户端出包另窗 2026-11-18 01:28:49 +08:00
huangzd1997 24272a910c feat(phase-2): 京东商品上架后端地基(v1.5 蓝图 docs/ITERATION_PLAN.md §4 Phase 2)——V210 发布明细表 biz_jd_publish_item(号段实核:V207~V209 已按序占用)+JdPublishTaskService 建单/配额/归属/生命周期(建单即落快照行,AC-8 配额闸前置、AC-9 他人商品 403、铁律 27a 改价同源、铁律 19 LOCAL 显式写)+items 分批下发(SQL 侧下推只出 PENDING 行=AC-4 断点服务端半边,图片 jd-products 预签名 GET 新开 presignObjectDownload 出口)+JdPublishIngestService chunk 行级回传(isEnd 按行级真源汇总终态,铁律 31 分档判死口凭据化)+JdPublishStaleTaskService 判死(JdStaleTaskService 同形,60 分钟 aiimage.jd.publish.stale-minutes)+派发三件套(SPI jd-product-publish-run+白名单 JD_PUBLISH+建单响应 queuePayload,铁律 32)+JdPublishTaskHeartbeatSpi override ensureOwnership(B98-07 同形债预防:SPI 轻校验+服务层用户域归属闸,LOCAL 客户端心跳实例域不适用)+registry/EXPECTED_MODULES/清理清单/CollectChannel.LOCAL_DEFAULT_MODULES 四清单同步;激活 JdPublishContractPendingTest 7 支 Pending 契约全绿。判据:点名 12 类 87 例 BUILD SUCCESS(契约 8+建单 14+回传 11+判死 3+schema V210 格+coverage/golden/channel/pull-spi/migration 各格);mvn -o test-compile rc=0;可读棘轮 OssStorageService 1161→1176 行随本笔点名更新(presignObjectDownload +15);LockSkipWitness 分母 30→32、覆盖文件 12→13(JdPublishStaleTaskService 两处留痕,ops 仓同窗更新);快检后端 9.5/用户端 9.6 绿、唯一 fail 红格=后管 readSource 属他窗在飞 align-group-editor 用例 10→13(本笔零后管文件);真机带库整链(V210 实跑)随 Phase 5 发版窗口 2026-11-18 00:31:53 +08:00
huangzd1997 f4bde32f83 feat(admin): 新建分组组长可下拉选(2026-11-18 用户口径「组长不能下拉选吗」)——组长原为只读回显当前登录用户(2026-10-07 对齐 admin.js 的有意设计);后端 validateLeaderOperator 对站点超管本就放行任意 createdById(只要求组长与操作者同公司 ensureLeaderSharesOperatorCompany),故纯前端落地:新建+站点超管出 filterable 下拉(候选=本公司账号,公司超管永不领衔、站点超管仅保留操作者本人,管理员/普通账号均可领衔);组长改选联动两件事——组员候选按新组长重算(eligibleGroupMembers 已吃 leaderUserId)+ 把新组长从已选组员里摘掉(后端「组长不能作为组员重复加入分组」);创建提交 createdById=所选组长;编辑与非超管新建保持只读(后端更新载荷不收组长/强制组长=操作者本人);编辑历史行缺 leaderUserId 保持 null 口径不回落当前登录人(组员候选过滤不悄悄变)。判据:align_group_leader_candidates_* 3 支新模型用例+ui_wiring 改钉新形状(v-if=canPickLeader/v-else 只读回显/createdById=leaderId/companyTab 绊线保留)+platform-account-pages 调用形状同步;vue-tsc rc=0;node --test 39/39(align-group-editor 13+task-253 8+platform-account-pages 10+task-268 8) 2026-11-18 00:27:04 +08:00
huangzd1997 885fa813db feat(admin): 侧边栏父菜单默认全展开+mount 断言对齐标题去后缀(2026-11-17 用户口径「父菜单不要默认折叠」)——menu-mapper 的 groupKeysForActive(按激活路由命中展开)换 allGroupKeys(全部分组);AdminLayout 对 entries 变更命令式补开(el-menu 的 default-openeds 只在挂载读一次,平台 tab 切换/菜单树刷新后新分组不会自动展开;watch 里读当下 computed 而非触发快照,快速连切 tab 不补开已离开渲染树的旧分组——el-menu 的 open 对未注册 index 会抛);用户手动收起的组在 entries 不变期间保持收起。判据:task-6 8 例(allGroupKeys 全展开/顶级叶不产键/空菜单空键+壳层绊线:groupKeysForActive 回流即红、watch(openedKeys)+nextTick 缺一即红);mount 京东页「分类管理」断言对齐 ea9dca3f 标题去后缀(那笔漏改的存量红);vue-tsc rc=0;node --test 1932/1933(唯一红=在册 B116-03 ENOENT);vitest mount 180/180;ops fast 闸门后管格绿(overall=fail 甄别=后端巡检格/用户端棘轮格红属 crawler-plugin 34 个在飞件,本笔不触碰后端与用户端) 2026-11-18 00:00:33 +08:00
huangzd1997 ea9dca3faf style(admin): 分类管理弹窗标题去掉「· 分组名」后缀(2026-11-17 用户口径「不要显示周丽娥」)
modal-sub span 与 .modal-sub 样式整段删除;挂载用例改反向钉(.modal-sub 不存在、分组名不进标题),翻组/直建等其余 20 例不受影响。vitest 21 例全绿+vue-tsc rc=0。
2026-11-17 23:02:22 +08:00
huangzd1997 7f76a96264 style(admin): 分类管理弹窗搜索/新建/按钮合回一排(2026-11-17 用户口径「弄成一排呗」)
340px 弹窗里垂直两行显空,三件改回一行。宽度分配先试 flex 1:1.75 实测偏移(搜索 122、新建输入只剩 105,7 字占位 115px 被截),改成搜索定宽 108px+新建行吃剩余(输入 119px),两个占位都完整。挂载用例同步为一排结构,并钉新建行只有输入框+按钮两个子元素(用户旧构建截图里多出的空框=11-15 已下线的排序输入,重新构建即消)。判据:vitest 挂载 21 例全绿+vue-tsc rc=0。
2026-11-17 22:57:23 +08:00
huangzd1997 0c4354fc1e feat(jd): 京东数据库写权限放宽到管理员级+分组筛选收超管档(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」「超管可以有分组筛选,管理员及以下则没有」)——后端 requirePlatformSuperAdminWrite 改 requireJdProductWrite:平台超管/公司超管/admin 三档放行、普通账号(resolveRole=null)403「仅超级管理员或管理员可以编辑或删除京东数据库数据」(四条商品行写路由同闸;批量归类 V203 requireWritableGroup 不动);前端 canWriteProducts(isAdminRole)管操作列/批量删除/勾选列/只读提示,canFilterGroup(平台+公司超管)管筛选行「分组」控件整块显隐(管理员及以下连单组锁定芯片都不渲染,分类面静默落默认组)。判据:后端 29 例(普通账号四写 403 不触服务+admin 四写放行+公司超管放行+结构钉三档谓词与 403 文案);前端挂载 42 例(普通员工 5 列只读+无分组控件、admin 7 列全写+多组也无下拉、公司超管齐写+多组可切组、超管照旧);vue-tsc rc=0;ops fast 闸门 overall=pass 2026-11-17 22:42:15 +08:00
huangzd1997 8b0cde4a51 feat(admin): 京东数据库动作条上移+文案三刀(2026-11-17 用户截图口径)——「共X条京东商品」汇总删除;原工具栏(批量编辑分类/分类筛选/状态快筛/分类管理/批量删除)整体上移并入筛选行与查询/重置同排(.jd-toolbar 容器摘除,放不下靠 flex-wrap 折行;下拉位宽钉定改 .jd-filter-row 直接子级选择器防误伤「分组」表单下拉);「删除勾选(N)」改「批量删除(N)」、确认弹窗改「确定批量删除选中的 N 个商品吗」。行为零改动(勾选累计/权限分档/筛选语义全不动)。判据:vitest 挂载 jd-database-page 39 例全绿(文案断言同步、汇总条加反向钉)+ jd-category-manage-dialog 21 例+静态扫描 node --test 24 例+vue-tsc rc=0 2026-11-17 22:23:35 +08:00
huangzd1997 c15f0ce229 fix(jd): 采集分类默认口径改「全店采集」——占位符去「不选=」改「全店采集(点击选择分类)」、未选中提示改「默认全店采集。」(2026-11-17 用户口径「默认全店采集,不要写不选=全店采集」;选择行为零改动,空数组=全店采集的三处同键契约不动)。判据:vitest 挂载 jd-collect-progress 10 例全绿(含新占位符 prop 钉与清空恢复断言)+vue-tsc rc=0 2026-11-17 21:17:18 +08:00
huangzd1997 6ccf7f2bb3 feat(admin): 账号域四弹窗撤「所属平台」手选,平台跟随当前 tab(2026-11-17 用户截图「有京东就不需要亚马逊了阿,亚马逊那边也是」)——公司/分组/用户新建编辑弹窗不再出平台单选:新建取当前平台 tab(props.platform),编辑回填行值原样下发(后端契约与 payload 形状零改动);form.platform 仍驱动授权树按平台收窄(UserMenuAuthTree)与京东上架额度可见性(includeQuota),判定出口不动。护栏翻转:platform-account-pages「单选恒在」两处改 doesNotMatch 反向钉(写回单选即红)+ task-48 编辑弹窗按钮钉回只剩角色两枚。判据:node --test 1932/1933(唯一红=B116-03 在册环境红,参考仓 shop-finance-source 已移除)+ vitest mount 177/177 + vue-tsc rc=0 + ops fast 闸门 overall=pass。⚠ 后果登记:记录跨平台挪档的弹窗入口随之消失(B116-01 的「待用户翻档归侧」前置失效),需要时另窗补列表级动作或直改 DB。 2026-11-17 21:16:23 +08:00
huangzd1997 ae250ea182 feat(admin): 分类管理弹窗删三处说明小字(2026-11-17 用户口径「小字不需要」)——弹窗顶部「分类按数据权限分组隔离…」提示、平台超管空态引导语「京东侧还没有数据权限分组…」、组长说明「组长=你…」整段删除,空态只留直建表单本体;对应 CSS(.modal-tip/.bootstrap-lead/.bootstrap-hint)与挂载断言同步(指路句改反向钉、空态改钉表单形状、有组格改钉 .group-bootstrap 不渲染)。判据:vitest 挂载 21 例全绿+vue-tsc rc=0 2026-11-17 21:09:10 +08:00
huangzd1997 d850c46f46 fix(jd): 京东分组作用域两条取组 SQL 补 platform 投影——平台闸读不到平台档把全部组(含 jd 档)判非 jd 清空,平台超管建组建成功京东侧永不显示(2026-11-17 用户截图「咋没显示」实录)。selectAllGroups/selectLedGroups 各补 g.platform AS platform(selectAllGroups 上次 47fc0e08 补 company_id 同一条查询同款病);selectLedGroups 按先例整行摘迁移等价账本点名 NOT_MIGRATED(LEDGER_ROWS 82→81/SELECTS 58→57);ShopManageGroupScopeSqlTest 升级双事故绊线:超管投影钉 company_id+platform 两列、新增组长档投影格。判据:投影缺任一列即红(mock 掉 mapper 的服务用例照旧绿——这正是两连漏的成因);mvn -o test 三类 22 例全绿 2026-11-17 21:08:59 +08:00
huangzd1997 2a0cc86572 fix(jd/account): 用户弹窗选京东桌面端分区整组消失——V209 前台京东菜单(jd_tools/jd-collect/jd-publish)补进平台判定(2026-11-17 用户截图「前台的京东少了」)。新增 JD_APP_MENU_KEYS 与 JD_MENU_KEYS 分列:app 菜单没有 admin 路由,不得混进「与 routes.ts 对撞」的后台清单;platformsOfMenuKey 两份同认,过滤算法与授权树/侧边栏两消费方零改动。判据:user-menu-tree-platform-filter 新增桌面端分区正反两例(jd 留京东工具台整组/amazon 留亚马逊 app)+三 key 判定钉;platform-menu-filter 清单钉死用例同步 JD_APP_MENU_KEYS 形状。node --test 29 例全绿+vue-tsc rc=0 2026-11-17 20:58:54 +08:00
huangzd1997 164b9b83fa feat(jd/account): 授权树按平台过滤+平台超管空态直建京东档分组——用户弹窗选京东只发京东侧菜单(京东数据库+双侧账号域三件,platform-scope 唯一算法出口、侧边栏委托同源),翻档时另一侧勾选自动收敛(pruneCheckedIdsToTree),京东档账号不再整树混发亚马逊授权;分类管理弹窗京东侧零分组时给平台超管开直建口子(POST shop-manages/groups platform 恒 jd、组长=当前登录人),建完 group-created 让父页整条作用域重取翻到新组接着建分类,不再死在「你还不属于任何数据权限分组」(2026-11-17 用户口径「admin 权限最大」)。判据:tests/user-menu-tree-platform-filter.test.ts 钉过滤/收敛/两消费方同形(B79-12 钉法);分类管理弹窗挂载 6 例(直建表单/无登录人/失败不发事件/翻组重取/非超管维持文案/有组不出口子)+京东页挂载 2 例页面级链路;vue-tsc rc=0 2026-11-17 18:59:35 +08:00
270 changed files with 21085 additions and 4742 deletions
+5
View File
@@ -142,6 +142,11 @@ data/logs/
# 生产库转储永不再入库(本体只留 backend-java/data/,那里已被忽略)
backend-java/src/main/resources/db/aiimage.sql
# ===== 文档与参考资料不入库(2026-11-19 用户拍板:docs/reference 及非源码内容不提交,只留本地;
# 取代上面「规划文档入库」的 2026-10-04 口径——当前实测本仓 0 支 docs/md 跟踪件)=====
/docs/
/reference/
# 打包前由 scripts/_git_stamp.py write 生成,随 jar 进 BOOT-INF/classes/;
# 入库会变成"孤儿构建产物"(10-07 那笔 target/classes 里的 V148 就是这个形状造成的宕机)
backend-java/src/main/resources/git.properties
@@ -0,0 +1,58 @@
import { expect, test } from '@playwright/test'
const brandPath = '/admin-vue/asin-center/invalid'
test('品牌数据库:单行筛选控件等高、底边对齐,窄屏可以换行', async ({ page }) => {
await page.goto(brandPath)
const filters = page.locator('.invalid-filter-row')
await expect(filters.getByRole('button', { name: '查询' })).toBeVisible()
const controls = [
filters.getByPlaceholder('输入 ASIN'),
filters.getByPlaceholder('输入品牌'),
filters.locator('.el-select__wrapper'),
filters.getByRole('button', { name: '查询' }),
]
const boxes = await Promise.all(controls.map((control) => control.evaluate((el) => {
const { height, bottom } = el.getBoundingClientRect()
return { height, bottom }
})))
expect(boxes.map((box) => box.height)).toEqual([34, 34, 34, 34])
expect(Math.max(...boxes.map((box) => box.bottom)) - Math.min(...boxes.map((box) => box.bottom))).toBeLessThan(1)
const batchDelete = page.getByRole('button', { name: '批量删除(0)' })
await expect(batchDelete).toBeDisabled()
const batchBox = await batchDelete.boundingBox()
const tableBox = await page.locator('.invalid-asin-table-scroll').boundingBox()
expect(batchBox?.height).toBe(34)
expect(tableBox!.y - batchBox!.y - batchBox!.height).toBeGreaterThanOrEqual(8)
await page.setViewportSize({ width: 680, height: 900 })
await expect.poll(async () => filters.evaluate((row) => {
const first = row.firstElementChild!.getBoundingClientRect()
const last = row.lastElementChild!.getBoundingClientRect()
return last.top >= first.bottom && last.right <= row.getBoundingClientRect().right + 1
})).toBe(true)
})
test('品牌数据库:键盘搜索分组、查询和新增仍可用', async ({ page }) => {
await page.goto(brandPath)
const filters = page.locator('.invalid-filter-row')
await filters.getByPlaceholder('输入品牌').press('Tab')
const group = filters.getByRole('combobox')
await expect(group).toBeFocused()
await group.fill('测试')
await expect(page.getByRole('option', { name: '测试分组' })).toBeVisible()
await expect(page.getByRole('option', { name: '其他分组' })).not.toBeVisible()
await page.getByRole('option', { name: '测试分组' }).click()
await filters.getByPlaceholder('输入 ASIN').fill('B0INVALID1')
const queried = page.waitForRequest((req) => new URL(req.url()).pathname === '/api/admin/invalid-asin-data' && req.url().includes('group_id=1'))
await filters.getByRole('button', { name: '查询' }).click()
const params = new URL((await queried).url()).searchParams
expect(params.get('data_value')).toBe('B0INVALID1')
expect(params.get('page')).toBe('1')
await page.getByRole('button', { name: '新增', exact: true }).click()
const dialog = page.getByRole('dialog')
await expect(dialog.getByRole('button', { name: '保存' })).toBeVisible()
await dialog.getByRole('button', { name: '取消' }).click()
await expect(dialog).not.toBeVisible()
})
@@ -0,0 +1,159 @@
import { expect, test, type Locator } from '@playwright/test'
// 独立的可见菜单清单;不从运行时路由反推夹具,以免漏注册时测试仍然全绿。
const shared = [
['admin_users', '用户管理', 'account/users', '.form-row'],
['admin_columns', '菜单管理', 'account/menus', '.form-row'],
['admin_group_manage', '数据权限分组', 'account/groups', '.form-row'],
['admin_companies', '公司管理', 'account/companies', '.form-row'],
] as const
const amazon = [
...shared,
['admin_user_secrets', '密钥管理', 'account/user-secrets', '.form-row'],
['admin_user_secret_usage', '密钥用量统计', 'account/user-secret-usage', '.form-row'],
['admin_shop_data_duplicate_check', '店铺撞款监控', 'shop-center/duplicate-check', '.filter-row'],
['admin_brand_gating', '品牌Gating库', 'shop-center/brand-gating', '.g-filters'],
['admin_keyword_usage', '关键词使用记录', 'shop-center/keyword-usage', '.kw-filters'],
['admin_shop_keys', '店铺密钥管理', 'shop-center/keys', '.form-row'],
['admin_shop_manage', '店铺管理', 'shop-center/shops', '.form-row'],
['admin_history', '生成记录', 'records/history', '.form-row'],
['admin_version', '软件版本管理', 'records/software-version', '.admin-header-controls'],
['admin_tutorial', '教程管理', 'records/tutorial', '.admin-header-controls'],
['admin_workbench_client_package', '数富AI工作台客户端包管理', 'records/workbench-client-package', '.admin-header-controls'],
['admin_device_logs', '日志管理', 'records/device-logs', '.form-row'],
['admin_task_center', '客户端任务管理', 'task-center/board', '.form-row'],
['digital_human_version', '数字人版本管理', 'records/digital-human-version', '.admin-header-controls'],
['admin_image_video_tasks', '视频任务记录', 'records/image-video-tasks', '.form-row'],
['admin_shop_data_crawl_tasks', '店铺数据记录', 'shop-center/data-tasks', '.form-row'],
['admin_dedupe_total_data', '数据去重总数据', 'asin-center/registry', '.dedupe-filter-row'],
['admin_invalid_asin_data', '品牌数据库', 'asin-center/invalid', '.form-row'],
['admin_query_asin', '查询ASIN', 'asin-center/query', '.form-row'],
['admin_product_categories', '商品类目', 'asin-center/categories', '.admin-header-controls'],
['admin_skip_price_asin', '最低价ASIN', 'asin-center/skip-price', '.form-row'],
['admin_appearance_patent_clean_items', '外观专利数据库', 'patent-center/clean-items', '.clean-filter-row'],
] as const
const jdDatabase = ['admin_jd_database', '京东数据库', 'jd-center/database', '.jd-filter-row'] as const
const jd = [...shared, jdDatabase]
const allMenus = [...amazon, jdDatabase].map(([key, name, path]) => ({ key, name, route: `/${path}` }))
const emptyPage = { items: [], total: 0 }
const fixtures: Record<string, unknown> = {
'/api/admin/appearance-patent-clean-items': emptyPage,
'/api/admin/brand-gating': emptyPage,
'/api/admin/brand-gating/stats': { total: 0 },
'/api/admin/companies': { items: [{ id: 1, name: '测试公司' }], total: 1 },
'/api/admin/device-logs/files': emptyPage,
'/api/admin/history': emptyPage,
'/api/admin/image-video-tasks': emptyPage,
'/api/admin/jd-product-groups': { items: [{ id: 1, name: '测试分类' }] },
'/api/admin/jd-product-groups/scope': {
platformSuperAdmin: true, defaultGroupId: 1,
groups: [{ id: 1, name: '测试分组', label: '测试分组', editable: true }, { id: 2, name: '其他分组', label: '其他分组', editable: true }],
},
'/api/admin/jd-products': emptyPage,
'/api/admin/jd-products/categories': [],
'/api/admin/keyword-usage': emptyPage,
'/api/admin/keyword-usage/deletes': emptyPage,
'/api/admin/keyword-usage/overview': {},
'/api/admin/shop-data-crawl-tasks': emptyPage,
'/api/admin/shop-keys': emptyPage,
'/api/admin/shop-manages': emptyPage,
'/api/admin/shop-manages/groups': [{ id: 1, group_name: '测试分组' }],
'/api/admin/task-center/overview': { runningTasks: 0, todayFinishedTasks: 0, stuckTasks: 0 },
'/api/admin/task-center/shop-options': { items: ['测试店铺'] },
'/api/admin/task-center/tasks': emptyPage,
'/api/admin/task-center/variant-tasks': emptyPage,
'/api/admin/user-secret-usage': emptyPage,
'/api/admin/versions': emptyPage,
'/api/admin/workbench-client/packages': emptyPage,
'/api/digital-human/versions': emptyPage,
}
// 这些接口在 mock-admin-server 里已经有专门的响应,不吃通用兜底。
const serverFixtures = new Set([
'/api/admin/current-user', '/api/admin/notifications/summary', '/api/admin/users',
'/api/admin/permission-menus', '/api/admin/user-secrets', '/api/admin/user-secrets/balances',
'/api/admin/shop-data-crawl/duplicate-check-console', '/api/admin/shop-data-crawl/duplicate-check-ledger',
'/api/admin/tutorials', '/api/admin/invalid-asin-data', '/api/admin/invalid-asin-data/groups',
'/api/admin/dedupe-total-data', '/api/admin/query-asins', '/api/admin/product-categories/children',
'/api/admin/skip-price-asins',
])
async function controlDeviations(row: Locator) {
await expect(row).toBeVisible()
return row.evaluate((el) => {
const selector = 'input[type="text"], input[type="number"], input[type="date"], input[type="datetime-local"], select, .el-select__wrapper:not(.is-multiple), button:not(.btn-sm), .admin-header-controls > .btn'
const controls = Array.from(el.querySelectorAll<HTMLElement>(selector)).flatMap((control) => {
if (control.matches('.el-select__input, .el-input__inner') || control.closest('[role="listbox"], .cat-panel')) return []
const box = control.getBoundingClientRect()
if (!box.width || !box.height) return []
const name = control.getAttribute('placeholder') || control.textContent?.trim() || control.className
return [{ name, box }]
})
if (!controls.length) return ['没有测到可见控件']
const failures = controls.filter(({ box }) => Math.abs(box.height - 34) >= 1)
.map(({ name, box }) => `${name}: ${box.height}px`)
for (const [index, { name, box }] of controls.entries()) {
for (const other of controls.slice(index + 1)) {
const overlapY = Math.min(box.bottom, other.box.bottom) - Math.max(box.top, other.box.top)
if (overlapY < 17) continue
if (Math.abs(box.bottom - other.box.bottom) >= 1) failures.push(`${name} / ${other.name} 底边未对齐`)
}
}
return failures
})
}
for (const [platform, menus] of [['亚马逊', amazon], ['京东', jd]] as const) {
test(`${platform}:逐个点击侧栏菜单,检查筛选区外框`, async ({ page, baseURL }) => {
test.setTimeout(120_000)
const pageErrors: string[] = []
const missingFixtures = new Set<string>()
page.on('pageerror', (error) => pageErrors.push(error.message))
await page.route('**/*', async (route) => {
const url = new URL(route.request().url())
if (url.origin !== baseURL) return route.abort()
if (url.pathname === '/api/admin/current-user/menus') {
return route.fulfill({ json: { success: true, data: { items: allMenus } } })
}
if (Object.hasOwn(fixtures, url.pathname)) {
return route.fulfill({ json: { success: true, data: fixtures[url.pathname] } })
}
if (url.pathname.startsWith('/api/') && !serverFixtures.has(url.pathname)) {
missingFixtures.add(url.pathname)
return route.abort()
}
return route.continue()
})
await page.goto('/admin-vue/')
await page.getByRole('tab', { name: platform }).click()
const sidebar = page.locator('.admin-menu')
await expect(sidebar.getByRole('menuitem')).toHaveCount(menus.length)
const deviations: string[] = []
for (const [, name, path, selector] of menus) {
await test.step(name, async () => {
await sidebar.getByRole('menuitem', { name, exact: true }).click()
await expect(page).toHaveURL(new RegExp(`/admin-vue/${path}$`))
await expect(page.locator('.admin-topbar h1')).toHaveText(name)
const content = page.locator('#admin-content')
await expect(content.locator('.load-failure-bar:visible, .page-error:visible')).toHaveCount(0)
const record = async (label: string, row: Locator) => {
const mismatches = await controlDeviations(row)
if (mismatches.length) deviations.push(`${name}${label}:${mismatches.join('、')}`)
}
await record('', content.locator(`${selector}:visible`).first())
if (path === 'asin-center/registry') {
await record('日期导出', content.locator('.dedupe-filter-date-row'))
}
if (path === 'task-center/board') {
await content.getByRole('button', { name: /^变体采集/ }).click()
await expect(content.getByRole('heading', { name: '变体采集(麦象批量任务)' })).toBeVisible()
await record('变体采集', content.locator('.form-row:visible'))
}
})
}
expect.soft(pageErrors).toEqual([])
expect.soft([...missingFixtures], '逐菜单验收不能使用未登记的空响应').toEqual([])
expect(deviations).toEqual([])
})
}
+6 -4
View File
@@ -8,6 +8,7 @@ import { defineConfig } from '@playwright/test'
* 会让 playwright 直接连上那个「不是本站」的服务,整份验收测的是别人的页面。
*/
const PORT = Number(process.env.E2E_PORT || 5174)
const MOCK_PORT = Number(process.env.MOCK_PORT || 18100)
export default defineConfig({
testDir: './e2e',
@@ -27,13 +28,14 @@ export default defineConfig({
webServer: [
{
command: 'node scripts/mock-admin-server.mjs',
port: 18100,
reuseExistingServer: true,
port: MOCK_PORT,
reuseExistingServer: false,
},
{
command: `set VITE_API_TARGET=http://127.0.0.1:18100&& npm run dev -- --port ${PORT} --strictPort`,
command: `npm run dev -- --host 127.0.0.1 --port ${PORT} --strictPort`,
env: { VITE_API_TARGET: `http://127.0.0.1:${MOCK_PORT}` },
port: PORT,
reuseExistingServer: true,
reuseExistingServer: false,
timeout: 120_000,
},
],
@@ -345,6 +345,9 @@ const server = createServer((req, res) => {
],
})
}
if (url === '/api/admin/invalid-asin-data/groups') {
return json(res, { success: true, data: [{ id: 1, group_name: '测试分组' }, { id: 2, group_name: '其他分组' }] })
}
if (url === '/api/admin/invalid-asin-data') {
return json(res, {
success: true,
@@ -589,4 +592,4 @@ const server = createServer((req, res) => {
return json(res, { success: true }, 200)
})
server.listen(PORT, () => console.log(`mock admin api listening on ${PORT}`))
server.listen(PORT, '127.0.0.1', () => console.log(`mock admin api listening on ${PORT}`))
@@ -0,0 +1,49 @@
<script setup lang="ts">
defineProps<{
batch: {
verb: string
count: number
disabled: boolean
progress: string
result: { failures: ReadonlyArray<{ id: number | string; label: string; reason: string }> } | null
submit: () => Promise<void>
clearSelection: () => void
}
}>()
</script>
<template>
<div class="batch-delete-actions">
<button class="btn btn-danger batch-delete-button" type="button" :disabled="batch.disabled || !batch.count" @click="batch.submit">
{{ batch.progress ? `正在${batch.verb} ${batch.progress}` : `批量${batch.verb}(${batch.count})` }}
</button>
<button v-if="batch.count" class="btn btn-sm batch-clear-button" type="button" :disabled="batch.disabled" @click="batch.clearSelection">清除勾选</button>
<details v-if="batch.result?.failures.length" class="batch-delete-failures">
<summary>查看失败原因({{ batch.result.failures.length }} 条)</summary>
<ul>
<li v-for="failure in batch.result.failures" :key="failure.id">{{ failure.label }}:{{ failure.reason }}</li>
</ul>
</details>
</div>
</template>
<style scoped>
.batch-delete-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.batch-delete-actions button {
min-height: 34px;
padding: 5px 12px;
border: 1px solid var(--admin-border);
border-radius: 9px;
background: #fff;
color: var(--admin-text);
font: inherit;
cursor: pointer;
}
.batch-delete-actions .batch-delete-button { color: #fff; background: #b35f6a; border-color: #b35f6a; }
.batch-delete-button:hover:not(:disabled) { background: #a34f5b; }
.batch-clear-button:hover:not(:disabled) { background: #edf5fb; }
.batch-delete-actions button:focus-visible { outline: 2px solid var(--admin-primary); outline-offset: 2px; }
.batch-delete-actions button:disabled { cursor: not-allowed; opacity: 0.55; }
.batch-delete-failures { max-width: 520px; color: #9f3845; overflow-wrap: anywhere; }
.batch-delete-failures ul { max-height: 180px; overflow: auto; margin: 4px 0; padding-left: 20px; }
</style>
@@ -0,0 +1,20 @@
<script setup lang="ts">
defineProps<{
label: string
checked: boolean
disabled: boolean
partial?: boolean
}>()
defineEmits<{ change: [] }>()
</script>
<template>
<input class="batch-delete-checkbox" type="checkbox" :aria-label="label" :title="label"
:checked="checked" :disabled="disabled" :indeterminate="partial ?? false" @change.stop="$emit('change')" @click.stop />
</template>
<style scoped>
.batch-delete-checkbox { width: 15px; height: 15px; vertical-align: middle; cursor: pointer; accent-color: #b33a2e; }
.batch-delete-checkbox:disabled { cursor: not-allowed; }
</style>
@@ -10,7 +10,28 @@ import { userNotice } from '../api/user-notice.ts'
/** 失败条上那个按钮的字样:必须是「重试」而不是一句「知道了」——撤入口同时得是出口。 */
export const LOAD_FAILURE_RETRY_LABEL = '重试'
/** 从 axios 错误 / Error / 字符串里取后端给的原因;取不到、或原文不是中文时返回空串。 */
/** 网络层失败(请求没到服务器就断了)给用户的中文提示。2026-11-21 线上实录:用户代理
* 链路抖动成批掐断 TLS 连接(当天全服 29 条「连接未完成即断」记录全部来自该用户的两个
* 出口 IP),axios 拿到英文 "Network Error" 按 userNotice 口径被滤空 ⇒ 界面只剩页面
* 兜底文案,用户看不出是网络问题、更不知道该重试还是该找人。这里显式补一句。 */
export const NETWORK_FAILURE_DETAIL = '网络连接中断,请检查网络后重试'
/** axios 错误且没有 response = 网络层失败(连接被掐断/超时/DNS),服务端根本没回话。
* 只认 axios 形状(code 为网络错误码,或带 config+isAxiosError 标记);普通 Error 没有
* response 不算(走原有 message 解析)。 */
function isNetworkLevelError(error: unknown): boolean {
if (!error || typeof error !== 'object') return false
const record = error as Record<string, unknown>
if (record.response !== undefined) return false
const code = typeof record.code === 'string' ? record.code : ''
if (code === 'ECONNABORTED' || code === 'ERR_NETWORK' || code === 'ETIMEDOUT' || code === 'ECONNRESET') {
return true
}
return record.isAxiosError === true && record.config !== undefined
}
/** 从 axios 错误 / Error / 字符串里取后端给的原因;取不到、或原文不是中文时返回空串。
* 例外:axios 网络层失败(无 response)不算「取不到原因」,给中文网络提示。 */
export function failureDetail(error: unknown): string {
const data = (error as { response?: { data?: unknown } } | undefined)?.response?.data
if (data && typeof data === 'object') {
@@ -20,6 +41,7 @@ export function failureDetail(error: unknown): string {
if (typeof value === 'string' && value.trim()) return userNotice(value, '')
}
}
if (isNetworkLevelError(error)) return NETWORK_FAILURE_DETAIL
if (error instanceof Error && error.message.trim()) return userNotice(error.message, '')
if (typeof error === 'string' && error.trim()) return userNotice(error, '')
return ''
@@ -19,24 +19,61 @@ export const PLATFORM_TABS: readonly PlatformTabDef[] = [
* 2026-11-17 晚:分类管理子菜单(admin_jd_category_manage,V204)随「京东分类管理并到
* 京东数据库分类编辑里」用户口径整体下线(页/路由/菜单行 V208 删),key 从清单摘除。
* 后续京东新页面上线把 key 加进这里即可,清单外的 key(含店铺管理/生成记录等
* 存量页)一律归亚马逊或双侧清单。 */
* 存量页)一律归亚马逊或双侧清单。
* ⚠ 本清单只收后台(admin)侧 key——护栏用例要求每条都在 routes.ts 登记 menuKey;
* 桌面端(app)京东菜单走 {@link JD_APP_MENU_KEYS}(无 admin 路由,不进侧边栏)。 */
export const JD_MENU_KEYS: readonly string[] = [
'admin_jd_database',
]
/** 双侧共用菜单(2026-11-17 用户口径「这些亚马逊这边也要有」):三个账号域页面在两个
* 平台 tab 下都显示——同一套组件、按当前 tab 给接口传 platform,各自只看/管各自平台的
* 账号、分组、公司(后端 V206 三表加列,存量默认亚马逊,京东侧数据在编辑弹窗里翻档)。 */
/** 桌面端(app)京东菜单的 column_key 清单(V209,2026-11-17 用户口径「前台的京东少了」):
* 组行 jd_tools(京东工具台)+两工具子行 jd-collect(京东店铺数据采集)/jd-publish(京东商品上架),
* 与用户端 permissionKeys 逐字一致。app 菜单不进后管侧边栏与 routes.ts 路由表,故与
* {@link JD_MENU_KEYS} 分列——判定出口 {@link platformsOfMenuKey} 两份同认。
* 后续用户端京东新工具上线把 column_key 加进这里即可。 */
export const JD_APP_MENU_KEYS: readonly string[] = [
'jd_tools',
'jd-collect',
'jd-publish',
]
/** 双侧共用账号管理页面:用户、分组、公司与菜单权限配置。
* 密钥管理/密钥用量统计按 2026-11-18 截图口径收回亚马逊侧。 */
export const BOTH_PLATFORM_MENU_KEYS: readonly string[] = [
'admin_users',
'admin_group_manage',
'admin_companies',
'admin_columns',
]
/** menuKey → 平台归属清单(唯一判定出口):京东独占 → ['jd'];双侧清单 → ['amazon','jd'];
* 其余(未知 key 在内)默认亚马逊。 */
/** menuKey → 平台归属清单(唯一判定出口):京东独占(后台或桌面端清单)→ ['jd'];
* 双侧清单 → ['amazon','jd'];其余(未知 key 在内)默认亚马逊。 */
export function platformsOfMenuKey(key: string): PlatformTabId[] {
if (JD_MENU_KEYS.includes(key)) return ['jd']
if (JD_MENU_KEYS.includes(key) || JD_APP_MENU_KEYS.includes(key)) return ['jd']
if (BOTH_PLATFORM_MENU_KEYS.includes(key)) return ['amazon', 'jd']
return ['amazon']
}
/**
* 通用「按平台过滤菜单树」(唯一算法出口,2026-11-17 用户口径「授权树也按平台收」):
* 叶子按 {@link platformsOfMenuKey} 是否包含当前平台留下;分组节点自身的 key 不参与
* 平台判定,按「有存活的子项」决定去留——否则京东侧「账号与权限」这类混合分组会被整组误剪。
* 两个消费方必须同形:侧边栏(platform-menu-filter.ts)与账号弹窗的授权树
* (UserMenuAuthTree.vue),改判定规则只改这一处。
*/
export function filterMenuTreeNodesByPlatform<T extends { key?: string; children?: T[] }>(
nodes: readonly T[] | null | undefined,
platform: PlatformTabId,
): T[] {
const filtered: T[] = []
for (const node of nodes || []) {
const children = filterMenuTreeNodesByPlatform(node.children, platform)
if (children.length > 0) {
filtered.push({ ...node, children })
continue
}
if ((node.children || []).length > 0) continue
if (platformsOfMenuKey(node.key || '').includes(platform)) filtered.push({ ...node })
}
return filtered
}
+44 -9
View File
@@ -1,12 +1,12 @@
<script setup lang="ts">
import { computed, watch } from 'vue'
import { computed, nextTick, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElMessageBox } from 'element-plus'
import { useAdminSessionStore } from '@/stores/admin-session'
import { joinAdminPath } from '@/config/app'
import { pageTitleOf, topbarUserOf } from '@/layout/topbar-model'
import { groupKeysForActive, toSidebarEntries } from '@/layout/menu-mapper'
import { filterMenuTreeByPlatform, visiblePlatformsFor } from '@/layout/platform-menu-filter'
import { allGroupKeys, toSidebarEntries } from '@/layout/menu-mapper'
import { filterMenuTreeByPlatform, allowedPlatformsForUser } from '@/layout/platform-menu-filter'
import { PLATFORM_TABS, platformsOfMenuKey } from '@/config/platform-scope'
import { usePlatformTabStore } from '@/stores/platform-tab'
import { firstVisiblePath } from '@/router/helpers'
@@ -41,10 +41,27 @@ const platformTab = usePlatformTabStore()
const menuEntries = computed(() =>
toSidebarEntries(filterMenuTreeByPlatform(session.menuTree, platformTab.active)),
)
const visibleTabIds = computed(() => visiblePlatformsFor(session.menuTree))
const visibleTabDefs = computed(() => PLATFORM_TABS.filter((tab) => visibleTabIds.value.includes(tab.id)))
const showPlatformTabs = computed(() => visibleTabIds.value.length > 1)
const openedKeys = computed(() => groupKeysForActive(menuEntries.value, route.path))
// 平台锁定(2026-11-18 用户口径「隔离下除站点超管外,京东用户只看京东菜单、亚马逊看不了」):
// tab 可见性 = 站点超管随菜单树分布;其余用户锁 users.platform 那一侧(后端下发树已按平台
// 裁剪,这里再把 tab 收敛到本人平台,单侧时 tab 条整个隐藏)。
const allowedTabIds = computed(() => allowedPlatformsForUser(session.menuTree, session.user))
const visibleTabDefs = computed(() => PLATFORM_TABS.filter((tab) => allowedTabIds.value.includes(tab.id)))
const showPlatformTabs = computed(() => allowedTabIds.value.length > 1)
// 父菜单默认全展开(2026-11-17 用户口径「父菜单不要默认折叠」)。el-menu 的 default-openeds
// 只在挂载时读一次,平台 tab 切换/菜单树刷新导致 entries 变化后新分组不会自动展开,
// 这里在 entries 变更渲染完成后按当下值命令式补开;用户手动收起的组在 entries 不变期间
// 保持收起(watch 不重触发)。读当下 computed 而非触发时快照:快速连切 tab 时不补开已
// 离开渲染树的旧分组(el-menu 的 open 对未注册 index 会抛)。
const menuRef = ref<{ open: (index: string) => void } | null>(null)
const openedKeys = computed(() => allGroupKeys(menuEntries.value))
watch(openedKeys, async () => {
await nextTick()
const menu = menuRef.value
if (!menu) return
for (const key of openedKeys.value) {
menu.open(key)
}
}, { immediate: true })
const emptyMenu = computed(() => shouldShowEmptyMenu(menuEntries.value.length > 0, session.loading, session.initialized))
const pageTitle = computed(() => pageTitleOf(route.meta.title))
const userVm = computed(() => topbarUserOf(session.user))
@@ -59,13 +76,14 @@ watch(
// 直达 URL/面包屑跳到另一平台的页面时,tab 指示自动跟过去(与侧边栏保持一致)。
// 双侧清单里的页面(账号域三页)两个 tab 都算归属:当前 tab 已含它就不动。
// 跟随目标只在允许集(allowedTabIds)里找:被平台锁定的侧不会成为落点。
watch(
() => route.meta.menuKey as string | undefined,
(menuKey) => {
if (!menuKey) return
const owners = platformsOfMenuKey(menuKey)
if (owners.includes(platformTab.active)) return
const target = owners.find((platform) => visibleTabIds.value.includes(platform))
const target = owners.find((platform) => allowedTabIds.value.includes(platform))
if (target && target !== platformTab.active) {
platformTab.setActive(target)
}
@@ -73,6 +91,23 @@ watch(
{ immediate: true },
)
// 平台锁定的归位(2026-11-18):会话就位/菜单树刷新后允许集收敛时,把残留的另一侧 tab
// (超管在同一浏览器切过,localStorage 落的值)归位本人平台;当前页若在被禁侧一并跳回
// 该侧第一可见页。切 tab 的跳转复用下面 platformTab.active 的 watch(active 被 syncToAllowed
// 改写后同链路生效)。
watch(
allowedTabIds,
(allowed) => {
if (!session.user) return
platformTab.syncToAllowed(allowed)
const menuKey = route.meta.menuKey as string | undefined
if (!menuKey || platformsOfMenuKey(menuKey).includes(platformTab.active)) return
const first = firstVisiblePath(filterMenuTreeByPlatform(session.menuTree, platformTab.active))
if (first) void router.replace(first)
},
{ immediate: true },
)
// 切到另一侧 tab 时当前页多半不在那边:跳到该侧第一个可见页;该侧为空(tab 不可见)则不动。
// 双侧清单里的页面(账号域三页)切 tab 不跳转——页面自己按当前平台过滤数据。
watch(
@@ -131,7 +166,7 @@ async function signOut() {
</nav>
<el-scrollbar class="admin-menu-scroll">
<el-menu :default-active="activePath" :default-openeds="openedKeys" router class="admin-menu">
<el-menu ref="menuRef" :default-active="activePath" :default-openeds="openedKeys" router class="admin-menu">
<template v-for="entry in menuEntries" :key="entry.key">
<el-sub-menu v-if="entry.kind === 'group'" :index="entry.key">
<template #title>
+3 -3
View File
@@ -34,11 +34,11 @@ export function toSidebarEntries(nodes: AdminMenuNode[] | null | undefined): Sid
return entries
}
/** 计算需默认展开的分组 key:分组下含当前激活路由子项时返回该分组 key。 */
export function groupKeysForActive(entries: SidebarEntry[], activeRoute: string): string[] {
/** 计算需默认展开的分组 key:父菜单默认全展开(2026-11-17 用户口径「父菜单不要默认折叠」)。 */
export function allGroupKeys(entries: SidebarEntry[]): string[] {
const keys: string[] = []
for (const entry of entries) {
if (entry.kind === 'group' && entry.children.some((child) => child.route === activeRoute)) {
if (entry.kind === 'group') {
keys.push(entry.key)
}
}
@@ -1,5 +1,6 @@
import type { AdminMenuNode } from '../types/admin'
import { PLATFORM_TABS, platformsOfMenuKey } from '../config/platform-scope.ts'
import type { AdminMenuNode, AdminUser } from '../types/admin'
import { isSuperAdminRole } from '../types/admin.ts'
import { PLATFORM_TABS, filterMenuTreeNodesByPlatform } from '../config/platform-scope.ts'
import type { PlatformTabId } from '../config/platform-scope.ts'
import { firstVisiblePath } from '../router/helpers.ts'
@@ -7,27 +8,15 @@ import { firstVisiblePath } from '../router/helpers.ts'
* 按平台 tab 过滤后端菜单树(2026-11-16「亚马逊/京东不混」):**只做显示分组,不做鉴权**——
* 准入仍由 session.menuTree(后端按权限裁剪)与路由守卫负责,这里只是把当前用户已被授权的
* 菜单按平台分到两个 tab 下展示。
* 规则:叶子按 platformsOfMenuKey(key) 是否包含当前平台留下(双侧清单里的账号域三页两个
* tab 都显示);分组节点(admin_group_*)自身的 key 不参与平台判定,按「留住的子项数 > 0」
* 决定去留——否则京东 tab 下「账号与权限」这类混合分组会被整组误剪。节点的 key/name/
* route/children 形状原样透传(浅拷贝不改写),toSidebarEntries、groupKeysForActive 与
* 面包屑都不受影响。
* 规则与算法在 {@link filterMenuTreeNodesByPlatform}(2026-11-17 起唯一出口,账号弹窗授权树
* 同用一份);本壳只钉侧边栏专属的两条:节点的 key/name/route/children 形状原样透传(浅拷贝
* 不改写),toSidebarEntries、groupKeysForActive 与面包屑都不受影响。
*/
export function filterMenuTreeByPlatform(
nodes: AdminMenuNode[] | null | undefined,
platform: PlatformTabId,
): AdminMenuNode[] {
const filtered: AdminMenuNode[] = []
for (const node of nodes || []) {
const children = filterMenuTreeByPlatform(node.children, platform)
if (children.length > 0) {
filtered.push({ ...node, children })
continue
}
if ((node.children || []).length > 0) continue
if (platformsOfMenuKey(node.key || '').includes(platform)) filtered.push({ ...node })
}
return filtered
return filterMenuTreeNodesByPlatform(nodes, platform)
}
/** 当前用户在哪些平台下至少有一个可点页面(tab 显示依据);顺序固定随 PLATFORM_TABS。
@@ -37,3 +26,20 @@ export function visiblePlatformsFor(nodes: AdminMenuNode[] | null | undefined):
.filter((tab) => firstVisiblePath(filterMenuTreeByPlatform(nodes, tab.id)) !== '')
.map((tab) => tab.id)
}
/** 登录用户可用的平台 tab(2026-11-18 用户口径「隔离下除站点超管外,京东用户只看京东菜单、
* 亚马逊看不了」):站点超管不限侧、沿用菜单树分布;其余用户锁 users.platform 那一侧
* (未知/缺省按亚马逊存量口径,与后端 AdminMenuPlatformScope.normalize 同形),与「菜单树
* 该侧有可点页面」求交——交集空则仍回落单侧(管理角色必有双侧账号域页,交集实际非空;
* 宁可锁死自己平台也不放开被禁侧)。会话未就位(user 为空)时按可见分布,锁定的收窄
* 由 AdminLayout 的 watch 在 user 就位后再做。 */
export function allowedPlatformsForUser(
nodes: AdminMenuNode[] | null | undefined,
user: Pick<AdminUser, 'role' | 'platform'> | null | undefined,
): PlatformTabId[] {
const visible = visiblePlatformsFor(nodes)
if (!user || isSuperAdminRole(user.role)) return visible
const own: PlatformTabId = user.platform === 'jd' ? 'jd' : 'amazon'
const allowed = visible.filter((id) => id === own)
return allowed.length > 0 ? allowed : [own]
}
@@ -13,7 +13,9 @@ import {
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { actionableErrorText } from '@/components/admin-feedback'
/** 新建/编辑公司(改名 + 启停 + 备注 + 所属平台 V206);写操作仅超管可用,权限由后端把关。 */
/** 新建/编辑公司(改名 + 启停 + 备注);写操作仅超管可用,权限由后端把关。
* 所属平台不设手选(2026-11-17 用户口径「有京东就不需要亚马逊了,亚马逊那边也是」):
* 平台跟随当前平台 tab——新建取当前 tab(props.platform),编辑保持行值原样下发。 */
const props = defineProps<{ modelValue: boolean; company: CompanyItem | null; platform?: PlatformTabId }>()
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'saved'): void }>()
@@ -77,12 +79,6 @@ async function save() {
placeholder="请输入公司名称(全平台唯一)"
/>
</el-form-item>
<el-form-item label="所属平台">
<el-radio-group v-model="form.platform">
<el-radio-button value="amazon">亚马逊</el-radio-button>
<el-radio-button value="jd">京东</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="状态">
<el-select v-model="form.status" style="width: 100%">
<el-option :value="COMPANY_STATUS_ACTIVE" label="启用" />
@@ -29,7 +29,7 @@ const props = defineProps<{
operatorCompanyId?: number | null
/** 当前公司 tab:这次建号落在哪家,就决定能建哪些角色。 */
activeCompanyId?: number | null
/** 当前平台 tab(V206):新号默认落当前平台,单选可改。 */
/** 当前平台 tab(V206):新号落当前平台(跟随所在 tab,弹窗不再手选——2026-11-17 用户口径)。 */
platform?: PlatformTabId
}>()
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'created'): void }>()
@@ -136,12 +136,6 @@ async function create(): Promise<void> {
<el-option v-for="opt in roleChoices" :key="opt.value" :label="opt.label" :value="opt.value" />
</el-select>
</el-form-item>
<el-form-item label="所属平台">
<el-radio-group v-model="form.platform">
<el-radio-button value="amazon">亚马逊</el-radio-button>
<el-radio-button value="jd">京东</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item
v-if="operatorSuper && form.role === 'company_super_admin'"
label="所属公司"
@@ -184,7 +178,9 @@ async function create(): Promise<void> {
</el-form-item>
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
<div class="auth-tree-box">
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="form.companyId" />
<!-- 授权树按账号平台收(2026-11-17 用户口径):京东 tab 只给京东侧菜单。
平台不再手选(跟随当前 tab),树收窄的判定出口不变。 -->
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="form.companyId" :platform="form.platform" />
</div>
</el-form-item>
</el-form>
@@ -128,12 +128,6 @@ async function save(): Promise<void> {
<el-form-item v-if="targetIsCompanySuperAdmin" label="角色">
<el-input model-value="公司超级管理员" readonly />
</el-form-item>
<el-form-item label="所属平台">
<el-radio-group v-model="form.platform">
<el-radio-button value="amazon">亚马逊</el-radio-button>
<el-radio-button value="jd">京东</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item v-if="expiryEditable" label="到期时间(清空 = 永不过期;到期后该账号及其名下账号将停用)">
<el-date-picker
v-model="form.expiresAt"
@@ -152,7 +146,9 @@ async function save(): Promise<void> {
</el-form-item>
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
<div class="auth-tree-box">
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="props.companyId" />
<!-- 授权树按账号平台收(2026-11-17 用户口径):京东档账号不再整树混发亚马逊菜单。
平台不再手选(跟随当前平台 tab,编辑取行值),树收窄的判定出口不变。 -->
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="props.companyId" :platform="form.platform" />
<div v-if="loadingAuth" class="auth-loading">菜单权限加载中…</div>
<div v-else-if="!authReady" class="auth-loading auth-loading-error">
菜单权限加载失败,保存已禁用;请关闭后重试
@@ -3,6 +3,7 @@ import { computed, onMounted, ref, watch } from 'vue'
import type { AdminUser } from '@/types/admin'
import type { PlatformTabId } from '@/config/platform-scope'
import {
eligibleGroupLeaders,
eligibleGroupMembers,
groupMemberCandidateHint,
validateShopGroupForm,
@@ -19,22 +20,38 @@ const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'save
const session = useAdminSessionStore()
const groupName = ref('')
/** 所属平台(V206):新建默认当前平台 tab,编辑回填分组原值,单选可翻档。 */
/** 所属平台(V206):不设手选(2026-11-17 用户口径「有京东就不需要亚马逊了,亚马逊那边也是」)——
* 新建取当前平台 tab(props.platform),编辑保持分组原值,值仍随保存下发。 */
const groupPlatform = ref<PlatformTabId>('amazon')
const memberIds = ref<number[]>([])
const errorText = ref('')
const busy = ref(false)
const users = ref<AdminUser[]>([])
/** 组长:新建=当前登录用户;编辑=分组原组长(不可改,只读展示)。 */
const leaderUserId = computed<number | null>(() =>
props.group ? (props.group.leaderUserId ?? null) : (session.user?.id ?? null),
)
const leaderUsername = computed<string>(() =>
props.group ? (props.group.leaderUsername || '') : (session.user?.username || '当前登录用户'),
)
/**
* 组长:新建默认当前登录用户,站点超管可下拉改选(2026-11-18 用户口径,后端 validateLeaderOperator
* 对站点超管放行任意 createdById、只要求组长与操作者同公司);编辑=分组原组长(后端更新载荷不收
* 组长,不可改);非站点超管新建时后端强制组长=操作者本人,同样只读展示。
*/
const leaderUserId = ref<number | null>(null)
/** 只有「新建 + 站点超管」出组长下拉;其余场景只读回显。 */
const canPickLeader = computed(() => !props.group && !!props.operatorSuper)
const operatorRole = computed<string>(() => session.user?.role || '')
const leaderUsername = computed<string>(() => {
const picked = leaderUserId.value != null
? users.value.find((u) => u.id === leaderUserId.value)
: null
if (picked) return picked.username
if (props.group) return props.group.leaderUsername || ''
return session.user?.username || '当前登录用户'
})
/** 组长候选:与组员同池(本公司账号),排除公司超管;站点超管仅保留操作者本人。 */
const leaderCandidates = computed(() =>
eligibleGroupLeaders(users.value, operatorRole.value, session.user?.id ?? null),
)
/** 组员候选:按组长归属过滤(超管全量、非超管仅本组长创建的普通账号)。 */
const memberCandidates = computed(() =>
eligibleGroupMembers(users.value, leaderUserId.value, operatorRole.value),
@@ -52,18 +69,29 @@ watch(
groupName.value = props.group.name
memberIds.value = props.group.memberUserIds ?? []
groupPlatform.value = props.group.platform === 'jd' ? 'jd' : 'amazon'
// 编辑保持原值口径:历史行可能没有 leaderUserId(旧负载),回落 null 而不是当前登录人,
// 否则组员候选过滤会跟着悄悄变。
leaderUserId.value = props.group.leaderUserId ?? null
} else {
groupPlatform.value = props.platform ?? 'amazon'
leaderUserId.value = session.user?.id ?? null
}
},
)
// 组长改选后,若该人已被选为组员要立刻摘掉——后端「组长不能作为组员重复加入分组」会打回。
watch(leaderUserId, (id) => {
if (id == null) return
memberIds.value = memberIds.value.filter((v) => v !== id)
})
async function loadCandidates(): Promise<void> {
try {
// 对齐 admin.js loadUserOptions:page=1&page_size=999 全量拉取,避免归属过滤漏人。
// company_id 必带:不带时后端对站点超管返回全平台账号,别家公司的人就会出现在本公司分组的候选里。
// 取的是**组长自己那家**(当前登录用户),不是公司 tab——新建时组长就是操作者本人,
// 按 tab 取人会在超管停在别家 tab 时列出那家的人,保存时被后端"只能添加组长本公司的账号"打回。
// 取操作者自己那家,不是公司 tab——组长候选与组员候选同池,后端要求组长与操作者同公司
// (ensureLeaderSharesOperatorCompany),按 tab 取人会在超管停在别家 tab 时列出保存必被
// 打回的人("只能添加组长本公司的账号")。
const page = await fetchUserList({ page: 1, pageSize: 999, companyId: session.user?.companyId ?? null })
users.value = page.items
} catch (error) {
@@ -85,13 +113,13 @@ async function save(): Promise<void> {
await updateShopGroup(props.group.id, groupName.value, memberIds.value, groupPlatform.value)
showAdminFeedback('更新成功', 'success')
} else {
// 对齐 admin:组长恒为当前登录用户,提交 createdBy=当前用户 id。
const operatorId = session.user?.id ?? 0
if (!operatorId) {
showAdminFeedback('无法获取当前登录用户,请重新登录', 'error')
// 组长默认当前登录用户;站点超管可改选本公司其他账号(createdById=所选组长)。
const leaderId = leaderUserId.value ?? 0
if (!leaderId) {
showAdminFeedback('无法获取组长账号,请重新登录', 'error')
return
}
await createShopGroup(groupName.value, memberIds.value, operatorId, groupPlatform.value)
await createShopGroup(groupName.value, memberIds.value, leaderId, groupPlatform.value)
showAdminFeedback('创建成功', 'success')
}
emit('saved')
@@ -119,14 +147,17 @@ onMounted(loadCandidates)
<el-form-item label="分组名称" :error="errorText || undefined">
<el-input v-model="groupName" placeholder="请输入分组名称" />
</el-form-item>
<el-form-item label="所属平台">
<el-radio-group v-model="groupPlatform">
<el-radio-button value="amazon">亚马逊</el-radio-button>
<el-radio-button value="jd">京东</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="组长">
<el-input :model-value="leaderUsername" readonly placeholder="当前登录用户" />
<el-select
v-if="canPickLeader"
v-model="leaderUserId"
filterable
placeholder="选择组长(默认当前登录用户)"
style="width: 100%"
>
<el-option v-for="u in leaderCandidates" :key="u.id" :label="u.username" :value="u.id" />
</el-select>
<el-input v-else :model-value="leaderUsername" readonly placeholder="当前登录用户" />
</el-form-item>
<el-form-item label="组员">
<el-select
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
import { formatDateTime } from '@/utils/datetime'
/** 分组管理页 · 像素复刻旧版 admin.html panel-group-manage(自绘:顶部数据权限分组摘要 chips + 分组列表表格 + 新建分组;全量无分页同旧版)。
* script 逻辑沿用现有 Vue 实现;编辑器保留现有组件。 */
@@ -51,16 +55,22 @@ function canEditOf(group: ShopGroupItem): boolean {
return currentUserId.value != null && group.leaderUserId != null && currentUserId.value === group.leaderUserId
}
const batchListGate = createLatestRequestGate()
async function loadGroups() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
rows.value = await fetchShopGroups(companyTab.requestCompanyId, platformTab.active)
const items = await fetchShopGroups(companyTab.requestCompanyId, platformTab.active)
if (!batchListGate.isCurrent(token)) return
rows.value = items
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '数据权限分组加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -84,11 +94,24 @@ function openEdit(group: ShopGroupItem) {
editorVisible.value = true
}
const batch = useRowSelection({
pageRows: () => pagedGroups.value,
rowId: (row) => row.id,
rowLabel: (row) => row.name,
deleteOne: (id) => deleteShopGroup(id),
refresh: loadGroups,
blocked: () => loading.value || !!loadFailure.value,
scope: () => [companyTab.activeId, platformTab.active, currentUserId.value],
precheck: (row) => canEditOf(row) ? undefined : '无权删除此分组',
})
async function removeGroup(group: ShopGroupItem) {
if (batch.busy) return
const ok = await openAdminConfirm({ message: `确定删除分组“${group.name}”吗?`, danger: true })
if (!ok) return
try {
await deleteShopGroup(group.id)
batch.removeFromSelection(group.id)
ElMessage.success('删除成功')
await loadGroups()
} catch (error) {
@@ -119,10 +142,15 @@ onMounted(loadGroups)
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadGroups" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 58px">序号</th>
<th style="width: 16%">分组名称</th>
<th style="width: 12%">组长</th>
@@ -135,7 +163,11 @@ onMounted(loadGroups)
</thead>
<tbody>
<template v-if="filteredRows.length">
<tr v-for="(group, index) in pagedGroups" :key="group.id">
<tr v-for="(group, index) in pagedGroups" :key="group.id" :class="{ 'batch-selected': batch.isSelected(group) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(group) || `选择 ${batch.label(group)}`" :checked="batch.isSelected(group)"
:disabled="batch.disabled || !!batch.reason(group)" @change="batch.toggle(group)" />
</td>
<td>{{ index + 1 }}</td>
<td>{{ group.name }}</td>
<td>{{ group.leaderUsername || '-' }}</td>
@@ -151,17 +183,17 @@ onMounted(loadGroups)
<td class="ops-cell">
<template v-if="canEditOf(group)">
<button class="btn btn-sm" type="button" @click="openEdit(group)">编辑</button>
<button class="btn btn-sm btn-danger" type="button" @click="removeGroup(group)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeGroup(group)">删除</button>
</template>
<span v-else class="member-none">-</span>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="8" class="empty-tip">加载中...</td>
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="8" class="empty-tip">{{ filterKeyword || filterLeader ? '暂无匹配分组' : '暂无分组' }}</td>
<td colspan="9" class="empty-tip">{{ filterKeyword || filterLeader ? '暂无匹配分组' : '暂无分组' }}</td>
</tr>
</tbody>
</table>
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
import { formatDateTime } from '@/utils/datetime'
/** 菜单权限配置页 · 像素复刻旧版 admin.html panel-columns(自绘:面板头+新增菜单、拖拽手柄 ⠿、树形缩进+└、旧式表格、全量无分页同旧版)。
* script 逻辑沿用现有 Vue 实现(拖拽分组/落点/重排保存、弹窗表单)。 */
@@ -6,6 +10,8 @@ import { computed, onMounted, reactive, ref, watch } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import OldPagination from '@/components/OldPagination.vue'
import { useCompanyTabStore } from '@/stores/company-tab'
import { usePlatformTabStore } from '@/stores/platform-tab'
import { filterMenuTreeNodesByPlatform } from '@/config/platform-scope'
import { createMenu, deleteMenu, loadMenuManageTree, reorderMenus, updateMenu } from './menu-manage-api'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { openAdminConfirm } from '@/components/admin-confirm'
@@ -31,11 +37,22 @@ import {
interface MenuRow extends MenuManageNode {
depth: number
}
interface PlatformMenuNode extends MenuManageNode {
key: string
children?: PlatformMenuNode[]
}
const companyTab = useCompanyTabStore()
const loading = ref(false)
const loadFailure = ref('')
const rows = ref<MenuManageNode[]>([])
const platformTab = usePlatformTabStore()
// 菜单字典保留全树;显示与父级候选先分平台,再展平分页,避免京东项被亚马逊菜单挤到后页。
const visibleMenuTree = computed(() => {
const withKeys = (nodes: MenuManageNode[]): PlatformMenuNode[] =>
nodes.map((node) => ({ ...node, key: node.columnKey, children: withKeys(node.children || []) }))
return filterMenuTreeNodesByPlatform(withKeys(rows.value), platformTab.active)
})
/** 筛选:菜单名称/类型(用户要求账户域子菜单补筛选条件)。 */
const filterName = ref('')
const filterType = ref('')
@@ -63,14 +80,14 @@ const menuRows = computed<MenuRow[]>(() => {
if (node.children?.length) walk(node.children, depth + 1)
}
}
walk(rows.value, 0)
walk(visibleMenuTree.value, 0)
return out
})
const createVisible = ref(false)
const saving = ref(false)
const editingNode = ref<MenuManageNode | null>(null)
const menuForm = reactive<MenuManageForm>(createMenuForm(null, 0))
const parentOptions = computed(() => menuParentCandidates(rows.value, menuForm.menuType))
const parentOptions = computed(() => menuParentCandidates(visibleMenuTree.value, menuForm.menuType))
const dialogTitle = computed(() => (editingNode.value ? '编辑菜单' : '新增菜单'))
/** 节点 id -> 名称,供「上级菜单」列展示。 */
const nameById = computed(() => {
@@ -87,16 +104,22 @@ function parentNameOf(node: MenuManageNode): string {
return nameById.value.get(node.parentId) ?? `#${node.parentId}`
}
const batchListGate = createLatestRequestGate()
async function loadMenus() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
rows.value = await loadMenuManageTree(companyTab.requestCompanyId)
const items = await loadMenuManageTree(companyTab.requestCompanyId)
if (!batchListGate.isCurrent(token)) return
rows.value = items
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '菜单列表加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -114,7 +137,7 @@ function openEdit(node: MenuManageNode) {
/** 菜单类型切换时:当前父菜单不属于新类型则重置为根。 */
function onMenuTypeChange(): void {
const candidates = menuParentCandidates(rows.value, menuForm.menuType)
const candidates = menuParentCandidates(visibleMenuTree.value, menuForm.menuType)
if (menuForm.parentId != null && !candidates.some((node) => node.id === menuForm.parentId)) {
menuForm.parentId = null
}
@@ -195,7 +218,19 @@ async function saveMenu() {
}
}
const batch = useRowSelection({
pageRows: () => pagedMenuRows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.name,
deleteOne: (id) => deleteMenu(id),
refresh: loadMenus,
blocked: () => loading.value || !!loadFailure.value || saving.value,
scope: () => [companyTab.activeId, platformTab.active],
precheck: (row) => menuDeleteReason(row),
})
async function removeMenu(node: MenuManageNode) {
if (batch.busy) return
const reason = menuDeleteReason(node)
if (reason) {
ElMessage.warning(reason)
@@ -205,6 +240,7 @@ async function removeMenu(node: MenuManageNode) {
if (!(await openAdminConfirm({ message: `确定删除菜单“${node.name}”吗?`, danger: true }))) return
try {
await deleteMenu(node.id)
batch.removeFromSelection(node.id)
ElMessage.success('删除成功')
await loadMenus()
} catch (error) {
@@ -215,6 +251,7 @@ async function removeMenu(node: MenuManageNode) {
/** 切公司:菜单名称/类型是客户端筛选(在 filteredMenuRows 上筛,不进请求),留着上一家填的值
* 就是拿别家的字符串去筛新一家那一套树 ⇒ 首屏「暂无匹配菜单」而输入框里还显示着它;页码回 1
* 是因为新一家的行数不同。末尾的 void loadMenus() 才是本页唯一的数据出口。 */
watch(() => platformTab.active, () => { filterName.value = ''; filterType.value = ''; page.value = 1; createVisible.value = false })
watch(() => companyTab.activeId, () => { filterName.value = ''; filterType.value = ''; page.value = 1; void loadMenus() })
onMounted(loadMenus)
@@ -249,10 +286,15 @@ onMounted(loadMenus)
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadMenus" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll columns-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th class="column-drag-cell"><span class="visually-hidden">排序</span></th>
<th style="width: 60px">ID</th>
<th style="width: 200px">菜单名称</th>
@@ -268,10 +310,14 @@ onMounted(loadMenus)
<tr
v-for="row in pagedMenuRows"
:key="row.id"
:class="{ 'is-column-dragging': dragState?.id === row.id }"
:class="{ 'batch-selected': batch.isSelected(row), 'is-column-dragging': dragState?.id === row.id }"
@dragover="onDragOver($event, row)"
@drop="onDrop($event, row)"
>
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td class="column-drag-cell">
<span
class="column-drag-handle"
@@ -296,7 +342,7 @@ onMounted(loadMenus)
<button
class="btn btn-sm btn-danger"
type="button"
:disabled="menuDeleteReason(row) !== undefined"
:disabled="batch.busy || menuDeleteReason(row) !== undefined"
:title="menuDeleteReason(row) || undefined"
@click="removeMenu(row)"
>
@@ -306,10 +352,10 @@ onMounted(loadMenus)
</tr>
</template>
<tr v-else-if="loading">
<td colspan="8" class="empty-tip">加载中...</td>
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="8" class="empty-tip">{{ filterName || filterType ? '暂无匹配菜单' : '暂无菜单,请先在上方新增' }}</td>
<td colspan="9" class="empty-tip">{{ filterName || filterType ? '暂无匹配菜单' : '暂无菜单,请先在上方新增' }}</td>
</tr>
</tbody>
</table>
@@ -1,10 +1,12 @@
<script setup lang="ts">
import { computed, nextTick, onMounted, ref, watch } from 'vue'
import { filterMenuTreeNodesByPlatform } from '../../config/platform-scope.ts'
import type { PlatformTabId } from '../../config/platform-scope.ts'
import type { MenuOptionNode } from './user-menu-auth'
import { compactDirectGrantIds } from './user-menu-auth'
import { compactDirectGrantIds, pruneCheckedIdsToTree } from './user-menu-auth'
import { fetchGrantableMenus } from './user-menu-auth-api'
const props = defineProps<{ checked?: number[]; companyId?: number | null }>()
const props = defineProps<{ checked?: number[]; companyId?: number | null; platform?: PlatformTabId }>()
const emit = defineEmits<{
(e: 'update:checked', ids: number[]): void
(e: 'load', ok: boolean): void
@@ -17,9 +19,16 @@ const appTree = ref<{ setCheckedKeys(keys: unknown[]): void; getCheckedKeys(): u
const data = ref<MenuOptionNode[]>([])
const loaded = ref(false)
/**
* 按平台过滤后的可见树(2026-11-17 用户口径「授权树也按平台收,选京东就去掉亚马逊的」):
* 平台缺省按亚马逊(历史调用形状)。过滤算法与侧边栏同源(platform-scope 唯一出口),
* 叶子按 menuKey 判定——京东侧=「京东数据库+双侧账号域三件+桌面端京东工具台三件」。
*/
const visibleData = computed(() => filterMenuTreeNodesByPlatform(data.value, props.platform ?? 'amazon'))
/** 两种一级分类…(与 API menuType 分区一致):后台(admin) / 桌面端(app)。 */
const adminNodes = computed(() => data.value.filter((node) => node.type === 'admin'))
const appNodes = computed(() => data.value.filter((node) => node.type === 'app'))
const adminNodes = computed(() => visibleData.value.filter((node) => node.type === 'admin'))
const appNodes = computed(() => visibleData.value.filter((node) => node.type === 'app'))
function applyChecked(): void {
const ids = Array.isArray(props.checked) ? props.checked.filter((id) => typeof id === 'number' && id > 0) : []
@@ -37,7 +46,8 @@ function onCheck(): void {
// 提交前压缩为最小直接授权集:父级已勾选时后代不再重复提交(后端按“父级授权
// 展开全部后代”判断权限,与旧 admin.html 勾父清后代语义一致),
// 并剔除置灰的祖先分组(派生勾选,操作者无权授予)。
emit('update:checked', compactDirectGrantIds(ids, data.value))
// 压缩按「可见树」算:另一侧菜单不在树上,其历史勾选天然进不来。
emit('update:checked', compactDirectGrantIds(ids, visibleData.value))
}
async function load(): Promise<void> {
@@ -49,12 +59,26 @@ async function load(): Promise<void> {
// 渲染完成后再应用已勾选 id,否则作用在空 store 上导致已授权不回显。
await nextTick()
applyChecked()
// 首屏就把勾选集收敛进可见树:编辑一个混档账号(既有亚马逊又有京东授权)时,
// 打开弹窗那一刻就该按当前平台剪掉另一侧,而不是等用户点一下树才剪。
pruneChecked()
} catch {
loaded.value = false
emit('load', false)
}
}
/** 平台切换/首屏后把勾选集收敛进可见树:被过滤掉的另一侧勾选不再随表单提交,
* 否则「京东档账号保存后仍带亚马逊授权」会把平台分侧静默架空。集合没变就不发
* update 事件(避免与父级 v-model 循环互刷)。 */
function pruneChecked(): void {
const pruned = pruneCheckedIdsToTree(props.checked, visibleData.value)
const current = Array.isArray(props.checked) ? props.checked : []
if (pruned.length !== current.length || pruned.some((id, index) => id !== current[index])) {
emit('update:checked', pruned)
}
}
onMounted(load)
watch(
() => props.checked,
@@ -62,6 +86,16 @@ watch(
if (loaded.value) applyChecked()
},
)
/** 平台翻档:可见树整棵换,勾选集同步收敛到新树并回显(被剪掉的勾选以 emit 形式
* 落回表单,父级拿到的是纯当前平台的授权集)。 */
watch(
() => props.platform,
() => {
if (!loaded.value) return
pruneChecked()
void nextTick().then(applyChecked)
},
)
/** 公司换了要整棵重取:勾选集里存的是 column id,别家同名菜单是另一份 id(V149 每公司一套树),
* 拿别家的树勾出来的 id 提交会被后端判「无效的菜单权限项」,而已授权项也因为 id 不在这棵树上勾不上。 */
watch(
@@ -0,0 +1,274 @@
/* 像素复刻旧版 admin.html 面板风格(与店铺密钥页同一视觉语言)。 */
.user-secrets-view {
font-family: inherit;
color: #24384d;
}
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.secrets-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.secrets-filter-row {
margin: 0 0 16px;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 18px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.filter-actions {
display: flex;
gap: 10px;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-ghost {
background: #ffffff;
border-color: #c7d7e5;
color: #4f78a5;
box-shadow: none;
}
.btn-ghost:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.secrets-table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.secrets-table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
min-width: 1440px;
}
.secrets-table-scroll th,
.secrets-table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.secrets-table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.secrets-table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.secrets-table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.user-name {
color: #24384d;
font-weight: 600;
/* 用户名(含中文)可完整换行展示,不截断 */
white-space: normal;
overflow-wrap: anywhere;
}
.creator-name {
color: #5b6f83;
font-size: 12.5px;
}
.module-cell {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
/* 代理列:脱敏地址独占一行,状态药丸另起一行(列宽按最长药丸文案留的,不按整条链接) */
.module-cell--stack {
flex-direction: column;
align-items: flex-start;
gap: 6px;
}
.module-cell .mono-mask {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
/* 代理列只显示后端脱敏后的 scheme://host(短串,单行足够)。
这里**不许**再出现"允许折行展示完整明文 + user-select:all"那套样式:
它等于给整条带 key/pwd 的链接做了一键全选复制的旁路(2026-11-02 脱敏收口时一并拆掉)。 */
.mono-mask {
font-family: Consolas, "Cascadia Mono", monospace;
font-size: 12.5px;
letter-spacing: 0.5px;
}
.empty-value {
color: #a7b4c1;
}
/* 余额列:数字按等宽数位对齐(两行叠着看差值才不用竖着对),超长进 title。 */
.balance-line {
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-variant-numeric: tabular-nums;
font-size: 12.5px;
color: #2f4256;
}
.ops-cell {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.empty-tip {
color: #8293a5;
text-align: center;
}
.wh-pill {
display: inline-flex;
align-items: center;
padding: 2px 10px;
border-radius: 999px;
border: 1px solid;
font-size: 12px;
line-height: 1.7;
cursor: help;
flex-shrink: 0;
}
.wh-pill.is-source {
background: #eef2fb;
border-color: #ccd8f2;
color: #3d5a99;
font-weight: 600;
}
.wh-pill.is-allowed {
background: #e8f6ee;
border-color: #b9e0c9;
color: #2f7d52;
}
.wh-pill.is-blocked {
background: #fdecef;
border-color: #f2c4cd;
color: #b04a5a;
}
.wh-pill.is-warn {
background: #fdf6e3;
border-color: #f0dfae;
color: #8f6d1e;
}
/* 「等一会再点」这一族(无可用通道/限流/超时/网络/上游):既不红(密钥没坏)
也不黄(不是欠费)更不是灰(不是查不出),独立一档青色——三种处置一眼分开。 */
.wh-pill.is-retry {
background: #e6f2f7;
border-color: #b6d8e6;
color: #2b6b86;
}
.wh-pill.is-unknown {
background: #f0f3f6;
border-color: #d6dee6;
color: #6b7d8f;
}
.wh-pill.is-locked {
background: #f0ecfb;
border-color: #d5caf0;
color: #5b4a96;
}
.module-cell-pills {
display: inline-flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
import { computed, onMounted, ref, watch } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDateTime } from '@/utils/datetime'
@@ -128,7 +132,10 @@ function rowStatusTooltip(row: AdminUserSecretRow) {
return parts.join(';') || '暂无检测记录'
}
const batchListGate = createLatestRequestGate()
async function load() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
@@ -140,15 +147,17 @@ async function load() {
page: page.value,
pageSize: pageSize.value,
})
if (!batchListGate.isCurrent(token)) return
rows.value = result?.items || []
total.value = Number(result?.total || 0)
groupOptions.value = result?.groupOptions || []
void loadBalances()
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -247,11 +256,25 @@ async function check(row: AdminUserSecretRow) {
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.userId,
rowLabel: (row) => row.username || `UID ${row.userId}`,
deleteOne: (id) => deleteUserSecret(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
scope: () => companyTab.activeId,
consequence: '将清空这些用户的全部密钥与代理配置;后台锁定的代理也会一并清除并解锁,用户需要重新配置。',
verb: '清空',
})
async function remove(row: AdminUserSecretRow) {
if (batch.busy) return
const who = row.username || `UID ${row.userId}`
if (!(await openAdminConfirm({ message: `确定清空「${who}」的全部密钥与代理配置吗?后台锁定的代理会一并清除并解锁,该用户需要重新配置。`, danger: true }))) return
try {
await deleteUserSecret(row.userId)
batch.removeFromSelection(row.userId)
ElMessage.success('已清空')
load()
} catch (error) {
@@ -361,10 +384,15 @@ onMounted(load)
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="secrets-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 58px">序号</th>
<th style="width: 260px">用户</th>
<th v-if="isSuperAdmin" style="width: 130px">分组</th>
@@ -381,7 +409,11 @@ onMounted(load)
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="(row, index) in rows" :key="row.userId">
<tr v-for="(row, index) in rows" :key="row.userId" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td>{{ (page - 1) * pageSize + index + 1 }}</td>
<td>
<span class="user-name">{{ row.username || '—' }}</span>
@@ -483,15 +515,15 @@ onMounted(load)
>
解锁
</button>
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">清空</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">清空</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td :colspan="isSuperAdmin ? 12 : 11" class="empty-tip">加载中...</td>
<td :colspan="isSuperAdmin ? 13 : 12" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td :colspan="isSuperAdmin ? 12 : 11" class="empty-tip">{{ keyword || statusFilter || groupFilter ? '暂无匹配记录' : '暂无用户密钥记录' }}</td>
<td :colspan="isSuperAdmin ? 13 : 12" class="empty-tip">{{ keyword || statusFilter || groupFilter ? '暂无匹配记录' : '暂无用户密钥记录' }}</td>
</tr>
</tbody>
</table>
@@ -511,279 +543,4 @@ onMounted(load)
</div>
</template>
<style scoped>
/* 像素复刻旧版 admin.html 面板风格(与店铺密钥页同一视觉语言)。 */
.user-secrets-view {
font-family: inherit;
color: #24384d;
}
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.secrets-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.secrets-filter-row {
margin: 0 0 16px;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 18px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.filter-actions {
display: flex;
gap: 10px;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-ghost {
background: #ffffff;
border-color: #c7d7e5;
color: #4f78a5;
box-shadow: none;
}
.btn-ghost:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.secrets-table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.secrets-table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
min-width: 1440px;
}
.secrets-table-scroll th,
.secrets-table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.secrets-table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.secrets-table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.secrets-table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.user-name {
color: #24384d;
font-weight: 600;
/* 用户名(含中文)可完整换行展示,不截断 */
white-space: normal;
overflow-wrap: anywhere;
}
.creator-name {
color: #5b6f83;
font-size: 12.5px;
}
.module-cell {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
/* 代理列:脱敏地址独占一行,状态药丸另起一行(列宽按最长药丸文案留的,不按整条链接) */
.module-cell--stack {
flex-direction: column;
align-items: flex-start;
gap: 6px;
}
.module-cell .mono-mask {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
/* 代理列只显示后端脱敏后的 scheme://host(短串,单行足够)。
这里**不许**再出现"允许折行展示完整明文 + user-select:all"那套样式:
它等于给整条带 key/pwd 的链接做了一键全选复制的旁路(2026-11-02 脱敏收口时一并拆掉)。 */
.mono-mask {
font-family: Consolas, "Cascadia Mono", monospace;
font-size: 12.5px;
letter-spacing: 0.5px;
}
.empty-value {
color: #a7b4c1;
}
/* 余额列:数字按等宽数位对齐(两行叠着看差值才不用竖着对),超长进 title。 */
.balance-line {
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-variant-numeric: tabular-nums;
font-size: 12.5px;
color: #2f4256;
}
.ops-cell {
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.empty-tip {
color: #8293a5;
text-align: center;
}
.wh-pill {
display: inline-flex;
align-items: center;
padding: 2px 10px;
border-radius: 999px;
border: 1px solid;
font-size: 12px;
line-height: 1.7;
cursor: help;
flex-shrink: 0;
}
.wh-pill.is-source {
background: #eef2fb;
border-color: #ccd8f2;
color: #3d5a99;
font-weight: 600;
}
.wh-pill.is-allowed {
background: #e8f6ee;
border-color: #b9e0c9;
color: #2f7d52;
}
.wh-pill.is-blocked {
background: #fdecef;
border-color: #f2c4cd;
color: #b04a5a;
}
.wh-pill.is-warn {
background: #fdf6e3;
border-color: #f0dfae;
color: #8f6d1e;
}
/* 「等一会再点」这一族(无可用通道/限流/超时/网络/上游):既不红(密钥没坏)
也不黄(不是欠费)更不是灰(不是查不出),独立一档青色——三种处置一眼分开。 */
.wh-pill.is-retry {
background: #e6f2f7;
border-color: #b6d8e6;
color: #2b6b86;
}
.wh-pill.is-unknown {
background: #f0f3f6;
border-color: #d6dee6;
color: #6b7d8f;
}
.wh-pill.is-locked {
background: #f0ecfb;
border-color: #d5caf0;
color: #5b4a96;
}
.module-cell-pills {
display: inline-flex;
align-items: center;
gap: 6px;
flex-wrap: wrap;
}
</style>
<style scoped src="./UserSecretsPage.css"></style>
@@ -1,4 +1,7 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { formatDateTime } from '@/utils/datetime'
/** 用户管理页 · 像素复刻旧版 admin.html panel-users(自绘:panel-box + 页头按钮 + 筛选 form-row + 旧式表格/分页 + 原生 confirm 删除)。
* script 逻辑沿用现有 Vue 实现;创建/编辑弹窗保留现有组件(含用户菜单权限树)。 */
@@ -122,7 +125,19 @@ function search() {
void loadUsers()
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.username,
deleteOne: (id) => deleteUser(id),
refresh: loadUsers,
blocked: () => loading.value || !!loadError.value,
scope: () => [companyTab.activeId, platformTab.active, currentUserId.value],
precheck: (row) => deleteBlockReason(row, currentUserId.value),
})
async function removeUser(row: AdminUser) {
if (batch.busy) return
const reason = deleteBlockReason(row, currentUserId.value)
if (reason) {
ElMessage.warning(reason)
@@ -132,6 +147,7 @@ async function removeUser(row: AdminUser) {
if (!(await openAdminConfirm({ message: deleteConfirmMessage(row), danger: true }))) return
try {
await deleteUser(row.id)
batch.removeFromSelection(row.id)
ElMessage.success('删除成功')
await loadUsers()
} catch (error) {
@@ -248,10 +264,15 @@ onMounted(() => {
<button class="btn btn-sm btn-secondary" type="button" @click="retry">重试</button>
</div>
<BatchDeleteActions :batch="batch" />
<div class="table-scroll user-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 70px">ID</th>
<th style="width: 180px">用户名</th>
<th style="width: 140px">角色</th>
@@ -266,7 +287,11 @@ onMounted(() => {
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="row in rows" :key="row.id">
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td>{{ row.id }}</td>
<td>{{ row.username }}</td>
<td>{{ roleLabel(row.role) }}</td>
@@ -302,7 +327,7 @@ onMounted(() => {
<button
class="btn btn-sm btn-danger"
type="button"
:disabled="deleteBlockReason(row, currentUserId) !== undefined"
:disabled="batch.busy || deleteBlockReason(row, currentUserId) !== undefined"
:title="deleteBlockReason(row, currentUserId) || undefined"
@click="removeUser(row)"
>
@@ -312,10 +337,10 @@ onMounted(() => {
</tr>
</template>
<tr v-else-if="loading">
<td :colspan="isJdSide ? 10 : 9" class="empty-tip">加载中...</td>
<td :colspan="isJdSide ? 11 : 10" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td :colspan="isJdSide ? 10 : 9" class="empty-tip">{{ userListEmptyHint() }}</td>
<td :colspan="isJdSide ? 11 : 10" class="empty-tip">{{ userListEmptyHint() }}</td>
</tr>
</tbody>
</table>
@@ -155,6 +155,30 @@ export function eligibleGroupMembers(
})
}
/**
* 组长候选(2026-11-18 用户口径「新建分组组长要能下拉选」):
* - 公司超管永不领衔——与组员「超级管理员不属于任何分组」同源,它是本公司最高账号;
* - 站点超管只保留操作者本人(admin 保持「自己领衔建组」的既有能力,其余站点超管不进候选);
* - 管理员与普通账号均可领衔(普通账号当组长有既有文案背书:「当前账号只能作为组长使用」)。
*
* 后端契约:站点超管走 `validateLeaderOperator` 放行通道,可给任意 `createdById` 建组,
* 但组长必须与操作者同公司(`ensureLeaderSharesOperatorCompany`)——候选池天然同公司(按操作者
* companyId 拉取),不会列出后端要打回的人。非超管操作者不出下拉(后端强制组长=操作者本人)。
*/
export function eligibleGroupLeaders(
users: GroupMemberCandidateUser[],
operatorRole: string,
operatorId: number | null,
): GroupMemberCandidateUser[] {
const operatorKey = operatorId != null && operatorId > 0 ? String(operatorId) : ''
const operatorIsSiteSuper = isSuperAdminRole(operatorRole)
return users.filter((u) => {
if (!isGroupIneligibleRole(u.role)) return true
// 两档超管默认不领衔;站点超管只保留操作者本人这一个例外。
return operatorIsSiteSuper && String(u.id) === operatorKey
})
}
/** 组员候选帮助文案(对齐 admin.js:3179-3182)。 */
export function groupMemberCandidateHint(candidateCount: number, operatorRole: string): string {
if (candidateCount > 0) return '可添加当前组长创建的普通员工账号'
@@ -22,7 +22,7 @@ export interface CreateUserForm {
expiresAt: string
/** 所属公司 id:仅 role=company_super_admin 时由站点超管必选(2026-10-05 需求)。 */
companyId?: number | null
/** 所属平台(V206):弹窗打开时预填当前平台 tab,单选可改。 */
/** 所属平台(V206):弹窗打开时预填当前平台 tab(不设手选——2026-11-17 用户口径)。 */
platform: PlatformTabId
}
@@ -46,7 +46,7 @@ export interface CreateUserPayload {
* 反向钉(company-user-create.test.ts)唯一豁免的例外:公司超管必须落指定公司,
* 否则会静默落操作者自己的公司(公司 1),用户需求就是给别家公司开超管。 */
companyId?: number
/** 所属平台(V206):恒下发(弹窗单选默认当前平台 tab),缺省后端落 amazon。 */
/** 所属平台(V206):恒下发(预填当前平台 tab),缺省后端落 amazon。 */
platform: PlatformTabId
}
@@ -20,7 +20,7 @@ export interface EditUserForm {
originalRole: string
/** 到期时间(yyyy-MM-dd HH:mm:ss);空串 = 永不过期。null = 后端本来就无到期。 */
expiresAt: string
/** 所属平台(V206):单选可翻档,未知/缺省归亚马逊(存量默认)。 */
/** 所属平台(V206):编辑回填行值(不设手选——2026-11-17 用户口径),未知/缺省归亚马逊(存量默认)。 */
platform: PlatformTabId
}
@@ -38,7 +38,7 @@ export interface EditUserUpdateRequest {
password?: string
/** 到期时间:空串=清除(恢复永不过期),有值=改期;总是下发(与后端"传了就更新"对齐)。 */
expiresAt: string
/** 所属平台(V206):总是下发(弹窗单选恒渲染),翻档即把记录挪到另一平台的列表。 */
/** 所属平台(V206):总是下发(编辑保持行值原样,后端显式才落)。 */
platform: PlatformTabId
}
@@ -146,3 +146,24 @@ export function compactDirectGrantIds(checkedIds: unknown, tree: MenuOptionNode[
walk(tree, false)
return ids.filter((id) => !ungrantable.has(id) && !coveredByAncestor.has(id))
}
/**
* 把勾选集收敛到「可见树」内(2026-11-17 用户口径「授权树按平台收」的另一半):
* 授权树按平台过滤后,另一侧的已勾 id 在树上不可见、也不再属于这棵树——它们必须
* 从表单勾选集里剔除,否则「京东档账号」保存后仍携带整批亚马逊菜单授权(侧边栏
* 亚马逊 tab 照样全亮,平台分侧被静默架空)。纯函数:入参不动,返回去重升序交集。
*/
export function pruneCheckedIdsToTree(checkedIds: unknown, visibleTree: MenuOptionNode[]): number[] {
const ids = normalizeMenuIds(checkedIds)
if (ids.length === 0) return []
if (visibleTree.length === 0) return []
const visible = new Set<number>()
const walk = (nodes: MenuOptionNode[]): void => {
for (const node of nodes) {
visible.add(node.id)
if (node.children?.length) walk(node.children)
}
}
walk(visibleTree)
return ids.filter((id) => visible.has(id))
}
@@ -1,4 +1,7 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { formatDateTime } from '@/utils/datetime'
/** 品牌数据库(不符合ASIN)页 · 像素复刻旧版 admin.html panel-invalid-asin-data(自绘:面板头+新增、筛选、旧式表格/分页、原生 confirm 删除)。
* 全平台一份黑名单:分组是行上的归类标签,对任何角色都不构成可见性边界(2026-10-07 定档)。
@@ -130,11 +133,22 @@ async function submit() {
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.dataValue,
deleteOne: (id) => deleteInvalidAsin(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
})
async function remove(row: InvalidAsinItem) {
if (batch.busy) return
// 对齐旧版:原生 confirm。
if (!(await openAdminConfirm({ message: invalidAsinDeleteText(row), danger: true }))) return
try {
await deleteInvalidAsin(row.id)
batch.removeFromSelection(row.id)
ElMessage.success('已删除')
load()
} catch (error) {
@@ -157,17 +171,17 @@ onMounted(() => {
</div>
<div class="form-row invalid-filter-row">
<div class="form-group" style="min-width: 200px">
<label>ASIN</label>
<input v-model="filter.dataValue" type="text" placeholder="输入 ASIN" @keyup.enter="apply" />
<div class="form-group">
<label for="invalid-asin-filter">ASIN</label>
<input id="invalid-asin-filter" v-model="filter.dataValue" type="text" placeholder="输入 ASIN" @keyup.enter="apply" />
</div>
<div class="form-group" style="min-width: 200px">
<label>品牌</label>
<input v-model="filter.brand" type="text" placeholder="输入品牌" @keyup.enter="apply" />
<div class="form-group">
<label for="invalid-brand-filter">品牌</label>
<input id="invalid-brand-filter" v-model="filter.brand" type="text" placeholder="输入品牌" @keyup.enter="apply" />
</div>
<div class="form-group" style="min-width: 180px">
<label>分组</label>
<el-select v-model="filter.groupId" class="admin-filter" filterable clearable placeholder="全部分组">
<div class="form-group">
<label for="invalid-group-filter">分组</label>
<el-select id="invalid-group-filter" v-model="filter.groupId" class="admin-filter" filterable clearable placeholder="全部分组">
<el-option v-for="group in groupOptions" :key="group.id" :label="group.groupName" :value="group.id" />
</el-select>
</div>
@@ -175,10 +189,15 @@ onMounted(() => {
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll invalid-asin-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 70px">ID</th>
<th style="width: 170px">ASIN</th>
<th style="width: 150px">品牌</th>
@@ -191,7 +210,11 @@ onMounted(() => {
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="row in rows" :key="row.id">
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td>{{ row.id }}</td>
<td class="mono-cell">{{ row.dataValue }}</td>
<td>{{ row.brand || '—' }}</td>
@@ -205,15 +228,15 @@ onMounted(() => {
<td>{{ formatDateTime(row.updatedAt) }}</td>
<td class="ops-cell">
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">删除</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="8" class="empty-tip">加载中...</td>
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="8" class="empty-tip">暂无数据</td>
<td colspan="9" class="empty-tip">暂无数据</td>
</tr>
</tbody>
</table>
@@ -270,7 +293,7 @@ h3 {
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
margin-bottom: 10px;
}
.form-row {
display: flex;
@@ -285,6 +308,11 @@ h3 {
gap: 7px;
margin-bottom: 0;
}
.invalid-filter-row > .form-group {
flex: 0 1 190px;
min-width: 0;
max-width: 100%;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
@@ -0,0 +1,348 @@
/* 像素复刻旧版 admin.html panel-dedupe-total-data(蓝白末层样式)。 */
.dedupe-view {
font-family: inherit;
color: var(--c-text, #24384d);
display: flex;
flex-direction: column;
gap: 18px;
}
.form-box,
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0 0 16px;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.dedupe-panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.dedupe-panel-head h3 {
margin: 0;
}
.dedupe-head-actions {
display: flex;
gap: 10px;
}
.dedupe-filter-row {
display: grid;
grid-template-columns: repeat(4, minmax(160px, 1fr)) auto;
gap: 12px;
align-items: end;
margin-bottom: 16px;
}
.dedupe-filter-row .form-group {
min-width: 0;
}
.dedupe-filter-actions {
display: flex;
gap: 10px;
align-items: center;
white-space: nowrap;
}
.dedupe-filter-date-row {
display: flex;
gap: 12px;
align-items: flex-end;
flex-wrap: wrap;
margin-bottom: 16px;
}
.dedupe-filter-date-row .form-group {
flex: 0 0 200px;
min-width: 0;
}
.dedupe-filter-date-row .dedupe-filter-actions {
margin-left: auto;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.form-group input[type="file"] {
background: #ffffff;
padding: 6px 10px;
}
.form-group input[type="date"] {
color-scheme: light;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.6;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.dedupe-table-scroll > table {
min-width: 900px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.mono-cell {
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
font-size: 12.5px;
}
.ops-cell {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
text-align: right;
flex-wrap: wrap;
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
.page-jump input {
width: 56px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 3000;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.modal {
display: flex;
flex-direction: column;
width: min(560px, 100%);
max-height: 84vh;
padding: 22px 24px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
overflow-y: auto;
}
.modal .form-group {
margin-bottom: 14px;
}
.modal-actions {
display: flex;
gap: 10px;
margin-top: 16px;
}
.progress-wrap {
margin-top: 12px;
}
.progress-text {
font-size: 12.5px;
color: #5b6f83;
line-height: 1.6;
}
.dedupe-export-wait-mask {
position: fixed;
inset: 0;
z-index: 3100;
display: flex;
align-items: center;
justify-content: center;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.dedupe-export-wait {
display: flex;
align-items: center;
gap: 14px;
padding: 22px 28px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
}
.request-spinner {
width: 26px;
height: 26px;
flex: none;
border: 3px solid #d5e3ef;
border-top-color: #5f85ad;
border-radius: 50%;
animation: dedupe-spin 0.9s linear infinite;
}
@keyframes dedupe-spin {
to { transform: rotate(360deg); }
}
.dedupe-export-wait-title {
font-size: 15px;
font-weight: 600;
color: #24384d;
}
.dedupe-export-wait-detail {
margin-top: 4px;
font-size: 12.5px;
color: #5b6f83;
}
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
import { formatDateTime, orderedPair } from '@/utils/datetime'
/** 数据去重总数据(registry) · 像素复刻旧版 admin.html panel-dedupe-total-data(自绘:分组摘要 + 双行筛选 + 旧式表格/分页 + 编辑/导入弹窗 + 导出等待遮罩)。
* script 逻辑沿用现有 Vue 实现(查询/编辑/删除/导入轮询/导出秒表)。 */
@@ -107,13 +111,17 @@ function stopExportWait(): void {
exportWaitVisible.value = false
}
const batchListGate = createLatestRequestGate()
async function load(): Promise<void> {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
const result = await fetchDedupeTotalList(
toDedupeListParams(filter, page.value, pageSize.value, pendingCursor, companyTab.requestCompanyId),
)
if (!batchListGate.isCurrent(token)) return
rows.value = result.items
total.value = result.total
if (result.page >= 1) page.value = result.page
@@ -121,10 +129,11 @@ async function load(): Promise<void> {
pageCursor.value = result.nextLastId ?? null
pendingCursor = null
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = loadFailureMessage(error, '去重数据加载失败')
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -192,11 +201,23 @@ async function saveEdit(): Promise<void> {
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.dataValue,
deleteOne: (id) => deleteDedupeTotal(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
scope: () => companyTab.activeId,
})
async function removeRow(row: DedupeTotalItem): Promise<void> {
if (batch.busy) return
// 对齐旧版:浏览器原生 confirm 确认后删除。
if (!(await openAdminConfirm({ message: `确定删除总数据“${row.dataValue}”吗?`, danger: true }))) return
try {
await deleteDedupeTotal(row.id)
batch.removeFromSelection(row.id)
ElMessage.success('删除成功')
await load()
} catch (error) {
@@ -408,10 +429,15 @@ onUnmounted(() => {
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll dedupe-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th>ID</th>
<th>ASIN</th>
<th>国家</th>
@@ -424,7 +450,11 @@ onUnmounted(() => {
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="row in rows" :key="row.id">
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td>{{ row.id }}</td>
<td class="mono-cell">{{ row.dataValue }}</td>
<td>{{ asinCountryLabel(row.country || '') }}</td>
@@ -434,15 +464,15 @@ onUnmounted(() => {
<td>{{ formatDateTime(row.updatedAt) }}</td>
<td class="ops-cell">
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
<button class="btn btn-sm btn-danger" type="button" @click="removeRow(row)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeRow(row)">删除</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">加载中...</td>
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">暂无总数据</td>
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">暂无总数据</td>
</tr>
</tbody>
</table>
@@ -541,353 +571,4 @@ onUnmounted(() => {
</div>
</template>
<style scoped>
/* 像素复刻旧版 admin.html panel-dedupe-total-data(蓝白末层样式)。 */
.dedupe-view {
font-family: inherit;
color: var(--c-text, #24384d);
display: flex;
flex-direction: column;
gap: 18px;
}
.form-box,
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0 0 16px;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.dedupe-panel-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.dedupe-panel-head h3 {
margin: 0;
}
.dedupe-head-actions {
display: flex;
gap: 10px;
}
.dedupe-filter-row {
display: grid;
grid-template-columns: repeat(4, minmax(160px, 1fr)) auto;
gap: 12px;
align-items: end;
margin-bottom: 16px;
}
.dedupe-filter-row .form-group {
min-width: 0;
}
.dedupe-filter-actions {
display: flex;
gap: 10px;
align-items: center;
white-space: nowrap;
}
.dedupe-filter-date-row {
display: flex;
gap: 12px;
align-items: flex-end;
flex-wrap: wrap;
margin-bottom: 16px;
}
.dedupe-filter-date-row .form-group {
flex: 0 0 200px;
min-width: 0;
}
.dedupe-filter-date-row .dedupe-filter-actions {
margin-left: auto;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.form-group input[type="file"] {
background: #ffffff;
padding: 6px 10px;
}
.form-group input[type="date"] {
color-scheme: light;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.6;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.dedupe-table-scroll > table {
min-width: 900px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.mono-cell {
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
font-size: 12.5px;
}
.ops-cell {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
text-align: right;
flex-wrap: wrap;
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
.page-jump input {
width: 56px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.modal-mask {
position: fixed;
inset: 0;
z-index: 3000;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.modal {
display: flex;
flex-direction: column;
width: min(560px, 100%);
max-height: 84vh;
padding: 22px 24px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
overflow-y: auto;
}
.modal .form-group {
margin-bottom: 14px;
}
.modal-actions {
display: flex;
gap: 10px;
margin-top: 16px;
}
.progress-wrap {
margin-top: 12px;
}
.progress-text {
font-size: 12.5px;
color: #5b6f83;
line-height: 1.6;
}
.dedupe-export-wait-mask {
position: fixed;
inset: 0;
z-index: 3100;
display: flex;
align-items: center;
justify-content: center;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.dedupe-export-wait {
display: flex;
align-items: center;
gap: 14px;
padding: 22px 28px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
}
.request-spinner {
width: 26px;
height: 26px;
flex: none;
border: 3px solid #d5e3ef;
border-top-color: #5f85ad;
border-radius: 50%;
animation: dedupe-spin 0.9s linear infinite;
}
@keyframes dedupe-spin {
to { transform: rotate(360deg); }
}
.dedupe-export-wait-title {
font-size: 15px;
font-weight: 600;
color: #24384d;
}
.dedupe-export-wait-detail {
margin-top: 4px;
font-size: 12.5px;
color: #5b6f83;
}
</style>
<style scoped src="./DedupeRegistryPage.css"></style>
@@ -0,0 +1,287 @@
/* 像素复刻旧版 admin.html panel-product-categories(蓝白末层)。 */
.category-view {
font-family: inherit;
color: #24384d;
}
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.category-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.category-head-tools {
display: flex;
align-items: center;
gap: 8px;
}
.category-keyword {
width: 240px;
min-height: 36px;
padding: 6px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.category-keyword:hover {
border-color: #9fb7cd;
}
.category-keyword:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.category-table-scroll > table {
/* table-layout:fixed 下,没写宽度的列在容器变窄时第一个被压到 0(10-06 截图:层级路径只剩一个字、
备注只剩破折号)。承重的是 thead 里 8 列全部显式 px 定宽;这个下限与它们成对维护,
数值由 tests/align-product-category.test.ts 从 markup 现算比对,改列宽要同时改这里。 */
min-width: 1262px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.tree-name-cell {
display: flex;
align-items: center;
gap: 6px;
min-height: 24px;
cursor: pointer;
}
.tree-indent {
flex: 0 0 auto;
display: inline-block;
}
.tree-node-mark {
width: 20px;
height: 20px;
border: 0;
border-radius: 5px;
background: var(--admin-primary-soft, #e7f0f8);
color: var(--admin-primary-strong, #2f5d8b);
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 13px;
font-weight: 700;
cursor: pointer;
padding: 0;
line-height: 1;
flex: none;
transition: background 0.12s ease, color 0.12s ease;
}
.tree-node-mark:not(.is-leaf):hover {
background: var(--admin-primary-strong, #2f5d8b);
color: #ffffff;
}
.tree-node-mark.is-leaf {
background: transparent;
cursor: default;
}
.node-name {
font-weight: 600;
color: #24384d;
white-space: nowrap;
}
.selected-flag {
padding: 1px 8px;
border-radius: 999px;
background: #e7f0f8;
color: #2f5d8b;
font-size: 11px;
}
.category-tag {
padding: 2px 8px;
border-radius: 6px;
border: 1px solid #c2d5e6;
background: #e7f0f8;
color: #2f5d8b;
font-size: 12px;
}
.category-tag.is-custom {
border-color: #bcd9c6;
background: #eef7f0;
color: #3d7158;
}
.category-path-value {
display: block;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.node-desc {
color: #5b6f83;
font-size: 12px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 320px;
display: inline-block;
vertical-align: middle;
}
.dim {
color: #8293a5;
}
.ops-cell {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.load-more-row td {
background: #fbfdfe;
}
.load-more-cell {
display: flex;
align-items: center;
gap: 8px;
}
.loaded-count {
color: #8293a5;
font-size: 12.5px;
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
@@ -1,4 +1,7 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
/** 商品类目 · 像素复刻旧版 admin.html panel-product-categories(自绘:面板头搜索框组+新增类目 同行、原生树表格[+/−]折叠+懒加载「加载更多 已加载 x/y」、搜索态旧式分页)。
* script 逻辑沿用现有 Vue 实现(懒加载树/编辑删除/导出/弹窗)。 */
import { computed, onMounted, reactive, ref } from 'vue'
@@ -257,7 +260,21 @@ function canDelete(node: ProductCategoryNode | null): boolean {
return !(node.childCount > 0 || (Array.isArray(node.children) && node.children.some((child) => !isCategoryLoadMoreNode(child))))
}
const batch = useRowSelection({
pageRows: () => searching.value ? searchRows.value : treeRows.value.map(({ node }) => node),
rowId: (row) => row.id,
rowLabel: (row) => row.path || row.name,
deleteOne: async (id) => {
await deleteProductCategory(id)
if (selected.value?.id === id) selected.value = null
},
refresh: () => searching.value ? runSearch(1) : loadTree(),
blocked: () => loading.value || searchLoading.value || saving.value,
precheck: (row) => canDelete(row) ? undefined : '存在子类目,不能删除',
})
async function removeCategory(node: ProductCategoryNode): Promise<void> {
if (batch.busy) return
if (!canDelete(node)) {
ElMessage.warning('存在子类目,不能删除')
return
@@ -266,6 +283,7 @@ async function removeCategory(node: ProductCategoryNode): Promise<void> {
if (!(await openAdminConfirm({ message: `确定删除“${node.name}”?`, danger: true }))) return
try {
await deleteProductCategory(node.id)
batch.removeFromSelection(node.id)
ElMessage.success('已删除')
if (selected.value?.id === node.id) selected.value = null
if (searching.value) void runSearch(1)
@@ -318,7 +336,7 @@ onMounted(loadTree)
<section class="panel-box">
<div class="category-head">
<h3>商品类目</h3>
<div class="category-head-tools">
<div class="category-head-tools admin-header-controls">
<input v-model="keyword" type="text" placeholder="搜索类目名称、编码或备注" class="category-keyword" @keyup.enter="apply" />
<button class="btn btn-sm" type="button" @click="apply">搜索</button>
<button class="btn btn-sm btn-secondary" type="button" @click="reset">清空</button>
@@ -329,10 +347,15 @@ onMounted(loadTree)
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadTree" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll category-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col" style="width: 38px">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 220px">类目</th>
<th style="width: 230px">层级路径</th>
<th style="width: 66px">排序</th>
@@ -347,7 +370,7 @@ onMounted(loadTree)
<template v-if="treeRows.length">
<template v-for="row in treeRows" :key="String(row.node.id)">
<tr v-if="isCategoryLoadMoreNode(row.node)" class="load-more-row">
<td colspan="8">
<td colspan="9">
<div class="load-more-cell">
<span class="tree-indent" :style="{ width: `${(row.depth + 1) * 24}px` }"></span>
<button class="btn btn-sm btn-secondary" type="button" :disabled="moreLoading(row.node)" @click="loadMoreChildren(row.node)">
@@ -357,7 +380,11 @@ onMounted(loadTree)
</div>
</td>
</tr>
<tr v-else>
<tr v-else :class="{ 'batch-selected': batch.isSelected(row.node) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row.node) || `选择 ${batch.label(row.node)}`" :checked="batch.isSelected(row.node)"
:disabled="batch.disabled || !!batch.reason(row.node)" @change="batch.toggle(row.node)" />
</td>
<td>
<div class="tree-name-cell" @click="onNodeClick(row.node)">
<span class="tree-indent" :style="{ width: `${row.depth * 24}px` }"></span>
@@ -393,7 +420,7 @@ onMounted(loadTree)
<button
class="btn btn-sm btn-danger"
type="button"
:disabled="!canDelete(row.node)"
:disabled="batch.busy || !canDelete(row.node)"
:title="!canDelete(row.node) ? '存在子类目,不能删除' : undefined"
@click="removeCategory(row.node)"
>
@@ -404,15 +431,19 @@ onMounted(loadTree)
</template>
</template>
<tr v-else-if="loading">
<td colspan="8" class="empty-tip">加载中...</td>
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="8" class="empty-tip">暂无商品类目</td>
<td colspan="9" class="empty-tip">暂无商品类目</td>
</tr>
</tbody>
<tbody v-else>
<template v-if="searchRows.length">
<tr v-for="row in searchRows" :key="row.id">
<tr v-for="row in searchRows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td><strong class="node-name">{{ row.name }}</strong></td>
<td><span class="category-path-value" :title="row.path || row.name">{{ row.path || row.name }}</span></td>
<td>{{ row.sortOrder ?? '—' }}</td>
@@ -430,7 +461,7 @@ onMounted(loadTree)
<button
class="btn btn-sm btn-danger"
type="button"
:disabled="!canDelete(row)"
:disabled="batch.busy || !canDelete(row)"
:title="!canDelete(row) ? '存在子类目,不能删除' : undefined"
@click="removeCategory(row)"
>
@@ -440,10 +471,10 @@ onMounted(loadTree)
</tr>
</template>
<tr v-else-if="searchLoading">
<td colspan="8" class="empty-tip">搜索中...</td>
<td colspan="9" class="empty-tip">搜索中...</td>
</tr>
<tr v-else>
<td colspan="8" class="empty-tip">暂无搜索结果</td>
<td colspan="9" class="empty-tip">暂无搜索结果</td>
</tr>
</tbody>
</table>
@@ -483,292 +514,4 @@ onMounted(loadTree)
</div>
</template>
<style scoped>
/* 像素复刻旧版 admin.html panel-product-categories(蓝白末层)。 */
.category-view {
font-family: inherit;
color: #24384d;
}
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.category-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.category-head-tools {
display: flex;
align-items: center;
gap: 8px;
}
.category-keyword {
width: 240px;
min-height: 36px;
padding: 6px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.category-keyword:hover {
border-color: #9fb7cd;
}
.category-keyword:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.category-table-scroll > table {
/* table-layout:fixed 下,没写宽度的列在容器变窄时第一个被压到 0(10-06 截图:层级路径只剩一个字、
备注只剩破折号)。承重的是 thead 里 8 列全部显式 px 定宽;这个下限与它们成对维护,
数值由 tests/align-product-category.test.ts 从 markup 现算比对,改列宽要同时改这里。 */
min-width: 1224px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.tree-name-cell {
display: flex;
align-items: center;
gap: 6px;
min-height: 24px;
cursor: pointer;
}
.tree-indent {
flex: 0 0 auto;
display: inline-block;
}
.tree-node-mark {
width: 20px;
height: 20px;
border: 0;
border-radius: 5px;
background: var(--admin-primary-soft, #e7f0f8);
color: var(--admin-primary-strong, #2f5d8b);
display: inline-flex;
align-items: center;
justify-content: center;
font-size: 13px;
font-weight: 700;
cursor: pointer;
padding: 0;
line-height: 1;
flex: none;
transition: background 0.12s ease, color 0.12s ease;
}
.tree-node-mark:not(.is-leaf):hover {
background: var(--admin-primary-strong, #2f5d8b);
color: #ffffff;
}
.tree-node-mark.is-leaf {
background: transparent;
cursor: default;
}
.node-name {
font-weight: 600;
color: #24384d;
white-space: nowrap;
}
.selected-flag {
padding: 1px 8px;
border-radius: 999px;
background: #e7f0f8;
color: #2f5d8b;
font-size: 11px;
}
.category-tag {
padding: 2px 8px;
border-radius: 6px;
border: 1px solid #c2d5e6;
background: #e7f0f8;
color: #2f5d8b;
font-size: 12px;
}
.category-tag.is-custom {
border-color: #bcd9c6;
background: #eef7f0;
color: #3d7158;
}
.category-path-value {
display: block;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.node-desc {
color: #5b6f83;
font-size: 12px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 320px;
display: inline-block;
vertical-align: middle;
}
.dim {
color: #8293a5;
}
.ops-cell {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
flex-wrap: wrap;
}
.load-more-row td {
background: #fbfdfe;
}
.load-more-cell {
display: flex;
align-items: center;
gap: 8px;
}
.loaded-count {
color: #8293a5;
font-size: 12.5px;
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
</style>
<style scoped src="./ProductCategoryPage.css"></style>
@@ -0,0 +1,272 @@
/* 像素复刻旧版 admin.html panel-query-asin(蓝白末层)。 */
.query-view {
font-family: inherit;
color: #24384d;
}
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.query-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.query-head-actions {
display: flex;
gap: 10px;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 12px;
margin-bottom: 16px;
}
.query-filter-row > .form-group {
flex: 1 1 140px;
min-width: 0;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.query-asin-table-scroll > table {
min-width: 860px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.table-scroll td {
vertical-align: top;
}
.asin-cell {
display: block;
max-width: 100%;
margin: -3px 0 -3px -7px;
padding: 3px 7px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: inherit;
font-size: 13.5px;
font-variant-numeric: tabular-nums;
line-height: 1.5;
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}
.asin-cell:hover {
border-color: #c7d7e5;
background: #eef4fa;
color: #2f5d8b;
}
.asin-empty {
color: #8b9aaa;
}
.asin-col-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
white-space: nowrap;
/* 与最低价 ASIN 同形:列宽已从 9% 改成 140px 下限,再补 wrap 兜住文案变长的情况,
让"超宽"从"按钮静默消失"退化成"多占一行"。 */
flex-wrap: wrap;
background: #ffffff;
box-shadow: -9px 0 12px -10px rgba(31, 48, 66, 0.45);
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
.page-jump input {
width: 56px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.drawer-tip {
color: #5b6f83;
font-size: 12px;
margin: 0 0 12px;
}
.import-tip {
margin: 6px 0 0;
color: #5b6f83;
font-size: 12px;
}
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
/** 查询 ASIN · 像素复刻旧版 admin.html panel-query-asin(自绘:面板头操作组、筛选+导出 XLSX、原生 rowspan 表格+可复制 ASIN、旧式分页)。
* script 逻辑沿用现有 Vue 实现(新增级联/配置抽屉/导入轮询/导出)。 */
import { computed, onMounted, reactive, ref, watch } from 'vue'
@@ -71,13 +75,37 @@ function normalizeAsinInput(country: string): void {
}
// 同一家店铺部分站点删除成功后,重试只发未完成的站点。
const pendingCountries = new WeakMap<QueryAsinItem, Set<(typeof QUERY_ASIN_COUNTRIES)[number]>>()
async function deleteShopCountries(item: QueryAsinItem, isCurrent: () => boolean = () => true) {
const pending = pendingCountries.get(item) ?? new Set(QUERY_ASIN_COUNTRIES.filter((country) => asinOf(item, country)))
pendingCountries.set(item, pending)
for (const country of pending) {
if (!isCurrent()) throw new Error('列表范围已切换,店铺剩余站点未删除')
await deleteQueryAsinCountryAsin(item.id, country)
pending.delete(country)
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.groupName ? `${row.shopName}(${row.groupName})` : row.shopName,
deleteOne: (_id, row, isCurrent) => deleteShopCountries(row, isCurrent),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
scope: () => companyTab.activeId,
consequence: '将删除所选店铺全部站点的 ASIN 配置,此操作不可恢复。',
})
async function removeShopAsin(item: QueryAsinItem) {
if (batch.busy) return
// 删除该店铺全部站点的 ASIN 配置(逐国调用现有端点)。
if (!(await openAdminConfirm({ message: `确定删除店铺“${item.shopName}”的全部站点 ASIN 配置吗?`, danger: true }))) return
try {
for (const country of QUERY_ASIN_COUNTRIES) {
if (asinOf(item, country)) await deleteQueryAsinCountryAsin(item.id, country)
}
await deleteShopCountries(item)
batch.removeFromSelection(item.id)
ElMessage.success('已删除')
await load()
} catch (error) {
@@ -300,7 +328,10 @@ async function loadGroups() {
}
}
const batchListGate = createLatestRequestGate()
async function load() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
@@ -313,14 +344,16 @@ async function load() {
country: filter.country || undefined,
companyId: companyTab.requestCompanyId,
})
if (!batchListGate.isCurrent(token)) return
rows.value = result.items
total.value = result.total
page.value = result.page
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '数据加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -405,10 +438,15 @@ onMounted(() => {
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll query-asin-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 6%">序号</th>
<th v-if="isSuperAdmin" style="width: 13%">分组</th>
<th style="width: 15%">店铺名</th>
@@ -421,8 +459,12 @@ onMounted(() => {
</thead>
<tbody>
<template v-if="displayRows.length">
<tr v-for="row in displayRows" :key="`${row.item.id}-${row.country}`">
<tr v-for="row in displayRows" :key="`${row.item.id}-${row.country}`" :class="{ 'batch-selected': batch.isSelected(row.item) }">
<template v-if="row.isFirst">
<td class="batch-delete-cell" :rowspan="row.rowspan">
<BatchDeleteCheckbox :label="batch.reason(row.item) || `选择 ${batch.label(row.item)}`" :checked="batch.isSelected(row.item)"
:disabled="batch.disabled || !!batch.reason(row.item)" @change="batch.toggle(row.item)" />
</td>
<td :rowspan="row.rowspan">{{ row.rowNo }}</td>
<td v-if="isSuperAdmin" :rowspan="row.rowspan">{{ row.item.groupName || '—' }}</td>
<td :rowspan="row.rowspan">{{ row.item.shopName }}</td>
@@ -439,16 +481,16 @@ onMounted(() => {
<td :rowspan="row.rowspan">{{ formatDateTime(row.item.updatedAt) }}</td>
<td :rowspan="row.rowspan" class="asin-col-actions">
<button class="btn btn-sm" type="button" @click="openConfig(row.item as QueryAsinItem)">配置</button>
<button class="btn btn-sm btn-danger" type="button" @click="removeShopAsin(row.item as QueryAsinItem)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeShopAsin(row.item as QueryAsinItem)">删除</button>
</td>
</template>
</tr>
</template>
<tr v-else-if="loading">
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">加载中...</td>
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td :colspan="isSuperAdmin ? 8 : 7" class="empty-tip">暂无数据</td>
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">暂无数据</td>
</tr>
</tbody>
</table>
@@ -531,277 +573,4 @@ onMounted(() => {
</div>
</template>
<style scoped>
/* 像素复刻旧版 admin.html panel-query-asin(蓝白末层)。 */
.query-view {
font-family: inherit;
color: #24384d;
}
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.query-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.query-head-actions {
display: flex;
gap: 10px;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 12px;
margin-bottom: 16px;
}
.query-filter-row > .form-group {
flex: 1 1 140px;
min-width: 0;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.query-asin-table-scroll > table {
min-width: 860px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.table-scroll td {
vertical-align: top;
}
.asin-cell {
display: block;
max-width: 100%;
margin: -3px 0 -3px -7px;
padding: 3px 7px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: inherit;
font-size: 13.5px;
font-variant-numeric: tabular-nums;
line-height: 1.5;
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}
.asin-cell:hover {
border-color: #c7d7e5;
background: #eef4fa;
color: #2f5d8b;
}
.asin-empty {
color: #8b9aaa;
}
.asin-col-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
white-space: nowrap;
/* 与最低价 ASIN 同形:列宽已从 9% 改成 140px 下限,再补 wrap 兜住文案变长的情况,
让"超宽"从"按钮静默消失"退化成"多占一行"。 */
flex-wrap: wrap;
background: #ffffff;
box-shadow: -9px 0 12px -10px rgba(31, 48, 66, 0.45);
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
.page-jump input {
width: 56px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.drawer-tip {
color: #5b6f83;
font-size: 12px;
margin: 0 0 12px;
}
.import-tip {
margin: 6px 0 0;
color: #5b6f83;
font-size: 12px;
}
</style>
<style scoped src="./QueryAsinPage.css"></style>
@@ -0,0 +1,300 @@
/* 像素复刻旧版 admin.html panel-skip-price-asin(蓝白末层)。 */
.skip-view {
font-family: inherit;
color: #24384d;
}
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.skip-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.skip-head-actions {
display: flex;
gap: 10px;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 12px;
margin-bottom: 16px;
}
.skip-filter-row > .form-group {
flex: 1 1 130px;
min-width: 0;
}
.skip-filter-row .form-group.price-range {
flex: 1 1 220px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.price-range-row {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
}
.price-range-row input {
flex: 1;
min-width: 0;
}
.price-range-row .range-sep {
color: #8293a5;
flex: none;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.skip-price-asin-table-scroll > table {
min-width: 900px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.table-scroll td {
vertical-align: top;
}
.asin-cell {
display: block;
max-width: 100%;
margin: -3px 0 -3px -7px;
padding: 3px 7px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: inherit;
font-size: 13.5px;
font-variant-numeric: tabular-nums;
line-height: 1.5;
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}
.asin-cell:hover {
border-color: #c7d7e5;
background: #eef4fa;
color: #2f5d8b;
}
.asin-empty {
color: #8b9aaa;
}
.price-cell {
text-align: right;
font-variant-numeric: tabular-nums;
}
.asin-col-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
white-space: nowrap;
/* 列宽已从 9% 改成 140px 下限(两字按钮 53×2 + gap 8 + td 左右 padding 24 = 138)。
百分比会跟着容器一起缩,配上 justify-content:flex-end 后溢出翻到左侧,
"配置"整颗被吃掉而"删除"看着完好——2026-10-08 那单截图就是这个形状。 */
flex-wrap: wrap;
background: #ffffff;
box-shadow: -9px 0 12px -10px rgba(31, 48, 66, 0.45);
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
.page-jump input {
width: 56px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.drawer-tip {
color: #5b6f83;
font-size: 12px;
margin: 0 0 12px;
}
.country-cell {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
width: 100%;
}
.import-tip {
margin: 6px 0 0;
color: #5b6f83;
font-size: 12px;
}
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
/** 最低价 ASIN(跳过跟价)· 像素复刻旧版 admin.html panel-skip-price-asin(自绘:面板头操作组、筛选(分组/店铺/国家/ASIN/最低价≥≤)+导出 XLSX、原生 rowspan 表格、旧式分页)。
* script 逻辑沿用现有 Vue 实现(新增级联+最低价、配置抽屉双列、导入轮询、导出)。 */
import { computed, onMounted, reactive, ref, watch } from 'vue'
@@ -225,7 +229,19 @@ async function saveConfig(): Promise<void> {
}
// ---- 整条删除 ----
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.groupName ? `${row.shopName}(${row.groupName})` : row.shopName,
deleteOne: (id) => deleteSkipPriceAsin(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
scope: () => companyTab.activeId,
consequence: '将删除所选店铺全部站点的最低价 ASIN 配置,此操作不可恢复。',
})
async function removeRow(item: SkipPriceItem): Promise<void> {
if (batch.busy) return
try {
await ElMessageBox.confirm(
`确定删除「${item.shopName}」${item.groupName ? `(${item.groupName})` : ''}全部站点的最低价 ASIN 配置吗?`,
@@ -237,6 +253,7 @@ async function removeRow(item: SkipPriceItem): Promise<void> {
}
try {
await deleteSkipPriceAsin(item.id)
batch.removeFromSelection(item.id)
ElMessage.success('删除成功')
// 删除后当前页若已空且非首页,回退一页避免展示空页。
if (rows.value.length === 1 && page.value > 1) {
@@ -353,19 +370,24 @@ async function loadGroups() {
}
}
const batchListGate = createLatestRequestGate()
async function load() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
const result = await fetchSkipPriceList(toSkipPriceParams(filter, page.value, pageSize.value, companyTab.requestCompanyId))
if (!batchListGate.isCurrent(token)) return
rows.value = result.items
total.value = result.total
page.value = result.page
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '数据加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -458,10 +480,15 @@ onMounted(() => {
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll skip-price-asin-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 6%">序号</th>
<th v-if="isSuperAdmin" style="width: 13%">分组</th>
<th style="width: 15%">店铺名</th>
@@ -475,8 +502,12 @@ onMounted(() => {
</thead>
<tbody>
<template v-if="displayRows.length">
<tr v-for="row in displayRows" :key="`${row.item.id}-${row.country}`">
<tr v-for="row in displayRows" :key="`${row.item.id}-${row.country}`" :class="{ 'batch-selected': batch.isSelected(row.item) }">
<template v-if="row.isFirst">
<td class="batch-delete-cell" :rowspan="row.rowspan">
<BatchDeleteCheckbox :label="batch.reason(row.item) || `选择 ${batch.label(row.item)}`" :checked="batch.isSelected(row.item)"
:disabled="batch.disabled || !!batch.reason(row.item)" @change="batch.toggle(row.item)" />
</td>
<td :rowspan="row.rowspan">{{ row.rowNo }}</td>
<td v-if="isSuperAdmin" :rowspan="row.rowspan">{{ row.item.groupName || '—' }}</td>
<td :rowspan="row.rowspan">{{ row.item.shopName }}</td>
@@ -494,16 +525,16 @@ onMounted(() => {
<td :rowspan="row.rowspan">{{ formatDateTime(row.item.updatedAt) }}</td>
<td :rowspan="row.rowspan" class="asin-col-actions">
<button class="btn btn-sm" type="button" @click="openConfig(row.item as SkipPriceItem)">配置</button>
<button class="btn btn-sm btn-danger" type="button" @click="removeRow(row.item as SkipPriceItem)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="removeRow(row.item as SkipPriceItem)">删除</button>
</td>
</template>
</tr>
</template>
<tr v-else-if="loading">
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">加载中...</td>
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td :colspan="isSuperAdmin ? 9 : 8" class="empty-tip">暂无数据</td>
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">暂无数据</td>
</tr>
</tbody>
</table>
@@ -592,305 +623,4 @@ onMounted(() => {
</div>
</template>
<style scoped>
/* 像素复刻旧版 admin.html panel-skip-price-asin(蓝白末层)。 */
.skip-view {
font-family: inherit;
color: #24384d;
}
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.skip-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 16px;
}
.skip-head-actions {
display: flex;
gap: 10px;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 12px;
margin-bottom: 16px;
}
.skip-filter-row > .form-group {
flex: 1 1 130px;
min-width: 0;
}
.skip-filter-row .form-group.price-range {
flex: 1 1 220px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
/* 下拉壳由全局 .el-select.admin-filter(main.css:42px/9px 圆角/#f8fbfd 浅底/focus ring)出,
与亚马逊面同一套;这里只留 input 的原生壳规则(2026-11-17 原生 select 全换 el-select)。 */
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.price-range-row {
display: flex;
align-items: center;
gap: 6px;
min-width: 0;
}
.price-range-row input {
flex: 1;
min-width: 0;
}
.price-range-row .range-sep {
color: #8293a5;
flex: none;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.skip-price-asin-table-scroll > table {
min-width: 900px;
}
.table-scroll th,
.table-scroll td {
padding: 10px 12px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
.table-scroll td {
vertical-align: top;
}
.asin-cell {
display: block;
max-width: 100%;
margin: -3px 0 -3px -7px;
padding: 3px 7px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: inherit;
font-size: 13.5px;
font-variant-numeric: tabular-nums;
line-height: 1.5;
text-align: left;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
cursor: pointer;
}
.asin-cell:hover {
border-color: #c7d7e5;
background: #eef4fa;
color: #2f5d8b;
}
.asin-empty {
color: #8b9aaa;
}
.price-cell {
text-align: right;
font-variant-numeric: tabular-nums;
}
.asin-col-actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
white-space: nowrap;
/* 列宽已从 9% 改成 140px 下限(两字按钮 53×2 + gap 8 + td 左右 padding 24 = 138)。
百分比会跟着容器一起缩,配上 justify-content:flex-end 后溢出翻到左侧,
"配置"整颗被吃掉而"删除"看着完好——2026-10-08 那单截图就是这个形状。 */
flex-wrap: wrap;
background: #ffffff;
box-shadow: -9px 0 12px -10px rgba(31, 48, 66, 0.45);
}
.empty-tip {
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.pagination button {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
.page-jump input {
width: 56px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.drawer-tip {
color: #5b6f83;
font-size: 12px;
margin: 0 0 12px;
}
.country-cell {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
width: 100%;
}
.import-tip {
margin: 6px 0 0;
color: #5b6f83;
font-size: 12px;
}
</style>
<style scoped src="./SkipPricePage.css"></style>
@@ -38,6 +38,8 @@ export async function deleteDedupeTotal(id: number): Promise<void> {
/** 加载数据权限分组选项:GET /shop-manages/groups → {id,name,leaderUserId}[]。 */
export async function fetchDedupeTotalGroups(companyId?: number | null): Promise<DedupeGroupOption[]> {
// null 由发送口自己丢掉(不依赖 axios 丢 null):非超管/未选 tab 时不发 company_id,后端按会话裁剪。
const { data } = await http.get<unknown>(DEDUPE_GROUPS_ENDPOINT, { params: companyId != null ? { company_id: companyId } : {} })
// platform 恒 'amazon'(2026-11-22 用户口径「亚马逊的也是同理」):去重/ASIN 面是亚马逊域,
// 京东档分组(platform='jd')不得混进本下拉——与分组管理页按平台 tab 过滤同口径。
const { data } = await http.get<unknown>(DEDUPE_GROUPS_ENDPOINT, { params: { platform: 'amazon', ...(companyId != null ? { company_id: companyId } : {}) } })
return parseDedupeGroupOptionList(data)
}
@@ -1,469 +0,0 @@
<script setup lang="ts">
/** 京东数据库「类目」筛选的京麦同款级联面板(2026-11-16 客户口径「京麦类目是这些 我们
* 后台的现在的不对」+「你直接爬」→ 树数据换成京麦授权类目真树,见 ./jd-category-tree.ts
* 头注释的取证来源与边界)。
*
* 交互(京麦真机同款,2026-11-16 面板逐级点开取证):面板按点亮路径动态出栏——第一栏
* 一级(3 个)、后续栏=点亮节点的 children(最深 4 栏);**非末级行点击=下钻**(推进
* 路径)、**末级行(children 空)点击=选中**(radio 蓝,emit change→按 category_path
* 等值过滤,后端契约零改动)。搜索框搜**树内全部末级**(名称或路径命中,行 title 带
* 全路径);树外命中(已落库但京麦类目体系变更后的历史名)从 options 兜底段选,语义
* 同旧版第三栏。「全部类目」行=清选;触发框已选时出 × 清除;面板外点透明遮罩关闭。
* 零依赖自绘(radio 圆点/箭头都是 CSS),无 element 依赖。 */
import { computed, nextTick, ref, watch } from 'vue'
import {
jdCategoryChildren,
jdCategoryRoots,
jdCategorySearchLeaves,
type JdCategoryNode,
} from './jd-category-tree.ts'
import { clampPanelLeftX } from './jd-category-cascader-position.ts'
const props = defineProps<{
/** 已落库末级类目全集(/categories 现算,页面传入)——只作**树外兜底**(搜索无树内
* 命中时列出「已落库类目(树外历史)」段),不再默认铺第三栏。 */
options?: { name: string; productCount: number }[]
/** 当前选中末级类目名;'' = 全部类目。 */
modelValue: string
groups?: { id: number; name: string; productCount: number }[]
groupId?: string
createVersion?: number
busy?: boolean
treeOnly?: boolean
}>()
const emit = defineEmits<{
(event: 'change', value: string): void
(event: 'group', value: string): void
(event: 'create-group', value: string): void
(event: 'delete-group', id: number): void
}>()
const newGroupName = ref('')
watch(() => props.createVersion, () => { newGroupName.value = '' })
function createGroup(): void {
const name = newGroupName.value.trim()
if (name) emit('create-group', name)
}
function pickGroup(id: number): void {
emit('group', String(id))
close()
}
const open = ref(false)
/** 已下钻的节点名路径(非末级行点击推进)。 */
const activePath = ref<string[]>([])
const searchText = ref('')
/** 面板水平定位钳制(2026-11-16「超出视窗了」):触发框在筛选行中部偏右时,锚 left:0
* 的多栏面板会伸出视窗右缘。打开与栏数/搜索态变化后用真实 rect 重算 left 偏移——
* 右缘贴齐视口后继续下钻即向左生长,不再截掉末栏。钳制数学在
* ./jd-category-cascader-position.ts(纯函数,tests/jd-category-cascader-position.test.ts)。 */
const hostRef = ref<HTMLElement | null>(null)
const panelRef = ref<HTMLElement | null>(null)
const panelOffsetX = ref(0)
function reposition(): void {
const host = hostRef.value
const panel = panelRef.value
if (!host || !panel) return
panelOffsetX.value = clampPanelLeftX({
hostLeft: host.getBoundingClientRect().left,
panelWidth: panel.offsetWidth,
viewportWidth: window.innerWidth,
})
}
const roots = jdCategoryRoots()
/** 树内全部末级名集合(判定 options 哪些是「树外历史」)。 */
const treeLeafNames = new Set(
jdCategorySearchLeaves('').map((leaf) => leaf.name),
)
/** 面板各栏内容:第 0 栏一级,第 i+1 栏=点亮路径前 i+1 个的 children(路径推进到
* 末级时末栏是叶子所在栏,children 空不出栏——栏数随路径动态 1~4)。 */
const columns = computed<JdCategoryNode[][]>(() => {
const cols: JdCategoryNode[][] = [roots]
for (let i = 0; i < activePath.value.length; i++) {
const children = jdCategoryChildren(activePath.value.slice(0, i + 1))
if (!children.length) break
cols.push(children)
}
return cols
})
/** 搜索激活=搜索词非空:面板切换成扁平末级结果列表。 */
const searching = computed(() => searchText.value.trim().length > 0)
/** 树内命中末级(名称或路径段命中)。 */
const searchLeaves = computed(() =>
searching.value ? jdCategorySearchLeaves(searchText.value) : [],
)
/** 树外兜底:options 里不在树名集的行按搜索词过滤(历史行仍可选中过滤)。 */
const fallbackOptions = computed(() => {
if (!searching.value) return []
const keyword = searchText.value.trim().toLowerCase()
return (props.options ?? [])
.filter((option) => !treeLeafNames.has(option.name))
.filter((option) => option.name.toLowerCase().includes(keyword))
})
/** 栏数随下钻动态 1~4、搜索态切单栏 ⇒ 面板宽度变,开着就要重算偏移(下钻向左生长)。 */
watch(
() => [columns.value.length, searching.value] as const,
() => {
if (open.value) nextTick(reposition)
},
)
function toggle(): void {
if (open.value) {
close()
return
}
activePath.value = []
searchText.value = ''
open.value = true
nextTick(reposition)
}
function close(): void {
open.value = false
activePath.value = []
}
/** 非末级行点击=下钻;末级行点击=选中并收面板。 */
function pick(node: JdCategoryNode, depth: number): void {
if (node.children && node.children.length) {
activePath.value = [...activePath.value.slice(0, depth), node.name]
return
}
emit('change', node.name)
close()
}
function pickAll(): void {
emit('change', '')
close()
}
/** 搜索结果行点击(树内末级或树外兜底行)=按名选中。 */
function pickName(name: string): void {
emit('change', name)
close()
}
function clear(): void {
emit('change', '')
}
</script>
<template>
<div ref="hostRef" class="cat-cascader">
<button
class="cat-trigger"
type="button"
:class="{ open, filled: !!modelValue || !!groupId }"
@click="toggle"
>
<span class="cat-trigger-text" :title="modelValue || ''">{{ groups?.find(group => String(group.id) === groupId)?.name || modelValue || '全部类目' }}</span>
<span
v-if="modelValue || groupId"
class="cat-clear"
role="button"
aria-label="清除类目"
@click.stop="clear"
>×</span>
<span class="cat-chevron" aria-hidden="true"></span>
</button>
<!-- 面板外点透明遮罩关闭(零 document 监听器,无泄漏面)。 -->
<div v-if="open" class="cat-mask" @click="close"></div>
<div v-if="open" ref="panelRef" class="cat-panel" :style="{ left: `${panelOffsetX}px` }">
<div v-if="!treeOnly" class="cat-custom cat-col-custom">
<div class="cat-seg">自定义分类</div>
<form class="cat-create" @submit.prevent="createGroup">
<input v-model="newGroupName" class="cat-search" placeholder="新建分类" aria-label="新建分类名称" />
<button type="submit" :disabled="busy || !newGroupName.trim()">添加</button>
</form>
<div v-for="group in groups || []" :key="group.id" class="cat-row" :class="{ active: groupId === String(group.id) }">
<button type="button" class="cat-group-pick" :title="group.name" @click="pickGroup(group.id)">{{ group.name }}({{ group.productCount }})</button>
<button type="button" :aria-label="`删除分类 ${group.name}`" @click.stop="emit('delete-group', group.id)">删除</button>
</div>
</div>
<!-- 搜索态:树内末级命中+树外兜底段(扁平列表,行 title 带全路径)。 -->
<template v-if="searching">
<div class="cat-col cat-col-search">
<div class="cat-search-row"><input v-model="searchText" type="text" class="cat-search" placeholder="搜索类目" /></div>
<template v-if="searchLeaves.length || fallbackOptions.length">
<div
v-for="leaf in searchLeaves"
:key="`tree-${leaf.path.join('/')}`"
class="cat-row"
:class="{ active: modelValue === leaf.name }"
:title="leaf.path.join(' > ')"
@click="pickName(leaf.name)"
>
<span class="cat-dot" :class="{ on: modelValue === leaf.name }" aria-hidden="true"></span>
<span class="cat-name">{{ leaf.name }}</span>
<span class="cat-path">{{ leaf.path.slice(0, -1).join(' › ') }}</span>
</div>
<div v-if="fallbackOptions.length" class="cat-seg">已落库类目(树外历史)</div>
<div
v-for="option in fallbackOptions"
:key="`db-${option.name}`"
class="cat-row"
:class="{ active: modelValue === option.name }"
:title="option.name"
@click="pickName(option.name)"
>
<span class="cat-dot" :class="{ on: modelValue === option.name }" aria-hidden="true"></span>
<span class="cat-name">{{ option.name }}</span>
<span class="cat-count">{{ option.productCount }}</span>
</div>
</template>
<div v-else class="cat-empty">未找到类目</div>
</div>
</template>
<!-- 下钻态:逐级动态栏;首栏顶部「全部类目」行=清选。 -->
<template v-else>
<div
v-for="(col, depth) in columns"
:key="depth"
class="cat-col"
>
<div v-if="depth === 0" class="cat-search-row">
<input
v-model="searchText"
type="text"
class="cat-search"
placeholder="搜索类目"
@click.stop
/>
</div>
<div v-if="depth === 0" class="cat-row cat-row-all" :class="{ active: !modelValue }" @click="pickAll">
<span class="cat-dot" :class="{ on: !modelValue }" aria-hidden="true"></span>
<span class="cat-name">全部类目</span>
</div>
<div
v-for="node in col"
:key="`${depth}-${node.name}`"
class="cat-row"
:class="{ active: activePath[depth] === node.name || (depth === 0 && modelValue === node.name) }"
:title="node.name"
@click="pick(node, depth)"
>
<span class="cat-dot" aria-hidden="true"></span>
<span class="cat-name">{{ node.name }}</span>
<span v-if="node.children && node.children.length" class="cat-arrow" aria-hidden="true">›</span>
</div>
</div>
</template>
</div>
</div>
</template>
<style scoped>
.cat-custom { flex: none; width: 200px; max-height: 340px; overflow-y: auto; border-right: 1px solid #e7eef5; }
.cat-create { display: flex; gap: 4px; padding: 6px 8px; }
.cat-create input { min-width: 0; }
.cat-group-pick { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; color: inherit; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-cascader {
position: relative;
min-width: 0;
}
/* 触发框像素对齐页面 .form-group select(42 高/9 圆角/#cbd9e6 边框/#f8fbfd 底)。 */
.cat-trigger {
display: flex;
align-items: center;
gap: 6px;
width: 100%;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
cursor: pointer;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.cat-trigger:hover {
border-color: #9fb7cd;
}
.cat-trigger.open,
.cat-trigger:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.cat-trigger-text {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-align: left;
}
.cat-trigger:not(.filled) .cat-trigger-text {
color: #8293a5;
}
.cat-clear {
flex: none;
width: 18px;
height: 18px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #e7eef5;
color: #5b6f83;
font-size: 13px;
line-height: 1;
}
.cat-clear:hover {
background: #dbe7f1;
color: #24384d;
}
/* 下拉箭头:CSS 三角(京麦同款向下 chevron,展开翻向上)。 */
.cat-chevron {
flex: none;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 6px solid #7b8a99;
transition: transform 160ms ease;
}
.cat-trigger.open .cat-chevron {
transform: rotate(180deg);
}
.cat-mask {
position: fixed;
inset: 0;
z-index: 2550;
}
.cat-panel {
position: absolute;
top: calc(100% + 4px);
left: 0;
z-index: 2560;
display: flex;
align-items: stretch;
max-width: min(820px, 90vw);
border: 1px solid #d8e3ee;
border-radius: 10px;
background: #ffffff;
box-shadow: 0 16px 44px rgba(39, 67, 94, 0.18);
overflow-x: auto;
overflow-y: hidden;
}
.cat-col {
flex: none;
width: 200px;
max-height: 340px;
overflow-y: auto;
padding: 6px 0;
border-right: 1px solid #e7eef5;
}
.cat-col:last-child {
border-right: 0;
}
.cat-col-search {
width: 300px;
}
/* 行=京麦同款:圆点 radio + 名称 + 右箭头;hover 浅蓝底。 */
.cat-row {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
font-size: 13.5px;
color: #24384d;
cursor: pointer;
}
.cat-row:hover,
.cat-row.active {
background: #f1f7fb;
}
.cat-row.active {
color: #2f5d8b;
font-weight: 550;
}
.cat-dot {
flex: none;
width: 13px;
height: 13px;
border: 1px solid #c0ccda;
border-radius: 50%;
background: #ffffff;
}
/* radio 选中=京麦同款蓝芯。 */
.cat-dot.on {
border-color: #3b82c4;
background: radial-gradient(circle, #3b82c4 0 4px, #ffffff 4.6px);
}
.cat-name {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 搜索态行尾的路径灰字(同名跨支时定位用)。 */
.cat-path {
flex: none;
max-width: 110px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #9fb0c0;
font-size: 12px;
}
.cat-arrow {
flex: none;
color: #9fb0c0;
font-size: 15px;
line-height: 1;
}
.cat-count {
flex: none;
color: #8293a5;
font-size: 12px;
}
.cat-seg {
padding: 8px 12px 4px;
color: #8293a5;
font-size: 11.5px;
border-top: 1px solid #e7eef5;
}
.cat-search-row {
padding: 4px 8px 6px;
border-bottom: 1px solid #e7eef5;
}
.cat-search {
display: block;
width: 100%;
min-height: 30px;
padding: 4px 10px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 12.5px;
font-family: inherit;
outline: none;
}
.cat-search:focus {
background: #ffffff;
border-color: #5f85ad;
}
.cat-empty {
padding: 16px 12px;
color: #8293a5;
font-size: 12.5px;
text-align: center;
}
</style>
@@ -1,11 +1,18 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
/** 分类管理对话框(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里,
* 做一个搜索和添加 删除 编辑 分类名称即可」):原 V204 独立子菜单页(JdCategoryManagerPage)
* 整体并入本对话框,从京东数据库页工具栏「分类管理」打开。
* 职责不变:当前数据权限分组的分类建/改名/删除+新增的名称搜索;商品归类不在这里
* (去「批量编辑分类」)。列表状态自管理(写操作后自刷新并 emit changed 让父页刷筛选下拉)。
* 权限口径(V203)不变:本组管理员/公司超管/平台超管可写(editable);同组普通号
* 只读可看(无新建行,改名/删除按钮逐行不渲染),后端同口径 403 兜底。 */
* 只读可看(无新建行,改名/删除按钮逐行不渲染),后端同口径 403 兜底。
* 2026-11-17 晚用户口径「admin 权限最大」:京东侧还没有任何数据权限分组时(平台闸
* 上线后 jd 档组全空),平台超管在本弹窗空态直建第一个京东档分组(组长=自己),
* 建完 emit group-created 让父页重取作用域,当前分组翻到新组后接着就能建分类,
* 不再死在「你还不属于任何数据权限分组」。 */
import { computed, ref, watch } from 'vue'
import {
createJdProductGroup,
@@ -14,6 +21,8 @@ import {
updateJdProductGroup,
type JdProductGroup,
} from './jd-product-api.ts'
import { createShopGroup } from '../account/shop-group-api.ts'
import { useAdminSessionStore } from '@/stores/admin-session'
import { openAdminConfirm } from '@/components/admin-confirm'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { loadFailureMessage } from '@/components/load-failure-model'
@@ -27,9 +36,13 @@ const props = defineProps<{
ownerGroupName: string
/** 当前分组可写(scope 的 editable):建/改名/删除控件全挂它。 */
editable: boolean
/** 操作者是否平台超管(scope 原样透传):只在「还没有分组」的空态开直建口子。 */
platformSuperAdmin?: boolean
}>()
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void }>()
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void; (event: 'group-created'): void }>()
const session = useAdminSessionStore()
const loading = ref(false)
/** 首屏取数失败(可见红条+重试);写操作失败走 errorText 红条(无重试语义)。 */
@@ -73,7 +86,8 @@ const showPager = computed(() => filteredGroups.value.length > PAGE_SIZE)
function goPage(target: number): void {
pageNo.value = Math.min(Math.max(1, target), totalPages.value)
}
/** 空表文案分四种:不属于任何组 / 本组没分类(可管理)/ 本组没分类(只读)/ 搜索无命中。 */
/** 空表文案分四种:不属于任何组 / 本组没分类(可管理)/ 本组没分类(只读)/ 搜索无命中。
* 平台超管的「还没有分组」空态不走这里——模板换成直建分组的表单(canBootstrapGroup)。 */
const emptyListText = computed(() => {
if (props.ownerGroupId <= 0) return '你还不属于任何数据权限分组'
if (!groups.value.length) {
@@ -82,6 +96,40 @@ const emptyListText = computed(() => {
return '没有匹配的分类'
})
/** 空态直建分组的口子(2026-11-17 用户口径「admin 权限最大」):平台超管 + 还没有任何
* 可见分组时才开。组员/翻档等完整分组管理仍归「分组管理」页,这里只解决「从 0 到 1」。 */
const canBootstrapGroup = computed(() => props.platformSuperAdmin === true && props.ownerGroupId <= 0)
/** 直建表单:只收名称;组长=当前操作者,platform 恒 'jd'(京东侧作用域只认 jd 档)。 */
const newGroupName = ref('')
const creatingGroup = ref(false)
const canCreateGroup = computed(() =>
canBootstrapGroup.value && newGroupName.value.trim().length > 0 && !creatingGroup.value)
/** 平台超管空态直建第一个京东档分组:走分组管理同一条 POST(shop-manages/groups),
* 组长=当前操作者、组员先空。成功后 emit group-created 让父页整条作用域重取——
* ownerGroupId 翻到新组后由下方 watch 接手按新组重取分类,操作者接着就能建分类。 */
async function submitCreateGroup(): Promise<void> {
const name = newGroupName.value.trim()
if (!name || creatingGroup.value || !canBootstrapGroup.value) return
const operatorId = session.user?.id ?? 0
if (!operatorId) {
errorText.value = '无法获取当前登录用户,请重新登录'
return
}
creatingGroup.value = true
errorText.value = ''
try {
await createShopGroup(name, [], operatorId, 'jd')
newGroupName.value = ''
showAdminFeedback(`已新建京东档分组「${name}」`, 'success')
emit('group-created')
} catch (error) {
errorText.value = requestErrorMessage(error) || '新建分组失败'
} finally {
creatingGroup.value = false
}
}
async function loadGroups(): Promise<void> {
if (props.ownerGroupId <= 0) {
groups.value = []
@@ -151,13 +199,29 @@ async function submitRename(group: JdProductGroup): Promise<void> {
}
/** 删除分类不删商品:只解挂本组归属行(商品回到未分类),后端 JdProductGroupService.delete。 */
const batch = useRowSelection({
pageRows: () => pagedGroups.value,
rowId: (row) => row.id,
rowLabel: (row) => row.name,
deleteOne: (id) => deleteJdProductGroup(id),
refresh: async (outcome) => {
if (outcome.deleted.length) emit('changed')
await loadGroups()
},
blocked: () => !props.visible || !props.editable || loading.value || saving.value || creating.value || !!editingId.value || !!loadFailure.value,
scope: () => [props.visible, props.ownerGroupId, props.editable],
consequence: '分类下的商品将回到未分类,商品本身不会被删除。',
})
async function removeGroup(group: JdProductGroup): Promise<void> {
if (batch.busy) return
const ok = await openAdminConfirm({ title: '删除分类', message: `确定删除分类「${group.name}」吗?删除后该分类下 ${group.productCount} 个商品回到未分类。`, confirmText: '确认删除', danger: true })
if (!ok || saving.value) return
saving.value = true
errorText.value = ''
try {
await deleteJdProductGroup(group.id)
batch.removeFromSelection(group.id)
showAdminFeedback(`已删除分类「${group.name}」`, 'success')
emit('changed')
await loadGroups()
@@ -177,6 +241,7 @@ watch(
loadFailure.value = ''
cancelRename()
createName.value = ''
newGroupName.value = ''
pageNo.value = 1
void loadGroups()
}
@@ -185,6 +250,15 @@ watch(
{ immediate: true },
)
/** 建组成功后父页重取作用域会把 ownerGroupId 翻到新组:按新组重取分类列表,
* 操作者不用关弹窗重开就能接着建分类。 */
watch(
() => props.ownerGroupId,
(next, prev) => {
if (next > 0 && next !== prev) void loadGroups()
},
)
/** 改关键字回第一页(命中集变了,停在旧页码会落在空白处)。 */
watch(keyword, () => {
pageNo.value = 1
@@ -199,28 +273,38 @@ watch(totalPages, (pages) => {
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
<div class="manage-modal">
<div class="modal-head">
<h3>分类管理<span v-if="ownerGroupName" class="modal-sub">· {{ ownerGroupName }}</span></h3>
<h3>分类管理</h3>
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
</div>
<p class="modal-tip">
分类按「数据权限分组」隔离,当前组{{ editable ? '只组长/超管可维护' : '由组长/超管维护' }};
给商品归类:关掉本框,勾选商品后点「批量编辑分类」。
</p>
<div class="manage-bar">
<input v-model="keyword" class="search-input" type="text" placeholder="搜索分类名称" aria-label="搜索分类名称" />
<div v-if="editable" class="group-create">
<input v-model="createName" type="text" placeholder="输入新分类名称" aria-label="新分类名称" @keyup.enter="submitCreate" />
<button class="btn" type="button" :disabled="!canCreate" @click="submitCreate">新建</button>
<button class="btn" type="button" :disabled="batch.busy || !canCreate" @click="submitCreate">新建</button>
</div>
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="loadGroups" />
<p v-if="errorText" class="group-error">{{ errorText }}</p>
<BatchDeleteActions v-if="editable" :batch="batch" />
<!-- 表头(2026-11-18 用户红框口径):列表有数据时在搜索行下列出三列名,与行同构对齐;
只读口径下行没有改名/删除按钮,操作列表头随之不渲染。 -->
<div v-if="filteredGroups.length" class="option-head">
<BatchDeleteCheckbox v-if="editable" label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
<span class="head-name">分类名称</span>
<span class="head-count">商品数</span>
<span v-if="editable" class="head-actions">操作</span>
</div>
<ul class="option-list">
<template v-if="filteredGroups.length">
<li v-for="group in pagedGroups" :key="group.id" class="option-row">
<li v-for="group in pagedGroups" :key="group.id" class="option-row" :class="{ 'batch-selected': batch.isSelected(group) }">
<BatchDeleteCheckbox v-if="editable" :label="batch.reason(group) || `选择 ${batch.label(group)}`" :checked="batch.isSelected(group)"
:disabled="batch.disabled || !!batch.reason(group)" @change="batch.toggle(group)" />
<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">
@@ -232,14 +316,29 @@ watch(totalPages, (pages) => {
<span class="option-name" :title="group.name">{{ group.name }}</span>
<span class="option-meta" title="该分类下的商品数">{{ group.productCount }}</span>
<span v-if="editable" class="row-actions">
<button class="btn btn-sm btn-secondary" type="button" :disabled="saving" @click="startRename(group)">改名</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="saving" @click="removeGroup(group)">删除</button>
<button class="btn btn-sm btn-secondary" type="button" :disabled="saving || batch.busy" @click="startRename(group)">改名</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="saving || batch.busy" @click="removeGroup(group)">删除</button>
</span>
</template>
</li>
</template>
<li v-else-if="loading" class="manage-empty">加载中...</li>
<li v-else class="manage-empty">{{ emptyListText }}</li>
<li v-else class="manage-empty">
<template v-if="canBootstrapGroup">
<div class="group-bootstrap">
<input
v-model="newGroupName"
class="search-input"
type="text"
placeholder="输入分组名称"
aria-label="新分组名称"
@keyup.enter="submitCreateGroup"
/>
<button class="btn" type="button" :disabled="!canCreateGroup" @click="submitCreateGroup">新建分组</button>
</div>
</template>
<template v-else>{{ emptyListText }}</template>
</li>
</ul>
<div v-if="showPager" class="manage-pager">
@@ -293,12 +392,6 @@ watch(totalPages, (pages) => {
font-weight: 650;
color: #24384d;
}
.modal-sub {
margin-left: 6px;
color: #5b6f83;
font-size: 13px;
font-weight: 500;
}
.modal-close {
width: 30px;
height: 30px;
@@ -315,18 +408,16 @@ watch(totalPages, (pages) => {
background: #eef4fa;
color: #24384d;
}
.modal-tip {
margin: 8px 0 10px;
color: #8293a5;
font-size: 12.5px;
line-height: 1.5;
}
/* 2026-11-17 用户口径「垂直排阿,这样好看」「不然留白太多了」:搜索与新建各占整行
(原来两件并排 flex:1 各挤一半宽),弹窗内容变高、列表下方空白收窄,两行输入等宽也更整齐。 */
/* 2026-11-17 用户口径演变:「垂直排阿」→ 弹窗收窄到 340px 后「弄成一排呗」:
搜索框、新分类名输入、新建按钮合回一行。340−42=298px 可用宽度:新建按钮约 56
+两处 gap 16。实测按比例分(flex 1:1.75)会偏移(搜索 122/新建输入只剩 105,
7 字占位 115px 被截),改成搜索定宽 108px(6 字占位 102px 放得下),新建行吃剩余
(298−108−16=174,输入约 118px,占位完整)。 */
.manage-bar {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
gap: 8px;
align-items: center;
margin-bottom: 12px;
}
.search-input,
@@ -353,12 +444,14 @@ watch(totalPages, (pages) => {
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.search-input {
width: 100%;
flex: 0 0 108px;
min-width: 0;
}
.group-create {
display: flex;
flex: 1;
gap: 8px;
width: 100%;
min-width: 0;
}
.group-create input {
flex: 1;
@@ -373,6 +466,33 @@ watch(totalPages, (pages) => {
color: #a04432;
font-size: 13px;
}
/* 表头与行同形(同 gap、同左右内边距),列名只是淡色小字不抢行内容;
商品数列吃与徽标一致的 min-width/内边距,操作列同 rows 的 margin-left:auto 靠右。 */
.option-head {
display: flex;
align-items: center;
gap: 10px;
padding: 6px 8px;
border-bottom: 1px solid #e7eef5;
font-size: 12px;
color: #8293a5;
}
.head-name {
flex: 0 1 auto;
min-width: 0;
}
.head-count {
flex: none;
min-width: 22px;
padding: 0 7px;
text-align: center;
white-space: nowrap;
}
.head-actions {
flex: none;
margin-left: auto;
white-space: nowrap;
}
.option-list {
flex: 1;
min-height: 0;
@@ -427,6 +547,16 @@ watch(totalPages, (pages) => {
font-size: 13px;
list-style: none;
}
/* 平台超管空态直建分组:只有输入行(引导语/组长说明等小字 2026-11-17 用户口径「小字不需要」删除)。 */
.group-bootstrap {
display: flex;
gap: 8px;
}
.group-bootstrap .search-input {
flex: 1;
min-width: 0;
text-align: left;
}
.manage-pager {
display: flex;
align-items: center;
@@ -0,0 +1,845 @@
<script setup lang="ts">
/** 京东数据库页左侧栏(v1.6 蓝图 Phase 2,additive——页面接线随 Phase 5):
* 双 Tab=商品目录(京麦授权类目真树+计数徽标+展开折叠+树外兜底组)/
* 店铺分类(当前数据权限分组的分类平铺+计数+新建分类+分类管理入口)。
*
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本组件不发请求、
* 不 import api——mount 测试免 mock;内部状态只有双 Tab 切换、树展开/折叠与新建输入框。
* 计数聚合走 jdCategoryCountTree(v1.6 Phase 1):节点徽标=自身名+子树叶和(与
* 「点节点 → 子树展开 IN 过滤」的命中集合同源),树上对不上的历史行归「树外兜底」组
* (点兜底行=单名等值旧形状,path 空数组交给页面回落)。 */
import { computed, nextTick, ref, watch } from 'vue'
import {
jdCategoryCountTree,
type JdCategoryCountedNode,
} from './jd-category-tree.ts'
import type { JdProductCategoryOption, JdProductGroup } from './jd-product-api.ts'
const props = defineProps<{
/** /categories 计数行(京麦末级类目+商品数;页面持有,失败静默回空数组)。 */
categoryOptions: JdProductCategoryOption[]
/** 当前数据权限分组的分类(V203 归属口径,带 productCount 徽标;v1.7 每行可带
* shops 店铺名单——铺开渲染店铺行点选过滤,空分类也常驻「添加店铺」入口)。 */
categories: JdProductGroup[]
/** 当前分组分类可写(scope.editable 投影):可写档渲染「新建分类」行、分类/店铺行的
* hover 改名/删除与「添加店铺」入口;「分类管理」入口对所有人渲染(同组普通号只读可看,
* V203,写控件由对话框分档)。 */
editable: boolean
/** 当前类目选中(name+完整名称路径;树外历史名 path 为空数组;null=全部商品)。 */
selectedCategory?: { name: string; path: string[] } | null
/** 当前分类选中 id(null=全部分类)。 */
selectedGroupId?: number | null
/** 当前店铺筛选(v1.7 店铺名单点选;空/缺省=未按店铺过滤)。 */
selectedShopName?: string | null
}>()
const emit = defineEmits<{
/** 选类目:树内节点带完整路径(页面按子树展开类目名集合 IN 下发);树外兜底名
* path=[](序列化回落单名等值);null=「全部商品」清选重查。 */
(event: 'select-category', value: { name: string; path: string[] } | null): void
/** 选分类:分类 id;再点已选中的=清选(emit null,回全部分类)。 */
(event: 'select-group', id: number | null): void
/** 选店铺(v1.7 名单点选):分类+店铺名成对下发(点店铺=该分类归属 ∩ 该店铺,
* 精确 eq);再点已选中的=emit null(只清店铺筛选,分类选中保留)。 */
(event: 'select-shop', value: { groupId: number; shopName: string } | null): void
/** 新建分类(可写档):页面调 createJdProductGroup 落当前分组,成功后刷新,
* 侧栏数据随 props 流回(本组件不感知成功/失败,输入框提交即清)。 */
(event: 'create-category', name: string): void
/** 分类行内改名(可写档 hover ✎):分类 id+新名,API 调用与刷新在页面。 */
(event: 'rename-category', category: JdProductGroup, name: string): void
/** 分类行内删除(可写档 hover ✕):页面二次确认后调 deleteJdProductGroup。 */
(event: 'delete-category', category: JdProductGroup): void
/** 店铺行内改名(可写档 hover ✎):分类、老名、新名(同分类查重 409 由后端拒)。 */
(event: 'rename-shop', category: JdProductGroup, oldName: string, newName: string): void
/** 店铺行内移除(可写档 hover ✕):页面调 removeJdGroupShop。 */
(event: 'remove-shop', category: JdProductGroup, shopName: string): void
/** 打开添加店铺弹窗(可写档「+ 添加店铺」行):弹窗与提交在页面。 */
(event: 'add-shops', category: JdProductGroup): void
/** 打开分类管理对话框(建/改名/删+搜索,V204 并入的既有组件)。 */
(event: 'manage-categories'): void
}>()
/** 左 Tab 内置展示态:出厂停在「商品目录」(首屏主筛选面)。 */
const activeTab = ref<'catalog' | 'custom'>('catalog')
// ---------------- 计数聚合(Phase 1 纯函数) ----------------
const counted = computed(() => jdCategoryCountTree(props.categoryOptions ?? []))
/** 「全部商品」徽标=全部计数行求和(树内+树外=有类目名的商品总数;无类目名的行
* 不在任何类目筛选的命中集里,不计进任何徽标)。 */
const totalCount = computed(() =>
(props.categoryOptions ?? []).reduce((sum, row) => sum + (row.productCount || 0), 0))
/** 展开态:按路径串('/' 连接)记,含树外兜底组头。出厂(无记忆)一级默认展开(二级可见);
* 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('/')
function persistExpanded(): void {
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 },
)
// ---------------- 商品目录树:扁平渲染(深度缩进 + 祖先全展开才可见) ----------------
interface FlatNode {
node: JdCategoryCountedNode
path: string[]
depth: number
}
const flatTree = computed<FlatNode[]>(() => {
const out: FlatNode[] = []
const walk = (nodes: JdCategoryCountedNode[], depth: number, prefix: string[]): void => {
for (const node of nodes) {
const path = [...prefix, node.name]
out.push({ node, path, depth })
if (node.children.length && expanded.value.has(expandKey(path))) {
walk(node.children, depth + 1, path)
}
}
}
walk(counted.value.roots, 0, [])
return out
})
function toggleExpand(path: string[]): void {
const key = expandKey(path)
const next = new Set(expanded.value)
if (next.has(key)) next.delete(key)
else next.add(key)
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()
}
/** 点树行=选中即筛;非末级行顺手展开(下钻感,与京麦列表筛选器同形;收起走箭头)。 */
function pickNode(node: FlatNode): void {
if (node.node.children.length && !expanded.value.has(expandKey(node.path))) {
toggleExpand(node.path)
}
emit('select-category', { name: node.node.name, path: node.path })
}
/** 外部选中态(重置/清选/页面回显):展开选中节点的全部祖先,让它可见,并把选中行
* 滚进视口(v1.7 树增强;jsdom 无 scrollIntoView 自动跳过——测试不需要真滚)。
* immediate=页面带着已激活的类目筛选挂载侧栏时(如切换回本页),选中路径直接展开到位。 */
watch(
() => props.selectedCategory,
(selected) => {
if (!selected || !selected.path.length) return
const next = new Set(expanded.value)
for (let i = 1; i < selected.path.length; i++) {
next.add(expandKey(selected.path.slice(0, i)))
}
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 },
)
const isSelectedNode = (node: FlatNode): boolean => {
const selected = props.selectedCategory
if (!selected || selected.path.length !== node.path.length) return false
return selected.path.every((name, index) => name === node.path[index])
}
// ---------------- 树外兜底组(树上对不上的历史行,单名等值出口) ----------------
const extraOpen = ref(true)
function pickExtra(name: string): void {
// 树外名不进树:path 空数组=页面按「无路径」序列化(单名等值旧形状,不静默丢筛选)。
emit('select-category', { name, path: [] })
}
const isSelectedExtra = (name: string): boolean => {
const selected = props.selectedCategory
return !!selected && selected.path.length === 0 && selected.name === name
}
// ---------------- 店铺分类 Tab(当前分组分类平铺+店铺名单 v1.7) ----------------
function pickGroup(group: JdProductGroup): void {
// 再点已选中的=清选(回全部分类),与旧「全部分类」下拉行的语义等价。
// 店铺筛选随分类清选一起走(店铺名单挂在分类下,分类清了店铺筛选无意义——页面同清)。
emit('select-group', props.selectedGroupId === group.id ? null : group.id)
}
const newCategoryName = ref('')
function submitCreate(): void {
const name = newCategoryName.value.trim()
if (!name) return
emit('create-category', name)
newCategoryName.value = ''
}
// ---------------- 店铺名单(v1.7 F6 完整对齐原型:分类下挂店铺名单) ----------------
/** 名单铺开渲染(2026-11-22 原型对齐:分类→店铺名单→「+ 添加店铺」直接可见)。
* 旧折叠版把入口藏在展开区里,且箭头只在已有名单时才出 ⇒ 空分类永远加不进
* 第一个店铺(死锁);铺开后名单与入口常驻,空分类直接可加。 */
function pickShop(group: JdProductGroup, shopName: string): void {
const picked = props.selectedGroupId === group.id && props.selectedShopName === shopName
emit('select-shop', picked ? null : { groupId: group.id, shopName })
}
// 行内改名(分类与店铺同构):点 hover ✎ 进编辑形态,Enter/✓ 提交、✕ 取消。
const renamingCategory = ref<number | null>(null)
const renameCategoryDraft = ref('')
const renamingShop = ref<{ categoryId: number; name: string } | null>(null)
const renameShopDraft = ref('')
function startRenameCategory(group: JdProductGroup): void {
cancelShopRename()
renamingCategory.value = group.id
renameCategoryDraft.value = group.name
}
function submitRenameCategory(group: JdProductGroup): void {
const name = renameCategoryDraft.value.trim()
cancelRenameCategory()
// 空名/未改动不 emit(静默收编辑态,不白发请求)。
if (!name || name === group.name) return
emit('rename-category', group, name)
}
function cancelRenameCategory(): void {
renamingCategory.value = null
renameCategoryDraft.value = ''
}
function startRenameShop(group: JdProductGroup, shopName: string): void {
cancelRenameCategory()
renamingShop.value = { categoryId: group.id, name: shopName }
renameShopDraft.value = shopName
}
function submitRenameShop(group: JdProductGroup): void {
const entry = renamingShop.value
if (!entry) return
const name = renameShopDraft.value.trim()
cancelShopRename()
if (!name || name === entry.name) return
emit('rename-shop', group, entry.name, name)
}
function cancelShopRename(): void {
renamingShop.value = null
renameShopDraft.value = ''
}
</script>
<template>
<aside class="jd-sidebar" aria-label="商品目录与店铺分类">
<div class="jd-sidebar-tabs" role="tablist">
<button
type="button"
role="tab"
:aria-selected="activeTab === 'catalog'"
class="jd-sidebar-tab"
:class="{ active: activeTab === 'catalog' }"
@click="activeTab = 'catalog'"
>商品目录</button>
<button
type="button"
role="tab"
:aria-selected="activeTab === 'custom'"
class="jd-sidebar-tab"
:class="{ active: activeTab === 'custom' }"
@click="activeTab = 'custom'"
>店铺分类</button>
</div>
<!-- 商品目录:全部商品 + 京麦授权类目树(计数徽标)+ 树外兜底组 -->
<div v-show="activeTab === 'catalog'" class="jd-sidebar-body jd-side-catalog">
<button
type="button"
class="jd-side-row jd-side-all"
:class="{ selected: !selectedCategory }"
@click="emit('select-category', null)"
>
<span class="jd-side-name">全部商品</span>
<span class="jd-side-count">{{ totalCount }}</span>
</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">
<button
v-for="flat in flatTree"
:key="flat.path.join('/')"
type="button"
class="jd-side-row"
:class="[`depth-${flat.depth}`, { selected: isSelectedNode(flat) }]"
:title="flat.path.join(' / ')"
@click="pickNode(flat)"
>
<span
v-if="flat.node.children.length"
class="jd-side-arrow"
:class="{ open: expanded.has(flat.path.join('/')) }"
role="button"
:aria-label="`展开或收起 ${flat.node.name}`"
@click.stop="toggleExpand(flat.path)"
>▸</span>
<span v-else class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ flat.node.name }}</span>
<span class="jd-side-count">{{ flat.node.count }}</span>
</button>
</div>
<div v-if="counted.extra.length" class="jd-side-extra">
<button
type="button"
class="jd-side-row jd-side-extra-head"
:aria-expanded="extraOpen"
@click="extraOpen = !extraOpen"
>
<span class="jd-side-name">树外兜底</span>
<span class="jd-side-count">{{ counted.extraTotal }}</span>
</button>
<template v-if="extraOpen">
<button
v-for="row in counted.extra"
:key="row.name"
type="button"
class="jd-side-row depth-1"
:class="{ selected: isSelectedExtra(row.name) }"
:title="row.name"
@click="pickExtra(row.name)"
>
<span class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ row.name }}</span>
<span class="jd-side-count">{{ row.productCount }}</span>
</button>
</template>
</div>
</div>
<!-- 店铺分类:新建分类(可写档)+ 分类管理入口(所有人)置顶(2026-11-21 用户口径
「换一下位置」,红框块挪到 Tab 正下方),分类平铺随其后。 -->
<div v-show="activeTab === 'custom'" class="jd-sidebar-body jd-side-custom">
<div v-if="editable" class="jd-side-create">
<input
v-model="newCategoryName"
type="text"
placeholder="新分类名称"
aria-label="新分类名称"
@keyup.enter="submitCreate"
/>
<button type="button" :disabled="!newCategoryName.trim()" @click="submitCreate">新建分类</button>
</div>
<button type="button" class="jd-side-manage" @click="emit('manage-categories')">分类管理</button>
<template v-if="categories.length">
<!-- 分类行(div role=button,行内要嵌 hover 操作按钮——button 嵌 button 非法 HTML):
铺开形态(2026-11-22 原型对齐)无折叠箭头;可写档 hover 出改名/删除;
名单店铺行与「添加店铺」入口直接铺在分类行下。 -->
<template v-for="cat in categories" :key="cat.id">
<div
class="jd-side-row jd-side-cat"
role="button"
tabindex="0"
:class="{ selected: selectedGroupId === cat.id }"
:title="cat.name"
@click="pickGroup(cat)"
@keydown.enter="pickGroup(cat)"
>
<span class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ cat.name }}</span>
<span class="jd-side-count">{{ cat.productCount }}</span>
<span v-if="editable" class="jd-side-ops">
<button
type="button"
class="jd-side-op"
:aria-label="`改名分类 ${cat.name}`"
title="改名"
@click.stop="startRenameCategory(cat)"
>✎</button>
<button
type="button"
class="jd-side-op jd-side-op-danger"
:aria-label="`删除分类 ${cat.name}`"
title="删除"
@click.stop="emit('delete-category', cat)"
>✕</button>
</span>
</div>
<!-- 分类行内改名(编辑形态替换该行):Enter/✓ 提交(空名/未改动静默收起)。 -->
<div v-if="renamingCategory === cat.id" class="jd-side-inline-edit">
<input
v-model="renameCategoryDraft"
type="text"
:aria-label="`修改分类名称(原:${cat.name})`"
@keyup.enter="submitRenameCategory(cat)"
/>
<button type="button" :aria-label="`确认改名分类 ${cat.name}`" @click.stop="submitRenameCategory(cat)">✓</button>
<button type="button" aria-label="取消改名" @click.stop="cancelRenameCategory()">✕</button>
</div>
<!-- 铺开的店铺名单(v1.7 铺开形态):点店铺=分类+店铺成对过滤;可写档 hover 改名/移除;
名单尾「+ 添加店铺」入口常驻(空分类也能加第一个店)开页面级弹窗。 -->
<template v-for="shop in (cat.shops ?? [])" :key="`${cat.id}:${shop}`">
<div
class="jd-side-row jd-side-shop depth-1"
role="button"
tabindex="0"
:class="{ selected: selectedGroupId === cat.id && selectedShopName === shop }"
:title="shop"
@click="pickShop(cat, shop)"
@keydown.enter="pickShop(cat, shop)"
>
<span class="jd-side-leaf-dot" />
<span class="jd-side-name">{{ shop }}</span>
<span v-if="editable" class="jd-side-ops">
<button
type="button"
class="jd-side-op"
:aria-label="`改名店铺 ${shop}`"
title="改名"
@click.stop="startRenameShop(cat, shop)"
>✎</button>
<button
type="button"
class="jd-side-op jd-side-op-danger"
:aria-label="`移除店铺 ${shop}`"
title="移除"
@click.stop="emit('remove-shop', cat, shop)"
>✕</button>
</span>
</div>
<!-- 店铺行内改名(编辑形态替换该行)。 -->
<div v-if="renamingShop && renamingShop.categoryId === cat.id" class="jd-side-inline-edit jd-side-shop-edit depth-1">
<input
v-model="renameShopDraft"
type="text"
:aria-label="`修改店铺名称(原:${renamingShop.name})`"
@keyup.enter="submitRenameShop(cat)"
/>
<button type="button" :aria-label="`确认改名店铺 ${renamingShop.name}`" @click.stop="submitRenameShop(cat)">✓</button>
<button type="button" aria-label="取消改名" @click.stop="cancelShopRename()">✕</button>
</div>
</template>
<button
v-if="editable"
type="button"
class="jd-side-row jd-side-shop-add depth-1"
@click="emit('add-shops', cat)"
>
<span class="jd-side-leaf-dot" />
<span class="jd-side-name">+ 添加店铺</span>
</button>
</template>
</template>
<p v-else class="jd-side-empty">{{ editable ? '本组暂无分类,先新建一个' : '本组暂无分类' }}</p>
</div>
</aside>
</template>
<style scoped>
.jd-sidebar {
width: 232px;
flex-shrink: 0;
background: #fff;
border: 1px solid #e4e7ed;
border-radius: 8px;
overflow: hidden;
/* 左右高度对齐(2026-11-21 用户口径):侧栏外框随主面板拉满(页面容器已改 stretch),
自身转纵向 flex——Tab 行固定、滚动区吃剩余高度,第三张截图红框那截空白带消失。 */
display: flex;
flex-direction: column;
align-self: stretch;
}
.jd-sidebar-tabs {
display: flex;
flex-shrink: 0;
border-bottom: 1px solid #e4e7ed;
}
.jd-sidebar-tab {
flex: 1;
padding: 10px 0;
border: none;
background: transparent;
cursor: pointer;
font-size: 14px;
color: #606266;
}
.jd-sidebar-tab.active {
color: #409eff;
font-weight: 600;
box-shadow: inset 0 -2px 0 #409eff;
}
.jd-sidebar-body {
display: flex;
flex-direction: column;
/* 等高对齐下的滚动区:放弃 640px 上限(上限会让宽屏侧栏短于主面板=又不对齐),
flex 吃满侧栏剩余高度,树/分类超出时内部滚动。窄屏(≤980px)侧栏整行摆放时
恢复上限,防树全展开把整页拉长(断点与页面装配层一致)。 */
flex: 1 1 auto;
min-height: 0;
overflow-y: auto;
padding: 6px;
/* 滚动带常驻(2026-11-21 用户口径「这边还要个进度条」,红框指树右缘滚动带):
Win 新版 Chrome/Edge 的 fluent overlay 滚动条不悬停不显形,长类目树看不出可滚;
标准属性(Chrome/Edge/Firefox 通用)+自绘 webkit 滚动条兜旧版,无溢出时不占位。 */
scrollbar-width: thin;
scrollbar-color: #bccfe1 transparent;
}
.jd-sidebar-body::-webkit-scrollbar {
width: 8px;
}
.jd-sidebar-body::-webkit-scrollbar-track {
background: transparent;
}
.jd-sidebar-body::-webkit-scrollbar-thumb {
background: #bccfe1;
border-radius: 4px;
}
.jd-sidebar-body::-webkit-scrollbar-thumb:hover {
background: #9fb7cd;
}
@media (max-width: 980px) {
.jd-sidebar-body {
max-height: 480px;
}
}
.jd-side-row {
display: flex;
align-items: center;
gap: 6px;
width: 100%;
padding: 6px 8px;
border: none;
background: transparent;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
color: #303133;
text-align: left;
}
.jd-side-row:hover {
background: #f5f7fa;
}
.jd-side-row.selected {
background: #ecf5ff;
color: #409eff;
font-weight: 600;
}
.jd-side-row.depth-1 { padding-left: 22px; }
.jd-side-row.depth-2 { padding-left: 36px; }
.jd-side-row.depth-3 { padding-left: 50px; }
.jd-side-arrow {
width: 14px;
flex-shrink: 0;
color: #909399;
transition: transform 0.15s;
cursor: pointer;
}
.jd-side-arrow.open {
transform: rotate(90deg);
}
.jd-side-leaf-dot {
width: 14px;
flex-shrink: 0;
text-align: center;
color: #c0c4cc;
}
.jd-side-leaf-dot::before {
content: '·';
}
.jd-side-name {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.jd-side-count {
flex-shrink: 0;
min-width: 24px;
text-align: right;
font-size: 12px;
color: #909399;
background: #f0f2f5;
border-radius: 10px;
padding: 1px 7px;
}
.jd-side-row.selected .jd-side-count {
color: #409eff;
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 {
margin-top: 4px;
border-top: 1px dashed #e4e7ed;
padding-top: 4px;
}
.jd-side-extra-head {
color: #909399;
}
.jd-side-empty {
margin: 8px 4px;
font-size: 13px;
color: #909399;
text-align: center;
}
.jd-side-create {
display: flex;
gap: 6px;
/* 置顶档(2026-11-21 换位):贴 Tab 行下方,分隔虚线随位置挪到「分类管理」与列表之间。 */
margin-top: 4px;
padding: 6px 4px;
}
.jd-side-create input {
flex: 1;
min-width: 0;
padding: 5px 8px;
border: 1px solid #dcdfe6;
border-radius: 6px;
font-size: 13px;
}
.jd-side-create button {
padding: 5px 10px;
border: 1px solid #dcdfe6;
border-radius: 6px;
background: #fff;
cursor: pointer;
font-size: 13px;
color: #409eff;
}
.jd-side-create button:disabled {
color: #c0c4cc;
cursor: not-allowed;
}
.jd-side-manage {
margin-top: 0;
margin-bottom: 4px;
padding: 6px 8px;
border: none;
/* 置顶档:虚线分隔「控制块 ↔ 分类列表」。 */
border-bottom: 1px dashed #e4e7ed;
background: transparent;
color: #606266;
font-size: 13px;
cursor: pointer;
text-align: left;
}
.jd-side-manage:hover {
color: #409eff;
}
/* 店铺名单(v1.7 F6):分类行 hover 操作钮(改名/删除)、店铺行缩进、行内改名编辑形态、
「+ 添加店铺」入口。行本体是 div role=button(行内嵌操作按钮,button 嵌 button 非法)。 */
.jd-side-row.jd-side-cat,
.jd-side-row.jd-side-shop {
cursor: pointer;
}
/* hover 操作钮:默认藏,行 hover 时浮出(占位 0 宽,不挤名字/徽标布局)。 */
.jd-side-ops {
display: inline-flex;
gap: 2px;
flex-shrink: 0;
width: 0;
overflow: hidden;
transition: width 120ms ease;
}
.jd-side-row:hover .jd-side-ops,
.jd-side-row:focus-within .jd-side-ops {
width: 36px;
}
.jd-side-op {
width: 17px;
height: 17px;
padding: 0;
border: none;
border-radius: 4px;
background: transparent;
color: #909399;
font-size: 11px;
line-height: 1;
cursor: pointer;
}
.jd-side-op:hover {
background: #e6edf4;
color: #409eff;
}
.jd-side-op-danger:hover {
background: #fdf1ef;
color: #a04432;
}
/* 行内改名编辑形态:替换该行的紧凑输入行(Enter/✓ 提交、✕ 取消)。 */
.jd-side-inline-edit {
display: flex;
align-items: center;
gap: 4px;
padding: 3px 8px;
}
.jd-side-inline-edit.jd-side-shop-edit {
padding-left: 22px;
}
.jd-side-inline-edit input {
flex: 1;
min-width: 0;
padding: 4px 8px;
border: 1px solid #9fc3e8;
border-radius: 6px;
font-size: 12.5px;
font-family: inherit;
outline: none;
}
.jd-side-inline-edit input:focus {
box-shadow: 0 0 0 2px rgba(95, 133, 173, 0.18);
}
.jd-side-inline-edit button {
width: 22px;
height: 24px;
padding: 0;
border: 1px solid #dcdfe6;
border-radius: 6px;
background: #fff;
color: #409eff;
font-size: 12px;
line-height: 1;
cursor: pointer;
}
.jd-side-inline-edit button:last-child {
color: #909399;
}
/* 「+ 添加店铺」入口:名单尾部的弱化行(虚线上缘分隔),可写档才渲染(v-if 在模板)。 */
.jd-side-shop-add {
color: #409eff;
border-top: 1px dashed #e4e7ed;
border-radius: 0;
}
.jd-side-shop-add:hover {
color: #2f7cd6;
background: #f0f7ff;
}
</style>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,263 @@
<script setup lang="ts">
/** 京东商品卡片(v1.6 蓝图 Phase 3;v1.7 Phase 4 对齐原型交互):
* 主图(无图占位)/店铺徽标/标题/价格区间/商品编码+复制/采集日期/勾选框,
* 字段映射与现表格「商品信息」列逐字段同源(价格走 jdPriceRange、日期走 formatDateTime)。
*
* v1.7 交互增强(F7/F1):点图片区=切换勾选(可勾选档;不可勾选档点图照常开详情)、
* 图片 hover 出「点击选择/点击取消」提示胶囊。(右上角「已下载」角标随 CSV 导出功能
* 整体下线,2026-11-21 用户拍板「删除掉」导出按钮。)
*
* 2026-11-21 用户口径「这边改成分类名称就可以 自己分类的那个名称就可以」:图底条从
* 店铺名改显归属分类名(groupName,后端 fillGroupNames 按当前分组补)——没归入分类的
* 出「未分类」,条常驻渲染;店铺名不再上卡(详情弹窗仍可看)。
*
* 纯展示组件:入参=item+选中态+可勾选档;出事件=切换勾选、打开详情、
* 复制编码。卡片整体点击=开详情;勾选与复制 @click.stop 防冒泡(与现表格行
* @click.stop 同形)。healthScore 徽标随图渲染(现表格同款「信息分」),null 不渲染。 */
import { formatDateTime } from '@/utils/datetime'
import { jdPriceRange, type JdProductItem } from './jd-product-model.ts'
const props = defineProps<{
/** 列表行(解析层归一后的 JdProductItem)。 */
item: JdProductItem
/** 勾选态(页面持有,跨页累计记忆)。 */
selected?: boolean
/** 可勾选档:管理员级/本组可写分类账号才渲染勾选框(页面按 canWriteProducts∨canManageCategories 投影)。 */
selectable?: boolean
}>()
const emit = defineEmits<{
/** 勾选切换(checked 来自 checkbox 原生 change 或点图片区)。 */
(event: 'toggle-select', checked: boolean): void
/** 打开详情(卡片整体点击;详情弹窗/抽屉由页面渲染)。 */
(event: 'open'): void
/** 复制商品编码(剪贴板与回执文案在页面,与现表格 copyText 同一条链)。 */
(event: 'copy'): void
}>()
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>
<template>
<article class="jd-card" :class="{ selected: props.selected }" @click="emit('open')">
<label v-if="props.selectable" class="jd-card-check" @click.stop>
<input
type="checkbox"
:checked="props.selected"
aria-label="勾选商品"
@change="emit('toggle-select', ($event.target as HTMLInputElement).checked)"
/>
</label>
<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" />
<span v-else class="jd-card-thumb jd-card-thumb-empty">无图</span>
<!-- 右上角徽标:信息分(随图渲染,null 不出)。 -->
<span class="jd-card-badges">
<span v-if="props.item.healthScore !== null" class="jd-card-health">信息分 {{ props.item.healthScore }}</span>
</span>
<!-- hover 提示胶囊(v1.7):可勾选档才出,随选中态换文案。 -->
<span v-if="props.selectable" class="jd-card-hover-tip">{{ props.selected ? '点击取消' : '点击选择' }}</span>
<span class="jd-card-category" :title="props.item.groupName || '未分类'">{{ props.item.groupName || '未分类' }}</span>
</div>
<div class="jd-card-body">
<div class="jd-card-title" :title="props.item.title">{{ props.item.title || '-' }}</div>
<div class="jd-card-price">{{ priceText() }}</div>
<div class="jd-card-meta">
<span class="jd-card-code" :title="props.item.productCode">商品编码:{{ props.item.productCode || '-' }}</span>
<button
v-if="props.item.productCode"
class="jd-card-copy"
type="button"
title="复制商品编码"
@click.stop="emit('copy')"
>⧉</button>
</div>
<div class="jd-card-date">采集:{{ formatDateTime(props.item.syncedAt || '') }}</div>
</div>
</article>
</template>
<style scoped>
.jd-card {
position: relative;
display: flex;
flex-direction: column;
background: #fff;
border: 1px solid #e4e7ed;
border-radius: 8px;
overflow: hidden;
cursor: pointer;
transition: box-shadow 0.15s, border-color 0.15s;
}
.jd-card:hover {
border-color: #c6e2ff;
box-shadow: 0 2px 12px rgba(64, 158, 255, 0.12);
}
.jd-card.selected {
border-color: #409eff;
box-shadow: 0 0 0 1px #409eff inset;
}
.jd-card-check {
position: absolute;
top: 8px;
left: 8px;
z-index: 2;
line-height: 1;
cursor: pointer;
}
.jd-card-check input {
width: 15px;
height: 15px;
cursor: pointer;
}
.jd-card-figure {
position: relative;
aspect-ratio: 1 / 1;
background: #f5f7fa;
}
/* 可勾选档的图片区才是「点图切换勾选」热区;不可勾选档不加该类(点图冒泡开详情)。 */
.jd-card-figure.jd-card-figure-pick {
cursor: pointer;
}
.jd-card-thumb {
width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
.jd-card-thumb-empty {
display: flex;
align-items: center;
justify-content: center;
color: #c0c4cc;
font-size: 13px;
}
/* 右上角徽标容器:信息分徽标随图渲染(原「已下载」角标槽位随导出功能退役,容器保留)。 */
.jd-card-badges {
position: absolute;
top: 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);
color: #e6a23c;
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-category {
position: absolute;
bottom: 0;
left: 0;
right: 0;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
background: rgba(48, 49, 51, 0.62);
color: #fff;
font-size: 12px;
padding: 3px 8px;
}
.jd-card-body {
display: flex;
flex-direction: column;
gap: 6px;
padding: 10px 12px 12px;
}
.jd-card-title {
font-size: 13px;
color: #303133;
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
min-height: 2.8em;
}
.jd-card-price {
font-size: 16px;
font-weight: 600;
color: #f56c6c;
}
.jd-card-meta {
display: flex;
align-items: center;
gap: 4px;
font-size: 12px;
color: #606266;
}
.jd-card-code {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.jd-card-copy {
flex-shrink: 0;
border: none;
background: transparent;
cursor: pointer;
color: #409eff;
font-size: 13px;
padding: 0 2px;
}
.jd-card-date {
font-size: 12px;
color: #909399;
}
</style>
@@ -1,10 +1,12 @@
<script setup lang="ts">
/** 京东商品详情抽屉(v1.4 Phase 5):点行打开,展示基本信息 + attrGroups 分块表格 +
* 图片网格(MAIN/ATTR/DETAIL 三区,attr 图按 attrName 归并)。
* 基本信息=商品全部字段(B104:列表只摆部分字段,类目/信息分/SKU 数/上架时间/京东创建/
* 修改时间/店铺/分组都在这里看)。
* 图片点击放大预览用自绘 modal-mask(先例:RecordsHistoryPage 的 thumb + modal-mask +
* 原图新标签;不用 element-plus)。数据由本组件按 id 自取(公共库无公司维度),失败条内提示可重试。 */
/** 京东商品详情内容块(v1.6 蓝图 Phase 4,从 JdProductDetailDrawer 原样抽出):
* 数据自取(fetchJdProductDetail,失败条内可重试)+ hero「左图右信息」(2026-11-16 客户口径
* 「详情页样式和京麦商品详情一样」)+ attrGroups 分块表格(解析失败回 attrJsonRaw 原文)+
* SKU 矩阵 + 图片三区(MAIN/ATTR/DETAIL,attr 图按 attrName 归并)+ 自绘放大预览。
*
* Drawer(侧滑薄壳)与 Modal(居中弹窗壳)共用本组件:壳只管 chrome(遮罩/标题/关闭/
* 动作按钮),内容与取数全在这里——两条壳的行为由同一份实现保证等价。模板与类名照搬
* 旧抽屉(.detail-hero/.hero-main/.hero-info 等被页面 mount 测试逐字钉住,不得改名)。 */
import { computed, ref, watch } from 'vue'
import { fetchJdProductDetail } from './jd-product-api.ts'
import type {
@@ -22,8 +24,6 @@ const props = defineProps<{
visible: boolean
}>()
const emit = defineEmits<{ (event: 'close'): void }>()
const loading = ref(false)
const loadFailure = ref('')
const attrGroups = ref<JdProductAttrGroup[]>([])
@@ -42,8 +42,7 @@ function skuAttrValue(sku: JdProductSku, dimension: string): string {
/** 图片三区:MAIN / ATTR / DETAIL;未知类型归 DETAIL 之外的「其他」,不丢。 */
const mainImages = computed(() => images.value.filter((image) => image.imageType === 'MAIN'))
/** 顶部画廊(2026-11-16 客户口径「详情页样式和京麦商品详情一样」=左图右信息):
* 左侧主图大图+缩略图切换(MAIN 档),右侧关键信息。 */
/** 顶部画廊:左侧主图大图+缩略图切换(MAIN 档),右侧关键信息。 */
const galleryImages = computed(() => mainImages.value)
const activeImageUrl = ref('')
@@ -75,11 +74,6 @@ function openPreview(url: string): void {
previewVisible.value = true
}
function close(): void {
previewVisible.value = false
emit('close')
}
async function loadDetail(): Promise<void> {
const item = props.item
if (!item) return
@@ -107,6 +101,9 @@ async function loadDetail(): Promise<void> {
}
}
/** 打开/换行即取数。immediate 必须带:两条壳都把本组件放在 `v-if="visible"` 的遮罩里,
* 关闭时整组件卸载——重挂载(visible 已是 true)没有"变更"可触发,非 immediate 的
* watch 永远不跑=弹窗永远停在加载中(2026-11-21 薄壳化实测真红)。 */
watch(
() => [props.visible, props.item?.id] as const,
([visible]) => {
@@ -115,6 +112,7 @@ watch(
activeImageUrl.value = ''
if (visible && props.item) void loadDetail()
},
{ immediate: true },
)
function dash(value: string | number | null | undefined): string {
@@ -124,184 +122,177 @@ function dash(value: string | number | null | undefined): string {
</script>
<template>
<div v-if="visible" class="drawer-mask" @click.self="close">
<aside class="drawer">
<header class="drawer-head">
<h3>商品详情{{ item?.productCode ? ` · ${item.productCode}` : '' }}</h3>
<button class="drawer-close" type="button" aria-label="关闭" @click="close">×</button>
</header>
<!-- 根节点随 visible 显隐:壳(Drawer/Modal)关闭时预览浮层必须一起摘掉,
不能留在 fixed 蒙层里挡住整屏(旧抽屉的 v-if 边界原样搬移)。 -->
<div v-if="visible" class="detail-content">
<div v-if="loadFailure" class="drawer-failure">
<span>{{ loadFailure }}</span>
<button class="btn btn-secondary" type="button" @click="loadDetail">重试</button>
</div>
<p v-else-if="loading" class="drawer-tip">加载中...</p>
<div class="drawer-body">
<div v-if="loadFailure" class="drawer-failure">
<span>{{ loadFailure }}</span>
<button class="btn btn-secondary" type="button" @click="loadDetail">重试</button>
<template v-else>
<!-- 顶部「左图右信息」(2026-11-16 客户口径「详情页的样式要和京麦商品详情一样的布局样式」):
左侧主图大图+缩略图切换,右侧关键信息;属性/SKU/详情图等区块保持下方。 -->
<section class="detail-block">
<div class="detail-hero">
<div class="hero-gallery">
<img
v-if="activeImageUrl"
class="hero-main"
:src="activeImageUrl"
alt=""
title="点击放大预览"
@click="openPreview(activeImageUrl)"
/>
<div v-else class="hero-empty">无图</div>
<div v-if="galleryImages.length > 1" class="hero-thumbs">
<img
v-for="image in galleryImages"
:key="image.id"
:src="image.url"
alt=""
loading="lazy"
:class="{ active: image.url === activeImageUrl }"
title="切换主图"
@click="switchGallery(image)"
/>
</div>
</div>
<dl class="hero-info">
<div class="info-item info-item-wide hero-title">
<dt>标题</dt>
<dd :title="item?.title || ''">{{ dash(item?.title) }}</dd>
</div>
<div class="info-item"><dt>价格区间</dt><dd>{{ dash(jdPriceRange(item ?? { priceMin: '', priceMax: '' })) }}</dd></div>
<div class="info-item"><dt>总库存</dt><dd>{{ dash(item?.stockTotal) }}</dd></div>
<div class="info-item"><dt>状态</dt><dd>{{ dash(item?.saleStatus) }}</dd></div>
<div class="info-item"><dt>信息分</dt><dd>{{ dash(item?.healthScore) }}</dd></div>
<div class="info-item"><dt>SKU 数</dt><dd>{{ dash(item?.skuCount) }}</dd></div>
<div class="info-item"><dt>商品编码</dt><dd>{{ dash(item?.productCode) }}</dd></div>
<div class="info-item"><dt>货号</dt><dd>{{ dash(item?.itemNum) }}</dd></div>
<div class="info-item"><dt>SKU</dt><dd>{{ dash(item?.skuId) }}</dd></div>
<div class="info-item"><dt>品牌</dt><dd>{{ dash(item?.brand) }}</dd></div>
<div class="info-item"><dt>店铺</dt><dd :title="item?.shopName || ''">{{ dash(item?.shopName) }}</dd></div>
<div class="info-item"><dt>分类</dt><dd>{{ dash(item?.groupName || '未分类') }}</dd></div>
<div class="info-item info-item-wide"><dt>类目</dt><dd :title="item?.categoryPath || ''">{{ dash(item?.categoryPath) }}</dd></div>
<div class="info-item"><dt>上架时间</dt><dd>{{ item?.jdOnlineAt ? formatDateTime(item.jdOnlineAt) : '-' }}</dd></div>
<div class="info-item"><dt>同步时间</dt><dd>{{ formatDateTime(item?.syncedAt || '') }}</dd></div>
<div class="info-item"><dt>京东创建时间</dt><dd>{{ item?.jdCreatedAt ? formatDateTime(item.jdCreatedAt) : '-' }}</dd></div>
<div class="info-item"><dt>京东修改时间</dt><dd>{{ item?.jdUpdatedAt ? formatDateTime(item.jdUpdatedAt) : '-' }}</dd></div>
</dl>
</div>
<p v-else-if="loading" class="drawer-tip">加载中...</p>
</section>
<template v-else>
<!-- 顶部「左图右信息」(2026-11-16 客户口径「详情页的样式要和京麦商品详情一样的布局样式」):
左侧主图大图+缩略图切换,右侧关键信息;属性/SKU/详情图等区块保持下方。 -->
<section class="detail-block">
<div class="detail-hero">
<div class="hero-gallery">
<img
v-if="activeImageUrl"
class="hero-main"
:src="activeImageUrl"
alt=""
title="点击放大预览"
@click="openPreview(activeImageUrl)"
/>
<div v-else class="hero-empty">无图</div>
<div v-if="galleryImages.length > 1" class="hero-thumbs">
<img
v-for="image in galleryImages"
:key="image.id"
:src="image.url"
alt=""
loading="lazy"
:class="{ active: image.url === activeImageUrl }"
title="切换主图"
@click="switchGallery(image)"
/>
</div>
</div>
<dl class="hero-info">
<div class="info-item info-item-wide hero-title">
<dt>标题</dt>
<dd :title="item?.title || ''">{{ dash(item?.title) }}</dd>
</div>
<div class="info-item"><dt>价格区间</dt><dd>{{ dash(jdPriceRange(item ?? { priceMin: '', priceMax: '' })) }}</dd></div>
<div class="info-item"><dt>总库存</dt><dd>{{ dash(item?.stockTotal) }}</dd></div>
<div class="info-item"><dt>状态</dt><dd>{{ dash(item?.saleStatus) }}</dd></div>
<div class="info-item"><dt>信息分</dt><dd>{{ dash(item?.healthScore) }}</dd></div>
<div class="info-item"><dt>SKU 数</dt><dd>{{ dash(item?.skuCount) }}</dd></div>
<div class="info-item"><dt>商品编码</dt><dd>{{ dash(item?.productCode) }}</dd></div>
<div class="info-item"><dt>货号</dt><dd>{{ dash(item?.itemNum) }}</dd></div>
<div class="info-item"><dt>SKU</dt><dd>{{ dash(item?.skuId) }}</dd></div>
<div class="info-item"><dt>品牌</dt><dd>{{ dash(item?.brand) }}</dd></div>
<div class="info-item"><dt>店铺</dt><dd :title="item?.shopName || ''">{{ dash(item?.shopName) }}</dd></div>
<div class="info-item"><dt>分类</dt><dd>{{ dash(item?.groupName || '未分类') }}</dd></div>
<div class="info-item info-item-wide"><dt>类目</dt><dd :title="item?.categoryPath || ''">{{ dash(item?.categoryPath) }}</dd></div>
<div class="info-item"><dt>上架时间</dt><dd>{{ item?.jdOnlineAt ? formatDateTime(item.jdOnlineAt) : '-' }}</dd></div>
<div class="info-item"><dt>同步时间</dt><dd>{{ formatDateTime(item?.syncedAt || '') }}</dd></div>
<div class="info-item"><dt>京东创建时间</dt><dd>{{ item?.jdCreatedAt ? formatDateTime(item.jdCreatedAt) : '-' }}</dd></div>
<div class="info-item"><dt>京东修改时间</dt><dd>{{ item?.jdUpdatedAt ? formatDateTime(item.jdUpdatedAt) : '-' }}</dd></div>
</dl>
</div>
</section>
<section v-if="attrGroups.length" class="detail-block">
<h4>属性与设置(按京麦 Tab 分组)</h4>
<div v-for="group in attrGroups" :key="group.groupName" class="attr-group">
<h5>{{ group.groupName }}</h5>
<table>
<tbody>
<tr v-for="(attr, index) in group.attrs" :key="`${attr.key}-${index}`">
<th>{{ attr.label || attr.key || '-' }}</th>
<td>{{ attr.value || '-' }}</td>
</tr>
</tbody>
</table>
</div>
</section>
<section v-else-if="attrJsonRaw" class="detail-block">
<h4>属性(原始 JSON)</h4>
<pre class="attr-raw">{{ attrJsonRaw }}</pre>
</section>
<section v-if="attrGroups.length" class="detail-block">
<h4>属性与设置(按京麦 Tab 分组)</h4>
<div v-for="group in attrGroups" :key="group.groupName" class="attr-group">
<h5>{{ group.groupName }}</h5>
<table>
<tbody>
<tr v-for="(attr, index) in group.attrs" :key="`${attr.key}-${index}`">
<th>{{ attr.label || attr.key || '-' }}</th>
<td>{{ attr.value || '-' }}</td>
</tr>
</tbody>
</table>
</div>
</section>
<section v-else-if="attrJsonRaw" class="detail-block">
<h4>属性(原始 JSON)</h4>
<pre class="attr-raw">{{ attrJsonRaw }}</pre>
</section>
<section class="detail-block">
<h4>销售属性 / SKU 矩阵</h4>
<template v-if="skus.length">
<p class="sku-summary">{{ skuSummary }}</p>
<div class="sku-table-wrap">
<table class="sku-table">
<thead>
<tr>
<th>序号</th>
<th v-for="dimension in skuDimensions" :key="dimension">{{ dimension }}</th>
<th>京东价</th>
<th>库存</th>
<th>SKU ID</th>
<th>SKU 名称</th>
</tr>
</thead>
<tbody>
<tr v-for="(sku, index) in skus" :key="sku.skuId">
<td>{{ sku.skuSeq || index + 1 }}</td>
<td v-for="dimension in skuDimensions" :key="dimension">{{ skuAttrValue(sku, dimension) }}</td>
<td>{{ sku.price ? `¥${sku.price}` : '-' }}</td>
<td>{{ dash(sku.stock) }}</td>
<td class="sku-id">{{ sku.skuId }}</td>
<td :title="sku.skuName">{{ dash(sku.skuName) }}</td>
</tr>
</tbody>
</table>
</div>
</template>
<p v-else class="drawer-tip">暂无 SKU 矩阵(V198 之前采集的旧行需重新采集)</p>
</section>
<section class="detail-block">
<h4>主图</h4>
<div v-if="mainImages.length" class="image-grid">
<img
v-for="image in mainImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
<p v-else class="drawer-tip">暂无主图</p>
</section>
<section v-for="bucket in attrImageGroups" :key="bucket.attrName" class="detail-block">
<h4>属性图 · {{ bucket.attrName }}</h4>
<div class="image-grid">
<img
v-for="image in bucket.list"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
</section>
<section class="detail-block">
<h4>详情图</h4>
<div v-if="detailImages.length" class="image-grid">
<img
v-for="image in detailImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
<p v-else class="drawer-tip">暂无详情图</p>
</section>
<section v-if="otherImages.length" class="detail-block">
<h4>其他图</h4>
<div class="image-grid">
<img
v-for="image in otherImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
</section>
<section class="detail-block">
<h4>销售属性 / SKU 矩阵</h4>
<template v-if="skus.length">
<p class="sku-summary">{{ skuSummary }}</p>
<div class="sku-table-wrap">
<table class="sku-table">
<thead>
<tr>
<th>序号</th>
<th v-for="dimension in skuDimensions" :key="dimension">{{ dimension }}</th>
<th>京东价</th>
<th>库存</th>
<th>SKU ID</th>
<th>SKU 名称</th>
</tr>
</thead>
<tbody>
<tr v-for="(sku, index) in skus" :key="sku.skuId">
<td>{{ sku.skuSeq || index + 1 }}</td>
<td v-for="dimension in skuDimensions" :key="dimension">{{ skuAttrValue(sku, dimension) }}</td>
<td>{{ sku.price ? `¥${sku.price}` : '-' }}</td>
<td>{{ dash(sku.stock) }}</td>
<td class="sku-id">{{ sku.skuId }}</td>
<td :title="sku.skuName">{{ dash(sku.skuName) }}</td>
</tr>
</tbody>
</table>
</div>
</template>
</div>
</aside>
<p v-else class="drawer-tip">暂无 SKU 矩阵(V198 之前采集的旧行需重新采集)</p>
</section>
<section class="detail-block">
<h4>主图</h4>
<div v-if="mainImages.length" class="image-grid">
<img
v-for="image in mainImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
<p v-else class="drawer-tip">暂无主图</p>
</section>
<section v-for="bucket in attrImageGroups" :key="bucket.attrName" class="detail-block">
<h4>属性图 · {{ bucket.attrName }}</h4>
<div class="image-grid">
<img
v-for="image in bucket.list"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
</section>
<section class="detail-block">
<h4>详情图</h4>
<div v-if="detailImages.length" class="image-grid">
<img
v-for="image in detailImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
<p v-else class="drawer-tip">暂无详情图</p>
</section>
<section v-if="otherImages.length" class="detail-block">
<h4>其他图</h4>
<div class="image-grid">
<img
v-for="image in otherImages"
:key="image.url"
:src="image.url"
alt=""
title="点击放大预览"
@click="openPreview(image.url)"
/>
</div>
</section>
</template>
<div v-if="previewVisible" class="modal-mask" @click.self="previewVisible = false">
<div class="preview-modal">
@@ -320,57 +311,7 @@ function dash(value: string | number | null | undefined): string {
</template>
<style scoped>
.drawer-mask {
position: fixed;
inset: 0;
z-index: 2600;
display: flex;
justify-content: flex-end;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(4px);
}
.drawer {
display: flex;
flex-direction: column;
width: min(920px, 100%);
height: 100%;
background: #ffffff;
box-shadow: -18px 0 40px rgba(39, 67, 94, 0.18);
}
.drawer-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 20px;
border-bottom: 1px solid #dbe5ee;
}
.drawer-head h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
}
.drawer-close {
width: 30px;
height: 30px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: #5b6f83;
font-size: 20px;
line-height: 1;
cursor: pointer;
}
.drawer-close:hover {
border-color: #cbd9e6;
background: #eef4fa;
color: #24384d;
}
.drawer-body {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 16px 20px 28px;
.detail-content {
display: flex;
flex-direction: column;
gap: 18px;
@@ -489,12 +430,6 @@ function dash(value: string | number | null | undefined): string {
width: 100%;
}
}
.info-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px 16px;
margin: 0;
}
.info-item {
min-width: 0;
}
@@ -662,6 +597,22 @@ function dash(value: string | number | null | undefined): string {
color: #2f5d8b;
font-size: 13px;
}
.drawer-close {
width: 30px;
height: 30px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: #5b6f83;
font-size: 20px;
line-height: 1;
cursor: pointer;
}
.drawer-close:hover {
border-color: #cbd9e6;
background: #eef4fa;
color: #24384d;
}
.btn {
display: inline-flex;
align-items: center;
@@ -0,0 +1,150 @@
<script setup lang="ts">
/** 京东商品详情居中弹窗(v1.6 蓝图 Phase 4,additive——页面接线随 Phase 5):
* 居中大弹窗壳(设计稿款式):顶部标题+「编辑/删除」动作(按写权限档渲染)+关闭,
* 内容区=JdProductDetailContent 共享块(hero 左图右信息/属性分组/SKU 矩阵/图片三区/
* 放大预览,数据自取)。壳不发请求、不碰业务链——编辑/删除 emit 给页面接既有链
* (EditDrawer 与 removeOne),与现表格行操作同源。 */
import JdProductDetailContent from './JdProductDetailContent.vue'
import type { JdProductItem } from './jd-product-model.ts'
const props = defineProps<{
/** 详情行(来自列表行集;内容块按 item.id 自取详情)。 */
item: JdProductItem | null
visible: boolean
/** 写权限档(isAdminRole 投影):可写档顶部渲染「编辑/删除」,普通账号只读无动作。 */
canWrite?: boolean
}>()
const emit = defineEmits<{
/** 关闭弹窗(mask 自身点击/右上 ×)。 */
(event: 'close'): void
/** 编辑(页面开 JdProductEditDrawer 既有链)。 */
(event: 'edit'): void
/** 删除(页面走 removeOne 既有链:确认弹窗→先桶后库)。 */
(event: 'remove'): void
}>()
const title = (): string =>
`商品详情${props.item?.productCode ? ` · ${props.item.productCode}` : ''}`
</script>
<template>
<div v-if="props.visible" class="jd-modal-mask" @click.self="emit('close')">
<div class="jd-modal" role="dialog" aria-label="商品详情">
<header class="jd-modal-head">
<h3>{{ title() }}</h3>
<div v-if="props.canWrite" class="jd-modal-actions">
<button class="jd-modal-btn" type="button" @click="emit('edit')">编辑</button>
<button class="jd-modal-btn jd-modal-btn-danger" type="button" @click="emit('remove')">删除</button>
</div>
<button class="jd-modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
</header>
<div class="jd-modal-body">
<JdProductDetailContent :item="props.item" :visible="props.visible" />
</div>
</div>
</div>
</template>
<style scoped>
.jd-modal-mask {
position: fixed;
inset: 0;
z-index: 2600;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(4px);
}
.jd-modal {
display: flex;
flex-direction: column;
width: min(1080px, 100%);
max-height: 90vh;
background: #ffffff;
border-radius: 14px;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
overflow: hidden;
}
.jd-modal-head {
display: flex;
align-items: center;
gap: 12px;
padding: 14px 20px;
border-bottom: 1px solid #dbe5ee;
}
.jd-modal-head h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.jd-modal-actions {
display: flex;
gap: 8px;
flex-shrink: 0;
}
.jd-modal-btn {
min-height: 32px;
padding: 4px 14px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #2f5d8b;
font-size: 13px;
cursor: pointer;
}
.jd-modal-btn:hover {
border-color: #95b1cb;
background: #edf5fb;
}
.jd-modal-btn-danger {
color: #a04432;
border-color: #f0c9c2;
}
.jd-modal-btn-danger:hover {
background: #fdf1ef;
border-color: #e0a79c;
}
.jd-modal-close {
flex-shrink: 0;
width: 30px;
height: 30px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: #5b6f83;
font-size: 20px;
line-height: 1;
cursor: pointer;
}
.jd-modal-close:hover {
border-color: #cbd9e6;
background: #eef4fa;
color: #24384d;
}
.jd-modal-body {
flex: 1;
min-height: 0;
overflow-y: auto;
padding: 16px 20px 28px;
}
</style>
@@ -0,0 +1,439 @@
<script setup lang="ts">
/** 添加店铺弹窗(v1.7 F6 对齐原型《商品数据商城》的「店铺名单维度」):
* 侧栏店铺分类 Tab 展开某分类后的「+ 添加店铺」行打开。候选=服务端
* fetchJdAvailableShops(biz_jd_product.shop_name DISTINCT,关键词包含匹配+排除本分类
* 已有名单,limit ≤ 200——商品行 shop_name 是京麦店铺全名,与名单来源同源);
* 勾选候选+手输自定义项(不在候选里的新店名)合并成一个待添加清单,一次批量提交
* (服务侧 trim/去重/上限 100,INSERT IGNORE 幂等跳过已存在行,回执=实际新增行数)。
* 结构复制 JdBatchAssignDialog(modal-mask+modal-head/tip/foot 同款皮肤)。 */
import { computed, ref, watch } from 'vue'
import { addJdGroupShops, fetchJdAvailableShops } from './jd-product-api.ts'
import { requestErrorMessage } from '../../api/envelope.ts'
const props = defineProps<{
visible: boolean
/** 目标分类(名单挂在分类下)。 */
categoryId: number
categoryName: string
}>()
const emit = defineEmits<{ (event: 'close'): void; (event: 'done', added: number, categoryName: string): void }>()
/** 候选搜索(关键词输入后手动点「搜索」或 Enter 触发——不随输入逐键打后端)。 */
const keyword = ref('')
const candidates = ref<string[]>([])
const searching = ref(false)
const searched = ref(false)
/** 待添加清单(勾选的候选+手输自定义项,Set 保序去重)。 */
const pending = ref<string[]>([])
/** 手输自定义项输入框。 */
const customName = ref('')
const submitting = ref(false)
const errorText = ref('')
/** 批量上限与服务端 JdGroupShopService.MAX_ADD_SHOPS 同值(文案点名 100)。 */
const MAX_ADD_SHOPS = 100
const canSubmit = computed(() => pending.value.length > 0 && !submitting.value)
watch(
() => props.visible,
(visible) => {
if (visible) {
keyword.value = ''
candidates.value = []
searched.value = false
pending.value = []
customName.value = ''
errorText.value = ''
// 打开即拉一次空关键词候选(让用户不输词也有东西可勾)。
void search()
}
},
)
async function search(): Promise<void> {
searching.value = true
errorText.value = ''
try {
candidates.value = await fetchJdAvailableShops(keyword.value, props.categoryId)
searched.value = true
} catch (error) {
errorText.value = requestErrorMessage(error) || '候选店铺加载失败'
} finally {
searching.value = false
}
}
function toggleCandidate(name: string): void {
const index = pending.value.indexOf(name)
if (index >= 0) pending.value = pending.value.filter((item) => item !== name)
else pending.value = [...pending.value, name]
}
/** 手输自定义项:空白不收;与待添加清单重复不收(静默忽略——清单里已有就是同一个)。 */
function addCustom(): void {
const name = customName.value.trim()
if (!name) return
if (!pending.value.includes(name)) pending.value = [...pending.value, name]
customName.value = ''
}
function removePending(name: string): void {
pending.value = pending.value.filter((item) => item !== name)
}
async function submit(): Promise<void> {
if (!canSubmit.value) return
submitting.value = true
errorText.value = ''
try {
const added = await addJdGroupShops(props.categoryId, pending.value)
emit('done', added, props.categoryName)
emit('close')
} catch (error) {
errorText.value = requestErrorMessage(error) || '添加店铺失败'
} finally {
submitting.value = false
}
}
</script>
<template>
<div v-if="visible" class="modal-mask" @click.self="emit('close')">
<div class="shop-picker-modal">
<div class="modal-head">
<h3>添加店铺<span v-if="categoryName" class="modal-sub">· {{ categoryName }}</span></h3>
<button class="modal-close" type="button" aria-label="关闭" @click="emit('close')">×</button>
</div>
<p class="modal-tip">
从已采集商品的店铺里勾选,或手动输入名单里还没有的店铺名;
一次最多添加 {{ MAX_ADD_SHOPS }} 个,已有的会自动跳过。
</p>
<p v-if="errorText" class="group-error">{{ errorText }}</p>
<!-- 候选搜索:关键词包含匹配(服务端 DISTINCT+like),Enter 或按钮触发。 -->
<div class="shop-search">
<input
v-model="keyword"
type="text"
placeholder="搜索店铺名"
aria-label="候选店铺关键词"
@keyup.enter="search"
/>
<button type="button" :disabled="searching" @click="search">{{ searching ? '搜索中...' : '搜索' }}</button>
</div>
<ul class="shop-candidate-list">
<li v-if="searching" class="shop-list-tip">搜索中...</li>
<li v-else-if="!candidates.length && searched" class="shop-list-tip">没有可添加的候选店铺(已采商品的店铺都在名单里了,试试手动输入)</li>
<li
v-for="name in candidates"
:key="name"
class="shop-candidate-row"
:class="{ active: pending.includes(name) }"
:title="name"
@click="toggleCandidate(name)"
>
<span class="shop-check" aria-hidden="true"></span>
<span class="shop-name">{{ name }}</span>
<span v-if="pending.includes(name)" class="shop-picked-tag">已选</span>
</li>
</ul>
<!-- 手输自定义项+待添加清单(chips 可移除)。 -->
<div class="shop-custom">
<input
v-model="customName"
type="text"
placeholder="手动输入店铺名(自定义)"
aria-label="自定义店铺名"
@keyup.enter="addCustom"
/>
<button type="button" :disabled="!customName.trim() || pending.length >= MAX_ADD_SHOPS" @click="addCustom">加入</button>
</div>
<div v-if="pending.length" class="shop-pending">
<span v-for="name in pending" :key="name" class="shop-chip">
{{ name }}
<button type="button" :aria-label="`移除待添加 ${name}`" @click="removePending(name)">×</button>
</span>
</div>
<div class="modal-foot">
<button class="btn btn-secondary" type="button" @click="emit('close')">取消</button>
<button class="btn" type="button" :disabled="!canSubmit" @click="submit">
{{ submitting ? '提交中...' : `添加(${pending.length})` }}
</button>
</div>
</div>
</div>
</template>
<style scoped>
.modal-mask {
position: fixed;
inset: 0;
z-index: 2800;
display: flex;
align-items: center;
justify-content: center;
padding: 40px 20px;
background: rgba(45, 66, 86, 0.36);
backdrop-filter: blur(6px);
}
.shop-picker-modal {
display: flex;
flex-direction: column;
width: min(460px, 100%);
max-height: 80vh;
padding: 18px 20px 20px;
border: 1px solid #c7d7e5;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 22px 60px rgba(39, 67, 94, 0.2);
}
.modal-head {
display: flex;
align-items: center;
justify-content: space-between;
}
.modal-head h3 {
margin: 0;
font-size: 15px;
font-weight: 650;
color: #24384d;
}
.modal-sub {
margin-left: 6px;
color: #5b6f83;
font-size: 13px;
font-weight: 500;
}
.modal-close {
width: 30px;
height: 30px;
border: 1px solid transparent;
border-radius: 9px;
background: none;
color: #5b6f83;
font-size: 20px;
line-height: 1;
cursor: pointer;
}
.modal-close:hover {
border-color: #cbd9e6;
background: #eef4fa;
color: #24384d;
}
.modal-tip {
margin: 8px 0 10px;
color: #8293a5;
font-size: 12.5px;
line-height: 1.5;
}
.group-error {
margin: 0 0 8px;
padding: 10px 12px;
border: 1px solid #f0c9c2;
border-radius: 10px;
background: #fdf1ef;
color: #a04432;
font-size: 13px;
}
.shop-search {
display: flex;
gap: 8px;
margin-bottom: 10px;
}
.shop-search input {
flex: 1;
min-width: 0;
min-height: 36px;
padding: 6px 10px;
border: 1px solid #cbd9e6;
border-radius: 8px;
font-size: 13px;
font-family: inherit;
outline: none;
}
.shop-search input:focus {
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.shop-search button {
padding: 6px 14px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-size: 13px;
font-family: inherit;
cursor: pointer;
}
.shop-search button:disabled {
cursor: not-allowed;
opacity: 0.6;
}
.shop-candidate-list {
flex: 1;
min-height: 0;
overflow-y: auto;
margin: 0 0 10px;
padding: 0;
list-style: none;
border: 1px solid #e7eef5;
border-radius: 10px;
}
.shop-candidate-row {
display: flex;
align-items: center;
gap: 10px;
padding: 9px 10px;
border-bottom: 1px solid #eef3f8;
font-size: 13px;
cursor: pointer;
}
.shop-candidate-row:last-child {
border-bottom: none;
}
.shop-candidate-row:hover {
background: #f1f7fb;
}
.shop-candidate-row.active {
background: #e8f1fa;
box-shadow: inset 3px 0 0 #4f78a5;
}
.shop-check {
flex: none;
width: 14px;
height: 14px;
border: 1.6px solid #9fb7cd;
border-radius: 4px;
background: #ffffff;
}
.shop-candidate-row.active .shop-check {
border-color: #4f78a5;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
box-shadow: inset 0 0 0 2.4px #ffffff;
}
.shop-name {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: #24384d;
}
.shop-picked-tag {
flex: none;
padding: 1px 7px;
border-radius: 9px;
background: #d9ecff;
color: #2f5d8b;
font-size: 12px;
}
.shop-list-tip {
padding: 22px 12px;
color: #8293a5;
font-size: 12.5px;
text-align: center;
}
.shop-custom {
display: flex;
gap: 8px;
}
.shop-custom input {
flex: 1;
min-width: 0;
min-height: 36px;
padding: 6px 10px;
border: 1px solid #cbd9e6;
border-radius: 8px;
font-size: 13px;
font-family: inherit;
outline: none;
}
.shop-custom input:focus {
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.shop-custom button {
padding: 6px 14px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-size: 13px;
font-family: inherit;
cursor: pointer;
}
.shop-custom button:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.shop-pending {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 10px;
}
.shop-chip {
display: inline-flex;
align-items: center;
gap: 4px;
padding: 3px 6px 3px 10px;
border-radius: 999px;
background: #e8f1f9;
color: #3d5a77;
font-size: 12.5px;
}
.shop-chip button {
width: 18px;
height: 18px;
padding: 0;
border: none;
border-radius: 50%;
background: #c9dcea;
color: #3d5a77;
font-size: 12px;
line-height: 1;
cursor: pointer;
}
.shop-chip button:hover {
background: #b3cde4;
}
.modal-foot {
display: flex;
justify-content: flex-end;
gap: 10px;
margin-top: 14px;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
min-height: 38px;
padding: 7px 16px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.6;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
</style>
@@ -1,29 +0,0 @@
/** 类目级联面板的水平定位钳制(2026-11-16 客户截图「超出视窗了」:面板锚在触发框
* left:0,下钻到 3~4 栏时宽 600~800px,而「类目」筛选框在 jd-filter-row 流式布局里
* 常落在页面中部偏右 ⇒ 面板右半截伸出视窗,末栏被窗缘裁到只剩一列 radio 圆点)。
*
* 本文件是**纯钳制数学**(零依赖,node --test 可直测):默认锚左(偏移 0);视口右缘
* 装不下时整体左移到右缘贴齐(留 margin),左移后越出左缘则贴左缘为止。组件侧在面板
* 打开与栏数/搜索态变化后用真实 rect 调它(JdCategoryCascader.vue),栏数随下钻动态
* 1~4,宽度变了要重算——右贴齐后继续下钻即向左生长,不会再伸出右缘。 */
export interface PanelClampInput {
/** 触发框(.cat-cascader)的视口左缘 x。 */
hostLeft: number
/** 面板当前实际渲染宽(含边框;栏数不同宽度不同)。 */
panelWidth: number
/** 视口宽(window.innerWidth)。 */
viewportWidth: number
/** 视口两侧最小留白,默认 8px。 */
margin?: number
}
/** 返回面板相对触发框左缘应加的 left 偏移(px;负=左移、0=默认锚左即可、正=触发框
* 本身已贴近视口左缘时把面板推回 margin 内,物理上只在窄窗极端值出现)。 */
export function clampPanelLeftX(input: PanelClampInput): number {
const margin = input.margin ?? 8
const overflowRight = input.hostLeft + input.panelWidth - (input.viewportWidth - margin)
if (overflowRight <= 0) return 0
const desiredLeft = Math.max(margin, input.hostLeft - overflowRight)
return desiredLeft - input.hostLeft
}
@@ -85,3 +85,146 @@ export function jdCategorySearchLeaves(keyword: string): JdCategoryLeafRef[] {
leaf.path.some((segment) => segment.toLowerCase().includes(needle)),
)
}
/** 全树节点引用(含非末级)——2026-11-18 客户口径「一级/二级类目也要能选来搜索」:
* 搜索面板从"只铺末级"扩成"铺全部层级",非末级行可选中=按子树展开集合过滤。 */
export interface JdCategoryNodeRef {
name: string
value: string
/** 从一级到本节点的名称路径(选中态回显与子树展开都按它定位)。 */
path: string[]
/** children 缺省/空=末级(落库 category_path 直接等值命中)。 */
leaf: boolean
}
export function jdCategoryAllNodes(): JdCategoryNodeRef[] {
const out: JdCategoryNodeRef[] = []
const walk = (nodes: JdCategoryNode[], prefix: string[]): void => {
for (const node of nodes) {
const path = [...prefix, node.name]
const hasChildren = !!node.children && node.children.length > 0
out.push({ name: node.name, value: node.value, path, leaf: !hasChildren })
if (hasChildren) walk(node.children as JdCategoryNode[], path)
}
}
walk(JD_CATEGORY_TREE, [])
return out
}
/** 全树节点按关键词过滤:名称或路径任一段命中(大小写不敏感 includes)。 */
export function jdCategorySearchNodes(keyword: string): JdCategoryNodeRef[] {
const needle = keyword.trim().toLowerCase()
if (!needle) return jdCategoryAllNodes()
return jdCategoryAllNodes().filter(
(node) =>
node.name.toLowerCase().includes(needle) ||
node.path.some((segment) => segment.toLowerCase().includes(needle)),
)
}
/**
* 选中节点 → 下发后端的类目名集合(2026-11-18 前端展开+后端 IN 路线):
* 返回该节点**自身+全部后代**的类目名(去重、层级序)。含自身是因为落库
* `category_path` =京麦实际末级名,快照层级可能比实际深/浅——父级名本身也可能就是
* 某批行的末级名(真机样本「艺考形体服」即三级节点名)。路径无效返回 null(调用方
* 按单名等值兜底,语义同树外历史行)。
*/
export function jdCategoryNamesUnder(path: string[]): string[] | null {
let level = JD_CATEGORY_TREE
let target: JdCategoryNode | null = null
for (const name of path) {
const hit = level.find((node) => node.name === name)
if (!hit) return null
target = hit
level = hit.children ?? []
}
if (!target) return null
const out: string[] = []
const seen = new Set<string>()
const walk = (nodes: JdCategoryNode[]): void => {
for (const node of nodes) {
if (!seen.has(node.name)) {
seen.add(node.name)
out.push(node.name)
}
if (node.children && node.children.length) walk(node.children)
}
}
walk([target])
return out
}
/** GET /categories 的计数行({name, productCount},name=京麦末级类目即落库
* category_path;同名末级在后端是同一等值桶,此处一行一名)。 */
export interface JdCategoryCountEntry {
name: string
productCount: number
}
/** 带计数的树节点:count=自身名+全部后代名(子树内去重)的 productCount 之和——
* 与「点节点 → jdCategoryNamesUnder 展开集合 IN 过滤」的命中集合同源(v1.6 蓝图
* Phase 1 备料):徽标数必须就是点它之后列表会命中的行数,两边各算各的就会出现
* 「徽标 5、点进去 8 行」。leaf/children 与 JdCategoryNode 同义(leaf=children 空)。 */
export interface JdCategoryCountedNode {
name: string
value: string
count: number
leaf: boolean
children: JdCategoryCountedNode[]
}
/** 计数聚合回执:roots=树形计数树(全部授权类目都在,无词条的节点 count=0);
* extra=树上任何节点名(含非叶)都对不上的历史行(树外兜底组——京麦改树后的
* 存量 category_path 从这里选,语义同旧版级联第三栏兜底)。 */
export interface JdCategoryCountTree {
roots: JdCategoryCountedNode[]
extra: JdCategoryCountEntry[]
/** 兜底组计数和(徽标直接用)。 */
extraTotal: number
}
/** /categories 计数行 → 树形计数聚合(v1.6 蓝图 Phase 1)。同名跨支叶(短裤/唐装/
* 吊带/背心/赠品)按过滤语义如实计入两个分支——点哪个分支都按同一名字等值命中
* 同一批行,不是双计;父层子树内按名字去重求和(与展开集合口径一致,父层徽标
* 不因同名跨支翻倍)。名字对不上树上任何节点的行归树外兜底组。脏值归一:空名
* 跳过、计数非有限数归 0、负数钳 0、同名多行求和。 */
export function jdCategoryCountTree(entries: JdCategoryCountEntry[]): JdCategoryCountTree {
const counts = new Map<string, number>()
for (const entry of Array.isArray(entries) ? entries : []) {
const name = entry && typeof entry.name === 'string' ? entry.name.trim() : ''
if (!name) continue
const raw = entry.productCount
const value = typeof raw === 'number' && Number.isFinite(raw) ? Math.max(0, Math.floor(raw)) : 0
counts.set(name, (counts.get(name) ?? 0) + value)
}
const treeNames = new Set<string>()
const build = (
nodes: JdCategoryNode[],
): { out: JdCategoryCountedNode[]; names: Set<string> } => {
const out: JdCategoryCountedNode[] = []
const names = new Set<string>()
for (const node of nodes) {
treeNames.add(node.name)
const child =
node.children && node.children.length
? build(node.children)
: { out: [] as JdCategoryCountedNode[], names: new Set<string>() }
const set = new Set(child.names)
set.add(node.name)
let count = 0
for (const name of set) count += counts.get(name) ?? 0
out.push({ name: node.name, value: node.value, count, leaf: child.out.length === 0, children: child.out })
for (const name of set) names.add(name)
}
return { out, names }
}
const roots = build(JD_CATEGORY_TREE).out
const extra: JdCategoryCountEntry[] = []
let extraTotal = 0
for (const [name, count] of counts) {
if (treeNames.has(name)) continue
extra.push({ name, productCount: count })
extraTotal += count
}
return { roots, extra, extraTotal }
}
@@ -1,10 +1,49 @@
/* 像素复刻「外观专利数据库」页样式(panel-box + 自绘表格 + 旧式分页);列表只摆部分字段,全量属性在详情抽屉。 */
/* 京东数据库页样式(v1.6 蓝图 Phase 5 重写装配 → v1.7 对齐原型):顶部通栏(搜索行+
工具栏)+横排体(左侧栏类目树/分类平铺+主面板:回显条+卡片网格+分页条+已选条)。
旧自绘表格样式随操作列/表格退役整体摘除;列表字段映射收进 JdProductCard scoped 样式,
本文件只管页面装配层。
2026-11-21 用户口径四件:①面板删标题行(筛选往上摆,原型顶栏直接开始);
②筛选行收窄字段宽让归属三档并入一行;③左右高度对齐——stretch 让侧栏随主面板拉满;
④「放到上面筛选框」红框整体上移——筛选行+批量按钮条离开主面板、提到页面最顶
(提示条正下方、通栏整行),外层改纵向排:顶部通栏在上,侧栏+主面板横排在下。
v1.7(同日对齐原型《商品数据商城》)追加五件:合并搜索框(× 清除)、筛选按钮下方
absolute 浮层(价格区间+同步起止+重置/应用)、筛选回显条(条件芯片+共 N 条+
清除筛选)、自绘顶部分页条(OldPagination 从本页撤下)、底部已选条(sticky 悬浮)。
2026-11-22 用户口径「左侧菜单超出变滚动条、右侧一屏后也要滚动」:一屏装配——
admin-content 被本页 :has 规则转成纵向 flex(见 JdDatabasePage.vue 尾部非 scoped 块),
外层吃剩余可视高度、顶部通栏保持自然高,.jd-body 两栏同高一屏;侧栏树超出走既有
内部滚动带,主面板超出自己出滚动条(不再把整页拉高、整页一起滚)。窄屏(≤980px)
撤装配回自然流(见文件尾媒体查询)。 */
.jd-database-view {
font-family: inherit;
color: var(--c-text, #24384d);
/* ④红框整体上移:外层由「侧栏+主面板」横排改纵向——顶部通栏面板在上,
侧栏+主面板的横排体(.jd-body)在下。间距与全局密度规则对齐取 10px
(.admin-content > [class$="-view"] 本来就会压掉 16px,别靠覆盖链猜)。
一屏装配:admin-content 已转纵向 flex,这里吃它分给本页的剩余可视高度;
min-height: 0 允许本层被压回视口内,超出交给 .jd-body 两栏各自的内部滚动。 */
display: flex;
flex-direction: column;
gap: 18px;
gap: 10px;
flex: 1 1 auto;
min-height: 0;
}
/* 顶部通栏面板:筛选行+批量按钮条整行铺开(面板盒皮肤复用 .panel-box)。
flex-shrink: 0——极矮视口下收缩压力全由 .jd-body 吃,工具栏不被压扁。 */
.jd-top-panel {
min-width: 0;
flex-shrink: 0;
}
/* 侧栏+主面板横排体(原 .jd-database-view 的横排形状整体挪进来):
左右高度对齐——stretch 让侧栏与主面板同高(一屏装配后=通栏之下的剩余可视高度),
两侧内部滚动区各自吃剩余高度、各自出滚动条。 */
.jd-body {
display: flex;
align-items: stretch;
gap: 10px;
min-width: 0;
flex: 1 1 auto;
min-height: 0;
}
.panel-box {
width: 100%;
@@ -15,42 +54,276 @@
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0 0 16px;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
/* 主面板在「侧栏+主区」横排体(.jd-body)里吃掉剩余宽度;窄屏(侧栏 232px 起占位)
允许整行折行由 .jd-body 的 flex-wrap 兜住,面板自身保持弹性收缩。
一屏装配(2026-11-22 用户口径「右侧一屏后也要滚动」):面板高度被 .jd-body 钉在一屏,
卡片网格超出时面板自己出滚动条——滚动带样式与侧栏同款(细带常驻,Win fluent overlay
滚动条不悬停不显形的老问题在这里同样要兜)。 */
.jd-main-panel {
flex: 1 1 480px;
min-width: 0;
min-height: 0;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: #bccfe1 transparent;
}
.jd-panel-head {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
.jd-main-panel::-webkit-scrollbar {
width: 8px;
}
.jd-panel-head h3 {
margin: 0;
.jd-main-panel::-webkit-scrollbar-track {
background: transparent;
}
.jd-main-panel::-webkit-scrollbar-thumb {
background: #bccfe1;
border-radius: 4px;
}
.jd-main-panel::-webkit-scrollbar-thumb:hover {
background: #9fb7cd;
}
.jd-filter-row {
/* 可换行流式布局:固定 6 列 minmax(140px) 的网格在窄面板下最小宽超出容器,
把查询/重置挤出面板右缘(与「管理分组」重叠)。flex-wrap 让放不下的项自然折行。 */
/* 可换行流式布局:固定网格在窄面板下最小宽超出容器,把尾部的归属下拉挤出面板右缘。
flex-wrap 让放不下的项自然折行。v1.7 起内容=搜索框+筛选弹层锚点+分组+归属三档。 */
display: flex;
flex-wrap: wrap;
gap: 12px;
gap: 10px;
align-items: flex-end;
margin-bottom: 16px;
margin-bottom: 12px;
}
.jd-filter-row .form-group {
flex: 1 1 160px;
/* 「分组」表单组(label+下拉/锁定芯片):固定宽不再吃 flex(搜索框独占主弹性,
分组收窄到内容宽)。 */
flex: 0 1 auto;
min-width: 150px;
max-width: 260px;
max-width: 220px;
}
.jd-filter-actions {
/* 合并搜索框(v1.7 对齐原型):吃掉搜索行的主弹性;relative 壳给 × 清除按钮定位。 */
.jd-search-wrap {
position: relative;
flex: 1 1 260px;
min-width: 220px;
max-width: 420px;
}
.jd-search-input {
width: 100%;
box-sizing: border-box;
/* 34px 与筛选行两个 el-select.admin-filter(main.css 密度规则 250 行)同高——
2026-11-21 用户口径「高度不一样」:搜索框原来是 42px 旧档,行内三件参差。 */
min-height: 34px;
padding: 5px 34px 5px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.jd-search-input:hover {
border-color: #9fb7cd;
}
.jd-search-input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.jd-search-clear {
position: absolute;
right: 6px;
top: 50%;
transform: translateY(-50%);
width: 24px;
height: 24px;
padding: 0;
border: none;
border-radius: 50%;
background: #dbe7f1;
color: #5b6f83;
font-size: 15px;
line-height: 1;
cursor: pointer;
transition: background 120ms ease, color 120ms ease;
}
.jd-search-clear:hover {
background: #c7d9e8;
color: #2f5d8b;
}
/* 筛选弹层锚点:relative 给浮层「按钮下方 absolute」定位(v1.7 对齐原型)。 */
.jd-filter-anchor {
position: relative;
flex-shrink: 0;
}
/* 筛选按钮激活态(弹层开着时描一圈主色,提示当前条件挂在它下面)。 */
.jd-filter-anchor .jd-filter-open {
border-color: #5f85ad;
color: #2f5d8b;
background: #edf5fb;
}
.jd-filter-popover {
position: absolute;
top: calc(100% + 8px);
left: 0;
z-index: 30;
width: 300px;
padding: 14px;
border: 1px solid #d8e3ee;
border-radius: 12px;
background: #ffffff;
box-shadow: 0 18px 42px -22px rgba(39, 67, 94, 0.45);
display: flex;
flex-direction: column;
gap: 12px;
}
.jd-pop-row {
display: flex;
flex-direction: column;
gap: 6px;
}
.jd-pop-row > label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
.jd-pop-fields {
display: flex;
gap: 10px;
align-items: center;
gap: 8px;
}
.jd-pop-fields input {
flex: 1 1 0;
min-width: 0;
min-height: 36px;
padding: 6px 10px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.jd-pop-fields input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.jd-pop-sep {
color: #8293a5;
font-size: 12.5px;
}
.jd-pop-actions {
display: flex;
justify-content: flex-end;
gap: 10px;
}
.jd-pop-actions .btn {
min-height: 34px;
padding: 5px 14px;
}
/* 筛选回显条(v1.7 F5):条件芯片+共 N 条+清除筛选;无激活筛选不渲染(v-if 在模板)。 */
.jd-filter-chips {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
padding: 8px 10px;
margin-bottom: 12px;
border: 1px solid #e3ecf4;
border-radius: 9px;
background: #f6fafd;
}
.jd-chip {
padding: 3px 10px;
border-radius: 999px;
background: #e8f1f9;
color: #3d5a77;
font-size: 12.5px;
white-space: nowrap;
}
.jd-chip-total {
color: #5b6f83;
font-size: 12.5px;
white-space: nowrap;
}
.jd-chip-clear {
margin-left: auto;
padding: 2px 6px;
border: none;
border-radius: 6px;
background: transparent;
color: #4f78a5;
font-size: 12.5px;
font-family: inherit;
cursor: pointer;
text-decoration: underline;
white-space: nowrap;
}
.jd-chip-clear:hover {
color: #2f5d8b;
}
/* 顶部分页条(v1.7 F4):页码信息+五键+档位下拉;OldPagination 从本页撤下后的替身。 */
.jd-page-bar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
.jd-page-info {
color: #5b6f83;
font-size: 13px;
white-space: nowrap;
}
.jd-page-btns {
display: flex;
align-items: center;
gap: 6px;
}
.jd-page-btn {
min-height: 32px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-size: 12.5px;
font-family: inherit;
cursor: pointer;
white-space: nowrap;
transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.jd-page-btn:hover:not(:disabled) {
background: #edf5fb;
color: #2f5d8b;
border-color: #95b1cb;
}
.jd-page-btn:disabled {
cursor: not-allowed;
opacity: 0.5;
}
/* 档位下拉:42px 外壳由全局 .el-select.admin-filter 皮肤出——这里只补宽度与左侧外距。
.page-size-select 定位类保留(旧分页条的定位约定,测试与人工定位都认它)。 */
.jd-page-bar > .el-select.admin-filter,
.jd-page-bar > .page-size-select {
width: 120px;
margin-left: auto;
}
/* 底部已选条(v1.7 F7 骨架):主面板底部 sticky 悬浮,滚动到列表深处也看得见勾选规模。 */
.jd-select-bar {
position: sticky;
bottom: 8px;
z-index: 10;
margin-top: 12px;
padding: 9px 16px;
border: 1px solid #cfdff0;
border-radius: 10px;
background: #eef6fd;
color: #2f5d8b;
font-size: 13px;
font-weight: 600;
box-shadow: 0 -6px 18px -14px rgba(39, 67, 94, 0.5);
}
.form-group {
display: flex;
flex-direction: column;
@@ -84,8 +357,30 @@ h3 {
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.form-group input[type="date"] {
color-scheme: light;
/* 归属三档下拉(分类状态快筛):42px 外壳、9px 圆角、#cbd9e6 描边与 focus ring 都由
全局 .el-select.admin-filter 皮肤(main.css)出——与亚马逊面同一套。收窄到 150px
并进筛选行主体(2026-11-21「往上摆」:不再单独折一行);用直接子级选择器,
别误伤「分组」表单组里嵌的同款下拉(那个跟 form-group 走宽)。 */
.jd-filter-row > .el-select.admin-filter {
width: 150px;
flex-shrink: 0;
}
/* 工具栏(v1.6 重排,2026-11-21 按原型调序;同日红框整体上移随筛选行住顶部通栏面板):
全选本页/取消本页|删除商品|归入分类/取消归属。删除商品并入按钮组(原型里紧跟
「取消本页」),不再推到行尾;顶部面板里位于筛选行下、(主面板的)卡片网格上一行,
通栏整行放得下不再折行。它在顶部面板是最后一行,底边距归零不吃面板内边距。 */
.jd-toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
}
.jd-top-panel .jd-toolbar {
margin-bottom: 0;
}
.jd-toolbar .btn {
min-height: 34px;
padding: 5px 14px;
}
.btn {
display: inline-flex;
@@ -122,29 +417,7 @@ h3 {
border-color: #95b1cb;
background: #edf5fb;
}
.jd-toolbar {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
}
/* 工具栏分类筛选(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 {
margin-left: auto;
}
/* 分类管理(2026-11-17 独立分类管理页并入本页的对话框入口):贴着分类筛选下拉。 */
.jd-manage-btn {
margin-left: 6px;
}
/* 危险动作(删除勾选):与全站 .btn-danger 同形——实心红渐变+白字。
旧版是白底红字描边,落在工具栏里看着像「未激活的次要按钮」,与打卡/分组等页不统一。 */
/* 危险动作(删除商品):与全站 .btn-danger 同形——实心红渐变+白字。 */
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
@@ -153,20 +426,18 @@ h3 {
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.jd-summary {
color: #5b6f83;
font-size: 13px;
white-space: nowrap;
}
/* 非超管只读提示(2026-11-16 写权限收窄):紧跟汇总的一句话,不冒充可点按钮。 */
/* 非超管只读提示(2026-11-16 写权限收窄):工具栏下方的一句话说明,不冒充可点按钮。 */
.jd-readonly-tip {
display: block;
color: #8293a5;
font-size: 12.5px;
white-space: nowrap;
margin-bottom: 12px;
}
/* 只有一个可见分组时锁定的组名(不可切):筛选行「分组」标签下的静态芯片(2026-11-16 用户口径
「做成分组」把下拉从工具栏上移进筛选行后跟着搬),与同排 el-select 同高同壳(42px/9px 圆角),
"一组锁定"和"多组下拉"两种形态占位一致;组名超宽省略号收口,不把筛选行撑破。 */
.jd-top-panel .jd-readonly-tip {
margin-bottom: 0;
}
/* 只有一个可见分组时锁定的组名(不可切):筛选行「分组」标签下的静态芯片,
与同排 el-select 同高同壳(42px/9px 圆角),"一组锁定"和"多组下拉"两种形态占位一致。 */
.jd-group-locked {
display: flex;
align-items: center;
@@ -181,193 +452,39 @@ h3 {
overflow: hidden;
text-overflow: ellipsis;
}
.table-scroll {
width: 100%;
min-width: 0;
overflow-x: auto;
border: 1px solid #dbe5ee;
border-radius: 10px;
background: #ffffff;
/* 卡片网格(v1.6):自适应列数的商城款式;窄屏最小 170px 保住编码行不折断。 */
.jd-card-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
gap: 14px;
margin-bottom: 16px;
}
.table-scroll table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
/* 列宽收口(2026-11-16 用户口径「列表间距有点大」):1500px 的 min-width 让宽屏下
唯一的弹性列(商品信息)独吞剩余宽度,标题右侧留出近 800px 空白,价格/库存被推到最右。
商品信息改固定 520px 后各列按比例分摊余量,min-width 降到 1180px 即可无横向滚动。 */
.jd-table-scroll > table {
min-width: 1180px;
}
/* 操作列(编辑/删除):双小按钮需 138px(ops-cell-must-wrap 实测口径:两字按钮 53×2+24 padding)。
overflow 显式放开:td 全局是 overflow:hidden(611 行),压线时第二颗(删除)会被裁成
「编辑+…」的形状——2026-11-16 用户报「删除没了」的真因,列宽 120px < 实测 138px。 */
.jd-ops-cell {
white-space: nowrap;
text-overflow: clip;
overflow: visible;
}
.btn-sm {
min-height: 28px;
padding: 3px 10px;
font-size: 12.5px;
margin-right: 6px;
}
.btn-sm:last-child {
margin-right: 0;
}
.table-scroll th,
.table-scroll td {
/* 单元格左右内距 12→10px(同上「间距有点大」):列与列之间少 4px,行内更紧凑。 */
padding: 10px 10px;
text-align: left;
font-size: 13.5px;
line-height: 1.5;
border-bottom: 1px solid #e0e8ef;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* 首列勾选格:checkbox 的 UA 默认 margin(3px 3px 3px 4px)使其 margin-box 溢出
42px 格的内容盒(42−24 padding=18px),配合上面的 overflow:hidden,Chromium 在
首次渲染时会把被裁的 checkbox 碎片留在裁剪边缘,看起来像格子右边多出 ".."。
margin 归零后 margin-box 收进内容盒,首渲染即干净(playwright 三次冷加载已验)。 */
.table-scroll th:first-child input,
.table-scroll td:first-child input {
margin: 0;
}
.table-scroll th {
background: #edf4fa;
color: #4e6479;
border-bottom-color: #d5e1eb;
font-size: 12.5px;
font-weight: 600;
letter-spacing: 0.4px;
}
.table-scroll tbody tr:hover td {
background: #f1f7fb;
}
.table-scroll tbody tr:last-child td {
border-bottom: 0;
}
/* 点行开详情抽屉:行级 hover 已有底色反馈,光标再点一下提示可点。 */
.jd-row {
cursor: pointer;
}
.jd-thumb {
display: block;
width: 48px;
height: 48px;
object-fit: cover;
border: 1px solid #d8e3ee;
border-radius: 6px;
background: #f2f7fb;
}
/* 商品信息列=京麦同款合并布局:td 的全局 nowrap/ellipsis 与多行内容冲突,本列放开换行,
截断交给内部各行(标题两行 line-clamp、编码/货号单行 ellipsis)。 */
.jd-info-cell {
white-space: normal;
text-overflow: clip;
}
.jd-info-wrap {
display: flex;
align-items: flex-start;
gap: 10px;
min-width: 0;
}
.jd-info-figure {
display: flex;
flex-direction: column;
align-items: center;
gap: 3px;
flex-shrink: 0;
}
.jd-thumb-empty {
display: flex;
align-items: center;
justify-content: center;
color: #8293a5;
font-size: 12px;
}
.jd-health {
color: #2e9e6b;
font-size: 11px;
line-height: 1.2;
white-space: nowrap;
}
.jd-info-body {
min-width: 0;
display: flex;
flex-direction: column;
gap: 3px;
}
.jd-info-title {
color: #24384d;
font-size: 13.5px;
font-weight: 500;
line-height: 1.45;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-all;
}
.jd-info-meta {
display: flex;
align-items: center;
gap: 4px;
color: #7b8a99;
font-size: 12px;
line-height: 1.4;
white-space: nowrap;
overflow: hidden;
}
.jd-info-code {
font-family: "Cascadia Mono", "SF Mono", Consolas, "Courier New", monospace;
color: #4e6479;
overflow: hidden;
text-overflow: ellipsis;
}
.jd-copy-btn {
flex-shrink: 0;
border: 0;
background: transparent;
color: #8aa5bf;
font-size: 12px;
cursor: pointer;
padding: 0 2px;
line-height: 1;
}
.jd-copy-btn:hover {
color: #3b82c4;
}
.jd-info-tags {
display: flex;
gap: 6px;
margin-top: 2px;
}
/* 品牌·类目行(京麦列表同款深色文字):信息 meta 是灰色,这行按京麦用主文字色。 */
.jd-brand-cat {
color: #3d5368;
font-weight: 550;
}
.jd-tag {
display: inline-flex;
align-items: center;
height: 18px;
padding: 0 6px;
border: 1px solid #cfe3f5;
border-radius: 3px;
background: #eef5fc;
color: #3b82c4;
font-size: 11.5px;
white-space: nowrap;
}
.empty-tip {
.jd-empty-tip {
grid-column: 1 / -1;
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
border: 1px dashed #dbe5ee;
border-radius: 10px;
background: #ffffff;
}
/* 窄屏:侧栏收回横排体(.jd-body)顶部整行(树/分类平铺横向铺开高度可控),主面板
落在下面;顶部通栏面板本就是整行,不受影响。一屏装配一并撤(2026-11-22):横排体
恢复自然高度、主面板内部滚动关闭——两栏折行堆叠后没有「一屏」可言,整页交回
admin-content 滚动(其 overflow: auto 未被本页关掉,天然兜住)。 */
@media (max-width: 980px) {
.jd-database-view,
.jd-body {
flex: 0 0 auto;
}
.jd-body {
flex-wrap: wrap;
}
.jd-body > :first-child {
width: 100%;
}
.jd-main-panel {
overflow: visible;
}
}
@@ -1,10 +1,11 @@
/** 京东数据库查询适配(v1.4 Phase 5):GET /api/admin/jd-products + 删除(DELETE /{id} +
* POST /batch-delete)+ 分组端点 /api/admin/jd-product-groups。
/** 京东数据库查询适配(v1.4 Phase 5 → v1.7 对齐原型):GET /api/admin/jd-products +
* 删除(DELETE /{id} + POST /batch-delete)+ 分组端点 /api/admin/jd-product-groups。
* CSV 导出已下线(2026-11-21 用户拍板「删除掉」导出按钮,exportJdProductsCsv 同步摘除;
* 后端 POST /export 端点暂留,下一 jar 发版窗再收)。
* 公司口径(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」):全页零公司维度——
* 只读列表与类目下拉的 company_id 发送口已随公司 tab 摘除(后端读侧谓词同窗撤,重上时
* 从 git 历史找回),详情/编辑/删除/分组管理本就不带;行 company_id 列仍是同步来源标记、
* 随详情下发。反向钉在 company-tab-wiring「公司维度不得回流」清单。
* 导出发送口已随 2026-11-15 客户口径「导出也不用」从前端下线(后端 /export 端点保留)。 */
* 随详情下发。反向钉在 company-tab-wiring「公司维度不得回流」清单。 */
import { http } from '@/api/http'
import { errorTextOf, unwrap } from '../../api/envelope.ts'
import {
@@ -25,11 +26,14 @@ export async function fetchJdProductList(
): Promise<JdProductPageResult> {
const query = toJdProductListParams(
{
productCode: params.productCode ?? '',
titleKeyword: params.titleKeyword ?? '',
keyword: params.keyword ?? '',
category: params.category ?? '',
categoryPath: params.categoryPath ?? [],
shopName: params.shopName ?? '',
groupId: params.groupId ?? '',
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
minPrice: params.minPrice ?? '',
maxPrice: params.maxPrice ?? '',
syncedFrom: params.syncedFrom ?? '',
syncedTo: params.syncedTo ?? '',
},
@@ -37,7 +41,13 @@ export async function fetchJdProductList(
params.pageSize,
params.ownerGroupId ?? null,
)
const { data } = await http.get<unknown>(JD_PRODUCT_ENDPOINT, { params: query })
// category 多值(父级展开集合)必须序列化成重复 `category=a&category=b`:axios 默认
// 给数组加 `[]` 后缀,后端 @RequestParam("category") List<String> 认不到。
// indexes:false = 无括号无下标的重复键(axios 1.x 官方口径)。
const { data } = await http.get<unknown>(JD_PRODUCT_ENDPOINT, {
params: query,
paramsSerializer: { indexes: false },
})
return parseJdProductPage(data)
}
@@ -135,13 +145,16 @@ export async function uploadJdProductImage(
return parseJdProductDetail(data)
}
/** 分组行(GET 列表返回:[{id,name,ownerGroupId,sortOrder,productCount}])。 */
/** 分组行(GET 列表返回:[{id,name,ownerGroupId,sortOrder,productCount,shops}])。
* shops=该分类下的店铺名单(v1.7 V214 店铺名单维度,后端列表响应每行带;可选字段——
* 旧夹具/消费方不传按空名单处理,Phase 3 侧栏名单交互读它)。 */
export interface JdProductGroup {
id: number
name: string
ownerGroupId: number
sortOrder: number
productCount: number
shops?: string[]
}
/** 分组管理的写入负载(POST / PUT body:{name, sortOrder, ownerGroupId?})。 */
@@ -153,7 +166,8 @@ export interface JdProductGroupPayload {
}
/** 「当前分组」下拉的一项(GET /scope 的 groups[],V203):editable=本账号对该组分类可写
* (建/改名/删除/归类)。跨公司的组名由后端拼进 label,前端不解析公司字段。 */
* (建/改名/删除/归类)。跨组长的组名由后端拼进 label(2026-11-21 用户口径「不是选公司
* 是选超管/管理员」:前缀=组长账号名),前端不解析公司/组长字段。 */
export interface JdCategoryGroupOption {
id: number
name: string
@@ -197,12 +211,19 @@ export async function fetchJdProductGroups(ownerGroupId?: number | null): Promis
const record = raw as Record<string, unknown>
const id = numberOr(record.id, 0)
if (id <= 0) continue
// 店铺名单(v1.7 V214):后端按店名升序给数组;前端只滤空白不重排(排序语义在服务端)。
const shops = Array.isArray(record.shops)
? record.shops
.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
.map((shop) => shop.trim())
: []
out.push({
id,
name: typeof record.name === 'string' ? record.name.trim() : '',
ownerGroupId: numberOr(record.ownerGroupId ?? record.owner_group_id, 0),
sortOrder: numberOr(record.sortOrder ?? record.sort_order, 0),
productCount: numberOr(record.productCount ?? record.product_count, 0),
shops,
})
}
return out
@@ -304,3 +325,64 @@ export async function batchAssignJdProductGroup(
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/batch-assign-group`, body)
return groupDataOf<number>(data)
}
// ---------------------------------------------------------------- 店铺名单(v1.7 F6,V214)
/** 名单行形状=纯店名字符串(GET /{id}/shops 返回 shop_name 升序数组)。 */
/** 某分类的店铺名单(服务端已升序;前端只滤空白不重排)。失败文案原样抛给调用方。 */
export async function fetchJdGroupShops(categoryId: number): Promise<string[]> {
const { data } = await http.get<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`)
const core = groupDataOf<unknown>(data)
return Array.isArray(core)
? core
.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
.map((shop) => shop.trim())
: []
}
/** 批量添加店铺到分类名单(弹窗勾选候选+手输自定义项合并下发):服务侧 trim/去空/
* 去重/上限 100,INSERT IGNORE 幂等跳过已存在行;返回实际新增行数(全重复=0 不报错)。 */
export async function addJdGroupShops(categoryId: number, shopNames: string[]): Promise<number> {
const { data } = await http.post<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`, { shopNames })
return groupDataOf<number>(data)
}
/** 移除分类名单里的店铺(删 (分类, 店铺名) 那一行);该分类下不存在时后端按业务错误拒绝。 */
export async function removeJdGroupShop(categoryId: number, shopName: string): Promise<void> {
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops`, {
params: { shop_name: shopName },
})
groupDataOf<unknown>(data)
}
/** 改名分类名单里的店铺:老名必须在该名单里,新名同分类查重 409;
* 名单改名只更新名单表(商品归类不带店铺维,无原型 assignment 同步链)。 */
export async function renameJdGroupShop(categoryId: number, oldName: string, newName: string): Promise<void> {
const { data } = await http.patch<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${categoryId}/shops/rename`, {
oldName,
newName,
})
groupDataOf<unknown>(data)
}
/** 可添加的店铺候选(biz_jd_product.shop_name DISTINCT +关键词包含匹配+排除指定分类
* 已有名单;limit ≤ 200 服务侧钳制)。商品是全平台公共的,候选同样全平台去重。 */
export async function fetchJdAvailableShops(
keyword: string,
excludeCategoryId?: number | null,
limit?: number,
): Promise<string[]> {
const params: Record<string, unknown> = {}
const trimmed = (keyword || '').trim()
if (trimmed) params.keyword = trimmed
if (typeof excludeCategoryId === 'number' && excludeCategoryId > 0) {
params.exclude_category_id = excludeCategoryId
}
if (typeof limit === 'number' && limit > 0) params.limit = limit
const { data } = await http.get<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/shops/available`, { params })
const core = groupDataOf<unknown>(data)
return Array.isArray(core)
? core.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
: []
}
@@ -1,44 +1,74 @@
/** 京东数据库页筛选纯函数(v1.4 Phase 5):商品编码/标题关键字/类目/分组/同步起止 + snake 分页参数。
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 20、上限 100)、
* `product_code`、`title_keyword`、`category`(京麦末级类目等值过滤,2026-11-15 增)、
/** 京东数据库页筛选纯函数(v1.7 对齐原型《商品数据商城》):合并搜索/类目/店铺/分组/
* 归属筛选查询(状态三档+按分类查询,2026-11-22 用户口径「还要加个归属筛选查询」)/
* 价格区间/同步起止 + snake 分页参数。
* 产出与后端契约 §列表 query 逐字对撞:`page`/`page_size`(默认 50、上限 1000——v1.7
* 与后端 JdProductQueryService.MAX_PAGE_SIZE 逐字同步放宽,契约测试钉着这两个数)、
* `keyword`(v1.7 合并搜索:后端 `product_code LIKE OR title LIKE`,OR 语义在 SQL 段;
* 旧 `product_code`/`title_keyword` 两参数后端保留兼容但前端停发)、`shop_name`
* (v1.7 店铺名单点选,精确 eq)、`min_price`/`max_price`(v1.7 价格区间:商品区间完全
* 落在筛选区间内)、`category`(京麦末级类目等值过滤,2026-11-15 增)、
* `group_id`(当前分组下的分类 id)、`owner_group_id`(当前数据权限分组,V203)、
* `synced_from`/`synced_to`(ISO yyyy-MM-dd;空白不下发)。
* 商品状态筛选与导出(2026-11-15 客户口径「这两个不要/导出也不用」)已从前端下线;
* 店铺筛选同日客户口径「店铺不需要」从前端下线(后端 shop_name 参数同窗撤,DB 列与详情不动)。
* 后端 `sale_status` 参数与 `/export` 端点保留(无 UI 入口),重上时从 git 历史找回取值口。
* 商品状态筛选与 json/txt/CSV 导出均从前端下线(CSV v1.7 曾恢复,2026-11-21 用户拍板
* 「删除掉」导出按钮,exportJdProductsCsv 同步摘除)。
* 分页钳制(铁律 15):page < 1 归 1、上限 10_000(后端 CR-18 同值),(page-1)*page_size
* 最大 999_900,Number.MAX_SAFE_INTEGER 也不会把乘积顶出安全整数。纯逻辑,node --test 直测。
* 最大 999_900 档在 10×1000 时为 9_999_000,Number.MAX_SAFE_INTEGER 也顶不出去。
* 纯逻辑,node --test 直测。
* 公司维已整页摘除(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」):归一化构造器
* 与入参类型都不认识 company_id——读侧发送口已随公司 tab 撤下(品牌库 2026-10-06 先例同形)。
* 日期默认空字符串:同步台账是累计数据,默认当天会让首屏只剩今天同步的行
* (date-filter-default-today 护栏 EXEMPT 口径,外观专利页同款)。 */
import { validIsoDateOrUndefined } from '../asin/asin-filter.ts'
import { jdCategoryNamesUnder } from './jd-category-tree.ts'
/** 每页条数默认 20(v1.4 §3.4),上限 100。 */
export const JD_PRODUCT_PAGE_SIZE = 20
export const JD_PRODUCT_MAX_PAGE_SIZE = 100
/** 每页条数默认 50(v1.6 蓝图 Phase 1 新契约,商城款式一屏 50),上限 1000
* (v1.7 对齐原型档位 50/100/200/500/1000,与后端 MAX_PAGE_SIZE 逐字同步——契约
* 测试两侧钉着,改这里必须同窗改 JdProductQueryService.MAX_PAGE_SIZE)。 */
export const JD_PRODUCT_PAGE_SIZE = 50
export const JD_PRODUCT_MAX_PAGE_SIZE = 1000
/** 每页条数档位(v1.7 对齐原型:50/100/200/500/1000,原 20 档退役):页面装配层的
* 档位选择器从这里取数,不再各写各的字面量。 */
export const JD_PRODUCT_PAGE_SIZE_OPTIONS = [50, 100, 200, 500, 1000] as const
/** 页码上限:与后端 MAX_PAGE(CR-18 先例,外观专利同值)对齐,两侧不漂。 */
export const JD_PRODUCT_MAX_PAGE = 10_000
/** 分类状态快筛的出厂档位(2026-11-17 用户口径「不需要全部分类 默认卡在未分类上就行」):
* 首屏/重置都卡它;「筛选激活」判定也以「是否偏离它」为准。 */
export const JD_PRODUCT_DEFAULT_CLASSIFIED = 'ungrouped' as const
/** 分类状态快筛的出厂档位(2026-11-21 用户口径「默认改成全部」,推翻 11-17「默认卡在
* 未分类上就行」;''=全部档):首屏/重置都卡它;非空档(已分类/未分类)才算激活筛选。 */
export const JD_PRODUCT_DEFAULT_CLASSIFIED = '' as const
/** 价格输入 → 有限数:空白/非数字回 null(不下发,后端 BigDecimal 侧也不认脏值)。 */
export function finitePriceOrNull(raw: string): number | null {
const text = (raw || '').trim()
if (!text) return null
const value = Number(text)
return Number.isFinite(value) ? value : null
}
export interface JdProductFilterState {
/** 商品编码,空串不限。 */
productCode: string
/** 标题关键字,空串不限。 */
titleKeyword: string
/** 类目(京麦末级类目名,等值过滤;选项来自 GET /categories),空串=全部类目。 */
/** 合并搜索词(v1.7 对齐原型:一个框同时搜商品编码与标题,OR 语义在后端 SQL)。
* 旧 productCode/titleKeyword 两框随 v1.7 前端下线(后端参数保留兼容在飞请求)。 */
keyword: string
/** 类目(京麦类目名,末级或父级;选项来自侧栏商品目录树),空串=全部类目。 */
category: string
/** 分组 id 文本(分组管理里那一行),空串=全部分组。 */
/** 选中节点的名称路径(2026-11-18 一级/二级类目可选中):非空时序列化按
* jdCategoryNamesUnder 展开为子树类目名集合下发(后端 IN);空=末级/树外行,
* 按单名等值下发(旧形状)。 */
categoryPath?: string[]
/** 店铺名(v1.7 店铺名单维度:侧栏点店铺行下发,精确 eq;空串不限)。 */
shopName: string
/** 分类 id 文本(侧栏店铺分类 Tab 里那一行),空串=全部分类。 */
groupId: string
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」,同日二档收敛
* 「不需要全部分类 默认卡在未分类上就行」):'classified'=已分类(当前分组下有分类),
* 'ungrouped'=未分类,**出厂默认='ungrouped'**(首屏与「重置」都卡未分类档)。
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」;2026-11-18「加个全部
* 选项」恢复全量档;**2026-11-21 用户口径「默认改成全部」=出厂默认改卡 ''**,推翻
* 11-17「默认卡未分类」):'classified'=已分类(当前分组下有分类),'ungrouped'=
* 未分类,''=全部(当前分组下全部商品)。
* 语义按 V203 归属表(当前数据权限分组)判定,与列表分类列同形;不是 11-16 撤掉的
* 旧 grouped/ungrouped 参数(那两档读已停用的 biz_jd_product.group_id 列,后端仍拒收)。
* ''/缺省=「全部」仍是序列化出口的兜底语义(脏值不冒充档位),但界面不再给这一档。 */
* ''(全部档)序列化时不带 classified 参数=后端跳过谓词查全部;脏值同走该兜底。 */
classified?: '' | 'classified' | 'ungrouped'
/** 价格区间下限(v1.7;空串不限,非法数字不下发)。 */
minPrice: string
/** 价格区间上限(v1.7;空串不限,非法数字不下发)。 */
maxPrice: string
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
syncedFrom: string
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
@@ -46,20 +76,33 @@ export interface JdProductFilterState {
}
export function createJdProductFilterState(): JdProductFilterState {
// 分类状态出厂卡「未分类」(2026-11-17 用户口径「默认卡在未分类上就行」):
// 首屏与「重置」都带 classified=false 查,用户要全量自己点「已分类」逐档看。
return { productCode: '', titleKeyword: '', category: '', groupId: '', classified: JD_PRODUCT_DEFAULT_CLASSIFIED, syncedFrom: '', syncedTo: '' }
// 分类状态出厂卡「全部」(2026-11-21 用户口径「默认改成全部」,推翻 11-17「默认卡
// 未分类」):首屏与「重置」都不带 classified 参数查全量;已分类/未分类走显式选档。
return {
keyword: '',
category: '',
categoryPath: [],
shopName: '',
groupId: '',
classified: JD_PRODUCT_DEFAULT_CLASSIFIED,
minPrice: '',
maxPrice: '',
syncedFrom: '',
syncedTo: '',
}
}
/** 是否有任一激活筛选条件。 */
/** 是否有任一激活筛选条件(回显条「清除筛选」的渲染判据;分组作用域 ownerGroupId
* 不在其中——它是作用域不是筛选条件,清除不得碰)。 */
export function jdProductFilterActive(state: JdProductFilterState): boolean {
if ((state.productCode || '').trim()) return true
if ((state.titleKeyword || '').trim()) return true
if ((state.keyword || '').trim()) return true
if ((state.category || '').trim()) return true
if ((state.shopName || '').trim()) return true
if ((state.groupId || '').trim()) return true
// 出厂默认本身卡未分类档(2026-11-17 用户口径),所以只有「偏离默认档」才算激活筛选,
// 否则首屏就永远处于"有筛选"状态,空结果提示会误导用户去重置一个没动过的筛选。
if (state.classified && state.classified !== JD_PRODUCT_DEFAULT_CLASSIFIED) return true
// 出厂默认=「全部」档(2026-11-21 用户口径),任何非空档(已分类/未分类)都算激活筛选;
// ''/缺省不激活,否则首屏就永远处于"有筛选"状态,空结果提示会误导用户去重置没动过的筛选。
if (state.classified) return true
if (finitePriceOrNull(state.minPrice) != null || finitePriceOrNull(state.maxPrice) != null) return true
if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true
return false
}
@@ -68,15 +111,21 @@ export function jdProductFilterActive(state: JdProductFilterState): boolean {
export interface JdProductQuery {
page: number
page_size: number
product_code?: string
title_keyword?: string
/** 京麦末级类目等值过滤(后端 JdProductQueryService.Filter.category)。 */
category?: string
/** 合并搜索词(v1.7:后端 product_code LIKE OR title LIKE)。 */
keyword?: string
/** 京麦类目名集合 IN 过滤(后端 JdProductQueryService.Filter.categories,
* 2026-11-18 一级/二级类目可选中:父级展开为子树类目名集合;末级/树外=单元素)。 */
category?: string[]
/** 店铺名精确过滤(v1.7 店铺名单点选;后端 eq 谓词,铁律 1/20 SQL 下推)。 */
shop_name?: string
/** 自定义分类 id(当前分组下的一个分类;V203 起按归属表 EXISTS 过滤)。 */
group_id?: number
/** 分类状态快筛(2026-11-17):true=已分类、false=未分类,缺省不下发=全部。
* 后端按「当前分组」(owner_group_id)的归属表 EXISTS/NOT EXISTS 在 SQL 侧下推。 */
classified?: boolean
/** 价格区间(v1.7):商品区间完全落在筛选区间内(price_min >= X AND price_max <= Y)。 */
min_price?: number
max_price?: number
/** 当前数据权限分组 id(分类列/分类筛选都按它取;V203「不同组不能看到跨组的分类」)。 */
owner_group_id?: number
synced_from?: string
@@ -87,33 +136,51 @@ export interface JdProductQuery {
export interface JdProductListParams {
page: number
pageSize: number
productCode?: string
titleKeyword?: string
keyword?: string
category?: string
/** 选中类目节点路径(见 JdProductFilterState.categoryPath;空=单名等值)。 */
categoryPath?: string[]
shopName?: string
groupId?: string
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
classified?: string
/** 价格区间(v1.7;空串不限)。 */
minPrice?: string
maxPrice?: string
/** 当前分组(数据权限分组 id):分类列/分类筛选的作用域,非筛选条件(重置不清它)。 */
ownerGroupId?: number | null
syncedFrom?: string
syncedTo?: string
}
/** 过滤态 → 过滤面参数(snake_case,仅下发非空字段)。 */
/** 过滤态 → 过滤面参数(snake_case,仅下发非空字段)。
* 旧 `product_code`/`title_keyword` v1.7 起前端停发(合并进 keyword),反钉在
* jd-product-group.test.ts「参数面不再出现」。 */
function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuery, 'page' | 'page_size'> {
const query: Omit<JdProductQuery, 'page' | 'page_size'> = {}
const productCode = (state.productCode || '').trim()
if (productCode) query.product_code = productCode
const titleKeyword = (state.titleKeyword || '').trim()
if (titleKeyword) query.title_keyword = titleKeyword
const keyword = (state.keyword || '').trim()
if (keyword) query.keyword = keyword
const category = (state.category || '').trim()
if (category) query.category = category
if (category) {
// 2026-11-18 一级/二级类目可选中:带路径=按子树展开类目名集合(后端 IN);
// 路径失效(树外历史名)回落单名等值集合——与旧 eq 语义逐字同形。
const expanded = state.categoryPath && state.categoryPath.length
? jdCategoryNamesUnder(state.categoryPath)
: null
query.category = expanded && expanded.length ? expanded : [category]
}
const shopName = (state.shopName || '').trim()
if (shopName) query.shop_name = shopName
const groupId = Number.parseInt((state.groupId || '').trim(), 10)
if (Number.isFinite(groupId) && groupId > 0) query.group_id = groupId
// 分类状态快筛:只认两个显式档位,其余值(含脏值)按「全部」不下发——后端 classified
// 只收 true/false/缺省,不拿脏值冒充档位。
if (state.classified === 'classified') query.classified = true
else if (state.classified === 'ungrouped') query.classified = false
const minPrice = finitePriceOrNull(state.minPrice)
if (minPrice != null) query.min_price = minPrice
const maxPrice = finitePriceOrNull(state.maxPrice)
if (maxPrice != null) query.max_price = maxPrice
const syncedFrom = validIsoDateOrUndefined(state.syncedFrom)
if (syncedFrom) query.synced_from = syncedFrom
const syncedTo = validIsoDateOrUndefined(state.syncedTo)
@@ -121,7 +188,7 @@ function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuer
return query
}
/** 过滤态 + 分页 → 列表查询参数;空白/非法日期不下发,分页钳制在此单出口(不含公司维)。
/** 过滤态 + 分页 → 列表查询参数;空白/非法日期/非法价格不下发,分页钳制在此单出口(不含公司维)。
* {@code ownerGroupId} 是「当前分组」(分类列/分类筛选作用域,V203),不是筛选条件:
* >0 时下发 `owner_group_id`,缺省/0 不下发=后端按作用域默认分组取。 */
export function toJdProductListParams(
@@ -143,3 +210,45 @@ export function toJdProductListParams(
}
return query
}
// ---------------- 归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」) ----------------
// 归属下拉从 11-17 的状态三档(全部/已分类/未分类)升级成一颗能按分类查询的归属下拉:
// 三档之外追加「按分类查询」组(当前分组的分类项),四类档位互斥、单值表达。分类档走
// 既有 group_id → 归属表 EXISTS 下推(铁律 1/20),与侧栏点分类同一条谓词,后端零改动。
/** 归属下拉「按分类查询」档位的 value 前缀:`cat:<id>`。与状态档共用一颗下拉,靠前缀
* 区分档类;模板选项与选档回写都必须从本常量拼/拆,不允许各写字面量。 */
export const JD_OWNERSHIP_CATEGORY_PREFIX = 'cat:'
/** 归属下拉当前应显示的档位值(派生——下拉是 filter 的视图,真源只有 groupId/classified
* 两个字段):分类档优先,groupId 非空时必须卡 `cat:<id>`(同一颗下拉里选了分类就不该
* 显示状态档,反之亦然);否则回状态档。'' 值的显示走 placeholder「全部」(el-select 对
* '' 按空值处理,placeholder 文案必须与默认档同词——f742df9f 同坑,别再写「未分类」)。 */
export function jdOwnershipSelectValue(state: JdProductFilterState): string {
const groupId = (state.groupId || '').trim()
if (groupId) return `${JD_OWNERSHIP_CATEGORY_PREFIX}${groupId}`
return state.classified || ''
}
/** 归属下拉选档 → 筛选态(原地改 state;调用方随后自行重查,本函数不发请求):
* - `cat:<id>`=按分类查询:写 groupId、清状态档;店铺谓词一起清——店铺名单挂在分类下
* (v1.7 名单维度),换分类后旧店铺词是孤儿谓词(店铺全平台 DISTINCT,会命中别组分类
* 下的同名店),与侧栏 onSelectGroup 同一条纪律;类目维(category/categoryPath)是
* 京麦树,独立维度不碰。
* - ''/classified/ungrouped=状态档:写 classified、清 groupId;店铺词不属分类维度,
* 与既有三档行为一致不动 shopName。
* 脏值(未知前缀/非数字 id)按「全部」档兜底——不拿脏值冒充档位(classified 序列化同形)。 */
export function applyJdOwnershipSelection(state: JdProductFilterState, value: string): void {
const raw = (value || '').trim()
if (raw.startsWith(JD_OWNERSHIP_CATEGORY_PREFIX)) {
const id = Number.parseInt(raw.slice(JD_OWNERSHIP_CATEGORY_PREFIX.length), 10)
if (Number.isFinite(id) && id > 0) {
state.groupId = String(id)
state.classified = ''
state.shopName = ''
return
}
}
state.groupId = ''
state.classified = raw === 'classified' || raw === 'ungrouped' ? raw : ''
}
@@ -48,8 +48,8 @@ export interface JdProductPageResult {
pageSize: number
}
/** 前端首屏默认容量(与 filter 侧 JD_PRODUCT_PAGE_SIZE 同值 20)。 */
export const JD_PRODUCT_DEFAULT_SIZE = 20
/** 前端首屏默认容量(与 filter 侧 JD_PRODUCT_PAGE_SIZE 同值 50,v1.6 蓝图 Phase 1 新契约)。 */
export const JD_PRODUCT_DEFAULT_SIZE = 50
export function emptyJdProductPage(): JdProductPageResult {
return { items: [], total: 0, page: 1, pageSize: JD_PRODUCT_DEFAULT_SIZE }
@@ -1,4 +1,7 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
/** 日志管理页:桌面客户端 / 麦象采集机上报的日志浏览(仅超管)。
* 支持来源/用户/日期筛选,尾部内容查看(自动滚到底、可向前加载更早内容)、
* 完整下载、删除;「采集配置」可调全量/精选模式(全局默认 + 终端覆盖)。 */
@@ -191,10 +194,23 @@ function loadMore() {
loadContent(false)
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.fileName,
deleteOne: (id) => deleteDeviceLogFile(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
scope: () => companyTab.activeId,
consequence: '将删除所选云端日志,此操作不可恢复。',
})
async function remove(row: DeviceLogFileRow) {
if (batch.busy) return
if (!(await openAdminConfirm({ message: `确认删除「${row.fileName}」(${row.deviceName || row.deviceId})的云端日志?删除后不可恢复。`, danger: true }))) return
try {
await deleteDeviceLogFile(row.id)
batch.removeFromSelection(row.id)
ElMessage.success('已删除')
load()
} catch (error) {
@@ -339,10 +355,15 @@ onMounted(() => {
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="logs-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 110px">来源</th>
<th style="width: 200px">用户</th>
<th style="width: 230px">文件名</th>
@@ -355,7 +376,11 @@ onMounted(() => {
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="row in rows" :key="row.id">
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td>
<span class="source-pill" :class="row.source === 'maixiang' ? 'is-maixiang' : 'is-client'">
{{ sourceLabel(row.source) }}
@@ -376,15 +401,15 @@ onMounted(() => {
<td class="ops-cell">
<button class="btn btn-sm" type="button" @click="openViewer(row)">查看</button>
<a class="btn btn-sm btn-ghost dl-link" :href="deviceLogDownloadUrl(row.id)" download>下载</a>
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">删除</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="8" class="empty-tip">加载中...</td>
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="8" class="empty-tip">
<td colspan="9" class="empty-tip">
{{ sourceFilter || uidFilter ? '暂无匹配日志' : '暂无日志上报(客户端/采集机上报后自动出现在这里)' }}
</td>
</tr>
@@ -1,4 +1,7 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
/** 数字人版本管理页 · 像素复刻旧版 admin.html panel-digital-human-version(自绘:面板头+上传、三态状态色、最新★、操作矩阵、数字页码分页)。
* script 逻辑沿用现有 Vue 实现(确认文案/上传进度/下载取链接);确认走原生 confirm 对齐旧版。 */
import { formatDateTime } from '@/utils/datetime'
@@ -182,13 +185,25 @@ async function download(row: DigitalHumanVersion) {
}
}
const batch = useRowSelection({
pageRows: () => pagedItems.value,
rowId: (row) => row.version,
rowLabel: (row) => row.version,
deleteOne: (id) => deleteDigitalHumanVersion(id),
refresh: load,
blocked: () => loading.value || confirming.value != null || !!loadFailure.value,
precheck: (row) => canDelete(row) ? undefined : '不能删除当前最新版本',
})
async function remove(row: DigitalHumanVersion) {
if (batch.busy) return
const text = digitalHumanDeleteConfirmText(row.version)
if (!text) return
if (!(await openAdminConfirm({ message: text, danger: true }))) return
confirming.value = row.version
try {
await deleteDigitalHumanVersion(row.version)
batch.removeFromSelection(row.version)
ElMessage.success('删除成功')
load()
} catch (error) {
@@ -214,17 +229,22 @@ onMounted(load)
<section class="panel-box">
<div class="dh-head">
<h3>版本列表</h3>
<div class="dh-head-tools">
<div class="dh-head-tools admin-header-controls">
<input v-model="versionKeyword" type="text" placeholder="搜索版本号" class="dh-keyword" />
<button class="btn" type="button" @click="uploadVisible = true">上传新版本</button>
</div>
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll digital-human-version-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 80px">版本号</th>
<th style="width: 60px">状态</th>
<th style="width: 60px">最新</th>
@@ -237,7 +257,11 @@ onMounted(load)
</thead>
<tbody>
<template v-if="pagedItems.length">
<tr v-for="row in pagedItems" :key="row.version + row.id">
<tr v-for="row in pagedItems" :key="row.version + row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td><span class="mono-cell">{{ row.version }}</span></td>
<td>
<span class="st-pill" :class="`is-${statusOf(row).tag}`">{{ statusOf(row).text }}</span>
@@ -261,15 +285,15 @@ onMounted(load)
设为最新
</button>
<button v-if="canSetLatestDigitalHumanVersion(row.status)" class="btn btn-sm btn-secondary" type="button" :disabled="downloadingVersion === row.version" @click="download(row)">下载</button>
<button v-if="canDelete(row)" class="btn btn-sm btn-danger" type="button" :disabled="confirming === row.version" @click="remove(row)">删除</button>
<button v-if="canDelete(row)" class="btn btn-sm btn-danger" type="button" :disabled="batch.busy || confirming === row.version" @click="remove(row)">删除</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="8" class="empty-tip">加载中...</td>
<td colspan="9" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="8" class="empty-tip">{{ versionKeyword ? '暂无匹配版本' : '暂无版本记录' }}</td>
<td colspan="9" class="empty-tip">{{ versionKeyword ? '暂无匹配版本' : '暂无版本记录' }}</td>
</tr>
</tbody>
</table>
@@ -162,7 +162,7 @@ onMounted(load)
<section class="panel-box">
<div class="version-head">
<h3>版本列表</h3>
<div class="version-head-tools">
<div class="version-head-tools admin-header-controls">
<input v-model="versionKeyword" type="text" placeholder="搜索版本号" class="version-keyword" />
<button class="btn btn-danger" type="button" :disabled="!selectedCount" @click="removeSelected">删除选中{{ selectedCount ? `(${selectedCount})` : '' }}</button>
<button class="btn" type="button" @click="openUpload">上传新版本</button>
@@ -214,7 +214,7 @@ onMounted(load)
<section class="panel-box">
<div class="tutorial-head">
<h3>教程包列表</h3>
<div class="tutorial-head-tools">
<div class="tutorial-head-tools admin-header-controls">
<input v-model="keyword" type="text" placeholder="搜索文件名" class="tutorial-keyword" />
<button class="btn btn-danger" type="button" :disabled="!selectedCount" @click="removeSelected">删除选中{{ selectedCount ? `(${selectedCount})` : '' }}</button>
<button class="btn" type="button" @click="openUpload">上传教程包</button>
@@ -170,7 +170,7 @@ onMounted(load)
<section class="panel-box">
<div class="workbench-head">
<h3>客户端包列表</h3>
<div class="workbench-head-tools">
<div class="workbench-head-tools admin-header-controls">
<input v-model="keyword" type="text" placeholder="搜索版本号或文件名" class="workbench-keyword" />
<button class="btn btn-danger" type="button" :disabled="!selectedCount" @click="removeSelected">删除选中{{ selectedCount ? `(${selectedCount})` : '' }}</button>
<button class="btn" type="button" @click="openUpload">上传客户端包</button>
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
import { formatDateTime } from '@/utils/datetime'
/** 店铺密钥管理页 · 像素复刻旧版 admin.html panel-shop-keys(自绘:面板头+新增店铺密钥、序号列、令牌掩码、白名单状态药丸+悬停详情、旧式分页)。
* script 逻辑沿用现有 Vue 实现(编辑留空令牌=沿用);弹窗保留现有组件。 */
@@ -57,7 +61,10 @@ function whitelistTooltip(row: ShopKeyItem): string {
return parts.join('\n')
}
const batchListGate = createLatestRequestGate()
async function load() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
@@ -69,14 +76,16 @@ async function load() {
whitelistStatus: filter.whitelistStatus || undefined,
companyId: companyTab.requestCompanyId,
})
if (!batchListGate.isCurrent(token)) return
rows.value = result.items
total.value = result.total
page.value = result.page
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '密钥列表加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -151,11 +160,23 @@ async function submit() {
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.ziniaoAccountName,
deleteOne: (id) => deleteShopKey(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
scope: () => companyTab.activeId,
})
async function remove(row: ShopKeyItem) {
if (batch.busy) return
// 对齐旧版:原生 confirm。
if (!(await openAdminConfirm({ message: `确定删除店铺密钥“${row.ziniaoAccountName}”吗?`, danger: true }))) return
try {
await deleteShopKey(row.id)
batch.removeFromSelection(row.id)
ElMessage.success('已删除')
load()
} catch (error) {
@@ -226,12 +247,17 @@ onMounted(load)
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="shop-key-table-scroll">
<table>
<thead>
<!-- 刚性列(序号/两个时间/操作)给准 px,文本列收到"能 ellipsis 但不白占"的宽度:
原来 1538px 在 ~1280 的内容区里放不下,"操作"整列要横向滚动才看得见。 -->
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 52px">序号</th>
<th style="width: 110px">备注名</th>
<th style="width: 140px">紫鸟账号名称</th>
@@ -245,7 +271,11 @@ onMounted(load)
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="(row, index) in rows" :key="row.id">
<tr v-for="(row, index) in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td>{{ (page - 1) * pageSize + index + 1 }}</td>
<td>{{ row.remarkName || '—' }}</td>
<td>{{ row.ziniaoAccountName }}</td>
@@ -280,15 +310,15 @@ onMounted(load)
>
{{ checkingId === row.id ? '检测中…' : '检测白名单' }}
</button>
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">删除</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td colspan="9" class="empty-tip">加载中...</td>
<td colspan="10" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td colspan="9" class="empty-tip">{{ anyFilterActive ? '暂无匹配密钥' : '暂无店铺密钥' }}</td>
<td colspan="10" class="empty-tip">{{ anyFilterActive ? '暂无匹配密钥' : '暂无店铺密钥' }}</td>
</tr>
</tbody>
</table>
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
import { formatDateTime } from '@/utils/datetime'
/** 店铺管理页 · 像素复刻旧版 admin.html panel-shop-manage(自绘:面板头+新增店铺、筛选、密码列 ******+眼睛实时读明文、旧式表格/分页、原生 confirm 删除)。
* script 逻辑沿用现有 Vue 实现(凭证明文 dialog/编辑弹窗/分组筛选)。 */
@@ -87,7 +91,10 @@ async function loadGroups() {
}
}
const batchListGate = createLatestRequestGate()
async function load() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
@@ -98,14 +105,16 @@ async function load() {
shopName: filter.shopName.trim() || undefined,
companyId: companyTab.requestCompanyId,
})
if (!batchListGate.isCurrent(token)) return
rows.value = result.items
total.value = result.total
page.value = result.page
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '店铺列表加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -199,11 +208,23 @@ async function showCredential(row: ShopSummary) {
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.shopName,
deleteOne: (id) => deleteShopManage(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value,
scope: () => companyTab.activeId,
})
async function remove(row: ShopSummary) {
if (batch.busy) return
// 对齐旧版:原生 confirm。
if (!(await openAdminConfirm({ message: `确定删除店铺“${row.shopName}”吗?`, danger: true }))) return
try {
await deleteShopManage(row.id)
batch.removeFromSelection(row.id)
ElMessage.success('已删除')
load()
} catch (error) {
@@ -249,10 +270,15 @@ onMounted(() => {
</div>
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
<BatchDeleteActions :batch="batch" />
<div class="table-scroll shop-manage-table-scroll">
<table>
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 58px">序号</th>
<th v-if="isSuperAdmin" style="width: 120px">分组</th>
<th style="width: 150px">店铺名</th>
@@ -267,7 +293,11 @@ onMounted(() => {
</thead>
<tbody>
<template v-if="rows.length">
<tr v-for="(row, index) in rows" :key="row.id">
<tr v-for="(row, index) in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td>{{ (page - 1) * pageSize + index + 1 }}</td>
<td v-if="isSuperAdmin" data-text :title="row.groupName || '—'">{{ row.groupName || '—' }}</td>
<td :title="row.shopName">{{ row.shopName }}</td>
@@ -290,15 +320,15 @@ onMounted(() => {
<td class="ops-cell">
<button class="btn btn-sm" type="button" @click="openEdit(row)">编辑</button>
<button class="btn btn-sm btn-secondary" type="button" @click="showCredential(row)">凭证</button>
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">删除</button>
<button class="btn btn-sm btn-danger" type="button" :disabled="batch.busy" @click="remove(row)">删除</button>
</td>
</tr>
</template>
<tr v-else-if="loading">
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">加载中...</td>
<td :colspan="isSuperAdmin ? 11 : 10" class="empty-tip">加载中...</td>
</tr>
<tr v-else>
<td :colspan="isSuperAdmin ? 10 : 9" class="empty-tip">暂无店铺</td>
<td :colspan="isSuperAdmin ? 11 : 10" class="empty-tip">暂无店铺</td>
</tr>
</tbody>
</table>
@@ -38,7 +38,9 @@ export const SHOP_MANAGE_GROUPS_ENDPOINT = '/api/admin/shop-manages/groups'
/** 分组下拉:打的是与分组管理页同一个 GET /groups,所以它也必须跟着公司 tab 收窄,
* 否则店铺列表窄了、下拉里还选得到别家的组。 */
export async function fetchShopManageGroups(companyId?: number | null): Promise<ShopGroupOption[]> {
const { data } = await http.get<unknown>(SHOP_MANAGE_GROUPS_ENDPOINT, { params: companyId != null ? { company_id: companyId } : {} })
// platform 恒 'amazon'(2026-11-22 用户口径「亚马逊的也是同理」):店铺/查询ASIN/跟价页是
// 亚马逊域,京东档分组(platform='jd')不得混进本下拉——与分组管理页按平台 tab 过滤同口径。
const { data } = await http.get<unknown>(SHOP_MANAGE_GROUPS_ENDPOINT, { params: { platform: 'amazon', ...(companyId != null ? { company_id: companyId } : {}) } })
return parseShopManageGroups(data)
}
@@ -1,4 +1,7 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
/**
* 品牌Gating库管理页(独立菜单 admin_brand_gating,V174 恢复)。
* 数据源 /api/admin/brand-gating(biz_brand_gating,全平台共享,不随公司 Tab 收窄)。
@@ -191,7 +194,18 @@ async function toggleStatus(row: BrandGatingRow): Promise<void> {
}
}
const batch = useRowSelection({
pageRows: () => rows.value,
rowId: (row) => row.id,
rowLabel: (row) => row.brand || `ID ${row.id}`,
deleteOne: (id) => deleteBrandGating(id),
refresh: () => Promise.all([loadPage(), loadStats()]),
blocked: () => pageLoading.value || busyRowId.value !== 0 || !!loadError.value,
consequence: '删除后可能影响已有数据,此操作不可恢复。',
})
async function removeRow(row: BrandGatingRow): Promise<void> {
if (batch.busy) return
const confirmed = await openAdminConfirm({ danger: true,
targetName: row.brand,
message: `确认删除 ID=${row.id} 的「${row.brand}」Gating记录?此操作可能影响已有数据。`,
@@ -200,6 +214,7 @@ async function removeRow(row: BrandGatingRow): Promise<void> {
busyRowId.value = row.id
try {
await deleteBrandGating(row.id)
batch.removeFromSelection(row.id)
feedback('已删除', 'success')
const nextPage = rows.value.length === 1 && page.value > 1 ? page.value - 1 : page.value
await Promise.all([loadPage(nextPage), loadStats()])
@@ -328,10 +343,15 @@ onMounted(() => {
<LoadFailureBar v-if="loadError" :message="loadError" @retry="loadPage()" />
<BatchDeleteActions :batch="batch" />
<div class="g-table-wrap" v-loading="pageLoading">
<table v-if="rows.length" class="g-table">
<thead>
<tr>
<th class="batch-delete-cell" scope="col">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
</th>
<th style="width: 64px">ID</th>
<th>品牌</th>
<th>ASIN</th>
@@ -346,7 +366,11 @@ onMounted(() => {
</tr>
</thead>
<tbody>
<tr v-for="row in rows" :key="row.id">
<tr v-for="row in rows" :key="row.id" :class="{ 'batch-selected': batch.isSelected(row) }">
<td class="batch-delete-cell">
<BatchDeleteCheckbox :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
</td>
<td class="g-dim">{{ row.id }}</td>
<td class="g-strong">{{ row.brand }}</td>
<td class="g-mono">{{ row.asin || '—' }}</td>
@@ -375,7 +399,7 @@ onMounted(() => {
<button
class="g-btn g-btn-sm g-btn-danger"
type="button"
:disabled="busyRowId === row.id"
:disabled="batch.busy || busyRowId === row.id"
@click="removeRow(row)"
>
删除
@@ -0,0 +1,349 @@
/* 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(蓝白末层)。 */
.sd-view {
font-family: inherit;
color: #24384d;
display: flex;
flex-direction: column;
gap: 18px;
}
.form-box,
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0 0 14px;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.sd-filter-title {
margin: 0 0 14px;
font-size: 13.5px;
font-weight: 600;
color: #40586e;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 18px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.sd-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
margin-bottom: 14px;
}
.sd-toolbar-main {
display: inline-flex;
align-items: center;
gap: 14px;
flex-wrap: wrap;
}
.sd-toolbar-side {
display: inline-flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
justify-content: flex-end;
}
.sd-select-all {
display: inline-flex;
align-items: center;
gap: 7px;
font-size: 13px;
color: #5b6f83;
cursor: pointer;
}
.sd-summary {
color: #5b6f83;
font-size: 13px;
white-space: nowrap;
}
.sd-shop-pager {
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: #5b6f83;
}
.sd-shop-pager button,
.pagination button,
.jump-btn {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.sd-shop-pager button:hover:not(:disabled),
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.sd-shop-pager button:disabled,
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.sd-shop-pager input,
.page-jump input {
width: 52px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.shop-card-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 14px;
}
.sd-card {
border: 1px solid #d8e3ee;
border-radius: 12px;
background: #ffffff;
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
overflow: hidden;
}
.sd-card-head {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 16px;
border-bottom: 1px solid #e6edf4;
}
.sd-shop-name {
font-weight: 600;
color: #24384d;
}
.sd-card-select-row {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 16px 0;
}
.shop-card-task-no {
flex: 1 1 auto;
min-width: 0;
font-weight: 600;
font-size: 12px;
color: #24384d;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.sd-card-row {
display: flex;
align-items: flex-start;
gap: 10px;
padding: 6px 16px;
font-size: 13px;
}
.sd-card-label {
flex: none;
width: 52px;
color: #8293a5;
}
.sd-card-value {
color: #40586e;
min-width: 0;
}
.sd-card-file {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.sd-card-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 6px 16px 14px;
}
.st-pill {
display: inline-flex;
align-items: center;
padding: 2px 10px;
border-radius: 999px;
font-size: 12px;
line-height: 1.7;
border: 1px solid transparent;
white-space: nowrap;
flex: none;
}
.st-pill.is-success {
color: #3d7158;
background: #e8f2eb;
border-color: #bdd7c5;
}
.st-pill.is-failed {
color: #91474f;
background: #f8ebeb;
border-color: #e4c2c5;
}
.st-pill.is-cancelled {
color: #5b6f83;
background: #f1f6fa;
border-color: #d6e2ec;
}
.st-pill.is-pending,
.st-pill.is-running {
color: #8a6d3b;
background: #fbf4ea;
border-color: #e7d3ae;
}
.country-chip {
padding: 1px 8px;
margin-right: 4px;
border-radius: 999px;
background: #eef4fa;
color: #40586e;
font-size: 12px;
}
.dim {
color: #8293a5;
font-size: 12px;
}
.sd-progress-hint {
margin: 10px 0 0;
text-align: center;
color: #5b6f83;
font-size: 13px;
}
.empty-tip {
grid-column: 1 / -1;
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
@media (max-width: 1400px) {
.shop-card-grid {
grid-template-columns: repeat(3, 1fr);
}
}
@media (max-width: 1100px) {
.shop-card-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 760px) {
.shop-card-grid {
grid-template-columns: 1fr;
}
}
@@ -1,4 +1,8 @@
<script setup lang="ts">
import BatchDeleteActions from '@/components/BatchDeleteActions.vue'
import BatchDeleteCheckbox from '@/components/BatchDeleteCheckbox.vue'
import { useRowSelection } from '@/utils/use-row-selection'
import { createLatestRequestGate } from '@/utils/latest-request'
import { formatDateTime, orderedPair } from '@/utils/datetime'
/** 店铺数据记录页 · 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(自绘:form-box 筛选[h4 筛选条件] + panel-box toolbar[全选/批量下载/权限配置/汇总] + 每店卡片网格 + 旧式分页(店铺级+卡片级 9/页))。
* script 逻辑沿用现有 Vue 实现(批量打包/删除结果文件[保留]/权限授权)。 */
@@ -129,19 +133,24 @@ function toFilter(): ShopDataFilter {
}
}
const batchListGate = createLatestRequestGate()
async function load() {
const token = batchListGate.begin()
loading.value = true
loadFailure.value = ''
try {
const result = await fetchShopDataTaskList(toFilter(), page.value, pageSize.value, companyTab.requestCompanyId)
if (!batchListGate.isCurrent(token)) return
groups.value = result.items
totalShops.value = result.total
page.value = result.page
} catch (error) {
if (!batchListGate.isCurrent(token)) return
loadFailure.value = error instanceof Error ? error.message : '店铺数据记录加载失败'
showAdminFeedback(loadFailure.value, 'error')
} finally {
loading.value = false
if (batchListGate.isCurrent(token)) loading.value = false
}
}
@@ -256,12 +265,26 @@ async function downloadBatch() {
}
}
const batch = useRowSelection({
pageRows: () => pagedResultRows.value,
rowId: (row) => row.resultId,
rowLabel: (row) => `${row.shopName || '店铺'}(${row.filename || row.taskNo || row.resultId})`,
deleteOne: (id) => deleteShopDataResultHistory(id),
refresh: load,
blocked: () => loading.value || !!loadFailure.value || !!deletingKey.value,
scope: () => companyTab.activeId,
precheck: (row) => isTerminalStatus(row.status) && row.resultId ? undefined : '仅终态数据记录可删除',
consequence: '店铺数据文件及对应记录将一起删除,此操作不可恢复。',
})
async function removeRowByRow(row: ShopDataResultRow) {
if (batch.busy) return
// 管理端真删:删除该店这条店铺数据记录(累计档 + 文件 + 明细),前台任务记录仍保留但文件不可再下载
if (!(await openAdminConfirm({ message: `确认删除店铺“${row.shopName}”这条店铺数据记录及其数据文件?此操作不可恢复。`, danger: true }))) return
deletingKey.value = row.resultId
try {
await deleteShopDataResultHistory(row.resultId)
batch.removeFromSelection(row.resultId)
ElMessage.success('删除成功')
await load()
} catch (error) {
@@ -371,14 +394,25 @@ onMounted(load)
</div>
</div>
<div class="sd-toolbar">
<label class="sd-select-all">
<BatchDeleteCheckbox label="全选当前页可删除记录" :checked="batch.pageAll" :partial="batch.pageSome"
:disabled="batch.disabled || batch.pageEmpty" @change="batch.togglePage" />
全选本页可删除记录
</label>
<BatchDeleteActions :batch="batch" />
</div>
<div v-loading="loading" class="shop-card-grid">
<template v-if="allResultRows.length">
<article
v-for="row in pagedResultRows"
:key="row.resultId || `${row.taskNo}-${row.filename}`"
class="sd-card"
:class="{ 'batch-selected': batch.isSelected(row) }"
>
<header class="sd-card-head">
<BatchDeleteCheckbox v-if="!batch.reason(row)" :label="batch.reason(row) || `选择 ${batch.label(row)}`" :checked="batch.isSelected(row)"
:disabled="batch.disabled || !!batch.reason(row)" @change="batch.toggle(row)" />
<span class="sd-shop-name" :title="row.shopName || '-'">{{ row.shopName || '-' }}</span>
</header>
<div class="sd-card-select-row">
@@ -418,7 +452,7 @@ onMounted(load)
v-if="isTerminalStatus(row.status) && !!row.resultId"
class="btn btn-sm btn-danger"
type="button"
:disabled="deletingKey === row.resultId"
:disabled="batch.busy || deletingKey === row.resultId"
@click="removeRowByRow(row)"
>
{{ deletingKey === row.resultId ? '删除中...' : '删除' }}
@@ -462,354 +496,4 @@ onMounted(load)
</div>
</template>
<style scoped>
/* 像素复刻旧版 admin.html panel-shop-data-crawl-tasks(蓝白末层)。 */
.sd-view {
font-family: inherit;
color: #24384d;
display: flex;
flex-direction: column;
gap: 18px;
}
.form-box,
.panel-box {
width: 100%;
min-width: 0;
padding: 20px 22px 24px;
border: 1px solid #d8e3ee;
border-radius: 14px;
background: linear-gradient(145deg, #ffffff, #f9fbfd);
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
}
h3 {
margin: 0 0 14px;
font-size: 15px;
font-weight: 650;
color: #24384d;
letter-spacing: 0.2px;
}
.sd-filter-title {
margin: 0 0 14px;
font-size: 13.5px;
font-weight: 600;
color: #40586e;
}
.form-row {
display: flex;
flex-wrap: wrap;
align-items: flex-end;
gap: 14px 18px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 7px;
margin-bottom: 0;
}
.form-group label {
color: #5b6f83;
font-size: 12.5px;
font-weight: 600;
}
.form-group input {
min-width: 0;
min-height: 42px;
padding: 8px 12px;
border: 1px solid #cbd9e6;
border-radius: 9px;
background: #f8fbfd;
color: #24384d;
font-size: 13.5px;
font-family: inherit;
color-scheme: light;
outline: none;
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}
.form-group input:hover {
border-color: #9fb7cd;
}
.form-group input:focus {
background: #ffffff;
border-color: #5f85ad;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
min-height: 42px;
padding: 9px 18px;
border: 1px solid #4f78a5;
border-radius: 9px;
background: linear-gradient(135deg, #5f85ad, #4f78a5);
color: #ffffff;
font-family: inherit;
font-size: 13.5px;
cursor: pointer;
box-shadow: 0 8px 18px -14px rgba(79, 120, 165, 0.72);
transition: background 160ms ease, box-shadow 160ms ease, transform 120ms ease;
}
.btn:hover:not(:disabled) {
background: linear-gradient(135deg, #7094ba, #5d83ac);
box-shadow: 0 11px 22px -14px rgba(79, 120, 165, 0.8);
}
.btn:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.btn-secondary {
background: #ffffff;
color: #5b6f83;
border-color: #c7d7e5;
}
.btn-secondary:hover:not(:disabled) {
color: #2f5d8b;
border-color: #95b1cb;
background: #edf5fb;
}
.btn-danger {
background: linear-gradient(135deg, #c06d77, #b35f6a);
border-color: #b35f6a;
}
.btn-danger:hover:not(:disabled) {
background: linear-gradient(135deg, #cb7c84, #b96570);
}
.btn-sm {
min-height: 36px;
padding: 7px 12px;
}
.sd-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
margin-bottom: 14px;
}
.sd-toolbar-main {
display: inline-flex;
align-items: center;
gap: 14px;
flex-wrap: wrap;
}
.sd-toolbar-side {
display: inline-flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
justify-content: flex-end;
}
.sd-select-all {
display: inline-flex;
align-items: center;
gap: 7px;
font-size: 13px;
color: #5b6f83;
cursor: pointer;
}
.sd-summary {
color: #5b6f83;
font-size: 13px;
white-space: nowrap;
}
.sd-shop-pager {
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 13px;
color: #5b6f83;
}
.sd-shop-pager button,
.pagination button,
.jump-btn {
min-height: 30px;
padding: 4px 12px;
border: 1px solid #c7d7e5;
border-radius: 8px;
background: #ffffff;
color: #5b6f83;
font-family: inherit;
font-size: 13px;
cursor: pointer;
}
.sd-shop-pager button:hover:not(:disabled),
.pagination button:hover:not(:disabled) {
background: #edf5fb;
border-color: #95b1cb;
color: #2f5d8b;
}
.sd-shop-pager button:disabled,
.pagination button:disabled {
background: #eef3f7;
color: #9baaba;
cursor: not-allowed;
}
.sd-shop-pager input,
.page-jump input {
width: 52px;
min-height: 30px;
padding: 4px 8px;
border: 1px solid #cbd9e6;
border-radius: 8px;
background: #f8fbfd;
color: #24384d;
font-size: 13px;
font-family: inherit;
}
.shop-card-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 14px;
}
.sd-card {
border: 1px solid #d8e3ee;
border-radius: 12px;
background: #ffffff;
box-shadow: 0 1px 2px rgba(39, 67, 94, 0.04), 0 14px 30px -24px rgba(39, 67, 94, 0.28);
overflow: hidden;
}
.sd-card-head {
display: flex;
align-items: center;
gap: 10px;
padding: 12px 16px;
border-bottom: 1px solid #e6edf4;
}
.sd-shop-name {
font-weight: 600;
color: #24384d;
}
.sd-card-select-row {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 16px 0;
}
.shop-card-task-no {
flex: 1 1 auto;
min-width: 0;
font-weight: 600;
font-size: 12px;
color: #24384d;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.sd-card-row {
display: flex;
align-items: flex-start;
gap: 10px;
padding: 6px 16px;
font-size: 13px;
}
.sd-card-label {
flex: none;
width: 52px;
color: #8293a5;
}
.sd-card-value {
color: #40586e;
min-width: 0;
}
.sd-card-file {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.sd-card-actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
padding: 6px 16px 14px;
}
.st-pill {
display: inline-flex;
align-items: center;
padding: 2px 10px;
border-radius: 999px;
font-size: 12px;
line-height: 1.7;
border: 1px solid transparent;
white-space: nowrap;
flex: none;
}
.st-pill.is-success {
color: #3d7158;
background: #e8f2eb;
border-color: #bdd7c5;
}
.st-pill.is-failed {
color: #91474f;
background: #f8ebeb;
border-color: #e4c2c5;
}
.st-pill.is-cancelled {
color: #5b6f83;
background: #f1f6fa;
border-color: #d6e2ec;
}
.st-pill.is-pending,
.st-pill.is-running {
color: #8a6d3b;
background: #fbf4ea;
border-color: #e7d3ae;
}
.country-chip {
padding: 1px 8px;
margin-right: 4px;
border-radius: 999px;
background: #eef4fa;
color: #40586e;
font-size: 12px;
}
.dim {
color: #8293a5;
font-size: 12px;
}
.sd-progress-hint {
margin: 10px 0 0;
text-align: center;
color: #5b6f83;
font-size: 13px;
}
.empty-tip {
grid-column: 1 / -1;
padding: 44px 24px;
text-align: center;
color: #8293a5;
font-size: 13.5px;
}
.pagination {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 18px;
color: #5b6f83;
font-size: 13px;
}
.page-total {
margin-right: 4px;
}
.page-jump {
display: inline-flex;
align-items: center;
gap: 6px;
}
@media (max-width: 1400px) {
.shop-card-grid {
grid-template-columns: repeat(3, 1fr);
}
}
@media (max-width: 1100px) {
.shop-card-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 760px) {
.shop-card-grid {
grid-template-columns: 1fr;
}
}
</style>
<style scoped src="./ShopDataTasksPage.css"></style>
@@ -75,6 +75,7 @@ import 'element-plus/es/components/input-number/style/css'
import 'element-plus/es/components/menu/style/css'
import 'element-plus/es/components/menu-item/style/css'
import 'element-plus/es/components/option/style/css'
import 'element-plus/es/components/option-group/style/css'
import 'element-plus/es/components/progress/style/css'
import 'element-plus/es/components/radio-button/style/css'
import 'element-plus/es/components/radio-group/style/css'
@@ -38,5 +38,13 @@ export const usePlatformTabStore = defineStore('platform-tab', {
this.active = id
writeStoredTab(id)
},
/** 平台锁定(2026-11-18 用户口径「非站点超管只看自己平台侧」):允许集收敛时把 active
* 归位——localStorage 残留的另一侧(超管在同一浏览器切过 tab)自动回落本人平台;
* 允许集为空(会话未就位)不动。 */
syncToAllowed(allowed: readonly PlatformTabId[]) {
if (allowed.length > 0 && !allowed.includes(this.active)) {
this.setActive(allowed[0])
}
},
},
})
+83 -13
View File
@@ -41,7 +41,10 @@ body {
button, input, textarea, select { font: inherit; }
/* ===== 蓝白浅色壳层(对齐 admin.html 末层皮肤) ===== */
.admin-shell { display: flex; min-height: 100vh; background: var(--admin-bg); }
/* 壳层锁视口高(2026-11-18「菜单加个滚动条」):min-height 会让 flex 高度链失去确定性,
* el-scrollbar 与 .admin-content 的 overflow 全部失效、回落整页滚,侧边栏顶部(品牌区/平台
* tab)被滚出视口。height:100vh 定高后侧边栏与 .admin-content 各自独立滚动、顶栏固定。 */
.admin-shell { display: flex; height: 100vh; overflow: hidden; background: var(--admin-bg); }
.admin-sidebar {
display: flex; flex: 0 0 252px; flex-direction: column;
background: linear-gradient(180deg, var(--admin-sidebar) 0%, var(--admin-sidebar-deep) 100%);
@@ -111,7 +114,7 @@ button, input, textarea, select { font: inherit; }
.admin-main { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.admin-topbar {
display: flex; align-items: center; justify-content: space-between; gap: 24px;
min-height: 76px; padding: 0 32px;
min-height: 56px; padding: 0 16px; flex-shrink: 0;
background: rgba(255, 255, 255, 0.92);
border-bottom: 1px solid var(--admin-border);
box-shadow: 0 10px 28px -28px rgba(39, 67, 94, 0.42);
@@ -132,8 +135,8 @@ button, input, textarea, select { font: inherit; }
}
.admin-user-logout.el-button:hover { color: var(--admin-primary-strong); border-color: #95b1cb; background: #edf5fb; }
.admin-content { flex: 1; min-width: 0; padding: 30px 32px 56px; overflow: auto; }
.page-stack { display: flex; flex-direction: column; gap: 18px; }
.admin-content { flex: 1; min-width: 0; min-height: 0; padding: 12px 16px 20px; overflow: auto; }
.page-stack { display: flex; flex-direction: column; gap: 10px; }
/* 表格操作按钮工具栏:置于表格卡片顶部、右对齐(新增/删除/导入/导出等贴近表格行操作)。 */
.table-toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
@@ -216,19 +219,86 @@ button, input, textarea, select { font: inherit; }
background: #f8fbfd;
box-shadow: 0 0 0 1px #cbd9e6 inset;
}
.el-select.admin-filter .el-select__wrapper:hover {
.el-select.admin-filter .el-select__wrapper:hover:not(.is-disabled, .is-focused) {
box-shadow: 0 0 0 1px #9fb7cd inset;
}
.el-select.admin-filter.is-focused .el-select__wrapper {
.el-select.admin-filter .el-select__wrapper.is-focused {
background: #ffffff;
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
box-shadow: 0 0 0 1px var(--admin-primary) inset, 0 0 0 3px rgba(95, 133, 173, 0.16);
}
/* 列表密度统一收口;带壳层作用域的选择器覆盖各页 scoped 旧皮肤,不影响弹窗编辑表单。 */
.admin-shell .admin-content :is(.panel-box, .form-box) { padding: 12px 14px; }
.admin-shell .admin-content .el-card { --el-card-padding: 12px; }
.admin-shell .admin-content > [class$="-view"] { gap: 10px; min-width: 0; }
.admin-shell .admin-content :is(.panel-box, .form-box) h3 { margin-bottom: 8px; }
.admin-shell .admin-content :is(.jd-panel-head, .dedupe-panel-head) { margin-bottom: 8px; }
.admin-shell .admin-content :is(.jd-panel-head, .dedupe-panel-head) h3 { margin-bottom: 0; }
.admin-shell .admin-content :is(.users-desc, .page-heading p) { margin-top: 4px; margin-bottom: 8px; }
.admin-shell .admin-content :is(.form-row, .clean-filter-row, .dedupe-filter-row, .dedupe-filter-date-row, .jd-filter-row) {
display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-bottom: 10px;
}
.admin-shell .admin-content :is(.clean-filter-row, .dedupe-filter-row, .jd-filter-row) > .form-group {
flex: 1 1 140px; min-width: 0; max-width: 220px;
}
.admin-shell .admin-content :is(.form-row, .clean-filter-row, .dedupe-filter-row, .dedupe-filter-date-row, .jd-filter-row) .form-group { gap: 4px; }
/* 只给原生字段的外框定尺寸,不穿透下拉/级联组件的内部输入。 */
.admin-shell .admin-content :is(.panel-box, .form-box) .form-group > input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.admin-shell .admin-content .price-range-row > input,
.admin-shell .admin-content .admin-header-controls > input,
.admin-shell .admin-content .jd-group-locked { min-height: 34px; padding: 5px 10px; }
.admin-shell .admin-content .el-select.admin-filter .el-select__wrapper { min-height: 34px; padding: 4px 10px; }
.admin-shell .admin-content .admin-header-controls { min-width: 0; flex-wrap: wrap; gap: 8px; }
.admin-shell .admin-content .admin-header-controls > input { max-width: 100%; }
.admin-shell .admin-content .admin-header-controls > .btn,
.admin-shell .admin-content :is(.panel-box, .form-box) .btn:not(.btn-sm) { min-height: 34px; padding: 5px 12px; }
.admin-shell .admin-content :is(.clean-filter-actions, .dedupe-filter-actions, .jd-filter-actions) { flex-wrap: wrap; gap: 6px; }
.admin-shell .admin-content .jd-filter-row > .el-select.admin-filter { width: 170px; }
.admin-shell .admin-content :is(.table-toolbar, .clean-toolbar) { margin-bottom: 8px; }
.admin-shell .admin-content :is(.table-scroll, .table-wrap) :is(th, td) { padding-top: 6px; padding-bottom: 6px; }
.admin-shell .admin-content :is(.table-scroll, .table-wrap) .btn-sm { min-height: 28px; padding: 3px 6px; font-size: 12.5px; }
.admin-shell .admin-content :is(.table-scroll, .table-wrap) .ops-cell { gap: 4px; }
.admin-shell .admin-content .el-table .el-table__cell { padding: 5px 0; }
.admin-shell .admin-content .old-pagination { gap: 8px; margin-top: 10px; }
.admin-shell .admin-content .table-footer { padding-top: 10px; }
.admin-shell .admin-content .admin-breadcrumb { margin-bottom: 8px; }
.admin-shell .admin-content .company-tabs { margin-bottom: 8px; }
.admin-shell .admin-content .company-tab { padding: 4px 12px; }
.admin-shell .admin-content .operation-guide { margin-bottom: 10px; padding: 8px 12px; }
.admin-shell .admin-content .og-body { margin-top: 4px; }
.admin-shell .admin-content .og-text { line-height: 1.5; }
.admin-shell .admin-content .og-steps { gap: 4px; margin-top: 4px; }
@media (max-width: 1440px) {
.admin-sidebar { flex-basis: 208px; }
.admin-content { padding: 10px 12px 16px; }
}
@media (max-width: 820px) {
.admin-sidebar { flex-basis: 64px; }
.admin-brand-copy, .admin-menu .el-sub-menu__title span, .admin-menu .el-menu-item { display: none; }
.admin-topbar { align-items: flex-start; flex-direction: column; padding: 12px 18px; }
.admin-user { width: 100%; justify-content: space-between; }
.admin-user-meta { align-items: flex-start; }
.admin-content { padding: 18px 16px 40px; }
.admin-sidebar { flex-basis: 160px; }
.admin-brand { padding: 12px 10px; }
.admin-brand-copy span, .admin-kicker { display: none; }
.admin-topbar { min-height: 56px; gap: 8px; padding: 8px 12px; flex-wrap: wrap; }
.admin-topbar h1 { margin-top: 0; font-size: 16px; }
.admin-user { gap: 8px; flex-wrap: wrap; }
.admin-content { padding: 8px 10px 12px; }
.admin-shell .admin-content :is(.panel-box, .form-box) { padding: 10px; }
.admin-shell .admin-content .form-row > .form-group { flex: 1 1 140px; min-width: 0; max-width: 100%; }
}
@media (max-width: 560px) {
.admin-sidebar { flex-basis: 128px; }
.admin-brand { gap: 6px; }
.admin-brand-logo { width: 28px; height: 28px; }
.admin-brand-copy strong { font-size: 13px; }
.admin-menu-scroll { padding: 8px 4px; }
.admin-menu .el-sub-menu__title, .admin-menu .el-menu-item { padding: 0 8px; font-size: 12px; }
.menu-group-title { font-size: 13px; }
.admin-user-role { display: none; }
.admin-shell .admin-content :is(.clean-filter-row, .dedupe-filter-row, .jd-filter-row) > .form-group { max-width: 100%; }
}
/* 自绘表格的批量选择列保持窄列,不挤占数据列。 */
.admin-shell table :is(th, td).batch-delete-cell { width: 38px; text-align: center; padding-inline: 4px; }
.admin-shell table tbody tr.batch-selected > td { background: #fdf0ee; }
.admin-shell .batch-selected:is(.sd-card, .option-row) { background: #fdf0ee; }
@@ -0,0 +1,61 @@
import { failureDetail } from '../components/load-failure-model.ts'
type RowId = number | string
interface BatchRow<Id extends RowId> { id: Id; label: string }
export interface BatchDeleteResult<Id extends RowId> {
deleted: Id[]
failures: Array<BatchRow<Id> & { reason: string }>
remaining: number
}
export function togglePageSelection<Id extends RowId, Row extends BatchRow<Id>>(
selected: ReadonlyMap<Id, Row>, rows: readonly Row[],
): Map<Id, Row> {
const next = new Map(selected)
if (rows.every(({ id }) => next.has(id))) {
rows.forEach(({ id }) => next.delete(id))
} else {
rows.forEach((row) => next.set(row.id, row))
}
return next
}
export async function runBatchDelete<Id extends RowId, Row extends BatchRow<Id>>(options: {
rows: readonly Row[]
deleteOne: (row: Row) => Promise<unknown>
precheck?: (row: Row) => string | undefined
isCurrent?: () => boolean
onProgress?: (processed: number) => void
}): Promise<BatchDeleteResult<Id>> {
const { deleteOne, isCurrent, onProgress, precheck } = options
const rows = [...new Map(options.rows.map((row) => [row.id, row])).values()]
const deleted: Id[] = []
const failures: BatchDeleteResult<Id>['failures'] = []
let processed = 0
for (const row of rows) {
if (isCurrent && !isCurrent()) break
try {
const reason = precheck?.(row)
if (reason) failures.push({ id: row.id, label: row.label, reason })
else {
await deleteOne(row)
deleted.push(row.id)
}
} catch (error) {
failures.push({ id: row.id, label: row.label, reason: failureDetail(error) || '删除请求失败' })
}
processed++
onProgress?.(processed)
}
return { deleted, failures, remaining: rows.length - processed }
}
export function batchResultMessage(result: BatchDeleteResult<RowId>, verb = '删除', detailLimit = Infinity): string {
const counts = [`已${verb} ${result.deleted.length} 条`]
if (result.failures.length) counts.push(`失败 ${result.failures.length} 条`)
if (result.remaining) counts.push(`未处理 ${result.remaining} 条`)
const details = result.failures.slice(0, detailLimit).map(({ label, reason }) => `${label}(${reason})`)
if (details.length && details.length < result.failures.length) details.push('其余原因见列表上方')
return counts.join(',') + (details.length ? `:${details.join(';')}` : '')
}
@@ -0,0 +1,109 @@
import { computed, onScopeDispose, reactive, ref, shallowRef, watch } from 'vue'
import { openAdminConfirm } from '@/components/admin-confirm'
import { showAdminFeedback } from '@/components/admin-feedback-ui'
import { batchResultMessage, runBatchDelete, togglePageSelection, type BatchDeleteResult } from './batch-delete'
type RowId = number | string
export function useRowSelection<Row, Id extends RowId>(options: {
pageRows: () => readonly Row[]
rowId: (row: Row) => Id
rowLabel: (row: Row) => string
deleteOne: (id: Id, row: Row, isCurrent: () => boolean) => Promise<unknown>
refresh: (result: BatchDeleteResult<Id>) => unknown
scope?: () => unknown
blocked?: () => boolean
precheck?: (row: Row) => string | undefined
consequence?: string
verb?: string
}) {
type Item = { id: Id; label: string; row: Row }
const selected = shallowRef(new Map<Id, Item>())
const busy = ref(false)
const progress = ref('')
const result = shallowRef<BatchDeleteResult<Id> | null>(null)
const disabled = computed(() => busy.value || Boolean(options.blocked?.()))
const pageItems = computed(() => options.pageRows().filter((row) => !options.precheck?.(row)).map(itemOf))
const pageAll = computed(() => pageItems.value.length > 0 && pageItems.value.every(({ id }) => selected.value.has(id)))
const pageSome = computed(() => !pageAll.value && pageItems.value.some(({ id }) => selected.value.has(id)))
const verb = options.verb ?? '删除'
let generation = 0
function itemOf(row: Row): Item {
return { id: options.rowId(row), label: options.rowLabel(row), row }
}
function clearSelection() {
generation++
selected.value = new Map()
result.value = null
}
if (options.scope) watch(options.scope, clearSelection, { flush: 'sync' })
onScopeDispose(clearSelection)
function removeFromSelection(id: Id) {
const next = new Map(selected.value)
next.delete(id)
selected.value = next
}
function toggle(row: Row) {
if (disabled.value || options.precheck?.(row)) return
selected.value = togglePageSelection(selected.value, [itemOf(row)])
}
function togglePage() {
if (disabled.value) return
selected.value = togglePageSelection(selected.value, pageItems.value)
}
async function submit() {
if (disabled.value || !selected.value.size) return
const current = generation
const isCurrent = () => current === generation
const items = [...selected.value.values()]
const names = items.slice(0, 3).map(({ label }) => label).join('、')
const sample = items.length > 3 ? `${names}等` : names
busy.value = true
try {
const confirmed = await openAdminConfirm({ danger: true,
title: `批量${verb}`,
confirmText: `确认${verb}`,
message: `确定${verb}选中的 ${items.length} 条记录(${sample})吗?${options.consequence ?? '此操作不可恢复。'}`,
})
if (!confirmed || !isCurrent() || options.blocked?.()) return
result.value = null
progress.value = `0/${items.length}`
const outcome = await runBatchDelete<Id, Item>({
rows: items,
precheck: ({ row }) => options.precheck?.(row),
deleteOne: ({ id, row }) => options.deleteOne(id, row, isCurrent),
isCurrent,
onProgress: (done) => { progress.value = `${done}/${items.length}` },
})
if (isCurrent()) {
const next = new Map(selected.value)
outcome.deleted.forEach((id) => next.delete(id))
selected.value = next
result.value = outcome.failures.length ? outcome : null
}
showAdminFeedback(batchResultMessage(outcome, verb, isCurrent() ? 3 : Infinity),
outcome.failures.length || outcome.remaining ? 'error' : 'success')
if (isCurrent() && (outcome.deleted.length || outcome.failures.length)) await options.refresh(outcome)
} finally {
busy.value = false
progress.value = ''
}
}
return reactive({
busy, disabled, progress, result, verb, pageAll, pageSome,
count: computed(() => selected.value.size),
pageEmpty: computed(() => !pageItems.value.length),
isSelected: (row: Row) => selected.value.has(options.rowId(row)),
reason: (row: Row) => options.precheck?.(row),
label: options.rowLabel,
toggle, togglePage, submit, clearSelection, removeFromSelection,
})
}
@@ -41,7 +41,7 @@ test('align_product_category_row_buttons_old_btn', () => {
})
test('align_product_category_no_indigo_left', () => {
const s = readSource('src/pages/asin/ProductCategoryPage.vue')
const s = readSource('src/pages/asin/ProductCategoryPage.vue', true)
assert.doesNotMatch(s, /#6366f1|#eef0fe|6366f1|eef0fe/, '靛蓝色点已清')
assert.match(s, /--admin-primary-soft/, '折叠钮改用蓝白主色 soft token')
})
@@ -63,7 +63,7 @@ test('align_dedupe_registry_row_buttons_old_btn', () => {
test('align_asin_actions_cell_spacing', () => {
// 反馈:查询ASIN操作按钮要有间距——asin-col-actions 统一 flex + gap 8px(对齐全站 ops-cell)。
for (const page of ['src/pages/asin/QueryAsinPage.vue', 'src/pages/asin/SkipPricePage.vue']) {
const s = readSource(page)
const s = readSource(page, true)
assert.match(s, /\.asin-col-actions\s*\{[^}]*gap:\s*8px/, `${page} 操作列按钮间距 8px`)
}
})
@@ -2,11 +2,12 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import {
eligibleGroupLeaders,
eligibleGroupMembers,
groupMemberCandidateHint,
} from '../src/pages/account/shop-group-model.ts'
/** 对齐 admin.js:3020-3028 getEligibleShopManageGroupUsers 与 3179-3182 帮助文案。 */
/** 对齐 admin.js:3020-3028 getEligibleShopManageGroupUsers 与 3179-3182 帮助文案;组长候选为 2026-11-18 新增口径。 */
const USERS = [
{ id: 1, username: '组长A', role: 'admin', createdById: null },
@@ -63,21 +64,47 @@ test('align_group_candidate_hint_empty_for_admin', () => {
})
test('align_group_editor_dialog_ui_wiring', () => {
// UI 接线:候选请求 page_size=999;新建时组长恒为当前登录用户(无改选下拉);候选/提示走新模型。
// UI 接线:候选请求 page_size=999;组长默认当前登录用户,新建+站点超管出改选下拉
// (2026-11-18 用户口径「新建分组组长要能下拉选」),编辑与非超管仍只读;候选/提示走新模型。
const dialog = readSource('src/pages/account/GroupEditorDialog.vue')
assert.match(dialog, /pageSize:\s*999/, '候选列表按参考 page_size=999 拉取')
assert.doesNotMatch(dialog, /组长(创建人)/, '新建弹窗不再提供组长改选下拉')
assert.match(dialog, /当前登录用户/, '新建时组长只读显示当前登录用户')
assert.match(dialog, /canPickLeader/, '组长下拉按「新建+站点超管」条件渲染')
assert.match(dialog, /v-if="canPickLeader"/, '下拉分支挂在 canPickLeader 上')
assert.match(dialog, /eligibleGroupLeaders/, '组长候选走 eligibleGroupLeaders 过滤')
assert.match(dialog, /v-else :model-value="leaderUsername" readonly/, '编辑与非超管新建仍走只读回显')
assert.match(dialog, /当前登录用户/, '只读回显保留当前登录用户兜底')
assert.match(dialog, /memberIds\.value\.filter/, '组长改选后把该人从组员里摘掉(后端拒绝组长重复入组)')
assert.match(dialog, /createShopGroup\(groupName\.value, memberIds\.value, leaderId/,
'创建提交 createdById=所选组长(站点超管改选通道,后端 validateLeaderOperator 放行)')
assert.match(dialog, /eligibleGroupMembers/, '组员候选走归属过滤')
assert.match(dialog, /groupMemberCandidateHint/, '候选提示文案走对齐逻辑')
assert.match(dialog, /companyId:\s*session\.user\?\.companyId \?\? null/,
'候选必须按组长(新建时=当前登录用户)那家取人:不带时后端对站点超管返回全平台账号,别家公司的人会进到这家的候选里')
'候选必须按操作者那家取人:组长必须与操作者同公司(后端 ensureLeaderSharesOperatorCompany),不带时站点超管会拿到全平台账号')
assert.doesNotMatch(dialog, /companyTab/, '分组候选不能按公司 tab 取人——超管停在别家 tab 时会列出那家的人,保存必被后端打回')
const page = readSource('src/pages/account/GroupsPage.vue')
assert.match(page, /创建时间/, '列表补创建时间列')
assert.doesNotMatch(page, /slice\(0,\s*10\)/, '组员 chips 全量渲染不再收 +N')
})
test('align_group_leader_candidates_site_super_keeps_self_drops_company_super', () => {
// 组长候选:公司超管永不领衔;站点超管只保留操作者本人(保持 admin 自建组的既有能力)。
const result = eligibleGroupLeaders(USERS, 'super_admin', 6)
assert.deepEqual(result.map((u) => u.id), [1, 2, 3, 4, 5, 6])
})
test('align_group_leader_candidates_non_super_operator_drops_all_supers', () => {
// 非站点超管操作者:两档超管全部出局(弹窗此时不出下拉,这里是同池复用方的兜底口径)。
const result = eligibleGroupLeaders(USERS, 'admin', 1)
assert.deepEqual(result.map((u) => u.id), [1, 2, 3, 4, 5])
})
test('align_group_leader_candidates_normal_accounts_can_lead', () => {
// 普通账号可领衔(既有文案背书:「当前账号只能作为组长使用」)。
const normals = USERS.filter((u) => u.role === 'normal')
const result = eligibleGroupLeaders(normals, 'super_admin', 6)
assert.deepEqual(result.map((u) => u.id), [2, 3, 4])
})
test('align_group_backend_gate_super_never_joins_and_leader_shares_company', () => {
// 界面收窄只是少踩一次;这两条 403 才是出口。锚在调用点与抛出语句,不锚注释。
const java = readSource(
@@ -31,7 +31,7 @@ test('align_invalid_asin_page_has_no_role_branch_left', () => {
assert.doesNotMatch(page, /isSuperAdmin/, '品牌库页又出现了角色分支:这一页的可见集不随操作者变')
assert.doesNotMatch(page, /useAdminSessionStore/, '同上:页面已经不需要知道操作者是谁')
assert.doesNotMatch(page, /lockedGroupId/i, '锁定分组的老模型回流了')
assert.doesNotMatch(page, /:disabled="/, '分组下拉又被禁用了:非站点超管也该能选任意分组(CSS 里的 :not(:disabled) 不算,只排绑定)')
assert.doesNotMatch(page, /<el-select\b[^>]*:disabled="/, '分组下拉又被禁用了:非站点超管也该能选任意分组(CSS 里的 :not(:disabled) 不算,只排绑定)')
})
test('align_invalid_asin_page_keeps_group_column_and_filter_for_everyone', () => {
@@ -84,4 +84,8 @@ test('align_menu_page_drag_and_type_wiring', () => {
assert.match(page, /menuSiblingGroupKey/, '拖拽分组按类型+父级')
assert.match(page, /MENU_TYPE_OPTIONS|菜单类型/, '新建/编辑弹窗含菜单类型下拉')
assert.match(page, /menuParentCandidates/, '父菜单候选按类型过滤')
assert.match(page, /filterMenuTreeNodesByPlatform/, '配置树必须先按当前平台裁剪,再展平分页')
assert.match(page, /platformTab\.active/, '配置树跟随当前平台')
assert.match(page, /walk\(visibleMenuTree\.value, 0\)/, '展平读取当前平台树,京东数据库不能被全量菜单分页挤走')
assert.match(page, /watch\(\(\) => platformTab\.active/, '切平台必须回第一页并清筛选')
})
@@ -21,7 +21,7 @@ test('el_message_above_custom_overlays', () => {
})
test('dedupe_overlay_and_warning_kept', () => {
const page = readSource('src/pages/asin/DedupeRegistryPage.vue')
const page = readSource('src/pages/asin/DedupeRegistryPage.vue', true)
assert.match(page, /\.modal-mask\s*\{[^}]*z-index:\s*3000/, '页内遮罩仍为 3000,消息 4000 需保持在其上')
assert.match(page, /\.dedupe-export-wait-mask\s*\{[^}]*z-index:\s*3100/, '导出等待遮罩 3100 同样低于消息 4000')
assert.match(page, /请选择数据权限分组|请选择分组/, '导入/编辑未选分组需保留警告岔口')
@@ -105,7 +105,7 @@ function categoryHeaderColumns(page: string): Array<{ label: string; px: number
const theadBlocks = page.match(/<thead>[\s\S]*?<\/thead>/g) ?? []
assert.equal(theadBlocks.length, 1, '类目页应只有一个 thead(本闸门按单个表头求列宽之和)')
const columns: Array<{ label: string; px: number | null }> = []
for (const cell of theadBlocks[0].matchAll(/<th\b[^>]*>([^<]*)<\/th>/g)) {
for (const cell of theadBlocks[0].matchAll(/<th(?=[\s>])[^>]*>([\s\S]*?)<\/th>/g)) {
const style = cell[0].match(/style="([^"]*)"/)?.[1] ?? ''
const px = /width:\s*(\d+)px/.exec(style)?.[1]
columns.push({ label: cell[1].trim(), px: px === undefined ? null : Number(px) })
@@ -120,14 +120,14 @@ function categoryTableMinWidth(page: string): number | null {
}
test('align_category_fixed_layout_never_leaves_a_column_to_be_squeezed', () => {
const page = readSource('src/pages/asin/ProductCategoryPage.vue')
const page = readSource('src/pages/asin/ProductCategoryPage.vue', true)
// 前提也要钉:这条闸门只在 fixed 布局下成立,改成 auto 布局时它该喊,而不是安静地继续绿。
// 窗口用 [^}] 而不是定长字符数:本页 CSS 注释里就写着 "table-layout:fixed 下……" 这句话,
// 定长窗口能跨过 } 把注释喂成"前提成立"(变异自证时实测过一次 SURVIVED)。
assert.match(page, /\.table-scroll\s+table\s*\{[^}]*table-layout:\s*fixed/, '本闸门的前提:表格是 table-layout:fixed')
const columns = categoryHeaderColumns(page)
assert.equal(columns.length, 8, `表头应有 8 列(与 <td colspan="8"> 对齐),实际 ${columns.length}:${JSON.stringify(columns)}`)
assert.equal(columns.length, 9, `表头应有 9 列(与 <td colspan="9"> 对齐),实际 ${columns.length}:${JSON.stringify(columns)}`)
const unwidthed = columns.filter((c) => c.px === null).map((c) => c.label)
assert.deepEqual(unwidthed, [], 'fixed 布局下没写宽度的列会在容器变窄时被第一个压到 0px:' + unwidthed.join('/'))
assert.equal(/width:\s*\d+%/.test(page.match(/<thead>[\s\S]*?<\/thead>/)?.[0] ?? ''), false,
@@ -137,7 +137,7 @@ test('align_category_fixed_layout_never_leaves_a_column_to_be_squeezed', () => {
const minWidth = categoryTableMinWidth(page)
assert.notEqual(minWidth, null, '.category-table-scroll > table 必须有 px 下限,否则塌缩区又合法了')
assert.ok((minWidth ?? 0) >= sum,
`min-width(${minWidth}px) 必须 >= 8 列宽度之和(${sum}px):否则表格落在 [min-width, 列宽和] 这一段时列被等比压缩`)
`min-width(${minWidth}px) 必须 >= 9 列宽度之和(${sum}px):否则表格落在 [min-width, 列宽和] 这一段时列被等比压缩`)
// 控制方圈出的那两列是这次的直接症状:它们是文字列,宽度下限给死,别被"重新调配比"顺手砍回去。
for (const label of ['层级路径', '备注']) {
@@ -7,7 +7,7 @@ import { readSource } from './helpers.ts'
const PAGE = 'src/pages/tasks/ShopDataTasksPage.vue'
test('align_shop_data_grid_normal_primary_path', () => {
const src = readSource(PAGE)
const src = readSource(PAGE, true)
assert.match(src, /grid-template-columns:\s*repeat\(4,\s*1fr\)/, '卡片容器应为 4 列宫格')
})
@@ -19,10 +19,10 @@ test('align_shop_data_grid_normal_variant_input', () => {
})
test('align_shop_data_grid_boundary_empty_input', () => {
// 卡片区下方有翻页组件(prev/next),与店铺分页并存(均为旧式分页)。
// 卡片分页与授权弹窗分页独立,不能用残留样式充当分页入口。
const src = readSource(PAGE)
const count = (src.match(/class="pagination"/g) || []).length + (src.match(/sd-shop-pager/g) || []).length
assert.ok(count >= 2, '页面应含店铺分页 + 卡片分页两处分页')
assert.match(src, /<OldPagination[^\n]*:page="cardPage"/, '卡片列表应有可操作的分页')
assert.match(src, /<OldPagination[^\n]*:page="permPage"/, '授权弹窗应有独立分页')
assert.match(src, /cardPage/, '卡片分页状态')
})
@@ -1,10 +1,10 @@
{
"note": "readSource 钉子逐文件基线。两把尺子:pins=落在用例体内的读盘,reads=全文读点总数(含模块级夹具与 helper)。都只许减;pins 下降而 reads 没同步下降=把读盘挪出体内,不算改进。由 tests/source-pin-ratchet.test.ts 生成。",
"totals": {
"files": 262,
"cases": 1832,
"pins": 460,
"reads": 658
"files": 264,
"cases": 1857,
"pins": 462,
"reads": 663
},
"files": {
"admin-scaffold.test.ts": {
@@ -58,7 +58,7 @@
"reads": 1
},
"align-group-editor.test.ts": {
"cases": 10,
"cases": 13,
"pins": 2,
"reads": 3
},
@@ -192,6 +192,11 @@
"pins": 0,
"reads": 0
},
"batch-delete.test.ts": {
"cases": 3,
"pins": 0,
"reads": 0
},
"brand-gating-model.test.ts": {
"cases": 5,
"pins": 0,
@@ -302,13 +307,13 @@
"pins": 1,
"reads": 1
},
"jd-category-cascader-position.test.ts": {
"cases": 4,
"pins": 0,
"reads": 0
"group-dropdown-platform-scope.test.ts": {
"cases": 2,
"pins": 2,
"reads": 5
},
"jd-category-tree.test.ts": {
"cases": 6,
"cases": 14,
"pins": 0,
"reads": 0
},
@@ -318,7 +323,7 @@
"reads": 0
},
"jd-product-group.test.ts": {
"cases": 7,
"cases": 10,
"pins": 0,
"reads": 0
},
@@ -398,7 +403,7 @@
"reads": 7
},
"platform-menu-filter.test.ts": {
"cases": 7,
"cases": 9,
"pins": 0,
"reads": 0
},
@@ -1302,6 +1307,11 @@
"pins": 2,
"reads": 2
},
"user-menu-tree-platform-filter.test.ts": {
"cases": 8,
"pins": 0,
"reads": 0
},
"user-notice-chinese-only.test.ts": {
"cases": 4,
"pins": 0,
@@ -0,0 +1,40 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { batchResultMessage, runBatchDelete, togglePageSelection } from '../src/utils/batch-delete.ts'
const rows = [{ id: 1, label: '甲' }, { id: 2, label: '乙' }, { id: 3, label: '丙' }]
test('表头只选择或取消当前页,同一业务行不重复选择', () => {
const selected = new Map([[1, rows[0]]])
const next = togglePageSelection(selected, [rows[1], rows[1], rows[2]])
assert.deepEqual([...next.keys()], [1, 2, 3])
assert.deepEqual([...togglePageSelection(next, rows.slice(1)).keys()], [1])
assert.deepEqual([...selected.keys()], [1])
})
test('逐条执行,失败不阻塞其他行,受保护行不发请求', async () => {
const calls: number[] = []
const result = await runBatchDelete({
rows: [...rows, { id: 4, label: '丁' }],
precheck: (row) => row.id === 2 ? '不能删除当前登录账号' : undefined,
deleteOne: async (row) => {
calls.push(row.id)
if (row.id === 3) throw new Error('分组下还有店铺')
},
})
assert.deepEqual(calls, [1, 3, 4])
assert.deepEqual(result.deleted, [1, 4])
assert.deepEqual(result.failures.map(({ id, reason }) => [id, reason]), [[2, '不能删除当前登录账号'], [3, '分组下还有店铺']])
assert.equal(batchResultMessage(result), '已删除 2 条,失败 2 条:乙(不能删除当前登录账号);丙(分组下还有店铺)')
})
test('范围失效后不再发下一条请求,未处理记录不计为失败或成功', async () => {
let current = true
const result = await runBatchDelete({
rows,
isCurrent: () => current,
deleteOne: async () => { current = false },
})
assert.deepEqual(result, { deleted: [1], failures: [], remaining: 2 })
assert.equal(batchResultMessage(result), '已删除 1 条,未处理 2 条')
})
@@ -98,7 +98,7 @@ const SEND_POINTS: ReadonlyArray<SendPoint> = [
{ menuKey: 'admin_task_center', file: 'src/pages/task-center/task-center-model.ts', fn: 'buildTaskQuery', line: TASK_CENTER_SEND_LINE, window: TASK_CENTER_WINDOW, title: '任务列表 query 构造器' },
{ menuKey: 'admin_task_center', file: 'src/pages/task-center/task-center-model.ts', fn: 'buildVariantQuery', line: TASK_CENTER_SEND_LINE, window: TASK_CENTER_WINDOW, title: '变体采集 query 构造器' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-total-api.ts', fn: 'fetchDedupeTotalList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 400, title: 'GET /dedupe-total-data 列表' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-total-api.ts', fn: 'fetchDedupeTotalGroups', line: 'http.get<unknown>(DEDUPE_GROUPS_ENDPOINT, { params: companyId != null ? { company_id: companyId } : {} })', window: 400, title: 'GET /shop-manages/groups 分组候选(与店铺管理同源,两页口径要对得上)' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-total-api.ts', fn: 'fetchDedupeTotalGroups', line: 'http.get<unknown>(DEDUPE_GROUPS_ENDPOINT, { params: { platform: \'amazon\', ...(companyId != null ? { company_id: companyId } : {}) } })', window: 400, title: 'GET /shop-manages/groups 分组候选(与店铺管理同源,两页口径要对得上;2026-11-22 用户口径「亚马逊的也是同理」——platform 恒 amazon,京东档组不进本下拉)' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-total-export.ts', fn: 'buildDedupeExportParams', line: 'if (companyId != null) params.company_id = String(companyId)', window: 800, title: 'GET /dedupe-total-data/export 导出' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-import-api.ts', fn: 'startDedupeImport', line: "if (companyId != null) form.append('company_id', String(companyId))", window: 400, title: 'POST /dedupe-total-data/import 新增导入(写侧归属,不发就落进操作者自己那一家)' },
{ menuKey: 'admin_dedupe_total_data', file: 'src/pages/asin/dedupe-import-api.ts', fn: 'startDedupeDeleteImport', line: "if (companyId != null) form.append('company_id', String(companyId))", window: 900, title: 'POST /dedupe-total-data/delete-import 删除导入(不发就会按别家的值删错行)' },
@@ -51,7 +51,7 @@ test('请求体:admin/normal 一律不带 companyId;公司超管必须带且
password: 'secret123',
role: 'normal',
columnIds: [3, 1],
// V206:所属平台恒下发(弹窗单选默认当前平台 tab,空表单缺省亚马逊)。
// V206:所属平台恒下发(预填当前平台 tab,空表单缺省亚马逊;弹窗不设手选)。
platform: 'amazon',
})
// 所属管理员仍按原语义携带(仅 normal 角色)
@@ -89,11 +89,11 @@ test('账号页与顶栏的源码里公司维度已摘干净', () => {
// 「删了列忘了改占位行 colspan」是这类改动最常留下的残行:按表头列数交叉核对
// (`<th` 是 `<thead` 的前缀,必须带上后随字符才数得准)。
// 2026-11-17 V206:上架上限列 v-if="isJdSide" 按平台动态渲染 ⇒ 表头数 10(含源码里的 v-if th),
// 2026-11-17 V206:上架上限列 v-if="isJdSide" 按平台动态渲染 ⇒ 加上批量选择后表头数 11(含源码里的 v-if th),
// 占位行走 :colspan 动态绑定;字面量 colspan 在动态列下必然错位一半的 tab,反向钉死。
const headers = (page.match(/<th[\s>]/g) || []).length
assert.equal(headers, 10, `用户列表表头应为 10 列(9 列存量 + 京东侧上架上限 v-if 列),实际 ${headers}`)
assert.match(page, /:colspan="isJdSide \? 10 : 9"/, '空态占位行必须按平台动态切 colspan(静态值与动态列数错位一半 tab)')
assert.equal(headers, 11, `用户列表表头应为 11 列(9 列存量 + 批量选择 + 京东侧上架上限 v-if 列),实际 ${headers}`)
assert.match(page, /:colspan="isJdSide \? 11 : 10"/, '空态占位行必须按平台动态切 colspan(静态值与动态列数错位一半 tab)')
assert.equal(/colspan="\d+"/.test(page), false, '动态列下不许再留字面量 colspan(必有一侧 tab 列数对不上)')
const dialog = readSource('src/pages/account/CreateUserDialog.vue')
@@ -110,7 +110,7 @@ test('不许用客户端猜测禁用行内入口:那会误伤真能改的行',
const src = readSource(PAGE)
const opsCell = /<td class="ops-cell">[\s\S]*?<\/td>/.exec(src)
assert.ok(opsCell, '行内操作列结构变了:这条判据要重写')
assert.equal(/:disabled=|v-if=/.test(opsCell[0]), false,
assert.equal(/:disabled=|v-if=/.test(opsCell[0].replace(':disabled="batch.busy"', '')), false,
'行内编辑/删除上加了客户端权限闸——但前端拿不到后端写侧的 companyGroupIds,'
+ '按分组下拉收窄会把同事名下"看得见也改得动"的行一起禁掉(静默删功能)。'
+ '要收窄请先让后端在列表响应里下发可写标志(先例:用户菜单授权树的 grantable)。')
@@ -0,0 +1,41 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
/**
* 分组下拉按平台归属过滤(2026-11-22 用户口径「京东创建的分组就归属京东,
* 下拉就只能显示京东分组管理的,亚马逊的也是同理」)。
*
* 背景:biz_shop_manage_group 一张表服务两侧(platform 列 V206 起 amazon|jd),
* 京东侧(JdCategoryScopeService + /api/jd-collect/groups)已有 platform='jd' 闸;
* 亚马逊侧四个页面(查询ASIN/跟价/去重/外观专利清理)共用的两个取数口原本不传
* platform ⇒ 京东档分组(如「京东-团队」「测试1111」)漏进亚马逊侧下拉。
* 两支源码钉守住发送口形状:platform 恒 'amazon' 且 company_id 条件透传不丢。
*/
test('amazon_group_dropdowns_send_platform_amazon_and_keep_company_id_passthrough', () => {
const dedupe = readSource('src/pages/asin/dedupe-total-api.ts')
assert.match(dedupe, /DEDUPE_GROUPS_ENDPOINT, \{ params: \{ platform: 'amazon', \.\.\.\(companyId != null \? \{ company_id: companyId \} : \{\}\) \} \}/,
'去重/外观专利清理页的分组候选必须恒带 platform=amazon(京东档组不进亚马逊侧下拉)')
assert.match(dedupe, /export async function fetchDedupeTotalGroups\(companyId\?: number \| null\)/,
'签名不变:company_id 仍由调用方(公司 tab)传入')
const shopManage = readSource('src/pages/shop/shop-manage-api.ts')
assert.match(shopManage, /SHOP_MANAGE_GROUPS_ENDPOINT, \{ params: \{ platform: 'amazon', \.\.\.\(companyId != null \? \{ company_id: companyId \} : \{\}\) \} \}/,
'店铺/查询ASIN/跟价页的分组下拉必须恒带 platform=amazon')
assert.match(shopManage, /export async function fetchShopManageGroups\(companyId\?: number \| null\)/,
'签名不变:company_id 仍由调用方(公司 tab)传入')
})
test('group_manage_page_keeps_following_platform_tab_not_hardcoded', () => {
// 分组管理页本身是双侧页面,继续跟当前平台 tab 走——不许被这批「亚马逊域恒 amazon」
// 顺手改死,否则京东 tab 的分组列表会被清空(2026-11-17 平台闸既有口径)。
const groupsPage = readSource('src/pages/account/GroupsPage.vue')
assert.match(groupsPage, /fetchShopGroups\(companyTab\.requestCompanyId, platformTab\.active\)/,
'分组管理页取数仍按当前平台 tab 过滤')
// 反向钉:两个亚马逊域取数口里不许出现 platformTab(它们不该感知平台 tab)。
const dedupe = readSource('src/pages/asin/dedupe-total-api.ts')
const shopManage = readSource('src/pages/shop/shop-manage-api.ts')
assert.equal(/platformTab/.test(dedupe), false, '去重取数口不感知平台 tab(恒 amazon)')
assert.equal(/platformTab/.test(shopManage), false, '店铺取数口不感知平台 tab(恒 amazon)')
})
+6 -2
View File
@@ -15,8 +15,12 @@ const INDEX_CANDIDATES = ['/index.ts', '/index.tsx', '/index.vue', '/index.js']
* (内容逐字节等价,主树 LF 3565 B / 新检出 CRLF 3629 B)在干净检出树上会多红一条与本任务无关的用例。
* 归一之后判据只取决于内容,不取决于在哪台机器、哪个 worktree 里跑。
*/
export function readSource(rel: string): string {
return readFileSync(join(ROOT, rel), 'utf8').replace(/\r\n/g, '\n')
export function readSource(rel: string, includeVueStyles = false): string {
const source = readFileSync(join(ROOT, rel), 'utf8').replace(/\r\n/g, '\n')
if (!includeVueStyles) return source
const styles = [...source.matchAll(/<style\b[^>]*\bsrc="(\.\/[^"\n]+\.css)"[^>]*>/g)]
.map(([, path]) => readSource(join(dirname(rel), path)))
return [source, ...styles].join('\n')
}
/** 统计非重叠子串出现次数(幂等、只读)。 */
@@ -1,37 +0,0 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { clampPanelLeftX } from '../src/pages/jd/jd-category-cascader-position.ts'
/** 类目面板水平钳制(2026-11-16 客户截图「超出视窗了」回归判据):面板锚 left:0 最宽
* 4 栏 ×200px,触发框落在筛选行中部偏右时面板伸出视窗右缘。判据形状统一=「右缘装
* 不下必须左移、左移过头贴左缘、装得下不动」三种写法一格定红;把组件改回无条件锚左
* 即红(JdCategoryCascader.vue 的 reposition 必须经本函数算偏移)。 */
test('视口装得下=不偏移(默认锚左)', () => {
// 宽视口:触发框在 x=300,4 栏 800px,右缘 1100 < 1920-8。
assert.equal(clampPanelLeftX({ hostLeft: 300, panelWidth: 800, viewportWidth: 1920 }), 0)
// 恰好贴齐:右缘正好压在 viewport-margin 上=零偏移(≤0 分支)。
assert.equal(clampPanelLeftX({ hostLeft: 300, panelWidth: 800, viewportWidth: 1108 }), 0)
})
test('右缘越界=整体左移到右缘贴齐(客户截图形状:末栏被窗缘裁掉)', () => {
// 截图形状:触发框 x=250、3 栏 600px、窗宽 830 ⇒ 右缘 850 越界 28px ⇒ 左移 28。
assert.equal(clampPanelLeftX({ hostLeft: 250, panelWidth: 600, viewportWidth: 830 }), -28)
// 宽视口下钻到 4 栈仍越界(触发框靠右):1920 窗、触发框 x=1200、800px 面板。
assert.equal(clampPanelLeftX({ hostLeft: 1200, panelWidth: 800, viewportWidth: 1920 }), -88)
})
test('越界过头不得把面板推出左缘=钳在 margin', () => {
// 窄窗:触发框 x=100、面板 800、窗宽 830 ⇒ 直移要 -78,但那样左缘到 22>8 可行;
// 极端:触发框 x=4、面板 800、窗宽 500 ⇒ 直移 -312 ⇒ 左缘 -308 越左,钳到 margin=8。
assert.equal(clampPanelLeftX({ hostLeft: 4, panelWidth: 800, viewportWidth: 500, margin: 8 }), 4)
// 钳制后面板左缘=margin:偏移=margin-hostLeft。
assert.equal(clampPanelLeftX({ hostLeft: 2, panelWidth: 600, viewportWidth: 400, margin: 8 }), 6)
})
test('窄窗越界:直移后左缘仍够留白就正常左移;不够则钳在 margin(物理极限,不假装能塞下)', () => {
// 窗宽 400、margin 8:面板 380 ⇒ 直移 -138 后左缘 12 ≥ 8 可行;
// 面板 390 ⇒ 直移后左缘 2 < 8 ⇒ 钳到左缘 8(偏移 -142),右侧溢出是物理极限。
assert.equal(clampPanelLeftX({ hostLeft: 150, panelWidth: 380, viewportWidth: 400, margin: 8 }), -138)
assert.equal(clampPanelLeftX({ hostLeft: 150, panelWidth: 390, viewportWidth: 400, margin: 8 }), -142)
})
@@ -2,10 +2,15 @@ import { test } from 'node:test'
import assert from 'node:assert/strict'
import {
JD_CATEGORY_TREE,
jdCategoryAllNodes,
jdCategoryChildren,
jdCategoryCountTree,
jdCategoryLeaves,
jdCategoryNamesUnder,
jdCategoryRoots,
jdCategorySearchLeaves,
jdCategorySearchNodes,
type JdCategoryCountedNode,
} from '../src/pages/jd/jd-category-tree.ts'
/** 京麦授权类目真树(2026-11-16 真机取证 getVenderLicenseCategory 快照;与用户端
@@ -95,3 +100,166 @@ test('树数据快照不可空、value 全非空(取证 id 留档完整)', (
assert.ok(leaf.value, `叶子 ${leaf.name} 必须带京麦类目 id`)
}
})
/** 2026-11-18 客户口径「一级/二级类目也要能选来搜索」:全层级节点+子树展开集合。 */
test('全节点搜索:一级/二级/末级都在结果里,leaf 标记如实', () => {
assert.equal(jdCategorySearchNodes('').length, jdCategoryAllNodes().length, '空词=全量节点')
assert.ok(jdCategoryAllNodes().length > 250, '全节点数必须大于末级 250(含非末级)')
const byName = jdCategorySearchNodes('女装')
const women = byName.find((node) => node.name === '女装')
assert.ok(women, '「女装」这个二级节点必须可搜到(旧版只铺末级,选不了它)')
assert.equal(women!.leaf, false, '女装有子级=非末级')
assert.deepEqual(women!.path, ['服饰内衣', '女装'], '路径从一级起(同名跨支靠它区分)')
assert.ok(byName.some((node) => node.leaf), '末级命中照旧在')
})
test('子树展开集合:含自身+全部后代名、去重、不越支;路径失效回 null', () => {
const dress = jdCategoryNamesUnder(['服饰内衣', '女装', '连衣裙'])
assert.ok(dress, '连衣裙路径有效')
assert.ok(dress!.includes('连衣裙'), '含节点自身名(实际末级可能就在这一级)')
assert.ok(dress!.includes('短袖连衣裙') && dress!.includes('长袖连衣裙') && dress!.includes('无袖连衣裙'))
assert.ok(!dress!.includes('女装'), '只展开本节点子树,不带上父级')
const top = jdCategoryNamesUnder(['运动户外'])
assert.ok(top!.includes('艺考形体服') && top!.includes('啦啦队服'), '一级展开覆盖全支')
assert.ok(!top!.includes('女装'), '不越支')
const hanfu = jdCategoryNamesUnder(['服饰内衣', '女装', '汉服'])
assert.ok(hanfu!.includes('汉服') && hanfu!.includes('汉服套装'), '非叶「汉服」展开含四级')
assert.equal(jdCategoryNamesUnder(['不存在', '的路径']), null, '路径失效回 null(调用方按单名兜底)')
assert.equal(jdCategoryNamesUnder([]), null, '空路径回 null')
// 去重:同名跨支在**同一子树内**出现两次时集合不重复(唐装/短裤等在女装支内只有一个)。
const women = jdCategoryNamesUnder(['服饰内衣', '女装'])!
assert.equal(new Set(women).size, women.length, '展开集合内部去重')
})
/** v1.6 蓝图 Phase 1 备料:/categories 计数行 → 树形计数聚合(侧栏徽标的数据源)。 */
/** 按名称路径取计数节点(与 jdCategoryChildren 同构的测试侧寻路)。 */
const nodeAt = (roots: JdCategoryCountedNode[], path: string[]): JdCategoryCountedNode | null => {
let level = roots
let hit: JdCategoryCountedNode | null = null
for (const name of path) {
hit = level.find((node) => node.name === name) ?? null
if (!hit) return null
level = hit.children
}
return hit
}
test('计数聚合——节点徽标=自身名+子树叶和,与 jdCategoryNamesUnder 展开集合同源', () => {
const tree = jdCategoryCountTree([
{ name: '艺考形体服', productCount: 5 },
{ name: '啦啦队服', productCount: 3 },
{ name: '拉丁舞服', productCount: 2 },
{ name: '连衣裙', productCount: 7 },
{ name: '短袖连衣裙', productCount: 4 },
])
assert.equal(tree.extra.length, 0, '树内名字不进兜底组')
assert.equal(tree.extraTotal, 0)
const roots = tree.roots
assert.equal(roots.length, 3, '一级节点全量保留(无词条的一级也在)')
assert.deepEqual(
roots.map((node) => node.name),
['服饰内衣', '母婴', '运动户外'],
)
assert.equal(roots.find((node) => node.name === '母婴')!.count, 0, '无词条的一级归 0 不缺节点')
const sport = nodeAt(roots, ['运动户外'])!
assert.equal(sport.count, 10, '运动户外=艺考5+啦啦3+拉丁2')
assert.equal(sport.leaf, false)
const dance = nodeAt(roots, ['运动户外', '舞蹈体操鞋服/装备'])!
assert.equal(dance.count, 10, '二级下钻同和')
const yikao = nodeAt(roots, ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'])!
assert.equal(yikao.count, 5, '末级叶子=该名计数')
assert.equal(yikao.leaf, true, 'children 空=末级')
assert.deepEqual(yikao.children, [], '叶子 children 是空数组(UI 直接遍历不炸)')
const dress = nodeAt(roots, ['服饰内衣', '女装', '连衣裙'])!
assert.equal(dress.count, 11, '连衣裙=自身名7+短袖4(长袖/无袖无词条归 0)')
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 11, '女装只有连衣裙支有词条')
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 11, '一级汇总到根')
const dressLeaves = nodeAt(roots, ['服饰内衣', '女装', '连衣裙'])!.children.map((node) => node.name)
assert.deepEqual(dressLeaves, ['短袖连衣裙', '长袖连衣裙', '无袖连衣裙'], '子节点形状与静态树逐字同')
})
test('计数聚合——父级名本身是落库末级名:计入自身节点(快照层级可能比实际浅)', () => {
const tree = jdCategoryCountTree([
{ name: '女装', productCount: 6 },
{ name: '短袖连衣裙', productCount: 1 },
])
const roots = tree.roots
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 7, '女装徽标=自身6+子树1')
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 7)
assert.equal(tree.extra.length, 0, '非叶名也是合法落库名,不进兜底组')
})
test('计数聚合——同名跨支叶:两个分支都计入(点哪支都等值命中同一批行),父层去重不翻倍', () => {
const tree = jdCategoryCountTree([{ name: '短裤', productCount: 9 }])
const roots = tree.roots
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 9, '女装支的短裤叶如实计入')
assert.equal(nodeAt(roots, ['服饰内衣', '男装'])!.count, 9, '男装支的同名叶同计数(过滤语义非双计)')
assert.equal(roots.find((node) => node.name === '服饰内衣')!.count, 9,
'父层子树按名字去重求和:展开集合里短裤只出现一次,徽标不得翻倍成 18')
assert.equal(tree.extra.length, 0)
})
test('计数聚合——树外兜底组:树上任何节点名都对不上的历史行单独归组', () => {
const tree = jdCategoryCountTree([
{ name: '已下架历史类目', productCount: 12 },
{ name: '另一个树外名', productCount: 8 },
{ name: '艺考形体服', productCount: 5 },
])
assert.deepEqual(
tree.extra.map((row) => row.name),
['已下架历史类目', '另一个树外名'],
'兜底组按入参顺序保留',
)
assert.deepEqual(
tree.extra.map((row) => row.productCount),
[12, 8],
)
assert.equal(tree.extraTotal, 20, '兜底组和=徽标直接用')
const sport = nodeAt(tree.roots, ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'])!
assert.equal(sport.count, 5, '树内行照常聚合,兜底不影响树形')
})
test('计数聚合——脏值归一:空名跳过、非有限/负数归 0、前后空白截掉、同名多行求和', () => {
const tree = jdCategoryCountTree([
{ name: '', productCount: 5 },
{ name: ' ', productCount: 7 },
{ name: '短裤', productCount: Number.NaN },
{ name: '唐装', productCount: -3 },
{ name: ' 女装 ', productCount: 2 },
{ name: '女装', productCount: 3 },
{ name: '艺考形体服', productCount: '4' as unknown as number },
] as { name: string; productCount: number }[])
const roots = tree.roots
assert.equal(nodeAt(roots, ['服饰内衣', '女装'])!.count, 5, 'trim 后同名求和 2+3')
assert.equal(nodeAt(roots, ['服饰内衣', '男装'])!.count, 0, 'NaN/负数/空名都归 0 不记账')
assert.equal(tree.extra.length, 0, '空名词条不进兜底组')
assert.equal(tree.extraTotal, 0)
})
test('计数聚合——空输入:全树 0、兜底组空(结构仍完整可渲染)', () => {
const tree = jdCategoryCountTree([])
assert.equal(tree.roots.length, 3)
assert.equal(tree.extra.length, 0)
assert.equal(tree.extraTotal, 0)
const total = tree.roots.reduce((sum, node) => sum + node.count, 0)
assert.equal(total, 0)
// 结构与静态树同形:一级孩子数与 jdCategoryChildren 逐一对齐。
for (const root of tree.roots) {
assert.deepEqual(
root.children.map((node) => node.name),
jdCategoryChildren([root.name]).map((node) => node.name),
)
}
// 非数组入参按空处理(运行期 resilience,JS 调用方传 null 不炸)。
const junk = jdCategoryCountTree(null as unknown as [])
assert.equal(junk.roots.length, 3)
assert.equal(junk.extraTotal, 0)
})
@@ -97,17 +97,30 @@ test('列表行价格:BigDecimal 的 JSON number 形状与字符串形状都
assert.equal(jdPriceRange(missing), '', '两侧都空回空串(列表显示 -)')
})
/** 类目筛选(2026-11-15):京麦末级类目等值过滤,空串不下发、非空透传 category。 */
test('类目筛选参数序列化:空串不下发、非空下发 category(等值过滤)', async () => {
/** 类目筛选(2026-11-15 末级等值;2026-11-18 一级/二级可选中=子树展开集合 IN):
* 空串不下发;无路径=单元素集合(等值旧形状);带路径=jdCategoryNamesUnder 展开。 */
test('类目筛选参数序列化:空串不下发、末级单值、父级展开子树集合', async () => {
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
await import('../src/pages/jd/jd-product-filter.ts')
const empty = createJdProductFilterState()
assert.equal('category' in toJdProductListParams(empty, 1, 20), false, '全部类目不下发 category')
assert.equal(jdProductFilterActive(empty), false)
const filtered = { ...empty, category: ' 服饰内衣 ' }
assert.equal(toJdProductListParams(filtered, 1, 20).category, '服饰内衣', '去空白透传(等值过滤)')
assert.equal(jdProductFilterActive(filtered), true, '选中类目算激活筛选')
const leaf = { ...empty, category: ' 艺考形体服 ' }
assert.deepEqual(toJdProductListParams(leaf, 1, 20).category, ['艺考形体服'],
'无路径=去空白单元素集合(等值旧形状,后端 IN 单值等价)')
assert.equal(jdProductFilterActive(leaf), true, '选中类目算激活筛选')
const parent = { ...empty, category: '女装', categoryPath: ['服饰内衣', '女装'] }
const expanded = toJdProductListParams(parent, 1, 20).category as string[]
assert.ok(Array.isArray(expanded) && expanded.length > 20, '一级/二级选中=子树展开集合')
assert.ok(expanded.includes('女装'), '集合含节点自身名(实际末级可能就在这一级)')
assert.ok(expanded.includes('连衣裙') && expanded.includes('短袖连衣裙'), '含后代各级名')
assert.ok(!expanded.includes('艺考形体服'), '不越出子树(艺考形体服在运动户外支)')
const stale = { ...empty, category: '已下架历史类目', categoryPath: ['不存在', '的路径'] }
assert.deepEqual(toJdProductListParams(stale, 1, 20).category, ['已下架历史类目'],
'路径失效(树外历史名)回落单名等值,不静默丢筛选')
})
test('自定义分类使用 group_id,不发送分类状态参数', async () => {
+130 -34
View File
@@ -1,16 +1,20 @@
/**
* 京东数据库页纯逻辑契约(v1.4 Phase 5)—— node --test 直跑(纯函数零依赖)。
* 京东数据库页纯逻辑契约(v1.4 Phase 5 → v1.7 对齐原型《商品数据商城》)——
* node --test 直跑(纯函数零依赖)。
*
* 不用 readFileSync/readSource/globSync 读点:source-pin-ratchet 对台账外新文件带读点即红,
* 本文件只 import 被测纯函数。
*
* 覆盖:
* 1. **snake 参数形状**:toJdProductListParams 产出 `page`/`page_size`(默认 20、上限 100)、
* `product_code`/`title_keyword`/`group_id`/`owner_group_id`/`synced_from`/`synced_to`
* (ISO yyyy-MM-dd;空白不下发;groupId 空串→不带、有值→snake group_id;ownerGroupId>0 才带、
* 0/null/NaN 一律不带=后端按作用域默认分组取,V203);分页钳制(铁律 15)。
* 商品状态筛选与导出参数口已随 2026-11-15 客户口径下线,不再出现在参数面;
* 店铺筛选同日客户口径「店铺不需要」下线(shop_name 也不在参数面)。
* 1. **snake 参数形状**:toJdProductListParams 产出 `page`/`page_size`(默认 50、上限 1000、
* 档位 50/100/200/500/1000〔v1.7 对齐原型,上限与后端 JdProductQueryService.MAX_PAGE_SIZE
* 逐字同步〕)、`keyword`(v1.7 合并搜索:商品编码 OR 标题,OR 语义在后端 SQL)、
* `shop_name`(v1.7 店铺名单点选,精确 eq)、`min_price`/`max_price`(v1.7 价格区间)、
* `group_id`/`owner_group_id`/`synced_from`/`synced_to`(ISO yyyy-MM-dd;空白/非法不下发;
* groupId 空串→不带、有值→snake group_id;ownerGroupId>0 才带、0/null/NaN 一律不带=
* 后端按作用域默认分组取,V203);分页钳制(铁律 15)。
* 旧 `product_code`/`title_keyword` 两参数 v1.7 起前端停发(合并进 keyword;后端参数
* 保留兼容在飞请求);商品状态筛选与 json/txt 导出参数口仍随 2026-11-15 客户口径下线。
* 2. **详情解析**:parseJdProductDetail 解析 attrGroups/images(camel 为正 snake 容错、缺 url 弃行),
* attrGroups 解析不出时 attrJsonRaw 原文兜底;列表行解析缺 id 弃行。
*
@@ -20,8 +24,14 @@ import { test } from 'node:test'
import assert from 'node:assert/strict'
import {
JD_OWNERSHIP_CATEGORY_PREFIX,
JD_PRODUCT_MAX_PAGE,
JD_PRODUCT_MAX_PAGE_SIZE,
JD_PRODUCT_PAGE_SIZE,
JD_PRODUCT_PAGE_SIZE_OPTIONS,
applyJdOwnershipSelection,
createJdProductFilterState,
jdOwnershipSelectValue,
toJdProductListParams,
} from '../src/pages/jd/jd-product-filter.ts'
import {
@@ -29,6 +39,7 @@ import {
jdCategoryRoots,
} from '../src/pages/jd/jd-category-tree.ts'
import {
JD_PRODUCT_DEFAULT_SIZE,
jdPriceRange,
parseJdProductDetail,
parseJdProductPage,
@@ -49,11 +60,13 @@ test('类目级联静态导航树——服饰内衣二级与京麦面板样本
}
})
test('京东列表参数——snake 形状:groupId 空→不带、有值→group_id,日期空白/非法不下发', () => {
test('京东列表参数——snake 形状:keyword/店铺/价格下发,旧编码标题两框停发、日期空白/非法不下发', () => {
const full = toJdProductListParams(
{
productCode: ' JD-10086 ',
titleKeyword: ' 保温杯 ',
keyword: ' 保温杯 ',
shopName: ' 绿屿街道店 ',
minPrice: ' 100 ',
maxPrice: 'abc',
groupId: ' 7 ',
syncedFrom: '2026-11-01',
syncedTo: '2026-11-09',
@@ -66,29 +79,44 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
assert.deepEqual(full, {
page: 2,
page_size: 20,
product_code: 'JD-10086',
title_keyword: '保温杯',
keyword: '保温杯',
shop_name: '绿屿街道店',
min_price: 100,
group_id: 7,
owner_group_id: 11,
synced_from: '2026-11-01',
synced_to: '2026-11-09',
})
assert.equal('shop_name' in full, false, '店铺筛选已下线,参数面不再出现 shop_name')
}, 'keyword/店铺 trim 后下发;非法价格(abc)不下发,合法价格转 number')
// 旧两框 v1.7 起前端停发(合并进 keyword):参数面不再出现(后端参数保留兼容在飞请求)。
assert.equal('product_code' in full, false, 'product_code 前端停发(合并搜索替代)')
assert.equal('title_keyword' in full, false, 'title_keyword 前端停发(合并搜索替代)')
assert.equal('sale_status' in full, false, '商品状态筛选已下线,参数面不再出现 sale_status')
// 出厂态=分页两项+默认未分类档(classified:false,2026-11-17 用户口径「默认卡在未分类上就行」);
// 脏值(非数字分组、非法日期)同罪不下发。
// 出厂态=分页两项、不带 classified(2026-11-21 用户口径「默认改成全部」——全部档
// 序列化不带 classified 参数=后端跳过谓词查全量);
// 脏值(非数字分组、非法日期、非法价格)同罪不下发。
const blank = toJdProductListParams(createJdProductFilterState(), 1, 20)
assert.deepEqual(blank, { page: 1, page_size: 20, classified: false },
'出厂默认必须带 classified:false——首屏就卡未分类,不是全量')
assert.deepEqual(blank, { page: 1, page_size: 20 },
'出厂默认不带 classified 键——首屏查全量(默认全部档),不再卡未分类')
assert.equal('group_id' in blank, false, 'groupId 空串不带 group_id')
assert.equal('owner_group_id' in blank, false, '没传当前分组就不带 owner_group_id(后端按作用域默认组取)')
const dirty = toJdProductListParams(
{ productCode: '', titleKeyword: '', groupId: 'abc', syncedFrom: '2026/11/01', syncedTo: 'not-a-date' },
{ ...createJdProductFilterState(), groupId: 'abc', syncedFrom: '2026/11/01', syncedTo: 'not-a-date', minPrice: 'abc', maxPrice: ' ' },
1,
20,
)
assert.deepEqual(dirty, { page: 1, page_size: 20 }, '脏值不下发')
assert.equal('sale_status' in full, false, '商品状态筛选已下线,参数面不再出现 sale_status')
assert.deepEqual(dirty, { page: 1, page_size: 20 },
'脏值(分组/日期/价格)不下发;出厂态查全量(默认全部档)')
// 价格区间(v1.7 F2):合法上下限转 number 下发(后端 price_min >= X AND price_max <= Y)。
const priced = toJdProductListParams(
{ ...createJdProductFilterState(), minPrice: ' 100.5 ', maxPrice: '200' },
1,
20,
)
assert.deepEqual({ min_price: priced.min_price, max_price: priced.max_price }, { min_price: 100.5, max_price: 200 },
'价格区间合法值转 number 下发(字符串不发给后端 BigDecimal)')
// 当前分组非法值(0/NaN/null)一律不下发:0 是「不属于任何组」的哨兵,不能当组 id 发出去。
for (const bad of [0, null, undefined, Number.NaN]) {
assert.equal('owner_group_id' in toJdProductListParams(createJdProductFilterState(), 1, 20, bad), false,
@@ -99,36 +127,104 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
test('京东列表参数——page 钳制防 (page-1)*page_size 溢出(铁律 15)', () => {
const low = toJdProductListParams(createJdProductFilterState(), 0, 0)
assert.equal(low.page, 1, 'page<1 归 1')
assert.equal(low.page_size, 20, 'page_size 非法回默认 20')
const big = toJdProductListParams(createJdProductFilterState(), 3, 500)
assert.equal(big.page_size, 100, 'page_size 上限 100')
assert.equal(low.page_size, 50, 'page_size 非法回默认 50(v1.6 新契约)')
const big = toJdProductListParams(createJdProductFilterState(), 3, 5000)
assert.equal(big.page_size, 1000, 'page_size 上限 1000(v1.7 对齐原型档位放宽)')
const extreme = toJdProductListParams(createJdProductFilterState(), Number.MAX_SAFE_INTEGER, 100)
const extreme = toJdProductListParams(createJdProductFilterState(), Number.MAX_SAFE_INTEGER, 1000)
assert.equal(extreme.page, JD_PRODUCT_MAX_PAGE)
const offset = (extreme.page - 1) * extreme.page_size
assert.equal(Number.isSafeInteger(offset), true, `(page-1)*page_size=${offset} 必须留在安全整数域`)
assert.equal(offset, 999_900)
assert.equal(offset, 9_999_000, '10_000 页 × 1000 条仍在 Number.MAX_SAFE_INTEGER 内')
})
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」,同日收敛
* 「不需要全部分类 默认卡在未分类上就行」):界面两档,'classified'→true、'ungrouped'→false;
* 出厂默认与「重置」都卡 ungrouped。''/缺省/脏值=「全部」仍是序列化出口的兜底语义
* (不拿脏值冒充档位),但界面不再提供这一档。
/** v1.7 契约:首屏默认 50、档位 50/100/200/500/1000、上限 1000;model 侧默认与 filter 侧
* 同值不漂(页面装配层挂常量,两处字面量从此只剩常量出处;上限与后端
* JdProductQueryService.MAX_PAGE_SIZE 逐字同步——契约测试两侧钉着这个数)。 */
test('分页档位——默认 50、档位 50/100/200/500/1000、上限 1000(v1.7 对齐原型)', () => {
assert.deepEqual([...JD_PRODUCT_PAGE_SIZE_OPTIONS], [50, 100, 200, 500, 1000], '档位清单逐字同(v1.7 新契约)')
assert.ok(JD_PRODUCT_PAGE_SIZE_OPTIONS.includes(JD_PRODUCT_PAGE_SIZE), '默认值必须是档位之一')
assert.equal(JD_PRODUCT_PAGE_SIZE, 50, '默认档 50(v1.6 拍板放宽,v1.4 §3.4 的 20 已废)')
assert.equal(JD_PRODUCT_DEFAULT_SIZE, JD_PRODUCT_PAGE_SIZE, 'model 侧默认与 filter 侧同值')
assert.equal(JD_PRODUCT_MAX_PAGE_SIZE, 1000, '上限 1000(v1.7 对齐原型,与后端 MAX_PAGE_SIZE 逐字同步)')
})
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」;2026-11-18「加个全部
* 选项」恢复全量档;**2026-11-21 用户口径「默认改成全部」=出厂默认改卡 ''**,推翻
* 11-17「默认卡未分类」):界面三档,'classified'→true、'ungrouped'→false、
* ''(全部)→ 不带 classified 参数;出厂默认与「重置」都卡 ''(全部)。
* 缺省/脏值同走「全部」兜底(不拿脏值冒充档位)。
* 参数名是新档 classified——不是后端仍拒收的旧 grouped/ungrouped 查询参数。 */
test('京东列表参数——classified 默认卡未分类:已分类→true、未分类→false、脏值兜底不下发', () => {
test('京东列表参数——classified 默认全部:已分类→true、未分类→false、脏值兜底不下发', () => {
const yes = toJdProductListParams({ ...createJdProductFilterState(), classified: 'classified' }, 1, 20, 11)
assert.equal(yes.classified, true)
assert.equal(yes.owner_group_id, 11, 'classified 与当前分组成对下发(后端按组判已/未分类)')
assert.equal(createJdProductFilterState().classified, 'ungrouped',
'出厂态与重置都必须卡未分类档(用户口径:默认卡在未分类上)')
const no = toJdProductListParams({ ...createJdProductFilterState(), classified: 'ungrouped' }, 1, 20, 11)
assert.equal(no.classified, false, '未分类档显式选档仍下发 classified:false')
for (const blank of ['', undefined, 'grouped', 'nonsense'] as const) {
assert.equal(createJdProductFilterState().classified, '',
'出厂态与重置都必须卡「全部」档(2026-11-21 用户口径:默认改成全部)')
for (const blank of [undefined, 'grouped', 'nonsense'] as const) {
const q = toJdProductListParams({ ...createJdProductFilterState(), classified: blank }, 1, 20)
assert.equal('classified' in q, false, `classified=${String(blank)} 按「全部」兜底处理,不拿脏值冒充档位`)
}
})
/** 归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」):归属下拉在状态三档之外
* 追加「按分类查询」组(cat:<id>),四类档位互斥单值。派生(jdOwnershipSelectValue)与
* 回写(applyJdOwnershipSelection)都在 filter 层纯函数里,本组用例钉三件事:
* ① 派生档位——分类档优先于状态档(groupId 非空必须卡 cat:<id>,否则同一颗下拉会同时
* 显示「已分类」和某分类、界面说谎);② 选分类档写 groupId、清状态档、清店铺孤儿谓词
* (店铺名单挂在分类下,换分类后旧店铺词会命中别组同名店——侧栏 onSelectGroup 同纪律);
* ③ 状态档清 groupId 不动店铺词(店铺不属分类维度,与既有三档行为一致);
* 脏值按「全部」兜底,不拿脏值冒充档位。 */
test('归属筛选查询——派生档位:分类档 cat:<id> 优先于状态档、默认卡全部', () => {
assert.equal(jdOwnershipSelectValue(createJdProductFilterState()), '',
'出厂态(groupId 空+classified 全部)下拉派生「全部」档')
assert.equal(
jdOwnershipSelectValue({ ...createJdProductFilterState(), classified: 'ungrouped' }),
'ungrouped',
'状态档原样派生',
)
const state = { ...createJdProductFilterState(), classified: 'classified', groupId: '7' }
assert.equal(jdOwnershipSelectValue(state), `${JD_OWNERSHIP_CATEGORY_PREFIX}7`,
'groupId 非空时分类档优先——下拉只显示分类,不显示状态档(否则界面说谎)')
})
test('归属筛选查询——选分类档写 groupId 清状态档清店铺词;状态档清 groupId 不动店铺词', () => {
// 选分类档:groupId 写入、状态档清空、店铺词清空(孤儿谓词纪律)
const catState = { ...createJdProductFilterState(), classified: 'classified', shopName: '绿屿街道店' }
applyJdOwnershipSelection(catState, `${JD_OWNERSHIP_CATEGORY_PREFIX}7`)
assert.equal(catState.groupId, '7', '选分类=按归属表查该分类(group_id EXISTS 下推)')
assert.equal(catState.classified, '', '分类档与状态档互斥——同一颗下拉选了分类就清状态档')
assert.equal(catState.shopName, '', '换分类必须清店铺词:旧店铺词是孤儿谓词(侧栏 onSelectGroup 同形)')
// 状态档:清 groupId、店铺词不动(店铺不属分类维度)
const stateState = { ...createJdProductFilterState(), groupId: '7', shopName: '绿屿街道店' }
applyJdOwnershipSelection(stateState, 'ungrouped')
assert.equal(stateState.groupId, '', '状态档与分类档互斥——选状态档清 groupId')
assert.equal(stateState.classified, 'ungrouped')
assert.equal(stateState.shopName, '绿屿街道店', '状态档不动店铺词(与既有三档行为一致)')
// 「全部」档:两字段都清
const allState = { ...createJdProductFilterState(), groupId: '7', classified: 'classified' }
applyJdOwnershipSelection(allState, '')
assert.equal(allState.groupId, '', '全部档清分类档')
assert.equal(allState.classified, '', '全部档清状态档')
// 脏值兜底:未知前缀/非数字 id 都按「全部」档,不拿脏值冒充档位
for (const dirty of ['cat:abc', 'cat:0', 'cat:-1', 'shop:9', 'nonsense']) {
const dirtyState = { ...createJdProductFilterState(), groupId: '7', classified: 'classified' }
applyJdOwnershipSelection(dirtyState, dirty)
assert.equal(dirtyState.groupId, '', `脏值 ${dirty} 按「全部」兜底清分类档`)
assert.equal(dirtyState.classified, '', `脏值 ${dirty} 按「全部」兜底清状态档`)
}
})
test('详情解析——attrGroups/images 结构化解析(snake 容错、缺 url 弃行)', () => {
const detail = parseJdProductDetail({
code: 0,
@@ -16,6 +16,7 @@ import { readdirSync } from 'node:fs'
import { readSource } from './helpers.ts'
import {
LOAD_FAILURE_RETRY_LABEL,
NETWORK_FAILURE_DETAIL,
failureDetail,
loadFailureMessage,
scopeRefusalNote,
@@ -102,6 +103,27 @@ test('失败文案模型:后端的中文原因进得来,英文原文进不
assert.equal(loadFailureMessage('网关超时', '数据加载失败'), '数据加载失败:网关超时')
// 兜底句里已经含原因时不重复拼一遍
assert.equal(loadFailureMessage(new Error('去重数据加载失败'), '去重数据加载失败'), '去重数据加载失败')
// 网络层失败(axios 无 response):2026-11-21 线上实录——用户代理链路抖动掐断 TLS,
// axios 的英文 "Network Error" 原本被 userNotice 滤空 ⇒ 只剩兜底文案看不出是网络问题。
// 现在必须显式给出中文网络提示(判据:axios 形状 + 无 response;普通 Error 不受影响)。
const networkErr = Object.assign(new Error('Network Error'), {
code: 'ERR_NETWORK', config: {}, isAxiosError: true,
})
assert.equal(failureDetail(networkErr), NETWORK_FAILURE_DETAIL)
assert.equal(loadFailureMessage(networkErr, '京东商品列表加载失败'),
`京东商品列表加载失败:${NETWORK_FAILURE_DETAIL}`)
const timeoutErr = Object.assign(new Error('timeout of 30000ms exceeded'), {
code: 'ECONNABORTED', config: {}, isAxiosError: true,
})
assert.equal(failureDetail(timeoutErr), NETWORK_FAILURE_DETAIL)
// 带 response 的 axios 错误仍按服务端原因走(网络提示不得抢话)
const serverErr = Object.assign(new Error('Request failed with status code 403'), {
code: 'ERR_BAD_REQUEST', config: {}, isAxiosError: true,
response: { status: 403, data: { message: '无权操作该总数据' } },
})
assert.equal(failureDetail(serverErr), '无权操作该总数据')
// 普通 Error(非 axios 形状)保持原口径:英文仍被滤空
assert.equal(failureDetail(new Error('Some English Failure')), '')
})
test('范围拒绝要给出路,不是只说"失败了"', () => {
@@ -0,0 +1,165 @@
/**
* AdminLayout × 平台锁定(2026-11-18 用户口径「隔离下除站点超管外,京东用户只看京东菜单、
* 亚马逊看不了」)的挂载契约:
* - 京东用户(company_super_admin + platform=jd)即使 localStorage 残留另一侧 tab,挂载后
* active 归位本人平台(syncToAllowed),单侧时平台 tab 条整个隐藏;
* - 站点超管不受限:双平台 tab 照画、active 保持残留值(超管切过的侧照记);
* - 京东用户当前路由落在被禁侧(直达 URL):跳回本人平台第一可见页。
* menuTree 模拟后端裁剪后的下发树(京东用户树里本来就没有亚马逊叶子)。
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
*
* 跑法:`npx vitest run tests/mount/admin-layout-platform-lock.mount.test.ts`
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import ElementPlus from 'element-plus'
import { createMemoryHistory, createRouter, type Router } from 'vue-router'
import AdminLayout from '@/layout/AdminLayout.vue'
import { usePlatformTabStore } from '@/stores/platform-tab'
import { useAdminSessionStore } from '@/stores/admin-session'
import { adminPages } from '@/router/routes'
import type { AdminMenuNode } from '@/types/admin'
// AdminLayout 的顶栏/告警子组件各带定时器或远端拉取,与本契约无关,替身化。
vi.mock('@/components/NotificationBell.vue', () => ({ default: { template: '<div class="bell-stub" />' } }))
vi.mock('@/components/ExpiryNotice.vue', () => ({ default: { template: '<div class="expiry-stub" />' } }))
vi.mock('@/layout/OperationGuide.vue', () => ({ default: { template: '<div class="guide-stub" />' } }))
vi.mock('@/layout/CompanyTabs.vue', () => ({ default: { template: '<div class="company-tabs-stub" />' } }))
vi.mock('@/layout/GlobalErrorContainer.vue', () => ({ default: { template: '<div class="error-stub" />' } }))
/** 后端裁剪后下发给京东用户的树形状:双侧账号域六页 + 京东数据库(无任何亚马逊叶子)。 */
const JD_TREE: AdminMenuNode[] = [
{
key: 'admin_group_account',
name: '账号与权限',
children: [
{ key: 'admin_users', name: '用户管理', route: '/account/users' },
{ key: 'admin_group_manage', name: '分组管理', route: '/account/groups' },
{ key: 'admin_columns', name: '菜单权限配置', route: '/account/menus' },
{ key: 'admin_user_secrets', name: '密钥管理', route: '/account/user-secrets' },
{ key: 'admin_user_secret_usage', name: '密钥用量统计', route: '/account/user-secret-usage' },
],
},
{
key: 'admin_group_data',
name: '数据管理',
children: [{ key: 'admin_jd_database', name: '京东数据库', route: '/jd-center/database' }],
},
]
/** 站点超管的树:亚马逊业务页 + 京东页 + 双侧账号域(现状全量形状)。 */
const SUPER_TREE: AdminMenuNode[] = [
{
key: 'admin_group_account',
name: '账号与权限',
children: [{ key: 'admin_users', name: '用户管理', route: '/account/users' }],
},
{
key: 'admin_group_data',
name: '数据管理',
children: [
{ key: 'admin_query_asin', name: '查询ASIN', route: '/asin-center/query' },
{ key: 'admin_jd_database', name: '京东数据库', route: '/jd-center/database' },
],
},
]
let pinia: Pinia
let router: Router
beforeEach(async () => {
vi.clearAllMocks()
window.localStorage.removeItem('admin-platform-tab')
pinia = createPinia()
setActivePinia(pinia)
// adminPages 是相对 /admin-vue/ 的子路径注册表(不带前导斜杠),这里按 memory history
// 补 "/" 建表:路由 meta 带上 menuKey,AdminLayout 的 tab 跟随/replace 判定吃真实 meta。
// component 全部换同步桩——真实页面是懒 import,导航确认会卡在组件 promise 上,
// 而本契约只盯 AdminLayout 的 tab/replace 行为,页面本体无关。
router = createRouter({
history: createMemoryHistory(),
routes: adminPages.map((page) => ({
path: `/${page.path}`,
component: { template: '<div class="page-stub" />' },
meta: { title: page.title, menuKey: page.menuKey },
})),
})
await router.push('/')
await router.isReady()
})
async function mountLayout() {
const wrapper = mount(AdminLayout, { global: { plugins: [pinia, router, ElementPlus] } })
await flushPromises()
return wrapper
}
describe('AdminLayout × 平台锁定(2026-11-18)', () => {
it('京东用户挂载:残留的亚马逊 tab 归位京东侧,tab 条隐藏,侧边栏只画本人平台菜单', async () => {
window.localStorage.setItem('admin-platform-tab', 'amazon')
const session = useAdminSessionStore()
session.user = { id: 10, username: '阿华66', role: 'company_super_admin', platform: 'jd' }
session.menuTree = JD_TREE
session.initialized = true
const wrapper = await mountLayout()
const platformTab = usePlatformTabStore()
expect(platformTab.active).toBe('jd')
expect(wrapper.findAll('.admin-platform-tab').length).toBe(0)
const texts = wrapper.findAll('.admin-menu .el-menu-item').map((item) => item.text())
expect(texts).toContain('京东数据库')
expect(texts).not.toContain('查询ASIN')
// 共用菜单配置保留,两个密钥入口仅亚马逊侧可见。
expect(texts).toContain('菜单权限配置')
expect(texts).not.toContain('密钥管理')
expect(texts).not.toContain('密钥用量统计')
wrapper.unmount()
})
it('站点超管挂载:双平台 tab 照画、残留 active 保持(不受平台锁定影响)', async () => {
window.localStorage.setItem('admin-platform-tab', 'jd')
const session = useAdminSessionStore()
session.user = { id: 1, username: 'admin', role: 'super_admin', platform: 'amazon' }
session.menuTree = SUPER_TREE
session.initialized = true
const wrapper = await mountLayout()
const platformTab = usePlatformTabStore()
expect(platformTab.active).toBe('jd')
const tabs = wrapper.findAll('.admin-platform-tab').map((tab) => tab.text())
expect(tabs).toEqual(['亚马逊', '京东'])
expect(tabs[1]).toBe('京东')
wrapper.unmount()
})
it('京东用户直达被禁侧 URL(/asin-center/query):挂载后跳回本人平台第一可见页', async () => {
const session = useAdminSessionStore()
session.user = { id: 10, username: '阿华66', role: 'company_super_admin', platform: 'jd' }
session.menuTree = JD_TREE
session.initialized = true
await router.push('/asin-center/query')
const wrapper = await mountLayout()
expect(router.currentRoute.value.path).toBe('/account/users')
wrapper.unmount()
})
it('亚马逊存量用户(platform 缺省兜底亚马逊):锁亚马逊侧,京东页不可达', async () => {
const session = useAdminSessionStore()
session.user = { id: 8, username: '存量号', role: 'admin' }
session.menuTree = SUPER_TREE
session.initialized = true
const wrapper = await mountLayout()
const platformTab = usePlatformTabStore()
expect(platformTab.active).toBe('amazon')
expect(wrapper.findAll('.admin-platform-tab').length).toBe(0)
wrapper.unmount()
})
})
@@ -14,6 +14,7 @@ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import JdCategoryManageDialog from '@/pages/jd/JdCategoryManageDialog.vue'
import { useAdminSessionStore } from '@/stores/admin-session'
const jdApi = vi.hoisted(() => ({
fetchJdProductGroups: vi.fn(),
@@ -22,9 +23,14 @@ const jdApi = vi.hoisted(() => ({
deleteJdProductGroup: vi.fn(),
}))
const groupApi = vi.hoisted(() => ({
createShopGroup: vi.fn(),
}))
const confirmMock = vi.hoisted(() => vi.fn())
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
vi.mock('@/pages/account/shop-group-api.ts', () => groupApi)
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
/** 分组 id 常量:默认作用域就这一个可见且可写的组(组长档形状)。 */
@@ -40,7 +46,10 @@ beforeEach(() => {
vi.clearAllMocks()
pinia = createPinia()
setActivePinia(pinia)
// 空态直建分组(2026-11-17 用户口径「admin 权限最大」)需要当前登录人做组长。
useAdminSessionStore().user = { id: 9, username: 'admin', role: 'super_admin' } as never
jdApi.fetchJdProductGroups.mockResolvedValue([])
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
confirmMock.mockResolvedValue(true)
})
@@ -59,13 +68,32 @@ async function mountDialog(editable = true): Promise<VueWrapper<Element>> {
return wrapper
}
it('批量删除分类:全选当前页、确认只移除分类、刷新一次;只读模式无入口', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3), group(8, '裤装', 1)])
jdApi.deleteJdProductGroup.mockResolvedValue(undefined)
const wrapper = await mountDialog()
await wrapper.get('.option-head input[type="checkbox"]').setValue(true)
await wrapper.get('.batch-delete-actions .btn-danger').trigger('click')
await flushPromises()
expect(confirmMock).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('商品本身不会被删除') }))
expect(jdApi.deleteJdProductGroup.mock.calls).toEqual([[7], [8]])
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledTimes(2)
expect(wrapper.emitted('changed')).toHaveLength(1)
expect(wrapper.get('.batch-delete-actions .btn-danger').text()).toBe('批量删除(0)')
await wrapper.setProps({ editable: false })
expect(wrapper.find('.batch-delete-actions').exists()).toBe(false)
expect(wrapper.find('.batch-delete-checkbox').exists()).toBe(false)
wrapper.unmount()
})
describe('京东分类管理对话框(V204 独立页 2026-11-17 并入京东数据库页)', () => {
it('打开即按当前分组取分类(ownerGroupId 必带);标题带当前分组名', async () => {
it('打开即按当前分组取分类(ownerGroupId 必带);标题不带分组名(2026-11-17 用户口径「不要显示周丽娥」)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
const wrapper = await mountDialog()
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(GROUP_A)
expect(wrapper.get('.manage-modal').text()).toContain('分类管理')
expect(wrapper.get('.manage-modal').text()).toContain('甲组', '标题/上下文带当前分组名')
expect(wrapper.find('.modal-sub').exists()).toBe(false, '标题后缀(· 分组名)已删,不得长回来')
expect(wrapper.get('.manage-modal').text()).not.toContain('甲组', '分组名不进标题')
expect(wrapper.findAll('.option-row')).toHaveLength(1)
wrapper.unmount()
})
@@ -142,14 +170,15 @@ describe('京东分类管理对话框(V204 独立页 2026-11-17 并入京东
wrapper.unmount()
})
it('搜索与新建行同属 manage-bar 的两行(搜索在上、新建在下,2026-11-17 改垂直排列)', async () => {
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, '新建行在下')
expect(children).toHaveLength(2, '一排只有两件:搜索框、新建行(新建行内=输入框+新建按钮)')
expect(children[0].classList.contains('search-input')).toBe(true, '搜索框在左')
expect(children[1].classList.contains('group-create')).toBe(true, '新建行在右')
expect(children[1].children).toHaveLength(2, '新建行只有输入框+按钮(排序输入 11-15 已下线,不得长出第三个框)')
wrapper.unmount()
})
@@ -250,8 +279,104 @@ describe('京东分类管理对话框(V204 独立页 2026-11-17 并入京东
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
const wrapper = await mountDialog()
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '归类入口在京东数据库页')
expect(wrapper.text()).toContain('批量编辑分类', '但提示要指路(关掉本框去勾选商品归类)')
expect(wrapper.text()).not.toContain('批量编辑分类',
'指路小字已随 2026-11-17 用户口径「小字不需要」删除,弹窗里不该再出现这句')
expect(jdApi.deleteJdProductGroup).not.toHaveBeenCalled()
wrapper.unmount()
})
})
/** 平台超管空态直建分组(2026-11-17 用户口径「admin 权限最大」):京东侧还没有任何
* 数据权限分组时(平台闸上线后 jd 档组全空,B117-02 前置未做),平台超管在弹窗里
* 直接建第一个京东档分组,不再死在「你还不属于任何数据权限分组」。 */
describe('平台超管空态直建京东档分组', () => {
function mountEmpty(platformSuperAdmin: boolean): VueWrapper<Element> {
return mount(JdCategoryManageDialog, {
global: { plugins: [pinia] },
props: { visible: true, ownerGroupId: 0, ownerGroupName: '', editable: false, platformSuperAdmin },
})
}
it('平台超管空态:出直建表单(不是死路文案),提交走分组管理同一条 POST 且 platform 恒 jd、组长=当前登录人', async () => {
const wrapper = mountEmpty(true)
await flushPromises()
await flushPromises()
expect(jdApi.fetchJdProductGroups).not.toHaveBeenCalled()
expect(wrapper.get('.manage-empty').find('[aria-label="新分组名称"]').exists()).toBe(true,
'空态直建表单就在空态区里(引导语小字已删,表单本身还在)')
const input = wrapper.get('[aria-label="新分组名称"]')
await input.setValue('京东-团队')
await wrapper.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
await flushPromises()
await flushPromises()
expect(groupApi.createShopGroup).toHaveBeenCalledTimes(1)
expect(groupApi.createShopGroup).toHaveBeenCalledWith('京东-团队', [], 9, 'jd')
expect(wrapper.emitted('group-created'), '建组成功即通知父页重取作用域').toBeTruthy()
expect((input.element as HTMLInputElement).value).toBe('', '成功后清输入')
wrapper.unmount()
})
it('没有当前登录人就不发请求并给可见错误(组长缺了这单没法建)', async () => {
useAdminSessionStore().user = null
const wrapper = mountEmpty(true)
await flushPromises()
await wrapper.get('[aria-label="新分组名称"]').setValue('京东-团队')
await wrapper.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
await flushPromises()
expect(groupApi.createShopGroup).not.toHaveBeenCalled()
expect(wrapper.text()).toContain('无法获取当前登录用户')
wrapper.unmount()
})
it('建组失败:错误进红条、不发 group-created(父页作用域不动)', async () => {
groupApi.createShopGroup.mockRejectedValueOnce(new Error('分组名称已存在'))
const wrapper = mountEmpty(true)
await flushPromises()
await wrapper.get('[aria-label="新分组名称"]').setValue('京东-团队')
await wrapper.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
await flushPromises()
await flushPromises()
expect(wrapper.text()).toContain('分组名称已存在')
expect(wrapper.emitted('group-created')).toBeFalsy()
wrapper.unmount()
})
it('父页把 ownerGroupId 翻到新组后:直建表单消失、按新组重取分类(不用关弹窗重开)', async () => {
const wrapper = mountEmpty(true)
await flushPromises()
await wrapper.get('[aria-label="新分组名称"]').setValue('京东-团队')
await wrapper.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
await flushPromises()
const emittedBefore = wrapper.emitted('group-created')?.length ?? 0
await wrapper.setProps({ ownerGroupId: 21, ownerGroupName: '京东-团队', editable: true })
await flushPromises()
await flushPromises()
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(21)
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(21)
expect(wrapper.find('[aria-label="新分组名称"]').exists()).toBe(false, '有组了直建口子就关')
expect(wrapper.emitted('group-created')?.length).toBe(emittedBefore, '翻组重取不再重复通知父页')
wrapper.unmount()
})
it('非平台超管的空态维持原状:死路文案照旧、无直建表单(口子不开给组长/公司超管)', async () => {
const wrapper = mountEmpty(false)
await flushPromises()
expect(wrapper.get('.manage-empty').text()).toBe('你还不属于任何数据权限分组')
expect(wrapper.find('[aria-label="新分组名称"]').exists()).toBe(false)
wrapper.unmount()
})
it('平台超管但已有分组(ownerGroupId>0):直建口子不出现(完整分组管理归「分组管理」页)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
const wrapper = mount(JdCategoryManageDialog, {
global: { plugins: [pinia] },
props: { visible: true, ownerGroupId: GROUP_A, ownerGroupName: '甲组', editable: true, platformSuperAdmin: true },
})
await flushPromises()
await flushPromises()
expect(wrapper.find('[aria-label="新分组名称"]').exists()).toBe(false)
expect(wrapper.find('.group-bootstrap').exists()).toBe(false, '有组时直建表单整体不渲染')
wrapper.unmount()
})
})
@@ -0,0 +1,448 @@
/**
* 京东数据库侧栏(JdCategorySidebar,v1.6 蓝图 Phase 2)的挂载契约。
*
* 纯展示组件:取数与失败兜底全在页面(props 流入、emit 流出),本文件零 api mock——
* 钉的是「徽标数=点节点后列表命中的行数」(jdCategoryCountTree 同源)、双 Tab 切换、
* 点节点 emit 形状(树内带路径/树外兜底 path 空/全部商品 null)、可写档分档入口。
*
* 跑法:`npx vitest run tests/mount/jd-category-sidebar.mount.test.ts`
*/
import { beforeEach, describe, expect, it } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import JdCategorySidebar from '@/pages/jd/JdCategorySidebar.vue'
import type { JdProductCategoryOption, JdProductGroup } from '@/pages/jd/jd-product-api.ts'
/** 类目计数夹具:树内名(连衣裙支+同名跨支短裤)+树外历史名,读数与 Phase 1
* 纯函数测试同源——服饰内衣根徽标 20(子树去重)、全部商品 37、兜底 12。 */
const CATEGORY_OPTIONS: JdProductCategoryOption[] = [
{ name: '连衣裙', productCount: 7 },
{ name: '短袖连衣裙', productCount: 4 },
{ name: '艺考形体服', productCount: 5 },
{ name: '短裤', productCount: 9 },
{ name: '已下架历史类目', productCount: 12 },
]
const CATEGORIES: JdProductGroup[] = [
{ id: 7, name: '裙装', ownerGroupId: 11, sortOrder: 0, productCount: 3 },
{ id: 8, name: '裤装', ownerGroupId: 11, sortOrder: 1, productCount: 1 },
]
/** 店铺名单夹具(v1.7 F6):裙装带两名单店,裤装无名单(无箭头)。 */
const CATEGORIES_WITH_SHOPS: JdProductGroup[] = [
{ id: 7, name: '裙装', ownerGroupId: 11, sortOrder: 0, productCount: 3, shops: ['绿屿街道店', '花屿巷旗舰店'] },
{ id: 8, name: '裤装', ownerGroupId: 11, sortOrder: 1, productCount: 1 },
]
interface MountOptions {
editable?: boolean
selectedCategory?: { name: string; path: string[] } | null
selectedGroupId?: number | null
selectedShopName?: string | null
categories?: JdProductGroup[]
}
function mountSidebar(options: MountOptions = {}): VueWrapper<Element> {
return mount(JdCategorySidebar, {
props: {
categoryOptions: CATEGORY_OPTIONS,
categories: options.categories ?? CATEGORIES,
editable: options.editable ?? true,
selectedCategory: options.selectedCategory ?? null,
selectedGroupId: options.selectedGroupId ?? null,
selectedShopName: options.selectedShopName ?? null,
},
})
}
/** 在指定 Tab 体内按文案找行(两个 Tab 体 v-show 共存于 DOM,必须先圈定范围)。 */
function rowByText(scope: VueWrapper<Element>, text: string) {
const row = scope.findAll('.jd-side-row').find((node) => node.text().includes(text))
expect(row, `应存在文案含「${text}」的侧栏行`).toBeTruthy()
return row!
}
beforeEach(() => {
// v1.7 起展开态持久化 localStorage:用例间清掉防串台(出厂态=无记忆)。
localStorage.removeItem('jd_db_cat_expand')
})
describe('商品目录 Tab(京麦授权类目树+计数徽标)', () => {
it('出厂停在商品目录 Tab;徽标与 Phase 1 聚合同源(根=子树去重和、全部商品=计数行总和)', () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
const all = catalog.get('.jd-side-all')
expect(all.text()).toContain('全部商品')
expect(all.text()).toContain('37', '全部商品徽标=5 条计数行求和(7+4+5+9+12)')
expect(rowByText(catalog, '服饰内衣').text()).toContain('20',
'服饰内衣根徽标=子树去重和(连衣裙7+短袖4+短裤9,短裤跨支同名只记一次)')
expect(rowByText(catalog, '母婴').text()).toContain('0', '无词条一级归 0 不缺节点')
expect(rowByText(catalog, '运动户外').text()).toContain('5')
wrapper.unmount()
})
it('一级默认展开(二级首屏可见);逐级展开后末级行点行 emit {name, path}', async () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
const women = rowByText(catalog, '女装')
expect(women.classes()).toContain('depth-1', '一级默认展开 ⇒ 二级行(depth-1 缩进)首屏可见')
// 末级艺考形体服在 depth-2:其父(舞蹈体操鞋服/装备)未展开时不可见。
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('艺考形体服'))).toBe(false)
await catalog.get('[aria-label="展开或收起 舞蹈体操鞋服/装备"]').trigger('click')
await flushPromises()
const yikao = rowByText(catalog, '艺考形体服')
expect(yikao.classes()).toContain('depth-2', '艺考形体服是 level 3(depth 2 缩进)')
await yikao.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')).toEqual([[{ name: '艺考形体服', path: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'] }]])
wrapper.unmount()
})
it('点二级节点 emit 完整路径(页面按子树展开 IN);箭头只折展不选中', async () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
// 女装行未展开时,其子行(连衣裙)不可见。
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(false)
const women = rowByText(catalog, '女装')
await women.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')).toEqual([[{ name: '女装', path: ['服饰内衣', '女装'] }]],
'点行=选中即筛,emit 完整名称路径')
// 点行顺手展开(下钻感):子行现在可见。
expect(wrapper.emitted('select-category')).toHaveLength(1)
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(true,
'非末级行点行后展开子级')
// 箭头(role=button, aria-label)只折展:点它不得触发 select-category。
const before = wrapper.emitted('select-category')?.length ?? 0
await catalog.get('[aria-label="展开或收起 女装"]').trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')?.length).toBe(before, '箭头点击不选中(click.stop 防冒泡)')
expect(catalog.findAll('.jd-side-row').some((node) => node.text().includes('连衣裙'))).toBe(false,
'再点箭头=收起(子行隐藏)')
wrapper.unmount()
})
it('「全部商品」行 emit null(页面清类目筛选重查);挂载即带选中态时祖先自动展开并高亮', async () => {
const wrapper = mountSidebar({ selectedCategory: { name: '连衣裙', path: ['服饰内衣', '女装', '连衣裙'] } })
const catalog = wrapper.get('.jd-side-catalog')
const dress = rowByText(catalog, '连衣裙')
expect(dress.classes()).toContain('selected', '外部选中态回显高亮')
expect(dress.classes()).toContain('depth-2', '挂载即带选中 ⇒ watch immediate 展开祖先(女装已展开,行可见)')
await wrapper.setProps({ selectedCategory: null })
expect(catalog.get('.jd-side-all').classes()).toContain('selected', 'null=全部商品高亮')
await catalog.get('.jd-side-all').trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')).toEqual([[null]], '点全部商品=清选')
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('树外兜底组(树上对不上的历史行,单名等值出口)', () => {
it('兜底组头渲染计数和=extraTotal;行点击 emit {name, path:[]}(页面按单名等值回落)', async () => {
const wrapper = mountSidebar()
const catalog = wrapper.get('.jd-side-catalog')
const head = catalog.get('.jd-side-extra-head')
expect(head.text()).toContain('树外兜底')
expect(head.text()).toContain('12', '兜底组头徽标=extraTotal(历史行求和)')
const extra = rowByText(catalog, '已下架历史类目')
await extra.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-category')).toEqual([[{ name: '已下架历史类目', path: [] }]],
'树外名 path 空数组=无路径序列化(单名等值旧形状,不静默丢筛选)')
wrapper.unmount()
})
it('全部是树内名时兜底组整体不渲染(不占一条空组)', () => {
const wrapper = mount(JdCategorySidebar, {
props: {
categoryOptions: [{ name: '连衣裙', productCount: 7 }],
categories: CATEGORIES,
editable: true,
selectedCategory: null,
selectedGroupId: null,
},
})
expect(wrapper.find('.jd-side-extra').exists()).toBe(false)
wrapper.unmount()
})
})
describe('店铺分类 Tab(当前分组分类平铺+入口分档)', () => {
it('点店铺分类切 Tab;分类行带计数;点行 emit id、再点已选中的 emit null(toggle 清选)', async () => {
const wrapper = mountSidebar()
const tabs = wrapper.findAll('.jd-sidebar-tab')
expect(tabs.map((tab) => tab.text())).toEqual(['商品目录', '店铺分类'])
await tabs[1]!.trigger('click')
await flushPromises()
expect(tabs[1]!.classes()).toContain('active')
const custom = wrapper.get('.jd-side-custom')
const skirt = rowByText(custom, '裙装')
expect(skirt.text()).toContain('3', '分类行计数徽标')
await skirt.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-group')).toEqual([[7]])
await wrapper.setProps({ selectedGroupId: 7 })
expect(rowByText(custom, '裙装').classes()).toContain('selected', '选中态回显')
await rowByText(custom, '裙装').trigger('click')
await flushPromises()
expect(wrapper.emitted('select-group')?.at(-1)).toEqual([null], '再点已选中=清选回全部分类')
wrapper.unmount()
})
it('可写档出「新建分类」行:emit 分类名并清输入,空名按钮置灰;只读档不渲染该行', async () => {
const editable = mountSidebar({ editable: true })
const custom = editable.get('.jd-side-custom')
const input = custom.get('[aria-label="新分类名称"]')
const createBtn = custom.findAll('button').find((b) => b.text() === '新建分类')!
expect(createBtn.attributes('disabled')).toBeDefined()
await input.setValue('上新区')
await createBtn.trigger('click')
await flushPromises()
expect(editable.emitted('create-category')).toEqual([['上新区']],
'侧栏只 emit,建分类的 API 调用与刷新在页面(Phase 5 接线)')
expect((input.element as HTMLInputElement).value).toBe('', '提交即清输入')
await input.setValue(' ')
expect(createBtn.attributes('disabled')).toBeDefined(), '纯空白名按钮置灰'
editable.unmount()
const readonly = mountSidebar({ editable: false })
expect(readonly.get('.jd-side-custom').find('[aria-label="新分类名称"]').exists()).toBe(false,
'只读档不渲染新建行')
readonly.unmount()
})
it('「分类管理」入口对所有人渲染(同组普通号只读可看 V203),点击 emit manage-categories', async () => {
for (const editable of [true, false]) {
const wrapper = mountSidebar({ editable })
const manage = wrapper.get('.jd-side-custom').get('.jd-side-manage')
expect(manage.text()).toBe('分类管理')
await manage.trigger('click')
await flushPromises()
expect(wrapper.emitted('manage-categories')).toHaveLength(1)
wrapper.unmount()
}
})
it('空分类空态文案分档:可写档引导新建,只读档直说', () => {
const writable = mount(JdCategorySidebar, {
props: { categoryOptions: [], categories: [], editable: true, selectedCategory: null, selectedGroupId: null },
})
expect(writable.get('.jd-side-empty').text()).toBe('本组暂无分类,先新建一个')
writable.unmount()
const readonly = mount(JdCategorySidebar, {
props: { categoryOptions: [], categories: [], editable: false, selectedCategory: null, selectedGroupId: null },
})
expect(readonly.get('.jd-side-empty').text()).toBe('本组暂无分类')
readonly.unmount()
})
})
/** 店铺名单(v1.7 F6,2026-11-22 原型对齐铺开形态):分类行下直接铺店铺行(点选过滤/
* 行内改名移除)+「+ 添加店铺」入口常驻(空分类也能加第一个店——旧折叠版箭头只在
* 已有名单时才出 ⇒ 空分类永远加不进第一个店铺的死锁,判据就在下面的空分类用例)。
* 侧栏纯展示:全部只 emit,API 调用与刷新在页面。 */
describe('店铺名单(v1.7 铺开形态:分类下挂店铺名单)', () => {
async function openCustomTab(wrapper: VueWrapper<Element>): Promise<void> {
const tabs = wrapper.findAll('.jd-sidebar-tab')
await tabs[1]!.trigger('click')
await flushPromises()
}
it('店铺名单铺开:店铺行直接可见(无折叠箭头),可写档名单尾出添加店铺入口', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
expect(custom.find('[aria-label="展开或收起 裙装 的店铺名单"]').exists()).toBe(false,
'铺开形态无店铺名单折叠箭头(类目树的箭头不受影响)')
const shops = custom.findAll('.jd-side-shop')
expect(shops).toHaveLength(2, '店铺行首屏直接可见(服务端升序原样渲染)')
expect(shops[0]!.text()).toContain('绿屿街道店')
expect(shops[1]!.text()).toContain('花屿巷旗舰店')
expect(custom.get('.jd-side-shop-add').text()).toContain('+ 添加店铺', '可写档名单尾出添加入口')
wrapper.unmount()
})
it('空分类也常驻「+ 添加店铺」入口(2026-11-22 死锁修复:空分类能加进第一个店铺)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
expect(custom.findAll('.jd-side-shop')).toHaveLength(0, '两个分类都无名单')
const addRows = custom.findAll('.jd-side-shop-add')
expect(addRows).toHaveLength(2, '空分类名单尾照样出添加入口(旧折叠版此处为 0=加不进第一个店)')
await addRows[1]!.trigger('click')
await flushPromises()
expect(wrapper.emitted('add-shops')).toEqual([[CATEGORIES[1]]],
'点裤装(空分类)的添加入口=emit 该分类')
wrapper.unmount()
})
it('点店铺行 emit {groupId, shopName} 成对下发;选中回流高亮;再点已选 emit null(只清店铺保留分类)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7 })
await openCustomTab(wrapper)
const shopRow = wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!
await shopRow.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-shop')).toEqual([[{ groupId: 7, shopName: '绿屿街道店' }]],
'点店铺=分类+店铺成对(页面发 group_id+shop_name 精确过滤)')
await wrapper.setProps({ selectedShopName: '绿屿街道店' })
expect(wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!.classes()).toContain('selected', '选中回流高亮')
await wrapper.get('.jd-side-custom').findAll('.jd-side-shop')[0]!.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-shop')?.at(-1)).toEqual([null], '再点已选=清店铺筛选(分类保留)')
wrapper.unmount()
})
it('页面带着店铺筛选挂载:店铺行直接可见并高亮(铺开态无需展开)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7, selectedShopName: '花屿巷旗舰店' })
await openCustomTab(wrapper)
const selected = wrapper.get('.jd-side-custom').findAll('.jd-side-shop').find((row) => row.text().includes('花屿巷旗舰店'))
expect(selected, '铺开态店铺行首屏可见').toBeTruthy()
expect(selected!.classes()).toContain('selected')
wrapper.unmount()
})
it('可写档:分类行与店铺行 hover 出改名/删除操作钮;分类行内改名 Enter 提交 emit (cat, 新名)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
expect(custom.get('[aria-label="改名分类 裙装"]').exists()).toBe(true)
expect(custom.get('[aria-label="删除分类 裙装"]').exists()).toBe(true)
// 分类行内改名:点 ✎ → 行替换成编辑输入(预填原名)→ Enter 提交。
await custom.get('[aria-label="改名分类 裙装"]').trigger('click')
await flushPromises()
const editInput = custom.get('[aria-label="修改分类名称(原:裙装)"]')
expect((editInput.element as HTMLInputElement).value).toBe('裙装', '编辑形态预填原名')
await editInput.setValue('长裙')
await editInput.trigger('keyup.enter')
await flushPromises()
expect(wrapper.emitted('rename-category')).toEqual([[CATEGORIES_WITH_SHOPS[0], '长裙']],
'侧栏只 emit(API 调用与刷新在页面)')
// 空名/未改动不 emit(静默收编辑态)。
await custom.get('[aria-label="改名分类 裙装"]').trigger('click')
await flushPromises()
const unchanged = custom.get('[aria-label="修改分类名称(原:裙装)"]')
await unchanged.setValue(' 裙装 ')
await unchanged.trigger('keyup.enter')
await flushPromises()
expect(wrapper.emitted('rename-category')).toHaveLength(1, '未改动不白发请求')
// 店铺行 hover 操作钮随铺开直接可见。
expect(custom.get('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(true)
expect(custom.get('[aria-label="移除店铺 绿屿街道店"]').exists()).toBe(true)
wrapper.unmount()
})
it('店铺行内改名 emit (cat, oldName, newName);移除 emit (cat, shopName);添加店铺入口 emit (cat)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
// 店铺改名:✎ → 预填 → 改名 → ✓ 提交。
await custom.get('[aria-label="改名店铺 绿屿街道店"]').trigger('click')
await flushPromises()
const shopEdit = custom.get('[aria-label="修改店铺名称(原:绿屿街道店)"]')
expect((shopEdit.element as HTMLInputElement).value).toBe('绿屿街道店')
await shopEdit.setValue('绿屿新址店')
await custom.get('[aria-label="确认改名店铺 绿屿街道店"]').trigger('click')
await flushPromises()
expect(wrapper.emitted('rename-shop')).toEqual([[CATEGORIES_WITH_SHOPS[0], '绿屿街道店', '绿屿新址店']])
// 移除:hover ✕ 直接 emit(可重做,不设二次确认)。
await custom.get('[aria-label="移除店铺 花屿巷旗舰店"]').trigger('click')
await flushPromises()
expect(wrapper.emitted('remove-shop')).toEqual([[CATEGORIES_WITH_SHOPS[0], '花屿巷旗舰店']])
// 添加店铺入口。
await custom.get('.jd-side-shop-add').trigger('click')
await flushPromises()
expect(wrapper.emitted('add-shops')).toEqual([[CATEGORIES_WITH_SHOPS[0]]])
wrapper.unmount()
})
it('只读档:无 hover 操作钮、无添加店铺入口;店铺行仍可见可点(读面 V203)', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, editable: false })
await openCustomTab(wrapper)
const custom = wrapper.get('.jd-side-custom')
expect(custom.find('[aria-label="改名分类 裙装"]').exists()).toBe(false, '分类行无改名钮')
expect(custom.find('[aria-label="删除分类 裙装"]').exists()).toBe(false, '分类行无删除钮')
expect(custom.findAll('.jd-side-shop')).toHaveLength(2, '店铺行照常可见(读面)')
expect(custom.find('.jd-side-shop-add').exists()).toBe(false, '只读档无添加店铺入口')
expect(custom.find('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(false, '店铺行无改名钮')
expect(custom.find('[aria-label="移除店铺 绿屿街道店"]').exists()).toBe(false, '店铺行无移除钮')
await custom.findAll('.jd-side-shop')[0]!.trigger('click')
await flushPromises()
expect(wrapper.emitted('select-shop')).toEqual([[{ groupId: 7, shopName: '绿屿街道店' }]],
'只读档点店铺照常过滤')
wrapper.unmount()
})
it('分类行仍是 toggle 选中(点行 emit id/再点 null),店铺行高亮不改变分类行选中判定', async () => {
const wrapper = mountSidebar({ categories: CATEGORIES_WITH_SHOPS, selectedGroupId: 7 })
await openCustomTab(wrapper)
expect(rowByText(wrapper, '裙装').classes()).toContain('selected', '分类行选中(含选店铺时)')
await rowByText(wrapper, '裙装').trigger('click')
await flushPromises()
expect(wrapper.emitted('select-group')).toEqual([[null]], '再点已选分类=清选(页面同清店铺筛选)')
wrapper.unmount()
})
})
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,163 @@
/**
* 京东商品卡片(JdProductCard,v1.6 蓝图 Phase 3)的挂载契约。
*
* 纯展示组件(零 api 依赖):字段渲染与现表格「商品信息」列同源(价格走 jdPriceRange、
* 日期走 formatDateTime);卡片点击=开详情,勾选/复制 @click.stop 防冒泡——这两处
* 防冒泡是行为红线(点了复制却弹详情=误开弹窗),逐一钉死。
*
* 跑法:`npx vitest run tests/mount/jd-product-card.mount.test.ts`
*/
import { describe, expect, it } from 'vitest'
import { mount } from '@vue/test-utils'
import JdProductCard from '@/pages/jd/JdProductCard.vue'
import type { JdProductItem } from '@/pages/jd/jd-product-model.ts'
/** 行夹具:价格用 number 形状(2026-11-16 实录:BigDecimal 序列化成 JSON number,
* 字符串夹具会藏住「解析层丢数字形状」的真红);字段与页面 mount 测试同源。 */
function item(over: Partial<JdProductItem> = {}): JdProductItem {
return {
id: 1,
shopId: 3,
shopName: '旗舰自营店',
productCode: 'JD-10086',
skuId: 'SKU-1',
itemNum: 'ITEM-1',
skuCount: 12,
healthScore: 81,
title: '304不锈钢保温杯大容量便携',
brand: '锅宝',
categoryPath: '家居 > 厨具 > 保温杯',
priceMin: '12.90',
priceMax: '15.90',
stockTotal: 500,
saleStatus: '上架中',
listTab: 'search',
jdCreatedAt: '2026-11-07 18:49:47',
jdOnlineAt: '2026-11-12 15:03:37',
jdUpdatedAt: '2026-11-13 14:06:07',
mainImageUrl: 'https://img.example/main-1.jpg',
attrCount: 6,
imageCount: 9,
groupId: 7,
groupName: '甲组',
syncedAt: '2026-11-12 09:00:00',
...over,
} as JdProductItem
}
describe('卡片字段渲染(与现表格「商品信息」列同源)', () => {
it('主图/分类条/标题/价格区间/商品编码/采集日期逐字段上卡', () => {
const wrapper = mount(JdProductCard, { props: { item: item(), selected: false, selectable: true } })
const img = wrapper.get('img.jd-card-thumb')
expect(img.attributes('src')).toBe('https://img.example/main-1.jpg')
// 2026-11-21 用户口径「这边改成分类名称就可以」:图底条显归属分类名(groupName),
// 店铺名不再上卡(详情弹窗仍可看)。
expect(wrapper.get('.jd-card-category').text()).toBe('甲组')
expect(wrapper.find('.jd-card-shop').exists()).toBe(false, '店铺名条退役')
expect(wrapper.get('.jd-card-title').text()).toBe('304不锈钢保温杯大容量便携')
expect(wrapper.get('.jd-card-price').text()).toBe('12.9 ~ 15.9', '价格走 jdPriceRange(number/字符串都收、去尾零)')
expect(wrapper.get('.jd-card-code').text()).toContain('JD-10086')
expect(wrapper.get('.jd-card-date').text()).toContain('2026-11-12 09:00:00', '采集日期走 formatDateTime')
expect(wrapper.get('.jd-card-health').text()).toBe('信息分 81', 'healthScore 徽标随图渲染')
wrapper.unmount()
})
it('未归类商品分类条常驻出「未分类」( groupName 空不过滤条,与归属三档口径同词)', () => {
const wrapper = mount(JdProductCard, { props: { item: item({ groupName: '', groupId: null }) } })
expect(wrapper.get('.jd-card-category').text()).toBe('未分类')
wrapper.unmount()
})
it('无图占位:缺 mainImageUrl 出「无图」占位不出 img 元素;缺价与缺码按占位符兜底', () => {
const wrapper = mount(JdProductCard, {
props: { item: item({ mainImageUrl: '', priceMin: '', priceMax: '', productCode: '', syncedAt: '', healthScore: null }) },
})
expect(wrapper.find('img.jd-card-thumb').exists()).toBe(false)
expect(wrapper.get('.jd-card-thumb-empty').text()).toBe('无图')
expect(wrapper.get('.jd-card-price').text()).toBe('-')
expect(wrapper.get('.jd-card-code').text()).toContain('-')
expect(wrapper.get('.jd-card-date').text()).toContain('—', 'formatDateTime 空值回 em dash 兜底')
expect(wrapper.find('.jd-card-copy').exists()).toBe(false, '缺编码不渲染复制按钮(现表格同形)')
expect(wrapper.find('.jd-card-health').exists()).toBe(false, 'healthScore null 不渲染徽标')
wrapper.unmount()
})
})
describe('交互事件(防冒泡是行为红线)', () => {
it('点卡片整体 emit open(详情入口);点复制按钮只 emit copy 不冒泡开详情', async () => {
const wrapper = mount(JdProductCard, { props: { item: item() } })
await wrapper.get('.jd-card').trigger('click')
expect(wrapper.emitted('open')).toHaveLength(1)
await wrapper.get('.jd-card-copy').trigger('click')
expect(wrapper.emitted('copy')).toHaveLength(1, '复制按钮 emit copy(页面走剪贴板与回执)')
expect(wrapper.emitted('open')?.length).toBe(1, '@click.stop 防冒泡:复制不得误开详情')
wrapper.unmount()
})
it('可勾选档渲染勾选框:change emit toggle-select;点击勾选区不冒泡开详情', async () => {
const wrapper = mount(JdProductCard, { props: { item: item(), selected: false, selectable: true } })
const box = wrapper.get('input[type="checkbox"]')
await box.setValue(true)
expect(wrapper.emitted('toggle-select')).toEqual([[true]])
await box.setValue(false)
expect(wrapper.emitted('toggle-select')?.at(-1)).toEqual([false])
// 勾选区(label @click.stop)点击不触发卡片 open。
await wrapper.get('.jd-card-check').trigger('click')
expect(wrapper.emitted('open')).toBeFalsy()
wrapper.unmount()
})
it('不可勾选档不渲染勾选框(普通账号/纯只读行集);selected 高亮类由外部选中态控制', () => {
const plain = mount(JdProductCard, { props: { item: item() } })
expect(plain.find('input[type="checkbox"]').exists()).toBe(false)
expect(plain.get('.jd-card').classes()).not.toContain('selected')
plain.unmount()
const picked = mount(JdProductCard, { props: { item: item(), selected: true, selectable: true } })
expect(picked.get('.jd-card').classes()).toContain('selected')
expect(picked.get('input[type="checkbox"]').element.checked).toBe(true)
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('「已下载」角标随 CSV 导出功能整体下线(2026-11-21 用户拍板):downloaded prop 不存在,任何档都不出角标', () => {
const wrapper = mount(JdProductCard, { props: { item: item() } })
expect(wrapper.find('.jd-card-downloaded').exists()).toBe(false)
wrapper.unmount()
})
})
@@ -0,0 +1,161 @@
/**
* 京东商品详情居中弹窗(JdProductDetailModal,v1.6 蓝图 Phase 4)的挂载契约。
*
* 弹窗壳只管 chrome(遮罩/标题/「编辑/删除」动作分档/关闭),内容与取数在共享块
* JdProductDetailContent(与侧滑抽屉同一份实现,抽屉薄壳化行为由页面 mount 测试兜住)。
* 挂载时序与真实页面一致:先 visible=false 挂载,再置 true(Content 的 watch 靠变更触发取数)。
*
* 跑法:`npx vitest run tests/mount/jd-product-detail-modal.mount.test.ts`
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import JdProductDetailModal from '@/pages/jd/JdProductDetailModal.vue'
import type { JdProductItem } from '@/pages/jd/jd-product-model.ts'
const jdApi = vi.hoisted(() => ({
fetchJdProductDetail: vi.fn(),
}))
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
function item(): JdProductItem {
return {
id: 1,
shopId: 3,
shopName: '旗舰自营店',
productCode: 'JD-10086',
skuId: 'SKU-1',
itemNum: 'ITEM-1',
skuCount: 1,
healthScore: 81,
title: '304不锈钢保温杯大容量便携',
brand: '锅宝',
categoryPath: '家居 > 厨具 > 保温杯',
priceMin: '12.90',
priceMax: '15.90',
stockTotal: 500,
saleStatus: '上架中',
listTab: 'search',
jdCreatedAt: '2026-11-07 18:49:47',
jdOnlineAt: '2026-11-12 15:03:37',
jdUpdatedAt: '2026-11-13 14:06:07',
mainImageUrl: 'https://img.example/main-1.jpg',
attrCount: 6,
imageCount: 2,
groupId: 7,
groupName: '甲组',
syncedAt: '2026-11-12 09:00:00',
} as JdProductItem
}
/** fetchJdProductDetail 的返回(已由 parseJdProductDetail 归一的形状,与页面 mount 测试同构)。 */
function detailPayload() {
return {
item: item(),
attrGroups: [
{ groupName: '规格', attrs: [{ key: 'capacity', label: '容量', value: '500ml' }] },
],
images: [
{ id: 1, imageType: 'MAIN', attrName: '', sortNo: 1, url: 'https://img.example/main.jpg', byteSize: null, width: 800, height: 800 },
{ id: 2, imageType: 'DETAIL', attrName: '', sortNo: 2, url: 'https://img.example/detail.jpg', byteSize: null, width: null, height: null },
],
skus: [
{ skuId: 'S1', skuName: '上衣 S', skuSeq: '1', price: '162', stock: 200, saleAttrs: [{ name: '颜色', value: '上衣' }, { name: '尺码', value: 'S' }], sortNo: 0 },
],
attrJsonRaw: '',
}
}
beforeEach(() => {
vi.clearAllMocks()
})
/** 与真实页面同构的挂载:先 visible=false 挂载,再置 true 触发 Content 取数。 */
async function mountOpened(canWrite = true): Promise<VueWrapper<Element>> {
jdApi.fetchJdProductDetail.mockResolvedValue(detailPayload())
const wrapper = mount(JdProductDetailModal, {
props: { item: item(), visible: false, canWrite },
})
await wrapper.setProps({ visible: true })
await flushPromises()
await flushPromises()
return wrapper
}
describe('居中弹窗 chrome(设计稿款式:居中大弹窗+顶部动作)', () => {
it('打开即取数(按 item.id)并渲染共享块内容:hero 左图右信息/属性分组/SKU 矩阵/图片三区', async () => {
const wrapper = await mountOpened()
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1)
expect(wrapper.get('.jd-modal-mask').exists()).toBe(true)
expect(wrapper.get('.jd-modal-head h3').text()).toBe('商品详情 · JD-10086')
// 共享块(与侧滑抽屉同一份实现)——类名与页面 mount 测试钉住的抽屉断言同字。
expect(wrapper.get('.detail-hero').exists()).toBe(true)
expect(wrapper.get('.hero-main').exists()).toBe(true)
expect(wrapper.get('.hero-info').text()).toContain('价格区间')
expect(wrapper.get('.hero-info').text()).toContain('12.9 ~ 15.9')
expect(wrapper.get('.jd-modal').text()).toContain('规格')
expect(wrapper.get('.jd-modal').text()).toContain('容量')
expect(wrapper.get('.jd-modal').text()).toContain('销售属性 / SKU 矩阵')
expect(wrapper.get('.jd-modal').text()).toContain('1 个 SKU · ¥162 · 库存 200')
expect(wrapper.get('.jd-modal').text()).toContain('主图')
expect(wrapper.get('.jd-modal').text()).toContain('详情图')
wrapper.unmount()
})
it('关闭:点遮罩自身与右上 × 都 emit close;关闭后 mask 摘掉', async () => {
const wrapper = await mountOpened()
await wrapper.get('.jd-modal-mask').trigger('click')
expect(wrapper.emitted('close')).toHaveLength(1, 'mask @click.self(点内容区不算)')
await wrapper.get('.jd-modal-close').trigger('click')
expect(wrapper.emitted('close')).toHaveLength(2)
await wrapper.setProps({ visible: false })
await flushPromises()
expect(wrapper.find('.jd-modal-mask').exists()).toBe(false)
wrapper.unmount()
})
})
describe('顶部动作按写权限档分档(emit 给页面接既有链)', () => {
it('可写档渲染「编辑/删除」:点击分别 emit edit/remove 且不冒泡成 close', async () => {
const wrapper = await mountOpened(true)
const actions = wrapper.get('.jd-modal-actions')
const buttons = actions.findAll('button')
expect(buttons.map((b) => b.text())).toEqual(['编辑', '删除'])
await buttons[0]!.trigger('click')
expect(wrapper.emitted('edit')).toHaveLength(1)
expect(wrapper.emitted('close')).toBeFalsy()
await buttons[1]!.trigger('click')
expect(wrapper.emitted('remove')).toHaveLength(1)
expect(wrapper.emitted('close')).toBeFalsy()
wrapper.unmount()
})
it('只读档(canWrite=false):无动作区(普通账号只读,与现表格操作列分档同口径)', async () => {
const wrapper = await mountOpened(false)
expect(wrapper.find('.jd-modal-actions').exists()).toBe(false)
expect(wrapper.findAll('button').map((b) => b.text())).not.toContain('编辑')
expect(wrapper.findAll('button').map((b) => b.text())).not.toContain('删除')
wrapper.unmount()
})
})
describe('加载失败与重试(取数在共享块,两条壳同一份兜底)', () => {
it('失败红条可见且重试真能重跑', async () => {
jdApi.fetchJdProductDetail.mockRejectedValueOnce(new Error('上游 502'))
jdApi.fetchJdProductDetail.mockResolvedValue(detailPayload())
const wrapper = mount(JdProductDetailModal, { props: { item: item(), visible: false, canWrite: true } })
await wrapper.setProps({ visible: true })
await flushPromises()
await flushPromises()
const bar = wrapper.get('.drawer-failure')
expect(bar.text()).toContain('上游 502', 'requestErrorMessage 透传后端/网络原因(与旧抽屉同一出口)')
expect(bar.find('button').text()).toBe('重试')
await bar.find('button').trigger('click')
await flushPromises()
await flushPromises()
expect(wrapper.find('.drawer-failure').exists()).toBe(false, '重试成功后红条消失')
expect(wrapper.get('.detail-hero').exists()).toBe(true)
wrapper.unmount()
})
})
@@ -0,0 +1,186 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import MenusPage from '@/pages/account/MenusPage.vue'
import type { MenuManageNode } from '@/pages/account/menu-manage-model'
import { useAdminSessionStore } from '@/stores/admin-session'
import { useCompanyTabStore } from '@/stores/company-tab'
import { usePlatformTabStore } from '@/stores/platform-tab'
const menuApi = vi.hoisted(() => ({
loadMenuManageTree: vi.fn(),
createMenu: vi.fn(),
updateMenu: vi.fn(),
deleteMenu: vi.fn(),
reorderMenus: vi.fn(),
}))
vi.mock('@/pages/account/menu-manage-api', () => menuApi)
/** 同一次加载返回完整字典,平台隔离由真实页面完成。 */
function mixedMenuTree(): MenuManageNode[] {
let nextId = 1
function node(
columnKey: string,
name: string,
menuType: 'admin' | 'app',
children: MenuManageNode[] = [],
): MenuManageNode {
const id = nextId++
return {
id, columnKey, name, menuType, parentId: null, routePath: '', sortOrder: id,
children: children.map((child) => ({ ...child, parentId: id })),
}
}
return [
node('video_image', '视频图片', 'app'),
node('admin_account', '账号与权限管理', 'admin', [
node('admin_columns', '菜单权限管理', 'admin'),
node('admin_users', '用户管理', 'admin'),
node('admin_group_manage', '分组管理', 'admin'),
node('admin_companies', '公司管理', 'admin'),
node('admin_user_secrets', '密钥管理', 'admin'),
node('admin_user_secret_usage', '密钥用量统计', 'admin'),
]),
node('admin_data', '数据管理', 'admin', [
node('admin_shop_manage', '店铺管理', 'admin'),
node('admin_appearance_patent', '外观专利管理', 'admin'),
node('admin_similar_asin', '相似ASIN管理', 'admin'),
node('admin_price_track', '跟价管理', 'admin'),
node('admin_collect_data', '采集数据管理', 'admin'),
node('admin_publish', '发布管理', 'admin'),
node('admin_brand', '品牌管理', 'admin'),
node('admin_records', '生成记录管理', 'admin'),
node('admin_jd_database', '京东数据库', 'admin'),
]),
node('jd_tools', '京东工具台', 'app', [
node('jd-collect', '京东店铺数据采集', 'app'),
node('jd-publish', '京东商品上架', 'app'),
]),
]
}
let pinia: Pinia
let wrapper: VueWrapper<Element> | undefined
let host: HTMLDivElement
beforeEach(() => {
vi.clearAllMocks()
window.localStorage.removeItem('admin-platform-tab')
pinia = createPinia()
setActivePinia(pinia)
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
useCompanyTabStore().setActiveId(7)
menuApi.loadMenuManageTree.mockResolvedValue(mixedMenuTree())
host = document.createElement('div')
document.body.appendChild(host)
})
afterEach(() => {
wrapper?.unmount()
wrapper = undefined
host.remove()
window.localStorage.removeItem('admin-platform-tab')
})
async function mountMenus() {
wrapper = mount(MenusPage, { attachTo: host, global: { plugins: [pinia, ElementPlus] } })
await flushPromises()
expect(menuApi.loadMenuManageTree).toHaveBeenCalledWith(7)
return wrapper
}
function visibleNames(page: VueWrapper<Element>) {
return page.findAll('tbody .menu-name-text').map((cell) => cell.text())
}
async function clickNextPage(page: VueWrapper<Element>) {
const next = page.findAll('.old-pagination button').find((button) => button.text() === '下一页')
expect(next).toBeTruthy()
expect(next!.attributes('disabled')).toBeUndefined()
await next!.trigger('click')
await flushPromises()
}
/** 通过真实分页收齐表格行,避免只检查首屏而漏掉后页的跨平台菜单。 */
async function allVisibleNames(page: VueWrapper<Element>) {
const names = visibleNames(page)
while (true) {
const next = page.findAll('.old-pagination button').find((button) => button.text() === '下一页')
if (!next || next.attributes('disabled') !== undefined) return names
await clickNextPage(page)
names.push(...visibleNames(page))
}
}
async function pickMenuType(page: VueWrapper<Element>, label: string) {
const input = page.get('[aria-label="筛选菜单类型"]')
await input.trigger('click')
await flushPromises()
const contentId = input.attributes('aria-controls')
const panel = contentId ? document.getElementById(contentId) : null
expect(panel).toBeTruthy()
const option = [...panel!.querySelectorAll('.el-select-dropdown__item')]
.find((item) => !item.classList.contains('is-hidden') && item.textContent?.trim() === label)
expect(option).toBeTruthy()
await new DOMWrapper(option!).trigger('click')
await flushPromises()
}
describe('菜单权限配置页的平台隔离', () => {
it('京东表格排除视频图片和密钥,保留账号基础菜单、数据管理祖先及京东工具', async () => {
usePlatformTabStore().setActive('jd')
const page = await mountMenus()
expect(await allVisibleNames(page)).toEqual([
'账号与权限管理', '菜单权限管理', '用户管理', '分组管理', '公司管理',
'数据管理', '京东数据库', '京东工具台', '京东店铺数据采集', '京东商品上架',
])
const databaseRow = page.findAll('tbody tr')
.find((row) => row.find('.menu-name-text').text() === '京东数据库')
expect(databaseRow!.findAll('td')[5].text()).toBe('数据管理')
expect(databaseRow!.find('.column-child-mark').exists()).toBe(true)
})
it('从京东切回亚马逊,视频图片和密钥仍在,京东数据库及京东工具均消失', async () => {
usePlatformTabStore().setActive('jd')
const page = await mountMenus()
usePlatformTabStore().setActive('amazon')
await flushPromises()
expect(await allVisibleNames(page)).toEqual([
'视频图片', '账号与权限管理', '菜单权限管理', '用户管理', '分组管理', '公司管理',
'密钥管理', '密钥用量统计', '数据管理', '店铺管理', '外观专利管理',
'相似ASIN管理', '跟价管理', '采集数据管理', '发布管理', '品牌管理', '生成记录管理',
])
expect(menuApi.loadMenuManageTree).toHaveBeenCalledTimes(1)
})
it('带名称和类型筛选进入第二页后切平台,回到第一页并清空两项筛选', async () => {
const page = await mountMenus()
const nameInput = page.get<HTMLInputElement>('input[placeholder="输入菜单名称"]')
await nameInput.setValue('管理')
await pickMenuType(page, '后台')
expect(page.findAll('.menus-filter-row .el-select__selected-item').map((item) => item.text())).toContain('后台')
expect(page.findAll('tbody .menu-type-text').every((cell) => cell.text() === '后台')).toBe(true)
await clickNextPage(page)
expect(page.get('.page-cur').text()).toBe('第 2 / 2 页')
expect(visibleNames(page).length).toBeGreaterThan(0)
expect(visibleNames(page).every((name) => name.includes('管理'))).toBe(true)
usePlatformTabStore().setActive('jd')
await flushPromises()
expect(nameInput.element.value).toBe('')
expect(page.findAll('.menus-filter-row .el-select__selected-item').map((item) => item.text())).toContain('全部')
expect(page.get('.page-cur').text()).toBe('第 1 / 1 页')
expect(page.get('.page-total').text()).toBe('共 10 条')
expect(visibleNames(page)).toEqual([
'账号与权限管理', '菜单权限管理', '用户管理', '分组管理', '公司管理',
'数据管理', '京东数据库', '京东工具台', '京东店铺数据采集', '京东商品上架',
])
expect(menuApi.loadMenuManageTree).toHaveBeenCalledTimes(1)
})
})
@@ -0,0 +1,45 @@
import { beforeEach, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import QueryAsinPage from '@/pages/asin/QueryAsinPage.vue'
import { useAdminSessionStore } from '@/stores/admin-session'
const api = vi.hoisted(() => ({
fetchQueryAsinList: vi.fn(),
deleteQueryAsinCountryAsin: vi.fn(),
openAdminConfirm: vi.fn(),
}))
vi.mock('@/pages/asin/query-asin-api.ts', () => ({ ...api, createQueryAsin: vi.fn(), fetchShopNamesByGroup: vi.fn() }))
vi.mock('@/pages/asin/query-asin-detail-api.ts', () => ({ ...api, updateQueryAsinCountryAsin: vi.fn() }))
vi.mock('@/pages/shop/shop-manage-api.ts', () => ({ fetchShopManageGroups: vi.fn().mockResolvedValue([]) }))
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: api.openAdminConfirm }))
beforeEach(() => {
vi.resetAllMocks()
setActivePinia(createPinia())
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
})
it('多站点店铺只占一个勾选;部分站点失败时,重试不重删成功站点', async () => {
const shop = { id: 7, shopName: '甲店', groupName: '甲组', asinDe: 'B000000001', asinUk: 'B000000002' }
api.fetchQueryAsinList.mockResolvedValue({ page: 1, total: 1, items: [shop] })
api.deleteQueryAsinCountryAsin.mockResolvedValueOnce(undefined).mockRejectedValueOnce(new Error('暂时无法删除英国站'))
api.openAdminConfirm.mockResolvedValue(true)
const wrapper = mount(QueryAsinPage, { global: { stubs: ['el-select', 'el-option', 'el-dialog', 'el-drawer', 'el-progress'] } })
await flushPromises()
expect(wrapper.findAll('tbody .batch-delete-checkbox')).toHaveLength(1)
expect(wrapper.get('tbody .batch-delete-cell').attributes('rowspan')).toBe('2')
await wrapper.get('thead .batch-delete-checkbox').setValue(true)
const button = wrapper.get('.batch-delete-actions .btn-danger')
expect(button.text()).toBe('批量删除(1)')
await button.trigger('click')
await flushPromises()
expect(api.openAdminConfirm).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('全部站点') }))
expect(api.deleteQueryAsinCountryAsin.mock.calls).toEqual([[7, 'DE'], [7, 'UK']])
expect(wrapper.get('details').text()).toContain('暂时无法删除英国站')
await button.trigger('click')
await flushPromises()
expect(api.deleteQueryAsinCountryAsin.mock.calls).toEqual([[7, 'DE'], [7, 'UK'], [7, 'UK']])
expect(button.text()).toBe('批量删除(0)')
wrapper.unmount()
})
@@ -28,6 +28,22 @@ const secretsApi = vi.hoisted(() => ({
}))
vi.mock('@/api/user-secrets', () => secretsApi)
const confirmBatch = vi.hoisted(() => vi.fn())
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmBatch }))
it('批量清空点名全部密钥与代理,只调用用户级清空接口', async () => {
const wrapper = await mountWith([row(7), row(8)])
confirmBatch.mockResolvedValue(true)
secretsApi.deleteUserSecret.mockResolvedValue(undefined)
await wrapper.get('thead .batch-delete-checkbox').setValue(true)
await wrapper.get('.batch-delete-actions .btn-danger').trigger('click')
await flushPromises()
expect(confirmBatch).toHaveBeenCalledWith(expect.objectContaining({ danger: true, message: expect.stringContaining('全部密钥与代理配置') }))
expect(secretsApi.deleteUserSecret.mock.calls).toEqual([[7], [8]])
expect(secretsApi.clearUserSecretModule).not.toHaveBeenCalled()
expect(wrapper.get('.batch-delete-actions .btn-danger').text()).toBe('批量清空(0)')
wrapper.unmount()
})
function moduleCell(moduleKey: string, over: Record<string, unknown> = {}) {
return {
@@ -122,7 +138,7 @@ describe('余额两列接在密钥管理列表上', () => {
const headerCount = wrapper.findAll('thead th').length
const cellCount = wrapper.findAll('tbody tr')[0].findAll('td').length
expect(cellCount, '每行的 td 数必须等于表头列数').toBe(headerCount)
expect(headerCount).toBe(12)
expect(headerCount).toBe(13)
const emptyWrapper = await mountWith([])
const colspan = Number(emptyWrapper.find('tbody td').attributes('colspan'))
@@ -133,7 +149,7 @@ describe('余额两列接在密钥管理列表上', () => {
useAdminSessionStore().user = { id: 2, username: 'leader', role: 'admin' }
const wrapper = await mountWith([row(7)])
const headerCount = wrapper.findAll('thead th').length
expect(headerCount).toBe(11)
expect(headerCount).toBe(12)
expect(wrapper.findAll('tbody tr')[0].findAll('td').length).toBe(headerCount)
const emptyWrapper = await mountWith([])
@@ -21,6 +21,8 @@ const usersApi = vi.hoisted(() => ({
}))
vi.mock('@/api/users', () => usersApi)
const confirmBatch = vi.hoisted(() => vi.fn())
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmBatch }))
vi.mock('@/api/companies', () => ({ fetchCompanies: vi.fn().mockResolvedValue([]) }))
vi.mock('@/pages/account/user-menu-auth-api', () => ({ loadUserMenuAuth: vi.fn() }))
@@ -48,6 +50,45 @@ beforeEach(() => {
const session = useAdminSessionStore()
session.user = { id: 1, username: 'root', role: 'super_admin' }
usersApi.fetchUserList.mockResolvedValue(pageOf())
usersApi.deleteUser.mockReset().mockResolvedValue(undefined)
confirmBatch.mockReset().mockResolvedValue(false)
})
it('批量删除取消不发请求;部分失败只保留失败用户', async () => {
usersApi.deleteUser.mockRejectedValueOnce(new Error('无权删除此用户'))
const wrapper = mount(UsersPage)
await flushPromises()
const button = wrapper.get('.batch-delete-actions .btn-danger')
expect(button.attributes('disabled')).toBeDefined()
await wrapper.get('input[aria-label="选择 京东号"]').setValue(true)
await wrapper.get('input[aria-label="选择 存量号"]').setValue(true)
await button.trigger('click')
await flushPromises()
expect(confirmBatch).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('京东号、存量号') }))
expect(usersApi.deleteUser).not.toHaveBeenCalled()
confirmBatch.mockResolvedValue(true)
await button.trigger('click')
await flushPromises()
expect(usersApi.deleteUser.mock.calls).toEqual([[7], [8]])
expect(button.text()).toBe('批量删除(1)')
expect(wrapper.get('details').text()).toContain('京东号:无权删除此用户')
expect(usersApi.fetchUserList).toHaveBeenCalledTimes(2)
wrapper.unmount()
})
it('确认弹窗期间切平台,旧勾选不发删除请求', async () => {
let resolveConfirm!: (ok: boolean) => void
confirmBatch.mockReturnValue(new Promise<boolean>((resolve) => { resolveConfirm = resolve }))
const wrapper = mount(UsersPage)
await flushPromises()
await wrapper.get('input[aria-label="选择 京东号"]').setValue(true)
await wrapper.get('.batch-delete-actions .btn-danger').trigger('click')
usePlatformTabStore().setActive('jd')
resolveConfirm(true)
await flushPromises()
expect(usersApi.deleteUser).not.toHaveBeenCalled()
expect(wrapper.get('.batch-delete-actions .btn-danger').text()).toBe('批量删除(0)')
wrapper.unmount()
})
describe('UsersPage × 平台 tab(V206)', () => {
@@ -60,8 +101,8 @@ describe('UsersPage × 平台 tab(V206)', () => {
expect(params).toHaveProperty('companyId')
const headers = wrapper.findAll('thead th').map((th) => th.text())
expect(headers).not.toContain('上架上限')
// 亚马逊侧表头 9 列(存量表头,quota 列不渲染)
expect(headers.length).toBe(9)
// 亚马逊侧保留原有 9 列,另加 1 列批量选择。
expect(headers.length).toBe(10)
wrapper.unmount()
})
@@ -78,12 +119,11 @@ describe('UsersPage × 平台 tab(V206)', () => {
const headers = wrapper.findAll('thead th').map((th) => th.text())
expect(headers).toContain('上架上限')
expect(headers.length).toBe(10)
expect(headers.length).toBe(11)
// quota 单元格:0=不限(存量号 8),null/缺省=-(京东号 7、没配号 10),800 原样
const quotaCells = wrapper.findAll('tbody tr').map((tr) => {
const tds = tr.findAll('td')
// 上架上限列在第 5 列(ID/用户名/角色/所属管理员/到期时间 之后)
return tds[5]?.text()
return tds[6]?.text()
})
expect(quotaCells).toEqual(['-', '不限', '800', '-'])
wrapper.unmount()
@@ -118,7 +118,7 @@ function opsColDecl(source: string): string | null {
}
function sourcesOfAll(): Array<{ file: string; source: string }> {
return vueFiles(SRC).map((file) => ({ file, source: readSource(file) }))
return vueFiles(SRC).map((file) => ({ file, source: readSource(file, true) }))
}
test('ops_ruler_actually_sees_the_family', () => {
@@ -13,20 +13,22 @@ import { toCompanyPayload } from '../src/api/companies-dto.ts'
/**
* 账号域三页按平台 tab 分列(V206,2026-11-17 用户口径「这些亚马逊这边也要有……数据都是新的
* 别把亚马逊的带过来」):users/company/biz_shop_manage_group 三表加 platform 列,存量默认亚马逊;
* 前端同一套组件两 tab 共显,请求带 platform=当前 tab,弹窗单选默认当前平台、可翻档归侧。
* 前端同一套组件两 tab 共显,请求带 platform=当前 tab。
* 平台不设手选(2026-11-17 用户口径「有京东就不需要亚马逊了,亚马逊那边也是」):弹窗不再出
* 「所属平台」单选——新建取当前平台 tab,编辑保持行值;值仍随保存下发(后端契约不变)。
* 上架上限(jd_publish_quota)只属京东口径:编辑弹窗隐藏 + 校验/下发都跳过 + 列表列仅京东侧。
*/
// ---------- 纯函数:payload 的 platform 下发与翻档 ----------
// ---------- 纯函数:payload 的 platform 下发 ----------
test('建号 payload 恒带 platform:京东 tab 建的号默认归京东,单选翻档即改归属', () => {
test('建号 payload 恒带 platform:京东 tab 建的号默认归京东(平台跟随当前 tab,弹窗不手选)', () => {
const jd = toCreateUserRequest({ ...createEmptyCreateUserForm(), username: 'a', password: 'secret123', platform: 'jd' })
assert.equal(jd.platform, 'jd')
const amazon = toCreateUserRequest({ ...createEmptyCreateUserForm(), username: 'a', password: 'secret123' })
assert.equal(amazon.platform, 'amazon', '空表单缺省亚马逊(存量口径),后端 normalizeOrCreate 同口径兜底')
})
test('编辑回填 platform:行值 jd→jd,缺省/未知→amazon;请求体恒下发 platform(翻档即挪列)', () => {
test('编辑回填 platform:行值 jd→jd,缺省/未知→amazon;请求体恒下发 platform(编辑保持行值)', () => {
const jdForm = fillEditUserForm({ id: 7, username: '京东号', role: 'normal', platform: 'jd' })
assert.equal(jdForm.platform, 'jd')
assert.equal(toEditUserUpdateRequest(jdForm).platform, 'jd')
@@ -34,7 +36,7 @@ test('编辑回填 platform:行值 jd→jd,缺省/未知→amazon;请求
const legacy = fillEditUserForm({ id: 8, username: '存量号', role: 'normal' })
assert.equal(legacy.platform, 'amazon', '旧负载没有 platform 时归亚马逊(存量默认),不许渲染成空串')
assert.equal(toEditUserUpdateRequest(legacy).platform, 'amazon', 'platform 恒下发:单选恒渲染,后端显式才落')
assert.equal(toEditUserUpdateRequest(legacy).platform, 'amazon', 'platform 恒下发:编辑保持行值,后端显式才落')
})
test('includeQuota=false(亚马逊侧编辑):不下发 jdPublishQuota,校验也跳过;platform 照常下发', () => {
@@ -97,7 +99,7 @@ test('CompaniesPage:公司列表带平台、切平台重取数、编辑弹窗
assert.match(page, /:platform="platformTab\.active"/, '新建公司弹窗默认落当前平台')
})
test('EditUserDialog:上架上限仅京东侧显示且不参与亚马逊侧提交;所属平台单选恒在', () => {
test('EditUserDialog:上架上限仅京东侧显示且不参与亚马逊侧提交;所属平台不设手选', () => {
const dialog = readSource('src/pages/account/EditUserDialog.vue')
assert.match(dialog, /v-if="includeQuota && \(targetIsCompanySuperAdmin \|\| form\.role === 'admin'\)"/,
'quota 项必须叠上 includeQuota(京东侧)条件——只按角色判断会把该项带进亚马逊侧弹窗')
@@ -105,26 +107,30 @@ test('EditUserDialog:上架上限仅京东侧显示且不参与亚马逊侧提
'提交必须透传 includeQuota:亚马逊侧校验与下发都跳过 quota')
assert.match(dialog, /validateEditUserForm\(form, \{ includeQuota: includeQuota\.value \}\)/,
'校验与下发同口径(校验过了但不下发 = 静默改值)')
assert.match(dialog, /v-model="form\.platform"/, '所属平台单选恒在:翻档是把记录挪到另一平台列表的唯一入口')
assert.doesNotMatch(dialog, /v-model="form\.platform"/,
'所属平台不设手选(2026-11-17 用户口径):平台跟随当前平台 tab,把单选写回来即红')
assert.match(dialog, /props\.platform === 'jd'/, 'includeQuota 取自页面透传的当前平台')
assert.match(dialog, /form\.platform = base\.platform/, '打开弹窗必须回填行值(旧负载缺省归亚马逊)')
assert.match(dialog, /form\.platform = base\.platform/, '打开弹窗必须回填行值(旧负载缺省归亚马逊;保存原样下发)')
})
test('CreateUserDialog/GroupEditorDialog/CompanyEditorDialog:新建默认当前平台、编辑回填行值', () => {
test('CreateUserDialog/GroupEditorDialog/CompanyEditorDialog:平台不设手选,新建默认当前平台、编辑回填行值', () => {
const create = readSource('src/pages/account/CreateUserDialog.vue')
assert.match(create, /form\.platform = props\.platform \?\? 'amazon'/, '建号默认当前平台 tab')
assert.match(create, /v-model="form\.platform"/, '所属平台单选在')
assert.doesNotMatch(create, /v-model="form\.platform"/,
'建号弹窗不设平台手选(2026-11-17 用户口径):把单选写回来即红')
const group = readSource('src/pages/account/GroupEditorDialog.vue')
assert.match(group, /groupPlatform\.value = props\.platform \?\? 'amazon'/, '新建分组默认当前平台 tab')
assert.match(group, /props\.group\.platform === 'jd' \? 'jd' : 'amazon'/, '编辑分组回填行值')
assert.match(group, /createShopGroup\(groupName\.value, memberIds\.value, operatorId, groupPlatform\.value\)/,
'创建分组必须带平台')
assert.doesNotMatch(group, /v-model="groupPlatform"/, '分组弹窗不设平台手选:把单选写回来即红')
assert.match(group, /createShopGroup\(groupName\.value, memberIds\.value, leaderId, groupPlatform\.value\)/,
'创建分组必须带平台(createdById=所选组长,2026-11-18 起超管可改选)')
assert.match(group, /updateShopGroup\(props\.group\.id, groupName\.value, memberIds\.value, groupPlatform\.value\)/,
'更新分组必须带平台(翻档归侧)')
'更新分组必须带平台(编辑保持行值下发)')
assert.doesNotMatch(group, /companyTab/, '分组弹窗不读公司 tab(既有口径:候选按组长公司取人)')
const company = readSource('src/pages/account/CompanyEditorDialog.vue')
assert.match(company, /platform: props\.platform \?\? 'amazon'/, '新建公司默认当前平台 tab')
assert.match(company, /props\.company\.platform === 'jd' \? 'jd' : 'amazon'/, '编辑公司回填行值')
assert.doesNotMatch(company, /v-model="form\.platform"/, '公司弹窗不设平台手选:把单选写回来即红')
})
@@ -3,18 +3,19 @@ import assert from 'node:assert/strict'
import type { AdminMenuNode } from '../src/types/admin.ts'
import {
BOTH_PLATFORM_MENU_KEYS,
JD_APP_MENU_KEYS,
JD_MENU_KEYS,
PLATFORM_TABS,
platformsOfMenuKey,
} from '../src/config/platform-scope.ts'
import { filterMenuTreeByPlatform, visiblePlatformsFor } from '../src/layout/platform-menu-filter.ts'
import { allowedPlatformsForUser, filterMenuTreeByPlatform, visiblePlatformsFor } from '../src/layout/platform-menu-filter.ts'
import { adminPages } from '../src/router/routes.ts'
/** 2026-11-16 用户定案「亚马逊/京东不混一起」:侧边栏顶部加平台 tab,京东侧=截图圈定
* 数据页(京东数据库/分类管理)。2026-11-17 用户口径「这些亚马逊这边也要有」:账号域三页
* (用户管理/分组管理/公司管理)改为双侧显示(BOTH_PLATFORM_MENU_KEYS),同一组件按当前
* tab 传 platform 过滤各自数据。tab 只做显示分组——菜单可见性仍由 session.menuTree(后端
* 按权限裁剪)决定,这里钉的是「分侧归属」与「空侧隐藏」两条形状。
* 按权限裁剪)决定,这里钉的是「分侧归属」「空侧隐藏」与「登录用户平台锁定」三条形状。
* 辅助定义在所有 test 之前:node:test 的用例回调按声明序执行,挪到文件尾会踩 TDZ。 */
const node = (key: string, name: string, route?: string, children?: AdminMenuNode[]): AdminMenuNode => {
@@ -53,17 +54,17 @@ test('menuKey 平台归属:京东独占即 [jd],双侧清单即两侧,其
for (const key of JD_MENU_KEYS) assert.deepEqual(platformsOfMenuKey(key), ['jd'], key)
for (const key of BOTH_PLATFORM_MENU_KEYS) assert.deepEqual(platformsOfMenuKey(key), ['amazon', 'jd'], key)
assert.deepEqual(platformsOfMenuKey('admin_query_asin'), ['amazon'])
assert.deepEqual(platformsOfMenuKey('admin_columns'), ['amazon'])
assert.deepEqual(platformsOfMenuKey('admin_columns'), ['amazon', 'jd'])
assert.deepEqual(platformsOfMenuKey('admin_group_account'), ['amazon'])
assert.deepEqual(platformsOfMenuKey('admin_jd_unknown_future'), ['amazon'])
assert.deepEqual(platformsOfMenuKey(''), ['amazon'])
})
test('京东 tab:账号与权限只余双侧三项,数据管理只余京东独占页(2026-11-17 分类管理并入京东数据库页后只剩数据库一页);顺序与 route 原样透传', () => {
test('京东 tab:账号与权限保留账号管理四项,隐藏密钥管理与用量统计;数据管理保留京东数据库', () => {
const filtered = filterMenuTreeByPlatform(TREE, 'jd')
assert.deepEqual(filtered.map((item) => item.key), ['admin_group_account', 'admin_group_data'])
assert.deepEqual(groupChildKeys(filtered, 'admin_group_account'),
['admin_users', 'admin_group_manage', 'admin_companies'])
['admin_columns', 'admin_users', 'admin_group_manage', 'admin_companies'])
// 2026-11-17 晚用户口径「京东分类管理并到京东数据库分类编辑里」:分类管理子菜单
// (V204)下线,京东侧数据管理组只剩京东数据库一页。
assert.deepEqual(groupChildKeys(filtered, 'admin_group_data'), ['admin_jd_database'])
@@ -115,7 +116,7 @@ test('tab 显示依据:两侧都有可见页才画 tab 条,仅一侧授权
assert.deepEqual(visiblePlatformsFor(null), [])
})
test('平台 tab 定义与两份菜单清单钉死(防清单漂移):京东独占仅数据库一页、双侧共用账号域三页', () => {
test('平台 tab 定义与菜单清单钉死(防清单漂移):京东独占后台仅数据库一页、双侧共用账号域三页、桌面端京东工具台三件(V209)', () => {
assert.deepEqual(PLATFORM_TABS, [
{ id: 'amazon', label: '亚马逊' },
{ id: 'jd', label: '京东' },
@@ -123,7 +124,12 @@ test('平台 tab 定义与两份菜单清单钉死(防清单漂移):京东
// 2026-11-17 晚分类管理(admin_jd_category_manage)并入京东数据库页后从清单摘除。
assert.deepEqual([...JD_MENU_KEYS], ['admin_jd_database'])
assert.deepEqual([...BOTH_PLATFORM_MENU_KEYS].sort(),
['admin_companies', 'admin_group_manage', 'admin_users'])
['admin_columns', 'admin_companies', 'admin_group_manage', 'admin_users'])
assert.deepEqual(platformsOfMenuKey('admin_user_secrets'), ['amazon'])
assert.deepEqual(platformsOfMenuKey('admin_user_secret_usage'), ['amazon'])
// 桌面端(app)清单与 JD_MENU_KEYS 分列:app 菜单没有 admin 路由,不得混进
// 「与 routes.ts 对撞」的那份(下方护栏用例只扫 JD_MENU_KEYS/BOTH 两份是刻意的)。
assert.deepEqual([...JD_APP_MENU_KEYS].sort(), ['jd-collect', 'jd-publish', 'jd_tools'])
})
test('两份清单的每一条都必须在路由注册表登记(同 company-menu-route 护栏形状:少登记=看得见点进去404)', () => {
@@ -132,3 +138,34 @@ test('两份清单的每一条都必须在路由注册表登记(同 company-me
assert.ok(registered.has(key), `平台侧菜单 key "${key}" 未在 src/router/routes.ts 登记 menuKey`)
}
})
test('allowedPlatformsForUser:站点超管随菜单树分布;其余用户锁 users.platform 一侧(未知/缺省按亚马逊)', () => {
assert.deepEqual(allowedPlatformsForUser(TREE, { role: 'super_admin', platform: 'jd' }), ['amazon', 'jd'],
'站点超管不限侧:双平台 tab 照画')
assert.deepEqual(allowedPlatformsForUser(TREE, { role: 'company_super_admin', platform: 'jd' }), ['jd'],
'京东用户锁京东侧:亚马逊 tab 消失(单侧时 tab 条整个隐藏)')
assert.deepEqual(allowedPlatformsForUser(TREE, { role: 'admin', platform: 'amazon' }), ['amazon'])
assert.deepEqual(allowedPlatformsForUser(TREE, { role: 'normal', platform: undefined }), ['amazon'],
'platform 缺省按亚马逊存量口径(与后端 AdminMenuPlatformScope.normalize 同形)')
assert.deepEqual(allowedPlatformsForUser(TREE, { role: 'company_super_admin', platform: 'weird' }), ['amazon'],
'未知平台值同样兜底亚马逊,不得读成京东侧')
assert.deepEqual(allowedPlatformsForUser(TREE, null), ['amazon', 'jd'],
'会话未就位(user 为空)按可见分布:锁定的收窄由 AdminLayout 在 user 就位后再做')
})
test('allowedPlatformsForUser:菜单树缺本平台页时仍锁死本人平台(宁空侧不放开被禁侧)', () => {
const amazonOnlyTree: AdminMenuNode[] = [
node('admin_group_data', '数据管理', undefined, [
node('admin_dedupe_total_data', '去重数据汇总', '/asin-center/registry'),
]),
]
assert.deepEqual(
allowedPlatformsForUser(amazonOnlyTree, { role: 'company_super_admin', platform: 'amazon' }),
['amazon'],
)
assert.deepEqual(
allowedPlatformsForUser(amazonOnlyTree, { role: 'company_super_admin', platform: 'jd' }),
['jd'],
'交集空回落单侧:管理角色必有双侧账号域页所以实际非空,异常形状下宁可空侧也不放开被禁侧',
)
})
+10 -4
View File
@@ -2,14 +2,20 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
// module 13 task 243:壳层换皮成 admin.html 蓝白浅色 —— 侧栏 252px 浅底、顶栏 76px、
// module 13 task 243:壳层换皮成 admin.html 蓝白浅色 —— 侧栏 252px 浅底、顶栏 56px、
// 角色胶囊 + 次级退出按钮、去掉顶栏重复 logo、菜单激活态浅蓝渐变+左蓝条。
test('test_task_243_shell_normal_primary_path', () => {
const css = readSource('src/styles/main.css')
assert.match(css, /\.admin-sidebar\s*\{[^}]*flex:\s*0\s*0\s*252px/, '侧栏宽度应为 252px')
assert.match(css, /\.admin-topbar\s*\{[^}]*min-height:\s*76px/, '顶栏高度应为 76px')
assert.match(css, /\.admin-topbar\s*\{[^}]*min-height:\s*56px/, '顶栏高度应为 56px')
assert.match(css, /linear-gradient\(180deg,\s*var\(--admin-sidebar\)\s*0%,/, '侧栏应为浅色渐变底')
// 壳层锁视口高(2026-11-18「菜单加个滚动条」绊线):.admin-shell 必须 height:100vh +
// overflow:hidden——侧边栏固定、菜单区 el-scrollbar 与内容区 overflow:auto 才能各自独立滚动;
// 改回 min-height 会把整条 flex 高度链放软、回落整页滚(侧边栏顶部被滚出视口)。
assert.match(css, /\.admin-shell\s*\{[^}]*height:\s*100vh/, '.admin-shell 必须锁视口高')
assert.match(css, /\.admin-shell\s*\{[^}]*overflow:\s*hidden/, '.admin-shell 必须 overflow:hidden')
assert.equal(/\.admin-shell\s*\{[^}]*min-height:\s*100vh/.test(css), false, '.admin-shell 不得回退 min-height:100vh')
})
test('test_task_243_shell_normal_variant_input', () => {
@@ -22,8 +28,8 @@ test('test_task_243_shell_normal_variant_input', () => {
test('test_task_243_shell_normal_repeated_operation_is_idempotent', () => {
const css = readSource('src/styles/main.css')
const first = /\.admin-topbar\s*\{[^}]*min-height:\s*76px/.test(css)
const second = /\.admin-topbar\s*\{[^}]*min-height:\s*76px/.test(css)
const first = /\.admin-topbar\s*\{[^}]*min-height:\s*56px/.test(css)
const second = /\.admin-topbar\s*\{[^}]*min-height:\s*56px/.test(css)
assert.equal(first, true)
assert.equal(first, second)
})

Some files were not shown because too many files have changed in this diff Show More