diff --git a/lib/app/JlDrawApp.d.ts b/lib/app/JlDrawApp.d.ts index 88c281e..b25cf7a 100644 --- a/lib/app/JlDrawApp.d.ts +++ b/lib/app/JlDrawApp.d.ts @@ -28,7 +28,7 @@ export declare abstract class GraphicDrawAssistant(id: string): T; + queryById(id: number | string): T; /** * 根据id模糊查询图形 * @param id */ - queryByIdAmbiguous(id: string): JlGraphic[]; + queryByIdAmbiguous(id: number | string): JlGraphic[]; /** * 根据类型获取图形列表 */ @@ -33,13 +33,13 @@ export interface GraphicQueryStore { * 根据id或code查询图形 * @param v */ - queryByIdOrCode(v: string): JlGraphic[]; + queryByIdOrCode(v: string | number): JlGraphic[]; /** * 根据id或code及类型查询图形 * @param v * @param type */ - queryByIdOrCodeAndType(v: string, type: string): JlGraphic[]; + queryByIdOrCodeAndType(v: string | number, type: string): JlGraphic[]; /** * 根据code和类型获取图形 * @param code @@ -57,20 +57,20 @@ export interface GraphicQueryStore { * 图形存储 */ export declare class GraphicStore implements GraphicQueryStore { - store: Map; + store: Map; relationManage: RelationManage; constructor(); /** * 获取所有图形对象 */ getAllGraphics(): JlGraphic[]; - queryById(id: string): T; - queryByIdAmbiguous(id: string): JlGraphic[]; + queryById(id: number | string): T; + queryByIdAmbiguous(id: number | string): JlGraphic[]; queryByType(type: string): T[]; queryByCode(code: string): JlGraphic[] | undefined; queryByCodeAmbiguous(code: string): JlGraphic[]; - queryByIdOrCode(s: string): JlGraphic[]; - queryByIdOrCodeAndType(s: string, type: string): JlGraphic[]; + queryByIdOrCode(s: string | number): JlGraphic[]; + queryByIdOrCodeAndType(s: string | number, type: string): JlGraphic[]; queryByCodeAndType(code: string, type: string): T | undefined; queryByCodeAndTypeAmbiguous(code: string, type: string): T[]; /** diff --git a/lib/core/IdGenerator.d.ts b/lib/core/IdGenerator.d.ts index c27cada..db105f8 100644 --- a/lib/core/IdGenerator.d.ts +++ b/lib/core/IdGenerator.d.ts @@ -5,7 +5,7 @@ export declare class IdGenerator { serial: number; type: string; constructor(type: string); - next(): string; + next(): number; getType(): string; initSerial(serial: number): void; } diff --git a/lib/core/JlGraphic.d.ts b/lib/core/JlGraphic.d.ts index caa8068..d2d7e62 100644 --- a/lib/core/JlGraphic.d.ts +++ b/lib/core/JlGraphic.d.ts @@ -38,8 +38,8 @@ export declare class ChildTransform { * 图形数据 */ export interface GraphicData { - get id(): string; - set id(v: string); + get id(): number; + set id(v: number); get graphicType(): string; set graphicType(v: string); get transform(): GraphicTransform; @@ -142,15 +142,15 @@ export declare abstract class JlGraphic extends Container { /** * 是否此对象id/code */ - isIdOrCode(s: string): boolean; + isIdOrCode(s: string | number): boolean; /** * 获取图形id,如果图形数据对象存在,则返回图形数据对象id */ - get id(): string; + get id(): number; /** * 设置图形id,如果图形数据存在,则同时设置图形数据id */ - set id(v: string); + set id(v: number); /** * 获取图形业务code,如果业务code在图形数据或图形状态中,则需要重写此方法 */ diff --git a/lib/index.js b/lib/index.js index 51162cd..e216c89 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,7 +17,8 @@ class IdGenerator { } next() { ++this.serial; - return this.getType() + this.serial; + // console.log(this.getType() + this.serial) + return this.serial; } getType() { return this.type; @@ -4252,15 +4253,20 @@ class GraphicStore { return [...this.store.values()]; } queryById(id) { - const graphic = this.store.get(id); + let nid = id; + if (typeof id === 'string') { + nid = parseInt(id); + } + const graphic = this.store.get(nid); if (!graphic) - throw Error(`未找到id为 [${id}] 的图形.`); - return this.store.get(id); + throw Error(`未找到id为 [${nid}] 的图形.`); + return this.store.get(nid); } queryByIdAmbiguous(id) { + const nid = id + ''; const list = []; this.store.forEach((g) => { - if (g.id.search(id) >= 0) { + if ((g.id + '').search(nid) >= 0) { list.push(g); } }); @@ -4332,7 +4338,7 @@ class GraphicStore { * @param graphics 要存储的图形 */ storeGraphics(graphic) { - if (!graphic.id || graphic.id.trim() === '') { + if (!graphic.id || graphic.id === 0) { throw new Error(`存储图形对象异常: id为空, ${graphic}`); } if (this.store.has(graphic.id)) { @@ -4783,7 +4789,7 @@ class GraphicAnimation { class JlGraphic extends Container { __JlGraphic = true; type; // 图形类型 - _id = ''; // 图形的唯一标识,不具有业务意义,唯一,不可重复,可用做图形数据关联。 + _id = 0; // 图形的唯一标识,不具有业务意义,唯一,不可重复,可用做图形数据关联。 _code = ''; // 业务编号/名称,用于标识图形对象,具有业务意义 _datas; // 图形数据 _states; // 图形状态数据 @@ -6770,8 +6776,7 @@ class GraphicSceneBase extends EventEmitter { // 更新id生成器 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; GraphicIdGenerator.initSerial(max); diff --git a/lib/plugins/AnimationManager.d.ts b/lib/plugins/AnimationManager.d.ts index 77b6207..97f3875 100644 --- a/lib/plugins/AnimationManager.d.ts +++ b/lib/plugins/AnimationManager.d.ts @@ -9,7 +9,7 @@ export declare class AnimationManager { /** * key - graphic.id */ - graphicAnimationMap: Map>; + graphicAnimationMap: Map>; constructor(app: IGraphicScene); private run; pause(): void;