2019-11-29 12:51:58 +08:00
|
|
|
var base = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @public
|
|
|
|
* @param {string} type
|
|
|
|
* @return {string}
|
|
|
|
*/
|
2019-12-06 10:31:19 +08:00
|
|
|
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('_');
|
|
|
|
}
|
2019-12-05 16:17:54 +08:00
|
|
|
// use Math.random to make id as unique as possible.
|
2019-11-29 12:51:58 +08:00
|
|
|
}
|