1
0

uvue.uts 997 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // @ts-nocheck
  2. import { type ComponentPublicInstance } from 'vue';
  3. type SelectOptions = {
  4. context : ComponentPublicInstance,
  5. needAll : boolean | null,
  6. }
  7. export function selectAllComponent(selector : string, options : UTSJSONObject) : ComponentPublicInstance[]|null {
  8. const context = options.get('context')! as ComponentPublicInstance;
  9. let needAll = options.get('needAll') as boolean;
  10. let result:ComponentPublicInstance[] = []
  11. if(needAll == null) { needAll = true };
  12. if(context.$children.length > 0) {
  13. const queue:ComponentPublicInstance[] = [...context.$children];
  14. while(queue.length > 0) {
  15. const child = queue.shift();
  16. const name = child?.$options?.name;
  17. if(name == selector) {
  18. result.push(child as ComponentPublicInstance)
  19. } else {
  20. const children = child?.$children
  21. if(children !== null) {
  22. queue.push(...children)
  23. }
  24. }
  25. if(result.length > 0 && !needAll) {
  26. break;
  27. }
  28. }
  29. }
  30. if(result.length > 0) {
  31. return result
  32. }
  33. return null
  34. }