fit.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. export const generateFitLayout = (values) => {
  2. const layouts = Array.isArray(values) ? values : Object.values(values)
  3. const needUpgrade = layouts.some(item => {
  4. const { component, w } = item.layout || item
  5. const minWidth20Components = [
  6. 'NumberCard',
  7. 'Ring',
  8. 'Notify',
  9. 'Top5',
  10. 'UnrecoveredAlarm',
  11. 'AccountHealth',
  12. 'UserInfo',
  13. 'ServerNumberDetail',
  14. ]
  15. const minWidth40Components = [
  16. 'VmHistoryCount',
  17. 'AlertsTrend',
  18. ]
  19. if (minWidth20Components.includes(component)) {
  20. return w < 10
  21. } else if (minWidth40Components.includes(component)) {
  22. return w < 40
  23. }
  24. })
  25. if (needUpgrade) {
  26. layouts.forEach(item => {
  27. if (item.layout) {
  28. item.layout.w *= 4
  29. item.layout.x *= 4
  30. if (item.component !== 'Quota') {
  31. item.layout.h *= 2
  32. item.layout.y *= 2
  33. }
  34. } else {
  35. item.w *= 4
  36. item.x *= 4
  37. if (item.component !== 'Quota') {
  38. item.h *= 2
  39. item.y *= 2
  40. }
  41. }
  42. })
  43. }
  44. return values
  45. }