function getAdaptionWidth(prop, tableData) {
//接收两个参数,prop为列的属性值,tableData为表格数据源
prop = prop + ''
if(!Array.isArray(tableData) || tableData.length === 0) {
return
}
//判断传递的数据是否可用
if(!prop || prop.length || prop.length === 0 || prop === undefined || prop === null) {
return
}
//获取该列中最长的数据
let index = 0
let columnContent = ''
for(let i = 0; i < tableData.length; i++) {
if(tableData[i][prop] === null) {
continue
}
const now_text = tableData[i][prop] + ''
const max_text = tableData[index][prop] + ''
if(now_text.length > max_text.length) {
index = i
}
}
columnContent = tableData[index[prop]]
let coulmnWidth = 0
if(columnContent === null || columnContent === undefined) {
columnContent = ""
}
for(const char of columnContent) {
if((char >= 'A' && char <= 'Z') || (char >= 'a' && char <= 'z')) {
coulmnWidth += 10
}else if(char >= '\u4e00' && char <= '\u9fa5') {
coulmnWidth += 20
}else {
coulmnWidth += 10
}
}
if(coulmnWidth < 85) {
coulmnWidth = 86
}
if(coulmnWidth > 200) {
coulmnWidth = 200
}
return coulmnWidth + 'px'
}