diff --git a/packages/editor/src/services/props.ts b/packages/editor/src/services/props.ts index 5cf9e114..c022769b 100644 --- a/packages/editor/src/services/props.ts +++ b/packages/editor/src/services/props.ts @@ -17,7 +17,7 @@ */ import { reactive } from 'vue'; -import { cloneDeep, mergeWith, random } from 'lodash-es'; +import { cloneDeep, mergeWith } from 'lodash-es'; import type { FormConfig } from '@tmagic/form'; import type { Id, MComponent, MNode, MPage } from '@tmagic/schema'; @@ -121,12 +121,25 @@ class Props extends BaseService { return { id, ...defaultPropsValue, - ...mergeWith(cloneDeep(this.state.propsValueMap[type] || {}), data), + ...mergeWith({}, cloneDeep(this.state.propsValueMap[type] || {}), data), }; } + /** + * 生成指定位数的GUID,无【-】格式 + * @param digit 位数,默认值8 + * @returns + */ + guid(digit = 8): string { + return 'x'.repeat(digit).replace(/[xy]/g, (c) => { + const r = (Math.random() * 16) | 0; + const v = c == 'x' ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); + } + public async createId(type: string | number): Promise { - return `${type}_${random(10000, false)}`; + return `${type}_${this.guid()}`; } /**