Change object id type

This commit is contained in:
MrKBear 2022-03-09 11:54:31 +08:00
parent 8e3330b398
commit 97202fe976
3 changed files with 7 additions and 7 deletions

View File

@ -28,8 +28,8 @@ class Model extends Emitter<ModelEvent> {
* ID * ID
*/ */
private idIndex: number = 1; private idIndex: number = 1;
public get nextId(): number { public nextId(label: string = "U"): string {
return this.idIndex ++; return `${label}-${this.idIndex ++}`;
} }
/** /**
@ -55,7 +55,7 @@ class Model extends Emitter<ModelEvent> {
*/ */
public addLabel(name: string): Label { public addLabel(name: string): Label {
console.log(`Model: Creat label with id ${this.idIndex}`); console.log(`Model: Creat label with id ${this.idIndex}`);
let label = new Label(this, this.nextId, name); let label = new Label(this, this.nextId("L"), name);
this.labelPool.push(label); this.labelPool.push(label);
this.emit("labelAdd", label); this.emit("labelAdd", label);
this.emit("labelChange", this.labelPool); this.emit("labelChange", this.labelPool);
@ -95,7 +95,7 @@ class Model extends Emitter<ModelEvent> {
*/ */
public addGroup(): Group { public addGroup(): Group {
console.log(`Model: Creat group with id ${this.idIndex}`); console.log(`Model: Creat group with id ${this.idIndex}`);
let group = new Group(this, this.nextId); let group = new Group(this, this.nextId("G"));
this.objectPool.push(group); this.objectPool.push(group);
this.emit("groupAdd", group); this.emit("groupAdd", group);
this.emit("objectAdd", group); this.emit("objectAdd", group);
@ -108,7 +108,7 @@ class Model extends Emitter<ModelEvent> {
*/ */
public addRange(): Range { public addRange(): Range {
console.log(`Model: Creat range with id ${this.idIndex}`); console.log(`Model: Creat range with id ${this.idIndex}`);
let range = new Range(this, this.nextId); let range = new Range(this, this.nextId("R"));
this.objectPool.push(range); this.objectPool.push(range);
this.emit("rangeAdd", range); this.emit("rangeAdd", range);
this.emit("objectAdd", range); this.emit("objectAdd", range);

View File

@ -35,7 +35,7 @@ interface ICommonParam {
/** /**
* *
*/ */
type ObjectID = Symbol | string | number; type ObjectID = string;
/** /**
* *

View File

@ -113,7 +113,7 @@ class RangeDetails extends Component<IMixinStatusProps> {
if (this.props.status.focusObject.size > 1) { if (this.props.status.focusObject.size > 1) {
return <ErrorMessage i18nKey="Common.Attr.Key.Error.Multiple"/>; return <ErrorMessage i18nKey="Common.Attr.Key.Error.Multiple"/>;
} }
let id: ObjectID = 0; let id: ObjectID = "";
this.props.status.focusObject.forEach((cid => id = cid)); this.props.status.focusObject.forEach((cid => id = cid));
let range = this.props.status!.model.getObjectById(id); let range = this.props.status!.model.getObjectById(id);