1、判断当前时间到达某一指定时间
isOnTime () { let now = new Date() //当前时间 //如果传2022-02-22 14:15:00要转化成 2022/02/22 14:15:00 let startTime = '2022-05-26 24:00:00' // let startTime = '2022-05-13 14:00:00' let end = new Date(startTime.replace(/-/g,"/")) //对比时间 if(now.getTime() > end.getTime()){ //当前时间比指定时间大 this.arrivedTime = true; return this.arrivedTime; }else{ //小于指定时间 this.arrivedTime = false; return this.arrivedTime; } },
2、手机号加密
// 手机号加密 phonePass(phone) { const reg=/(\d{3})\d{4}(\d{4})/; //正则表达式 return phone.replace(reg, "$1****$2"); },
3、获取当前日期(年月日)
export const getCurrentDate = function() { const date = new Date(); const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); return `${year}${month}${day}`; };
4、获取url #中的参数
export const getUrlParam = function(name) { const parmsStr = window.location.search.substring(1); const parmsArr = parmsStr.split('&'); const parms = {}; for (let i = 0; i < parmsArr.length; i++) { parms[parmsArr[i].split('=')[0]] = parmsArr[i].split('=')[1]; } return parms[name]; };
5、删除url中的指定参数重新拼接路径
export const funcUrlDel = function(names) { try { console.log(window, "111111111dsfdsf") if (typeof names == "string") { names = [names]; } var loca = window.location; var obj = {}; var arr = loca.search.substring(1).split("&"); //获取参数转换为object for (var i = 0; i < arr.length; i++) { arr[i] = arr[i].split("="); obj[arr[i][0]] = arr[i][1]; } //删除指定参数 for (var i = 0; i < names.length; i++) { delete obj[names[i]]; } //重新拼接url var url = loca.origin + loca.pathname + "?" + JSON.stringify(obj) .replace(/[\"\{\}]/g, "") .replace(/\:/g, "=") .replace(/\,/g, "&") + loca.hash; console.log(url, "dsfdsf") return url; } catch (err) { console.log(err) } };