id转number类型

This commit is contained in:
joylink_zhaoerwei 2023-12-12 15:14:07 +08:00
parent 78a28b3031
commit b91c31f713
6 changed files with 20 additions and 21 deletions

View File

@ -143,7 +143,7 @@ export abstract class GraphicDrawAssistant<
/** /**
* id * id
*/ */
nextId(): string { nextId(): number {
return GraphicIdGenerator.next(); return GraphicIdGenerator.next();
} }

View File

@ -852,8 +852,7 @@ abstract class GraphicSceneBase
const max = const max =
this.queryStore this.queryStore
.getAllGraphics() .getAllGraphics()
.filter((g) => !isNaN(parseInt(g.id))) .map((g) => g.id)
.map((g) => parseInt(g.id))
.sort((a, b) => a - b) .sort((a, b) => a - b)
.pop() ?? 0; .pop() ?? 0;
// console.log('最大值', max) // console.log('最大值', max)

View File

@ -9,12 +9,12 @@ export interface GraphicQueryStore {
/** /**
* id获取图形 * id获取图形
*/ */
queryById<T extends JlGraphic>(id: string): T; queryById<T extends JlGraphic>(id: number): T;
/** /**
* id模糊查询图形 * id模糊查询图形
* @param id * @param id
*/ */
queryByIdAmbiguous(id: string): JlGraphic[]; queryByIdAmbiguous(id: number): JlGraphic[];
/** /**
* *
@ -66,10 +66,10 @@ export interface GraphicQueryStore {
* *
*/ */
export class GraphicStore implements GraphicQueryStore { export class GraphicStore implements GraphicQueryStore {
store: Map<string, JlGraphic>; store: Map<number, JlGraphic>;
relationManage: RelationManage; relationManage: RelationManage;
constructor() { constructor() {
this.store = new Map<string, JlGraphic>(); this.store = new Map<number, JlGraphic>();
this.relationManage = new RelationManage(); this.relationManage = new RelationManage();
} }
@ -79,15 +79,15 @@ export class GraphicStore implements GraphicQueryStore {
getAllGraphics(): JlGraphic[] { getAllGraphics(): JlGraphic[] {
return [...this.store.values()]; return [...this.store.values()];
} }
queryById<T extends JlGraphic>(id: string): T { queryById<T extends JlGraphic>(id: number): T {
const graphic = this.store.get(id) as T; const graphic = this.store.get(id) as T;
if (!graphic) throw Error(`未找到id为 [${id}] 的图形.`); if (!graphic) throw Error(`未找到id为 [${id}] 的图形.`);
return this.store.get(id) as T; return this.store.get(id) as T;
} }
queryByIdAmbiguous(id: string): JlGraphic[] { queryByIdAmbiguous(id: number): JlGraphic[] {
const list: JlGraphic[] = []; const list: JlGraphic[] = [];
this.store.forEach((g) => { this.store.forEach((g) => {
if (g.id.search(id) >= 0) { if (Math.abs(g.id - id) <= 10) {
list.push(g); list.push(g);
} }
}); });
@ -166,7 +166,7 @@ export class GraphicStore implements GraphicQueryStore {
* @param graphics * @param graphics
*/ */
storeGraphics(graphic: JlGraphic): boolean { storeGraphics(graphic: JlGraphic): boolean {
if (!graphic.id || graphic.id.trim() === '') { if (!graphic.id || graphic.id === 0) {
throw new Error(`存储图形对象异常: id为空, ${graphic}`); throw new Error(`存储图形对象异常: id为空, ${graphic}`);
} }
if (this.store.has(graphic.id)) { if (this.store.has(graphic.id)) {

View File

@ -9,10 +9,10 @@ export class IdGenerator {
this.type = type; this.type = type;
} }
next(): string { next(): number {
++this.serial; ++this.serial;
// console.log(this.getType() + this.serial) // console.log(this.getType() + this.serial)
return this.getType() + this.serial; return this.serial;
} }
getType(): string { getType(): string {

View File

@ -475,8 +475,8 @@ export class ChildTransform {
* *
*/ */
export interface GraphicData { export interface GraphicData {
get id(): string; // 图形id get id(): number; // 图形id
set id(v: string); set id(v: number);
get graphicType(): string; // 图形类型 get graphicType(): string; // 图形类型
set graphicType(v: string); set graphicType(v: string);
get transform(): GraphicTransform; // get transform(): GraphicTransform; //
@ -585,7 +585,7 @@ export class GraphicAnimation {
export abstract class JlGraphic extends Container { export abstract class JlGraphic extends Container {
readonly __JlGraphic = true as const; readonly __JlGraphic = true as const;
readonly type: string; // 图形类型 readonly type: string; // 图形类型
private _id = ''; // 图形的唯一标识,不具有业务意义,唯一,不可重复,可用做图形数据关联。 private _id = 0; // 图形的唯一标识,不具有业务意义,唯一,不可重复,可用做图形数据关联。
private _code = ''; // 业务编号/名称,用于标识图形对象,具有业务意义 private _code = ''; // 业务编号/名称,用于标识图形对象,具有业务意义
_datas?: GraphicData; // 图形数据 _datas?: GraphicData; // 图形数据
_states?: GraphicState; // 图形状态数据 _states?: GraphicState; // 图形状态数据
@ -707,13 +707,13 @@ export abstract class JlGraphic extends Container {
* id/code * id/code
*/ */
isIdOrCode(s: string): boolean { isIdOrCode(s: string): boolean {
return this.id === s || this.code === s; return this.id === +s || this.code === s;
} }
/** /**
* idid * idid
*/ */
public get id(): string { public get id(): number {
if (this._datas) { if (this._datas) {
return this._datas.id; return this._datas.id;
} }
@ -722,7 +722,7 @@ export abstract class JlGraphic extends Container {
/** /**
* idid * idid
*/ */
public set id(v: string) { public set id(v: number) {
this._id = v; this._id = v;
if (this._datas) { if (this._datas) {
this._datas.id = v; this._datas.id = v;

View File

@ -10,11 +10,11 @@ export class AnimationManager {
/** /**
* key - graphic.id * key - graphic.id
*/ */
graphicAnimationMap: Map<string, Map<string, GraphicAnimation>>; graphicAnimationMap: Map<number, Map<string, GraphicAnimation>>;
constructor(app: IGraphicScene) { constructor(app: IGraphicScene) {
this.app = app; this.app = app;
this._pause = false; this._pause = false;
this.graphicAnimationMap = new Map<string, Map<string, GraphicAnimation>>(); this.graphicAnimationMap = new Map<number, Map<string, GraphicAnimation>>();
// 动画控制 // 动画控制
app.pixi.ticker.add(this.run, this); app.pixi.ticker.add(this.run, this);
} }