import type { App } from 'vue'; /** * 对象深克隆 * @param obj 源对象 * @returns 克隆后的对象 */ export function deepClone(obj: EmptyObjectType) { let newObj: EmptyObjectType; try { newObj = obj.push ? [] : {}; } catch (error) { newObj = {}; } for (let attr in obj) { if (obj[attr] && typeof obj[attr] === 'object') { newObj[attr] = deepClone(obj[attr]); } else { newObj[attr] = obj[attr]; } } return newObj; } /** * 判断数组对象中所有属性是否为空,为空则删除当前行对象 * @description @感谢大黄 * @param list 数组对象 * @returns 删除空值后的数组对象 */ export function handleEmpty(list: EmptyArrayType) { const arr = []; for (const i in list) { const d = []; for (const j in list[i]) { d.push(list[i][j]); } const leng = d.filter((item) => item === '').length; if (leng !== d.length) { arr.push(list[i]); } } return arr; } export function getDictLabel(arr: RowDicDataType[], val:string) { if(arr.length) { const obj = arr.find(item => item.dictValue == val) if(obj) return obj.dictLabel return val } return val } /** * 防抖函数 * @param func 要执行的函数 * @param delay 延迟时间(毫秒) * @returns 防抖后的函数 */ export function debounce(func: Function, delay: number) { let timer: number | null = null return (...args: any[]) => { if (timer) { window.clearTimeout(timer) } timer = window.setTimeout(() => { func(...args) timer = null }, delay) } } /** * 统一批量导出 * @method elSvg 导出全局注册 element plus svg 图标 * @method useTitle 设置浏览器标题国际化 * @method setTagsViewNameI18n 设置 自定义 tagsView 名称、 自定义 tagsView 名称国际化 * @method lazyImg 图片懒加载 * @method globalComponentSize() element plus 全局组件大小 * @method deepClone 对象深克隆 * @method isMobile 判断是否是移动端 * @method handleEmpty 判断数组对象中所有属性是否为空,为空则删除当前行对象 * @method handleOpenLink 打开外部链接 * @method debounce 防抖函数 */ const other = { deepClone: (obj: EmptyObjectType) => { return deepClone(obj); }, handleEmpty: (list: EmptyArrayType) => { return handleEmpty(list); }, getDictLabel: (arr: RowDicDataType[], val:string) => { return getDictLabel(arr, val) }, debounce: (func: Function, delay: number) => { return debounce(func, delay) } }; // 统一批量导出 export default other;