id转number类型
This commit is contained in:
parent
98298af2b2
commit
9de8fbda46
@ -9,12 +9,12 @@ export interface GraphicQueryStore {
|
|||||||
/**
|
/**
|
||||||
* 根据id获取图形
|
* 根据id获取图形
|
||||||
*/
|
*/
|
||||||
queryById<T extends JlGraphic>(id: number | string): T;
|
queryById<T extends JlGraphic>(id: number): T;
|
||||||
/**
|
/**
|
||||||
* 根据id模糊查询图形
|
* 根据id模糊查询图形
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
queryByIdAmbiguous(id: number | string): JlGraphic[];
|
queryByIdAmbiguous(id: number): JlGraphic[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据类型获取图形列表
|
* 根据类型获取图形列表
|
||||||
@ -79,20 +79,15 @@ export class GraphicStore implements GraphicQueryStore {
|
|||||||
getAllGraphics(): JlGraphic[] {
|
getAllGraphics(): JlGraphic[] {
|
||||||
return [...this.store.values()];
|
return [...this.store.values()];
|
||||||
}
|
}
|
||||||
queryById<T extends JlGraphic>(id: number | string): T {
|
queryById<T extends JlGraphic>(id: number): T {
|
||||||
let nid = id;
|
const graphic = this.store.get(id) as T;
|
||||||
if (typeof id === 'string') {
|
if (!graphic) throw Error(`未找到id为 [${id}] 的图形.`);
|
||||||
nid = parseInt(id);
|
return this.store.get(id) as T;
|
||||||
}
|
|
||||||
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 | string): JlGraphic[] {
|
queryByIdAmbiguous(id: number): JlGraphic[] {
|
||||||
const nid = id + '';
|
|
||||||
const list: JlGraphic[] = [];
|
const list: JlGraphic[] = [];
|
||||||
this.store.forEach((g) => {
|
this.store.forEach((g) => {
|
||||||
if ((g.id + '').search(nid) >= 0) {
|
if (Math.abs(g.id - id) <= 10) {
|
||||||
list.push(g);
|
list.push(g);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user