2025-12-19 09:46:56 +08:00
|
|
|
"use strict";
|
|
|
|
|
const common_vendor = require("../vendor.js");
|
|
|
|
|
common_vendor.dayjs.locale("zh-cn");
|
|
|
|
|
common_vendor.dayjs.extend(common_vendor.relativeTime);
|
|
|
|
|
function ShowLastTime(time) {
|
|
|
|
|
return time ? common_vendor.dayjs(time).fromNow() : "-";
|
|
|
|
|
}
|
2026-01-30 09:54:46 +08:00
|
|
|
function showDay(time) {
|
|
|
|
|
return time ? common_vendor.dayjs(time).format("YYYY-MM-DD") : "-";
|
|
|
|
|
}
|
|
|
|
|
function getDay(num) {
|
|
|
|
|
if (num) {
|
|
|
|
|
const yesterday = common_vendor.dayjs().subtract(num, "day");
|
|
|
|
|
console.log(yesterday.format("YYYY-MM-DD"));
|
|
|
|
|
return yesterday.format("YYYY-MM-DD");
|
|
|
|
|
}
|
|
|
|
|
return common_vendor.dayjs().format("YYYY-MM-DD");
|
|
|
|
|
}
|
|
|
|
|
function getTime() {
|
|
|
|
|
return common_vendor.dayjs().format("YYYY-MM-DD HH:mm:ss");
|
|
|
|
|
}
|
2025-12-19 09:46:56 +08:00
|
|
|
function getTimeStatus(endTime) {
|
|
|
|
|
const now = common_vendor.dayjs();
|
|
|
|
|
const end = common_vendor.dayjs(endTime);
|
|
|
|
|
if (end.isBefore(now)) {
|
|
|
|
|
const hours = now.diff(end, "hour");
|
|
|
|
|
const minutes = now.diff(end, "minute") % 60;
|
|
|
|
|
let label = "已过期望处理时间:";
|
|
|
|
|
if (hours > 0) {
|
|
|
|
|
label += `${hours}个小时`;
|
|
|
|
|
}
|
|
|
|
|
if (minutes > 0) {
|
|
|
|
|
label += `${minutes}分钟`;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
label,
|
|
|
|
|
status: "4",
|
|
|
|
|
color: "#EA0000"
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
const diffHours = end.diff(now, "hour");
|
|
|
|
|
const diffMinutes = end.diff(now, "minute") % 60;
|
|
|
|
|
let status;
|
|
|
|
|
let color;
|
|
|
|
|
if (diffHours >= 24) {
|
|
|
|
|
status = "1";
|
|
|
|
|
color = "#24BC21";
|
|
|
|
|
} else if (diffHours >= 2) {
|
|
|
|
|
status = "2";
|
|
|
|
|
color = "#0082FA";
|
|
|
|
|
} else {
|
|
|
|
|
status = "3";
|
|
|
|
|
color = "#F97316";
|
|
|
|
|
}
|
|
|
|
|
const days = Math.floor(diffHours / 24);
|
|
|
|
|
const hours = diffHours % 24;
|
|
|
|
|
let label = "上门时间还剩:";
|
|
|
|
|
if (days > 0) {
|
|
|
|
|
label += `${days}天`;
|
|
|
|
|
}
|
|
|
|
|
if (hours > 0) {
|
|
|
|
|
label += `${hours}个小时`;
|
|
|
|
|
}
|
|
|
|
|
if (diffMinutes > 0) {
|
|
|
|
|
label += `${diffMinutes}分钟`;
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
label,
|
|
|
|
|
status,
|
|
|
|
|
color
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
function generateTimeSlots(externalDate = null) {
|
|
|
|
|
const baseDate = externalDate ? common_vendor.dayjs(externalDate) : common_vendor.dayjs();
|
|
|
|
|
const now = externalDate ? common_vendor.dayjs(externalDate) : common_vendor.dayjs();
|
|
|
|
|
const startHour = 8;
|
|
|
|
|
const endHour = 18;
|
|
|
|
|
const interval = 2;
|
|
|
|
|
const currentTime = now.valueOf();
|
|
|
|
|
const slots = [];
|
|
|
|
|
let currentStart = startHour;
|
|
|
|
|
while (currentStart < endHour) {
|
|
|
|
|
const currentEnd = Math.min(currentStart + interval, endHour);
|
|
|
|
|
const startTime = baseDate.hour(currentStart).minute(0).second(0);
|
|
|
|
|
const endTime = baseDate.hour(currentEnd).minute(0).second(0);
|
|
|
|
|
const startStr = startTime.format("HH:mm");
|
|
|
|
|
const endStr = endTime.format("HH:mm");
|
|
|
|
|
const isCurrentPeriod = currentTime >= startTime.valueOf() && currentTime < endTime.valueOf();
|
|
|
|
|
if (endTime.valueOf() > currentTime) {
|
|
|
|
|
slots.push({
|
|
|
|
|
label: isCurrentPeriod ? "两个小时内" : `${startStr}-${endStr}`,
|
|
|
|
|
str: startStr,
|
|
|
|
|
end: endStr,
|
|
|
|
|
isCurrent: isCurrentPeriod,
|
|
|
|
|
date: baseDate.format("YYYY-MM-DD"),
|
|
|
|
|
startTimestamp: startTime.valueOf(),
|
|
|
|
|
endTimestamp: endTime.valueOf()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
currentStart = currentEnd;
|
|
|
|
|
}
|
|
|
|
|
console.log("slots", slots);
|
|
|
|
|
return slots;
|
|
|
|
|
}
|
|
|
|
|
function getCurrentHour() {
|
|
|
|
|
const now = new Date();
|
|
|
|
|
const currentHour = now.getHours();
|
|
|
|
|
const currentMinute = now.getMinutes();
|
|
|
|
|
console.log(currentHour, currentMinute, "dayjs().hour()");
|
|
|
|
|
return { currentHour, currentMinute };
|
|
|
|
|
}
|
|
|
|
|
function getTheFutureDay(num = 1) {
|
|
|
|
|
const pastFifteenDays = common_vendor.dayjs().add(num, "day");
|
|
|
|
|
return pastFifteenDays.format("YYYY-MM-DD");
|
|
|
|
|
}
|
2026-01-30 09:54:46 +08:00
|
|
|
function showCurrentTime() {
|
|
|
|
|
return common_vendor.dayjs().format("HH:mm");
|
|
|
|
|
}
|
|
|
|
|
function isDatePassed(fixedDate) {
|
|
|
|
|
console.log(common_vendor.dayjs().isAfter(common_vendor.dayjs(fixedDate)), "dayjs().isAfter(dayjs(fixedDate))");
|
|
|
|
|
return common_vendor.dayjs().isAfter(common_vendor.dayjs(fixedDate), "day");
|
|
|
|
|
}
|
|
|
|
|
function showWeekDay() {
|
|
|
|
|
const weekMap = {
|
|
|
|
|
0: "星期日",
|
|
|
|
|
1: "星期一",
|
|
|
|
|
2: "星期二",
|
|
|
|
|
3: "星期三",
|
|
|
|
|
4: "星期四",
|
|
|
|
|
5: "星期五",
|
|
|
|
|
6: "星期六"
|
|
|
|
|
};
|
|
|
|
|
const today = weekMap[common_vendor.dayjs().day()];
|
|
|
|
|
return today;
|
|
|
|
|
}
|
|
|
|
|
function getDayTime(time) {
|
|
|
|
|
if (time) {
|
|
|
|
|
let dataTime = time == null ? void 0 : time.replace(/-/g, "/");
|
|
|
|
|
return common_vendor.dayjs(dataTime).format("YYYY-MM-DD HH:mm");
|
|
|
|
|
}
|
|
|
|
|
return common_vendor.dayjs().format("YYYY-MM-DD HH:mm");
|
|
|
|
|
}
|
|
|
|
|
function specificTime(targetTime) {
|
|
|
|
|
let dataTime = targetTime == null ? void 0 : targetTime.replace(/-/g, "/");
|
|
|
|
|
const now = common_vendor.dayjs();
|
|
|
|
|
const target = common_vendor.dayjs(dataTime);
|
|
|
|
|
let hoursDiff = Math.abs(target.diff(now, "hour", true)) <= 2 || target.isBefore(now);
|
|
|
|
|
console.log(hoursDiff, "hoursDiff");
|
|
|
|
|
return hoursDiff;
|
|
|
|
|
}
|
2025-12-19 09:46:56 +08:00
|
|
|
exports.ShowLastTime = ShowLastTime;
|
|
|
|
|
exports.generateTimeSlots = generateTimeSlots;
|
|
|
|
|
exports.getCurrentHour = getCurrentHour;
|
2026-01-30 09:54:46 +08:00
|
|
|
exports.getDay = getDay;
|
|
|
|
|
exports.getDayTime = getDayTime;
|
2025-12-19 09:46:56 +08:00
|
|
|
exports.getTheFutureDay = getTheFutureDay;
|
2026-01-30 09:54:46 +08:00
|
|
|
exports.getTime = getTime;
|
2025-12-19 09:46:56 +08:00
|
|
|
exports.getTimeStatus = getTimeStatus;
|
2026-01-30 09:54:46 +08:00
|
|
|
exports.isDatePassed = isDatePassed;
|
|
|
|
|
exports.showCurrentTime = showCurrentTime;
|
|
|
|
|
exports.showDay = showDay;
|
|
|
|
|
exports.showWeekDay = showWeekDay;
|
|
|
|
|
exports.specificTime = specificTime;
|