Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6dc33ea725 | |||
| b4e97823f4 | |||
| d25c91f6da | |||
| 20ee73349e | |||
| d28461d3d3 | |||
| 56fe32e8e9 | |||
| 283921df0c | |||
| 2078e9efde | |||
| 7299166e96 | |||
| 80060912ca |
@@ -2,6 +2,11 @@
|
||||
/** 旧版风格分页(像素复刻 admin.html .pagination)+ 每页条数下拉(10/20/50/100)。
|
||||
* props: total / page / pageSize / sizes(默认 10/20/50/100) / showTotal(默认 true) / jump(默认 true)。 */
|
||||
import { computed, ref } from 'vue'
|
||||
// 每页条数下拉 2026-11-17 用户口径「和亚马逊不统一」:原生 <select> 的弹层是浏览器直角
|
||||
// 原生物,全站分页条都有这一处 ⇒ 换 el-select(EP 圆角面板)。组件内局部导入,不与全局
|
||||
// 注册表耦合:任何挂载测试单独 mount 本组件都能正确渲染(不依赖外部 app.use)。
|
||||
// 样式已在 plugins/element.ts 里按组件全局引过,这里不重复引。
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -34,8 +39,7 @@ function goJump() {
|
||||
go(Math.min(Math.max(n, 1), totalPages.value))
|
||||
}
|
||||
|
||||
function onSizeChange(event: Event) {
|
||||
const value = Number((event.target as HTMLSelectElement).value)
|
||||
function onSizeChange(value: number) {
|
||||
if (Number.isFinite(value) && value > 0) emit('size-change', value)
|
||||
}
|
||||
</script>
|
||||
@@ -43,9 +47,16 @@ function onSizeChange(event: Event) {
|
||||
<template>
|
||||
<div class="old-pagination">
|
||||
<span v-if="showTotal" class="page-total">共 {{ total }} 条</span>
|
||||
<select class="page-size-select" :value="pageSize" @change="onSizeChange">
|
||||
<option v-for="size in sizes" :key="size" :value="size">{{ size }}条/页</option>
|
||||
</select>
|
||||
<!-- el-select 出厂宽度 100%(--el-select-width),进 flex 行会横涨 ⇒ 类里钉位宽。 -->
|
||||
<el-select
|
||||
class="page-size-select"
|
||||
:model-value="pageSize"
|
||||
size="small"
|
||||
aria-label="每页条数"
|
||||
@change="onSizeChange"
|
||||
>
|
||||
<el-option v-for="size in sizes" :key="size" :value="size" :label="`${size}条/页`" />
|
||||
</el-select>
|
||||
<button type="button" :disabled="page <= 1" @click="go(page - 1)">上一页</button>
|
||||
<span class="page-cur">第 {{ page }} / {{ totalPages }} 页</span>
|
||||
<button type="button" :disabled="page >= totalPages" @click="go(page + 1)">下一页</button>
|
||||
@@ -92,15 +103,22 @@ function onSizeChange(event: Event) {
|
||||
.page-total {
|
||||
margin-right: 4px;
|
||||
}
|
||||
/* 每页条数下拉:与原分页条同尺寸(30px 高、8px 圆角、#cbd9e6 描边、#f8fbfd 浅底)。
|
||||
外形走 .el-select__wrapper(EP 的结构类,scoped 需 :deep 穿透)。 */
|
||||
.page-size-select {
|
||||
width: 104px;
|
||||
}
|
||||
.page-size-select :deep(.el-select__wrapper) {
|
||||
min-height: 30px;
|
||||
padding: 3px 8px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 8px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
box-shadow: 0 0 0 1px #cbd9e6 inset;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
line-height: 22px;
|
||||
}
|
||||
.page-size-select :deep(.el-select__wrapper:hover) {
|
||||
box-shadow: 0 0 0 1px #9fb7cd inset;
|
||||
}
|
||||
.page-jump {
|
||||
display: inline-flex;
|
||||
|
||||
@@ -8,7 +8,7 @@ import { formatDateTime } from '@/utils/datetime'
|
||||
import { fetchCompanies } from '@/api/companies'
|
||||
import { COMPANY_STATUS_ACTIVE, type CompanyItem } from '@/api/companies-dto'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { refreshCompanyDirectory } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import CompanyEditorDialog from './CompanyEditorDialog.vue'
|
||||
@@ -18,9 +18,6 @@ import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
const session = useAdminSessionStore()
|
||||
// 平台 tab(V206):公司列表按当前平台过滤,新建默认落当前平台。
|
||||
const platformTab = usePlatformTabStore()
|
||||
// 公司 tab 条(2026-11-17 起按平台过滤)共用这一份目录:公司翻档/启停后必须强制重拉,
|
||||
// 否则 18 个页面的 tab 条端着旧名单,刚翻去京东的公司还挂在亚马逊侧。
|
||||
const companyTab = useCompanyTabStore()
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<CompanyItem[]>([])
|
||||
@@ -65,10 +62,13 @@ function openEdit(company: CompanyItem) {
|
||||
}
|
||||
|
||||
// 保存成功后:本页列表照常重拉,共享公司目录(tab 条)强制重拉一份。
|
||||
// 本页不参与公司隔离(控制方 2026-10-06「公司管理不要有 tab」)⇒ 走 store 的具名出口
|
||||
// refreshCompanyDirectory,而不是自己持一份 company-tab store(后者形状与「给这页上了 tab」
|
||||
// 分不开,company-config-entry-super-only 的 pageFiles 分母会当场红)。
|
||||
// 重拉失败不弹新提示(§12 第 5 条未批的界面暴露):tab 条保留旧名单,下一次切平台 tab / 重进页面会再试。
|
||||
async function onCompaniesSaved() {
|
||||
await loadCompanies()
|
||||
companyTab.refresh().catch((error: unknown) => {
|
||||
refreshCompanyDirectory().catch((error: unknown) => {
|
||||
console.warn('[company-tab] 公司保存后目录重拉失败', error)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -228,8 +228,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -243,12 +242,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -236,11 +236,15 @@ onMounted(loadMenus)
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 160px">
|
||||
<label>菜单类型</label>
|
||||
<select v-model="filterType">
|
||||
<option value="">全部</option>
|
||||
<option value="admin">后台</option>
|
||||
<option value="app">软件</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(admin-filter 同壳 42px/9px 圆角,弹层是 EP 圆角面板)。
|
||||
「全部」保留为空值首行=空串不按类型筛(与旧原生下拉同语义);model 是空串时
|
||||
EP 不显示 label 而走 placeholder,所以 placeholder 同文案,观感与改前一致。 -->
|
||||
<el-select v-model="filterType" class="admin-filter" placeholder="全部" aria-label="筛选菜单类型">
|
||||
<el-option label="全部" value="" />
|
||||
<el-option label="后台" value="admin" />
|
||||
<el-option label="软件" value="app" />
|
||||
</el-select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -398,8 +402,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -413,12 +416,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -151,10 +151,14 @@ onMounted(load)
|
||||
</div>
|
||||
<div class="form-group" v-if="isSuperAdmin && groupOptions.length" style="min-width: 170px">
|
||||
<label>分组</label>
|
||||
<select v-model="groupFilter">
|
||||
<option :value="null">全部分组</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="group.id">{{ group.groupName }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(admin-filter 同壳 42px/9px 圆角,弹层是 EP 圆角面板),组多时可搜。
|
||||
「全部分组」的值仍是 null(下游 groupId 照旧 `|| undefined`),空档时由
|
||||
placeholder 显示同一句文案。 -->
|
||||
<el-select v-model="groupFilter" class="admin-filter" filterable placeholder="全部分组" aria-label="筛选分组">
|
||||
<el-option label="全部分组" :value="null" />
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.groupName" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label> </label>
|
||||
@@ -290,8 +294,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -305,12 +308,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -324,16 +324,23 @@ onMounted(load)
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 170px">
|
||||
<label>状态(三项都通过才算通过)</label>
|
||||
<select v-model="statusFilter">
|
||||
<option v-for="option in STATUS_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(admin-filter 同壳 42px/9px 圆角,弹层是 EP 圆角面板)。
|
||||
「全部状态」仍是 STATUS_OPTIONS 里的空串档(下游 checkStatus 照旧传 ''→undefined);
|
||||
model 为空串时 EP 走 placeholder 显示,故 placeholder 与首档同文案。 -->
|
||||
<el-select v-model="statusFilter" class="admin-filter" placeholder="全部状态" aria-label="筛选密钥状态">
|
||||
<el-option v-for="option in STATUS_OPTIONS" :key="option.value" :label="option.label" :value="option.value" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" v-if="isSuperAdmin && groupOptions.length" style="min-width: 170px">
|
||||
<label>分组</label>
|
||||
<select v-model="groupFilter">
|
||||
<option :value="null">全部分组</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="group.id">{{ group.groupName }}</option>
|
||||
</select>
|
||||
<!-- 同上(2026-11-17 换 el-select):分组可能很多 ⇒ 保留 filterable 可搜。
|
||||
「全部分组」的值仍是 null(下游 groupId 照旧 `|| undefined`),空档时由
|
||||
placeholder 显示同一句文案。 -->
|
||||
<el-select v-model="groupFilter" class="admin-filter" filterable placeholder="全部分组" aria-label="筛选分组">
|
||||
<el-option label="全部分组" :value="null" />
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.groupName" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label> </label>
|
||||
@@ -553,8 +560,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -568,12 +574,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -390,8 +390,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -405,12 +404,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -290,8 +290,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -305,12 +304,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -70,6 +70,10 @@ const editSaving = ref(false)
|
||||
const editTarget = ref<DedupeTotalItem | null>(null)
|
||||
const editValue = ref('')
|
||||
const editGroupId = ref<number | null>(null)
|
||||
/** 弹窗分组下拉的清空回填值:EP 的 el-select 默认清空写 undefined,会破 editGroupId/importGroupId
|
||||
* 的 `number | null` 契约(下游 saveEdit/importValid 按假值判「未选」、updateDedupeTotal 的入参是 number)
|
||||
* ⇒ 清空一律钉回 null,与旧原生 select 空行(value=null)同语义。 */
|
||||
const nullOnClear = (): null => null
|
||||
|
||||
type ImportMode = 'add' | 'delete'
|
||||
const importVisible = ref(false)
|
||||
@@ -373,10 +377,14 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in ASIN_COUNTRY_CODES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(admin-filter 与亚马逊面同壳 42px/9px,弹层是 EP 圆角面板)。
|
||||
「全部国家」保留为空值首行(value="" 与改前同语义,下发参数仍是空串=不限);
|
||||
EP 把 '' 当空值 ⇒ 闭壳显示 placeholder,因此同时钉 placeholder="全部国家",视觉不变。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" filterable placeholder="全部国家" aria-label="筛选国家">
|
||||
<el-option label="全部国家" value="" />
|
||||
<el-option v-for="code in ASIN_COUNTRY_CODES" :key="code" :label="asinCountryLabel(code)" :value="code" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="dedupe-filter-actions">
|
||||
<button class="btn" type="button" @click="apply">查询</button>
|
||||
@@ -452,10 +460,23 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<select v-model="editGroupId" :disabled="lockedGroupId != null">
|
||||
<option disabled :value="null">请选择分组</option>
|
||||
<option v-for="group in groups" :key="group.id" :value="group.id">{{ group.name }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物 ⇒ el-select。
|
||||
「未选」语义:原写法是 disabled 的空行(:value="null",选中后不可回退),这里改成
|
||||
placeholder="请选择分组" + clearable,并用 :value-on-clear 把清空值钉回 null
|
||||
(理由见上方 nullOnClear 注释:EP 默认回 undefined 会破 number | null 契约)。
|
||||
值域仍是 null 或分组 id(number),下游 editGroupId 的假值判断与入参形状不变;
|
||||
非超管单分组时照旧锁定展示(:disabled 与护栏测试钉住的写法一致)。 -->
|
||||
<el-select
|
||||
v-model="editGroupId"
|
||||
class="admin-filter"
|
||||
placeholder="请选择分组"
|
||||
clearable
|
||||
:value-on-clear="nullOnClear"
|
||||
:disabled="lockedGroupId != null"
|
||||
aria-label="编辑分组"
|
||||
>
|
||||
<el-option v-for="group in groups" :key="group.id" :label="group.name" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<button class="btn" type="button" :disabled="editSaving" @click="saveEdit">保存</button>
|
||||
@@ -473,10 +494,20 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<select v-model="importGroupId" :disabled="importRunning || lockedGroupId != null">
|
||||
<option disabled :value="null">请选择分组</option>
|
||||
<option v-for="group in groups" :key="group.id" :value="group.id">{{ group.name }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物 ⇒ el-select。
|
||||
与编辑弹窗同款「未选」处理(placeholder + clearable + 清空钉回 null),
|
||||
导入锁定条件(importRunning 或单分组)照旧挂在 :disabled 上。 -->
|
||||
<el-select
|
||||
v-model="importGroupId"
|
||||
class="admin-filter"
|
||||
placeholder="请选择分组"
|
||||
clearable
|
||||
:value-on-clear="nullOnClear"
|
||||
:disabled="importRunning || lockedGroupId != null"
|
||||
aria-label="导入分组"
|
||||
>
|
||||
<el-option v-for="group in groups" :key="group.id" :label="group.name" :value="group.id" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div v-if="importProgress" class="progress-wrap">
|
||||
<div class="progress-text">{{ importProgress }}</div>
|
||||
@@ -591,8 +622,9 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
/* 下拉壳由全局 .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;
|
||||
@@ -606,12 +638,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -387,10 +387,14 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in QUERY_ASIN_COUNTRIES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(与上面分组同一套 admin-filter 壳 42px/9px,弹层是 EP 圆角面板)。
|
||||
「全部国家」保留为空值首行(value="" 与改前同语义,下发仍是空串=不限);
|
||||
EP 把 '' 视作空值 ⇒ 闭壳走 placeholder,因此同步钉 placeholder="全部国家" 保持文案。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" filterable placeholder="全部国家" aria-label="筛选国家">
|
||||
<el-option label="全部国家" value="" />
|
||||
<el-option v-for="code in QUERY_ASIN_COUNTRIES" :key="code" :label="asinCountryLabel(code)" :value="code" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>ASIN</label>
|
||||
@@ -582,8 +586,9 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
/* 下拉壳由全局 .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;
|
||||
@@ -597,12 +602,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -432,10 +432,14 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in COUNTRIES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 的弹层是浏览器直角原生物
|
||||
⇒ 换 el-select(与上面分组同一套 admin-filter 壳 42px/9px,弹层是 EP 圆角面板)。
|
||||
「全部国家」保留为空值首行(value="" 与改前同语义,下发仍是空串=不限);
|
||||
EP 把 '' 视作空值 ⇒ 闭壳走 placeholder,因此同步钉 placeholder="全部国家" 保持文案。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" filterable placeholder="全部国家" aria-label="筛选国家">
|
||||
<el-option label="全部国家" value="" />
|
||||
<el-option v-for="code in COUNTRIES" :key="code" :label="asinCountryLabel(code)" :value="code" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>ASIN</label>
|
||||
@@ -646,8 +650,9 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
/* 下拉壳由全局 .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;
|
||||
@@ -661,12 +666,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -38,6 +38,12 @@ const errorText = ref('')
|
||||
const groups = ref<JdProductGroup[]>([])
|
||||
/** 搜索:按分类名称包含过滤(本地过滤,不另发请求)。 */
|
||||
const keyword = ref('')
|
||||
/** 分页(2026-11-17 用户口径「分类这也要加分页」):分类与父页「分类」下拉共用同一条全量
|
||||
* 接口(下拉必须全量,不能分页),所以这里做本地切片;搜索同样是本地过滤 ⇒ 分页与搜索
|
||||
* 同源,不会出现「先 limit 再过滤」那种翻页永久漏项。每页 6 行:实测 8 行在 700px 高的
|
||||
* 视口里会顶出列表内滚动条(滚动条与页码条并存很难看),6 行矮屏也一屏放得下。 */
|
||||
const PAGE_SIZE = 6
|
||||
const pageNo = ref(1)
|
||||
/** 新建:只收名称(排序输入 2026-11-15 客户口径下线,sortOrder 恒 0,后端契约不变)。 */
|
||||
const createName = ref('')
|
||||
const creating = ref(false)
|
||||
@@ -53,6 +59,20 @@ const filteredGroups = computed(() => {
|
||||
if (!kw) return groups.value
|
||||
return groups.value.filter((group) => group.name.toLowerCase().includes(kw))
|
||||
})
|
||||
/** 总页数(至少 1 页:空列表时页码条不渲染,但钳制逻辑要有个有效上界)。 */
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(filteredGroups.value.length / PAGE_SIZE)))
|
||||
/** 当前页的行(在搜索命中集上切片)。 */
|
||||
const pagedGroups = computed(() => {
|
||||
const start = (pageNo.value - 1) * PAGE_SIZE
|
||||
return filteredGroups.value.slice(start, start + PAGE_SIZE)
|
||||
})
|
||||
/** 只有超过一页才出页码条:一屏装得下时不白占一行。 */
|
||||
const showPager = computed(() => filteredGroups.value.length > PAGE_SIZE)
|
||||
|
||||
/** 翻页:页码钳在 [1, totalPages](删除/搜索后越界不会翻到空白页)。 */
|
||||
function goPage(target: number): void {
|
||||
pageNo.value = Math.min(Math.max(1, target), totalPages.value)
|
||||
}
|
||||
/** 空表文案分四种:不属于任何组 / 本组没分类(可管理)/ 本组没分类(只读)/ 搜索无命中。 */
|
||||
const emptyListText = computed(() => {
|
||||
if (props.ownerGroupId <= 0) return '你还不属于任何数据权限分组'
|
||||
@@ -157,12 +177,22 @@ watch(
|
||||
loadFailure.value = ''
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
pageNo.value = 1
|
||||
void loadGroups()
|
||||
}
|
||||
},
|
||||
// immediate:对话框可能以 visible=true 直接挂载(测试/复用场景),这时也要首取。
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/** 改关键字回第一页(命中集变了,停在旧页码会落在空白处)。 */
|
||||
watch(keyword, () => {
|
||||
pageNo.value = 1
|
||||
})
|
||||
/** 命中集变少(删掉最后一条/搜索收窄)后把越界页码钳回最后一页。 */
|
||||
watch(totalPages, (pages) => {
|
||||
if (pageNo.value > pages) pageNo.value = pages
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -190,7 +220,7 @@ watch(
|
||||
|
||||
<ul class="option-list">
|
||||
<template v-if="filteredGroups.length">
|
||||
<li v-for="group in filteredGroups" :key="group.id" class="option-row">
|
||||
<li v-for="group in pagedGroups" :key="group.id" class="option-row">
|
||||
<template v-if="editingId === group.id">
|
||||
<input v-model="editingName" class="rename-input" type="text" aria-label="分类新名称" @keyup.enter="submitRename(group)" />
|
||||
<span class="row-actions">
|
||||
@@ -212,6 +242,12 @@ watch(
|
||||
<li v-else class="manage-empty">{{ emptyListText }}</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="showPager" class="manage-pager">
|
||||
<button class="btn btn-sm btn-secondary" type="button" :disabled="pageNo <= 1" @click="goPage(pageNo - 1)">上一页</button>
|
||||
<span class="pager-text">第 {{ pageNo }} / {{ totalPages }} 页 · 共 {{ filteredGroups.length }} 个分类</span>
|
||||
<button class="btn btn-sm btn-secondary" type="button" :disabled="pageNo >= totalPages" @click="goPage(pageNo + 1)">下一页</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-foot">
|
||||
<button class="btn btn-secondary" type="button" @click="emit('close')">关闭</button>
|
||||
</div>
|
||||
@@ -234,7 +270,11 @@ watch(
|
||||
.manage-modal {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: min(480px, 100%);
|
||||
/* 2026-11-17 用户口径「宽度不需要那么宽」「红框大小就够了」:垂直排列后每行拉满,
|
||||
480/420 都显空荡;按用户红框量到约 340px(全局 main.css 有 `* { box-sizing: border-box }`,
|
||||
这个 width 就是含内边距与边框的总宽)。行内容(名称+商品数徽标+改名/删除)与页码条
|
||||
在 340−42=298px 可用宽度里仍放得下,不会挤换行。 */
|
||||
width: min(340px, 100%);
|
||||
max-height: 80vh;
|
||||
padding: 18px 20px 20px;
|
||||
border: 1px solid #c7d7e5;
|
||||
@@ -281,11 +321,12 @@ watch(
|
||||
font-size: 12.5px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
/* 2026-11-17 用户口径「垂直排阿,这样好看」「不然留白太多了」:搜索与新建各占整行
|
||||
(原来两件并排 flex:1 各挤一半宽),弹窗内容变高、列表下方空白收窄,两行输入等宽也更整齐。 */
|
||||
.manage-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.search-input,
|
||||
@@ -312,14 +353,12 @@ watch(
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
}
|
||||
.search-input {
|
||||
flex: 1;
|
||||
min-width: 140px;
|
||||
width: 100%;
|
||||
}
|
||||
.group-create {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
gap: 8px;
|
||||
min-width: 220px;
|
||||
width: 100%;
|
||||
}
|
||||
.group-create input {
|
||||
flex: 1;
|
||||
@@ -354,8 +393,11 @@ watch(
|
||||
.option-row:hover {
|
||||
background: #f1f7fb;
|
||||
}
|
||||
/* 名称不占剩余空间:它只包住自己的文字,数量徽标紧贴其后。
|
||||
剩余空间全部让给 row-actions 的 margin-left:auto(有操作时按钮仍靠右)。
|
||||
写回 flex:1 会让名称把空白吃满、把号码顶到行尾(2026-11-17 用户反馈「0 和名称离的有点远」)。 */
|
||||
.option-name {
|
||||
flex: 1;
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
@@ -375,6 +417,7 @@ watch(
|
||||
}
|
||||
.row-actions {
|
||||
flex: none;
|
||||
margin-left: auto;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.manage-empty {
|
||||
@@ -384,6 +427,18 @@ watch(
|
||||
font-size: 13px;
|
||||
list-style: none;
|
||||
}
|
||||
.manage-pager {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
}
|
||||
.pager-text {
|
||||
color: #5b6f83;
|
||||
font-size: 12.5px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.rename-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
@@ -189,6 +189,7 @@ async function load(): Promise<void> {
|
||||
titleKeyword: filter.titleKeyword,
|
||||
category: filter.category,
|
||||
groupId: filter.groupId,
|
||||
classified: filter.classified,
|
||||
ownerGroupId: ownerGroupId.value,
|
||||
syncedFrom: filter.syncedFrom,
|
||||
syncedTo: filter.syncedTo,
|
||||
@@ -358,16 +359,20 @@ onMounted(async () => {
|
||||
<label>分组</label>
|
||||
<!-- 当前分组(V203):能看多组的人(平台超管/公司超管)下拉切换;只有一组时锁定显示组名。
|
||||
2026-11-16 用户口径「做成分组」:从工具栏裸下拉上移进筛选行,做成带标签的表单控件
|
||||
(与其他筛选同壳同圆角)。分组是分类列/分类筛选/分类管理的作用域,不是筛选条件
|
||||
⇒ 放在筛选行也只是占位,「重置」不清它(挂载测试钉住)。 -->
|
||||
<select
|
||||
(与其他筛选同壳同圆角)。2026-11-17 用户口径「和亚马逊不统一」:原生 <select> 的
|
||||
弹层是浏览器直角原生物,换 el-select(同亚马逊面 admin-filter 同壳),组多时可搜索。
|
||||
分组是分类列/分类筛选/分类管理的作用域,不是筛选条件 ⇒ 放在筛选行也只是占位,
|
||||
「重置」不清它(挂载测试钉住)。 -->
|
||||
<el-select
|
||||
v-if="canSwitchGroup"
|
||||
:value="ownerGroupId"
|
||||
:model-value="ownerGroupId"
|
||||
class="admin-filter"
|
||||
filterable
|
||||
aria-label="当前分组"
|
||||
@change="changeOwnerGroup(Number(($event.target as HTMLSelectElement).value))"
|
||||
@change="changeOwnerGroup"
|
||||
>
|
||||
<option v-for="group in categoryScope" :key="group.id" :value="group.id">{{ group.label }}</option>
|
||||
</select>
|
||||
<el-option v-for="group in categoryScope" :key="group.id" :value="group.id" :label="group.label" />
|
||||
</el-select>
|
||||
<span v-else class="jd-group-locked" title="你的数据权限内只有这一个分组">{{ currentGroupName }}</span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -400,10 +405,33 @@ onMounted(async () => {
|
||||
<!-- 商品行写只对平台超管;分类写由当前分组 editable 决定(本组管理员/公司超管/平台超管)。
|
||||
非超管看到只读提示,分类维护入口=工具栏「分类管理」(只读可看,写控件按 editable 分档)。 -->
|
||||
<span v-if="!isSuperAdmin" class="jd-readonly-tip">只读:编辑/删除仅超级管理员可用;分类在本页「分类管理」查看与维护</span>
|
||||
<select v-model="filter.groupId" aria-label="筛选店铺分类" @change="apply">
|
||||
<option value="">全部分类</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
<!-- 分类筛选(2026-11-17 与分组同刀换 el-select,弹层圆角与亚马逊统一):保留显式
|
||||
「全部分类」行(value='',与旧原生下拉同语义——列表里永远有回全量的出口),
|
||||
选中它/重置回 '' 时闭壳显示同文案占位。 -->
|
||||
<el-select
|
||||
v-model="filter.groupId"
|
||||
class="admin-filter"
|
||||
placeholder="全部分类"
|
||||
aria-label="筛选店铺分类"
|
||||
@change="apply"
|
||||
>
|
||||
<el-option label="全部分类" value="" />
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.name" :value="String(group.id)" />
|
||||
</el-select>
|
||||
<!-- 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」+同日收敛
|
||||
「不需要全部分类 默认卡在未分类上就行」):已分类=当前分组下有分类
|
||||
(V203 归属表,与列表分类列同形——筛"未分类"的行分类列必显示未分类);
|
||||
两档下拉、出厂默认卡「未分类」,选中即查(回第一页);「重置」也回未分类档。 -->
|
||||
<el-select
|
||||
v-model="filter.classified"
|
||||
class="admin-filter"
|
||||
placeholder="未分类"
|
||||
aria-label="筛选分类状态"
|
||||
@change="apply"
|
||||
>
|
||||
<el-option label="已分类" value="classified" />
|
||||
<el-option label="未分类" value="ungrouped" />
|
||||
</el-select>
|
||||
<!-- 分类管理(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里」):V204 独立
|
||||
子菜单页整体并入本对话框(搜索+新建+改名+删除)。入口对所有人渲染(同组普通号
|
||||
只读可看,V203),写控件由对话框按当前分组 editable 分档。 -->
|
||||
|
||||
@@ -62,8 +62,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -77,12 +76,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
@@ -131,38 +128,12 @@ h3 {
|
||||
gap: 10px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
/* 工具栏里的下拉与按钮统一 42px 外壳(2026-11-16 用户口径「样式要统一」):
|
||||
这一行此前只有 .btn 有壳,原生 <select> 落成 28px 灰框、字号也不跟,
|
||||
与旁边按钮同排时高矮不齐(分组下拉同日上移进筛选行,本行只剩分类筛选一颗)。
|
||||
数值与 .form-group select / .btn 同一套(42px 高、
|
||||
9px 圆角、#cbd9e6 描边、#f8fbfd 底),箭头用内联 SVG 自绘,避免各浏览器原生
|
||||
箭头粗细不一(appearance:none 后必须补 padding-right 给箭头留位)。 */
|
||||
.jd-toolbar select {
|
||||
min-height: 42px;
|
||||
max-width: 220px;
|
||||
padding: 0 34px 0 12px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background-color: #f8fbfd;
|
||||
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%235b6f83' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
|
||||
background-repeat: no-repeat;
|
||||
background-position: right 12px center;
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
color: #24384d;
|
||||
font-family: inherit;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.jd-toolbar select:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.jd-toolbar select:focus {
|
||||
background-color: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
/* 工具栏分类筛选(2026-11-17 用户口径「和亚马逊不统一」起换 el-select):42px 外壳、
|
||||
9px 圆角、#cbd9e6 描边、#f8fbfd 浅底与 focus ring 都由全局 .el-select.admin-filter
|
||||
皮肤(main.css)出——与亚马逊面同一套,弹层不再是浏览器原生直角列表。
|
||||
这里只钉工具栏位宽(admin-filter 出厂 width:100%,进 flex 工具栏会横涨)。 */
|
||||
.jd-toolbar .el-select.admin-filter {
|
||||
width: 200px;
|
||||
}
|
||||
/* 危险动作(删除勾选)推到行尾:留在「批量编辑分类/分类筛选」旁边会被读成同一组动作。 */
|
||||
.jd-delete-btn {
|
||||
@@ -194,7 +165,7 @@ h3 {
|
||||
white-space: nowrap;
|
||||
}
|
||||
/* 只有一个可见分组时锁定的组名(不可切):筛选行「分组」标签下的静态芯片(2026-11-16 用户口径
|
||||
「做成分组」把下拉从工具栏上移进筛选行后跟着搬),与同排 select 同高同壳(42px/9px 圆角),
|
||||
「做成分组」把下拉从工具栏上移进筛选行后跟着搬),与同排 el-select 同高同壳(42px/9px 圆角),
|
||||
"一组锁定"和"多组下拉"两种形态占位一致;组名超宽省略号收口,不把筛选行撑破。 */
|
||||
.jd-group-locked {
|
||||
display: flex;
|
||||
|
||||
@@ -29,6 +29,7 @@ export async function fetchJdProductList(
|
||||
titleKeyword: params.titleKeyword ?? '',
|
||||
category: params.category ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
classified: (params.classified ?? '') as '' | 'classified' | 'ungrouped',
|
||||
syncedFrom: params.syncedFrom ?? '',
|
||||
syncedTo: params.syncedTo ?? '',
|
||||
},
|
||||
|
||||
@@ -19,6 +19,9 @@ export const JD_PRODUCT_PAGE_SIZE = 20
|
||||
export const JD_PRODUCT_MAX_PAGE_SIZE = 100
|
||||
/** 页码上限:与后端 MAX_PAGE(CR-18 先例,外观专利同值)对齐,两侧不漂。 */
|
||||
export const JD_PRODUCT_MAX_PAGE = 10_000
|
||||
/** 分类状态快筛的出厂档位(2026-11-17 用户口径「不需要全部分类 默认卡在未分类上就行」):
|
||||
* 首屏/重置都卡它;「筛选激活」判定也以「是否偏离它」为准。 */
|
||||
export const JD_PRODUCT_DEFAULT_CLASSIFIED = 'ungrouped' as const
|
||||
|
||||
export interface JdProductFilterState {
|
||||
/** 商品编码,空串不限。 */
|
||||
@@ -29,6 +32,13 @@ export interface JdProductFilterState {
|
||||
category: string
|
||||
/** 分组 id 文本(分组管理里那一行),空串=全部分组。 */
|
||||
groupId: string
|
||||
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」,同日二档收敛
|
||||
* 「不需要全部分类 默认卡在未分类上就行」):'classified'=已分类(当前分组下有分类),
|
||||
* 'ungrouped'=未分类,**出厂默认='ungrouped'**(首屏与「重置」都卡未分类档)。
|
||||
* 语义按 V203 归属表(当前数据权限分组)判定,与列表分类列同形;不是 11-16 撤掉的
|
||||
* 旧 grouped/ungrouped 参数(那两档读已停用的 biz_jd_product.group_id 列,后端仍拒收)。
|
||||
* ''/缺省=「全部」仍是序列化出口的兜底语义(脏值不冒充档位),但界面不再给这一档。 */
|
||||
classified?: '' | 'classified' | 'ungrouped'
|
||||
/** 同步开始日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
syncedFrom: string
|
||||
/** 同步结束日期(ISO yyyy-MM-dd;空串不限)。 */
|
||||
@@ -36,7 +46,9 @@ export interface JdProductFilterState {
|
||||
}
|
||||
|
||||
export function createJdProductFilterState(): JdProductFilterState {
|
||||
return { productCode: '', titleKeyword: '', category: '', groupId: '', syncedFrom: '', syncedTo: '' }
|
||||
// 分类状态出厂卡「未分类」(2026-11-17 用户口径「默认卡在未分类上就行」):
|
||||
// 首屏与「重置」都带 classified=false 查,用户要全量自己点「已分类」逐档看。
|
||||
return { productCode: '', titleKeyword: '', category: '', groupId: '', classified: JD_PRODUCT_DEFAULT_CLASSIFIED, syncedFrom: '', syncedTo: '' }
|
||||
}
|
||||
|
||||
/** 是否有任一激活筛选条件。 */
|
||||
@@ -45,6 +57,9 @@ export function jdProductFilterActive(state: JdProductFilterState): boolean {
|
||||
if ((state.titleKeyword || '').trim()) return true
|
||||
if ((state.category || '').trim()) return true
|
||||
if ((state.groupId || '').trim()) return true
|
||||
// 出厂默认本身卡未分类档(2026-11-17 用户口径),所以只有「偏离默认档」才算激活筛选,
|
||||
// 否则首屏就永远处于"有筛选"状态,空结果提示会误导用户去重置一个没动过的筛选。
|
||||
if (state.classified && state.classified !== JD_PRODUCT_DEFAULT_CLASSIFIED) return true
|
||||
if (validIsoDateOrUndefined(state.syncedFrom) || validIsoDateOrUndefined(state.syncedTo)) return true
|
||||
return false
|
||||
}
|
||||
@@ -59,6 +74,9 @@ export interface JdProductQuery {
|
||||
category?: string
|
||||
/** 自定义分类 id(当前分组下的一个分类;V203 起按归属表 EXISTS 过滤)。 */
|
||||
group_id?: number
|
||||
/** 分类状态快筛(2026-11-17):true=已分类、false=未分类,缺省不下发=全部。
|
||||
* 后端按「当前分组」(owner_group_id)的归属表 EXISTS/NOT EXISTS 在 SQL 侧下推。 */
|
||||
classified?: boolean
|
||||
/** 当前数据权限分组 id(分类列/分类筛选都按它取;V203「不同组不能看到跨组的分类」)。 */
|
||||
owner_group_id?: number
|
||||
synced_from?: string
|
||||
@@ -73,6 +91,8 @@ export interface JdProductListParams {
|
||||
titleKeyword?: string
|
||||
category?: string
|
||||
groupId?: string
|
||||
/** 分类状态快筛(''/缺省=全部,'classified'/'ungrouped' 见 JdProductFilterState)。 */
|
||||
classified?: string
|
||||
/** 当前分组(数据权限分组 id):分类列/分类筛选的作用域,非筛选条件(重置不清它)。 */
|
||||
ownerGroupId?: number | null
|
||||
syncedFrom?: string
|
||||
@@ -90,6 +110,10 @@ function toJdProductFilterQuery(state: JdProductFilterState): Omit<JdProductQuer
|
||||
if (category) query.category = category
|
||||
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 syncedFrom = validIsoDateOrUndefined(state.syncedFrom)
|
||||
if (syncedFrom) query.synced_from = syncedFrom
|
||||
const syncedTo = validIsoDateOrUndefined(state.syncedTo)
|
||||
|
||||
@@ -170,18 +170,22 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in ASIN_COUNTRY_CODES" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 下拉 2026-11-17 用户口径「和亚马逊不统一」:原生 <select> 的弹层是浏览器直角
|
||||
原生物 ⇒ 换 el-select(admin-filter 同壳 42px/9px,弹层 EP 圆角面板)。
|
||||
「全部国家」保留为空值首行(与旧原生下拉同语义,查询参数仍是空串)。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" aria-label="筛选国家">
|
||||
<el-option label="全部国家" value="" />
|
||||
<el-option v-for="code in ASIN_COUNTRY_CODES" :key="code" :label="asinCountryLabel(code)" :value="code" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>分组</label>
|
||||
<!-- 分组(主管)选中即查:选完立刻按该主管过滤刷新(回第一页),不必再点查询。 -->
|
||||
<select v-model="filter.groupId" @change="apply">
|
||||
<option value="">全部分组</option>
|
||||
<option v-for="group in groupOptions" :key="group.id" :value="String(group.id)">{{ group.name }}</option>
|
||||
</select>
|
||||
<!-- 分组(主管)选中即查:选完立刻按该主管过滤刷新(回第一页),不必再点查询。
|
||||
value 保持字符串形状(下游按字符串比对/透传)。 -->
|
||||
<el-select v-model="filter.groupId" class="admin-filter" aria-label="筛选分组" @change="apply">
|
||||
<el-option label="全部分组" value="" />
|
||||
<el-option v-for="group in groupOptions" :key="group.id" :label="group.name" :value="String(group.id)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>同步开始日期</label>
|
||||
@@ -306,8 +310,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -321,12 +324,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -221,6 +221,11 @@ function modeLabel(mode: string): string {
|
||||
return mode === 'selected' ? '精选' : '全量'
|
||||
}
|
||||
|
||||
/** 终端覆盖下拉的显示文案(el-option 需要显式 label,文案与旧原生 <option> 逐字一致)。 */
|
||||
function deviceOptionLabel(device: DeviceLogDevice): string {
|
||||
return `${sourceLabel(device.source)} · ${device.deviceName || device.deviceId}(${device.deviceId})`
|
||||
}
|
||||
|
||||
async function openConfig() {
|
||||
configVisible.value = true
|
||||
await loadConfig()
|
||||
@@ -301,16 +306,20 @@ onMounted(() => {
|
||||
<div class="form-row logs-filter-row">
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>来源</label>
|
||||
<select v-model="sourceFilter">
|
||||
<option v-for="option in SOURCE_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部来源」保留为空值首行(value 语义不变,查询参数仍是空串)。 -->
|
||||
<el-select v-model="sourceFilter" class="admin-filter" aria-label="来源">
|
||||
<el-option v-for="option in SOURCE_OPTIONS" :key="option.value" :label="option.label" :value="option.value" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 180px">
|
||||
<label>指定用户</label>
|
||||
<select v-model="uidFilter" :disabled="usersLoading">
|
||||
<option value="">全部用户</option>
|
||||
<option v-for="u in userOptions" :key="u.id" :value="String(u.id)">{{ u.username }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部用户」保留为空值首行;用户值仍是 String(id)(下游按字符串判空、落库前再转数字)。 -->
|
||||
<el-select v-model="uidFilter" class="admin-filter" filterable aria-label="指定用户" :disabled="usersLoading">
|
||||
<el-option label="全部用户" value="" />
|
||||
<el-option v-for="u in userOptions" :key="u.id" :label="u.username" :value="String(u.id)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>日志日期(起)</label>
|
||||
@@ -425,15 +434,21 @@ onMounted(() => {
|
||||
<div class="config-block">
|
||||
<h4>终端覆盖</h4>
|
||||
<div class="override-add">
|
||||
<select v-model="newOverrideKey" class="override-select">
|
||||
<option value="">选择终端(最近上报的设备)</option>
|
||||
<option v-for="device in devices" :key="`${device.source}|${device.deviceId}`" :value="`${device.source}|${device.deviceId}`">
|
||||
{{ sourceLabel(device.source) }} · {{ device.deviceName || device.deviceId }}({{ device.deviceId }})
|
||||
</option>
|
||||
</select>
|
||||
<select v-model="newOverrideMode">
|
||||
<option v-for="option in MODE_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
value 仍是 `${source}|${deviceId}` 与 'full'/'selected' 常量,逐字保留(addOverride
|
||||
按 '|' 切分、后端按 mode 常量解析,值形状一动就错单)。 -->
|
||||
<el-select v-model="newOverrideKey" class="admin-filter override-select" filterable aria-label="选择终端">
|
||||
<el-option label="选择终端(最近上报的设备)" value="" />
|
||||
<el-option
|
||||
v-for="device in devices"
|
||||
:key="`${device.source}|${device.deviceId}`"
|
||||
:label="deviceOptionLabel(device)"
|
||||
:value="`${device.source}|${device.deviceId}`"
|
||||
/>
|
||||
</el-select>
|
||||
<el-select v-model="newOverrideMode" class="admin-filter override-mode" aria-label="覆盖模式">
|
||||
<el-option v-for="option in MODE_OPTIONS" :key="option.value" :label="option.label" :value="option.value" />
|
||||
</el-select>
|
||||
<button class="btn btn-sm" type="button" @click="addOverride">添加/更新覆盖</button>
|
||||
</div>
|
||||
<table class="override-table">
|
||||
@@ -529,8 +544,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -543,8 +557,7 @@ h3 {
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
@@ -743,21 +756,15 @@ td {
|
||||
gap: 10px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.override-add select {
|
||||
min-height: 38px;
|
||||
padding: 6px 10px;
|
||||
border: 1px solid #cbd9e6;
|
||||
border-radius: 9px;
|
||||
background: #f8fbfd;
|
||||
color: #24384d;
|
||||
font-size: 13px;
|
||||
font-family: inherit;
|
||||
color-scheme: light;
|
||||
}
|
||||
/* 只管布局:外壳皮肤(42px/9 圆角/#f8fbfd/focus ring)由全局 .admin-filter 提供,
|
||||
这里不再重复描边(旧 `.override-add select` 那段原生下拉皮肤已随 el-select 删除)。 */
|
||||
.override-select {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.override-mode {
|
||||
flex: 0 0 140px;
|
||||
}
|
||||
.override-table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@@ -146,10 +146,12 @@ onMounted(() => {
|
||||
<div class="form-row">
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>指定用户</label>
|
||||
<select v-model="filter.userId" :disabled="userLoading">
|
||||
<option value="">全部用户</option>
|
||||
<option v-for="u in userOptions" :key="u.id" :value="String(u.id)">{{ u.username }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部用户」保留为空值首行;用户值仍是 String(id)(查询前再 Number() 转数字)。 -->
|
||||
<el-select v-model="filter.userId" class="admin-filter" filterable aria-label="指定用户" :disabled="userLoading">
|
||||
<el-option label="全部用户" value="" />
|
||||
<el-option v-for="u in userOptions" :key="u.id" :label="u.username" :value="String(u.id)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>开始时间</label>
|
||||
@@ -294,8 +296,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -309,12 +310,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -379,17 +379,19 @@ onUnmounted(() => {
|
||||
<label>账号</label>
|
||||
<input v-model="filter.username" type="text" placeholder="模糊搜索账号名" @keyup.enter="search" />
|
||||
</div>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select
|
||||
(与下方店铺筛选同形,挂全局 admin-filter 皮肤)。 -->
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>业务</label>
|
||||
<select v-model="filter.moduleType">
|
||||
<option v-for="option in MODULE_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.moduleType" class="admin-filter" aria-label="筛选业务">
|
||||
<el-option v-for="option in MODULE_OPTIONS" :key="option.value" :value="option.value" :label="option.label" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 130px">
|
||||
<label>状态</label>
|
||||
<select v-model="filter.status">
|
||||
<option v-for="option in TASK_STATUS_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.status" class="admin-filter" aria-label="筛选任务状态">
|
||||
<el-option v-for="option in TASK_STATUS_OPTIONS" :key="option.value" :value="option.value" :label="option.label" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group shop-filter">
|
||||
<label>店铺</label>
|
||||
@@ -447,9 +449,11 @@ onUnmounted(() => {
|
||||
<div class="form-row">
|
||||
<div class="form-group" style="min-width: 150px">
|
||||
<label>状态</label>
|
||||
<select v-model="variantFilter.status">
|
||||
<option v-for="option in VARIANT_STATUS_OPTIONS" :key="option.value" :value="option.value">{{ option.label }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
value 原样透传('0'~'3' 是字符串,后端按值比对)。 -->
|
||||
<el-select v-model="variantFilter.status" class="admin-filter" aria-label="筛选变体状态">
|
||||
<el-option v-for="option in VARIANT_STATUS_OPTIONS" :key="option.value" :value="option.value" :label="option.label" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label> </label>
|
||||
@@ -689,8 +693,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -703,8 +706,7 @@ h3 {
|
||||
color-scheme: light;
|
||||
outline: none;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -253,15 +253,16 @@ onMounted(() => {
|
||||
</label>
|
||||
<label class="g-field">
|
||||
<span>国家</span>
|
||||
<select v-model="form.country">
|
||||
<option v-for="country in GATING_COUNTRIES" :key="country" :value="country">{{ country }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。 -->
|
||||
<el-select v-model="form.country" class="admin-filter" aria-label="表单国家">
|
||||
<el-option v-for="country in GATING_COUNTRIES" :key="country" :value="country" :label="country" />
|
||||
</el-select>
|
||||
</label>
|
||||
<label class="g-field">
|
||||
<span>类型</span>
|
||||
<select v-model="form.gatingType">
|
||||
<option v-for="type in typeOptions" :key="type" :value="type">{{ type }}</option>
|
||||
</select>
|
||||
<el-select v-model="form.gatingType" class="admin-filter" aria-label="表单类型">
|
||||
<el-option v-for="type in typeOptions" :key="type" :value="type" :label="type" />
|
||||
</el-select>
|
||||
</label>
|
||||
<label class="g-field">
|
||||
<span>ASIN</span>
|
||||
@@ -302,23 +303,25 @@ onMounted(() => {
|
||||
<div class="g-panel-body">
|
||||
<div class="g-filters">
|
||||
<input v-model="filter.keyword" placeholder="搜索品牌 / ASIN" @keyup.enter="query" />
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="country in countryOptions" :key="country" :value="country">{{ country }}</option>
|
||||
</select>
|
||||
<select v-model="filter.gatingType">
|
||||
<option value="">全部类型</option>
|
||||
<option v-for="type in typeOptions" :key="type" :value="type">{{ type }}</option>
|
||||
</select>
|
||||
<select v-model="filter.status">
|
||||
<option value="">全部状态</option>
|
||||
<option value="1">生效</option>
|
||||
<option value="0">已解除</option>
|
||||
</select>
|
||||
<select v-model="filter.source">
|
||||
<option value="">全部来源</option>
|
||||
<option v-for="source in GATING_SOURCES" :key="source" :value="source">{{ sourceText(source) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部 XX」空值行保留、status 的 '1'/'0' 仍是字符串(后端按值比对)。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" style="width: 132px" aria-label="筛选国家">
|
||||
<el-option value="" label="全部国家" />
|
||||
<el-option v-for="country in countryOptions" :key="country" :value="country" :label="country" />
|
||||
</el-select>
|
||||
<el-select v-model="filter.gatingType" class="admin-filter" style="width: 132px" aria-label="筛选类型">
|
||||
<el-option value="" label="全部类型" />
|
||||
<el-option v-for="type in typeOptions" :key="type" :value="type" :label="type" />
|
||||
</el-select>
|
||||
<el-select v-model="filter.status" class="admin-filter" style="width: 132px" aria-label="筛选状态">
|
||||
<el-option value="" label="全部状态" />
|
||||
<el-option value="1" label="生效" />
|
||||
<el-option value="0" label="已解除" />
|
||||
</el-select>
|
||||
<el-select v-model="filter.source" class="admin-filter" style="width: 132px" aria-label="筛选来源">
|
||||
<el-option value="" label="全部来源" />
|
||||
<el-option v-for="source in GATING_SOURCES" :key="source" :value="source" :label="sourceText(source)" />
|
||||
</el-select>
|
||||
<button class="g-btn g-btn-primary" type="button" @click="query">查询</button>
|
||||
<button class="g-btn g-btn-ghost" type="button" @click="resetFilter">重置</button>
|
||||
</div>
|
||||
@@ -522,10 +525,9 @@ onMounted(() => {
|
||||
.g-field-wide {
|
||||
grid-column: span 2;
|
||||
}
|
||||
/* 下拉已换 el-select(2026-11-17)⇒ 皮肤走全局 .admin-filter,这里只留原生输入框。 */
|
||||
.g-field input,
|
||||
.g-field select,
|
||||
.g-filters input,
|
||||
.g-filters select {
|
||||
.g-filters input {
|
||||
width: 100%;
|
||||
height: 34px;
|
||||
padding: 0 10px;
|
||||
@@ -538,13 +540,28 @@ onMounted(() => {
|
||||
outline: none;
|
||||
}
|
||||
.g-field input:focus,
|
||||
.g-field select:focus,
|
||||
.g-filters input:focus,
|
||||
.g-filters select:focus {
|
||||
.g-filters input:focus {
|
||||
border-color: var(--g-primary);
|
||||
box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
background: #fff;
|
||||
}
|
||||
/* 本页表单/筛选行是 34px 紧凑档(输入框与 `.g-btn` 同为 34px、7px 圆角、蓝色 focus)。
|
||||
新换的 el-select 若照全局 admin-filter(42px/9px/蓝灰 ring)会在同一行里高出一截,
|
||||
与旁边的输入框错位 ⇒ 在本页把壳压回本地档位(scoped 下 :deep 穿透 EP 内部结构)。 */
|
||||
.g-field :deep(.el-select__wrapper),
|
||||
.g-filters :deep(.el-select__wrapper) {
|
||||
min-height: 34px;
|
||||
padding: 0 10px;
|
||||
border-radius: 7px;
|
||||
background: #fbfcfe;
|
||||
box-shadow: 0 0 0 1px #d7dce5 inset;
|
||||
font-size: 13px;
|
||||
}
|
||||
.g-field :deep(.el-select__wrapper.is-focused),
|
||||
.g-filters :deep(.el-select__wrapper.is-focused) {
|
||||
background: #fff;
|
||||
box-shadow: 0 0 0 1px var(--g-primary) inset, 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
}
|
||||
.g-form-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
@@ -580,9 +597,6 @@ onMounted(() => {
|
||||
.g-filters input {
|
||||
width: 190px;
|
||||
}
|
||||
.g-filters select {
|
||||
width: 132px;
|
||||
}
|
||||
|
||||
.g-btn {
|
||||
height: 34px;
|
||||
|
||||
@@ -447,24 +447,26 @@ onMounted(() => {
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label>店铺</label>
|
||||
<select v-model="filter.shop">
|
||||
<option value="">全部店铺</option>
|
||||
<option v-for="shop in orderedShops" :key="shop.shopName" :value="shop.shopName">{{ shop.shopName }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部 XX」空值行保留,候选值原样透传。 -->
|
||||
<el-select v-model="filter.shop" class="admin-filter" filterable style="width: 150px" aria-label="筛选店铺">
|
||||
<el-option value="" label="全部店铺" />
|
||||
<el-option v-for="shop in orderedShops" :key="shop.shopName" :value="shop.shopName" :label="shop.shopName" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div v-if="isSuper" class="f-group">
|
||||
<label>分组</label>
|
||||
<select v-model="filter.group">
|
||||
<option value="">全部分组</option>
|
||||
<option v-for="group in groupStats" :key="group.name" :value="group.name">{{ group.name }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.group" class="admin-filter" filterable style="width: 150px" aria-label="筛选分组">
|
||||
<el-option value="" label="全部分组" />
|
||||
<el-option v-for="group in groupStats" :key="group.name" :value="group.name" :label="group.name" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label>国家 / 站点</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="code in countryOptions" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.country" class="admin-filter" style="width: 150px" aria-label="筛选国家">
|
||||
<el-option value="" label="全部国家" />
|
||||
<el-option v-for="code in countryOptions" :key="code" :value="code" :label="asinCountryLabel(code)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="f-group">
|
||||
<label>上架时间开始</label>
|
||||
@@ -774,7 +776,8 @@ onMounted(() => {
|
||||
.dup-ref .mono { font-family: var(--mono); }
|
||||
.dup-ref button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
|
||||
.dup-ref button:disabled { opacity: 0.55; cursor: not-allowed; }
|
||||
.dup-ref input, .dup-ref select { font-family: inherit; font-size: 13px; color: var(--text); }
|
||||
/* 原生 select 已换 el-select(2026-11-17)⇒ 选择器里不再列 select。 */
|
||||
.dup-ref input { font-family: inherit; font-size: 13px; color: var(--text); }
|
||||
.dup-ref a { color: var(--primary); text-decoration: none; }
|
||||
.dup-ref .dim-cell { color: var(--text3); }
|
||||
.dup-ref .num-cell { font-variant-numeric: tabular-nums; }
|
||||
@@ -801,14 +804,27 @@ onMounted(() => {
|
||||
.dup-ref .filter-row { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
|
||||
.dup-ref .f-group { display: flex; flex-direction: column; gap: 6px; }
|
||||
.dup-ref .f-group label { font-size: 12px; color: var(--text2); }
|
||||
.dup-ref .f-group input, .dup-ref .f-group select {
|
||||
/* 下拉已换 el-select(2026-11-17)⇒ 皮肤走全局 .admin-filter。
|
||||
本页 style 块不是 scoped,`.f-group input` 会连带命中 el-select 内层的
|
||||
`input.el-select__input`(EP 自己的边框/背景会被这套规则压掉,控件变成框里套框)
|
||||
⇒ 必须显式排除。 */
|
||||
.dup-ref .f-group input:not(.el-select__input) {
|
||||
width: 170px;
|
||||
height: 34px; border: 1px solid var(--border-strong); border-radius: 7px; padding: 0 10px; background: #FBFCFE; outline: none;
|
||||
transition: border-color 0.15s, box-shadow 0.15s;
|
||||
}
|
||||
.dup-ref .f-group input:focus, .dup-ref .f-group select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12); background: #fff; }
|
||||
.dup-ref .f-group input { width: 170px; }
|
||||
.dup-ref .f-group select { width: 150px; cursor: pointer; }
|
||||
.dup-ref .f-group input:not(.el-select__input):focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12); background: #fff; }
|
||||
.dup-ref .f-group input[type="date"] { width: 150px; }
|
||||
/* 本页筛选行是 34px 紧凑档(输入框与 `.btn` 同为 34px、7px 圆角、蓝色 focus)。
|
||||
新换的 el-select 若照全局 admin-filter(42px/9px/蓝灰 ring)会与同行输入框错位
|
||||
⇒ 在本页把壳压回本地档位;本页 style 不 scoped,EP 内部结构可直接选中。 */
|
||||
.dup-ref .f-group .el-select__wrapper {
|
||||
min-height: 34px; padding: 0 10px; border-radius: 7px;
|
||||
background: #FBFCFE; box-shadow: 0 0 0 1px var(--border-strong) inset; font-size: 13px;
|
||||
}
|
||||
.dup-ref .f-group .el-select__wrapper.is-focused {
|
||||
background: #fff; box-shadow: 0 0 0 1px var(--primary) inset, 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
}
|
||||
.dup-ref .btn {
|
||||
height: 34px; border-radius: 7px; padding: 0 16px; font-size: 13px; font-weight: 600;
|
||||
display: inline-flex; align-items: center; gap: 6px; transition: background 0.15s, color 0.15s, border-color 0.15s;
|
||||
|
||||
@@ -185,19 +185,21 @@ onMounted(() => {
|
||||
<div class="kw-panel-head">筛选条件</div>
|
||||
<div class="kw-panel-body">
|
||||
<div class="kw-filters">
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。
|
||||
「全部 XX」空值行保留。 -->
|
||||
<label class="kw-field">
|
||||
<span>使用者</span>
|
||||
<select v-model="filter.user">
|
||||
<option value="">全部使用者</option>
|
||||
<option v-for="user in userOptions" :key="user" :value="user">{{ user }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.user" class="admin-filter" filterable aria-label="筛选使用者">
|
||||
<el-option value="" label="全部使用者" />
|
||||
<el-option v-for="user in userOptions" :key="user" :value="user" :label="user" />
|
||||
</el-select>
|
||||
</label>
|
||||
<label class="kw-field">
|
||||
<span>国家</span>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部国家</option>
|
||||
<option v-for="country in countryOptions" :key="country" :value="country">{{ country }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.country" class="admin-filter" aria-label="筛选国家">
|
||||
<el-option value="" label="全部国家" />
|
||||
<el-option v-for="country in countryOptions" :key="country" :value="country" :label="country" />
|
||||
</el-select>
|
||||
</label>
|
||||
<label class="kw-field kw-field-wide">
|
||||
<span>关键词</span>
|
||||
@@ -205,10 +207,10 @@ onMounted(() => {
|
||||
</label>
|
||||
<label class="kw-field">
|
||||
<span>场景</span>
|
||||
<select v-model="filter.scene">
|
||||
<option value="">全部场景</option>
|
||||
<option v-for="scene in KEYWORD_USAGE_SCENES" :key="scene" :value="scene">{{ scene }}</option>
|
||||
</select>
|
||||
<el-select v-model="filter.scene" class="admin-filter" aria-label="筛选场景">
|
||||
<el-option value="" label="全部场景" />
|
||||
<el-option v-for="scene in KEYWORD_USAGE_SCENES" :key="scene" :value="scene" :label="scene" />
|
||||
</el-select>
|
||||
</label>
|
||||
<div class="kw-actions">
|
||||
<button class="kw-btn kw-btn-primary" type="button" @click="query">查询</button>
|
||||
@@ -405,8 +407,8 @@ onMounted(() => {
|
||||
font-size: 12px;
|
||||
color: #5a6474;
|
||||
}
|
||||
.kw-field input,
|
||||
.kw-field select {
|
||||
/* 下拉已换 el-select(2026-11-17)⇒ 皮肤走全局 .admin-filter,这里只留原生输入框。 */
|
||||
.kw-field input {
|
||||
height: 34px;
|
||||
padding: 0 10px;
|
||||
border: 1px solid #d7dce5;
|
||||
@@ -417,12 +419,26 @@ onMounted(() => {
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
}
|
||||
.kw-field input:focus,
|
||||
.kw-field select:focus {
|
||||
.kw-field input:focus {
|
||||
border-color: #2e5be6;
|
||||
box-shadow: 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
background: #fff;
|
||||
}
|
||||
/* 本页筛选行是 34px 紧凑档(关键词输入框 34px、7px 圆角、蓝色 focus)。
|
||||
新换的 el-select 若照全局 admin-filter(42px/9px/蓝灰 ring)会与同行输入框错位
|
||||
⇒ 在本页把壳压回本地档位(scoped 下 :deep 穿透 EP 内部结构)。 */
|
||||
.kw-field :deep(.el-select__wrapper) {
|
||||
min-height: 34px;
|
||||
padding: 0 10px;
|
||||
border-radius: 7px;
|
||||
background: #fbfcfe;
|
||||
box-shadow: 0 0 0 1px #d7dce5 inset;
|
||||
font-size: 13px;
|
||||
}
|
||||
.kw-field :deep(.el-select__wrapper.is-focused) {
|
||||
background: #fff;
|
||||
box-shadow: 0 0 0 1px #2e5be6 inset, 0 0 0 3px rgba(46, 91, 230, 0.12);
|
||||
}
|
||||
.kw-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
|
||||
@@ -334,10 +334,11 @@ onMounted(load)
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 130px">
|
||||
<label>国家</label>
|
||||
<select v-model="filter.country">
|
||||
<option value="">全部</option>
|
||||
<option v-for="code in ['UK', 'DE', 'FR', 'ES', 'IT']" :key="code" :value="code">{{ asinCountryLabel(code) }}</option>
|
||||
</select>
|
||||
<!-- 2026-11-17 用户口径「和亚马逊不统一」:原生 select 弹层是直角原生物,换 el-select。 -->
|
||||
<el-select v-model="filter.country" class="admin-filter" aria-label="筛选国家">
|
||||
<el-option value="" label="全部" />
|
||||
<el-option v-for="code in ['UK', 'DE', 'FR', 'ES', 'IT']" :key="code" :value="code" :label="asinCountryLabel(code)" />
|
||||
</el-select>
|
||||
</div>
|
||||
<div class="form-group" style="min-width: 176px">
|
||||
<label>创建开始</label>
|
||||
@@ -510,8 +511,7 @@ h3 {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.form-group input,
|
||||
.form-group select {
|
||||
.form-group input {
|
||||
min-width: 0;
|
||||
min-height: 42px;
|
||||
padding: 8px 12px;
|
||||
@@ -525,12 +525,10 @@ h3 {
|
||||
outline: none;
|
||||
transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
|
||||
}
|
||||
.form-group input:hover,
|
||||
.form-group select:hover {
|
||||
.form-group input:hover {
|
||||
border-color: #9fb7cd;
|
||||
}
|
||||
.form-group input:focus,
|
||||
.form-group select:focus {
|
||||
.form-group input:focus {
|
||||
background: #ffffff;
|
||||
border-color: #5f85ad;
|
||||
box-shadow: 0 0 0 3px rgba(95, 133, 173, 0.16);
|
||||
|
||||
@@ -86,3 +86,15 @@ export const useCompanyTabStore = defineStore('company-tab', {
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
/** 公司目录失效通知:公司管理页保存(新建/改名/启停/翻档)之后调这里,让全站 tab 条重拉一份。
|
||||
*
|
||||
* 为什么是 store 里的具名出口而不是让页面自己持一份 store:公司管理页**不参与公司隔离**
|
||||
* (控制方 2026-10-06「公司管理不要有 tab」),它要的不是 tab 状态,只是「别让 18 个页面的
|
||||
* tab 条端着旧名单」这一个动作。页面里一旦出现 `useCompanyTabStore()`,形状就和「给这页上了
|
||||
* tab」分不开——company-config-entry-super-only 的 pageFiles 分母会当场红(2026-11-17 实测:
|
||||
* ee613db0 给这页加了保存后重拉,正是踩在这条上)。
|
||||
* 失败语义同 refresh:error 落 store 再 rethrow,调用方决定要不要提示。 */
|
||||
export function refreshCompanyDirectory(): Promise<void> {
|
||||
return useCompanyTabStore().refresh()
|
||||
}
|
||||
|
||||
@@ -75,9 +75,11 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
|
||||
})
|
||||
assert.equal('shop_name' in full, false, '店铺筛选已下线,参数面不再出现 shop_name')
|
||||
|
||||
// 全空态只有分页两项;脏值(非数字分组、非法日期)同罪不下发。
|
||||
// 出厂态=分页两项+默认未分类档(classified:false,2026-11-17 用户口径「默认卡在未分类上就行」);
|
||||
// 脏值(非数字分组、非法日期)同罪不下发。
|
||||
const blank = toJdProductListParams(createJdProductFilterState(), 1, 20)
|
||||
assert.deepEqual(blank, { page: 1, page_size: 20 })
|
||||
assert.deepEqual(blank, { page: 1, page_size: 20, classified: false },
|
||||
'出厂默认必须带 classified:false——首屏就卡未分类,不是全量')
|
||||
assert.equal('group_id' in blank, false, 'groupId 空串不带 group_id')
|
||||
assert.equal('owner_group_id' in blank, false, '没传当前分组就不带 owner_group_id(后端按作用域默认组取)')
|
||||
const dirty = toJdProductListParams(
|
||||
@@ -108,6 +110,25 @@ test('京东列表参数——page 钳制防 (page-1)*page_size 溢出(铁律
|
||||
assert.equal(offset, 999_900)
|
||||
})
|
||||
|
||||
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」,同日收敛
|
||||
* 「不需要全部分类 默认卡在未分类上就行」):界面两档,'classified'→true、'ungrouped'→false;
|
||||
* 出厂默认与「重置」都卡 ungrouped。''/缺省/脏值=「全部」仍是序列化出口的兜底语义
|
||||
* (不拿脏值冒充档位),但界面不再提供这一档。
|
||||
* 参数名是新档 classified——不是后端仍拒收的旧 grouped/ungrouped 查询参数。 */
|
||||
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',
|
||||
'出厂态与重置都必须卡未分类档(用户口径:默认卡在未分类上)')
|
||||
|
||||
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)} 按「全部」兜底处理,不拿脏值冒充档位`)
|
||||
}
|
||||
})
|
||||
|
||||
test('详情解析——attrGroups/images 结构化解析(snake 容错、缺 url 弃行)', () => {
|
||||
const detail = parseJdProductDetail({
|
||||
code: 0,
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
* 账户域三页的原生 <select> → el-select(2026-11-17 用户口径「和亚马逊不统一」:
|
||||
* 原生 select 的弹层是浏览器直角原生物 ⇒ 换 EP 圆角弹层,外壳走全局 .admin-filter)。
|
||||
*
|
||||
* 钉住换壳最容易错的两件事:
|
||||
* 1. **值形状逐字不变**——菜单类型/密钥状态仍是 '' / 'admin' / 'app' / 'passed'…(空串=不筛),
|
||||
* 分组仍是 null 或数字 id(下游 `groupId: groupFilter.value || undefined` 一字不动);
|
||||
* 2. **「全部 XX」空值行还在**,且选中它就是"不改筛选条件",不是筛一个叫空的类型。
|
||||
*
|
||||
* aria-label 由 EP 落在内层 combobox input 上;选项清单走组件树读,点选走「点开→点选项」真实路径
|
||||
* (弹层 teleport 到 body)。页面模板靠 main.ts 全局注册 EP 组件,挂载测试不跑 main.ts ⇒
|
||||
* 这里必须显式把 ElSelect/ElOption 传进 plugins。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/account-select-el.mount.test.ts`
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
|
||||
import MenusPage from '@/pages/account/MenusPage.vue'
|
||||
import UserSecretsPage from '@/pages/account/UserSecretsPage.vue'
|
||||
import UserSecretUsagePage from '@/pages/account/UserSecretUsagePage.vue'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
|
||||
const menuApi = vi.hoisted(() => ({
|
||||
loadMenuManageTree: vi.fn(),
|
||||
createMenu: vi.fn(),
|
||||
updateMenu: vi.fn(),
|
||||
deleteMenu: vi.fn(),
|
||||
reorderMenus: vi.fn(),
|
||||
}))
|
||||
|
||||
const secretsApi = vi.hoisted(() => ({
|
||||
fetchUserSecretList: vi.fn(),
|
||||
fetchAdminSecretBalances: vi.fn(),
|
||||
checkUserSecret: vi.fn(),
|
||||
deleteUserSecret: vi.fn(),
|
||||
saveUserSecretModule: vi.fn(),
|
||||
clearUserSecretModule: vi.fn(),
|
||||
}))
|
||||
|
||||
const usageApi = vi.hoisted(() => ({ fetchUserSecretUsage: vi.fn() }))
|
||||
|
||||
vi.mock('@/pages/account/menu-manage-api', () => menuApi)
|
||||
vi.mock('@/api/user-secrets', () => secretsApi)
|
||||
vi.mock('@/api/user-secret-usage', () => usageApi)
|
||||
|
||||
const GROUPS = [
|
||||
{ id: 7, groupName: '甲组' },
|
||||
{ id: 9, groupName: '乙组' },
|
||||
]
|
||||
|
||||
const MENU_ROWS = [
|
||||
{ id: 1, name: '后台菜单', columnKey: 'admin-col', parentId: null, menuType: 'admin', routePath: '/a', sortOrder: 0, children: [] },
|
||||
{ id: 2, name: '软件菜单', columnKey: 'app-col', parentId: null, menuType: 'app', routePath: '/b', sortOrder: 1, children: [] },
|
||||
]
|
||||
|
||||
// ---------------- el-select 交互助手(与京东数据库页/亚马逊面同一套口径) ----------------
|
||||
|
||||
/** 按 aria-label 找对应的 ElSelect 实例(EP 把该属性落在内层 combobox input 上)。 */
|
||||
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
|
||||
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
|
||||
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
|
||||
return found!
|
||||
}
|
||||
|
||||
/** 某颗下拉的全部选项文案(读 el-option 的 label prop,不依赖插槽文本)。 */
|
||||
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
|
||||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
|
||||
}
|
||||
|
||||
/** 某颗下拉的全部选项 value(形状判据:空串/数字 id/null 逐字对撞)。 */
|
||||
function optionValues(wrapper: VueWrapper<Element>, label: string): unknown[] {
|
||||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('value'))
|
||||
}
|
||||
|
||||
/** 点开指定下拉并点选目标文案的选项(触发 update:modelValue + change,与真实用户一致)。
|
||||
* 面板按内层 input 的 aria-controls 圈定,避免另一颗(可能仍挂着的)弹层串台。 */
|
||||
async function pickSelectOption(wrapper: VueWrapper<Element>, label: string, optionText: string): Promise<void> {
|
||||
const input = wrapper.get(`[aria-label="${label}"]`)
|
||||
await input.trigger('click')
|
||||
await flushPromises()
|
||||
const contentId = input.attributes('aria-controls')
|
||||
const scope = (contentId && document.getElementById(contentId)) ?? document.body
|
||||
const items = [...scope.querySelectorAll('.el-select-dropdown__item')].filter((el) => !el.classList.contains('is-hidden'))
|
||||
const target = items.find((el) => (el.textContent ?? '').trim() === optionText)
|
||||
expect(target, `下拉应弹出「${optionText}」选项`).toBeTruthy()
|
||||
await new DOMWrapper(target as Element).trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 按文案点按钮(筛选条上的查询/重置)。 */
|
||||
async function clickButton(wrapper: VueWrapper<Element>, text: string): Promise<void> {
|
||||
const button = wrapper.findAll('button').find((b) => b.text().trim() === text)
|
||||
expect(button, `应存在「${text}」按钮`).toBeTruthy()
|
||||
await button!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 最近一次调用的入参(首屏 + 公司 tab watch 可能各发一次,判"选完落什么参"只认最后一次)。 */
|
||||
function lastArgs(fn: { mock: { calls: unknown[][] } }): Record<string, unknown> {
|
||||
const calls = fn.mock.calls
|
||||
expect(calls.length, '接口应至少被调用一次').toBeGreaterThan(0)
|
||||
return calls[calls.length - 1][0] as Record<string, unknown>
|
||||
}
|
||||
|
||||
let pinia: Pinia
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
useCompanyTabStore().setActiveId(1)
|
||||
})
|
||||
|
||||
async function mountMenus(): Promise<VueWrapper<Element>> {
|
||||
menuApi.loadMenuManageTree.mockResolvedValue(MENU_ROWS)
|
||||
const wrapper = mount(MenusPage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
async function mountSecrets(): Promise<VueWrapper<Element>> {
|
||||
secretsApi.fetchUserSecretList.mockResolvedValue({ items: [], total: 0, page: 1, pageSize: 15, groupOptions: GROUPS })
|
||||
secretsApi.fetchAdminSecretBalances.mockResolvedValue({ items: [] })
|
||||
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
async function mountUsage(): Promise<VueWrapper<Element>> {
|
||||
usageApi.fetchUserSecretUsage.mockResolvedValue({ items: [], total: 0, groupOptions: GROUPS })
|
||||
const wrapper = mount(UserSecretUsagePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
/** 菜单表格里正在显示的行名(顺序=树展平顺序)。 */
|
||||
function visibleMenuNames(wrapper: VueWrapper<Element>): string[] {
|
||||
return wrapper.findAll('.menu-name-text').map((el) => el.text().trim())
|
||||
}
|
||||
|
||||
describe('菜单管理页 × el-select', () => {
|
||||
it('菜单类型下拉:空值行仍是空串,另两档仍是 admin/app', async () => {
|
||||
const wrapper = await mountMenus()
|
||||
expect(optionLabels(wrapper, '筛选菜单类型')).toEqual(['全部', '后台', '软件'])
|
||||
expect(optionValues(wrapper, '筛选菜单类型')).toEqual(['', 'admin', 'app'])
|
||||
})
|
||||
|
||||
it('选「软件」按 menuType 筛表,选回「全部」恢复全量(空串不参与筛选)', async () => {
|
||||
const wrapper = await mountMenus()
|
||||
expect(visibleMenuNames(wrapper)).toEqual(['后台菜单', '软件菜单'])
|
||||
await pickSelectOption(wrapper, '筛选菜单类型', '软件')
|
||||
expect(visibleMenuNames(wrapper)).toEqual(['软件菜单'])
|
||||
await pickSelectOption(wrapper, '筛选菜单类型', '全部')
|
||||
expect(visibleMenuNames(wrapper)).toEqual(['后台菜单', '软件菜单'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('密钥管理页 × el-select', () => {
|
||||
it('状态下拉:「全部状态」是空串档,其余各档码逐一在案', async () => {
|
||||
const wrapper = await mountSecrets()
|
||||
expect(optionLabels(wrapper, '筛选密钥状态')).toEqual([
|
||||
'全部状态',
|
||||
'检测通过',
|
||||
'检测失败',
|
||||
'未配齐',
|
||||
'无法判定/可重试',
|
||||
'未检测',
|
||||
])
|
||||
expect(optionValues(wrapper, '筛选密钥状态')).toEqual(['', 'passed', 'failed', 'incomplete', 'error', 'unknown'])
|
||||
})
|
||||
|
||||
it('分组下拉:「全部分组」仍是 null,组选项是数字 id', async () => {
|
||||
const wrapper = await mountSecrets()
|
||||
expect(optionLabels(wrapper, '筛选分组')).toEqual(['全部分组', '甲组', '乙组'])
|
||||
expect(optionValues(wrapper, '筛选分组')).toEqual([null, 7, 9])
|
||||
})
|
||||
|
||||
it('落参:checkStatus 是状态码、groupId 是数字;选回空值行后两者都不出现', async () => {
|
||||
const wrapper = await mountSecrets()
|
||||
await pickSelectOption(wrapper, '筛选密钥状态', '检测失败')
|
||||
await pickSelectOption(wrapper, '筛选分组', '甲组')
|
||||
await clickButton(wrapper, '查询')
|
||||
const selected = lastArgs(secretsApi.fetchUserSecretList)
|
||||
expect(selected.checkStatus).toBe('failed')
|
||||
expect(selected.groupId).toBe(7)
|
||||
|
||||
// 空值行=不筛:'' / null 都落回 undefined,查询参数与换壳前逐字一致
|
||||
await pickSelectOption(wrapper, '筛选密钥状态', '全部状态')
|
||||
await pickSelectOption(wrapper, '筛选分组', '全部分组')
|
||||
await clickButton(wrapper, '查询')
|
||||
const cleared = lastArgs(secretsApi.fetchUserSecretList)
|
||||
expect(cleared.checkStatus).toBeUndefined()
|
||||
expect(cleared.groupId).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('密钥用量页 × el-select', () => {
|
||||
it('分组下拉与密钥页同口径(全部分组=null),落参仍是数字 id / 缺省', async () => {
|
||||
const wrapper = await mountUsage()
|
||||
expect(optionLabels(wrapper, '筛选分组')).toEqual(['全部分组', '甲组', '乙组'])
|
||||
expect(optionValues(wrapper, '筛选分组')).toEqual([null, 7, 9])
|
||||
|
||||
await pickSelectOption(wrapper, '筛选分组', '乙组')
|
||||
await clickButton(wrapper, '查询')
|
||||
expect(lastArgs(usageApi.fetchUserSecretUsage).groupId).toBe(9)
|
||||
|
||||
await pickSelectOption(wrapper, '筛选分组', '全部分组')
|
||||
await clickButton(wrapper, '查询')
|
||||
expect(lastArgs(usageApi.fetchUserSecretUsage).groupId).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -14,8 +14,9 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import AppearancePatentCleanItemsPage from '@/pages/patent/AppearancePatentCleanItemsPage.vue'
|
||||
import { adminPages } from '@/router/routes'
|
||||
@@ -74,12 +75,40 @@ beforeEach(() => {
|
||||
|
||||
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||||
cleanApi.fetchAppearancePatentCleanList.mockImplementation(() => Promise.resolve(payload))
|
||||
const wrapper = mount(AppearancePatentCleanItemsPage, { global: { plugins: [pinia] } })
|
||||
const wrapper = mount(AppearancePatentCleanItemsPage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
// ---------------- el-select 交互助手(2026-11-17 筛选行/分页条下拉换 el-select,与亚马逊面统一) ----------------
|
||||
// aria-label 经 EP 的 ariaLabel prop 落在内层 combobox input 上;弹层 teleport 到 body,
|
||||
// ElOption 仍在挂载树里 ⇒ 选项清单走组件树读,点选走「点开→点选项」真实路径。
|
||||
|
||||
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
|
||||
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
|
||||
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
|
||||
return found!
|
||||
}
|
||||
|
||||
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
|
||||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
|
||||
}
|
||||
|
||||
async function pickSelectOption(wrapper: VueWrapper<Element>, label: string, optionText: string): Promise<void> {
|
||||
const input = wrapper.get(`[aria-label="${label}"]`)
|
||||
await input.trigger('click')
|
||||
await flushPromises()
|
||||
const contentId = input.attributes('aria-controls')
|
||||
const scope = (contentId && document.getElementById(contentId)) ?? document.body
|
||||
const items = [...scope.querySelectorAll('.el-select-dropdown__item')]
|
||||
.filter((el) => !el.classList.contains('is-hidden'))
|
||||
const target = items.find((el) => (el.textContent ?? '').trim() === optionText)
|
||||
expect(target, `下拉应弹出「${optionText}」选项`).toBeTruthy()
|
||||
await new DOMWrapper(target as Element).trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
describe('外观专利数据库页(明细表,2026-11-11 恢复「昨天那个格式」)', () => {
|
||||
it('页面组件落位:明细表 + 明细端点 + 导出,卡片视图与删除入口已下架', () => {
|
||||
const src = readFileSync(resolve(process.cwd(), PAGE_PATH), 'utf-8')
|
||||
@@ -215,14 +244,13 @@ describe('外观专利数据库页(明细表,2026-11-11 恢复「昨天那
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([{ id: 7, name: '甲组', leaderUserId: 9 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]:not(.el-select__input)')
|
||||
expect(textInputs).toHaveLength(2, '任务号+ASIN 两个筛选框恢复(客户要一目了然)')
|
||||
await textInputs[0].setValue('33874')
|
||||
await textInputs[1].setValue('B0CLEAN')
|
||||
|
||||
const selects = wrapper.findAll('select')
|
||||
await selects[0].setValue('DE') // 国家排在前(模板顺序:任务号/ASIN/国家/分组)
|
||||
await selects[1].setValue('7') // 分组(主管=组长)
|
||||
await pickSelectOption(wrapper, '筛选国家', '德国') // 国家排在前(模板顺序:任务号/ASIN/国家/分组)
|
||||
await pickSelectOption(wrapper, '筛选分组', '甲组') // 分组(主管=组长)
|
||||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||||
await dateInputs[0].setValue('2026-11-01')
|
||||
await dateInputs[1].setValue('2026-11-09')
|
||||
@@ -249,13 +277,12 @@ describe('外观专利数据库页(明细表,2026-11-11 恢复「昨天那
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
expect(cleanApi.fetchDedupeTotalGroups).toHaveBeenCalledWith(1)
|
||||
|
||||
const groupSelect = wrapper.findAll('select')[1] // 模板顺序:国家在前、分组在后
|
||||
const optionTexts = groupSelect.findAll('option').map((o) => o.text())
|
||||
expect(optionTexts).toContain('全部分组')
|
||||
expect(optionTexts).toContain('甲组')
|
||||
const groups = optionLabels(wrapper, '筛选分组')
|
||||
expect(groups).toContain('全部分组')
|
||||
expect(groups).toContain('甲组')
|
||||
|
||||
const callsBeforeSelect = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||||
await groupSelect.setValue('7')
|
||||
await pickSelectOption(wrapper, '筛选分组', '甲组')
|
||||
await flushPromises()
|
||||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.length).toBe(callsBeforeSelect + 1,
|
||||
'选中分组必须立刻重查')
|
||||
@@ -267,7 +294,7 @@ describe('外观专利数据库页(明细表,2026-11-11 恢复「昨天那
|
||||
|
||||
it('重置把筛选面回空并回第一页重取', async () => {
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]:not(.el-select__input)')
|
||||
await textInputs[0].setValue('33874')
|
||||
await textInputs[1].setValue('B0CLEAN')
|
||||
const callsBefore = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||||
@@ -288,8 +315,9 @@ describe('外观专利数据库页(明细表,2026-11-11 恢复「昨天那
|
||||
expect(cleanApi.fetchAppearancePatentCleanList).toHaveBeenCalledTimes(2)
|
||||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls[1][0].page).toBe(3)
|
||||
|
||||
const sizeSelect = wrapper.find('.page-size-select')
|
||||
await sizeSelect.setValue('50')
|
||||
// 每页条数下拉 2026-11-17 随分页条一起换 el-select(OldPagination 内局部注册)。
|
||||
expect(wrapper.find('.page-size-select').exists()).toBe(true, '分页条下拉保留 .page-size-select 定位类')
|
||||
await pickSelectOption(wrapper, '每页条数', '50条/页')
|
||||
await flushPromises()
|
||||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||||
expect(last.pageSize).toBe(50)
|
||||
@@ -314,11 +342,10 @@ describe('外观专利数据库页(明细表,2026-11-11 恢复「昨天那
|
||||
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径)', async () => {
|
||||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([{ id: 7, name: '甲组', leaderUserId: 9 }])
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 10 })
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]:not(.el-select__input)')
|
||||
await textInputs[0].setValue('33874')
|
||||
await textInputs[1].setValue('B0CLEAN')
|
||||
const groupSelect = wrapper.findAll('select')[1]
|
||||
await groupSelect.setValue('7')
|
||||
await pickSelectOption(wrapper, '筛选分组', '甲组')
|
||||
const callsBefore = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||||
|
||||
useCompanyTabStore().setActiveId(2)
|
||||
|
||||
@@ -110,6 +110,49 @@ describe('京东分类管理对话框(V204 独立页 2026-11-17 并入京东
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('分页:每页 6 条、翻页只换当前页、改搜索回第一页(2026-11-17 用户口径「分类这也要加分页」)', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue(
|
||||
Array.from({ length: 11 }, (_, index) => group(100 + index, `分类${index + 1}`)),
|
||||
)
|
||||
const wrapper = await mountDialog()
|
||||
expect(wrapper.findAll('.option-row')).toHaveLength(6, '第一页只渲染 6 行')
|
||||
expect(wrapper.text()).not.toContain('分类7', '第 7 条以后不在第一页')
|
||||
const pagerText = wrapper.get('.manage-pager').text()
|
||||
expect(pagerText).toContain('第 1 / 2 页')
|
||||
expect(pagerText).toContain('共 11 个分类', '总数取搜索命中集,不是当前页行数')
|
||||
|
||||
await wrapper.findAll('.manage-pager button').find((b) => b.text() === '下一页')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.findAll('.option-row')).toHaveLength(5, '第二页剩 5 行')
|
||||
expect(wrapper.text()).toContain('分类11')
|
||||
expect(wrapper.get('.manage-pager').text()).toContain('第 2 / 2 页')
|
||||
|
||||
await wrapper.get('.search-input').setValue('分类1')
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.manage-pager').exists()).toBe(false, '命中 3 条不足一页 ⇒ 不渲染页码条')
|
||||
expect(wrapper.findAll('.option-row')).toHaveLength(3, '搜索回第一页(不是停在旧页码的空白处)')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('分页:一屏装得下就不出页码条(不白占一行)', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3), group(8, '裤装', 1)])
|
||||
const wrapper = await mountDialog()
|
||||
expect(wrapper.findAll('.option-row')).toHaveLength(2)
|
||||
expect(wrapper.find('.manage-pager').exists()).toBe(false)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('搜索与新建行同属 manage-bar 的两行(搜索在上、新建在下,2026-11-17 改垂直排列)', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountDialog()
|
||||
const bar = wrapper.get('.manage-bar')
|
||||
const children = Array.from(bar.element.children)
|
||||
expect(children).toHaveLength(2, 'bar 只有两件:搜索框、新建行')
|
||||
expect(children[0].classList.contains('search-input')).toBe(true, '垂直排列时搜索在上')
|
||||
expect(children[1].classList.contains('group-create')).toBe(true, '新建行在下')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('改名:行内编辑后按 (id, {name, sortOrder}) 提交并 emit changed', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = await mountDialog()
|
||||
|
||||
@@ -18,8 +18,9 @@
|
||||
* 跑法:`npx vitest run tests/mount/jd-database-page.mount.test.ts`
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
@@ -107,12 +108,44 @@ beforeEach(() => {
|
||||
|
||||
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||||
jdApi.fetchJdProductList.mockImplementation(() => Promise.resolve(payload))
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia] } })
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
// ---------------- el-select 交互助手(2026-11-17 两颗下拉换 el-select,与亚马逊面统一) ----------------
|
||||
// aria-label 经 EP 的 ariaLabel prop 落在内层 combobox input 上;选项弹层 teleport 到 body,
|
||||
// 但 ElOption/ElSelect 组件仍在挂载树里 ⇒ 选项清单走组件树读,点选走「点开→点选项」真实路径。
|
||||
|
||||
/** 按 aria-label 找对应的 ElSelect 组件实例(页面有两颗下拉,靠内层 input 的 aria-label 区分)。 */
|
||||
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
|
||||
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
|
||||
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
|
||||
return found!
|
||||
}
|
||||
|
||||
/** 读某颗下拉的全部选项文案(label prop;组件树查询不受弹层 teleport 影响)。 */
|
||||
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
|
||||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
|
||||
}
|
||||
|
||||
/** 点开指定下拉并点选目标文案的选项(触发 update:modelValue + change,与真实用户一致)。
|
||||
* 面板按内层 input 的 aria-controls 圈定,避免另一颗(可能仍挂着的)弹层串台。 */
|
||||
async function pickSelectOption(wrapper: VueWrapper<Element>, label: string, optionText: string): Promise<void> {
|
||||
const input = wrapper.get(`[aria-label="${label}"]`)
|
||||
await input.trigger('click')
|
||||
await flushPromises()
|
||||
const contentId = input.attributes('aria-controls')
|
||||
const scope = (contentId && document.getElementById(contentId)) ?? document.body
|
||||
const items = [...scope.querySelectorAll('.el-select-dropdown__item')]
|
||||
.filter((el) => !el.classList.contains('is-hidden'))
|
||||
const target = items.find((el) => (el.textContent ?? '').trim() === optionText)
|
||||
expect(target, `下拉应弹出「${optionText}」选项`).toBeTruthy()
|
||||
await new DOMWrapper(target as Element).trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 批量编辑分类(2026-11-17 用户口径「店铺分类弹窗删了,加个批量编辑分类」):
|
||||
* 勾选跨页累计记忆(翻页/重取不清)→ 对话框选目标分类归入或移出 → 按 (ids, groupId,
|
||||
* ownerGroupId) 提交;成功后清勾选并重取。旧弹窗的「勾选翻页即清」口径同日废止。 */
|
||||
@@ -121,7 +154,7 @@ describe('批量编辑分类(店铺分类弹窗 2026-11-17 下线后的替代
|
||||
jdApi.fetchJdProductList
|
||||
.mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 40, page: 1, pageSize: 20 }))
|
||||
.mockImplementation(() => Promise.resolve({ items: [item(2)], total: 40, page: 2, pageSize: 20 }))
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia] } })
|
||||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
const deleteBtn = () => wrapper.get('.jd-delete-btn')
|
||||
@@ -229,6 +262,34 @@ describe('批量编辑分类(店铺分类弹窗 2026-11-17 下线后的替代
|
||||
})
|
||||
})
|
||||
|
||||
/** 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」+同日收敛
|
||||
* 「不需要全部分类 默认卡在未分类上就行」):工具栏「筛选分类状态」下拉只有两档
|
||||
* (已分类/未分类),出厂默认与「重置」都卡未分类;选中即查重回第一页;
|
||||
* 页面发的是筛选态字符串(classified/ungrouped),布尔换算收在 jd-product-filter 单一出口
|
||||
* (纯测试钉形状)。 */
|
||||
describe('分类状态快筛(两档,默认卡未分类)', () => {
|
||||
it('下拉只有两档且首屏就卡「未分类」(classified="ungrouped" 随首取下发)', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
expect(optionLabels(wrapper, '筛选分类状态')).toEqual(['已分类', '未分类'])
|
||||
expect(jdApi.fetchJdProductList.mock.calls[0][0].classified).toBe('ungrouped',
|
||||
'首屏默认档=未分类——用户口径「默认卡在未分类上就行」')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('选「已分类」下发 classified 态;「重置」不放开筛选,而是回默认未分类档', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await pickSelectOption(wrapper, '筛选分类状态', '已分类')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1 }, '选中即查回第一页')
|
||||
|
||||
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('ungrouped',
|
||||
'重置回出厂默认档(未分类),界面没有「全部」这一档可回')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
/** 分类管理入口(2026-11-17 用户口径「京东分类管理并到京东数据库分类编辑里」):
|
||||
* V204 独立子菜单页下线,工具栏「分类管理」打开 JdCategoryManageDialog(搜索+新建+
|
||||
* 改名+删除);入口对所有人渲染(同组普通号只读可看),写控件由对话框按 editable 分档;
|
||||
@@ -264,7 +325,7 @@ describe('分类管理入口(V204 独立页并入京东数据库页)', () =>
|
||||
: Promise.resolve([{ id: 8, name: '裤装', sortOrder: 1, productCount: 1 }])
|
||||
})
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
expect(wrapper.get('[aria-label="筛选店铺分类"]').text()).toContain('裙装', '首屏下拉含首取分类')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')).toContain('裙装', '首屏下拉含首取分类')
|
||||
|
||||
await wrapper.findAll('button').find((b) => b.text() === '分类管理')!.trigger('click')
|
||||
await flushPromises()
|
||||
@@ -276,9 +337,8 @@ describe('分类管理入口(V204 独立页并入京东数据库页)', () =>
|
||||
await flushPromises()
|
||||
expect(jdApi.deleteJdProductGroup, '删除按钮属于当前列表行').toHaveBeenCalledWith(8)
|
||||
// changed → 父页 loadGroupOptions:下拉按新列表重取(最后一次调用拿到删后列表)。
|
||||
const select = wrapper.get('[aria-label="筛选店铺分类"]')
|
||||
expect(select.text()).toContain('裤装', '下拉刷新出新一轮分类')
|
||||
expect(select.text()).not.toContain('裙装', '删掉的分类不再出现在筛选下拉')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')).toContain('裤装', '下拉刷新出新一轮分类')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')).not.toContain('裙装', '删掉的分类不再出现在筛选下拉')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
@@ -418,7 +478,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(textInputs).toHaveLength(2, '商品编码+标题关键字两个文本筛选框(店铺/商品状态已下线)')
|
||||
await textInputs[0].setValue('JD-1001')
|
||||
await textInputs[1].setValue('保温杯')
|
||||
await wrapper.get('[aria-label="筛选店铺分类"]').setValue('7')
|
||||
await pickSelectOption(wrapper, '筛选店铺分类', '甲组')
|
||||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||||
await dateInputs[0].setValue('2026-11-01')
|
||||
await dateInputs[1].setValue('2026-11-09')
|
||||
@@ -541,9 +601,8 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
it('重置把筛选面回空并回第一页重取', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 1 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const select = wrapper.get('[aria-label="筛选店铺分类"]')
|
||||
expect(select.text()).toContain('全部分类')
|
||||
await select.setValue('7')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')[0]).toBe('全部分类', '「全部分类」常驻列表首位(与旧原生下拉同语义)')
|
||||
await pickSelectOption(wrapper, '筛选店铺分类', '甲组')
|
||||
await wrapper.get('.cat-trigger').trigger('click')
|
||||
await wrapper.get('.cat-search').setValue('艺考')
|
||||
await wrapper.get('.cat-col-search .cat-row').trigger('click')
|
||||
@@ -558,7 +617,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore)
|
||||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(last).toMatchObject({ productCode: '', titleKeyword: '', groupId: '', category: '', page: 1 }, '重置后筛选全空、回第一页')
|
||||
expect((select.element as HTMLSelectElement).value).toBe('')
|
||||
expect(selectByLabel(wrapper, '筛选店铺分类').props('modelValue')).toBe('', '重置后分类筛选回「全部分类」')
|
||||
})
|
||||
|
||||
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
|
||||
@@ -569,8 +628,10 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(2)
|
||||
expect(jdApi.fetchJdProductList.mock.calls[1][0].page).toBe(3)
|
||||
|
||||
const sizeSelect = wrapper.find('.page-size-select')
|
||||
await sizeSelect.setValue('50')
|
||||
// 每页条数下拉 2026-11-17 随分页条一起换 el-select(OldPagination 内局部注册):
|
||||
// 点开→点选项,不再走原生 setValue。
|
||||
expect(wrapper.find('.page-size-select').exists()).toBe(true, '分页条下拉保留 .page-size-select 定位类')
|
||||
await pickSelectOption(wrapper, '每页条数', '50条/页')
|
||||
await flushPromises()
|
||||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||||
expect(last.pageSize).toBe(50)
|
||||
@@ -845,12 +906,12 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||||
const picker = wrapper.get('[aria-label="当前分组"]')
|
||||
// 2026-11-16 用户口径「做成分组」:分组在筛选行里是带标签的表单控件(与其他筛选同壳同圆角),
|
||||
// 不再是工具栏裸下拉——钉住形状,防止搬回工具栏或丢标签。
|
||||
const groupField = (picker.element as HTMLSelectElement).closest('.form-group')
|
||||
const groupField = picker.element.closest('.form-group')
|
||||
expect(groupField?.querySelector('label')?.textContent).toBe('分组')
|
||||
expect(picker.findAll('option').map((o) => o.text())).toEqual(['甲公司 / A组', '甲公司 / B组'],
|
||||
expect(optionLabels(wrapper, '当前分组')).toEqual(['甲公司 / A组', '甲公司 / B组'],
|
||||
'跨公司组名由后端拼进 label,前端不解析公司字段')
|
||||
|
||||
await picker.setValue('12')
|
||||
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(12)
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12, page: 1 },
|
||||
@@ -876,13 +937,12 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||||
],
|
||||
})
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const picker = wrapper.get('[aria-label="当前分组"]')
|
||||
await picker.setValue('12')
|
||||
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect((picker.element as HTMLSelectElement).value).toBe('12', '重置不清当前分组(作用域语义,搬进筛选行也不变)')
|
||||
expect(selectByLabel(wrapper, '当前分组').props('modelValue')).toBe(12, '重置不清当前分组(作用域语义,搬进筛选行也不变)')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 },
|
||||
'重置后的重取仍带当前分组')
|
||||
wrapper.unmount()
|
||||
@@ -893,7 +953,7 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||||
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 })
|
||||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false)
|
||||
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有分组就没有可锁定的组名')
|
||||
expect(wrapper.find('[aria-label="筛选店铺分类"]').text()).toContain('全部分类', '分类筛选只剩「全部分类」')
|
||||
expect(optionLabels(wrapper, '筛选店铺分类')).toEqual(['全部分类'], '分类筛选只剩「全部分类」')
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')[1].text()).toBe('未分类')
|
||||
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false, '没有分组就没有可写的分类面')
|
||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
/**
|
||||
* 日志管理页 / 生成记录页的原生 <select> → el-select(2026-11-17 用户口径「和亚马逊不统一」:
|
||||
* 原生 select 的弹层是浏览器直角原生物 ⇒ 换 EP 圆角弹层,外壳走全局 .admin-filter)。
|
||||
*
|
||||
* 这里钉住换壳时最容易错的两件事:
|
||||
* 1. **值形状逐字不变**——「全部来源」/「全部用户」空行仍是 ''、用户仍是 String(id)、
|
||||
* 终端仍是 `${source}|${deviceId}`、模式仍是 'full'/'selected' 常量(后端按这些字符串解析,
|
||||
* 形状一动就错单,而界面上看起来只是"选了个下拉");
|
||||
* 2. **选中 → 落参的链路仍只有一处**——来源 source、用户 Number(uid)、终端 '|' 切分与 mode 常量。
|
||||
*
|
||||
* aria-label 经 EP 的 ariaLabel prop 落在内层 combobox input 上,选项清单走组件树读
|
||||
* (弹层 teleport 到 body),点选走「点开→点选项」真实路径。
|
||||
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/records-select-el.mount.test.ts`
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
import { defineComponent, h } from 'vue'
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import DeviceLogsPage from '@/pages/records/DeviceLogsPage.vue'
|
||||
import RecordsHistoryPage from '@/pages/records/RecordsHistoryPage.vue'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
|
||||
const deviceLogsApi = vi.hoisted(() => ({
|
||||
fetchDeviceLogFiles: vi.fn(),
|
||||
fetchDeviceLogContent: vi.fn(),
|
||||
fetchDeviceLogConfig: vi.fn(),
|
||||
fetchDeviceLogDevices: vi.fn(),
|
||||
deviceLogDownloadUrl: vi.fn((id: number) => `/api/admin/device-logs/${id}/download`),
|
||||
deleteDeviceLogFile: vi.fn(),
|
||||
deleteDeviceLogOverride: vi.fn(),
|
||||
updateDeviceLogGlobalMode: vi.fn(),
|
||||
updateDeviceLogOverride: vi.fn(),
|
||||
}))
|
||||
|
||||
const historyApi = vi.hoisted(() => ({
|
||||
fetchHistoryList: vi.fn(),
|
||||
fetchHistoryUserOptions: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/device-logs', () => deviceLogsApi)
|
||||
vi.mock('@/pages/records/history-api.ts', () => historyApi)
|
||||
|
||||
/** 采集配置弹窗(el-dialog)用桩:真实 dialog 把内容 teleport 到 body,wrapper 里就查不到;
|
||||
* 桩只留一层 div 并把默认插槽摊在挂载树里,modelValue 与真实一样控制开关。 */
|
||||
const DialogStub = defineComponent({
|
||||
name: 'ElDialogStub',
|
||||
props: { modelValue: { type: Boolean, default: false } },
|
||||
setup(props, { slots }) {
|
||||
return () => (props.modelValue ? h('div', { class: 'dialog-stub' }, slots.default?.()) : null)
|
||||
},
|
||||
})
|
||||
|
||||
// ---------------- el-select 交互助手(与京东数据库页/亚马逊面同一套口径) ----------------
|
||||
|
||||
/** 按 aria-label 找对应的 ElSelect 组件实例(页面里还有 OldPagination 的「每页条数」,靠 aria-label 区分)。 */
|
||||
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
|
||||
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
|
||||
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
|
||||
return found!
|
||||
}
|
||||
|
||||
/** 读某颗下拉的全部选项文案(label prop;组件树查询不受弹层 teleport 影响)。 */
|
||||
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
|
||||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
|
||||
}
|
||||
|
||||
/** 读某颗下拉的全部选项 value(形状判据:空串/字符串 id/`source|deviceId`/mode 常量)。 */
|
||||
function optionValues(wrapper: VueWrapper<Element>, label: string): unknown[] {
|
||||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('value'))
|
||||
}
|
||||
|
||||
/** 点开指定下拉并点选目标文案的选项(触发 update:modelValue + change,与真实用户一致)。
|
||||
* 面板按内层 input 的 aria-controls 圈定,避免另一颗(可能仍挂着的)弹层串台。 */
|
||||
async function pickSelectOption(wrapper: VueWrapper<Element>, label: string, optionText: string): Promise<void> {
|
||||
const input = wrapper.get(`[aria-label="${label}"]`)
|
||||
await input.trigger('click')
|
||||
await flushPromises()
|
||||
const contentId = input.attributes('aria-controls')
|
||||
const scope = (contentId && document.getElementById(contentId)) ?? document.body
|
||||
const items = [...scope.querySelectorAll('.el-select-dropdown__item')].filter((el) => !el.classList.contains('is-hidden'))
|
||||
const target = items.find((el) => (el.textContent ?? '').trim() === optionText)
|
||||
expect(target, `下拉应弹出「${optionText}」选项`).toBeTruthy()
|
||||
await new DOMWrapper(target as Element).trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 按文案点按钮(筛选条上的查询/重置、弹窗里的添加/更新覆盖)。 */
|
||||
async function clickButton(wrapper: VueWrapper<Element>, text: string): Promise<void> {
|
||||
const button = wrapper.findAll('button').find((b) => b.text().trim() === text)
|
||||
expect(button, `应存在「${text}」按钮`).toBeTruthy()
|
||||
await button!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 最近一次调用的入参(首屏 + 公司 tab watch 可能各发一次,判"选完落什么参"只认最后一次)。 */
|
||||
function lastArgs(fn: { mock: { calls: unknown[][] } }): Record<string, unknown> {
|
||||
const calls = fn.mock.calls
|
||||
expect(calls.length, '接口应至少被调用一次').toBeGreaterThan(0)
|
||||
return calls[calls.length - 1][0] as Record<string, unknown>
|
||||
}
|
||||
|
||||
const USERS = [
|
||||
{ id: 7, username: '张三' },
|
||||
{ id: 8, username: '李四' },
|
||||
]
|
||||
|
||||
let pinia: Pinia
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
historyApi.fetchHistoryUserOptions.mockResolvedValue(USERS)
|
||||
})
|
||||
|
||||
async function mountDeviceLogs(): Promise<VueWrapper<Element>> {
|
||||
deviceLogsApi.fetchDeviceLogFiles.mockResolvedValue({ items: [], total: 0, page: 1, pageSize: 15, retentionDays: 7 })
|
||||
deviceLogsApi.fetchDeviceLogConfig.mockResolvedValue({ globalMode: 'full', overrides: [] })
|
||||
deviceLogsApi.fetchDeviceLogDevices.mockResolvedValue([
|
||||
{ source: 'client', deviceId: 'dev-1', deviceName: '工位A', lastUploadAt: null },
|
||||
])
|
||||
const wrapper = mount(DeviceLogsPage, {
|
||||
global: { plugins: [pinia, ElSelect, ElOption], stubs: { ElDialog: DialogStub } },
|
||||
})
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('日志管理页 × el-select', () => {
|
||||
it('筛选条两颗下拉:空行/字符串 id/来源常量逐字不变', async () => {
|
||||
const wrapper = await mountDeviceLogs()
|
||||
expect(optionLabels(wrapper, '来源')).toEqual(['全部来源', '桌面客户端', '麦象采集机'])
|
||||
expect(optionValues(wrapper, '来源')).toEqual(['', 'client', 'maixiang'])
|
||||
// 用户清单很长 ⇒ filterable;值仍是 String(id)(下游 `uidFilter.value ? Number(...)` 判空)
|
||||
expect(selectByLabel(wrapper, '指定用户').props('filterable')).toBe(true)
|
||||
expect(optionLabels(wrapper, '指定用户')).toEqual(['全部用户', '张三', '李四'])
|
||||
expect(optionValues(wrapper, '指定用户')).toEqual(['', '7', '8'])
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('选中来源/用户后查询:source 走常量、uid 仍是数字', async () => {
|
||||
const wrapper = await mountDeviceLogs()
|
||||
await pickSelectOption(wrapper, '来源', '麦象采集机')
|
||||
await pickSelectOption(wrapper, '指定用户', '李四')
|
||||
await clickButton(wrapper, '查询')
|
||||
const args = lastArgs(deviceLogsApi.fetchDeviceLogFiles)
|
||||
expect(args.source).toBe('maixiang')
|
||||
expect(args.uid).toBe(8)
|
||||
expect(typeof args.uid).toBe('number')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('重置回到空值首行:不发 source、不发 uid(空串的「全部」语义不变)', async () => {
|
||||
const wrapper = await mountDeviceLogs()
|
||||
await pickSelectOption(wrapper, '来源', '桌面客户端')
|
||||
await pickSelectOption(wrapper, '指定用户', '张三')
|
||||
await clickButton(wrapper, '重置')
|
||||
const args = lastArgs(deviceLogsApi.fetchDeviceLogFiles)
|
||||
expect(args.source).toBeUndefined()
|
||||
expect(args.uid).toBeUndefined()
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('采集配置弹窗:终端值仍是 `source|deviceId`、模式仍是 full/selected 常量', async () => {
|
||||
const wrapper = await mountDeviceLogs()
|
||||
await clickButton(wrapper, '采集配置')
|
||||
expect(optionLabels(wrapper, '选择终端')).toEqual(['选择终端(最近上报的设备)', '桌面客户端 · 工位A(dev-1)'])
|
||||
expect(optionValues(wrapper, '选择终端')).toEqual(['', 'client|dev-1'])
|
||||
expect(optionLabels(wrapper, '覆盖模式')).toEqual(['全量采集', '精选采集'])
|
||||
expect(optionValues(wrapper, '覆盖模式')).toEqual(['full', 'selected'])
|
||||
|
||||
await pickSelectOption(wrapper, '选择终端', '桌面客户端 · 工位A(dev-1)')
|
||||
await pickSelectOption(wrapper, '覆盖模式', '全量采集')
|
||||
await clickButton(wrapper, '添加/更新覆盖')
|
||||
expect(deviceLogsApi.updateDeviceLogOverride).toHaveBeenCalledWith('client', 'dev-1', '工位A', 'full')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('生成记录页 × el-select', () => {
|
||||
async function mountHistory(): Promise<VueWrapper<Element>> {
|
||||
historyApi.fetchHistoryList.mockResolvedValue({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
const wrapper = mount(RecordsHistoryPage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
it('指定用户下拉:空行 + String(id) 值形状不变', async () => {
|
||||
const wrapper = await mountHistory()
|
||||
expect(selectByLabel(wrapper, '指定用户').props('filterable')).toBe(true)
|
||||
expect(optionLabels(wrapper, '指定用户')).toEqual(['全部用户', '张三', '李四'])
|
||||
expect(optionValues(wrapper, '指定用户')).toEqual(['', '7', '8'])
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('选用户查询发数字 userId;选回「全部用户」不发 userId', async () => {
|
||||
const wrapper = await mountHistory()
|
||||
await pickSelectOption(wrapper, '指定用户', '李四')
|
||||
await clickButton(wrapper, '查询')
|
||||
expect(lastArgs(historyApi.fetchHistoryList).userId).toBe(8)
|
||||
|
||||
await pickSelectOption(wrapper, '指定用户', '全部用户')
|
||||
await clickButton(wrapper, '查询')
|
||||
expect(lastArgs(historyApi.fetchHistoryList).userId).toBeUndefined()
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
@@ -9,6 +9,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import KeywordUsagePage from '@/pages/tasks/KeywordUsagePage.vue'
|
||||
import BrandGatingPanel from '@/pages/tasks/BrandGatingPanel.vue'
|
||||
@@ -50,7 +51,9 @@ const loadingDirective = { mounted() {}, updated() {} }
|
||||
function mountPage(component: Parameters<typeof mount>[0], pinia: Pinia): VueWrapper {
|
||||
return mount(component, {
|
||||
global: {
|
||||
plugins: [pinia],
|
||||
// 筛选下拉 2026-11-17 换成 el-select(原生 select 弹层是直角原生物,与亚马逊页不统一),
|
||||
// 两支页面都要把 EP 组件注册进来,否则渲染成未解析标签。
|
||||
plugins: [pinia, ElSelect, ElOption],
|
||||
directives: { loading: loadingDirective },
|
||||
},
|
||||
})
|
||||
|
||||
@@ -17,12 +17,30 @@
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { ElOption, ElSelect } from 'element-plus'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
|
||||
import UserSecretsPage from '@/pages/account/UserSecretsPage.vue'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
|
||||
/* 筛选下拉 2026-11-17 起是 el-select(原生 select 的弹层是浏览器直角原生物,用户要求与亚马逊统一)。
|
||||
页面模板不带局部 import、靠 main.ts 全局注册,挂载测试不跑 main.ts ⇒ 必须在这里显式注册,
|
||||
否则拿到的是未解析的空壳,`findAllComponents(ElSelect)` 一条也找不到。 */
|
||||
const EL_PLUGINS = [ElSelect, ElOption]
|
||||
|
||||
/** 按 aria-label 找下拉:EP 把该属性落在内层 combobox input 上,比按节点顺序取更稳。 */
|
||||
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
|
||||
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
|
||||
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
|
||||
return found!
|
||||
}
|
||||
|
||||
/** 下拉里每一档的文案(读 el-option 的 label prop,不依赖插槽文本)。 */
|
||||
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
|
||||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
|
||||
}
|
||||
|
||||
const secretsApi = vi.hoisted(() => ({
|
||||
fetchUserSecretList: vi.fn(),
|
||||
fetchAdminSecretBalances: vi.fn(),
|
||||
@@ -106,7 +124,7 @@ describe('密钥管理页:检测结果按 check_code 分档渲染', () => {
|
||||
|
||||
async function mountWith(rowValue: Record<string, unknown>) {
|
||||
secretsApi.fetchUserSecretList.mockResolvedValue({ items: [rowValue], total: 1, page: 1, pageSize: 15, groupOptions: [] })
|
||||
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia] } })
|
||||
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia, ...EL_PLUGINS] } })
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
@@ -239,7 +257,7 @@ describe('密钥管理页:检测结果按 check_code 分档渲染', () => {
|
||||
|
||||
it('筛选项把 error 这一档的两个可能读法都点名(选了要能筛到无可用通道的行)', async () => {
|
||||
const wrapper = await mountWith(busyRow())
|
||||
const options = wrapper.findAll('.secrets-filter-row select')[0].findAll('option').map((option) => option.text().trim())
|
||||
const options = optionLabels(wrapper, '筛选密钥状态')
|
||||
expect(options).toContain('无法判定/可重试')
|
||||
expect(options).not.toContain('无法判定')
|
||||
})
|
||||
@@ -249,7 +267,7 @@ describe('密钥管理页:检测结果按 check_code 分档渲染', () => {
|
||||
secretsApi.checkUserSecret.mockResolvedValue([
|
||||
{ moduleKey: 'proxy', checkStatus: 'error', checkCode: 'channel_busy', checkMessage: BUSY_MESSAGE, checkLatencyMs: 30, checkedAt: '2026-11-02T15:51:07', viaProxy: false },
|
||||
])
|
||||
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia] } })
|
||||
const wrapper = mount(UserSecretsPage, { global: { plugins: [pinia, ...EL_PLUGINS] } })
|
||||
await flushPromises()
|
||||
const checkButton = wrapper.findAll('button').find((button) => button.text().trim() === '立即检测')
|
||||
expect(checkButton, '行内应有「立即检测」入口').toBeDefined()
|
||||
|
||||
@@ -19,7 +19,14 @@ const messageMock = vi.hoisted(() => ({ success: vi.fn() }))
|
||||
vi.mock('@/pages/records/workbench-client-api.ts', () => api)
|
||||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||
vi.mock('@/components/admin-feedback-ui', () => ({ showAdminFeedback: feedbackMock }))
|
||||
vi.mock('element-plus', () => ({ ElMessage: messageMock }))
|
||||
// 整包 mock element-plus 时,凡被挂载树里其它组件「局部 import」的 EP 组件都要一并给桩:
|
||||
// OldPagination 2026-11-17 起用 ElSelect/ElOption 渲染每页条数下拉,缺桩会
|
||||
// 让 render 拿到 undefined 抛 shapeFlag 错(本文件曾因此红)。样式与弹层不参与本页断言。
|
||||
vi.mock('element-plus', () => ({
|
||||
ElMessage: messageMock,
|
||||
ElSelect: { name: 'ElSelect', render: () => null },
|
||||
ElOption: { name: 'ElOption', render: () => null },
|
||||
}))
|
||||
|
||||
const SHA = 'c'.repeat(64)
|
||||
const row = {
|
||||
|
||||
+5
-1
@@ -120,6 +120,9 @@ public class AdminJdProductController {
|
||||
@RequestParam(name = "synced_from", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedFrom,
|
||||
@Parameter(description = "同步结束时间(包含,ISO datetime)")
|
||||
@RequestParam(name = "synced_to", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime syncedTo,
|
||||
@Parameter(description = "分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):"
|
||||
+ "true=当前分组下有分类,false=未分类,缺省=全部;按 V203 归属表 SQL 侧下推")
|
||||
@RequestParam(name = "classified", required = false) Boolean classified,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireJdAccess(request);
|
||||
if (request.getParameter("grouped") != null || request.getParameter("ungrouped") != null) {
|
||||
@@ -131,7 +134,8 @@ public class AdminJdProductController {
|
||||
requireVisibleCategory(scope, groupId);
|
||||
}
|
||||
return ApiResponse.success(jdProductQueryService.page(page, pageSize,
|
||||
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo, scopedOwnerGroupId));
|
||||
productCode, titleKeyword, category, groupId, syncedFrom, syncedTo, classified,
|
||||
scopedOwnerGroupId));
|
||||
}
|
||||
|
||||
@GetMapping("/categories")
|
||||
|
||||
@@ -49,13 +49,18 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
* 「分类不要了,全部整合到类目里」撤掉(独立「分类」筛选框前端下线,
|
||||
* {@code groupId} 改由类目面板「自定义分类」选中驱动)。
|
||||
* 店铺名过滤参数已随 2026-11-15 客户口径「店铺不需要」同窗撤掉(DB 列与详情/回传链不动)。
|
||||
* {@code classified}+{@code ownerGroupId}(2026-11-17 用户口径「加个已分类和未分类的筛选」):
|
||||
* 按 V203 归属表 EXISTS/NOT EXISTS 快筛分类状态,NULL=不过滤;与 11-16 撤掉的旧
|
||||
* grouped/ungrouped(读已停用的 biz_jd_product.group_id 列)不是一回事。
|
||||
*/
|
||||
long countProducts(@Param("productCode") String productCode,
|
||||
@Param("titleKeyword") String titleKeyword,
|
||||
@Param("category") String category,
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("syncedFrom") LocalDateTime syncedFrom,
|
||||
@Param("syncedTo") LocalDateTime syncedTo);
|
||||
@Param("syncedTo") LocalDateTime syncedTo,
|
||||
@Param("classified") Boolean classified,
|
||||
@Param("ownerGroupId") Long ownerGroupId);
|
||||
|
||||
/**
|
||||
* 商品上架配额计数({@code JdPublishQuotaService}):按 owner uid 集(管理员本人+
|
||||
@@ -95,6 +100,8 @@ public interface JdProductMapper extends BaseMapper<JdProductEntity> {
|
||||
@Param("groupId") Long groupId,
|
||||
@Param("syncedFrom") LocalDateTime syncedFrom,
|
||||
@Param("syncedTo") LocalDateTime syncedTo,
|
||||
@Param("classified") Boolean classified,
|
||||
@Param("ownerGroupId") Long ownerGroupId,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
|
||||
+16
-11
@@ -79,14 +79,18 @@ public class JdProductQueryService {
|
||||
* 分页查询商品行({@code synced_at} 倒序)。
|
||||
*
|
||||
* <p>过滤面:商品编码 contains、标题关键词 contains、类目 eq、分组 eq(2026-11-16 起
|
||||
* 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)。
|
||||
* 未分类/已分类两档(ungrouped/grouped)与独立「分类」筛选框随同日口径
|
||||
* 「分类不要了,全部整合到类目里」整批撤掉。
|
||||
* 由类目面板「自定义分类」选中驱动)、同步起止(datetime 闭区间)、分类状态档
|
||||
* {@code classified}(2026-11-17 用户口径「加个已分类和未分类的筛选」:true=当前分组下
|
||||
* 有分类、false=没有、null=全部;按 V203 归属表 EXISTS/NOT EXISTS 在 SQL 侧下推,
|
||||
* 判据与 {@link #fillGroupNames} 填分类列的条件同形——「筛选说未分类的行,列表分类列
|
||||
* 也必须是未分类」)。
|
||||
* 2026-11-16 撤掉的旧 ungrouped/grouped 两档读的是已停用的 biz_jd_product.group_id 列,
|
||||
* 与本档不是一回事;独立「分类」筛选框的撤掉口径不变。
|
||||
* 公司维过滤已随 2026-11-16 摘公司 tab 整批撤掉(全平台公共)。</p>
|
||||
*/
|
||||
public JdProductPageVo page(Long page, Long pageSize,
|
||||
String productCode, String titleKeyword, String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo, Long ownerGroupId) {
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified, Long ownerGroupId) {
|
||||
if (syncedFrom != null && syncedTo != null && syncedFrom.isAfter(syncedTo)) {
|
||||
throw new BusinessException("开始时间不能晚于结束时间");
|
||||
}
|
||||
@@ -94,14 +98,14 @@ public class JdProductQueryService {
|
||||
long safeSize = pageSize == null ? PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT
|
||||
: Math.min(Math.max(pageSize, 1), MAX_PAGE_SIZE);
|
||||
Filter filter = filter(productCode, titleKeyword, category,
|
||||
groupId, syncedFrom, syncedTo);
|
||||
groupId, syncedFrom, syncedTo, classified);
|
||||
long total = jdProductMapper.countProducts(filter.productCode(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(),
|
||||
filter.syncedFrom(), filter.syncedTo());
|
||||
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId);
|
||||
List<JdProductEntity> rows = total <= 0 ? List.of()
|
||||
: jdProductMapper.selectProductPage(filter.productCode(),
|
||||
filter.titleKeyword(), filter.category(), filter.groupId(),
|
||||
filter.syncedFrom(), filter.syncedTo(),
|
||||
filter.syncedFrom(), filter.syncedTo(), filter.classified(), ownerGroupId,
|
||||
(safePage - 1) * safeSize, (int) safeSize);
|
||||
List<JdProductListItemVo> items = rows.stream().map(this::toListItem).toList();
|
||||
fillGroupNames(items, ownerGroupId);
|
||||
@@ -176,18 +180,19 @@ public class JdProductQueryService {
|
||||
|
||||
// ---------------------------------------------------------------- 过滤面
|
||||
|
||||
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘)。 */
|
||||
/** 服务侧过滤面归一:groupId ≤0 按没选处理,文本 trim 后空串归 null(无公司维,2026-11-16 摘);
|
||||
* classified 原样直传(null=不过滤该面,2026-11-17 分类状态快筛)。 */
|
||||
private record Filter(String productCode, String titleKeyword,
|
||||
String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified) {
|
||||
}
|
||||
|
||||
private static Filter filter(String productCode, String titleKeyword,
|
||||
String category, Long groupId,
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo) {
|
||||
LocalDateTime syncedFrom, LocalDateTime syncedTo, Boolean classified) {
|
||||
Long safeGroupId = groupId != null && groupId > 0 ? groupId : null;
|
||||
return new Filter(trimToNull(productCode), trimToNull(titleKeyword),
|
||||
trimToNull(category), safeGroupId, syncedFrom, syncedTo);
|
||||
trimToNull(category), safeGroupId, syncedFrom, syncedTo, classified);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 列表/详情搬运
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
-- 迁移 V209:用户端京东功能纳入 app 菜单权限(「后台京东这边也要加菜单权限」2026-11-17)
|
||||
-- =============================================================
|
||||
-- 1. 变更目的:亚马逊/视频侧的用户端功能早已被 columns(menu_type='app') 树 + 逐用户勾授
|
||||
-- 管控(后管授权页勾选 → 用户端首页入口/工具台卡片按权限显隐),京东侧整条链缺失:
|
||||
-- app 树无任何京东行、京东工具台卡片不走过滤。本迁移补数据入口——新增「京东工具台」
|
||||
-- app 组行(jd_tools)+两个工具子行(jd-collect 获取店铺数据 / jd-publish 商品上架,
|
||||
-- 上架卡转正前占位,v1.5 Phase 4 无需再发迁移)。
|
||||
-- 【与 V190/V196 不预授权口径的偏离(有意,非漏写)】那是 admin 页面菜单——不预插时
|
||||
-- 默认仅超管可见,收紧不伤及现用人;app 行若不预授权,上线当天所有非超管账号立刻
|
||||
-- 失去现在人人可见的京东工具台,"隐藏"变成了静默断供。故预授权段逐字沿 V163 先例:
|
||||
-- 全表账号按所属公司授本公司【组行】(读侧 PermissionMenuService 展开子孙 ⇒ 两工具随组
|
||||
-- 可见;子行不预授,管理员收组后可按工具单独放)。停用账号照授(登录即拦,不构成可见
|
||||
-- 入口,避免解禁后菜单凭空消失——V163 头注 §2 同一口径)。
|
||||
--
|
||||
-- 2. 形状口径(V163 逐形,每公司一棵树按 V149 模型):
|
||||
-- - company_id=1 为模板树(CompanyService.create → copyTreeFromTemplate 的源头),
|
||||
-- 其余公司(含停用公司)逐家复制;子行 parent_id 认本公司组行,严禁跨公司认父。
|
||||
-- - 组行挂 app 根(parent_id=NULL,V80 组行形状),排序 140 接后勤工具(130) 之后;
|
||||
-- 子行 141/142。route_path=组 slug/前端 item key(V80/V90 形状),
|
||||
-- column_key 与前端 permissionKeys 逐字一致(jd_tools / jd-collect / jd-publish)。
|
||||
-- - 幂等守卫按 (company_id, column_key) 判存,同时防
|
||||
-- uk_company_menu_type_route_path(company_id, menu_type, route_path) 撞行。
|
||||
-- - 预授权 INSERT IGNORE 必须钉 col.column_key='jd_tools'——V163 第 4 段 JOIN 只按
|
||||
-- company_id 匹配(当时新键行天然唯一),照抄会让账号获得其本公司【全部】菜单行的
|
||||
-- 重复授权,属静默数据污染,此处按 key 收紧。
|
||||
--
|
||||
-- 3. 影响表与数据量:columns +3N 行(N=公司数),user_column_permission +账号数(只授组行);
|
||||
-- 字典/授权小表,毫秒级,不碰锁热点表。
|
||||
--
|
||||
-- 4. 可重跑性:三段 INSERT 都带 NOT EXISTS / INSERT IGNORE 守卫,重跑逐条 no-op;
|
||||
-- 自检闸门只读。
|
||||
--
|
||||
-- 5. 回滚(人工补丁,写成注释以免落在 Flyway 扫描路径里被当迁移执行;顺序照 V165:
|
||||
-- 先删授权,再删子行,最后删组行——parent_id 外键 ON DELETE RESTRICT):
|
||||
-- DELETE g FROM user_column_permission g JOIN columns c ON c.id=g.column_id
|
||||
-- WHERE c.column_key IN ('jd_tools','jd-collect','jd-publish');
|
||||
-- DELETE FROM columns WHERE column_key IN ('jd-collect','jd-publish');
|
||||
-- DELETE FROM columns WHERE column_key = 'jd_tools';
|
||||
-- DELETE FROM flyway_schema_history WHERE version='209';
|
||||
-- =============================================================
|
||||
|
||||
-- ---------- 1. 公司 1 模板树:组行 ----------
|
||||
INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`, `parent_id`, `company_id`)
|
||||
SELECT '京东工具台', 'jd_tools', 'app', 'jd-tools', 140, NULL, 1
|
||||
WHERE NOT EXISTS (
|
||||
SELECT 1 FROM `columns`
|
||||
WHERE `company_id` = 1
|
||||
AND (`column_key` = 'jd_tools'
|
||||
OR (`menu_type` = 'app' AND `route_path` = 'jd-tools'))
|
||||
);
|
||||
|
||||
-- ---------- 2. 组行复制到其余公司(含停用公司) ----------
|
||||
INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`, `parent_id`, `company_id`)
|
||||
SELECT '京东工具台', 'jd_tools', 'app', 'jd-tools', 140, NULL, c.`id`
|
||||
FROM `company` c
|
||||
WHERE c.`id` <> 1
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM `columns` col
|
||||
WHERE col.`company_id` = c.`id`
|
||||
AND (col.`column_key` = 'jd_tools'
|
||||
OR (col.`menu_type` = 'app' AND col.`route_path` = 'jd-tools'))
|
||||
);
|
||||
|
||||
-- ---------- 3. 两个工具子行(每家公司认本公司组行) ----------
|
||||
INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`, `parent_id`, `company_id`)
|
||||
SELECT '京东店铺数据采集', 'jd-collect', 'app', 'jd-collect', 141, grp.`id`, grp.`company_id`
|
||||
FROM `columns` grp
|
||||
WHERE grp.`column_key` = 'jd_tools'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM `columns` col
|
||||
WHERE col.`company_id` = grp.`company_id`
|
||||
AND (col.`column_key` = 'jd-collect'
|
||||
OR (col.`menu_type` = 'app' AND col.`route_path` = 'jd-collect'))
|
||||
);
|
||||
|
||||
INSERT INTO `columns` (`name`, `column_key`, `menu_type`, `route_path`, `sort_order`, `parent_id`, `company_id`)
|
||||
SELECT '京东商品上架', 'jd-publish', 'app', 'jd-publish', 142, grp.`id`, grp.`company_id`
|
||||
FROM `columns` grp
|
||||
WHERE grp.`column_key` = 'jd_tools'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM `columns` col
|
||||
WHERE col.`company_id` = grp.`company_id`
|
||||
AND (col.`column_key` = 'jd-publish'
|
||||
OR (col.`menu_type` = 'app' AND col.`route_path` = 'jd-publish'))
|
||||
);
|
||||
|
||||
-- ---------- 4. 全量账号默认授权组行(按账号所属公司授本公司的 jd_tools 行) ----------
|
||||
-- 必须钉 column_key:不钉就是"每账号获得本公司全部菜单行的重复授权"(见头注 §2)。
|
||||
INSERT IGNORE INTO `user_column_permission` (`user_id`, `column_id`)
|
||||
SELECT u.`id`, col.`id`
|
||||
FROM `users` u
|
||||
JOIN `columns` col
|
||||
ON col.`company_id` = u.`company_id`
|
||||
AND col.`column_key` = 'jd_tools';
|
||||
|
||||
-- ---------- 5. 自检闸门:不为 0 就抛 1048(列 must_be_zero NOT NULL,V143/V149/V163 家族) ----------
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS `_v209_gate` (`must_be_zero` INT NOT NULL);
|
||||
|
||||
-- 闸门 1:每家公司恰好 组行+子行 各一行,子行父指本公司组行、排序 140/141/142——
|
||||
-- 专防 INSERT 段被 NOT EXISTS 守卫"一声不响少一家树"(V149 闸门 1 同一形态)。
|
||||
INSERT INTO `_v209_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM (
|
||||
SELECT c.`id`
|
||||
FROM `company` c
|
||||
LEFT JOIN `columns` grp ON grp.`company_id` = c.`id` AND grp.`column_key` = 'jd_tools'
|
||||
LEFT JOIN `columns` kid ON kid.`company_id` = c.`id`
|
||||
AND kid.`column_key` IN ('jd-collect', 'jd-publish') AND kid.`parent_id` = grp.`id`
|
||||
GROUP BY c.`id`
|
||||
HAVING COUNT(DISTINCT grp.`id`) <> 1
|
||||
OR COUNT(DISTINCT kid.`id`) <> 2
|
||||
OR MAX(grp.`sort_order`) <> 140
|
||||
OR MIN(kid.`sort_order`) <> 141
|
||||
OR MAX(kid.`sort_order`) <> 142
|
||||
) bad;
|
||||
|
||||
-- 闸门 2:三条 app 路由不允许被别的 column_key 占行(防 uk_company_menu_type_route_path 语义被顶)。
|
||||
INSERT INTO `_v209_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM `columns` col
|
||||
WHERE col.`menu_type` = 'app'
|
||||
AND col.`route_path` IN ('jd-tools', 'jd-collect', 'jd-publish')
|
||||
AND col.`column_key` NOT IN ('jd_tools', 'jd-collect', 'jd-publish');
|
||||
|
||||
-- 闸门 3:每只账号都必须持有本公司 jd_tools 直授(第 4 段漏一行 = 该账号当天丢京东入口,
|
||||
-- 正是本迁移要防的"静默断供"形状)。
|
||||
INSERT INTO `_v209_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM (
|
||||
SELECT u.`id`
|
||||
FROM `users` u
|
||||
JOIN `columns` grp ON grp.`company_id` = u.`company_id` AND grp.`column_key` = 'jd_tools'
|
||||
LEFT JOIN `user_column_permission` g ON g.`user_id` = u.`id` AND g.`column_id` = grp.`id`
|
||||
WHERE g.`user_id` IS NULL
|
||||
) bad;
|
||||
|
||||
-- 闸门 4:jd_tools 的授权绝不指向别公司的组行(V163 闸门 2 同形,给手工插错留复验位)。
|
||||
INSERT INTO `_v209_gate`
|
||||
SELECT IF(COUNT(*) = 0, 0, NULL)
|
||||
FROM (
|
||||
SELECT g.`user_id`
|
||||
FROM `user_column_permission` g
|
||||
JOIN `users` u ON u.`id` = g.`user_id`
|
||||
JOIN `columns` col ON col.`id` = g.`column_id`
|
||||
WHERE col.`column_key` = 'jd_tools'
|
||||
AND col.`company_id` <> u.`company_id`
|
||||
) bad;
|
||||
|
||||
DROP TEMPORARY TABLE `_v209_gate`;
|
||||
@@ -122,6 +122,29 @@
|
||||
WHERE a.product_id = p.id AND a.category_id = #{groupId}
|
||||
)
|
||||
</if>
|
||||
<!-- 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):已分类=在
|
||||
「当前数据权限分组」(owner_group_id)下有 category_id 非空的归属行——与读侧
|
||||
fillGroupNames 把分类列填出来的条件同形;未分类=NOT EXISTS。谓词 SQL 侧下推
|
||||
(铁律 20 同形,不得 Java 侧对已取页 filter)。owner_group_id 为 NULL(作用域
|
||||
无可分组)时 EXISTS 恒假、NOT EXISTS 恒真——与列表「分类列全空」口径天然一致,
|
||||
不需要服务侧特判。与 2026-11-16 撤掉的旧 grouped/ungrouped 不是一回事:那两档
|
||||
读的是已停用的 biz_jd_product.group_id 列,本档读 V203 归属表。 -->
|
||||
<if test="classified != null">
|
||||
<choose>
|
||||
<when test="classified == true">
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM biz_jd_product_group_assign cs
|
||||
WHERE cs.product_id = p.id AND cs.owner_group_id = #{ownerGroupId} AND cs.category_id IS NOT NULL
|
||||
)
|
||||
</when>
|
||||
<otherwise>
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM biz_jd_product_group_assign cs
|
||||
WHERE cs.product_id = p.id AND cs.owner_group_id = #{ownerGroupId} AND cs.category_id IS NOT NULL
|
||||
)
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<if test="syncedFrom != null">AND p.synced_at >= #{syncedFrom}</if>
|
||||
<if test="syncedTo != null">AND p.synced_at <= #{syncedTo}</if>
|
||||
</sql>
|
||||
|
||||
@@ -105,6 +105,36 @@ class JdSchemaContractTest {
|
||||
assertTrue(sql.contains("迁移 V203"), "头注释必须是 `-- 迁移 V203…`(MigrationInventoryTest 口径)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void V209_app菜单_京东工具台三行与全量组行预授权() {
|
||||
String sql = read(DB_DIR.resolve("V209__jd_app_menu.sql"));
|
||||
assertTrue(sql.contains("迁移 V209"), "头注释必须是 `-- 迁移 V209…`(MigrationInventoryTest 口径)");
|
||||
for (String key : List.of("jd_tools", "jd-collect", "jd-publish")) {
|
||||
assertTrue(sql.contains("'" + key + "'"), "缺 app column_key: " + key);
|
||||
}
|
||||
assertTrue(sql.contains("京东工具台") && sql.contains("京东店铺数据采集") && sql.contains("京东商品上架"),
|
||||
"缺菜单名(组/采集/上架)");
|
||||
for (String route : List.of("jd-tools", "jd-collect", "jd-publish")) {
|
||||
assertTrue(sql.contains("'" + route + "'"), "缺 route_path: " + route);
|
||||
}
|
||||
assertTrue(sql.contains("'app'"), "三行必须是 menu_type='app'(用户端权限树)");
|
||||
assertTrue(sql.contains("NOT EXISTS"), "必须带幂等守卫");
|
||||
// 预授权段:与 V190/V196(admin 页不预插)不同,app 行不预授权=现用人当天丢功能,
|
||||
// 口径沿 V163——全量账号按公司授【组行】,且必须钉 column_key。
|
||||
assertTrue(sql.contains("INSERT IGNORE INTO `user_column_permission`"), "缺预授权段(V163 口径:默认全授组行)");
|
||||
assertTrue(sql.indexOf("INSERT IGNORE INTO `user_column_permission`") < sql.indexOf("_v209_gate"),
|
||||
"预授权段必须落在自检闸门之前");
|
||||
String grantSection = sql.substring(sql.indexOf("INSERT IGNORE INTO `user_column_permission`"));
|
||||
assertTrue(grantSection.lines().limit(15).anyMatch(line -> line.contains("col.`column_key` = 'jd_tools'")),
|
||||
"预授权 JOIN 必须钉 column_key='jd_tools'——不钉就是每账号获得本公司全部菜单行的重复授权(V163 隐患,本笔收紧)");
|
||||
// 四道自检闸门(形状/路由占位/无漏授/无跨公司授权)都要在。
|
||||
assertTrue(sql.contains("_v209_gate"), "缺自检闸门");
|
||||
long gates = sql.lines().filter(line -> line.startsWith("-- 闸门")).count();
|
||||
assertTrue(gates >= 4, "闸门不足四道(V163 只有两道,本笔必须多一道『无账号漏授』)");
|
||||
// 回滚写成注释(不进 Flyway 扫描),顺序照 V165:授权→子行→组行。
|
||||
assertTrue(sql.contains("flyway_schema_history WHERE version='209'"), "缺回滚注释");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 配置_独立图片桶不落默认桶() {
|
||||
String appYml = read(RESOURCES.resolve("application.yml"));
|
||||
|
||||
+87
-29
@@ -164,6 +164,10 @@ class AdminJdProductControllerTest {
|
||||
}
|
||||
assertFalse(source.contains("@RequestParam(name = \"ungrouped\""));
|
||||
assertFalse(source.contains("@RequestParam(name = \"grouped\""));
|
||||
// 2026-11-17 分类状态快筛:新参数名 classified(不复用旧 grouped/ungrouped 两档——
|
||||
// 那两档读已停用的 biz_jd_product.group_id 列,语义不同,旧参数仍必须被拒收)。
|
||||
assertTrue(source.contains("@RequestParam(name = \"classified\""),
|
||||
"分类状态快筛参数 classified 必须在册(2026-11-17 用户口径)");
|
||||
// company_id 参数已随 2026-11-16「删除掉公司 tab」整批摘除(读侧零公司维度支另有反向钉)。
|
||||
assertFalse(source.contains("company_id"), "company_id 请求参数必须已删除,不得回潜");
|
||||
// 商品状态筛选框已随 2026-11-15 客户口径从前端下线 ⇒ 服务端同名参数一起撤(反向钉住防回潜)。
|
||||
@@ -279,8 +283,8 @@ class AdminJdProductControllerTest {
|
||||
// 读:菜单权限命中即放行(公共库一人一份全量)。
|
||||
JdProductPageVo pageVo = new JdProductPageVo();
|
||||
pageVo.setItems(List.of());
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo);
|
||||
assertEquals(Boolean.TRUE, controller.page(1L, 20L, null, null, null, null, null, null, null, request)
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo);
|
||||
assertEquals(Boolean.TRUE, controller.page(1L, 20L, null, null, null, null, null, null, null, null, request)
|
||||
.isSuccess(), "非超管有菜单权限时读必须放行(读写分档只收窄写)");
|
||||
|
||||
// 商品行写:四条写入口一律 403,且业务服务一次都没被调到(不能「先写再拒」)。
|
||||
@@ -429,11 +433,11 @@ class AdminJdProductControllerTest {
|
||||
when(groupService.requireCategory(8L)).thenReturn(category(8L, 20L));
|
||||
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> controller.page(1L, 20L, null, null, null, 8L, null, null, null, request));
|
||||
() -> controller.page(1L, 20L, null, null, null, 8L, null, null, null, null, request));
|
||||
assertTrue(ex.getMessage().contains("无权查看该分组的分类"),
|
||||
"跨组分类筛选必须 403 点名分组,不做空结果降级");
|
||||
|
||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any());
|
||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
// ===================== 行为样本 =====================
|
||||
@@ -461,13 +465,13 @@ class AdminJdProductControllerTest {
|
||||
pageVo.setTotal(0L);
|
||||
pageVo.setPage(1L);
|
||||
pageVo.setPageSize((long) PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT);
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo);
|
||||
when(queryService.page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID)).thenReturn(pageVo);
|
||||
|
||||
// 请求面没有 company_id:任何授权身份看到的都是同一份全量;分类列按 owner_group_id 取。
|
||||
ApiResponse<JdProductPageVo> response = controller.page(1L, 20L, null, null, null, null,
|
||||
GROUP_ID, null, null, request);
|
||||
GROUP_ID, null, null, null, request);
|
||||
|
||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, GROUP_ID);
|
||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID);
|
||||
assertEquals(Boolean.TRUE, response.isSuccess(), "拒绝走 403 业务码,放行必须是 success 信封(B80-03)");
|
||||
assertEquals(pageVo, response.getData());
|
||||
}
|
||||
@@ -491,12 +495,12 @@ class AdminJdProductControllerTest {
|
||||
for (String value : List.of("true", "false", "")) {
|
||||
when(request.getParameter(name)).thenReturn(value);
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> controller.page(1L, 20L, null, null, null, 7L, null, null, null, request));
|
||||
() -> controller.page(1L, 20L, null, null, null, 7L, null, null, null, null, request));
|
||||
assertTrue(ex.getMessage().contains("刷新页面"));
|
||||
when(request.getParameter(name)).thenReturn(null);
|
||||
}
|
||||
}
|
||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any());
|
||||
verify(queryService, never()).page(any(), any(), any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -615,23 +619,23 @@ class AdminJdProductControllerTest {
|
||||
void 查询服务分页钳制防溢出() {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
|
||||
// page=0 / size=null ⇒ 归一为第 1 页、默认 20 条;offset = 0。
|
||||
service.page(0L, null, null, null, null, null, null, null, null);
|
||||
service.page(0L, null, null, null, null, null, null, null, null, null);
|
||||
ArgumentCaptor<Long> offset = ArgumentCaptor.forClass(Long.class);
|
||||
ArgumentCaptor<Integer> limit = ArgumentCaptor.forClass(Integer.class);
|
||||
verify(mapper).selectProductPage(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(),
|
||||
offset.capture(), limit.capture());
|
||||
isNull(), isNull(), offset.capture(), limit.capture());
|
||||
assertEquals(0L, offset.getValue());
|
||||
assertEquals(PageDefaults.JD_PRODUCTS_PAGE_SIZE_INT, limit.getValue());
|
||||
|
||||
// page=Long.MAX_VALUE / size=500 ⇒ 钳到 10_000 页、100 条;乘积 999_900 不得变负(铁律 15)。
|
||||
service.page(Long.MAX_VALUE, 500L, null, null, null, null, null, null, null);
|
||||
service.page(Long.MAX_VALUE, 500L, null, null, null, null, null, null, null, null);
|
||||
ArgumentCaptor<Long> offsetMax = ArgumentCaptor.forClass(Long.class);
|
||||
ArgumentCaptor<Integer> limitMax = ArgumentCaptor.forClass(Integer.class);
|
||||
verify(mapper, times(2)).selectProductPage(any(), any(), any(), any(), any(), any(),
|
||||
offsetMax.capture(), limitMax.capture());
|
||||
any(), any(), offsetMax.capture(), limitMax.capture());
|
||||
assertEquals(999_900L, offsetMax.getValue(), "(page-1)*page_size 最大 999_900,钳制后不得溢出变负");
|
||||
assertEquals(100, limitMax.getValue());
|
||||
}
|
||||
@@ -643,23 +647,77 @@ class AdminJdProductControllerTest {
|
||||
LocalDateTime from = LocalDateTime.of(2026, 11, 14, 12, 0);
|
||||
LocalDateTime to = LocalDateTime.of(2026, 11, 14, 8, 0);
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> service.page(1L, 20L, null, null, null, null, from, to, null));
|
||||
() -> service.page(1L, 20L, null, null, null, null, from, to, null, null));
|
||||
assertTrue(ex.getMessage().contains("开始时间不能晚于结束时间"), "倒挂时间按业务异常拒绝");
|
||||
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any());
|
||||
verify(mapper, never()).countProducts(any(), any(), any(), any(), any(), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void 查询服务过滤面原样直传且空串归null() {
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 7L, null, null, null);
|
||||
verify(mapper).countProducts("SKU-1", "连衣裙", "艺考形体服", 7L, null, null);
|
||||
verify(mapper).selectProductPage("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, 0L, 20);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
service.page(1L, 20L, " SKU-1 ", " 连衣裙 ", " 艺考形体服 ", 7L, null, null, null, null);
|
||||
verify(mapper).countProducts("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, null, null);
|
||||
verify(mapper).selectProductPage("SKU-1", "连衣裙", "艺考形体服", 7L, null, null, null, null, 0L, 20);
|
||||
|
||||
service.page(1L, 20L, " ", null, null, 0L, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, 0L, 20);
|
||||
service.page(1L, 20L, " ", null, null, 0L, null, null, null, null);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, null, null);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, null, null, 0L, 20);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类状态快筛(2026-11-17 用户口径「加个已分类和未分类的筛选」):
|
||||
* ① classified+ownerGroupId 必须原样下传给 mapper(谓词在 XML 的 EXISTS/NOT EXISTS 段,
|
||||
* 铁律 20 同形——不得 Java 侧对已取页 filter);
|
||||
* ② XML 绊线:两分支谓词逐字在册(改回 Java filter 或摘掉 owner_group_id 关联即红);
|
||||
* ③ 控制器把请求的 classified 直传服务(不吞、不改写)。
|
||||
*/
|
||||
@Test
|
||||
void 分类状态快筛必须SQL下推且classified与ownerGroupId成对直传() throws IOException {
|
||||
// ② XML 绊线:classified 档的 EXISTS/NOT EXISTS 两分支都在 productConds 里,
|
||||
// 且按「当前分组」owner_group_id+category_id 非空判——与读侧填分类列同形。
|
||||
Path xml = findJdProductMapperXml();
|
||||
String xmlText = stripComments(Files.readString(xml)).replaceAll("(?s)<!--.*?-->", "");
|
||||
assertTrue(xmlText.contains("classified == true"),
|
||||
"XML 必须有 classified==true 的已分类分支(SQL 侧下推,铁律 20 同形)");
|
||||
assertTrue(xmlText.contains("cs.owner_group_id = #{ownerGroupId}")
|
||||
&& xmlText.contains("cs.category_id IS NOT NULL"),
|
||||
"已分类判据必须按当前分组归属行且 category_id 非空(与 fillGroupNames 同形)");
|
||||
assertTrue(xmlText.contains("NOT EXISTS"), "未分类档必须是 NOT EXISTS(不是空结果降级)");
|
||||
assertEquals(2, count(xmlText, "cs.product_id = p.id"),
|
||||
"EXISTS/NOT EXISTS 两分支各一处商品关联,缺一个即红");
|
||||
|
||||
// ① 服务直传:classified 与 ownerGroupId 成对进 mapper(计数与分页同一过滤面)。
|
||||
JdProductMapper mapper = mock(JdProductMapper.class);
|
||||
JdProductQueryService service = queryService(mapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
service.page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, GROUP_ID);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, true, GROUP_ID);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, true, GROUP_ID, 0L, 20);
|
||||
|
||||
service.page(1L, 20L, null, null, null, null, null, null, Boolean.FALSE, GROUP_ID);
|
||||
verify(mapper).countProducts(null, null, null, null, null, null, false, GROUP_ID);
|
||||
verify(mapper).selectProductPage(null, null, null, null, null, null, false, GROUP_ID, 0L, 20);
|
||||
|
||||
// ③ 控制器直传:classified 原样进服务(owner_group_id 仍按作用域收敛后的值)。
|
||||
JdProductQueryService queryService = mock(JdProductQueryService.class);
|
||||
JdCategoryScopeService scopeService = mock(JdCategoryScopeService.class);
|
||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||
AdminJdProductController controller = new AdminJdProductController(
|
||||
queryService, mock(JdProductDeleteService.class), mock(JdProductUpdateService.class),
|
||||
mock(JdProductGroupService.class), scopeService, authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
JdCategoryScopeService.JdCategoryScope scope = writableScope(GROUP_ID, COMPANY_ID);
|
||||
when(scopeService.resolve(operator)).thenReturn(scope);
|
||||
when(scopeService.readGroupOrNull(scope, null)).thenReturn(GROUP_ID);
|
||||
controller.page(1L, 20L, null, null, null, null, null, null, null, Boolean.TRUE, request);
|
||||
verify(queryService).page(1L, 20L, null, null, null, null, null, null, Boolean.TRUE, GROUP_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -807,8 +865,8 @@ class AdminJdProductControllerTest {
|
||||
|
||||
JdProductEntity categorized = productEntity(1L);
|
||||
JdProductEntity missing = productEntity(2L);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(2L);
|
||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(),
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(2L);
|
||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
anyLong(), anyInt())).thenReturn(List.of(categorized, missing));
|
||||
when(assignMapper.selectList(any())).thenReturn(List.of(
|
||||
assign(1L, GROUP_ID, 3L), assign(2L, GROUP_ID, 99L)));
|
||||
@@ -817,7 +875,7 @@ class AdminJdProductControllerTest {
|
||||
category.setName("秋冬款");
|
||||
when(categoryMapper.selectBatchIds(any())).thenReturn(List.of(category));
|
||||
|
||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, GROUP_ID);
|
||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, GROUP_ID);
|
||||
|
||||
assertEquals(3L, vo.getItems().get(0).getGroupId(), "分类 id 取本组归属行");
|
||||
assertEquals("秋冬款", vo.getItems().get(0).getGroupName(), "行集归属一次取齐分类名(无逐行查询)");
|
||||
@@ -832,11 +890,11 @@ class AdminJdProductControllerTest {
|
||||
JdProductGroupAssignMapper assignMapper = mock(JdProductGroupAssignMapper.class);
|
||||
JdProductQueryService service = queryService(mapper, mock(JdProductImageMapper.class),
|
||||
mock(JdProductSkuMapper.class), mock(JdProductGroupMapper.class), assignMapper);
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(),
|
||||
when(mapper.countProducts(any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
|
||||
when(mapper.selectProductPage(any(), any(), any(), any(), any(), any(), any(), any(),
|
||||
anyLong(), anyInt())).thenReturn(List.of(productEntity(1L)));
|
||||
|
||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null);
|
||||
JdProductPageVo vo = service.page(1L, 20L, null, null, null, null, null, null, null, null);
|
||||
|
||||
assertNull(vo.getItems().get(0).getGroupId(), "不属于任何分组的账号:分类列一律空(未分类)");
|
||||
assertNull(vo.getItems().get(0).getGroupName());
|
||||
|
||||
@@ -64,9 +64,10 @@
|
||||
data-column-key="wb"
|
||||
>视频</router-link>
|
||||
|
||||
<!-- 京东入口:一级入口,不挂在亚马逊/视频的权限树里(京东工具台自带两个菜单,
|
||||
权限收口在工具台内部;入口恒显示,避免账号还没配京东菜单时入口凭空消失)。 -->
|
||||
<!-- 京东入口(V209 起纳入 app 菜单权限):jd_tools 组行或其子项/祖先命中即可见。
|
||||
权限接口异常时退回显示(与亚马逊/视频入口同一兜底),不空白。 -->
|
||||
<router-link
|
||||
v-if="canShow.jd"
|
||||
:to="jdHref"
|
||||
class="entrance-btn jd"
|
||||
:class="{ disabled: !jdHref }"
|
||||
@@ -81,7 +82,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { restoreLoginUser } from '@/shared/auth/ensure-auth'
|
||||
import { getCurrentUserAppColumnRaw, readCachedAppColumnPermissions, type PermissionMenuItem } from '@/shared/api/permission'
|
||||
import { getCurrentUserAppColumnRaw, readCachedAppColumnPermissions } from '@/shared/api/permission'
|
||||
import { computePermissionState, type PermissionState } from './home-permission'
|
||||
import { useVersionUpdate } from '@/shared/composables/useVersionUpdate'
|
||||
import UpdateProgressBar from '@/shared/components/UpdateProgressBar.vue'
|
||||
import UpdateLogList from '@/shared/components/UpdateLogList.vue'
|
||||
@@ -116,10 +118,10 @@ const {
|
||||
// 桌面端原 Flask /logout 已随瘦身下线:统一跳登录页并清本地 token(/login?logout=1)
|
||||
const logoutHref = computed(() => `${resolvePageHref('/new_web_source/login.html')}?logout=1`)
|
||||
|
||||
// 桌面端首页仅保留一级入口:亚马逊 / 视频;图片已收进视频页(/image-video)二级菜单。
|
||||
// 桌面端首页仅保留一级入口:亚马逊 / 视频 / 京东;图片已收进视频页(/image-video)二级菜单。
|
||||
// 入口先乐观显示(接口返回后按权限隐藏),避免权限接口慢时首页入口空白"点不了"。
|
||||
type PermissionState = { amazon: boolean; video: boolean }
|
||||
const permissionState = ref<PermissionState>({ amazon: true, video: true })
|
||||
// 权限计算在 ./home-permission(纯函数,tests/desktop-home-permission.test.ts 直测)。
|
||||
const permissionState = ref<PermissionState>({ amazon: true, video: true, jd: true })
|
||||
const permissionUnavailable = ref(false)
|
||||
|
||||
const amazonHref = computed(() => resolvePageHref('/new_web_source/amazon-console.html'))
|
||||
@@ -128,7 +130,7 @@ const videoHref = computed(() => resolvePageHref('/new_web_source/image-video.ht
|
||||
const jdHref = computed(() => resolvePageHref('/new_web_source/jd-console.html'))
|
||||
|
||||
const canShow = computed(() =>
|
||||
permissionUnavailable.value ? { amazon: true, video: true } : permissionState.value,
|
||||
permissionUnavailable.value ? { amazon: true, video: true, jd: true } : permissionState.value,
|
||||
)
|
||||
|
||||
function getUid() {
|
||||
@@ -137,36 +139,6 @@ function getUid() {
|
||||
return Number.isFinite(numeric) && numeric > 0 ? String(numeric) : ''
|
||||
}
|
||||
|
||||
function computePermissionState(items: PermissionMenuItem[]): PermissionState {
|
||||
const allowedKeys: string[] = []
|
||||
const allowedColumnKeys: string[] = []
|
||||
const allowedRootKeys: string[] = []
|
||||
let hasRootMetadata = false
|
||||
const push = (list: string[], value: unknown) => {
|
||||
const key = String(value || '').trim().toLowerCase()
|
||||
if (key && list.indexOf(key) < 0) list.push(key)
|
||||
}
|
||||
;(items || []).forEach((item) => {
|
||||
push(allowedColumnKeys, item.columnKey)
|
||||
push(allowedColumnKeys, item.column_key)
|
||||
const root = item.rootColumnKey || item.root_column_key
|
||||
if (root) {
|
||||
hasRootMetadata = true
|
||||
push(allowedRootKeys, root)
|
||||
}
|
||||
;[item.columnKey, item.column_key, item.routePath, item.route_path].forEach((v) => push(allowedKeys, v))
|
||||
})
|
||||
const videoVisible = allowedKeys.indexOf('wb') >= 0
|
||||
let amazonVisible =
|
||||
allowedRootKeys.indexOf('brand_front_tools') >= 0 ||
|
||||
allowedRootKeys.indexOf('brand_operation_tools') >= 0 ||
|
||||
allowedRootKeys.indexOf('brand_logistics_tools') >= 0
|
||||
if (!hasRootMetadata) {
|
||||
amazonVisible = allowedColumnKeys.some((key) => key !== 'wb')
|
||||
}
|
||||
return { amazon: amazonVisible, video: videoVisible }
|
||||
}
|
||||
|
||||
async function loadPermissions() {
|
||||
const currentUid = getUid()
|
||||
if (!currentUid) {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 桌面首页一级入口的权限计算(亚马逊 / 视频 / 京东)。
|
||||
*
|
||||
* 2026-11-17 自 DesktopHomePage.vue 原样抽薄(逻辑逐字未动):这段判据此前只活在 SFC 里、
|
||||
* 零测试;V209 把京东纳入 app 菜单权限并顺手收紧"只授京东的账号被误判亚马逊可见"的兜底,
|
||||
* 必须有用例钉住,故抽成纯函数模块由 tests/desktop-home-permission.test.ts 直测。
|
||||
* 数据源不变:shared/api/permission 的原始菜单项(含 localStorage 缓存路径),页面不得直连 /newApi。
|
||||
*/
|
||||
import type { PermissionMenuItem } from '@/shared/api/permission'
|
||||
|
||||
/** 京东侧权限键(V209 app 菜单):组行 jd_tools + 子行 jd-collect/jd-publish(route slug jd-tools)。 */
|
||||
export const JD_PERMISSION_KEYS: ReadonlySet<string> = new Set([
|
||||
'jd_tools',
|
||||
'jd-tools',
|
||||
'jd-collect',
|
||||
'jd-publish',
|
||||
])
|
||||
|
||||
export type PermissionState = { amazon: boolean; video: boolean; jd: boolean }
|
||||
|
||||
export function computePermissionState(items: PermissionMenuItem[]): PermissionState {
|
||||
const allowedKeys: string[] = []
|
||||
const allowedColumnKeys: string[] = []
|
||||
const allowedRootKeys: string[] = []
|
||||
let hasRootMetadata = false
|
||||
const push = (list: string[], value: unknown) => {
|
||||
const key = String(value || '').trim().toLowerCase()
|
||||
if (key && list.indexOf(key) < 0) list.push(key)
|
||||
}
|
||||
;(items || []).forEach((item) => {
|
||||
push(allowedColumnKeys, item.columnKey)
|
||||
push(allowedColumnKeys, item.column_key)
|
||||
const root = item.rootColumnKey || item.root_column_key
|
||||
if (root) {
|
||||
hasRootMetadata = true
|
||||
push(allowedRootKeys, root)
|
||||
}
|
||||
;[item.columnKey, item.column_key, item.routePath, item.route_path].forEach((v) => push(allowedKeys, v))
|
||||
})
|
||||
const videoVisible = allowedKeys.indexOf('wb') >= 0
|
||||
// 京东入口:组键命中(V209 预授权授的就是组行),或只授了子项时靠行的 root_column_key 祖先元数据命中。
|
||||
const jdVisible = allowedKeys.indexOf('jd_tools') >= 0 || allowedRootKeys.indexOf('jd_tools') >= 0
|
||||
let amazonVisible =
|
||||
allowedRootKeys.indexOf('brand_front_tools') >= 0 ||
|
||||
allowedRootKeys.indexOf('brand_operation_tools') >= 0 ||
|
||||
allowedRootKeys.indexOf('brand_logistics_tools') >= 0
|
||||
if (!hasRootMetadata) {
|
||||
// 旧权限接口不带 root 元数据时的兜底。原式只排除 'wb':V209 后"只授了京东"的账号会
|
||||
// 在这里被误判亚马逊可见(进去是空卡片墙),顺手把京东键一并排除——同形债不再留第二份。
|
||||
amazonVisible = allowedColumnKeys.some((key) => key !== 'wb' && !JD_PERMISSION_KEYS.has(key))
|
||||
}
|
||||
return { amazon: amazonVisible, video: videoVisible, jd: jdVisible }
|
||||
}
|
||||
@@ -31,11 +31,11 @@
|
||||
<i class="group-dot"></i>
|
||||
<span class="group-name">京东工具</span>
|
||||
<span class="group-desc">采集与上架,两条主线</span>
|
||||
<span class="group-count">{{ JD_TOOLS.length }} 个工具</span>
|
||||
<span class="group-count">{{ visibleTools.length }} 个工具</span>
|
||||
</header>
|
||||
|
||||
<div class="card-grid">
|
||||
<template v-for="tool in JD_TOOLS" :key="tool.id">
|
||||
<template v-for="tool in visibleTools" :key="tool.id">
|
||||
<router-link
|
||||
v-if="tool.href"
|
||||
:to="tool.href"
|
||||
@@ -89,11 +89,15 @@ import { onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
|
||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||
import { resolvePageHref } from '@/shared/page-prefix'
|
||||
import { JD_TOOLS, type JdToolInfo } from '@/pages/jd/tool-catalog'
|
||||
import { getCurrentUserAppColumnKeys } from '@/shared/api/permission'
|
||||
import { filterJdToolsByPermission, JD_TOOLS, type JdToolInfo } from '@/pages/jd/tool-catalog'
|
||||
|
||||
/** 返回桌面入口首页(亚马逊 / 京东 / 视频 一级入口) */
|
||||
const homeHref = resolvePageHref('/new_web_source/home.html')
|
||||
|
||||
/** 卡片显隐先乐观全量(接口返回后按菜单权限过滤,同 AmazonConsolePage 形状) */
|
||||
const visibleTools = ref<JdToolInfo[]>([...JD_TOOLS])
|
||||
|
||||
const username = ref('admin')
|
||||
const toastText = ref('')
|
||||
let toastTimer: number | undefined
|
||||
@@ -114,9 +118,21 @@ function onPendingClick(tool: JdToolInfo) {
|
||||
showToast(`${tool.name}暂未开通,敬请期待`)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
const localName = (window.localStorage.getItem('username') || '').trim()
|
||||
if (localName) username.value = localName
|
||||
// 判据与 AmazonConsolePage 同形:权限接口异常 ⇒ permissionUnavailable ⇒ 展示全部工具,
|
||||
// 正常 ⇒ 按 app 菜单权限过滤(V209:组键 jd_tools 整放,否则逐项 jd-collect/jd-publish)
|
||||
let allowedKeys: string[] = []
|
||||
let permissionUnavailable = false
|
||||
try {
|
||||
allowedKeys = await getCurrentUserAppColumnKeys()
|
||||
} catch (_error) {
|
||||
permissionUnavailable = true
|
||||
}
|
||||
visibleTools.value = permissionUnavailable
|
||||
? [...JD_TOOLS]
|
||||
: filterJdToolsByPermission(JD_TOOLS, allowedKeys)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
|
||||
@@ -6,6 +6,12 @@
|
||||
* 2. 商品上架:功能未落地,先按"假菜单"占位(点击提示暂未开通),不发 href。
|
||||
*
|
||||
* 卡片形状照亚马逊工具台(tool-catalog.ts)的 ToolInfo,样式复用同一套深色卡片墙。
|
||||
*
|
||||
* 菜单权限(V209):permissionKeys 与后端 columns(menu_type='app') 的 column_key 逐字一致
|
||||
* (jd_tools 组行 / jd-collect / jd-publish),跨端契约见 tests/jd-console-tool-catalog.test.ts。
|
||||
* 卡片显隐过滤用本文件的 filterJdToolsByPermission——判据与亚马逊 filterGroupsByPermission
|
||||
* 同形(组键命中整放,否则逐项),不直接导入是因为 ToolGroup.key 是 'front'|'ops'|'logi'
|
||||
* 字面量联合且组形状带颜色/工作流等必填件,京东借不了那个类型;改语义两头都要过用例。
|
||||
*/
|
||||
|
||||
export type JdToolInfo = {
|
||||
@@ -19,8 +25,13 @@ export type JdToolInfo = {
|
||||
tag?: string
|
||||
/** 功能页地址;未提供表示暂未开通(占位菜单) */
|
||||
href?: string
|
||||
/** 菜单权限键(小写),与后端 app 菜单 column_key 逐字一致 */
|
||||
permissionKeys: string[]
|
||||
}
|
||||
|
||||
/** app 菜单组键(columns.column_key='jd_tools'):勾中整组放行,同亚马逊 brand_*_tools 语义 */
|
||||
export const JD_GROUP_COLUMN_KEY = 'jd_tools'
|
||||
|
||||
export const JD_TOOLS: ReadonlyArray<JdToolInfo> = [
|
||||
{
|
||||
id: 'jd-collect',
|
||||
@@ -28,15 +39,33 @@ export const JD_TOOLS: ReadonlyArray<JdToolInfo> = [
|
||||
desc: '一键抓取已登录京麦后台的店铺商品(列表 + 详情全部属性 + 图片),导入后台「京东数据库」',
|
||||
tag: '核心',
|
||||
href: '/jd-collect',
|
||||
permissionKeys: ['jd-collect'],
|
||||
},
|
||||
{
|
||||
id: 'jd-publish',
|
||||
name: '商品上架',
|
||||
desc: '把京东数据库里的商品批量上架到京麦店铺(建设中,敬请期待)',
|
||||
tag: '规划中',
|
||||
permissionKeys: ['jd-publish'],
|
||||
},
|
||||
]
|
||||
|
||||
/**
|
||||
* 按菜单权限过滤京东工具卡片(与亚马逊 tool-catalog.ts::filterGroupsByPermission 同形判据):
|
||||
* 组键 jd_tools 命中则整组放行(预授权授的就是组行,读侧由后端展开子孙);
|
||||
* 否则只放行 permissionKeys 命中的卡片;空权限集 ⇒ 全隐藏。
|
||||
*/
|
||||
export function filterJdToolsByPermission(
|
||||
tools: ReadonlyArray<JdToolInfo>,
|
||||
allowedKeys: ReadonlyArray<string>,
|
||||
): JdToolInfo[] {
|
||||
const allowedSet = new Set(allowedKeys.map((key) => String(key || '').trim().toLowerCase()).filter(Boolean))
|
||||
if (allowedSet.has(JD_GROUP_COLUMN_KEY)) {
|
||||
return [...tools]
|
||||
}
|
||||
return tools.filter((tool) => tool.permissionKeys.some((key) => allowedSet.has(key.toLowerCase())))
|
||||
}
|
||||
|
||||
export const JD_TOOL_MAP: ReadonlyMap<string, JdToolInfo> = new Map(
|
||||
JD_TOOLS.map((tool) => [tool.id, tool] as const),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import { computePermissionState } from '../src/pages/home/home-permission.ts'
|
||||
|
||||
/**
|
||||
* 桌面首页一级入口权限计算(V209 把京东纳入 app 菜单权限)。
|
||||
* 判据形状:组行直授 / 子行直授带 root 元数据 / 无 root 元数据旧接口兜底,三条路都过。
|
||||
*/
|
||||
|
||||
type Item = Record<string, unknown>
|
||||
|
||||
function item(columnKey: string, rootColumnKey?: string, routePath?: string): Item {
|
||||
const it: Item = { id: columnKey, column_key: columnKey }
|
||||
if (rootColumnKey) it.root_column_key = rootColumnKey
|
||||
if (routePath) it.route_path = routePath
|
||||
return it
|
||||
}
|
||||
|
||||
test('组行 jd_tools 直授 ⇒ 京东入口可见', () => {
|
||||
const state = computePermissionState([item('jd_tools', 'jd_tools', 'jd-tools')])
|
||||
assert.equal(state.jd, true)
|
||||
})
|
||||
|
||||
test('只授子行(带 root_column_key=jd_tools 祖先元数据)⇒ 京东入口仍可见', () => {
|
||||
// V209 预授权授的是组行,但管理员收组后单授采集卡是合法配置:入口不能凭空消失。
|
||||
const state = computePermissionState([item('jd-collect', 'jd_tools', 'jd-collect')])
|
||||
assert.equal(state.jd, true)
|
||||
})
|
||||
|
||||
test('权限集与京东无关 ⇒ 京东入口隐藏', () => {
|
||||
const state = computePermissionState([item('wb', 'wb', 'image-video'), item('collect-data', 'brand_front_tools')])
|
||||
assert.equal(state.jd, false)
|
||||
assert.equal(state.video, true)
|
||||
})
|
||||
|
||||
test('只授京东 ⇒ 亚马逊入口不得假显示(有 root 元数据路)', () => {
|
||||
const state = computePermissionState([item('jd_tools', 'jd_tools', 'jd-tools')])
|
||||
assert.equal(state.jd, true)
|
||||
assert.equal(state.amazon, false)
|
||||
})
|
||||
|
||||
test('只授京东 ⇒ 亚马逊入口不得假显示(旧接口无 root 元数据兜底路,V209 顺手钉的判据)', () => {
|
||||
// 原实现兜底只排除 'wb':V209 后 jd 键混进兜底集合会被误判 amazon=true(点进去空卡片墙)。
|
||||
const state = computePermissionState([item('jd_tools'), item('jd-collect')])
|
||||
assert.equal(state.amazon, false, '无 root 元数据时,仅授京东键不得点亮亚马逊入口')
|
||||
assert.equal(state.jd, true)
|
||||
})
|
||||
|
||||
test('旧接口兜底不误伤既有语义:亚马逊子键仍点亮亚马逊入口', () => {
|
||||
const state = computePermissionState([item('collect-data')])
|
||||
assert.equal(state.amazon, true)
|
||||
})
|
||||
|
||||
test('大小写/空白归一:JD_TOOLS 照命中', () => {
|
||||
const state = computePermissionState([{ id: 1, column_key: ' JD_TOOLS ' }])
|
||||
assert.equal(state.jd, true)
|
||||
})
|
||||
@@ -3,7 +3,12 @@ import test from 'node:test'
|
||||
import { existsSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
import { JD_TOOLS, JD_TOOL_MAP } from '../src/pages/jd/tool-catalog.ts'
|
||||
import {
|
||||
filterJdToolsByPermission,
|
||||
JD_GROUP_COLUMN_KEY,
|
||||
JD_TOOLS,
|
||||
JD_TOOL_MAP,
|
||||
} from '../src/pages/jd/tool-catalog.ts'
|
||||
|
||||
/** 京东一级入口(v1.5):首页「京东」→ 京东工作台两个菜单(获取店铺数据 / 商品上架占位)。 */
|
||||
|
||||
@@ -54,3 +59,40 @@ test('获取店铺数据页是一键触发 + 服务端进度(任务面板改
|
||||
assert.ok(page.includes('jd-shop-collect-run'), '建单后必须推送本机客户端队列')
|
||||
assert.ok(page.includes('TaskCenterPanel'), '改版后右侧必须是共享任务面板(含历史任务层)')
|
||||
})
|
||||
|
||||
/* ===== V209 菜单权限:permissionKeys 与后端 app 菜单逐字对撞 + 过滤判据 ===== */
|
||||
|
||||
test('两张卡片都声明 permissionKeys 且与 V209 迁移 column_key 逐字一致', () => {
|
||||
// 跨仓对撞(后管 company-menu-route.test.ts 同族判据):迁移插的 app 菜单键与前端
|
||||
// permissionKeys 任何一侧改名而另一侧不动 ⇒ 这里红,而不是线上静默"勾了不显示"。
|
||||
const sqlPath = join(ROOT, '..', 'backend-java', 'src', 'main', 'resources', 'db', 'V209__jd_app_menu.sql')
|
||||
assert.ok(existsSync(sqlPath), `迁移缺失:${sqlPath}(V209 与前端权限键必须同窗改动)`)
|
||||
const sql = readFileSync(sqlPath, 'utf8')
|
||||
const frontendKeys = new Set<string>([JD_GROUP_COLUMN_KEY, ...JD_TOOLS.flatMap((tool) => tool.permissionKeys)])
|
||||
for (const key of frontendKeys) {
|
||||
assert.ok(sql.includes(`'${key}'`), `V209 迁移缺 column_key:${key}`)
|
||||
}
|
||||
for (const route of ['jd-tools', 'jd-collect', 'jd-publish']) {
|
||||
assert.ok(sql.includes(`'${route}'`), `V209 迁移缺 route_path:${route}`)
|
||||
}
|
||||
for (const tool of JD_TOOLS) {
|
||||
assert.ok(tool.permissionKeys.length > 0, `卡片 ${tool.id} 必须声明 permissionKeys`)
|
||||
}
|
||||
})
|
||||
|
||||
test('按菜单权限过滤京东卡片(与亚马逊 filterGroupsByPermission 同形判据)', () => {
|
||||
// 空权限集 ⇒ 全隐藏
|
||||
assert.deepEqual(filterJdToolsByPermission(JD_TOOLS, []), [])
|
||||
// 组键命中 ⇒ 整组放行(V209 预授权授的就是组行)
|
||||
assert.equal(filterJdToolsByPermission(JD_TOOLS, ['jd_tools']).length, 2)
|
||||
// 只授采集 ⇒ 只剩采集卡
|
||||
const collectOnly = filterJdToolsByPermission(JD_TOOLS, ['jd-collect'])
|
||||
assert.deepEqual(collectOnly.map((tool) => tool.id), ['jd-collect'])
|
||||
// 只授上架 ⇒ 只剩上架卡(占位卡转正前同样受控)
|
||||
const publishOnly = filterJdToolsByPermission(JD_TOOLS, ['jd-publish'])
|
||||
assert.deepEqual(publishOnly.map((tool) => tool.id), ['jd-publish'])
|
||||
// 大小写/空白归一(亚马逊侧同款 normalize:trim + lowercase)
|
||||
assert.equal(filterJdToolsByPermission(JD_TOOLS, [' JD_TOOLS ']).length, 2)
|
||||
// 无关键不放行任何卡片
|
||||
assert.deepEqual(filterJdToolsByPermission(JD_TOOLS, ['collect-data', 'wb']), [])
|
||||
})
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 京东工作台卡片按 app 菜单权限(V209)显隐的挂载用例。
|
||||
*
|
||||
* 四态判据,与 AmazonConsolePage 同形:
|
||||
* ① 组键 jd_tools 命中 ⇒ 两张卡都在(V209 预授权授的就是组行,线上默认形态);
|
||||
* ② 只授 jd-collect ⇒ 只剩采集卡(上架占位同样受控,转正后行为不变);
|
||||
* ③ 权限集与京东无关 ⇒ 两张卡都隐藏;
|
||||
* ④ 权限接口异常 ⇒ 展示全部(现用人不因接口抖动丢功能)。
|
||||
*
|
||||
* 跑法:cd frontend-vue && npx vitest run tests/mount/jd-console-permission.mount.test.ts
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { mount, type VueWrapper } from '@vue/test-utils'
|
||||
|
||||
vi.mock('@/shared/api/permission', () => ({
|
||||
getCurrentUserAppColumnKeys: vi.fn(),
|
||||
}))
|
||||
|
||||
import { getCurrentUserAppColumnKeys } from '@/shared/api/permission'
|
||||
import JdConsolePage from '@/pages/jd/JdConsolePage.vue'
|
||||
|
||||
let wrapper: VueWrapper | null = null
|
||||
|
||||
const mockKeys = (keys: string[]) =>
|
||||
vi.mocked(getCurrentUserAppColumnKeys).mockResolvedValue(keys)
|
||||
|
||||
async function mountConsole() {
|
||||
wrapper = mount(JdConsolePage, {
|
||||
global: {
|
||||
stubs: {
|
||||
NotificationBell: true,
|
||||
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
},
|
||||
},
|
||||
})
|
||||
// onMounted 里权限是异步 await,等过滤落地后再断言
|
||||
await vi.waitFor(() => {
|
||||
expect(vi.mocked(getCurrentUserAppColumnKeys).mock.calls.length).toBeGreaterThan(0)
|
||||
})
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('京东工作台按菜单权限显隐(V209)', () => {
|
||||
beforeEach(() => {
|
||||
window.localStorage.setItem('username', 'admin')
|
||||
vi.mocked(getCurrentUserAppColumnKeys).mockReset()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = null
|
||||
window.localStorage.clear()
|
||||
})
|
||||
|
||||
it('组键命中 ⇒ 两张卡都在', async () => {
|
||||
mockKeys(['jd_tools', 'jd-tools'])
|
||||
const w = await mountConsole()
|
||||
await vi.waitFor(() => expect(w.findAll('.tool-card').length).toBe(2))
|
||||
})
|
||||
|
||||
it('只授 jd-collect ⇒ 只剩获取店铺数据卡', async () => {
|
||||
mockKeys(['jd-collect'])
|
||||
const w = await mountConsole()
|
||||
await vi.waitFor(() => expect(w.findAll('.tool-card').length).toBe(1))
|
||||
// 断言圈在卡片节点上:hero 文案("店铺采集 · 商品上架")与计数是页面静态区,
|
||||
// 不参与权限过滤,拿整页 text() 判"商品上架消失"会误红。
|
||||
const cards = w.findAll('.tool-card')
|
||||
expect(cards[0].text()).toContain('获取店铺数据')
|
||||
expect(cards.every((card) => !card.classes().includes('tool-card--pending'))).toBe(true)
|
||||
expect(w.find('.group-count').text()).toContain('1 个工具')
|
||||
})
|
||||
|
||||
it('权限集与京东无关 ⇒ 两张卡都隐藏', async () => {
|
||||
mockKeys(['wb', 'collect-data'])
|
||||
const w = await mountConsole()
|
||||
await vi.waitFor(() => expect(w.findAll('.tool-card').length).toBe(0))
|
||||
expect(w.findAll('.tool-card').length).toBe(0)
|
||||
})
|
||||
|
||||
it('权限接口异常 ⇒ 展示全部(兜底不让现用人丢入口)', async () => {
|
||||
vi.mocked(getCurrentUserAppColumnKeys).mockRejectedValue(new Error('获取菜单权限失败'))
|
||||
const w = await mountConsole()
|
||||
await vi.waitFor(() => expect(w.findAll('.tool-card').length).toBe(2))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user