query调整

This commit is contained in:
fan 2023-12-14 10:34:54 +08:00 committed by Yuan
parent 9de8fbda46
commit eb3d46c037

View File

@ -9,12 +9,12 @@ export interface GraphicQueryStore {
/** /**
* id获取图形 * id获取图形
*/ */
queryById<T extends JlGraphic>(id: number): T; queryById<T extends JlGraphic>(id: number | string): T;
/** /**
* id模糊查询图形 * id模糊查询图形
* @param id * @param id
*/ */
queryByIdAmbiguous(id: number): JlGraphic[]; queryByIdAmbiguous(id: number | string): JlGraphic[];
/** /**
* *
@ -79,15 +79,20 @@ export class GraphicStore implements GraphicQueryStore {
getAllGraphics(): JlGraphic[] { getAllGraphics(): JlGraphic[] {
return [...this.store.values()]; return [...this.store.values()];
} }
queryById<T extends JlGraphic>(id: number): T { queryById<T extends JlGraphic>(id: number | string): T {
const graphic = this.store.get(id) as T; let nid = id;
if (!graphic) throw Error(`未找到id为 [${id}] 的图形.`); if (typeof id === 'string') {
return this.store.get(id) as T; nid = parseInt(id);
}
const graphic = this.store.get(nid as number) as T;
if (!graphic) throw Error(`未找到id为 [${nid}] 的图形.`);
return this.store.get(nid as number) as T;
} }
queryByIdAmbiguous(id: number): JlGraphic[] { queryByIdAmbiguous(id: number | string): JlGraphic[] {
const nid = id + '';
const list: JlGraphic[] = []; const list: JlGraphic[] = [];
this.store.forEach((g) => { this.store.forEach((g) => {
if (Math.abs(g.id - id) <= 10) { if ((g.id + '').search(nid) >= 0) {
list.push(g); list.push(g);
} }
}); });