layout-clone.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import _ from 'lodash'
  2. export const CloneLayout = (data) => {
  3. if (data.type === 'grid') {
  4. let key = Math.random().toString(36).slice(-8)
  5. return {
  6. ...data,
  7. key,
  8. model: data.type + '_' + key,
  9. columns: data.columns.map (item => {
  10. return {
  11. ...item,
  12. list: item.list.map(colItem => {
  13. return CloneLayout(colItem)
  14. })
  15. }
  16. })
  17. }
  18. } else if (data.type === 'tabs') {
  19. let key = Math.random().toString(36).slice(-8)
  20. return {
  21. ...data,
  22. key,
  23. model: data.type + '_' + key,
  24. tabs: data.tabs.map (item => {
  25. return {
  26. ...item,
  27. list: item.list.map (tabItem => {
  28. return CloneLayout(tabItem)
  29. })
  30. }
  31. })
  32. }
  33. } else if (data.type === 'table') {
  34. let key = Math.random().toString(36).slice(-8)
  35. return {
  36. ...data,
  37. key,
  38. model: data.type + '_' + key,
  39. tableColumns: data.tableColumns.map (item => {
  40. return CloneLayout(item)
  41. })
  42. }
  43. } else {
  44. let key = Math.random().toString(36).slice(-8)
  45. return {
  46. ...data,
  47. key,
  48. model: data.type + '_' + key,
  49. }
  50. }
  51. }