Commit 5f78c91ac2277d31ec688ac5fb8f962b10499c5e

Authored by ly525
2 parents bde7fe0e a59dbd3e

Merge branch 'master' into box-model

front-end/h5/src/components/core/editor/canvas/edit.js
@@ -193,6 +193,7 @@ export default { @@ -193,6 +193,7 @@ export default {
193 props: element.getProps() 193 props: element.getProps()
194 }) 194 })
195 } 195 }
  196 + const isEditingElement = this.editingElement && this.editingElement.uuid === element.uuid
196 const data = { 197 const data = {
197 style: { 198 style: {
198 width: '100%', 199 width: '100%',
@@ -203,7 +204,8 @@ export default { @@ -203,7 +204,8 @@ export default {
203 class: 'element-on-edit-canvas', 204 class: 'element-on-edit-canvas',
204 props: { 205 props: {
205 ...element.getProps(), // #6 #3, 206 ...element.getProps(), // #6 #3,
206 - editorMode: 'edit' 207 + editorMode: 'edit',
  208 + isEditingElement
207 }, 209 },
208 // nativeOn: { 210 // nativeOn: {
209 // contextmenu: e => { 211 // contextmenu: e => {
front-end/h5/src/components/core/editor/left-panel/shortcuts-panel/index.js
@@ -26,15 +26,15 @@ export default { @@ -26,15 +26,15 @@ export default {
26 * #!en click the plugin shortcut, create new Element with the plugin's meta data 26 * #!en click the plugin shortcut, create new Element with the plugin's meta data
27 * pluginInfo {Object}: 插件列表中的基础数据, {name}=pluginInfo 27 * pluginInfo {Object}: 插件列表中的基础数据, {name}=pluginInfo
28 * 28 *
29 - * shortcutItem: PluginListItem = { 29 + * elementShortcutConfig: PluginListItem = {
30 name: String, 30 name: String,
31 shortcutProps: {} 31 shortcutProps: {}
32 } 32 }
33 */ 33 */
34 - clone (shortcutItem) { 34 + clone (elementShortcutConfig) {
35 this.elementManager({ 35 this.elementManager({
36 type: 'add', 36 type: 'add',
37 - value: shortcutItem 37 + value: elementShortcutConfig
38 }) 38 })
39 } 39 }
40 /** 40 /**
front-end/h5/src/components/core/models/element.js
1 -import { parsePx } from '@/utils/element.js' 1 +import { parsePx, guid } from '@/utils/element.js'
2 2
3 // #! 编辑状态,不可以点击的按钮,因为点击按钮会触发一些默认行为,比如表单提交等 3 // #! 编辑状态,不可以点击的按钮,因为点击按钮会触发一些默认行为,比如表单提交等
4 const disabledPluginsForEditMode = ['lbp-form-input', 'lbp-form-button', 'lbp-video'] 4 const disabledPluginsForEditMode = ['lbp-form-input', 'lbp-form-button', 'lbp-video']
@@ -81,7 +81,7 @@ const defaultStyle = { @@ -81,7 +81,7 @@ const defaultStyle = {
81 class Element { 81 class Element {
82 constructor (ele) { 82 constructor (ele) {
83 this.name = ele.name 83 this.name = ele.name
84 - this.uuid = ele.uuid || +new Date() 84 + this.uuid = ele.uuid || guid()
85 /** 85 /**
86 * #!zh: 86 * #!zh:
87 * 之前版本代码:https://github.com/ly525/luban-h5/blob/a7875cbc73c0d18bc2459985ca3ce1d4dc44f141/front-end/h5/src/components/core/models/element.js#L21 87 * 之前版本代码:https://github.com/ly525/luban-h5/blob/a7875cbc73c0d18bc2459985ca3ce1d4dc44f141/front-end/h5/src/components/core/models/element.js#L21
front-end/h5/src/components/core/plugins/lbp-text.js
@@ -22,7 +22,7 @@ export default { @@ -22,7 +22,7 @@ export default {
22 clickOutside: vClickOutside.directive 22 clickOutside: vClickOutside.directive
23 }, 23 },
24 render (h) { 24 render (h) {
25 - const canEdit = this.canEdit && this.editorMode === 'edit' 25 + const canEdit = this.canEdit && this.editorMode === 'edit' && this.isEditingElement
26 const style = { 26 const style = {
27 position: 'relative', 27 position: 'relative',
28 color: `${this.color} !important`, 28 color: `${this.color} !important`,
@@ -109,6 +109,11 @@ export default { @@ -109,6 +109,11 @@ export default {
109 defaultValue: 'preview', // 可选值: preview/edit 109 defaultValue: 'preview', // 可选值: preview/edit
110 label: '模式', 110 label: '模式',
111 visible: false 111 visible: false
  112 + }),
  113 + isEditingElement: PropTypes.boolean({
  114 + defaultValue: false, // 可选值: preview/edit
  115 + label: '是否当前元素',
  116 + visible: false
112 }) 117 })
113 }, 118 },
114 editorConfig: { 119 editorConfig: {
front-end/h5/src/components/core/store/modules/element.js
@@ -32,7 +32,18 @@ export const mutations = { @@ -32,7 +32,18 @@ export const mutations = {
32 ...payload 32 ...payload
33 } 33 }
34 }, 34 },
  35 + /**
  36 + * 元素管理:增/删/复制/上移/下移
  37 + * @param {*} state
  38 + * @param {*} {
  39 + * type: add/copy/delete/move2Top/move2Bottom 增/删/复制/上移/下移
  40 + * value(elementShortcutConfig) 左侧元素列表中元素对应的配置,主要包含:
  41 + * - shortcutProps:默认Props,比如一个Chart是饼图、折线图、漏斗图,可以通过此指定
  42 + * - dragStyle:用于拖拽结束,确定最终放置的位置, // {left: Number, top: Number}
  43 + * }
  44 + */
35 elementManager (state, { type, value }) { 45 elementManager (state, { type, value }) {
  46 + const elementShortcutConfig = value
36 const { editingPage, editingElement } = state 47 const { editingPage, editingElement } = state
37 const elements = editingPage.elements 48 const elements = editingPage.elements
38 const len = elements.length 49 const len = elements.length
@@ -40,10 +51,12 @@ export const mutations = { @@ -40,10 +51,12 @@ export const mutations = {
40 switch (type) { 51 switch (type) {
41 case 'add': 52 case 'add':
42 const vm = getVM(value.name) 53 const vm = getVM(value.name)
43 - vm.$options.shortcutProps = value.shortcutProps  
44 - // 用于拖拽结束,确定最终放置的位置  
45 - vm.$options.dragStyle = value.dragStyle // {left: Number, top: Number}  
46 - const element = new Element(vm.$options) 54 + const basicElement = vm.$options
  55 + const element = new Element({
  56 + ...basicElement,
  57 + ...elementShortcutConfig,
  58 + zindex: len + 1
  59 + })
47 elements.push(element) 60 elements.push(element)
48 break 61 break
49 case 'copy': 62 case 'copy':
front-end/h5/src/utils/element.js
@@ -71,3 +71,13 @@ export const genUUID = () => { @@ -71,3 +71,13 @@ export const genUUID = () => {
71 // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript 71 // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
72 return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15) 72 return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
73 } 73 }
  74 +
  75 +// Generate four random hex digits.
  76 +function S4 () {
  77 + return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
  78 +}
  79 +
  80 +// Generate a pseudo-GUID by concatenating random hexadecimal.
  81 +export function guid () {
  82 + return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4())
  83 +}