page.js
1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Page from '../../components/core/models/page'
// actions
export const actions = {
setEditingPage ({ commit }, payload) {
commit('setEditingPage', payload)
},
pageManager ({ commit }, payload) {
commit('pageManager', payload)
}
}
// mutations
export const mutations = {
setEditingPage (state, payload) {
payload = payload || state.work.pages[0]
state.editingPage = payload
},
pageManager (state, { type, value }) {
switch (type) {
case 'add':
const page = new Page(value)
state.work.pages.push(page)
break
case 'copy':
state.work.pages.push(state.editingPage.clone())
break
case 'delete':
if (state.work.pages.length === 1) return // #!zh: 作品中至少需要保留一个页面,TODO 需要在页面中提示用户此信息
const { work, editingPage } = state
let index = work.pages.findIndex(page => page.uuid === editingPage.uuid)
if (index !== -1) {
let newPages = work.pages.slice()
newPages.splice(index, 1)
state.work.pages = newPages
}
break
default:
}
}
}