export const toast = (title, duration=2000)=> { setTimeout(_=>{ uni.showToast({ title: title, icon: 'none', duration }); }, 100) } export const loading = _ => { uni.showLoading({ title: '加载中...', mask: true }); } export const currentDate = (noDay=false, addDay=0, checkHour=false) => { let date = Date.parse(new Date())/1000, now; if(checkHour && hour < 6) { addDay-=1; } if(addDay !== 0) { date += (86400) * addDay } now = new Date(parseInt(date) * 1000); let year = now.getFullYear(); //年 let hour = now.getHours(); let month = now.getMonth() + 1; //月 let day = now.getDate(); //日 let clock = year + "-"; if (month < 10) clock += "0"; clock += month; if (!noDay) { clock += "-"; if (day < 10) clock += "0"; clock += day; } return (clock); } const numberFull = (n) => { return n >= 10 ? n : `0${n}` } export const getCurrentDataTime = () => { var now = new Date(); var year = now.getFullYear(); var month = now.getMonth() + 1; // 注意月份需要加1 var day = now.getDate(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); return `${year}-${numberFull(month)}-${numberFull(day)} ${numberFull(hour)}:${numberFull(minute)}:${numberFull(second)}` } export const currentNewDateHour = () => { const now = new Date(); const hour = now.getHours(); return hour; } export const bjDate = function(date, date1) { var date = new Date(date); var date1 = new Date(date1); if (date.getTime() - date1.getTime() < 0) { return true; //第二个时间大 } else { return false; // 第一个时间大 } } export const copyCode = code => { if(!code) return; uni.setClipboardData({ data: code, success: () => { uni.showToast({ title: "复制成功" }) } }); }