function cloneObj(obj) { var str; var newObj = obj.constructor === Array ? [] : {}; if (typeof obj !== 'object') { return; } else if (JSON) { str = JSON.stringify(obj); //系列化对象 newObj = JSON.parse(str); //还原 } else { for (var i in obj) { newObj[i] = typeof obj[i] === 'object' ? cloneObj(obj[i]) : obj[i]; } } return newObj; } /** * 规则流 程中保存 大数据 */ const state = { constaintsItem: [], projectCode: '', cond: {}, addResult: {}, treeData: [], nodeList: [], rp: {}, graph: null, tagsArry: [] //首页页签 } const mutations = { SETCValue: (state, data) => { let itemList = state.constaintsItem; if (itemList.length > 0) { var index = itemList.findIndex(item => item.id == data.id) if (index > -1) { itemList[index] = cloneObj(data) } else { state.constaintsItem.push(data) } } else { state.constaintsItem.push(data) } }, DELCValue: (state, data) => { state.constaintsItem = data; }, setProjectCode: (state, data) => { state.projectCode = data; }, setCond: (state, data) => { state.cond = data }, setaddResult: (state, data) => { state.addResult = data }, settreeData: (state, data) => { state.treeData = data }, getnodeList: (state, data) => { state.nodeList = data }, getRp: (state, data) => { state.rp = data }, getGraph: (state, data) => { state.graph = data }, // 添加标签 setTagsArry: (state, data) => { state.tagsArry = data }, // 删除当前的tag delTagsArry: (state, data) => { state.tagsArry.map((item, index) => { if (item.path.indexOf(data) > -1) { state.tagsArry.splice(index, 1) } }) }, } export default { state, mutations }