自动生成id
第一种
/** * 获取UUID * @returns {string} */export function getUUID() { let len = 32 // 32长度 let radix = 16 // 16进制 let chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') let uuid = [] let i radix = radix || chars.length if (len) { for (i = 0; i < len; i++) { uuid[i] = chars[0 | Math.random() * radix] } } else { var r uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-' uuid[14] = '4' for (i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | Math.random() * 16 uuid[i] = chars[(i === 19) ? (r & 0x3) | 0x8 : r] } } } return uuid.join('').toLowerCase()}
第二种
function generateID(len, seed = '') { var idLen = len ? (len < 12 ? 12 : len) : 12 var idSeed = seed var randomSeed = 'ABCDEFGHIGKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz' var randomStr = '' while (randomStr.length < idLen) { randomStr += randomSeed.substr(Math.ceil(Math.random() * 62), 1) } return idSeed + randomStr}