vue中用的,正常调用去掉export即可,默认为32位,大写字母+数字
export function getRandomString(length = 32) {
let arr = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"], num = "";
for (let i = 0; i < length; i++) {
num += arr[parseInt(Math.random() * 36)];
}
return num;
}
顺便发个生成订单号的:(大小写、数字,去掉易混淆字符)
/*生成32位随机流水号*/
/*默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1*/
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
var maxPos = $chars.length;
var pwd = '';
for (i = 0; i < 32; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}