UNPKG

y-gtmi-ui

Version:

y-gtmi-ui 基于Element-plus二次封装基础组件文档

45 lines (43 loc) 1.06 kB
/** * 遍历children形式数据 * @param data 需要遍历的数据 * @param callback 回调 * @param childrenField children字段名 */ export function eachTreeData( data: any[], callback: Function, childrenField = 'children', parent: any = '' ) { if (data) { data.forEach((d, i) => { if ( callback && callback(d, i, parent) !== false && d[childrenField]?.length ) { eachTreeData(d[childrenField], callback, childrenField, d); } }); } } /** * 生成随机字符串 * @param length 长度 * @param radix 基数 */ export function uuid(length = 32, radix: any) { const num = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; let result = ''; for (let i = 0; i < length; i++) { result += num.charAt(Math.floor(Math.random() * (radix || num.length))); } return result; } /** * 获取屏幕宽度 */ export function screenWidth() { return document.documentElement.clientWidth || document.body.clientWidth; }