JavaScript生成uuid

  • UUID概述
    UUID(Universally Unique Identifier)通用唯一标识符,在Java中使用居多,唯一的UUID可用于做数据库主键。在本次项目中涉及到批量上传文件(递归上传)功能,需要一个UUID来标识批量上传的每个文件,所以需要前端上传文件时,生成一个UUID。
  • 生成UUID
    要生成UUID一般最常用的方式即通过随机数+时间戳生成UUID,代码如下:
    tid(){
        var myDate = new Date();
        var uuid = myDate.getDay()+myDate.getHours()+myDate.getMinutes()+myDate.getMinutes()+myDate.getMilliseconds()+Math.round(Math.random()*10000);
        return uuid;
    }
    rid(){
        return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
    }
    uuid(){
        return (this.tid() +"_" + this.rid() +"_"+ this.rid() +"_"+ this.rid() );
    }
发布了58 篇原创文章 · 获赞 85 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/codezha/article/details/92810898