57 lines
1.1 KiB
JavaScript
57 lines
1.1 KiB
JavaScript
|
|
|
|
const getDefaultState = () => {
|
|
return {
|
|
// type = node ? relation
|
|
type: 'node',
|
|
data: {}
|
|
}
|
|
}
|
|
|
|
const state = getDefaultState()
|
|
|
|
const mutations = {
|
|
RESET_KG: (state) => {
|
|
state.type = 'node'
|
|
state.data = {}
|
|
// state = getDefaultState()
|
|
// console.log('mutation', state)
|
|
},
|
|
SET_KG: (state, obj) => {
|
|
state.type = obj.type
|
|
state.data = obj.item
|
|
},
|
|
SET_VALUE: (state, obj) => {
|
|
for(let i=0; i<state.data.properties.length; i++) {
|
|
let prop = state.data.properties[i]
|
|
if (prop.key == obj.key) {
|
|
prop.value = obj.value
|
|
break
|
|
}
|
|
}
|
|
},
|
|
DELETE_VALUE: (state, key) => {
|
|
let properties = state.data.properties
|
|
let index = -1
|
|
for(let i=0; i<properties.length; i++) {
|
|
if(properties[i].key == key) {
|
|
index = i
|
|
break
|
|
}
|
|
}
|
|
if(index != -1) {
|
|
properties.splice(index, 1)
|
|
}
|
|
}
|
|
}
|
|
|
|
const actions = {
|
|
|
|
}
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
mutations,
|
|
actions
|
|
} |