MCPcopy Create free account
hub / github.com/MankaiHuang/screen-visualization / TopDrawer

Function TopDrawer

src/components/Workspace/TopDrawer/index.tsx:28–204  ·  view source on GitHub ↗
({ effectFrame })

Source from the content-addressed store, hash-verified

26}
27
28const TopDrawer: React.FC<IProps> = ({ effectFrame }) => {
29 const [privateList, setPrivateList] = useState<ITemplateList>([])
30 const [isVisibleAi, setIsVisibleAi] = useState<Boolean>(false)
31 const [isVisibleMap, setIsVisibleMap] = useState<Boolean>(false)
32 const [clickComponent, setClickComponent] = useState<IClickComponent>({ type: '', secondType: '', typeName: '' }) // 点击选择的组件类型
33 useEffect(() => {
34 async function fetchData() {
35
36 setPrivateList([])
37
38 }
39 fetchData();
40 }, [])
41
42 async function insertElement(type: string, key: string, secondType: string, optionData: ITemplateList, typeName: string = '') {
43 // type 是具体类型 key是组件分类名
44 if (type === 'smartCity') {
45 setIsVisibleMap(true)
46 setClickComponent({
47 type,
48 secondType,
49 typeName,
50 })
51 }
52 else {
53 let option: ITemplateList;
54 option = elementList[type]
55 afterSelect(option, key, type, secondType, typeName)
56 }
57
58 }
59 function afterSelect(option: ITemplateList, componentsType: string, type: string, secondType: string, typeName: string) {
60 // 选择组件之后的处理
61 const baseConfig = getBaseConfig();
62 let selectProperty: ISelectProperty = { width: 0, height: 0, option: [] };
63 if (componentsType === 'private') {
64 const originBasic: ITemplateList['extend'] = option.extend;
65 // originBasic = option.extend
66 originBasic.preview = option.preview // 图层需要preview作为组件图片显示
67 const tempOption = { templateList: [], baseConfig: option.extend, data: option.extend.data }
68 option.componentList.map(item => {
69 // 重新生成id
70 // item.extend.property.elementId = guid()
71 tempOption.templateList.push(item.extend)
72 })
73 selectProperty.option = tempOption;
74 Object.assign(selectProperty, ...baseConfig);
75 selectProperty = { ...selectProperty, ...originBasic }
76 } else {
77 selectProperty.option = option;
78 Object.assign(selectProperty, ...baseConfig);
79 selectProperty.width = fixWidth(type); // 初始化宽高 解决首次新增拖拽超出限制的问题
80 selectProperty.height = fixHeight(type);
81 }
82
83 effectFrame({
84 command: 'append',
85 type,

Callers

nothing calls this directly

Calls 2

fetchDataFunction · 0.70
renderMenuFunction · 0.70

Tested by

no test coverage detected