'use strict'; /** * * * @author Zhong * @date 2019/11/12 * @version */ ((factory) => { if (typeof module !== 'undefined') { module.exports = factory(); } else { window.commonUtil = factory(); } })(() => { function isDef(val) { return typeof val !== 'undefined' && val !== null; } function isEmptyVal(val) { return val === null || val === undefined || val === ''; } // 将树数据排序好 function getSortedTreeData(rootID, items) { return sortSameDedth(rootID, items).reverse(); function sortSameDedth(parentID, items) { const sameDepthItems = items.filter(item => item.ParentID === parentID); if (!sameDepthItems.length) { return []; } const NextIDMapping = {}; sameDepthItems.forEach(item => NextIDMapping[item.NextSiblingID] = item); let curItem = sameDepthItems.length > 1 ? sameDepthItems.find(item => item.NextSiblingID === -1) : sameDepthItems[0]; const sorted = []; while (curItem) { sorted.push(...sortSameDedth(curItem.ID, items)); sorted.push(curItem); curItem = NextIDMapping[curItem.ID] || null; } return sorted; } } return { isDef, isEmptyVal, getSortedTreeData }; });