tableUtil.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * 获取操作列最大宽度
  3. * @returns
  4. */
  5. export function getOperatorWidth() {
  6. // 默认宽度
  7. let width = 100
  8. // 内间距
  9. let paddingSpacing = 5
  10. // 外边距
  11. let margin = 20;
  12. const operatorColumn = document.getElementsByClassName('optionDiv')
  13. // 如果节点数量大于0-循环这个节点,
  14. if (operatorColumn.length > 0) {
  15. let buttonCount = 0;
  16. for (let i = 0; i < operatorColumn.length; i++) {
  17. // 最宽的宽度
  18. width = width > operatorColumn[i].offsetWidth ? width : operatorColumn[i].offsetWidth;
  19. // 计算 <el-button> 标签的数量
  20. const buttons = operatorColumn[i].getElementsByClassName('el-button');
  21. buttonCount = buttons.length;
  22. buttonCount = buttonCount > buttons.length ? buttonCount : buttons.length;
  23. }
  24. // 如果按钮数量大于2,宽度要加上边距*(按钮数量-1)
  25. if (buttonCount > 2) {
  26. width += (paddingSpacing * (buttonCount - 1))
  27. }
  28. width += margin;
  29. }
  30. return width
  31. }