diff --git a/src/app/working-area/working-area.component.ts b/src/app/working-area/working-area.component.ts index c5431d6..d063522 100644 --- a/src/app/working-area/working-area.component.ts +++ b/src/app/working-area/working-area.component.ts @@ -88,15 +88,12 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV this.emit('deleteIcon'); } }); - // // 测试代码 - // this.eventManager.addGlobalEventListener('window', 'keypress', (event: any) => { - // if (event.keyCode === 97) { - // this.copy(); - // } - // if (event.keyCode === 115) { - // this.paste('1', '2', '3'); - // } - // }); + // 测试代码 + this.eventManager.addGlobalEventListener('window', 'keypress', (event: any) => { + if (event.keyCode === 97) { + console.log(Guid.uuid2(24, 16)); + } + }); } ngAfterViewInit(): void { @@ -384,7 +381,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV FixedSize: this.canvasData.selectTemplateData.fixedSize, Height : 32, Width : 32, - Id: Guid.NewGuid().ToString(), + Id: Guid.uuid2(24, 16), ImageUrl: this.canvasData.selectTemplateData.imageUrl, InteractiveMode: this.canvasData.selectTemplateData.interactiveMode, MultiPoint : null, @@ -435,7 +432,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV FixedSize: this.canvasData.selectTemplateData.fixedSize, Height: 32, Width: 32, - Id: Guid.NewGuid().ToString(), + Id: Guid.uuid2(24, 16), ImageUrl: this.canvasData.selectTemplateData.imageUrl, InteractiveMode: this.canvasData.selectTemplateData.interactiveMode, MultiPoint: JSON.parse(JSON.stringify(this.paintPoints)), @@ -704,7 +701,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV FixedSize: this.canvasData.selectTemplateData.fixedSize, Height: 32, Width: 32, - Id: Guid.NewGuid().ToString(), + Id: Guid.uuid2(24, 16), ImageUrl: this.canvasData.selectTemplateData.imageUrl, InteractiveMode: this.canvasData.selectTemplateData.interactiveMode, MultiPoint: JSON.parse(JSON.stringify(this.paintPoints)), @@ -746,7 +743,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV this.copyData.forEach(item => { item.Point = new PIXI.Point(item.Point.x + 5, item.Point.y + 5); const newData = JSON.parse(JSON.stringify(item)); - newData.Id = Guid.NewGuid().ToString(); + newData.Id = Guid.uuid2(24, 16), newData.CompanyId = companyId; newData.BuildingId = buildingId; newData.FloorId = floorId; @@ -1334,30 +1331,40 @@ export class Selection { * guid */ export class Guid { - private _guid: string; - constructor(public guid: string) { - this._guid = guid; - } - // Static member - static NewGuid(): Guid { - let result: string; - let i: string; - let j: number; - - result = ''; - for (j = 0; j < 32; j++) { - if (j === 8 || j === 12 || j === 16 || j === 20) { - result = result + '-'; + + static uuid2(len, radix) { + const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); + + // tslint:disable-next-line: one-variable-per-declaration + let uuid = [], i; + radix = radix || chars.length; + + if (len) { + // Compact form + // tslint:disable-next-line: no-bitwise + for (i = 0; i < len; i++) { uuid[i] = chars[0 | Math.random() * radix]; } + } else { + // rfc4122, version 4 form + let r; + + // rfc4122 requires these characters + uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; + uuid[14] = '4'; + + // Fill in random data. At i==19 set the high bits of clock sequence as + // per rfc4122, sec. 4.1.5 + for (i = 0; i < 36; i++) { + if (!uuid[i]) { + // tslint:disable-next-line: no-bitwise + r = 0 | Math.random() * 16; + // tslint:disable-next-line: no-bitwise + uuid[i] = chars[(i === 19) ? (r & 0x3) | 0x8 : r]; } - i = Math.floor(Math.random() * 16).toString(16).toUpperCase(); - result = result + i; } - return new Guid(result); } - public ToString(): string { - return this.guid; - } + return uuid.join(''); +} } /**