-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
780e6f3
commit 02c4a52
Showing
13 changed files
with
206 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
class GroupUtil { | ||
getGroupVisible(catalogs, item) { | ||
const rootGroup = this.getRootGroup(catalogs, item); | ||
if (!rootGroup) return true; | ||
export function getGroupVisible(catalogs, item) { | ||
const rootGroup = getRootGroup(catalogs, item); | ||
if (!rootGroup) return true; | ||
|
||
const { visible, children } = rootGroup; | ||
if (!visible) return false; | ||
const { | ||
visible, | ||
children | ||
} = rootGroup; | ||
if (!visible) return false; | ||
|
||
return this.getGroupVisible(children, item); | ||
} | ||
return getGroupVisible(children, item); | ||
} | ||
|
||
getRootGroup(catalogs, item) { | ||
const isRootItem = catalogs.find(c => (c.id === item.id)); | ||
if (isRootItem) return; // 说明是顶层,不存在父图层组 | ||
function getRootGroup(catalogs, item) { | ||
const isRootItem = catalogs.find(c => (c.id === item.id)); | ||
if (isRootItem) return; // 说明是顶层,不存在父图层组 | ||
|
||
// 图层组中的图层/图层组 | ||
const groups = catalogs.filter(catalog => catalog.type === 'group'); | ||
return groups.find((g) => this.isChild(g, item)); | ||
} | ||
// 图层组中的图层/图层组 | ||
const groups = catalogs.filter(catalog => catalog.type === 'group'); | ||
return groups.find((g) => isChild(g, item)); | ||
} | ||
|
||
// 是否是当前图层组的 子图层/子图层组 | ||
isChild(group, child) { | ||
const { children } = group; | ||
const target = children.find((c) => c.id === child.id); | ||
if (target) return true; | ||
// 是否是当前图层组的 子图层/子图层组 | ||
function isChild(group, child) { | ||
const { | ||
children | ||
} = group; | ||
const target = children.find((c) => c.id === child.id); | ||
if (target) return true; | ||
|
||
const childrenGroup = children.filter(catalog => catalog.type === 'group'); | ||
return !!childrenGroup.find((c) => this.isChild(c, child)); | ||
} | ||
const childrenGroup = children.filter(catalog => catalog.type === 'group'); | ||
return !!childrenGroup.find((c) => isChild(c, child)); | ||
} | ||
|
||
getGroupChildrenLayers(layerGroup) { | ||
const targetItems = []; | ||
for (const item of layerGroup) { | ||
// 图层组和图层都只选择可见的 | ||
if (item.visible === false) continue; | ||
|
||
if (item.type !== 'group') { | ||
targetItems.push(item); | ||
continue; | ||
} | ||
// 图层组 | ||
const group = item; | ||
targetItems.push(...this.getGroupChildrenLayers(group.children)); | ||
export function getGroupChildrenLayers(layerGroup) { | ||
const targetItems = []; | ||
for (const item of layerGroup) { | ||
// 图层组和图层都只选择可见的 | ||
if (item.visible === false) continue; | ||
|
||
if (item.type !== 'group') { | ||
targetItems.push(item); | ||
continue; | ||
} | ||
return targetItems; | ||
// 图层组 | ||
const group = item; | ||
targetItems.push(...getGroupChildrenLayers(group.children)); | ||
} | ||
} | ||
export default GroupUtil; | ||
return targetItems; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.