Browse Source

[完善] 新的guid

develop
徐振升 4 years ago
parent
commit
5ec65cf8b2
  1. 73
      src/app/working-area/working-area.component.ts

73
src/app/working-area/working-area.component.ts

@ -88,15 +88,12 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
this.emit('deleteIcon'); this.emit('deleteIcon');
} }
}); });
// // 测试代码 // 测试代码
// this.eventManager.addGlobalEventListener('window', 'keypress', (event: any) => { this.eventManager.addGlobalEventListener('window', 'keypress', (event: any) => {
// if (event.keyCode === 97) { if (event.keyCode === 97) {
// this.copy(); console.log(Guid.uuid2(24, 16));
// } }
// if (event.keyCode === 115) { });
// this.paste('1', '2', '3');
// }
// });
} }
ngAfterViewInit(): void { ngAfterViewInit(): void {
@ -384,7 +381,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
FixedSize: this.canvasData.selectTemplateData.fixedSize, FixedSize: this.canvasData.selectTemplateData.fixedSize,
Height : 32, Height : 32,
Width : 32, Width : 32,
Id: Guid.NewGuid().ToString(), Id: Guid.uuid2(24, 16),
ImageUrl: this.canvasData.selectTemplateData.imageUrl, ImageUrl: this.canvasData.selectTemplateData.imageUrl,
InteractiveMode: this.canvasData.selectTemplateData.interactiveMode, InteractiveMode: this.canvasData.selectTemplateData.interactiveMode,
MultiPoint : null, MultiPoint : null,
@ -435,7 +432,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
FixedSize: this.canvasData.selectTemplateData.fixedSize, FixedSize: this.canvasData.selectTemplateData.fixedSize,
Height: 32, Height: 32,
Width: 32, Width: 32,
Id: Guid.NewGuid().ToString(), Id: Guid.uuid2(24, 16),
ImageUrl: this.canvasData.selectTemplateData.imageUrl, ImageUrl: this.canvasData.selectTemplateData.imageUrl,
InteractiveMode: this.canvasData.selectTemplateData.interactiveMode, InteractiveMode: this.canvasData.selectTemplateData.interactiveMode,
MultiPoint: JSON.parse(JSON.stringify(this.paintPoints)), MultiPoint: JSON.parse(JSON.stringify(this.paintPoints)),
@ -704,7 +701,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
FixedSize: this.canvasData.selectTemplateData.fixedSize, FixedSize: this.canvasData.selectTemplateData.fixedSize,
Height: 32, Height: 32,
Width: 32, Width: 32,
Id: Guid.NewGuid().ToString(), Id: Guid.uuid2(24, 16),
ImageUrl: this.canvasData.selectTemplateData.imageUrl, ImageUrl: this.canvasData.selectTemplateData.imageUrl,
InteractiveMode: this.canvasData.selectTemplateData.interactiveMode, InteractiveMode: this.canvasData.selectTemplateData.interactiveMode,
MultiPoint: JSON.parse(JSON.stringify(this.paintPoints)), MultiPoint: JSON.parse(JSON.stringify(this.paintPoints)),
@ -746,7 +743,7 @@ export class WorkingAreaComponent extends EventEmitter implements OnInit, AfterV
this.copyData.forEach(item => { this.copyData.forEach(item => {
item.Point = new PIXI.Point(item.Point.x + 5, item.Point.y + 5); item.Point = new PIXI.Point(item.Point.x + 5, item.Point.y + 5);
const newData = JSON.parse(JSON.stringify(item)); const newData = JSON.parse(JSON.stringify(item));
newData.Id = Guid.NewGuid().ToString(); newData.Id = Guid.uuid2(24, 16),
newData.CompanyId = companyId; newData.CompanyId = companyId;
newData.BuildingId = buildingId; newData.BuildingId = buildingId;
newData.FloorId = floorId; newData.FloorId = floorId;
@ -1334,30 +1331,40 @@ export class Selection {
* guid * guid
*/ */
export class Guid { export class Guid {
private _guid: string;
constructor(public guid: string) { static uuid2(len, radix) {
this._guid = guid; const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
}
// Static member // tslint:disable-next-line: one-variable-per-declaration
static NewGuid(): Guid { let uuid = [], i;
let result: string; radix = radix || chars.length;
let i: string;
let j: number; if (len) {
// Compact form
result = ''; // tslint:disable-next-line: no-bitwise
for (j = 0; j < 32; j++) { for (i = 0; i < len; i++) { uuid[i] = chars[0 | Math.random() * radix]; }
if (j === 8 || j === 12 || j === 16 || j === 20) { } else {
result = result + '-'; // 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 uuid.join('');
return this.guid; }
}
} }
/** /**

Loading…
Cancel
Save