12345678910111213141516171819202122232425262728293031323334 |
- /**
- * 获取操作列最大宽度
- * @returns
- */
- export function getOperatorWidth() {
- // 默认宽度
- let width = 100
- // 内间距
- let paddingSpacing = 5
- // 外边距
- let margin = 20;
- const operatorColumn = document.getElementsByClassName('optionDiv')
- // 如果节点数量大于0-循环这个节点,
- if (operatorColumn.length > 0) {
- let buttonCount = 0;
- for (let i = 0; i < operatorColumn.length; i++) {
- // 最宽的宽度
- width = width > operatorColumn[i].offsetWidth ? width : operatorColumn[i].offsetWidth;
- // 计算 <el-button> 标签的数量
- const buttons = operatorColumn[i].getElementsByClassName('el-button');
- buttonCount = buttons.length;
- buttonCount = buttonCount > buttons.length ? buttonCount : buttons.length;
- }
- // 如果按钮数量大于2,宽度要加上边距*(按钮数量-1)
- if (buttonCount > 2) {
- width += (paddingSpacing * (buttonCount - 1))
- }
- width += margin;
- }
- return width
- }
|