diff --git a/utils/index.js b/utils/index.js index 28feac5..ba26030 100644 --- a/utils/index.js +++ b/utils/index.js @@ -1,5 +1,17 @@ import mqtt from './mqtt.js' import store from '../store/index.js' + + +/** + * 文本过长截取 + * @param {string} value 文本内容 + * @param {Number} length 设定长度 + * @returns {string} 截取完的内容最后加省略号 + */ +export function truncate(value, length = 5) { + if (!value) return ''; + return value.length > length ? value.slice(0, length) + '...' : value; +} /** * Parse the time to string * @param {(Object|string|number)} time