Commit 8ca8770fb2c4325552f353000283ce3f6eabfb43

Authored by ly525
2 parents 383deb83 f65fa61d

Merge branch 'fix_use_uuid_to_get_editing_element' into master

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/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']
@@ -19,7 +19,7 @@ const defaultStyle = { @@ -19,7 +19,7 @@ const defaultStyle = {
19 class Element { 19 class Element {
20 constructor (ele) { 20 constructor (ele) {
21 this.name = ele.name 21 this.name = ele.name
22 - this.uuid = ele.uuid || +new Date() 22 + this.uuid = ele.uuid || guid()
23 /** 23 /**
24 * #!zh: 24 * #!zh:
25 * 之前版本代码:https://github.com/ly525/luban-h5/blob/a7875cbc73c0d18bc2459985ca3ce1d4dc44f141/front-end/h5/src/components/core/models/element.js#L21 25 * 之前版本代码: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/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 +}