var base = 0; /** * @public * @param {string} type * @return {string} */ export function getUID(type, list) { if (list && list.length) { const code = [(type || ''), base++, Math.random().toFixed(5)].join('_'); let count = 0; for (let index = 0; index < list.length; index++) { count++; if (list[index].code == code) { this.getUID(type, list); return; } } if (count == list.length) { return code; } } else { return [(type || ''), base++, Math.random().toFixed(5)].join('_'); } // use Math.random to make id as unique as possible. }