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