mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 00:34:28 +08:00
optimize display style when text is too long
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
export default function (value, maxLength) {
|
||||
let length = 0;
|
||||
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const c = value.charCodeAt(i);
|
||||
|
||||
if ((c >= 0x0001 && c <= 0x007e) || (0xff60 <= c && c <= 0xff9f)) {
|
||||
length++;
|
||||
} else {
|
||||
length += 2;
|
||||
}
|
||||
}
|
||||
|
||||
if (length <= maxLength || maxLength <= 3) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.substr(0, maxLength - 3) + '...';
|
||||
}
|
||||
Reference in New Issue
Block a user