35b7decd49
- 概览与检索合并为单一概览页 - 类目/文档管理/入库整合为树形目录知识库页(Library),支持文档搜索 - 入库进度改为右侧 Drawer,支持任务详情、重试、删除 - 后端新增任务重试与删除接口
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
/**
|
|
* 截断文本,超过最大长度追加省略号
|
|
* @param {string} text
|
|
* @param {number} [maxLen=80]
|
|
* @returns {string}
|
|
*/
|
|
export function truncate(text, maxLen = 80) {
|
|
if (!text) return ''
|
|
const s = String(text)
|
|
return s.length > maxLen ? `${s.slice(0, maxLen)}…` : s
|
|
}
|
|
|
|
/**
|
|
* 格式化字节数为人类可读大小
|
|
* @param {number|null|undefined} bytes
|
|
* @returns {string}
|
|
*/
|
|
export function formatSize(bytes) {
|
|
if (bytes == null || bytes === '') return '-'
|
|
const n = Number(bytes)
|
|
if (Number.isNaN(n)) return '-'
|
|
if (n < 1024) return `${n} B`
|
|
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`
|
|
return `${(n / 1024 / 1024).toFixed(1)} MB`
|
|
}
|
|
|
|
/**
|
|
* 安全拼接类名
|
|
* @param {...(string | false | null | undefined)} args
|
|
* @returns {string}
|
|
*/
|
|
export function classnames(...args) {
|
|
return args.filter(Boolean).join(' ')
|
|
}
|
|
|
|
/**
|
|
* 防抖
|
|
* @param {Function} fn
|
|
* @param {number} [wait=300]
|
|
* @returns {Function}
|
|
*/
|
|
export function debounce(fn, wait = 300) {
|
|
let timer = null
|
|
return function debounced(...args) {
|
|
if (timer) {
|
|
clearTimeout(timer)
|
|
}
|
|
timer = setTimeout(() => {
|
|
fn.apply(this, args)
|
|
}, wait)
|
|
}
|
|
}
|