import store from '@/store/index.js' import * as baseUrls from '@/common/request.js' // export const BASE_IMG_URL = 'https://file-dev.xyyxt.net/' export default { isGoLogin(isBack=true) { if (!uni.getStorageSync('user_account')) { uni.navigateTo({url:'/pages/login/login?isBack='+isBack}); return true; } else { return false } }, isLogin() { if (uni.getStorageSync('user_account')) { return true; } else { return false } }, isLogout() { uni.removeStorageSync('user_account') }, //提示 showToast(title, icon = 'none', time = 2000) { return setTimeout(() => { uni.showToast({ title: title, icon: icon, duration: time }) }, 500) }, //图片路径填补 splitImgHost(url,scale=false,width=250) { if (!url) { return '' } else if (url.indexOf("http") != -1 || url.indexOf("https") != -1) { }else{ url = baseUrls.BASE_IMG_URL + url } if(scale){ url = url+"?x-oss-process=image/resize,w_"+width } return url; }, exit() { uni.removeStorageSync('user_account') uni.removeStorageSync('token') store.state.userInfo = null uni.reLaunch({ url: '/pages/index/index' }); }, /* 时间戳转换成日期 * @param timestamp * @returns {*} */ timestampToTime(timestamp, isDay = true) { var date = new Date(timestamp * 1000); //时间戳为10位需*1000,时间戳为13位的话不需乘1000 var Y = date.getFullYear() + '-'; var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-'; var D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '; var h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':'; var m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':': date.getMinutes() + ':'; var s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(); if (isDay) { return Y + M + D; } return Y + M + D + h + m + s; }, //当前时间距离目标时间还有多久 GetRTime(EndTime, isDay = true) { var EndTime = EndTime //结束时间 var NowTime = new Date(); //当前时间 //后台给我的是10位 精确到秒的 所有下面我就除以了1000,不要小数点后面的 var t = EndTime - (NowTime.getTime() / 1000).toFixed(0); if (t <= 0) { return '已结束' } //如果后台给的是毫秒 上面不用除以1000 下面的计算时间也都要除以1000 这里我去掉1000了 var d = Math.floor(t / 60 / 60 / 24); //天 var d=Math.floor(t/1000/60/60/24) var h = Math.floor(t / 60 / 60 % 24); //时 var h=Math.floor(t/1000/60/60%24) var m = Math.floor(t / 60 % 60); //分 var m=Math.floor(t/1000/60%60) var s = Math.floor(t % 60); //秒 var s=Math.floor(t/1000%60) if (parseInt(d) < 10) { d = "0" + d; } if (parseInt(h) < 10) { h = "0" + h; } if (parseInt(m) < 10) { m = "0" + m; } if (parseInt(s) < 10) { s = "0" + s; } if (isDay) { return d; } return d + '天' + h + '小时' + m + '分' + s + '秒' }, TimeTotimestamp(date) { var date = date.replace(/-/g, '/'); var newDate = new Date(date) return (newDate.getTime() / 1000) }, timest() { var tmp = Date.parse(new Date()).toString(); tmp = tmp.substr(0, 10); return tmp; }, getYears(strBirthday) { if (!strBirthday) { return '-'; } var returnAge; var strBirthdayArr = strBirthday.split('-'); var birthYear = strBirthdayArr[0]; var birthMonth = strBirthdayArr[1]; var birthDay = strBirthdayArr[2]; var d = new Date(); var nowYear = d.getFullYear(); var nowMonth = d.getMonth() + 1; var nowDay = d.getDate(); if (nowYear == birthYear) { returnAge = 0; //同年 则为0岁 } else { var ageDiff = nowYear - birthYear; //年之差 if (ageDiff > 0) { if (nowMonth == birthMonth) { var dayDiff = nowDay - birthDay; //日之差 if (dayDiff < 0) { returnAge = ageDiff - 1; } else { returnAge = ageDiff; } } else { var monthDiff = nowMonth - birthMonth; //月之差 if (monthDiff < 0) { returnAge = ageDiff - 1; } else { returnAge = ageDiff; } } } else { returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天 } } return returnAge; //返回周岁年龄 } }