vue3-help
Version:
Vue3 帮助工程
1 lines • 1.45 kB
JavaScript
import dayjs from"dayjs";const useOnlineTime=e=>{e=parseInt(e);const Y=Math.floor((new Date).getTime()/1e3)-new Date(Number(e)).getTime(),t=Math.floor(Y/2592e3),r=Math.floor(Y/86400),a=Y%86400,m=Math.floor(a/3600),n=a%3600,o=Math.floor(n/60),i=n%60,s=Math.round(i);return{visitorOnlineTime:()=>t>12?"一年前":t>0?`${t}月前`:r>0?`${r}天前`:m>0?`${m}小时前`:o>0?`${o}分钟前`:s>0?`${s}秒前`:"刚刚",notifyTrendOnlineTime:()=>{const Y=dayjs().format("YYYY"),t=dayjs(1e3*e).format("YYYY");return r>3?Y===t?dayjs(1e3*e).format("MM月DD日 HH:mm"):dayjs(1e3*e).format("YYYY年MM月DD日"):r>0&&r<=3?`${r}天前`:m>0?`${m}小时前`:o>0?`${o}分钟前`:s>0?`${s}秒前`:"刚刚"},trendOnlineTime:(Y=0)=>r>Y?`${dayjs(1e3*e).format("YYYY-MM-DD")}`:r>0&&r<=Y?`${r}天前`:m>0?`${m}小时前`:o>0?`${o}分钟前`:s>0?`${s}秒前`:"刚刚",trendOnlineTimeStr:()=>{const Y=dayjs().format("YYYY年MM月DD日"),t=dayjs(1e3*e).format("YYYY年MM月DD日");return r>0||Y!==t?dayjs(1e3*e).format("YYYY年MM月DD日"):"今天"},noticeOnlineTime:()=>dayjs().format("YYYY")===dayjs(1e3*e).format("YYYY")?dayjs(1e3*e).format("MM月DD日 HH:mm"):dayjs(1e3*e).format("YYYY年MM月DD日 HH:mm"),trendPublishTime:()=>`${dayjs(1e3*e).format("YYYY/MM/DD HH:mm")}`,userCardOnlineTime:()=>{let e="刚刚来过这里";return r>0?e=`${r}天内来过`:m>0?e=`${m}小时内来过`:o>30?e="1小时内来过":o>5&&(e="半小时内来过"),e}}};export default useOnlineTime;