
function genUserId(len) {
	len = len || 32;
	var t = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefhjkmnpqrstuvwxyz0123456789",
	a = t.length,
	n = "";
	for (i = 0; i < len; i++) n += t.charAt(Math.floor(Math.random() * a));
	return n
}

//随机生成办件流水批次号
function genRanNo(len){
	var num = "";
	len = len || 5;
	var date = new Date();
	for (var i = 0; i < len; i++) {
		num += Math.floor(Math.random() * 10);
	}
    return date.getFullYear().toString() + (date.getMonth() + 1).toString() + 
      date.getDate().toString() + date.getHours().toString() + date.getMinutes().toString() 
     + date.getSeconds().toString() + date.getMilliseconds().toString() + num; 
}

//获取当天日期
function getNowDate(){
	var date = new Date();
    return date.getFullYear() +'年' + (date.getMonth() + 1) + '月' + date.getDate() + '日'; 
}

//预审资源文件转base64
function getBase64(imgUrl) {
	var base64;
	window.URL = window.URL || window.webkitURL;
	var xhr = new XMLHttpRequest();
	xhr.open("get", imgUrl, true);
	xhr.responseType = "blob";
	xhr.onload = function(){
		if(this.status == 200){
			//得到一个blob对象
			var blob = this.response;
			// 至关重要
			let oFileReader = new FileReader();
			oFileReader.onloadend = function(e){
				// 此处拿到的已经是base64的图片了,可以赋值做相应的处理
				base64 = e.target.result;
				base64 = base64.replace(/^data:\w+\/\w+;base64,/, "");
			}
			oFileReader.readAsDataURL(blob);
		}
	}
	xhr.send();
	return base64;
}

module.exports = {
  genUserId,
  genRanNo,
  getNowDate,
	getBase64
}








