2 lines
1.4 KiB
JavaScript
2 lines
1.4 KiB
JavaScript
"use strict";const t=require("../vendor.js");t.dayjs.locale("zh-cn"),t.dayjs.extend(t.relativeTime),exports.ShowLastTime=function(e){return e?t.dayjs(e).fromNow():"-"},exports.generateTimeSlots=function(e=null){const o=e?t.dayjs(e):t.dayjs(),r=(e?t.dayjs(e):t.dayjs()).valueOf(),s=[];let n=8;for(;n<18;){const t=Math.min(n+2,18),e=o.hour(n).minute(0).second(0),u=o.hour(t).minute(0).second(0),a=e.format("HH:mm"),l=u.format("HH:mm"),f=r>=e.valueOf()&&r<u.valueOf();u.valueOf()>r&&s.push({label:f?"两个小时内":`${a}-${l}`,str:a,end:l,isCurrent:f,date:o.format("YYYY-MM-DD"),startTimestamp:e.valueOf(),endTimestamp:u.valueOf()}),n=t}return console.log("slots",s),s},exports.getCurrentHour=function(){const t=new Date,e=t.getHours(),o=t.getMinutes();return console.log(e,o,"dayjs().hour()"),{currentHour:e,currentMinute:o}},exports.getTheFutureDay=function(e=1){return t.dayjs().add(e,"day").format("YYYY-MM-DD")},exports.getTimeStatus=function(e){const o=t.dayjs(),r=t.dayjs(e);if(r.isBefore(o)){const t=o.diff(r,"hour"),e=o.diff(r,"minute")%60;let s="上门时间已超时";return t>0&&(s+=`${t}个小时`),e>0&&(s+=`${e}分钟`),{label:s,status:"4",color:"#EA0000"}}{const t=r.diff(o,"hour"),e=r.diff(o,"minute")%60;let s,n;t>=24?(s="1",n="#24BC21"):t>=2?(s="2",n="#0082FA"):(s="3",n="#F97316");const u=Math.floor(t/24),a=t%24;let l="上门时间还剩:";return u>0&&(l+=`${u}天`),a>0&&(l+=`${a}个小时`),e>0&&(l+=`${e}分钟`),{label:l,status:s,color:n}}};
|