tools.CwkibfPM.js 5.6 KB

1
  1. import{p as t,q as e,x as n,s as r,ah as a}from"./index-ESTWQ1DK.js";const o={urlAddVer(e){let n=e;const r=t().appVersion;return-1!==n.indexOf("_v=")||(-1!==n.indexOf("?")?n+="&_v="+r:n+="?_v="+r,console.log("[urlAddVer] newUrl",n)),n},appAction(t,r=""){console.log("appAction",t),-1!==t.indexOf("http")?window.location.href=this.urlAddVer(t):"reload"==t?window.location.reload():"uni.navigateTo"==r?e({url:this.urlAddVer(t)}):"uni.switchTab"==r?n({url:this.urlAddVer(t)}):window.location.href=t},fmtMcTime(t){var e=new Date(1e3*t);return(e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1)+"-"+((e.getDate()<10?"0"+e.getDate():e.getDate())+" ")+((e.getHours()<10?"0"+e.getHours():e.getHours())+":")+(e.getMinutes()<10?"0"+e.getMinutes():e.getMinutes())},getActtime(t,e){return this.fmtMcTime(t)+" 至 "+this.fmtMcTime(e)},fmtMcTime2(t,e){const n=new Date(1e3*t),r=new Date(1e3*e),a=n.getFullYear(),o=r.getFullYear(),i=n.getMonth()+1,s=r.getMonth()+1,u=n.getDate(),l=r.getDate();var g="";o!=a?g+=o+"."+s+"."+l:s!=i?g+=s+"."+l:l!=u&&(g+=l);var c=a+"."+i+"."+u;return g.length>0&&(c+="-"+g),c},fmtMcTime3(t,e){const n=new Date(1e3*t),r=new Date(1e3*e),a=n.getFullYear(),o=r.getFullYear(),i=n.getMonth()+1,s=r.getMonth()+1,u=n.getDate(),l=r.getDate();var g="",c=a+"年"+i+"月"+u+"日";return(g+=o!=a?o+"年"+s+"月"+l+"日":s+"月"+l+"日").length>0&&(c+=" 至 "+g),c},checkMcState(t,e){let n=0;if(t>0&&e>0){const r=Date.now()/1e3,a=e-r;t-r>0?(console.log("活动未开始"),n=0):a>0?(console.log("活动进行中"),n=1):(console.log("活动已结束"),n=2)}return n},loadCssCode(t,e="css-custom"){this.removeCssCode(e);var n=window.document.createElement("style");n.type="text/css",n.id=e,n.styleSheet?n.styleSheet.cssText=t:n.appendChild(document.createTextNode(t)),document.getElementsByTagName("head")[0].appendChild(n)},removeCssCode(t="css-custom"){var e=document.getElementById(t);null!=e&&(document.getElementsByTagName("head")[0].removeChild(e),console.log(t+" 已移除"))},getSelectedText(t,e){const n=t.find((t=>t.value===e));return n?n.text:""},objectToQueryString:t=>Object.keys(t).map((e=>e+"="+t[e])).join("&"),convertSecondsToDHM(t){var e=Math.floor(t/86400),n=Math.floor(t%86400/3600),r=Math.floor(t%86400%3600/60);return e>0?`${e}天${n.toString().padStart(2,"0")}小时`:`${n.toString().padStart(2,"0")}小时${r.toString().padStart(2,"0")}分钟`},convertSecondsToHMS(t,e=0){if(!(t>0))return"--";var n=Math.floor(t/3600),r=Math.floor(t%3600/60),a=Math.floor(t%60);return 0==e?`${n.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}:${a.toString().padStart(2,"0")}`:1==e?n>0?`${n}h${r}′${a.toString().padStart(2,"0")}″`:`${r}′${a.toString().padStart(2,"0")}″`:2==e?n>0?`${60*n+r}′${a.toString().padStart(2,"0")}″`:`${r}′${a.toString().padStart(2,"0")}″`:void 0},calStrLen(t){for(var e=0,n=0;n<t.length;n++){var r=t.charCodeAt(n);r>=0&&r<=128?e++:e+=2}return e},unique(t,e){for(var n={},r=[],a=0;a<t.length;a++)n[t[a][e]]||(n[t[a][e]]=1,r.push(t[a]));return r},repalceHtml:t=>t.replace(/<\/?.+?>/g,"").replace(/ /g,""),isSfz(t){if(""!==t)return/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|31)|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$/.test(t)||r({title:"身份证号格式不正确!",icon:"none"}),!1;r({title:"请输入身份证号",icon:"none"})},isPhone:t=>!(!/^((1[3456789][0-9]{1})+\d{8})$/.test(t)||""===t)||(r({title:"手机号格式不正确",icon:"none"}),!1),isEmail:t=>-1!=t.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/),getSuiji(){var t=Max-Min,e=Math.random();return Min+Math.round(e*t)},getDateDiff(t){var e=36e5,n=24*e,r=(new Date).getTime()-t;if(!(r<0)){var a=r/31536e6,o=r/2592e6,i=r/(7*n),s=r/n,u=r/e,l=r/6e4;return a>=1&&(result=parseInt(a)+"年前"),result=o>=1?parseInt(o)+"月前":i>=1?parseInt(i)+"周前":s>=1?parseInt(s)+"天前":u>=1?parseInt(u)+"小时前":l>=1?parseInt(l)+"分钟前":"刚刚",result}},timestampToTime(t,e){var n=null,r=(n=t>0?new Date(t):new Date).getFullYear(),a=n.getMonth()+1<10?"0"+(n.getMonth()+1):n.getMonth()+1,o=n.getDate()<10?"0"+n.getDate():n.getDate(),i=n.getHours()<10?"0"+n.getHours():n.getHours(),s=n.getMinutes()<10?"0"+n.getMinutes():n.getMinutes(),u=n.getSeconds()<10?"0"+n.getSeconds():n.getSeconds();return 1==e?r+"-"+a+"-"+o:2==e?r+"年"+a+"月"+o+"日":3==e?r+"-"+a+"-"+o+" "+i+":"+s:r+"-"+a+"-"+o+" "+i+":"+s+":"+u},isHanzi:t=>new RegExp("\\p{Unified_Ideograph}","ug").test(t),isStringAndNumber:t=>new RegExp(/^[0-9A-Za-z]+$/).test(t),listSort(t){arr3.sort((function(t,e){return t-e}))},listObjectSort:t=>(t.sort((function(t,e){return t.id-e.id})),t),isEqualsIgnorecase:function(t,e){return t.toUpperCase()==e.toUpperCase()},isNum:function(t){return null!=t&&t.length>0&&0==isNaN(t)},isChine:function(t){return!/^([u4E00-u9FA5]|[uFE30-uFFA0])*$/.test(t)},tmCheckImage:function(t){return/(gif|jpg|jpeg|png|GIF|JPG|PNG)$/gi.test(t)},tmCheckVideo:function(t){return/(mp4|mp3|flv|wav)$/gi.test(t)},trim:function(t){String.prototype.trim=function(){return t.replace(/(^\s*)|(\s*$)/g,"")}},isPassword(t){if(""!==t)return!!/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$)^.{8,16}$/.test(t)||(r({title:"至少6位,包括大小写字母、数字、特殊字符",icon:"none"}),!1);r({title:"请输入密码",icon:"none"})},noPassByMobile(t){if(null!=t&&null!=t){return t.replace(/(\d{3})\d*(\d{4})/,"$1****$2")}return""},Rad:t=>t*Math.PI/180,getMapDistance(t,e,n,r){n=n||0,e=e||0,r=r||0;var a=(t=t||0)*Math.PI/180,o=e*Math.PI/180,i=a-o,s=n*Math.PI/180-r*Math.PI/180,u=12756274*Math.asin(Math.sqrt(Math.pow(Math.sin(i/2),2)+Math.cos(a)*Math.cos(o)*Math.pow(Math.sin(s/2),2)));return Math.round(u)/1e3},yulanImg(t){a({urls:[t]})}};export{o as t};