You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
import { allowedNodeEnvironmentFlags } from "process"; |
|
|
|
/** |
|
* 选择器 |
|
*/ |
|
export class AxSelection { |
|
constructor() { |
|
} |
|
private objects: Set<any> = new Set<any>(); |
|
// 获得第一个对象 |
|
public first(): any { |
|
if (this.objects.size > 0) { |
|
return [...this.objects][0]; |
|
} else { |
|
return null; |
|
} |
|
} |
|
// 是否已经选择了对象 |
|
public has(obj: any): boolean { |
|
return this.objects.has(obj); |
|
} |
|
// 是否所有选择对象都允许编辑 |
|
public allowEdit(): boolean { |
|
let allowEdit = true; |
|
for (const item of this.objects) { |
|
if (!item.allowEdit) { |
|
allowEdit = false; |
|
break; |
|
} |
|
} |
|
return allowEdit; |
|
} |
|
// 获得所有对象 |
|
public all() { |
|
return [...this.objects]; |
|
} |
|
// 获取集合长度 |
|
public size(): number { |
|
return this.objects.size; |
|
} |
|
// 添加对象 |
|
public add(obj: any) { |
|
this.objects.add(obj); |
|
} |
|
// 添加集合 |
|
public addArray(array: any[]) { |
|
array.forEach(item => { |
|
this.objects.add(item); |
|
}); |
|
} |
|
// 移除对象 |
|
public delete(obj: any) { |
|
this.objects.delete(obj); |
|
} |
|
// 移除集合 |
|
public deleteArray(array: any[]) { |
|
array.forEach(item => { |
|
this.objects.delete(item); |
|
}); |
|
} |
|
// 清空所有对象 |
|
public clear() { |
|
this.objects.clear(); |
|
} |
|
}
|
|
|