fix(editor): id可能重复 (#221)

提升id位数,降低id重复几率
This commit is contained in:
王明华 2022-08-03 14:01:12 +08:00 committed by GitHub
parent 259a5aa530
commit a02fd2c695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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<string> {
return `${type}_${random(10000, false)}`;
return `${type}_${this.guid()}`;
}
/**