releaseTime: function(t) {
let time = t*1000
let diff = dayjs().diff(dayjs(time), 'second')
let diffTime = ''
if(diff <= 3600) {
diffTime = `${dayjs().diff(dayjs(time), 'minute')}分钟前`
}else if(3600 < diff && diff <= 3600*24) {
diffTime = `${dayjs().diff(dayjs(time), 'hour')}小时前`
}else if(3600*24 < diff && diff <= 3600*72) {
diffTime = `${dayjs().diff(dayjs(time), 'day')}天前`
}else {
diffTime = dayjs(time).format('YYYY-MM-DD')
}
return diffTime
},
//将以秒为单位的时间变成“00:00:00”格式的字符串
function getTimeStr(time) {
var h = Math.floor(time/3600);
var m = Math.floor(time%3600/60);
var s = Math.floor(time%60);
h = h>=10?h:"0"+h;
m = m>=10?m:"0"+m;
s = s>=10?s:"0"+s;
return h+":"+m+":"+s;
function getUrlParam(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null && r != 'null') {
return unescape(r[2]) == 'null' ? null : unescape(r[2]);
}
return null;
}
function redirectTo() {
let url = getUrlParam('redirect')?getUrlParam('redirect'):'/account/info'
window.location.replace(url)
}
const isNone = function (e) { //检查字段是否为空包括 ,[] ,null ,undefined,'', {}, '0', 0
let isNt = e === '0' || e === 0 || e === '' || e === null || e === undefined || (Array.isArray(e)&&e.length === 0) || JSON.stringify(e)==="{}";
return isNt;
}
function checkPhone(phone){ ///验证电话号码
return /^1[3456789]\d{9}$/.test(phone)
}
对数组某属性进行排序
compare(property) {
return function(obj1, obj2) {
var value1 = obj1[property];
var value2 = obj2[property];
return value1 - value2; // 升序
};
},
test() {
let infoObj = [
{ age: 322, name: "wadw", test: "ad" },
{ age: 0, name: "ww", test: "ad" },
{ age: 22, name: "wadw", test: "ad" },
];
console.log(infoObj.sort(this.compare("age")));
},
随机10位字母和数字的组合
ranDomString(len){
var a = "";
len = len || 32;
var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1
var maxPos = $chars.length;
var pwd = '';
var num = '';
for (var i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
num+=Math.floor(Math.random()*10);
}
pwd.toLowerCase();
a = pwd+num;
return pwd;
},