id转number类型
This commit is contained in:
parent
78a28b3031
commit
b91c31f713
@ -143,7 +143,7 @@ export abstract class GraphicDrawAssistant<
|
||||
/**
|
||||
* 获取下一个id
|
||||
*/
|
||||
nextId(): string {
|
||||
nextId(): number {
|
||||
return GraphicIdGenerator.next();
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -9,12 +9,12 @@ export interface GraphicQueryStore {
|
||||
/**
|
||||
* 根据id获取图形
|
||||
*/
|
||||
queryById<T extends JlGraphic>(id: string): T;
|
||||
queryById<T extends JlGraphic>(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<string, JlGraphic>;
|
||||
store: Map<number, JlGraphic>;
|
||||
relationManage: RelationManage;
|
||||
constructor() {
|
||||
this.store = new Map<string, JlGraphic>();
|
||||
this.store = new Map<number, JlGraphic>();
|
||||
this.relationManage = new RelationManage();
|
||||
}
|
||||
|
||||
@ -79,15 +79,15 @@ export class GraphicStore implements GraphicQueryStore {
|
||||
getAllGraphics(): JlGraphic[] {
|
||||
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;
|
||||
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)) {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -10,11 +10,11 @@ export class AnimationManager {
|
||||
/**
|
||||
* key - graphic.id
|
||||
*/
|
||||
graphicAnimationMap: Map<string, Map<string, GraphicAnimation>>;
|
||||
graphicAnimationMap: Map<number, Map<string, GraphicAnimation>>;
|
||||
constructor(app: IGraphicScene) {
|
||||
this.app = app;
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user