博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ionic-与时间有关的故事-localecompare()
阅读量:2494 次
发布时间:2019-05-11

本文共 5738 字,大约阅读时间需要 19 分钟。

  今天小咸儿想来分享一个有管时间的故事:

  这个故事发生在很久很久以前,大概十月份,主题思想就是消费,所以需要金钱-积分,成果-排名,主人公-小咸儿。

  背景:ionic前端页面

  道具:时间转换的方法、localeCompare()方法

  角色:小咸儿、时间、积分

  主线:获取当前时间,判断是否第一次查看排名,若是则花费积分查看,若否可免费查看

  故事内容:

  时间:今天是什么时候了,该如何知道我的面目呢?我需要一面镜子Date()。

  旁白:镜子上场……

this.newLeave = new Date();

  时间:魔镜魔镜,谁是这个世界上最美丽的人?

  魔镜[Date()]:嗯,现在说实话都有风险了,不是有美颜相机么?借来一用 。

this.converDateTime(this.newLeave);// 转成标准的时间格式 YYYY-MM-DD  HH:mm:ssconverDateTime(newLeave) { 	let datetime = new Date(newLeave);	let year = datetime.getFullYear();	let month = datetime.getMonth();	let date = datetime.getDate();	this.dateresult = year +	'-' +	((month + 1) >= 10 ? (month + 1) : '0' + (month + 1)) +	'-' +	((date) < 10 ? '0' + date : date)	return this.dateresult;}

  时间(dateresult):我看起来很美啊!符合大众的审美标准,值得夸奖!!赞,我就不走了,永葆我的青春美貌(localstorage.setItem()方法)。

  旁白:日复一日,突然小咸儿要去看现在的时间和以前的时间,谁更漂亮

  小咸儿:之前的时间我见过啦,但是现在时间还有见过,那么谁更漂亮呢?赶紧比较一下,来成全我的爱美人之心。

let resdate = this.dateresult.localeCompare(date);

  旁白:这个localeCompare()是什么人?敢如此大胆,竞评价两个女人!!!!

  localeCompare():我是一个公平的人,生来就是为了比较的,我手中握有本地特定的顺序规则之秤,主要就是利用本地特定顺序规则来进行比较两个人(字符串)。如果相等的话,则输入0,表示势均力敌;如果不相等则返回大于1或者小于1,来表示强者与弱者。所以我还是一个正直的人。

  小咸儿:哈哈哈哈,时间果然上当了,这就是我最终的目的,我已经盗取了localecompare()的最终结果,下面就能利用这个结果来达到我盈利的目的了。果然一夜暴富。

  旁白:从此小咸儿过上了幸福快乐的一生……

  使用金钱(积分)购买查看排名的机会:

gotoXrxDepartment() {    let date = localStorage.getItem('date');    // 比较当前时间与localstorage中的时间戳    // let resdate = this.dateresult.localeCompare(date);    let resdate = this.dateresult.localeCompare(date);    // 判断当前时间是否与localstorage中的时间戳一致,若一致则返回0    if(resdate==0){      if(this.count==0){        this.getIntegral=localStorage.getItem('userIntegral');        if(this.getIntegral<5){          const alert = this.alertCtrl.create({            title:'',            subTitle:"积分不足,快去赚取积分吧",            buttons:['我已了解~']          });          alert.present();        }else{          const alert = this.alertCtrl.create({            title:'是否购买查看排名机会?',            message:'将花费您5积分!',            buttons: [              {                text:'取消',                role:'cancel',                handler:() => {                  console.log('Cancel clicked');                }              },              {                text:'购买',                handler:() =>{                  let dataUrl = 'http://192.168.22.126/kernel-web/AddIntegral/create';                  this.creator = localStorage.getItem('userName');                  this.operator = localStorage.getItem('userName');                  this.loginID = localStorage.getItem('userId');                  let body = JSON.stringify({                    id:"",                    givingUserId: "givingUser_game",                    idInfo: [this.loginID],                    integral : -5,                    pluginId: "look_rank",                    primaryId: "0001",                    reason: "购买查看排名机会",                    typeKey: "buyRank",                    userId: this.loginID,                    creator:this.creator,                    operator: this.operator,                    remark: ""                  });                                    this.http.post(dataUrl,body).subscribe(                    res => {                      if(res.json().code=="0000"){                        this.navCtrl.push(XrxDepartmentPage, {                          flag: '部门'                        });                        this.count++;                      }                    }                  )                }              }            ]          });          alert.present();        }      }else{        this.navCtrl.push(XrxDepartmentPage, {          flag: '部门'        });      }    }else{      // 当日期不一致时,将计数count置为0      this.count=0;      if(this.count==0){        this.getIntegral=localStorage.getItem('userIntegral');        if(this.getIntegral<5){          const alert = this.alertCtrl.create({            title:'',            subTitle:"积分不足,快去赚取积分吧",            buttons:['我已了解~']          });          alert.present();        }else{          const alert = this.alertCtrl.create({            title:'是否购买查看排名机会?',            message:'将花费您5积分!',            buttons: [              {                text:'取消',                role:'cancel',                handler:() => {                  console.log('Cancel clicked');                }              },              {                text:'购买',                handler:() =>{                  let dataUrl = 'http://192.168.22.126/kernel-web/AddIntegral/create';                  this.creator = localStorage.getItem('userName');                  this.operator = localStorage.getItem('userName');                  this.loginID = localStorage.getItem('userId');                  let body = JSON.stringify({                    id:"",                    givingUserId: "givingUser_game",                    idInfo: [this.loginID],                    integral : -5,                    pluginId: "look_rank",                    primaryId: "0001",                    reason: "购买查看排名机会",                    typeKey: "buyRank",                    userId: this.loginID,                    creator:this.creator,                    operator: this.operator,                    remark: ""                  });                                    this.http.post(dataUrl,body).subscribe(                    res => {                      if(res.json().code=="0000"){                        this.navCtrl.push(XrxDepartmentPage, {                          flag: '部门'                        });                        this.count++;                      }                    }                  )                }              }            ]          });          alert.present();        }      }else{        this.navCtrl.push(XrxDepartmentPage, {          flag: '部门'        });      }    }  }

转载地址:http://gderb.baihongyu.com/

你可能感兴趣的文章
python3安装scrapy
查看>>
python正则表达式入门一
查看>>
python正则表达式入门二
查看>>
scrapy运行
查看>>
XPATH入门
查看>>
python爬虫 CSS选择器
查看>>
正常关闭java程序
查看>>
查看linux核心数
查看>>
数据结构与算法三: 数组
查看>>
Activiti工作流会签二 启动流程
查看>>
Activiti工作流会签三 撤销,审批,驳回
查看>>
Oauth2方式实现单点登录
查看>>
CountDownLatch源码解析加流程图详解--AQS类注释翻译
查看>>
ES相关度评分
查看>>
我们一起做一个可以商用的springboot脚手架
查看>>
idea在搭建ssm框架时mybatis整合问题 无法找到mapper
查看>>
java设计基本原则----单一职责原则
查看>>
HashMap的实现
查看>>
互斥锁 synchronized分析
查看>>
java等待-通知机制 synchronized和waity()的使用实践
查看>>