-
Notifications
You must be signed in to change notification settings - Fork 110
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
Showing
36 changed files
with
898 additions
and
585 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
114 changes: 101 additions & 13 deletions
114
src/designer/float-configs/layer-list/LayerBuilder.tsx
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,28 +1,116 @@ | ||
import {MovableItemType} from "../../operate-provider/movable/types"; | ||
import {ReactElement} from "react"; | ||
import LayerItem from "./item/LayerItem"; | ||
import LayerGroupItem from "./group/LayerGroupItem"; | ||
import eventOperateStore from "../../operate-provider/EventOperateStore"; | ||
import {cloneDeep} from "lodash"; | ||
import layerListStore from "./LayerListStore"; | ||
import ComponentContainer from "../../../framework/core/ComponentContainer"; | ||
|
||
export default class LayerBuilder { | ||
/** | ||
* 原始图层信息,取自于设计器store | ||
*/ | ||
private sourceLayer: MovableItemType | null = null; | ||
export enum RenderOrder { | ||
ASC, | ||
DESC, | ||
} | ||
|
||
/** | ||
* 将原始图层信息解析为树结构 | ||
*/ | ||
private layerTree: any | null = null; | ||
class LayerBuilder { | ||
|
||
/** | ||
* 解析函数 | ||
*/ | ||
public parser: (layer: MovableItemType) => {}; | ||
public parser = (layerMap: Record<string, MovableItemType>, order: RenderOrder = RenderOrder.DESC): MovableItemType[] => { | ||
layerMap = cloneDeep(layerMap); | ||
let sourceLayerArr; | ||
if (order === RenderOrder.DESC) | ||
sourceLayerArr = Object.values(layerMap).sort((a, b) => b.order! - a.order!); | ||
else | ||
sourceLayerArr = Object.values(layerMap).sort((a, b) => a.order! - b.order!); | ||
// 构建树结构 | ||
const resData: MovableItemType[] = []; | ||
for (const layerItem of sourceLayerArr) { | ||
if (!layerItem?.pid) { | ||
// 根节点 | ||
resData.push(layerItem); | ||
} else { | ||
// 非根节点,将其加入父节点的 children 中 | ||
const parent = layerMap[layerItem.pid]; | ||
if (parent) { | ||
parent.children = parent.children || []; | ||
parent.children.push(layerItem); | ||
} | ||
} | ||
} | ||
return resData; | ||
}; | ||
|
||
|
||
/** | ||
* 构建图层组件 | ||
*/ | ||
public build = (layer: MovableItemType) => { | ||
|
||
public buildLayerList = (layerMap: Record<string, MovableItemType>): ReactElement[] => { | ||
const res: ReactElement[] = []; | ||
this.parser(layerMap, RenderOrder.DESC).forEach((item: MovableItemType) => { | ||
res.push(this.buildLayer(item)); | ||
}); | ||
return res; | ||
} | ||
|
||
|
||
private buildLayer = (layer: MovableItemType): ReactElement => { | ||
const {type, children} = layer; | ||
const {targetIds} = eventOperateStore; | ||
const {layerInstances} = layerListStore; | ||
let _props = { | ||
key: layer.id, | ||
name: layer.name, | ||
lock: layer.lock, | ||
hide: layer.hide, | ||
compId: layer.id, | ||
type: layer.type, | ||
selected: targetIds.includes(layer.id!) | ||
} | ||
if (type === 'group') { | ||
//先生成子元素再包裹groupItem | ||
const childDomArr: ReactElement[] = []; | ||
children?.forEach((item: MovableItemType) => { | ||
childDomArr.push(this.buildLayer(item)); | ||
}); | ||
return <LayerGroupItem {..._props} ref={ref => layerInstances[layer.id!] = ref!}> | ||
{childDomArr} | ||
</LayerGroupItem>; | ||
} else { | ||
//直接生成layerItem | ||
return <LayerItem {..._props} ref={ref => layerInstances[layer.id!] = ref!}/>; | ||
} | ||
} | ||
|
||
/** | ||
* 构建设计器主画布组件 | ||
* @param layerMap | ||
*/ | ||
public buildCanvasComponents = (layerMap: Record<string, MovableItemType>): ReactElement[] => { | ||
const res: ReactElement[] = []; | ||
this.parser(layerMap, RenderOrder.ASC).forEach((item: MovableItemType) => { | ||
res.push(this.buildComponents(item)); | ||
}); | ||
return res; | ||
} | ||
|
||
private buildComponents = (layer: MovableItemType): ReactElement => { | ||
const {type, children} = layer; | ||
if (type === 'group') { | ||
//先生成子元素再包裹groupItem | ||
const childDomArr: ReactElement[] = []; | ||
children?.forEach((item: MovableItemType) => { | ||
childDomArr.push(this.buildComponents(item)); | ||
}); | ||
return <div key={layer.id} className={'component-group'} | ||
style={{position: 'absolute'}}>{childDomArr}</div>; | ||
} else { | ||
return <ComponentContainer layout={layer} key={layer.id}/>; | ||
} | ||
} | ||
|
||
} | ||
|
||
} | ||
const layerBuilder = new LayerBuilder(); | ||
export default layerBuilder; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.