From b91c31f713697af755d1396e4883e9649cf114ab Mon Sep 17 00:00:00 2001 From: joylink_zhaoerwei Date: Tue, 12 Dec 2023 15:14:07 +0800 Subject: [PATCH] =?UTF-8?q?id=E8=BD=ACnumber=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jlgraphic/app/JlDrawApp.ts | 2 +- src/jlgraphic/app/JlGraphicApp.ts | 3 +-- src/jlgraphic/core/GraphicStore.ts | 16 ++++++++-------- src/jlgraphic/core/IdGenerator.ts | 4 ++-- src/jlgraphic/core/JlGraphic.ts | 12 ++++++------ src/jlgraphic/plugins/AnimationManager.ts | 4 ++-- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/jlgraphic/app/JlDrawApp.ts b/src/jlgraphic/app/JlDrawApp.ts index 78040c7..294aa48 100644 --- a/src/jlgraphic/app/JlDrawApp.ts +++ b/src/jlgraphic/app/JlDrawApp.ts @@ -143,7 +143,7 @@ export abstract class GraphicDrawAssistant< /** * 获取下一个id */ - nextId(): string { + nextId(): number { return GraphicIdGenerator.next(); } diff --git a/src/jlgraphic/app/JlGraphicApp.ts b/src/jlgraphic/app/JlGraphicApp.ts index 908b08e..8e4d852 100644 --- a/src/jlgraphic/app/JlGraphicApp.ts +++ b/src/jlgraphic/app/JlGraphicApp.ts @@ -852,8 +852,7 @@ abstract class GraphicSceneBase const max = this.queryStore .getAllGraphics() - .filter((g) => !isNaN(parseInt(g.id))) - .map((g) => parseInt(g.id)) + .map((g) => g.id) .sort((a, b) => a - b) .pop() ?? 0; // console.log('最大值', max) diff --git a/src/jlgraphic/core/GraphicStore.ts b/src/jlgraphic/core/GraphicStore.ts index 300fc85..a100a89 100644 --- a/src/jlgraphic/core/GraphicStore.ts +++ b/src/jlgraphic/core/GraphicStore.ts @@ -9,12 +9,12 @@ export interface GraphicQueryStore { /** * 根据id获取图形 */ - queryById(id: string): T; + queryById(id: number): T; /** * 根据id模糊查询图形 * @param id */ - queryByIdAmbiguous(id: string): JlGraphic[]; + queryByIdAmbiguous(id: number): JlGraphic[]; /** * 根据类型获取图形列表 @@ -66,10 +66,10 @@ export interface GraphicQueryStore { * 图形存储 */ export class GraphicStore implements GraphicQueryStore { - store: Map; + store: Map; relationManage: RelationManage; constructor() { - this.store = new Map(); + this.store = new Map(); this.relationManage = new RelationManage(); } @@ -79,15 +79,15 @@ export class GraphicStore implements GraphicQueryStore { getAllGraphics(): JlGraphic[] { return [...this.store.values()]; } - queryById(id: string): T { + queryById(id: number): T { const graphic = this.store.get(id) as T; if (!graphic) throw Error(`未找到id为 [${id}] 的图形.`); return this.store.get(id) as T; } - queryByIdAmbiguous(id: string): JlGraphic[] { + queryByIdAmbiguous(id: number): JlGraphic[] { const list: JlGraphic[] = []; this.store.forEach((g) => { - if (g.id.search(id) >= 0) { + if (Math.abs(g.id - id) <= 10) { list.push(g); } }); @@ -166,7 +166,7 @@ export class GraphicStore implements GraphicQueryStore { * @param graphics 要存储的图形 */ storeGraphics(graphic: JlGraphic): boolean { - if (!graphic.id || graphic.id.trim() === '') { + if (!graphic.id || graphic.id === 0) { throw new Error(`存储图形对象异常: id为空, ${graphic}`); } if (this.store.has(graphic.id)) { diff --git a/src/jlgraphic/core/IdGenerator.ts b/src/jlgraphic/core/IdGenerator.ts index 131f699..57b2a09 100644 --- a/src/jlgraphic/core/IdGenerator.ts +++ b/src/jlgraphic/core/IdGenerator.ts @@ -9,10 +9,10 @@ export class IdGenerator { this.type = type; } - next(): string { + next(): number { ++this.serial; // console.log(this.getType() + this.serial) - return this.getType() + this.serial; + return this.serial; } getType(): string { diff --git a/src/jlgraphic/core/JlGraphic.ts b/src/jlgraphic/core/JlGraphic.ts index 65d58d1..9998d75 100644 --- a/src/jlgraphic/core/JlGraphic.ts +++ b/src/jlgraphic/core/JlGraphic.ts @@ -475,8 +475,8 @@ export class ChildTransform { * 图形数据 */ export interface GraphicData { - get id(): string; // 图形id - set id(v: string); + get id(): number; // 图形id + set id(v: number); get graphicType(): string; // 图形类型 set graphicType(v: string); get transform(): GraphicTransform; // @@ -585,7 +585,7 @@ export class GraphicAnimation { export abstract class JlGraphic extends Container { readonly __JlGraphic = true as const; readonly type: string; // 图形类型 - private _id = ''; // 图形的唯一标识,不具有业务意义,唯一,不可重复,可用做图形数据关联。 + private _id = 0; // 图形的唯一标识,不具有业务意义,唯一,不可重复,可用做图形数据关联。 private _code = ''; // 业务编号/名称,用于标识图形对象,具有业务意义 _datas?: GraphicData; // 图形数据 _states?: GraphicState; // 图形状态数据 @@ -707,13 +707,13 @@ export abstract class JlGraphic extends Container { * 是否此对象id/code */ isIdOrCode(s: string): boolean { - return this.id === s || this.code === s; + return this.id === +s || this.code === s; } /** * 获取图形id,如果图形数据对象存在,则返回图形数据对象id */ - public get id(): string { + public get id(): number { if (this._datas) { return this._datas.id; } @@ -722,7 +722,7 @@ export abstract class JlGraphic extends Container { /** * 设置图形id,如果图形数据存在,则同时设置图形数据id */ - public set id(v: string) { + public set id(v: number) { this._id = v; if (this._datas) { this._datas.id = v; diff --git a/src/jlgraphic/plugins/AnimationManager.ts b/src/jlgraphic/plugins/AnimationManager.ts index d783098..830f0b7 100644 --- a/src/jlgraphic/plugins/AnimationManager.ts +++ b/src/jlgraphic/plugins/AnimationManager.ts @@ -10,11 +10,11 @@ export class AnimationManager { /** * key - graphic.id */ - graphicAnimationMap: Map>; + graphicAnimationMap: Map>; constructor(app: IGraphicScene) { this.app = app; this._pause = false; - this.graphicAnimationMap = new Map>(); + this.graphicAnimationMap = new Map>(); // 动画控制 app.pixi.ticker.add(this.run, this); }