/** * @public * @param {string} type * @return {string} */ export function getUID(type, list) { // if (list && list.length) { let name = ''; if (type == 'T') { name = list.length ? Number(list[list.length - 1].code.replace('T', '')) + 1 : list.length + 1; } else { name = Math.floor((Math.random() * 100000) + 1); } const code = [(type || ''), name].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 || ''), Math.floor((Math.random() * 100000) + 1)].join(''); // } // use Math.random to make id as unique as possible. }