From 1070215d7013beb68b4b3f79762d6e17aa316c69 Mon Sep 17 00:00:00 2001 From: ly525 Date: Wed, 10 Jun 2020 23:42:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20shortcutProps=20to=20support=20sh?= =?UTF-8?q?ortcut=20themes;=20!#zh:=20=E5=A2=9E=E5=8A=A0=20shortcutProps?= =?UTF-8?q?=20=E4=BB=A5=E6=94=AF=E6=8C=81=E5=BF=AB=E6=8D=B7=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E5=AE=9A=E5=88=B6=E5=8C=96/=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front-end/h5/src/components/core/editor/index.js | 9 +++++++-- front-end/h5/src/components/core/models/element.js | 12 +++++++++--- front-end/h5/src/store/modules/element.js | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/front-end/h5/src/components/core/editor/index.js b/front-end/h5/src/components/core/editor/index.js index addca2db..5f7a48df 100644 --- a/front-end/h5/src/components/core/editor/index.js +++ b/front-end/h5/src/components/core/editor/index.js @@ -148,11 +148,16 @@ export default { * !#zh 点击插件,copy 其基础数据到组件树(中间画布) * #!en click the plugin shortcut, create new Element with the plugin's meta data * pluginInfo {Object}: 插件列表中的基础数据, {name}=pluginInfo + * + * shortcutItem: PluginListItem = { + name: String, + shortcutProps: {} + } */ - clone ({ name }) { + clone (shortcutItem) { this.elementManager({ type: 'add', - value: { name } + value: shortcutItem }) }, /** diff --git a/front-end/h5/src/components/core/models/element.js b/front-end/h5/src/components/core/models/element.js index bbd445d1..1bc2df1a 100644 --- a/front-end/h5/src/components/core/models/element.js +++ b/front-end/h5/src/components/core/models/element.js @@ -53,12 +53,12 @@ class Element { if (typeof ele.pluginProps === 'object') { return cloneObj({ ...ele.pluginProps, uuid: this.uuid }) } - return this.getDefaultPluginProps(ele.props || {}) + return this.getDefaultPluginProps(ele.props, ele.shortcutProps) } // init prop of plugin - getDefaultPluginProps (props) { - const pluginProps = { + getDefaultPluginProps (props = {}, shortcutProps) { + let pluginProps = { uuid: this.uuid } Object.keys(props).forEach(key => { @@ -70,6 +70,12 @@ class Element { const defaultValue = props[key].default pluginProps[key] = typeof defaultValue === 'function' ? defaultValue() : defaultValue }) + + pluginProps = { + ...pluginProps, + ...shortcutProps + } + return pluginProps } diff --git a/front-end/h5/src/store/modules/element.js b/front-end/h5/src/store/modules/element.js index 5457ff9e..89bcbaa4 100644 --- a/front-end/h5/src/store/modules/element.js +++ b/front-end/h5/src/store/modules/element.js @@ -40,6 +40,7 @@ export const mutations = { switch (type) { case 'add': const vm = getVM(value.name) + vm.$options.shortcutProps = value.shortcutProps const element = new Element(vm.$options) elements.push(element) break