Commit 385306d8 authored by 任建锋's avatar 任建锋

复制支持复制子级

parent f771a7e7
......@@ -36,6 +36,42 @@ function getDefaultOptions() {
return clonePureObj(defaultOptions);
}
function setUUIDForAllChildren(node){
if(node.children&&node.children.length>0){
for(let i=0 ;i<node.children.length;i++){
node.children[i]=copyBaseRoot(node.children[i])
setUUIDForAllChildren(node.children[i])
}
}
}
function copyBaseRoot(node){
let _node=JSON.parse(JSON.stringify(node));
let data
if(_node.children&&_node.children.length>0){
data={
name: _node.name,
type: _node.type,
properties: _node.properties,
events: _node.events,
uuid: generateUUID(),
children:_node.children
};
}else{
data={
name: _node.name,
type: _node.type,
properties: _node.properties,
events: _node.events,
uuid: generateUUID(),
};
}
return data
}
export const projectStore = {
state: {
id: '',
......@@ -282,25 +318,19 @@ export const projectStore = {
const index = parentChildren.indexOf(node);
parentChildren.splice(index, 1);
},
copyNode(state, { node, parentNode }) {
// const parentChildren = parentNode.children || parentNode;
// const index = parentChildren.indexOf(node);
// parentNode.children.push(node);
// parentChildren.push(parentChildren[index]);
const child = {
name: node.name,
type: node.type,
properties: node.properties,
events: node.events,
uuid: generateUUID(),
};
let _node1=node
let _node=copyBaseRoot(_node1);
setUUIDForAllChildren(_node)
if (parentNode) {
if (!parentNode.children) {
Vue.set(parentNode, 'children', []);
}
parentNode.children.push(child);
parentNode.children.push(_node);
} else {
state.data.views.push(child);
state.data.views.push(_node);
}
},
importAssets(state, assets) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment