utils.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * @Author: your name
  3. * @Date: 2022-01-13 17:09:05
  4. * @LastEditTime: 2022-03-03 15:02:41
  5. * @LastEditors: Please set LastEditors
  6. * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  7. * @FilePath: /KC-MiddlePlatform/src/utils.js
  8. */
  9. export const randomString = (length: number) => {
  10. const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_=-';
  11. let result = '';
  12. for (let i = length; i > 0; --i) {
  13. result += chars[Math.floor(Math.random() * chars.length)];
  14. }
  15. return result;
  16. };
  17. export interface TreeItemType {
  18. children?: TreeItemType[];
  19. [key: string]: any;
  20. }
  21. //获取树结构指定的值集合
  22. export const getValsFromTree = (data: TreeItemType[], key: string) => {
  23. let result: any[] = [];
  24. function looper(data: TreeItemType[], key: string) {
  25. data.forEach((t) => {
  26. if (t[key]) {
  27. result.push(t[key]);
  28. }
  29. if (t.children && t.children.length > 0) {
  30. looper(t.children, key);
  31. }
  32. });
  33. }
  34. looper(data, key);
  35. return result;
  36. };
  37. export const searchTree = (treeData: TreeItemType[]) => {};