8000 add remove item · supercoderhawk/emr-processor@374b538 · GitHub
[go: up one dir, main page]

Skip to content

Commit 374b538

Browse files
add remove item
1 parent 01ec02a commit 374b538

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

app/src/renderer/store/modules/entity.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
import * as types from '../mutation-types'
22
import {LIST} from '../../utils/constant'
3-
import {isRangeValid} from '../../utils/utils'
43

54
const state = {
65
items: LIST.INIT
76
}
87

98
const mutations = {
10-
[types.ADD_ITEM] (state, item, index) {
11-
state.items.splice(index, 0, item)
9+
[types.ADD_ITEM] (state, item) {
10+
state.items.splice(item.id, 0, item)
11+
},
12+
[types.REMOVE_ITEM] (state, item) {
13+
state.items.splice(item.id, 1)
14+
},
15+
[types.RESORT_ITEM] (state) {
16+
let items = state.items
17+
for (let i = 0; i < items.length; i++) {
18+
if (items[i].id !== i) {
19+
items[i].id = i
20+
}
21+
}
1222
}
1323
}
1424

1525
const actions = {
1626
addItem: ({ commit, state }, item) => {
17-
let items = state.items
18-
if (isRangeValid(item.start, item.end, items)) {
19-
let itemCount = items.length
20-
let insertIndex = itemCount > 0 ? items.filter(curItem => { return curItem.end <= item.start }).length : 0
21-
commit(types.ADD_ITEM, item, insertIndex)
22-
}
27+
commit(types.ADD_ITEM, item)
28+
commit(types.RESORT_ITEM)
29+
},
30+
removeItem: ({commit, state}, item) => {
31+
commit(types.REMOVE_ITEM, item)
32+
commit(types.RESORT_ITEM)
2333
}
2434
}
2535

0 commit comments

Comments
 (0)
0