合同小程序前端代码仓库
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.
 
 
 
 
 

39 lines
997 B

// @ts-nocheck
import { type ComponentPublicInstance } from 'vue';
type SelectOptions = {
context : ComponentPublicInstance,
needAll : boolean | null,
}
export function selectAllComponent(selector : string, options : UTSJSONObject) : ComponentPublicInstance[]|null {
const context = options.get('context')! as ComponentPublicInstance;
let needAll = options.get('needAll') as boolean;
let result:ComponentPublicInstance[] = []
if(needAll == null) { needAll = true };
if(context.$children.length > 0) {
const queue:ComponentPublicInstance[] = [...context.$children];
while(queue.length > 0) {
const child = queue.shift();
const name = child?.$options?.name;
if(name == selector) {
result.push(child as ComponentPublicInstance)
} else {
const children = child?.$children
if(children !== null) {
queue.push(...children)
}
}
if(result.length > 0 && !needAll) {
break;
}
}
}
if(result.length > 0) {
return result
}
return null
}