计算的实际应该是字符的宽度,Unicode换算出后中文算两个宽度
// Get string width
function getStringWidth(val) {
let len = 0;
for (let i = 0; i < val.length; i++) {
let length = val.charCodeAt(i);
if( length >= 0 && length <= 128 ) {
len += 1;
} else {
len += 2;
}
}
return len;
}