|
|
@ -60,3 +60,40 @@ export function praseStrEmpty (str) { |
|
|
|
} |
|
|
|
return str |
|
|
|
} |
|
|
|
|
|
|
|
// 表格列宽自适应
|
|
|
|
export function columnWidth (el) { |
|
|
|
let widthList = []; |
|
|
|
let thWidthList = []; |
|
|
|
// 计算表头宽度
|
|
|
|
el.querySelectorAll('.has-gutter tr').forEach((tr) => { |
|
|
|
tr.querySelectorAll('th').forEach((th, i) => { |
|
|
|
console.log(th.lastChild.innerText, th.lastChild.innerText.length*16+20); |
|
|
|
if(th.lastChild.innerText && th.lastChild.innerText.length){ |
|
|
|
if(thWidthList[i] && thWidthList[i].push){ |
|
|
|
thWidthList[i].push(th.lastChild.innerText.length*16+20); |
|
|
|
}else{ |
|
|
|
thWidthList[i]=[]; |
|
|
|
thWidthList[i].push(th.lastChild.innerText.length*16+20); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}) |
|
|
|
// 计算内容宽度
|
|
|
|
el.querySelectorAll('.el-table__body tr').forEach((tr) => { |
|
|
|
tr.querySelectorAll('td').forEach((td, i) => { |
|
|
|
if(td.lastChild.innerText && td.lastChild.innerText.length){ |
|
|
|
if(widthList[i] && widthList[i].push){ |
|
|
|
widthList[i].push(td.lastChild.innerText.length*14+20); |
|
|
|
widthList[i].push(thWidthList[i]); |
|
|
|
}else{ |
|
|
|
widthList[i]=[]; |
|
|
|
widthList[i].push(td.lastChild.innerText.length*14+20); |
|
|
|
widthList[i].push(thWidthList[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
console.log(11111111111); |
|
|
|
return widthList.map(width => Math.max(...width)); |
|
|
|
} |