Commit 16da314ea50dff51ee6a6d7a8f3f72c703dfdec1
1 parent
84abd56c
api: create and update work with strapi
Showing
3 changed files
with
27 additions
and
12 deletions
front-end/h5/src/components/core/editor/index.js
| @@ -48,7 +48,8 @@ export default { | @@ -48,7 +48,8 @@ export default { | ||
| 48 | 'elementManager', | 48 | 'elementManager', |
| 49 | 'pageManager', | 49 | 'pageManager', |
| 50 | 'saveWork', | 50 | 'saveWork', |
| 51 | - 'createWork' | 51 | + 'createWork', |
| 52 | + 'fetchWork' | ||
| 52 | ]), | 53 | ]), |
| 53 | /** | 54 | /** |
| 54 | * !#zh 点击插件,copy 其基础数据到组件树(中间画布) | 55 | * !#zh 点击插件,copy 其基础数据到组件树(中间画布) |
| @@ -191,6 +192,7 @@ export default { | @@ -191,6 +192,7 @@ export default { | ||
| 191 | let workId = this.$route.query.workId | 192 | let workId = this.$route.query.workId |
| 192 | if (workId) { | 193 | if (workId) { |
| 193 | // this.$store.dispatch('getWorkById', workId) | 194 | // this.$store.dispatch('getWorkById', workId) |
| 195 | + this.fetchWork(workId) | ||
| 194 | } else { | 196 | } else { |
| 195 | this.createWork() | 197 | this.createWork() |
| 196 | } | 198 | } |
front-end/h5/src/store/modules/editor.js
| 1 | // initial state | 1 | // initial state |
| 2 | +import strapi from '../../utils/strapi' | ||
| 2 | import Work from '../../components/core/models/work' | 3 | import Work from '../../components/core/models/work' |
| 3 | import { actions as pageActions, mutations as pageMutations } from './page' | 4 | import { actions as pageActions, mutations as pageMutations } from './page' |
| 4 | import { actions as elementActions, mutations as elementMutations } from './element' | 5 | import { actions as elementActions, mutations as elementMutations } from './element' |
| @@ -18,12 +19,7 @@ const getters = {} | @@ -18,12 +19,7 @@ const getters = {} | ||
| 18 | const actions = { | 19 | const actions = { |
| 19 | ...elementActions, | 20 | ...elementActions, |
| 20 | ...pageActions, | 21 | ...pageActions, |
| 21 | - ...workActions, | ||
| 22 | - createWork ({ commit }, payload) { | ||
| 23 | - commit('createWork') | ||
| 24 | - commit('pageManager', { type: 'add' }) | ||
| 25 | - commit('setEditingPage') | ||
| 26 | - } | 22 | + ...workActions |
| 27 | } | 23 | } |
| 28 | 24 | ||
| 29 | // mutations | 25 | // mutations |
front-end/h5/src/store/modules/work.js
| 1 | -import Work from '../../components/core/models/work' | 1 | +// import Work from '../../components/core/models/work' |
| 2 | import strapi from '../../utils/strapi' | 2 | import strapi from '../../utils/strapi' |
| 3 | 3 | ||
| 4 | export const actions = { | 4 | export const actions = { |
| @@ -8,17 +8,34 @@ export const actions = { | @@ -8,17 +8,34 @@ export const actions = { | ||
| 8 | deployWork ({ commit }, payload = {}) { | 8 | deployWork ({ commit }, payload = {}) { |
| 9 | commit('previewWork', payload) | 9 | commit('previewWork', payload) |
| 10 | }, | 10 | }, |
| 11 | + createWork ({ commit }, payload) { | ||
| 12 | + strapi.createEntry('works').then(entry => { | ||
| 13 | + window.location = `${window.location.origin}/#/?workId=${entry.id}` | ||
| 14 | + }) | ||
| 15 | + // commit('createWork') | ||
| 16 | + // commit('pageManager', { type: 'add' }) | ||
| 17 | + // commit('setEditingPage') | ||
| 18 | + }, | ||
| 11 | saveWork ({ commit, state }, payload = {}) { | 19 | saveWork ({ commit, state }, payload = {}) { |
| 12 | - // save work with strapi | ||
| 13 | - strapi.createEntry('works', state.work) | 20 | + // update work with strapi |
| 21 | + strapi.updateEntry('works', state.work.id, state.work) | ||
| 22 | + }, | ||
| 23 | + fetchWork ({ commit, state }, workId) { | ||
| 24 | + strapi.getEntry('works', workId).then(entry => { | ||
| 25 | + commit('setWork', entry) | ||
| 26 | + commit('setEditingPage') | ||
| 27 | + }) | ||
| 14 | } | 28 | } |
| 15 | } | 29 | } |
| 16 | 30 | ||
| 17 | // mutations | 31 | // mutations |
| 18 | export const mutations = { | 32 | export const mutations = { |
| 19 | - createWork (state) { | ||
| 20 | - state.work = new Work() | 33 | + setWork (state, payload) { |
| 34 | + state.work = payload | ||
| 21 | }, | 35 | }, |
| 36 | + // createWork (state) { | ||
| 37 | + // state.work = new Work() | ||
| 38 | + // }, | ||
| 22 | previewWork (state, { type, value }) {}, | 39 | previewWork (state, { type, value }) {}, |
| 23 | deployWork (state, { type, value }) {} | 40 | deployWork (state, { type, value }) {} |
| 24 | } | 41 | } |