sc
This commit is contained in:
@@ -110,14 +110,9 @@
|
|||||||
// 找到当前菜单
|
// 找到当前菜单
|
||||||
const menu = findMenuById(menuId, props.treeData)
|
const menu = findMenuById(menuId, props.treeData)
|
||||||
|
|
||||||
// 如果是上级菜单,选中所有子菜单
|
// 如果是上级菜单,选中所有子菜单(递归)
|
||||||
if (menu && hasChildren(menu)) {
|
if (menu && hasChildren(menu)) {
|
||||||
menu.children.forEach(child => {
|
selectAllChildren(menu, newSelected)
|
||||||
const childId = getMenuId(child)
|
|
||||||
if (!newSelected.includes(childId)) {
|
|
||||||
newSelected.push(childId)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查并选中上级菜单
|
// 检查并选中上级菜单
|
||||||
@@ -132,15 +127,9 @@
|
|||||||
// 找到当前菜单
|
// 找到当前菜单
|
||||||
const menu = findMenuById(menuId, props.treeData)
|
const menu = findMenuById(menuId, props.treeData)
|
||||||
|
|
||||||
// 如果是上级菜单,取消选中所有子菜单
|
// 如果是上级菜单,取消选中所有子菜单(递归)
|
||||||
if (menu && hasChildren(menu)) {
|
if (menu && hasChildren(menu)) {
|
||||||
menu.children.forEach(child => {
|
unselectAllChildren(menu, newSelected)
|
||||||
const childId = getMenuId(child)
|
|
||||||
const childIndex = newSelected.indexOf(childId)
|
|
||||||
if (childIndex > -1) {
|
|
||||||
newSelected.splice(childIndex, 1)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查并取消选中上级菜单
|
// 检查并取消选中上级菜单
|
||||||
@@ -151,6 +140,35 @@
|
|||||||
emit('update:modelValue', newSelected)
|
emit('update:modelValue', newSelected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 递归选中所有子菜单
|
||||||
|
function selectAllChildren(menu, selected) {
|
||||||
|
if (menu.children && menu.children.length > 0) {
|
||||||
|
menu.children.forEach(child => {
|
||||||
|
const childId = getMenuId(child)
|
||||||
|
if (!selected.includes(childId)) {
|
||||||
|
selected.push(childId)
|
||||||
|
}
|
||||||
|
// 递归处理更深层级的子菜单
|
||||||
|
selectAllChildren(child, selected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归取消选中所有子菜单
|
||||||
|
function unselectAllChildren(menu, selected) {
|
||||||
|
if (menu.children && menu.children.length > 0) {
|
||||||
|
menu.children.forEach(child => {
|
||||||
|
const childId = getMenuId(child)
|
||||||
|
const childIndex = selected.indexOf(childId)
|
||||||
|
if (childIndex > -1) {
|
||||||
|
selected.splice(childIndex, 1)
|
||||||
|
}
|
||||||
|
// 递归处理更深层级的子菜单
|
||||||
|
unselectAllChildren(child, selected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 根据ID查找菜单
|
// 根据ID查找菜单
|
||||||
function findMenuById(menuId, menus) {
|
function findMenuById(menuId, menus) {
|
||||||
for (const menu of menus) {
|
for (const menu of menus) {
|
||||||
@@ -187,10 +205,8 @@
|
|||||||
const parentMenu = findParentMenu(menuId, props.treeData)
|
const parentMenu = findParentMenu(menuId, props.treeData)
|
||||||
if (parentMenu) {
|
if (parentMenu) {
|
||||||
const parentId = getMenuId(parentMenu)
|
const parentId = getMenuId(parentMenu)
|
||||||
// 检查父菜单的所有子菜单是否都未选中
|
// 检查父菜单的所有子菜单(包括深层级)是否都未选中
|
||||||
const allChildrenUnchecked = parentMenu.children.every(child => {
|
const allChildrenUnchecked = checkAllChildrenUnchecked(parentMenu, selected)
|
||||||
return !selected.includes(getMenuId(child))
|
|
||||||
})
|
|
||||||
|
|
||||||
if (allChildrenUnchecked) {
|
if (allChildrenUnchecked) {
|
||||||
const parentIndex = selected.indexOf(parentId)
|
const parentIndex = selected.indexOf(parentId)
|
||||||
@@ -203,6 +219,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查所有子菜单(包括深层级)是否都未选中
|
||||||
|
function checkAllChildrenUnchecked(menu, selected) {
|
||||||
|
if (menu.children && menu.children.length > 0) {
|
||||||
|
return menu.children.every(child => {
|
||||||
|
// 检查当前子菜单是否未选中
|
||||||
|
const childId = getMenuId(child)
|
||||||
|
if (selected.includes(childId)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// 递归检查子菜单的子菜单
|
||||||
|
return checkAllChildrenUnchecked(child, selected)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// 查找父菜单
|
// 查找父菜单
|
||||||
function findParentMenu(menuId, menus) {
|
function findParentMenu(menuId, menus) {
|
||||||
for (const menu of menus) {
|
for (const menu of menus) {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@
|
|||||||
<view class="form-section">
|
<view class="form-section">
|
||||||
<view class="section-title">数据权限</view>
|
<view class="section-title">数据权限</view>
|
||||||
<view class="data-scope-list">
|
<view class="data-scope-list">
|
||||||
<radio-group v-model="form.dataScope">
|
<radio-group @change="handleDataScopeChange">
|
||||||
<view
|
<view
|
||||||
v-for="scope in dataScopeOptions"
|
v-for="scope in dataScopeOptions"
|
||||||
:key="scope.value"
|
:key="scope.value"
|
||||||
@@ -192,6 +192,11 @@
|
|||||||
function goBack() {
|
function goBack() {
|
||||||
uni.navigateBack({ delta: 1 });
|
uni.navigateBack({ delta: 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理数据权限变更
|
||||||
|
function handleDataScopeChange(e) {
|
||||||
|
form.value.dataScope = e.detail.value;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user