Commit 4f3bd1f1f3983882782c4143c03bc17f162dec8b
1 parent
9c783619
remove editorConfig prop for element model for saving to db
Showing
7 changed files
with
27 additions
and
20 deletions
front-end/h5/src/components/core/editor/canvas/preview.js
front-end/h5/src/components/core/editor/edit-panel/props.js
| ... | ... | @@ -2,7 +2,7 @@ import { mapState, mapActions } from 'vuex' |
| 2 | 2 | |
| 3 | 3 | export default { |
| 4 | 4 | computed: { |
| 5 | - ...mapState('editor', ['editingElement']) | |
| 5 | + ...mapState('editor', ['editingElement', 'editingElementEditorConfig']) | |
| 6 | 6 | }, |
| 7 | 7 | methods: { |
| 8 | 8 | ...mapActions('editor', [ |
| ... | ... | @@ -12,14 +12,14 @@ export default { |
| 12 | 12 | * 将插件属性的 自定义增强编辑器注入 属性编辑面板中 |
| 13 | 13 | */ |
| 14 | 14 | mixinEnhancedPropsEditor (editingElement) { |
| 15 | - const { components } = editingElement.editorConfig | |
| 15 | + const { components } = this.editingElementEditorConfig | |
| 16 | 16 | for (const key in components) { |
| 17 | 17 | if (this.$options.components[key]) return |
| 18 | 18 | this.$options.components[key] = components[key] |
| 19 | 19 | } |
| 20 | 20 | }, |
| 21 | 21 | renderPropsEditorPanel (h, editingElement) { |
| 22 | - const propsConfig = editingElement.editorConfig.propsConfig | |
| 22 | + const propsConfig = this.editingElementEditorConfig.propsConfig | |
| 23 | 23 | return ( |
| 24 | 24 | <a-form |
| 25 | 25 | ref="form" | ... | ... |
front-end/h5/src/components/core/editor/index.js
| 1 | -import Vue from 'vue' | |
| 2 | 1 | import { mapState, mapActions } from 'vuex' |
| 3 | -// import Element from '../models/element' | |
| 4 | 2 | import undoRedoHistory from '../../../store/plugins/undo-redo/History' |
| 3 | +import { getEditorConfigForEditingElement } from '../../../utils/element' | |
| 5 | 4 | |
| 6 | 5 | import '../styles/index.scss' |
| 7 | 6 | |
| ... | ... | @@ -51,12 +50,6 @@ export default { |
| 51 | 50 | 'saveWork', |
| 52 | 51 | 'createWork' |
| 53 | 52 | ]), |
| 54 | - getEditorConfig (pluginName) { | |
| 55 | - // const pluginCtor = Vue.options[pluginName] | |
| 56 | - // const pluginCtor = this.$options.components[pluginName] | |
| 57 | - const PluginCtor = Vue.component(pluginName) | |
| 58 | - return new PluginCtor().$options.editorConfig | |
| 59 | - }, | |
| 60 | 53 | /** |
| 61 | 54 | * !#zh 点击插件,copy 其基础数据到组件树(中间画布) |
| 62 | 55 | * #!en click the plugin shortcut, create new Element with the plugin's meta data |
| ... | ... | @@ -64,9 +57,7 @@ export default { |
| 64 | 57 | */ |
| 65 | 58 | clone ({ name }) { |
| 66 | 59 | const zindex = this.elements.length + 1 |
| 67 | - // const defaultPropsValue = this.getPropsDefaultValue(name) | |
| 68 | - const editorConfig = this.getEditorConfig(name) | |
| 69 | - // this.elements.push(new Element({ name, zindex, editorConfig })) | |
| 60 | + const editorConfig = getEditorConfigForEditingElement(name) | |
| 70 | 61 | this.elementManager({ |
| 71 | 62 | type: 'add', |
| 72 | 63 | value: { name, zindex, editorConfig } | ... | ... |
front-end/h5/src/components/core/models/element.js
| ... | ... | @@ -15,7 +15,6 @@ class Element { |
| 15 | 15 | constructor (ele) { |
| 16 | 16 | this.name = ele.name |
| 17 | 17 | this.uuid = +new Date() |
| 18 | - this.editorConfig = ele.editorConfig || {} | |
| 19 | 18 | /** |
| 20 | 19 | * 之前版本代码:https://github.com/ly525/luban-h5/blob/a7875cbc73c0d18bc2459985ca3ce1d4dc44f141/front-end/h5/src/components/core/models/element.js#L21 |
| 21 | 20 | * 1.之前的版本为:this.pluginProps = {}, 改为下面的版本 |
| ... | ... | @@ -23,7 +22,7 @@ class Element { |
| 23 | 22 | * |
| 24 | 23 | * 2. 移除 this.init() 原因是:如果是 复制元素,则 init 会把 copy 的值重新覆盖为初始值,copy 无效 |
| 25 | 24 | */ |
| 26 | - this.pluginProps = ele.pluginProps || this.getDefaultPluginProps() | |
| 25 | + this.pluginProps = ele.pluginProps || this.getDefaultPluginProps(ele.editorConfig || {}) | |
| 27 | 26 | this.commonStyle = ele.commonStyle || this.getDefaultCommonStyle() |
| 28 | 27 | this.events = [] |
| 29 | 28 | } |
| ... | ... | @@ -32,9 +31,9 @@ class Element { |
| 32 | 31 | return { ...defaultProps } |
| 33 | 32 | } |
| 34 | 33 | |
| 35 | - getDefaultPluginProps () { | |
| 34 | + getDefaultPluginProps (editorConfig) { | |
| 36 | 35 | // init prop of plugin |
| 37 | - const propConf = this.editorConfig.propsConfig | |
| 36 | + const propConf = editorConfig.propsConfig | |
| 38 | 37 | const pluginProps = {} |
| 39 | 38 | Object.keys(propConf).forEach(key => { |
| 40 | 39 | // #6 |
| ... | ... | @@ -75,7 +74,6 @@ class Element { |
| 75 | 74 | clone () { |
| 76 | 75 | return new Element({ |
| 77 | 76 | name: this.name, |
| 78 | - editorConfig: this.editorConfig, | |
| 79 | 77 | pluginProps: JSON.parse(JSON.stringify(this.pluginProps)), |
| 80 | 78 | commonStyle: { |
| 81 | 79 | ...this.commonStyle, | ... | ... |
front-end/h5/src/store/modules/editor.js
| ... | ... | @@ -7,7 +7,8 @@ import { actions as workActions, mutations as workMutations } from './work' |
| 7 | 7 | const state = { |
| 8 | 8 | work: new Work(), |
| 9 | 9 | editingPage: { elements: [] }, |
| 10 | - editingElement: null | |
| 10 | + editingElement: null, | |
| 11 | + editingElementEditorConfig: null | |
| 11 | 12 | } |
| 12 | 13 | |
| 13 | 14 | // getters | ... | ... |
front-end/h5/src/store/modules/element.js
| 1 | 1 | import Element from '../../components/core/models/element' |
| 2 | +import { getEditorConfigForEditingElement } from '../../utils/element' | |
| 2 | 3 | |
| 3 | 4 | // actions |
| 4 | 5 | export const actions = { |
| 5 | 6 | setEditingElement ({ commit }, payload) { |
| 6 | 7 | commit('setEditingElement', payload) |
| 8 | + | |
| 9 | + const vm = (payload && payload.name) ? getEditorConfigForEditingElement(payload.name) : null | |
| 10 | + commit('setEditingElementEditorConfig', vm) | |
| 7 | 11 | }, |
| 8 | 12 | setElementPosition ({ commit }, payload) { |
| 9 | 13 | commit('setElementCommonStyle', payload) |
| ... | ... | @@ -24,6 +28,9 @@ export const mutations = { |
| 24 | 28 | setEditingElement (state, payload) { |
| 25 | 29 | state.editingElement = payload |
| 26 | 30 | }, |
| 31 | + setEditingElementEditorConfig (state, payload) { | |
| 32 | + state.editingElementEditorConfig = payload | |
| 33 | + }, | |
| 27 | 34 | setElementCommonStyle (state, payload) { |
| 28 | 35 | state.editingElement.commonStyle = { |
| 29 | 36 | ...state.editingElement.commonStyle, | ... | ... |
front-end/h5/src/utils/element.js
0 → 100644