console
/*
草稿
bookDate number 预约日期
bookPeriod1 预约时间1 - 9:30 ~ 11:30(1)
bookPeriod2 预约时间2 - 9:30 ~ 11:30(2)
bookPeriod3 预约时间3 - 13:30 ~ 15:30(1)
bookPeriod4 预约时间4 - 13:30 ~ 15:30(2)
bookPeriod5 预约时间5 - 15:30 ~ 17:30(1)
bookPeriod6 预约时间6 - 15:30 ~ 17:30(2)
正式
employeeID string 工号
employeeName string 姓名
bookDate number 预约日期
bookPeriod number 预约时间
1 9:30 ~ 11:30(1)
2 9:30 ~ 11:30(2)
3 13:30 ~ 15:30(1)
4 13:30 ~ 15:30(2)
5 15:30 ~ 17:30(1)
6 15:30 ~ 17:30(2)
bookStatus number 预约状态
0 可预约
1 已约满
cmpltStatus number 完成状态
0 未签到
1 已签到,未完成
2 已签到,已完成
serviceType string 服务类型
systemReset Win11 系统重装
deviceReplace Win11 电脑更换
deviceType string 设备类型
notebook 笔记本
desktop 台式机
passWord string 密码
assetTag string 序列号
note string 备注
operatorID 处理人工号
operatorName 处理人名称
*/
// 当前时间
const nowTime = new Date().valueOf()
const nowDate = dayjs(new Date()).startOf('day').valueOf()
const nowMaxDate = null
// 使用dayjs解析时间戳
const endDate = dayjs(nowDate).add(30, 'day').valueOf()
console.log("开始日期:", dayjs(nowDate).format("YYYY-MM-DD HH:mm:ss"), nowDate)
console.log("结束日期:", dayjs(endDate).format("YYYY-MM-DD HH:mm:ss"), endDate)
console.log("库中最大日期:", dayjs(nowMaxDate).format("YYYY-MM-DD HH:mm:ss"), nowMaxDate)
const list = handleNewBookDate(nowDate, nowMaxDate, endDate)
console.log("生成日期结果:", list, list.length)
function handleNewBookDate(nowDate, nowMaxDate, endDate) {
let list = []
// 如果最大日期不存在: 当前日期 <= 需要生成日期数组 <= 当前日期30天后的结束日期
if (!nowMaxDate) {
// 使用 Day.js 决定初始日期
let currentDate = nowDate
while (currentDate < endDate) {
list.push(currentDate)
currentDate += 86400000 // 增加一天
}
}
// 最大日期 小于 当前日期:最大日期 < 需要生成日期数组 <= 当前日期30天后的结束日期
if (nowMaxDate < nowDate) {
// 使用 Day.js 决定初始日期
let currentDate = nowMaxDate + 86400000
while (currentDate < endDate) {
list.push(currentDate)
currentDate += 86400000 // 增加一天
}
// 追加最后一日
list.push(endDate)
}
// 最大日期 等于 当前日期:当前日期 < 需要生成日期数组 <= 当前日期30天后的结束日期
if (nowMaxDate === nowDate) {
// 使用 Day.js 决定初始日期
let currentDate = nowDate + 86400000
while (currentDate < endDate) {
list.push(currentDate)
currentDate += 86400000 // 增加一天
}
// 追加最后一日
list.push(endDate)
}
// 最大日期 大于 当前日期,小于当前日期30天后的结束日期: 最大日期 < 需要生成日期数组 <= 当前日期30天后的结束日期
if (nowMaxDate > nowDate && nowMaxDate < endDate) {
// 使用 Day.js 决定初始日期
let currentDate = nowMaxDate + 86400000
while (currentDate < endDate) {
list.push(currentDate)
currentDate += 86400000 // 增加一天
}
// 追加最后一日
list.push(endDate)
}
// 最大日期 大于等于 当前日期30天后的结束日期: 不需要生成日期数组
if (nowMaxDate >= endDate) {
list = []
}
return list
}
<!DOCTYPE html>
<html>
<head>
<title>Dayjs Example</title>
<script src="https://cdn.jsdelivr.net/npm/dayjs"></script>
</head>
<body>
</body>
</html>