当前位置: 首页 > news >正文

组成原理毕业设计代做网站推荐四川长昕建设工程有限公司网站

组成原理毕业设计代做网站推荐,四川长昕建设工程有限公司网站,网站建设服务便宜,网站保持排名随着前端业务越来越复杂#xff0c;自定义表单数据量比较大#xff0c;每条数据的id生成则至关重要。想到前期IOS中实现的雪花算法ID#xff0c;照着其实现JS版本#xff0c;供大家学习参考。 一、库的建立引入 在你项目中创建一个snowFlake.js的文件#xff1a;拷贝以下…随着前端业务越来越复杂自定义表单数据量比较大每条数据的id生成则至关重要。想到前期IOS中实现的雪花算法ID照着其实现JS版本供大家学习参考。 一、库的建立引入 在你项目中创建一个snowFlake.js的文件拷贝以下内容进去。 import bigInt from big-integerexport default class SnowFlake {constructor(_workerId1, _dataCenterId1, _sequence0) {// 开始时间截 (2012-01-01)这个可以设置开始使⽤该系统的时间可往后使⽤69年this.twepoch 1325347200000;this.workerIdBits 5;this.dataCenterIdBits 5;this.maxWorkerId -1 ^ (-1 this.workerIdBits) //值为31this.maxDataCenterId -1 ^ (-1 this.dataCenterIdBits) //值为31this.sequenceBits 12;this.workerIdShift this.sequenceBits; //值为12this.dataCenterIdShift this.sequenceBits this.workerIdBits; //17this.timestampLeftShift this.sequenceBits this.workerIdBits this.dataCenterIdBits;//22this.sequenceMask -1 ^ (-1 this.sequenceBits);//4095this.lastTimestamp -1;//设置默认值this.workdId 1;this.dataCenterId 1;this.sequence 0;if (this.workdId this.maxDataCenterId || this.workdId 0) {throw new Error(config.worker_id must max than 0 and small than maxWrokerId-[ this.maxWrokerId ]);}if (this.dataCenterId this.maxDataCenterId || this.dataCenterId 0) {throw new Error(config.data_center_id must max than 0 and small than maxDataCenterId-[ this.maxDataCenterId ]);}this.workerId _workerId;this.dataCenterId _dataCenterId;this.sequence _sequence;}tilNextMillis(lastTimestamp) {var timestamp this.timeGen();while (timestamp lastTimestamp) {timestamp this.timeGen();}return timestamp;}timeGen() {return Date.now();}nextId() {var timestamp this.timeGen();if (timestamp this.lastTimestamp) {throw new Error(Clock moved backwards. Refusing to generate id for (this.lastTimestamp - timestamp));}if (this.lastTimestamp timestamp) {this.sequence (this.sequence 1) this.sequenceMask;if (this.sequence 0) {timestamp this.tilNextMillis(this.lastTimestamp);}else {this.sequence 0;}}this.lastTimestamp timestamp;var shiftNum (this.dataCenterId this.dataCenterIdShift) | (this.workerId this.workerIdShift) | this.sequence; // dataCenterId:1,workerId:1,sequence:0 shiftNum:135168var nfirst new bigInt(String(timestamp - this.twepoch), 10);nfirst nfirst.shiftLeft(this.timestampLeftShift);var nnextId nfirst.or(new bigInt(String(shiftNum), 10)).toString(10);return nnextId;}/*** 获取更安全的随机ID(解决连续输出id会出现重复的问题)* 尽可能的避免重复* param {int} repeatRate 重复率默认值100(注释:最⼩是1,最⼤值越⼤,重复的概率越低,不过还需要考虑性能的问题,并不是越⼤越好,只是相对⽽⾔) */flakeId(repeatRate 1) {let arr []let ranNum Math.floor(window.crypto.getRandomValues(new Uint8Array(1)) * 0.001 * repeatRate)for (let index 0; index repeatRate; index) {arr[index] this.nextId()}return arr[ranNum]} }const snowflake new SnowFlake();export function snowFlakeId(val) {return snowflake.flakeId(); }因为生成的id比较大普通的int类型无法保持精度故而引入了big-integer这个类库。完成以上粘贴事宜后进入你的项目安装依赖 如果你使用的是npm来管理依赖库则运行 npm install big-integer --save如果你使用的是yarn(较旧版本)来管理依赖库则运行 yarn install big-integer --save 如果你使用的是yarn(新版本)来管理依赖则运行 yarn add big-integer --save 后面为什么跟着--save自行查询文档这里不做说明。 二、库的使用 我项目使用生成的页面比较多为了使用方便我直接将添加到Vue的扩展方法中。 三、运行验证
http://www.zqtcl.cn/news/952810/

相关文章:

  • 重庆璧山网站制作公司哪家专业商城网站建设 优帮云
  • 双语网站建设费用安徽省芜湖建设定额网站
  • 常州市城乡建设局网站wordpress 阿里云cdn
  • 福州制作网站设计哪里比较好百度网址大全官方网站
  • 一般做美食网站的产品需求我想做个网站
  • 成品网站制作公司应用公园是免费的吗
  • 做毕业网站的流程网站建设价格一览表
  • 企业服务网站开发做网站怎样建立服务器
  • 电子商务他们的代表网站360免费wifi官网
  • 网站后端开发软件cc域名做门户网站
  • 保定设计网站超云建站
  • 建筑工程网官网入口优化网站关键词排名软件
  • 企业网站功能怎么设计wordpress文章图片轮播
  • 网站后台登陆验证码不对阳江房产网楼市数据
  • 营销型网站建设遨龙仙居住房和城乡建设规划局网站
  • 中国做视频网站有哪些淘宝做详情页代码网站
  • 网站开发一般多钱在网站设计公司上班好吗
  • 餐饮连锁企业网站建设方案北京软件研发公司
  • 外国网站架构新闻稿
  • 营销网站建设企划案例友情链接怎么添加
  • seo网站搜索优化目前好的推广平台
  • 快速搭建网站页面黄页88网免费发布信息
  • 做网站能赚吗网址大全查询ip地址
  • html5网站正在建设中商城网站系统
  • 室内设计网课北京网站优化前景
  • 北京 网站建设 知乎上海公司买新能源车
  • 成都微网站wordpress 购买
  • 网站开发一般要用到哪些软件软件开发工程师机构
  • dj网站开发建设网站备案 换空间
  • 网站建设哪家最好网站开发怎么报价