Compare commits
3 Commits
6dc33ea725
...
164b9b83fa
| Author | SHA1 | Date | |
|---|---|---|---|
| 164b9b83fa | |||
| 0f375dcd04 | |||
| b59663ebdb |
@@ -40,3 +40,27 @@ export function platformsOfMenuKey(key: string): PlatformTabId[] {
|
||||
if (BOTH_PLATFORM_MENU_KEYS.includes(key)) return ['amazon', 'jd']
|
||||
return ['amazon']
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用「按平台过滤菜单树」(唯一算法出口,2026-11-17 用户口径「授权树也按平台收」):
|
||||
* 叶子按 {@link platformsOfMenuKey} 是否包含当前平台留下;分组节点自身的 key 不参与
|
||||
* 平台判定,按「有存活的子项」决定去留——否则京东侧「账号与权限」这类混合分组会被整组误剪。
|
||||
* 两个消费方必须同形:侧边栏(platform-menu-filter.ts)与账号弹窗的授权树
|
||||
* (UserMenuAuthTree.vue),改判定规则只改这一处。
|
||||
*/
|
||||
export function filterMenuTreeNodesByPlatform<T extends { key?: string; children?: T[] }>(
|
||||
nodes: readonly T[] | null | undefined,
|
||||
platform: PlatformTabId,
|
||||
): T[] {
|
||||
const filtered: T[] = []
|
||||
for (const node of nodes || []) {
|
||||
const children = filterMenuTreeNodesByPlatform(node.children, platform)
|
||||
if (children.length > 0) {
|
||||
filtered.push({ ...node, children })
|
||||
continue
|
||||
}
|
||||
if ((node.children || []).length > 0) continue
|
||||
if (platformsOfMenuKey(node.key || '').includes(platform)) filtered.push({ ...node })
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AdminMenuNode } from '../types/admin'
|
||||
import { PLATFORM_TABS, platformsOfMenuKey } from '../config/platform-scope.ts'
|
||||
import { PLATFORM_TABS, filterMenuTreeNodesByPlatform } from '../config/platform-scope.ts'
|
||||
import type { PlatformTabId } from '../config/platform-scope.ts'
|
||||
import { firstVisiblePath } from '../router/helpers.ts'
|
||||
|
||||
@@ -7,27 +7,15 @@ import { firstVisiblePath } from '../router/helpers.ts'
|
||||
* 按平台 tab 过滤后端菜单树(2026-11-16「亚马逊/京东不混」):**只做显示分组,不做鉴权**——
|
||||
* 准入仍由 session.menuTree(后端按权限裁剪)与路由守卫负责,这里只是把当前用户已被授权的
|
||||
* 菜单按平台分到两个 tab 下展示。
|
||||
* 规则:叶子按 platformsOfMenuKey(key) 是否包含当前平台留下(双侧清单里的账号域三页两个
|
||||
* tab 都显示);分组节点(admin_group_*)自身的 key 不参与平台判定,按「留住的子项数 > 0」
|
||||
* 决定去留——否则京东 tab 下「账号与权限」这类混合分组会被整组误剪。节点的 key/name/
|
||||
* route/children 形状原样透传(浅拷贝不改写),toSidebarEntries、groupKeysForActive 与
|
||||
* 面包屑都不受影响。
|
||||
* 规则与算法在 {@link filterMenuTreeNodesByPlatform}(2026-11-17 起唯一出口,账号弹窗授权树
|
||||
* 同用一份);本壳只钉侧边栏专属的两条:节点的 key/name/route/children 形状原样透传(浅拷贝
|
||||
* 不改写),toSidebarEntries、groupKeysForActive 与面包屑都不受影响。
|
||||
*/
|
||||
export function filterMenuTreeByPlatform(
|
||||
nodes: AdminMenuNode[] | null | undefined,
|
||||
platform: PlatformTabId,
|
||||
): AdminMenuNode[] {
|
||||
const filtered: AdminMenuNode[] = []
|
||||
for (const node of nodes || []) {
|
||||
const children = filterMenuTreeByPlatform(node.children, platform)
|
||||
if (children.length > 0) {
|
||||
filtered.push({ ...node, children })
|
||||
continue
|
||||
}
|
||||
if ((node.children || []).length > 0) continue
|
||||
if (platformsOfMenuKey(node.key || '').includes(platform)) filtered.push({ ...node })
|
||||
}
|
||||
return filtered
|
||||
return filterMenuTreeNodesByPlatform(nodes, platform)
|
||||
}
|
||||
|
||||
/** 当前用户在哪些平台下至少有一个可点页面(tab 显示依据);顺序固定随 PLATFORM_TABS。
|
||||
|
||||
@@ -184,7 +184,9 @@ async function create(): Promise<void> {
|
||||
</el-form-item>
|
||||
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
|
||||
<div class="auth-tree-box">
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="form.companyId" />
|
||||
<!-- 授权树按所选平台收(2026-11-17 用户口径):选京东只给京东侧菜单,
|
||||
平台单选翻档时另一侧勾选自动剪掉(见 UserMenuAuthTree pruneChecked)。 -->
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="form.companyId" :platform="form.platform" />
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
@@ -152,7 +152,9 @@ async function save(): Promise<void> {
|
||||
</el-form-item>
|
||||
<el-form-item label="菜单权限(勾选上级菜单会继承全部子菜单)">
|
||||
<div class="auth-tree-box">
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="props.companyId" />
|
||||
<!-- 授权树按账号平台收(2026-11-17 用户口径):京东档账号不再整树混发亚马逊菜单,
|
||||
翻档时另一侧勾选自动剪掉(见 UserMenuAuthTree pruneChecked)。 -->
|
||||
<UserMenuAuthTree v-model:checked="form.columnIds" :company-id="props.companyId" :platform="form.platform" />
|
||||
<div v-if="loadingAuth" class="auth-loading">菜单权限加载中…</div>
|
||||
<div v-else-if="!authReady" class="auth-loading auth-loading-error">
|
||||
菜单权限加载失败,保存已禁用;请关闭后重试
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
||||
import { filterMenuTreeNodesByPlatform } from '../../config/platform-scope.ts'
|
||||
import type { PlatformTabId } from '../../config/platform-scope.ts'
|
||||
import type { MenuOptionNode } from './user-menu-auth'
|
||||
import { compactDirectGrantIds } from './user-menu-auth'
|
||||
import { compactDirectGrantIds, pruneCheckedIdsToTree } from './user-menu-auth'
|
||||
import { fetchGrantableMenus } from './user-menu-auth-api'
|
||||
|
||||
const props = defineProps<{ checked?: number[]; companyId?: number | null }>()
|
||||
const props = defineProps<{ checked?: number[]; companyId?: number | null; platform?: PlatformTabId }>()
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:checked', ids: number[]): void
|
||||
(e: 'load', ok: boolean): void
|
||||
@@ -17,9 +19,16 @@ const appTree = ref<{ setCheckedKeys(keys: unknown[]): void; getCheckedKeys(): u
|
||||
const data = ref<MenuOptionNode[]>([])
|
||||
const loaded = ref(false)
|
||||
|
||||
/**
|
||||
* 按平台过滤后的可见树(2026-11-17 用户口径「授权树也按平台收,选京东就去掉亚马逊的」):
|
||||
* 平台缺省按亚马逊(历史调用形状)。过滤算法与侧边栏同源(platform-scope 唯一出口),
|
||||
* 叶子按 menuKey 判定——京东侧只剩「京东数据库+双侧账号域三件」。
|
||||
*/
|
||||
const visibleData = computed(() => filterMenuTreeNodesByPlatform(data.value, props.platform ?? 'amazon'))
|
||||
|
||||
/** 两种一级分类…(与 API menuType 分区一致):后台(admin) / 桌面端(app)。 */
|
||||
const adminNodes = computed(() => data.value.filter((node) => node.type === 'admin'))
|
||||
const appNodes = computed(() => data.value.filter((node) => node.type === 'app'))
|
||||
const adminNodes = computed(() => visibleData.value.filter((node) => node.type === 'admin'))
|
||||
const appNodes = computed(() => visibleData.value.filter((node) => node.type === 'app'))
|
||||
|
||||
function applyChecked(): void {
|
||||
const ids = Array.isArray(props.checked) ? props.checked.filter((id) => typeof id === 'number' && id > 0) : []
|
||||
@@ -37,7 +46,8 @@ function onCheck(): void {
|
||||
// 提交前压缩为最小直接授权集:父级已勾选时后代不再重复提交(后端按“父级授权
|
||||
// 展开全部后代”判断权限,与旧 admin.html 勾父清后代语义一致),
|
||||
// 并剔除置灰的祖先分组(派生勾选,操作者无权授予)。
|
||||
emit('update:checked', compactDirectGrantIds(ids, data.value))
|
||||
// 压缩按「可见树」算:另一侧菜单不在树上,其历史勾选天然进不来。
|
||||
emit('update:checked', compactDirectGrantIds(ids, visibleData.value))
|
||||
}
|
||||
|
||||
async function load(): Promise<void> {
|
||||
@@ -49,12 +59,26 @@ async function load(): Promise<void> {
|
||||
// 渲染完成后再应用已勾选 id,否则作用在空 store 上导致已授权不回显。
|
||||
await nextTick()
|
||||
applyChecked()
|
||||
// 首屏就把勾选集收敛进可见树:编辑一个混档账号(既有亚马逊又有京东授权)时,
|
||||
// 打开弹窗那一刻就该按当前平台剪掉另一侧,而不是等用户点一下树才剪。
|
||||
pruneChecked()
|
||||
} catch {
|
||||
loaded.value = false
|
||||
emit('load', false)
|
||||
}
|
||||
}
|
||||
|
||||
/** 平台切换/首屏后把勾选集收敛进可见树:被过滤掉的另一侧勾选不再随表单提交,
|
||||
* 否则「京东档账号保存后仍带亚马逊授权」会把平台分侧静默架空。集合没变就不发
|
||||
* update 事件(避免与父级 v-model 循环互刷)。 */
|
||||
function pruneChecked(): void {
|
||||
const pruned = pruneCheckedIdsToTree(props.checked, visibleData.value)
|
||||
const current = Array.isArray(props.checked) ? props.checked : []
|
||||
if (pruned.length !== current.length || pruned.some((id, index) => id !== current[index])) {
|
||||
emit('update:checked', pruned)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
watch(
|
||||
() => props.checked,
|
||||
@@ -62,6 +86,16 @@ watch(
|
||||
if (loaded.value) applyChecked()
|
||||
},
|
||||
)
|
||||
/** 平台翻档:可见树整棵换,勾选集同步收敛到新树并回显(被剪掉的勾选以 emit 形式
|
||||
* 落回表单,父级拿到的是纯当前平台的授权集)。 */
|
||||
watch(
|
||||
() => props.platform,
|
||||
() => {
|
||||
if (!loaded.value) return
|
||||
pruneChecked()
|
||||
void nextTick().then(applyChecked)
|
||||
},
|
||||
)
|
||||
/** 公司换了要整棵重取:勾选集里存的是 column id,别家同名菜单是另一份 id(V149 每公司一套树),
|
||||
* 拿别家的树勾出来的 id 提交会被后端判「无效的菜单权限项」,而已授权项也因为 id 不在这棵树上勾不上。 */
|
||||
watch(
|
||||
|
||||
@@ -146,3 +146,24 @@ export function compactDirectGrantIds(checkedIds: unknown, tree: MenuOptionNode[
|
||||
walk(tree, false)
|
||||
return ids.filter((id) => !ungrantable.has(id) && !coveredByAncestor.has(id))
|
||||
}
|
||||
|
||||
/**
|
||||
* 把勾选集收敛到「可见树」内(2026-11-17 用户口径「授权树按平台收」的另一半):
|
||||
* 授权树按平台过滤后,另一侧的已勾 id 在树上不可见、也不再属于这棵树——它们必须
|
||||
* 从表单勾选集里剔除,否则「京东档账号」保存后仍携带整批亚马逊菜单授权(侧边栏
|
||||
* 亚马逊 tab 照样全亮,平台分侧被静默架空)。纯函数:入参不动,返回去重升序交集。
|
||||
*/
|
||||
export function pruneCheckedIdsToTree(checkedIds: unknown, visibleTree: MenuOptionNode[]): number[] {
|
||||
const ids = normalizeMenuIds(checkedIds)
|
||||
if (ids.length === 0) return []
|
||||
if (visibleTree.length === 0) return []
|
||||
const visible = new Set<number>()
|
||||
const walk = (nodes: MenuOptionNode[]): void => {
|
||||
for (const node of nodes) {
|
||||
visible.add(node.id)
|
||||
if (node.children?.length) walk(node.children)
|
||||
}
|
||||
}
|
||||
walk(visibleTree)
|
||||
return ids.filter((id) => visible.has(id))
|
||||
}
|
||||
|
||||
@@ -5,7 +5,11 @@
|
||||
* 职责不变:当前数据权限分组的分类建/改名/删除+新增的名称搜索;商品归类不在这里
|
||||
* (去「批量编辑分类」)。列表状态自管理(写操作后自刷新并 emit changed 让父页刷筛选下拉)。
|
||||
* 权限口径(V203)不变:本组管理员/公司超管/平台超管可写(editable);同组普通号
|
||||
* 只读可看(无新建行,改名/删除按钮逐行不渲染),后端同口径 403 兜底。 */
|
||||
* 只读可看(无新建行,改名/删除按钮逐行不渲染),后端同口径 403 兜底。
|
||||
* 2026-11-17 晚用户口径「admin 权限最大」:京东侧还没有任何数据权限分组时(平台闸
|
||||
* 上线后 jd 档组全空),平台超管在本弹窗空态直建第一个京东档分组(组长=自己),
|
||||
* 建完 emit group-created 让父页重取作用域,当前分组翻到新组后接着就能建分类,
|
||||
* 不再死在「你还不属于任何数据权限分组」。 */
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
createJdProductGroup,
|
||||
@@ -14,6 +18,8 @@ import {
|
||||
updateJdProductGroup,
|
||||
type JdProductGroup,
|
||||
} from './jd-product-api.ts'
|
||||
import { createShopGroup } from '../account/shop-group-api.ts'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
@@ -27,9 +33,13 @@ const props = defineProps<{
|
||||
ownerGroupName: string
|
||||
/** 当前分组可写(scope 的 editable):建/改名/删除控件全挂它。 */
|
||||
editable: boolean
|
||||
/** 操作者是否平台超管(scope 原样透传):只在「还没有分组」的空态开直建口子。 */
|
||||
platformSuperAdmin?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void }>()
|
||||
const emit = defineEmits<{ (event: 'close'): void; (event: 'changed'): void; (event: 'group-created'): void }>()
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
|
||||
const loading = ref(false)
|
||||
/** 首屏取数失败(可见红条+重试);写操作失败走 errorText 红条(无重试语义)。 */
|
||||
@@ -73,7 +83,8 @@ const showPager = computed(() => filteredGroups.value.length > PAGE_SIZE)
|
||||
function goPage(target: number): void {
|
||||
pageNo.value = Math.min(Math.max(1, target), totalPages.value)
|
||||
}
|
||||
/** 空表文案分四种:不属于任何组 / 本组没分类(可管理)/ 本组没分类(只读)/ 搜索无命中。 */
|
||||
/** 空表文案分四种:不属于任何组 / 本组没分类(可管理)/ 本组没分类(只读)/ 搜索无命中。
|
||||
* 平台超管的「还没有分组」空态不走这里——模板换成直建分组的表单(canBootstrapGroup)。 */
|
||||
const emptyListText = computed(() => {
|
||||
if (props.ownerGroupId <= 0) return '你还不属于任何数据权限分组'
|
||||
if (!groups.value.length) {
|
||||
@@ -82,6 +93,40 @@ const emptyListText = computed(() => {
|
||||
return '没有匹配的分类'
|
||||
})
|
||||
|
||||
/** 空态直建分组的口子(2026-11-17 用户口径「admin 权限最大」):平台超管 + 还没有任何
|
||||
* 可见分组时才开。组员/翻档等完整分组管理仍归「分组管理」页,这里只解决「从 0 到 1」。 */
|
||||
const canBootstrapGroup = computed(() => props.platformSuperAdmin === true && props.ownerGroupId <= 0)
|
||||
/** 直建表单:只收名称;组长=当前操作者,platform 恒 'jd'(京东侧作用域只认 jd 档)。 */
|
||||
const newGroupName = ref('')
|
||||
const creatingGroup = ref(false)
|
||||
const canCreateGroup = computed(() =>
|
||||
canBootstrapGroup.value && newGroupName.value.trim().length > 0 && !creatingGroup.value)
|
||||
|
||||
/** 平台超管空态直建第一个京东档分组:走分组管理同一条 POST(shop-manages/groups),
|
||||
* 组长=当前操作者、组员先空。成功后 emit group-created 让父页整条作用域重取——
|
||||
* ownerGroupId 翻到新组后由下方 watch 接手按新组重取分类,操作者接着就能建分类。 */
|
||||
async function submitCreateGroup(): Promise<void> {
|
||||
const name = newGroupName.value.trim()
|
||||
if (!name || creatingGroup.value || !canBootstrapGroup.value) return
|
||||
const operatorId = session.user?.id ?? 0
|
||||
if (!operatorId) {
|
||||
errorText.value = '无法获取当前登录用户,请重新登录'
|
||||
return
|
||||
}
|
||||
creatingGroup.value = true
|
||||
errorText.value = ''
|
||||
try {
|
||||
await createShopGroup(name, [], operatorId, 'jd')
|
||||
newGroupName.value = ''
|
||||
showAdminFeedback(`已新建京东档分组「${name}」`, 'success')
|
||||
emit('group-created')
|
||||
} catch (error) {
|
||||
errorText.value = requestErrorMessage(error) || '新建分组失败'
|
||||
} finally {
|
||||
creatingGroup.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadGroups(): Promise<void> {
|
||||
if (props.ownerGroupId <= 0) {
|
||||
groups.value = []
|
||||
@@ -177,6 +222,7 @@ watch(
|
||||
loadFailure.value = ''
|
||||
cancelRename()
|
||||
createName.value = ''
|
||||
newGroupName.value = ''
|
||||
pageNo.value = 1
|
||||
void loadGroups()
|
||||
}
|
||||
@@ -185,6 +231,15 @@ watch(
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
/** 建组成功后父页重取作用域会把 ownerGroupId 翻到新组:按新组重取分类列表,
|
||||
* 操作者不用关弹窗重开就能接着建分类。 */
|
||||
watch(
|
||||
() => props.ownerGroupId,
|
||||
(next, prev) => {
|
||||
if (next > 0 && next !== prev) void loadGroups()
|
||||
},
|
||||
)
|
||||
|
||||
/** 改关键字回第一页(命中集变了,停在旧页码会落在空白处)。 */
|
||||
watch(keyword, () => {
|
||||
pageNo.value = 1
|
||||
@@ -239,7 +294,24 @@ watch(totalPages, (pages) => {
|
||||
</li>
|
||||
</template>
|
||||
<li v-else-if="loading" class="manage-empty">加载中...</li>
|
||||
<li v-else class="manage-empty">{{ emptyListText }}</li>
|
||||
<li v-else class="manage-empty">
|
||||
<template v-if="canBootstrapGroup">
|
||||
<p class="bootstrap-lead">京东侧还没有数据权限分组,先新建一个:</p>
|
||||
<div class="group-bootstrap">
|
||||
<input
|
||||
v-model="newGroupName"
|
||||
class="search-input"
|
||||
type="text"
|
||||
placeholder="输入分组名称"
|
||||
aria-label="新分组名称"
|
||||
@keyup.enter="submitCreateGroup"
|
||||
/>
|
||||
<button class="btn" type="button" :disabled="!canCreateGroup" @click="submitCreateGroup">新建分组</button>
|
||||
</div>
|
||||
<p class="bootstrap-hint">组长=你(当前登录账号);组员稍后可在「分组管理(京东)」里加</p>
|
||||
</template>
|
||||
<template v-else>{{ emptyListText }}</template>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div v-if="showPager" class="manage-pager">
|
||||
@@ -427,6 +499,25 @@ watch(totalPages, (pages) => {
|
||||
font-size: 13px;
|
||||
list-style: none;
|
||||
}
|
||||
/* 平台超管空态直建分组:引导语+输入行+组长说明(2026-11-17 用户口径「admin 权限最大」)。 */
|
||||
.bootstrap-lead {
|
||||
margin: 0 0 10px;
|
||||
color: #5b6f83;
|
||||
}
|
||||
.group-bootstrap {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
.group-bootstrap .search-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
text-align: left;
|
||||
}
|
||||
.bootstrap-hint {
|
||||
margin: 10px 0 0;
|
||||
font-size: 12px;
|
||||
color: #97a7b8;
|
||||
}
|
||||
.manage-pager {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -48,6 +48,10 @@ const filter = reactive(createJdProductFilterState())
|
||||
/** 分类作用域(V203):可见分组 + 每组可写标记。失败静默回空作用域(分类列全空但商品照常)。 */
|
||||
const categoryScope = ref<JdCategoryGroupOption[]>([])
|
||||
const scopeDefaultGroupId = ref(0)
|
||||
/** 操作者是否平台超管(scope 原样透传):京东侧还没有任何分组时,分类管理弹窗
|
||||
* 靠它给平台超管开「直接新建数据权限分组」的口子(2026-11-17 用户口径「admin 权限最大」),
|
||||
* 其余角色维持空态指路,不在分类管理里建组。 */
|
||||
const scopeSuperAdmin = ref(false)
|
||||
/** 当前分组(数据权限分组 id):分类列/分类筛选/分类管理的共同作用域。 */
|
||||
const ownerGroupId = ref(0)
|
||||
/** 当前分组的分类下拉选项(按 ownerGroupId 取,切组即换)。 */
|
||||
@@ -110,9 +114,11 @@ async function loadCategoryScope(): Promise<void> {
|
||||
const scope = await fetchJdCategoryScope()
|
||||
categoryScope.value = scope.groups
|
||||
scopeDefaultGroupId.value = scope.defaultGroupId ?? 0
|
||||
scopeSuperAdmin.value = scope.platformSuperAdmin === true
|
||||
} catch {
|
||||
categoryScope.value = []
|
||||
scopeDefaultGroupId.value = 0
|
||||
scopeSuperAdmin.value = false
|
||||
}
|
||||
// 当前分组:保留用户已选(仍可见时),否则回默认(可见组第一项)。
|
||||
const keep = categoryScope.value.some((group) => group.id === ownerGroupId.value)
|
||||
@@ -167,6 +173,15 @@ async function onManaged(): Promise<void> {
|
||||
await loadGroupOptions()
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类管理里新建了第一个数据权限分组(平台超管空态直建,2026-11-17 用户口径「admin
|
||||
* 权限最大」):整条作用域重取——新组会进可见集并把「当前分组」翻过去,分类下拉、
|
||||
* 弹窗内分类列表随之按新组取,操作者接着就能建分类,不用关弹窗再开一遍。
|
||||
*/
|
||||
async function onGroupCreated(): Promise<void> {
|
||||
await loadCategoryScope()
|
||||
}
|
||||
|
||||
/** 批量归类完成(对话框已关):清勾选+重取列表(行集 groupName 变了)。
|
||||
* 移出分类 targetName 为 null;updated 是后端实际写入/解挂的归属行数。 */
|
||||
async function onBatchAssigned(updated: number, targetName: string | null): Promise<void> {
|
||||
@@ -534,8 +549,10 @@ onMounted(async () => {
|
||||
:owner-group-id="ownerGroupId"
|
||||
:owner-group-name="currentGroupName"
|
||||
:editable="canManageCategories"
|
||||
:platform-super-admin="scopeSuperAdmin"
|
||||
@close="manageVisible = false"
|
||||
@changed="onManaged"
|
||||
@group-created="onGroupCreated"
|
||||
/>
|
||||
<JdProductDetailDrawer
|
||||
:item="detailItem"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
|
||||
import JdCategoryManageDialog from '@/pages/jd/JdCategoryManageDialog.vue'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
|
||||
const jdApi = vi.hoisted(() => ({
|
||||
fetchJdProductGroups: vi.fn(),
|
||||
@@ -22,9 +23,14 @@ const jdApi = vi.hoisted(() => ({
|
||||
deleteJdProductGroup: vi.fn(),
|
||||
}))
|
||||
|
||||
const groupApi = vi.hoisted(() => ({
|
||||
createShopGroup: vi.fn(),
|
||||
}))
|
||||
|
||||
const confirmMock = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
||||
vi.mock('@/pages/account/shop-group-api.ts', () => groupApi)
|
||||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||
|
||||
/** 分组 id 常量:默认作用域就这一个可见且可写的组(组长档形状)。 */
|
||||
@@ -40,7 +46,10 @@ beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
// 空态直建分组(2026-11-17 用户口径「admin 权限最大」)需要当前登录人做组长。
|
||||
useAdminSessionStore().user = { id: 9, username: 'admin', role: 'super_admin' } as never
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
|
||||
confirmMock.mockResolvedValue(true)
|
||||
})
|
||||
|
||||
@@ -255,3 +264,98 @@ describe('京东分类管理对话框(V204 独立页 2026-11-17 并入京东
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
/** 平台超管空态直建分组(2026-11-17 用户口径「admin 权限最大」):京东侧还没有任何
|
||||
* 数据权限分组时(平台闸上线后 jd 档组全空,B117-02 前置未做),平台超管在弹窗里
|
||||
* 直接建第一个京东档分组,不再死在「你还不属于任何数据权限分组」。 */
|
||||
describe('平台超管空态直建京东档分组', () => {
|
||||
function mountEmpty(platformSuperAdmin: boolean): VueWrapper<Element> {
|
||||
return mount(JdCategoryManageDialog, {
|
||||
global: { plugins: [pinia] },
|
||||
props: { visible: true, ownerGroupId: 0, ownerGroupName: '', editable: false, platformSuperAdmin },
|
||||
})
|
||||
}
|
||||
|
||||
it('平台超管空态:出直建表单(不是死路文案),提交走分组管理同一条 POST 且 platform 恒 jd、组长=当前登录人', async () => {
|
||||
const wrapper = mountEmpty(true)
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductGroups).not.toHaveBeenCalled()
|
||||
expect(wrapper.get('.manage-empty').text()).toContain('京东侧还没有数据权限分组')
|
||||
expect(wrapper.get('[aria-label="新分组名称"]').exists()).toBe(true)
|
||||
|
||||
const input = wrapper.get('[aria-label="新分组名称"]')
|
||||
await input.setValue('京东-团队')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(groupApi.createShopGroup).toHaveBeenCalledTimes(1)
|
||||
expect(groupApi.createShopGroup).toHaveBeenCalledWith('京东-团队', [], 9, 'jd')
|
||||
expect(wrapper.emitted('group-created'), '建组成功即通知父页重取作用域').toBeTruthy()
|
||||
expect((input.element as HTMLInputElement).value).toBe('', '成功后清输入')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('没有当前登录人就不发请求并给可见错误(组长缺了这单没法建)', async () => {
|
||||
useAdminSessionStore().user = null
|
||||
const wrapper = mountEmpty(true)
|
||||
await flushPromises()
|
||||
await wrapper.get('[aria-label="新分组名称"]').setValue('京东-团队')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(groupApi.createShopGroup).not.toHaveBeenCalled()
|
||||
expect(wrapper.text()).toContain('无法获取当前登录用户')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('建组失败:错误进红条、不发 group-created(父页作用域不动)', async () => {
|
||||
groupApi.createShopGroup.mockRejectedValueOnce(new Error('分组名称已存在'))
|
||||
const wrapper = mountEmpty(true)
|
||||
await flushPromises()
|
||||
await wrapper.get('[aria-label="新分组名称"]').setValue('京东-团队')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('分组名称已存在')
|
||||
expect(wrapper.emitted('group-created')).toBeFalsy()
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('父页把 ownerGroupId 翻到新组后:直建表单消失、按新组重取分类(不用关弹窗重开)', async () => {
|
||||
const wrapper = mountEmpty(true)
|
||||
await flushPromises()
|
||||
await wrapper.get('[aria-label="新分组名称"]').setValue('京东-团队')
|
||||
await wrapper.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
|
||||
await flushPromises()
|
||||
const emittedBefore = wrapper.emitted('group-created')?.length ?? 0
|
||||
await wrapper.setProps({ ownerGroupId: 21, ownerGroupName: '京东-团队', editable: true })
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(21)
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(21)
|
||||
expect(wrapper.find('[aria-label="新分组名称"]').exists()).toBe(false, '有组了直建口子就关')
|
||||
expect(wrapper.emitted('group-created')?.length).toBe(emittedBefore, '翻组重取不再重复通知父页')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('非平台超管的空态维持原状:死路文案照旧、无直建表单(口子不开给组长/公司超管)', async () => {
|
||||
const wrapper = mountEmpty(false)
|
||||
await flushPromises()
|
||||
expect(wrapper.get('.manage-empty').text()).toBe('你还不属于任何数据权限分组')
|
||||
expect(wrapper.find('[aria-label="新分组名称"]').exists()).toBe(false)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('平台超管但已有分组(ownerGroupId>0):直建口子不出现(完整分组管理归「分组管理」页)', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([group(7, '裙装', 3)])
|
||||
const wrapper = mount(JdCategoryManageDialog, {
|
||||
global: { plugins: [pinia] },
|
||||
props: { visible: true, ownerGroupId: GROUP_A, ownerGroupName: '甲组', editable: true, platformSuperAdmin: true },
|
||||
})
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('[aria-label="新分组名称"]').exists()).toBe(false)
|
||||
expect(wrapper.text()).not.toContain('京东侧还没有数据权限分组')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -45,7 +45,12 @@ const jdApi = vi.hoisted(() => ({
|
||||
|
||||
const confirmMock = vi.hoisted(() => vi.fn())
|
||||
|
||||
const groupApi = vi.hoisted(() => ({
|
||||
createShopGroup: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
||||
vi.mock('@/pages/account/shop-group-api.ts', () => groupApi)
|
||||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||
|
||||
function item(id: number, over: Record<string, unknown> = {}) {
|
||||
@@ -103,6 +108,7 @@ beforeEach(() => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||||
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
|
||||
confirmMock.mockResolvedValue(true)
|
||||
})
|
||||
|
||||
@@ -343,6 +349,55 @@ describe('分类管理入口(V204 独立页并入京东数据库页)', () =>
|
||||
})
|
||||
})
|
||||
|
||||
/** 平台超管空态直建分组(2026-11-17 用户口径「admin 权限最大」):京东侧还没有任何
|
||||
* 数据权限分组时,分类管理弹窗给平台超管开直建口子;建完 group-created ⇒ 父页整条
|
||||
* 作用域重取,当前分组翻到新组、分类下拉与弹窗列表随新组走——从「死路」到「接着建
|
||||
* 分类」一气呵成。scope.platformSuperAdmin 是这条链的唯一开关,非超管维持空态文案。 */
|
||||
describe('平台超管空态直建分组(页面级链路)', () => {
|
||||
it('超管 + 京东侧零分组:弹窗出直建表单,建组走 POST(jd 档) 且作用域重取翻到新组', async () => {
|
||||
let scopeFetchCount = 0
|
||||
jdApi.fetchJdCategoryScope.mockImplementation(() => {
|
||||
scopeFetchCount += 1
|
||||
return scopeFetchCount === 1
|
||||
? Promise.resolve({ platformSuperAdmin: true, defaultGroupId: null, groups: [] })
|
||||
: Promise.resolve({
|
||||
platformSuperAdmin: true,
|
||||
defaultGroupId: 21,
|
||||
groups: [{ id: 21, name: '京东-团队', label: '京东-团队', editable: true }],
|
||||
})
|
||||
})
|
||||
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '分类管理')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.manage-modal')
|
||||
expect(modal.get('[aria-label="新分组名称"]').exists()).toBe(true, '超管空态不是死路文案')
|
||||
|
||||
await modal.get('[aria-label="新分组名称"]').setValue('京东-团队')
|
||||
await modal.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(groupApi.createShopGroup).toHaveBeenCalledWith('京东-团队', [], 1, 'jd')
|
||||
expect(jdApi.fetchJdCategoryScope).toHaveBeenCalledTimes(2, 'group-created ⇒ 父页整条作用域重取')
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(21)
|
||||
expect(wrapper.find('[aria-label="新分组名称"]').exists()).toBe(false, '有组了直建口子关掉')
|
||||
expect(wrapper.get('.manage-modal').text()).toContain('本组暂无分类,先新建一个', '接着就能建分类')
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('非超管 + 京东侧零分组:弹窗维持空态文案,无直建表单(口子不开给组长/公司超管)', async () => {
|
||||
jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, defaultGroupId: null, groups: [] })
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '分类管理')!.trigger('click')
|
||||
await flushPromises()
|
||||
const modal = wrapper.get('.manage-modal')
|
||||
expect(modal.text()).toContain('你还不属于任何数据权限分组')
|
||||
expect(modal.find('[aria-label="新分组名称"]').exists()).toBe(false)
|
||||
expect(groupApi.createShopGroup).not.toHaveBeenCalled()
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
|
||||
describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
it('挂载后按首屏分页参数取列表(pageSize 默认 20、不带公司维度),行数=本页条数', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1), item(2), item(3)], total: 42, page: 1, pageSize: 20 })
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { filterMenuTreeNodesByPlatform, platformsOfMenuKey } from '../src/config/platform-scope.ts'
|
||||
import { filterMenuTreeByPlatform } from '../src/layout/platform-menu-filter.ts'
|
||||
import type { MenuOptionNode } from '../src/pages/account/user-menu-auth.ts'
|
||||
import { pruneCheckedIdsToTree } from '../src/pages/account/user-menu-auth.ts'
|
||||
|
||||
/**
|
||||
* 授权树按平台过滤(2026-11-17 用户口径「这边也没有去掉亚马逊的」):建号/编辑弹窗的
|
||||
* 菜单权限树在选「京东」时只留京东侧菜单(京东数据库+双侧账号域三件),亚马逊菜单整枝
|
||||
* 隐藏;切平台时勾选集收敛进可见树(pruneCheckedIdsToTree),否则京东档账号保存后仍带
|
||||
* 亚马逊授权,平台分侧被静默架空。
|
||||
*
|
||||
* 算法与侧边栏同源(platform-scope.filterMenuTreeNodesByPlatform 唯一出口)——本文件
|
||||
* 同时钉「两个消费方同形」:同一夹具喂侧边栏版与授权树版,逐层 key 序列必须一致
|
||||
* (B79-12 同款钉法:一句判据在册有多份正本时,同形性本身要有人钉)。
|
||||
*/
|
||||
|
||||
const node = (id: number, key: string, children?: MenuOptionNode[]): MenuOptionNode => {
|
||||
const out: MenuOptionNode = { id, key, name: `菜单${id}`, sort: id, parentId: null, type: 'admin' }
|
||||
if (children) out.children = children
|
||||
return out
|
||||
}
|
||||
|
||||
/** 授权树实测形状缩影:混编分组(京东库+亚马逊页混在一个分组下)+两侧叶子。 */
|
||||
const TREE: MenuOptionNode[] = [
|
||||
node(1, 'admin_group_account', [
|
||||
node(11, 'admin_users'),
|
||||
node(12, 'admin_group_manage'),
|
||||
node(13, 'admin_companies'),
|
||||
node(14, 'admin_columns'),
|
||||
]),
|
||||
node(2, 'admin_jd_database'),
|
||||
node(3, 'admin_group_shop', [
|
||||
node(31, 'admin_shop_keys'),
|
||||
node(32, 'admin_shop_manage'),
|
||||
]),
|
||||
]
|
||||
|
||||
const keysOf = (nodes: MenuOptionNode[]): string[] =>
|
||||
nodes.map((n) => (n.children?.length ? `${n.key}(${keysOf(n.children).join(',')})` : n.key))
|
||||
|
||||
test('京东侧:只剩京东数据库+双侧账号域三件,亚马逊分组整枝消失', () => {
|
||||
const jd = filterMenuTreeNodesByPlatform(TREE, 'jd')
|
||||
assert.deepEqual(keysOf(jd), [
|
||||
'admin_group_account(admin_users,admin_group_manage,admin_companies)',
|
||||
'admin_jd_database',
|
||||
])
|
||||
})
|
||||
|
||||
test('亚马逊侧:京东独占菜单消失,亚马逊菜单与账号域分组原样', () => {
|
||||
const amazon = filterMenuTreeNodesByPlatform(TREE, 'amazon')
|
||||
assert.deepEqual(keysOf(amazon), [
|
||||
'admin_group_account(admin_users,admin_group_manage,admin_companies,admin_columns)',
|
||||
'admin_group_shop(admin_shop_keys,admin_shop_manage)',
|
||||
])
|
||||
})
|
||||
|
||||
test('与侧边栏过滤同形:同一夹具两个消费方逐层 key 一致(B79-12 钉法)', () => {
|
||||
for (const platform of ['amazon', 'jd'] as const) {
|
||||
const viaSidebar = keysOf(filterMenuTreeByPlatform(TREE as never, platform) as never)
|
||||
const viaAuthTree = keysOf(filterMenuTreeNodesByPlatform(TREE, platform))
|
||||
assert.deepEqual(viaAuthTree, viaSidebar, `platform=${platform} 两处消费方必须同形`)
|
||||
}
|
||||
})
|
||||
|
||||
test('判定出口不变:京东独占/双侧/默认亚马逊三个档位原样(改档位先改这里再改清单)', () => {
|
||||
assert.deepEqual(platformsOfMenuKey('admin_jd_database'), ['jd'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_users'), ['amazon', 'jd'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_shop_keys'), ['amazon'])
|
||||
})
|
||||
|
||||
test('pruneCheckedIdsToTree:勾选集收敛进可见树,隐藏侧 id 被剔除且原数组不动', () => {
|
||||
const jd = filterMenuTreeNodesByPlatform(TREE, 'jd')
|
||||
const checked = [11, 12, 2, 31, 99]
|
||||
const snapshot = checked.slice()
|
||||
const pruned = pruneCheckedIdsToTree(checked, jd)
|
||||
assert.deepEqual(pruned, [2, 11, 12], '只留可见树内的 id(31=亚马逊店务、99=不存在)')
|
||||
assert.deepEqual(checked, snapshot, '入参数组不被改写')
|
||||
})
|
||||
|
||||
test('pruneCheckedIdsToTree:空树全剪、空勾选原样空、非法 id 不复活', () => {
|
||||
assert.deepEqual(pruneCheckedIdsToTree([1, 2], []), [], '可见树为空=无可保留')
|
||||
assert.deepEqual(pruneCheckedIdsToTree([], TREE), [])
|
||||
assert.deepEqual(pruneCheckedIdsToTree([0, -3, 'x', 11.7], TREE), [11], '非法 id 按 normalizeMenuIds 口径收敛(丢弃/取整),不会原样漏进提交集')
|
||||
})
|
||||
@@ -21,7 +21,7 @@ import { userNotice } from '@/shared/utils/user-notice'
|
||||
import { formatDateTime } from '@/shared/utils/datetime'
|
||||
import { useLiveTaskBoard } from '@/shared/composables/useLiveTaskBoard'
|
||||
import NotificationBell from '@/shared/components/NotificationBell.vue'
|
||||
import { JD_SHOP_CATEGORY_SNAPSHOT, type JdShopCategory } from './jd-shop-category.ts'
|
||||
import { JD_SHOP_CATEGORY_SNAPSHOT } from './jd-shop-category.ts'
|
||||
|
||||
/** 京东「获取店铺数据」(v1.5):一键建单 → 推送本机客户端 → 右侧任务面板实时进度。
|
||||
*
|
||||
@@ -55,23 +55,23 @@ const submitting = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const successMessage = ref('')
|
||||
|
||||
// ---- 采集分类(可选,多选;空=全店采集)----
|
||||
// ---- 采集分类(可选,下拉多选;空=全店采集)----
|
||||
/** 选项集=京麦「店内分类」快照(getShopCategoryList,2026-11-16 真机取证 9 个;
|
||||
* 京麦侧改分类后按取证路重抓,见 jd-shop-category.ts 头注释——快照不会自动过期告警)。 */
|
||||
* 京麦侧改分类后按取证路重抓,见 jd-shop-category.ts 头注释——快照不会自动过期告警)。
|
||||
* 2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」:复选列表换 el-select 多选
|
||||
* (collapse-tags 折叠成「+N」徽标),选择模型改存分类 id 数组,label/id 双键从快照反查。 */
|
||||
const shopCategoryOptions = JD_SHOP_CATEGORY_SNAPSHOT
|
||||
const selectedShopCategories = ref<JdShopCategory[]>([])
|
||||
|
||||
function toggleShopCategory(category: JdShopCategory) {
|
||||
const hit = selectedShopCategories.value.find((item) => item.value === category.value)
|
||||
selectedShopCategories.value = hit
|
||||
? selectedShopCategories.value.filter((item) => item.value !== category.value)
|
||||
: [...selectedShopCategories.value, category]
|
||||
}
|
||||
const selectedShopCategoryValues = ref<string[]>([])
|
||||
|
||||
function clearShopCategories() {
|
||||
selectedShopCategories.value = []
|
||||
selectedShopCategoryValues.value = []
|
||||
}
|
||||
|
||||
/** 选中项按快照原序反查回对象(下拉里点选的先后不进请求体——双键顺序恒等于快照序)。 */
|
||||
const selectedShopCategories = computed(() =>
|
||||
shopCategoryOptions.filter((item) => selectedShopCategoryValues.value.includes(item.value)),
|
||||
)
|
||||
|
||||
/** 建单/推送载荷的选中值:label 与 id 双键同发(行级填充形状未取证,任一键命中即命中)。 */
|
||||
const selectedShopCategoryNames = computed(() => selectedShopCategories.value.map((item) => item.label))
|
||||
const selectedShopCategoryIds = computed(() => selectedShopCategories.value.map((item) => item.value))
|
||||
@@ -413,22 +413,17 @@ onUnmounted(() => {
|
||||
<aside class="left-panel">
|
||||
<div class="category-block">
|
||||
<span class="category-label">采集分类(可选,多选)</span>
|
||||
<ul class="shop-cat-list">
|
||||
<li v-for="category in shopCategoryOptions" :key="category.value">
|
||||
<label class="shop-cat-item" :title="`${category.label}(id ${category.value})`">
|
||||
<input type="checkbox" class="shop-cat-check"
|
||||
:checked="selectedShopCategories.some((item) => item.value === category.value)"
|
||||
@change="toggleShopCategory(category)" />
|
||||
<span class="shop-cat-name">{{ category.label }}</span>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
<el-select v-model="selectedShopCategoryValues" multiple collapse-tags collapse-tags-tooltip
|
||||
:max-collapse-tags="1" placeholder="不选=全店采集(点击选择分类)" class="shop-cat-select">
|
||||
<el-option v-for="category in shopCategoryOptions" :key="category.value"
|
||||
:label="category.label" :value="category.value" />
|
||||
</el-select>
|
||||
<p class="category-hint">
|
||||
{{ selectedShopCategories.length
|
||||
? `只采选中 ${selectedShopCategories.length} 个分类的商品;`
|
||||
{{ selectedShopCategoryValues.length
|
||||
? `只采选中 ${selectedShopCategoryValues.length} 个分类的商品;`
|
||||
: '不选=全店采集。' }}
|
||||
分类是京麦后台「店内分类」(2026-11-16 快照);商品要先在京麦挂上分类才会被选中。
|
||||
<button v-if="selectedShopCategories.length" class="shop-cat-clear" type="button"
|
||||
<button v-if="selectedShopCategoryValues.length" class="shop-cat-clear" type="button"
|
||||
@click="clearShopCategories">清空</button>
|
||||
</p>
|
||||
</div>
|
||||
@@ -667,42 +662,21 @@ onUnmounted(() => {
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
/* 采集分类多选块(2026-11-16 京麦店内分类快照):label 复用 category-label,
|
||||
* 列表项按暗色主题复选行样式(快照是纯前端数据,无加载失败分支)。 */
|
||||
.shop-cat-list {
|
||||
margin: 8px 0 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
/* 采集分类下拉多选(2026-11-17 客户口径「别全展示,弄下拉式多选」):
|
||||
* 暗色主题套品牌页 el-select 同款壳(wrapper 底色/描边/文字色),
|
||||
* 面板内弹层由 Element Plus 自带样式,不再逐条铺 9 行复选框。 */
|
||||
.shop-cat-select {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.shop-cat-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 5px 10px;
|
||||
border: 1px solid #3e4a62;
|
||||
border-radius: 6px;
|
||||
background: #232b3d;
|
||||
.shop-cat-select :deep(.el-select__wrapper) {
|
||||
background-color: #232b3d;
|
||||
box-shadow: 0 0 0 1px #3e4a62 inset;
|
||||
}
|
||||
|
||||
.shop-cat-select :deep(.el-select__placeholder),
|
||||
.shop-cat-select :deep(.el-select__selected-item) {
|
||||
color: #c8d2e2;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.shop-cat-item:hover {
|
||||
border-color: #5a6b8c;
|
||||
}
|
||||
|
||||
.shop-cat-check {
|
||||
accent-color: #e1251b;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.shop-cat-name {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.shop-cat-clear {
|
||||
|
||||
@@ -71,6 +71,10 @@ test('分类多选来自京麦店内分类快照,平台分组从本页下线',
|
||||
'JdCollectTab.vue 必须消费京麦店内分类快照(jd-shop-category.ts)作采集分类多选选项')
|
||||
assert.ok(page.includes('采集分类(可选,多选)'),
|
||||
'JdCollectTab.vue 必须以「采集分类(可选,多选)」展示分类块')
|
||||
assert.ok(page.includes('<el-select') && page.includes('multiple'),
|
||||
'采集分类必须是下拉式多选(el-select multiple,2026-11-17 客户口径「不要全展示出来,弄个下拉式的多选」)')
|
||||
assert.ok(!page.includes('shop-cat-list'),
|
||||
'JdCollectTab.vue 不得再回到逐条复选框列表(旧形状 2026-11-17 下线)')
|
||||
assert.ok(!page.includes('JdCategoryCascader'),
|
||||
'JdCollectTab.vue 不得再引用类目级联(2026-11-16 客户口径「类目不需要」)')
|
||||
assert.ok(!page.includes('fetchJdCollectGroups'),
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import ElementPlus, { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import JdCollectTab from '@/pages/jd/JdCollectTab.vue'
|
||||
|
||||
@@ -101,13 +102,33 @@ function batchOf(item: Record<string, unknown>) {
|
||||
|
||||
let wrapper: VueWrapper | null = null
|
||||
|
||||
async function mountPage() {
|
||||
/** el-select/el-option 轻量桩:轮询组用例不带真实 ElementPlus——真件在 fake timers 下
|
||||
* 的内部计时/Popper 会被 `advanceTimersByTimeAsync(60s)` 一并点燃、打断任务面板轮询链
|
||||
* (2026-11-17 改版实测 SUCCESS/FAILED 两格因此转红)。下拉形状由分类两格的真实组件
|
||||
* 用例兜底,这里只保证模板可解析、v-model 透传、选项渲染计数。 */
|
||||
const ElSelectStub = {
|
||||
name: 'ElSelect',
|
||||
props: ['modelValue'],
|
||||
emits: ['update:modelValue'],
|
||||
template: '<div class="shop-cat-select"><slot /></div>',
|
||||
}
|
||||
const ElOptionStub = {
|
||||
name: 'ElOption',
|
||||
props: ['label', 'value'],
|
||||
template: '<div class="shop-cat-option">{{ label }}</div>',
|
||||
}
|
||||
|
||||
async function mountPage(realSelect = false) {
|
||||
wrapper = mount(JdCollectTab, {
|
||||
global: {
|
||||
// 分类两格用真实 ElementPlus 组件树(经 update:modelValue 模拟点选,
|
||||
// 弹层 teleport 到 body,不依赖开合动画);其余格用桩。
|
||||
...(realSelect ? { plugins: [ElementPlus] } : {}),
|
||||
stubs: {
|
||||
NotificationBell: true,
|
||||
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
...(realSelect ? {} : { 'el-select': ElSelectStub, 'el-option': ElOptionStub }),
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -284,52 +305,52 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
expect(w.find('.feedback.error').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('勾选分类后建单:店内分类双键随建单请求体与推送载荷同链下发', async () => {
|
||||
// 2026-11-16 客户口径「类目不需要只要分类」「选京麦的内部分类去采集」+「做成多选的」:
|
||||
// 选项集=京麦「店内分类」快照(jd-shop-category.ts,getShopCategoryList 取证 9 个),
|
||||
// checkbox 多选;建单请求体与推送载荷带 label+id 双键(行级填充形状未取证,客户端
|
||||
// 任一键命中即命中)——mock 选中项用快照真实行(拉丁舞服/1024347572),贴合下发形状。
|
||||
const w = await mountPage()
|
||||
it('下拉选分类后建单:店内分类双键随建单请求体与推送载荷同链下发', async () => {
|
||||
// 2026-11-16 客户口径「类目不需要只要分类」「选京麦的内部分类去采集」;
|
||||
// 2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」:checkbox 列表换 el-select
|
||||
// 多选(collapse-tags)。选项集=京麦「店内分类」快照(jd-shop-category.ts,取证 9 个),
|
||||
// 选择模型是 id 数组;建单请求体与推送载荷带 label+id 双键、按快照原序反查(行级填充
|
||||
// 形状未取证,客户端任一键命中即命中)——选中项用快照真实行,贴合下发形状。
|
||||
const w = await mountPage(true)
|
||||
|
||||
const rows = w.findAll('.shop-cat-item')
|
||||
expect(rows.length).toBeGreaterThan(0, '分类多选列表必须渲染快照选项')
|
||||
const latinRow = rows.find((row) => row.text().includes('拉丁舞服'))
|
||||
expect(latinRow, '快照里必须有「拉丁舞服」').toBeTruthy()
|
||||
await latinRow!.find('input').setValue(true)
|
||||
const uniformRow = rows.find((row) => row.text().includes('工作制服'))
|
||||
await uniformRow!.find('input').setValue(true)
|
||||
const select = w.findComponent(ElSelect)
|
||||
expect(select.exists(), '采集分类必须是下拉多选(el-select),不再是逐条复选框').toBe(true)
|
||||
await select.vm.$emit('update:modelValue', ['1024347572', '1024347567'])
|
||||
await flushPromises()
|
||||
|
||||
await startCollect(w)
|
||||
|
||||
// 双键顺序恒等于快照序(工作制服在前),与点选先后无关——同源反查,不随 UI 顺序漂。
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, [],
|
||||
['拉丁舞服', '工作制服'], ['1024347572', '1024347567'])
|
||||
['工作制服', '拉丁舞服'], ['1024347567', '1024347572'])
|
||||
const payload = api.enqueue.mock.calls[0][0]
|
||||
expect(payload.data).toEqual({
|
||||
taskId: 88,
|
||||
shopName: '京麦后台',
|
||||
listTabs: ['ONSALE', 'OFFSALE'],
|
||||
maxProducts: 0,
|
||||
shopCategoryNames: ['拉丁舞服', '工作制服'],
|
||||
shopCategoryIds: ['1024347572', '1024347567'],
|
||||
shopCategoryNames: ['工作制服', '拉丁舞服'],
|
||||
shopCategoryIds: ['1024347567', '1024347572'],
|
||||
})
|
||||
})
|
||||
|
||||
it('采集分类块:快照选项全量渲染并可取消勾选(清空恢复全店采集)', async () => {
|
||||
const w = await mountPage()
|
||||
it('采集分类块:下拉渲染快照全量选项并可清空(恢复全店采集)', async () => {
|
||||
const w = await mountPage(true)
|
||||
|
||||
const block = w.findAll('.category-block').find((el) => el.text().includes('采集分类'))
|
||||
expect(block, '必须有「采集分类(可选,多选)」块').toBeTruthy()
|
||||
expect(block!.text()).toContain('采集分类(可选,多选)')
|
||||
// 快照 9 项全渲染(客户端「能看见管理员/商家建的分类」口径落点就在这)
|
||||
expect(block!.findAll('.shop-cat-item').length).toBe(9)
|
||||
// 快照 9 项全进下拉选项(客户端「能看见管理员/商家建的分类」口径落点就在这;
|
||||
// 弹层 teleport 到 body,选项组件仍挂在页面组件树里,按组件计数不按 DOM)
|
||||
expect(w.findAllComponents(ElOption).length).toBe(9)
|
||||
expect(block!.find('.shop-cat-select').exists(), '分类块必须是 el-select 下拉').toBe(true)
|
||||
expect(block!.text()).toContain('不选=全店采集')
|
||||
|
||||
const first = block!.findAll('.shop-cat-item')[0]
|
||||
await first.find('input').setValue(true)
|
||||
const select = block!.findComponent(ElSelect)
|
||||
await select.vm.$emit('update:modelValue', ['1024347567'])
|
||||
await flushPromises()
|
||||
expect(block!.text()).toContain('只采选中 1 个分类的商品')
|
||||
expect(block!.find('.shop-cat-clear').exists()).toBe(true, '选中后出「清空」')
|
||||
expect(block!.find('.shop-cat-clear').exists(), '选中后出「清空」').toBe(true)
|
||||
await block!.find('.shop-cat-clear').trigger('click')
|
||||
await flushPromises()
|
||||
expect(block!.text()).toContain('不选=全店采集')
|
||||
|
||||
Reference in New Issue
Block a user