page.js
1.74 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* @Author: ly525
* @Date: 2019-12-08 17:05:09
* @LastEditors: ly525
* @LastEditTime: 2019-12-15 15:41:56
* @FilePath: /luban-h5/front-end/h5/src/store/modules/page.js
* @Github: https://github.com/ly525/luban-h5
* @Description: page module
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
*/
import { message } from 'ant-design-vue'
import Page from '../../components/core/models/page'
// actions
export const actions = {
setEditingPage ({ commit }, pageIndex = 0) {
commit('setEditingPage', pageIndex)
},
pageManager ({ commit }, payload) {
commit('pageManager', payload)
}
}
// mutations
export const mutations = {
setEditingPage (state, pageIndex = 0) {
state.editingPage = state.work.pages[pageIndex]
},
pageManager (state, { type, value }) {
switch (type) {
case 'editTitle':
const { pageIndexForEditingTitle, newTitle } = value
state.work.pages[pageIndexForEditingTitle].title = newTitle
break
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) {
// #!zh: 作品中至少需要保留一个页面
// #!en: At least one page needs to be kept in the work
message.info(`作品中至少需要保留一个页面`)
return
}
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:
}
}
}