util.js 666 B

123456789101112131415161718192021
  1. import { getFieldValue, isArray } from '@cip/utils/util'
  2. export const analyseData = (list = [], treeProps, count = 0, parentPath = []) => {
  3. return list.reduce((acc, item, index) => {
  4. const path = parentPath.concat(index)
  5. acc[count] = path
  6. count++
  7. const children = getFieldValue(item, treeProps.children)
  8. if (isArray(children)) {
  9. const indexed = analyseData(children, treeProps, count, path)
  10. acc = Object.assign(acc, indexed)
  11. count += Object.keys(indexed).length
  12. }
  13. return acc
  14. }, {})
  15. }
  16. export const getPropertyKeyByPath = (path, treeProps) => {
  17. const { children } = treeProps
  18. return path.join(`.${children}.`)
  19. }