Commit b751aa6de14a4e134f32fdb9ea91b551d723d2a9

Authored by ly525
1 parent 53c0bded

add Page, Work model and vuex module

front-end/h5/src/components/core/models/page.js 0 → 100644
  1 +class Page {
  2 + constructor (page = {}) {
  3 + this.elements = page.elements || []
  4 + }
  5 +}
  6 +
  7 +export default Page
... ...
front-end/h5/src/store/modules/page.js 0 → 100644
  1 +// initial state
  2 +import Page from '../../components/core/models/page'
  3 +
  4 +const state = {
  5 + editingPage: { pages: [] },
  6 + pagesOfCurrentWork: []
  7 +}
  8 +
  9 +// getters
  10 +const getters = {
  11 +
  12 +}
  13 +
  14 +// actions
  15 +const actions = {
  16 + setEditing ({ commit }, payload) {
  17 + commit('setEditing', payload)
  18 + },
  19 + manager ({ commit }, payload) {
  20 + commit('manager', payload)
  21 + }
  22 +}
  23 +
  24 +// mutations
  25 +const mutations = {
  26 + setEditing (state, payload) {
  27 + state.editing = payload
  28 + },
  29 + manager (state, { type, value }) {
  30 + switch (type) {
  31 + case 'add':
  32 + const page = new Page(value)
  33 + state.pagesOfCurrentWork.push(page)
  34 + break
  35 + case 'copy':
  36 + state.pagesOfCurrentWork.push(state.editing.clone())
  37 + break
  38 + case 'delete':
  39 + const { pagesOfCurrentWork, editing } = state
  40 + let index = pagesOfCurrentWork.findIndex(e => e.uuid === editing.uuid)
  41 + if (index !== -1) {
  42 + let newPages = pagesOfCurrentWork.slice()
  43 + newPages.splice(index, 1)
  44 + state.pagesOfCurrentWork = newPages
  45 + }
  46 + break
  47 + default:
  48 + }
  49 + }
  50 +}
  51 +
  52 +export default {
  53 + namespaced: true,
  54 + state,
  55 + getters,
  56 + actions,
  57 + mutations
  58 +}
... ...
front-end/h5/src/store/modules/work.js 0 → 100644
  1 +class Work {
  2 + constructor (work = {}) {
  3 + this.title = work.title || '标题'
  4 + this.description = work.description || '描述'
  5 + this.pages = work.pages || []
  6 + this.type = work.type || 'h5'
  7 + this.work = work
  8 +
  9 + this.id = this.id
  10 + this.coverImageUrl = ''
  11 + this.projectId = 1
  12 + this.isPublish = false
  13 + this.createTime = +new Date()
  14 + this.updateTime = +new Date()
  15 + }
  16 +}
  17 +
  18 +export default Work
... ...