import {env} from 'mutants-microfx'; const {constant,platform} = env; export default class tools { static isJsonStr(jsonStr:string):boolean{ if(this.isNull(jsonStr)){ return false; } if(jsonStr.indexOf('{')==0 || jsonStr.indexOf('[')==0){ return true; } } //去空函数 static trim(str:string):string { let localstr = new String(str); let pattern = /^\s+|\s+$/g; localstr = localstr.replace(pattern, ""); return localstr.toString(); } //判断是否为空 static isNull(s:string):boolean{ if (s == undefined || (this.trim(s) + "123" == "123")) { return true; } return false; } //判断数组是否包含 static arrayContains(array:Array,element:Object):boolean{ if(!array){ return false; } for (var i = 0; i < array.length; i++) { if (array[i] == element) { return true; } } return false; } //获取location search参数 static GetQueryString(locationSearch:string,name:string):string{ var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i"); var r = locationSearch.substr(1).match(reg); if (r!=null) return (r[2]); return null; } /** * 获取当前时间 * @return 返回时间类型 yyyy-MM-dd HH:mm:ss */ static sysTime():string{ const myDate = new Date(); const year = myDate.getFullYear(); const month = myDate.getMonth()+1; const date = myDate.getDate(); const h = myDate.getHours(); const m = myDate.getMinutes(); const s = myDate.getSeconds(); const now = year + '-' + this.getMakeZero(month) + "-" + this.getMakeZero(date) + " " + this.getMakeZero(h) + ':' + this.getMakeZero(m) + ":" + this.getMakeZero(s); return now; } /** * 时间补0 * * @return 返回时间类型 yyyy-MM-dd HH:mm:ss */ static getMakeZero(s):string{ return s < 10 ? '0' + s : s; } static isApp():boolean{ return platform == constant.platform.yonyou || platform == constant.platform.chanjet; } }