前端 UUID生成
export const generateUUID = () => {let timestamp = new Date().getTime()let performanceNow = (typeof performance !== 'undefined' && performance.now && performance.now() * 1000) || 0return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {let random = Math.random() * 16if (timestamp > 0) {random = (timestamp + random) % 16 | 0timestamp = Math.floor(timestamp / 16)} else {random = (performanceNow + random) % 16 | 0performanceNow = Math.floor(performanceNow / 16)}return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)})
}
输了格式
UUID的长度
function guid(len = 32, firstU = true, radix = null) {const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')const uuid = []radix = radix || chars.lengthif (len) {for (let i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]} else {let ruuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'uuid[14] = '4'for (let i = 0; i < 36; i++) {if (!uuid[i]) {r = 0 | Math.random() * 16uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]}}}if (firstU) {uuid.shift()return `u${uuid.join('')}`}return uuid.join('')
}
#### 输了格式