feat(需求): ①创建/编辑用户菜单权限勾选父菜单自动全选子菜单(el-tree去check-strictly走父子联动,提交前压缩为最小直接授权集,父勾选时后代不重复落库) ②修复管理员勾选店铺数据菜单仍提示'无权查看店铺数据任务'——admin分区授权后若有效授权含店铺数据任务/重复检查菜单(含经'店铺管理'分组展开),自动补内部数据权限 admin_shop_data_crawl_task_data(镜像V84惯例只增不删,回收仍走超管数据范围授权UI)
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readSource } from './helpers.ts'
|
||||
import { compactDirectGrantIds, type MenuOptionNode } from '../src/pages/account/user-menu-auth.ts'
|
||||
|
||||
// 验收反馈:创建/编辑用户的权限菜单里,勾选父菜单要自动全选子菜单。
|
||||
// 实现:el-tree 去掉 check-strictly 走父子联动;提交时把勾选 id 压缩为最小
|
||||
// 直接授权集(父级已勾选时后代不再重复提交,后端按“父级授权展开后代”判断权限)。
|
||||
|
||||
const tree: MenuOptionNode[] = [
|
||||
{
|
||||
id: 1,
|
||||
key: 'root',
|
||||
name: '账号权限',
|
||||
sort: 1,
|
||||
parentId: null,
|
||||
type: 'admin',
|
||||
children: [
|
||||
{ id: 11, key: 'users', name: '用户管理', sort: 1, parentId: 1, type: 'admin' },
|
||||
{ id: 12, key: 'menus', name: '菜单管理', sort: 2, parentId: 1, type: 'admin' },
|
||||
{
|
||||
id: 13,
|
||||
key: 'sub',
|
||||
name: '子分组',
|
||||
sort: 3,
|
||||
parentId: 1,
|
||||
type: 'admin',
|
||||
children: [
|
||||
{ id: 131, key: 'leaf-a', name: '叶子A', sort: 1, parentId: 13, type: 'admin' },
|
||||
{ id: 132, key: 'leaf-b', name: '叶子B', sort: 2, parentId: 13, type: 'admin' },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{ id: 2, key: 'wb', name: '视频', sort: 1, parentId: null, type: 'app' },
|
||||
]
|
||||
|
||||
test('compactDirectGrantIds_keep_parent_only_when_children_also_checked', () => {
|
||||
// 勾选父 + 联动全选的子:压缩后只保留最上层父级。
|
||||
assert.deepEqual(compactDirectGrantIds([1, 11, 12, 13, 131, 132], tree), [1])
|
||||
})
|
||||
|
||||
test('compactDirectGrantIds_keep_partial_children_when_parent_unchecked', () => {
|
||||
// 父级未勾选、只勾部分子级:原样保留(父级半选,子级为直接授权)。
|
||||
assert.deepEqual(compactDirectGrantIds([11, 131], tree), [11, 131])
|
||||
})
|
||||
|
||||
test('compactDirectGrantIds_keep_topmost_checked_in_multi_level', () => {
|
||||
// 多层嵌套:爷勾选后,父/孙虽也被勾选但均被覆盖,只留爷。
|
||||
assert.deepEqual(compactDirectGrantIds([1, 13, 131], tree), [1])
|
||||
// 爷未勾、子分组勾选时保留子分组(覆盖其叶子)。
|
||||
assert.deepEqual(compactDirectGrantIds([13, 131], tree), [13])
|
||||
})
|
||||
|
||||
test('compactDirectGrantIds_merges_two_groups_and_dedupes', () => {
|
||||
const merged = [...tree, { id: 21, key: 'dup', name: '重复', sort: 1, parentId: null, type: 'admin' }]
|
||||
assert.deepEqual(compactDirectGrantIds([1, 11, 2, 21, 21], merged), [1, 2, 21])
|
||||
})
|
||||
|
||||
test('compactDirectGrantIds_empty_inputs', () => {
|
||||
assert.deepEqual(compactDirectGrantIds([], tree), [])
|
||||
assert.deepEqual(compactDirectGrantIds([11], []), [11])
|
||||
})
|
||||
|
||||
test('user_menu_auth_tree_uses_linked_check_and_compacts', () => {
|
||||
const component = readSource('src/pages/account/UserMenuAuthTree.vue')
|
||||
assert.ok(!/check-strictly/.test(component), '必须去掉 check-strictly,勾父联动全选子')
|
||||
assert.match(component, /compactDirectGrantIds/, '@check 提交需压缩为最小直接授权集')
|
||||
assert.match(component, /default-expand-all/, '默认展开全部菜单')
|
||||
})
|
||||
Reference in New Issue
Block a user