diff --git a/src/components/Atom/index.jsx b/src/components/Atom/index.jsx new file mode 100644 index 0000000..52dd7be --- /dev/null +++ b/src/components/Atom/index.jsx @@ -0,0 +1,50 @@ +// Nie 2023/2/8 元素添加迭代递归渲染 + +import {useEffect, useState} from "react"; +import css from './index.module.scss'; +import {defaultStore} from "@/store/index.js"; + +export default function Atom(props) { + const AtomList = props.AtomList; + const [boxState, setBoxState] = useState(new Array(AtomList.length).fill(false)); + // 打开关闭标签 + function handleChangeBoxState(index){ + const temporaryState = new Array(boxState.length).fill(false); + if(!boxState[index]){ + temporaryState[index] = true; + } + setBoxState(temporaryState) + } + // 添加元素 + function handleAddElement(item){ + defaultStore.setNewElementIdentify(item.identify) + } + useEffect(() => { + if(props.state){ + setBoxState(new Array(boxState.length).fill(false)) + } + }, [props.state]) + return AtomList.map((item, index) => { + if (item.children && Array.isArray(item.children)) { + return