From d6b4ae011d9a07f77792c3e5df05888625914b3c Mon Sep 17 00:00:00 2001 From: lyc Date: Thu, 29 Aug 2024 16:45:17 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E7=BA=A6=E8=AF=BE=E7=A8=8B-=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E6=97=B6=E9=97=B4-=E6=97=B6=E9=97=B4=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/renderer/src/utils/date.js | 33 ++++++++++++ .../src/views/prepare/container/reserv.vue | 51 +++++++++++++++++++ .../src/views/tool/components/board.vue | 1 + 3 files changed, 85 insertions(+) diff --git a/src/renderer/src/utils/date.js b/src/renderer/src/utils/date.js index 4a1025d..f70414b 100644 --- a/src/renderer/src/utils/date.js +++ b/src/renderer/src/utils/date.js @@ -76,3 +76,36 @@ export const toTimeText = (timeStamp, simple) => { } return timeText } + +/** + * + * @returns 当前年-月-日 + */ +export const getCurrentTime = (format)=> { + const now = new Date(); + const year = now.getFullYear(); + const month = (now.getMonth() + 1).toString().padStart(2, '0'); + const day = now.getDate().toString().padStart(2, '0'); + const hours = now.getHours().toString().padStart(2, '0'); + const minutes = now.getMinutes().toString().padStart(2, '0'); + if(format == 'YYYY-MM-DD'){ + return `${year}-${month}-${day}`; + } + if(format == 'HH:mm'){ + return `${hours}:${minutes}`; + } +} +/** + * + * @param {number} m 指定时间 + * @returns 指定时间之后的 小时:分钟 + */ +export const getAfterMinutes = (m) => { + const now = new Date(); + const afterMinutes = new Date(now.getTime() + m * 60 * 1000); + let hours = afterMinutes.getHours(); + hours = hours < 10 ? ('0' + hours) : hours + let minutes = afterMinutes.getMinutes(); + minutes = minutes < 10 ? ('0' + minutes) : minutes + return `${hours}:${minutes}`; +} \ No newline at end of file diff --git a/src/renderer/src/views/prepare/container/reserv.vue b/src/renderer/src/views/prepare/container/reserv.vue index ceb4dcd..f08e0ec 100644 --- a/src/renderer/src/views/prepare/container/reserv.vue +++ b/src/renderer/src/views/prepare/container/reserv.vue @@ -35,6 +35,7 @@ placeholder="请选择日期" format="YYYY-MM-DD" value-format="YYYY-MM-DD" + :disabled-date="disabledDate" /> @@ -53,6 +54,8 @@ range-separator="-" start-placeholder="开始时间" end-placeholder="结束时间" + :disabled-hours="disabledHours" + :disabled-minutes="disabledMinute" /> @@ -81,6 +84,8 @@ import { ref, defineExpose, onMounted, reactive, computed, watch } from 'vue' import { addSmartClassReserv, updateSmartClassReserv, listClassmain } from '@/api/classManage' import useUserStore from '@/store/modules/user' import { ElMessage } from 'element-plus' +import { getCurrentTime, getAfterMinutes } from '@/utils/date' + const emit = defineEmits(['addSuccess']) const props = defineProps({ bookId: { @@ -143,6 +148,47 @@ const locationOptions = [ const locationMessage = computed(() => { return locationOptions.find((item) => item.value === form.type).message }) + +// 设置一个月后的日期不能选择 +const disabledDate = (time)=> { + // 禁用今天之前的日期 + const today = new Date(); + if (time.getTime() < today.getTime() - 8.64e7) { + // 返回true表示禁用 + return true; + } + // 同时禁用超过一个月后的日期 + const oneMonthLater = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000); + if (time.getTime() > oneMonthLater.getTime()) { + return true; + } + return false; +} + +// 限制小时-返回被禁选的小时 +const disabledHours = ()=>{ + if(getCurrentTime('YYYY-MM-DD') == form.day){ + const arrs = [] + for (let i = 0; i < 24; i++) { + if (new Date().getHours() <= i) continue; + arrs.push(i) + } + return arrs; + } +} +// 限制分-返回被禁选的 +const disabledMinute = () => { + if(getCurrentTime('YYYY-MM-DD') == form.day){ + const arrs = [] + for (let i = 0; i < 60; i++) { + if (new Date().getMinutes() <= i && form.time[0]) continue; + arrs.push(i) + } + return arrs; + } +} + + const openDialog = (data) => { if (data) { updateForm.value = data @@ -154,6 +200,11 @@ const openDialog = (data) => { form.resource = data.classList.split(',').map((item) => parseInt(item)) form.classRoom = data.classRoom } + else{ + // 默认当前时间 + form.day = getCurrentTime('YYYY-MM-DD') + form.time = [getCurrentTime('HH:mm'), getAfterMinutes(45)] + } centerDialogVisible.value = true } const closeDialog = () => { diff --git a/src/renderer/src/views/tool/components/board.vue b/src/renderer/src/views/tool/components/board.vue index 552722f..c6d4144 100644 --- a/src/renderer/src/views/tool/components/board.vue +++ b/src/renderer/src/views/tool/components/board.vue @@ -19,6 +19,7 @@ const emit = defineEmits(['update:modelValue']) onMounted(async() => { if (canvasRef.value) { FabricVue.drawConfig.drawColors = ['red'] + FabricVue.drawConfig.drawWidth = 3 FabricVue.boardConfig.mode = TYPES.ActionMode.OTHER FabricVue.boardConfig.backgroundColor = 'transparent' const option = { freeDrawingCursor: 'default' }