Commit f65fa61d3440f5a1a9de564e5b2a3734dd19a0f3

Authored by ly525
1 parent 4228dbb7

chore: add guid

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']
5 const cloneObj = (value) => JSON.parse(JSON.stringify(value)) 5 const cloneObj = (value) => JSON.parse(JSON.stringify(value))
6 6
7 -var seed = 0  
8 -var now = Date.now()  
9 -  
10 -function getUuid (ele) {  
11 - return `element_${ele.name}_${now}_${seed++}`  
12 -}  
13 const defaultStyle = { 7 const defaultStyle = {
14 top: 100, 8 top: 100,
15 left: 100, 9 left: 100,
@@ -25,7 +19,7 @@ const defaultStyle = { @@ -25,7 +19,7 @@ const defaultStyle = {
25 class Element { 19 class Element {
26 constructor (ele) { 20 constructor (ele) {
27 this.name = ele.name 21 this.name = ele.name
28 - this.uuid = ele.uuid || getUuid(ele) 22 + this.uuid = ele.uuid || guid()
29 /** 23 /**
30 * #!zh: 24 * #!zh:
31 * 之前版本代码: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/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 +}