diff --git a/src/renderer/src/utils/comm.js b/src/renderer/src/utils/comm.js index 29e7a48..a0d457f 100644 --- a/src/renderer/src/utils/comm.js +++ b/src/renderer/src/utils/comm.js @@ -310,3 +310,44 @@ export function timeToStr(time,str = '时分秒', isPad = false) { if (isPad) return `${h?toStr(h)+arr[0]:''}${m?toStr(m)+arr[1]:''}${toStr(s)}${arr[2]||''}` return `${h?h+arr[0]:''}${m?m+arr[1]:''}${s?s+arr[2]||'':''}` } + +/** + * 防抖:一定时间内,如果函数被连续调用,则只执行最后一次调用。 + * debounce(() => { + console.log('Input event handled'); + }, 300); + * @param {*} func + * @param {*} wait + * @returns + */ +export function debounce(func, wait) { + let timeout; + return function() { + const context = this; + const args = arguments; + clearTimeout(timeout); + timeout = setTimeout(() => func.apply(context, args), wait); + }; +} + +/** + * 节流:一定时间内,函数最多只执行一次 + * throttle(() => { + console.log('Scroll event handled'); + }, 300); + * @param {*} func + * @param {*} wait + * @returns + */ +export function throttle(func, wait) { + let lastTime = 0; + return function() { + const context = this; + const args = arguments; + const now = new Date(); + if (now - lastTime >= wait) { + func.apply(context, args); + lastTime = now; + } + }; +} diff --git a/src/renderer/src/views/classTask/classTask.vue b/src/renderer/src/views/classTask/classTask.vue index 737de18..158f202 100644 --- a/src/renderer/src/views/classTask/classTask.vue +++ b/src/renderer/src/views/classTask/classTask.vue @@ -72,6 +72,7 @@ import { getCurrentTime, getTomorrow } from '@/utils/date' import useUserStore from '@/store/modules/user' import useClassTaskStore from "@/store/modules/classTask"; import {sessionStore, createWindow} from '@/utils/tool' +import {throttle,debounce } from '@/utils/comm' const toolState = useToolState(); @@ -377,7 +378,10 @@ const closeDialog = () => { getStudentClassWorkDataPolling() } -const openDialogTime = ref(null);//弹窗 +const debounceOpenWin = debounce(() => { + toolState.isTaskWin=true; // 设置打开批改窗口 + createWindow('open-taskwin',{url:'/teachClassTask'}); // 调用新窗口批改页面 +}, 1000); /** * 开启新批改弹窗 * @param item 作业对象 @@ -385,17 +389,10 @@ const openDialogTime = ref(null);//弹窗 const onClickItem = (item) => { console.log('开启弹窗,关闭作业进度轮询') clearInterval(pollingST.value) - // itemDialogRef.value.openDialog(item) - if(openDialogTime.value) return; - clearTimeout(openDialogTime.value) - openDialogTime.value = setTimeout(() => { - openDialogTime.value = null; - toolState.isTaskWin=true; // 设置打开批改窗口 - sessionStore.set('teachClassWorkItem', item); // 缓存点击的item - // 调用新窗口批改页面 - createWindow('open-taskwin',{url:'/teachClassTask'}) - }, 1000*2) + console.log('防抖开启弹窗') + sessionStore.set('teachClassWorkItem', item); // 缓存点击的item + debounceOpenWin(); } diff --git a/src/renderer/src/views/classTask/classTaskAssign.vue b/src/renderer/src/views/classTask/classTaskAssign.vue index d74124b..2de08e4 100644 --- a/src/renderer/src/views/classTask/classTaskAssign.vue +++ b/src/renderer/src/views/classTask/classTaskAssign.vue @@ -155,10 +155,7 @@ - - + @@ -1042,6 +1039,14 @@ const handleTaskAssignToAllClass = () => { } } +/** + * 设计作业 + */ +const handleNewClassWorkDialog = () => { + // 打开作业设计页面 + router.push({ path: '/newClassTask' }); +} + // 作业说明编辑-确认 const submitWorkTitle = () => { if(currentWorkEdit.currentTask.title == currentWorkEdit.currentTitle){ diff --git a/src/renderer/src/views/desktop/container/work-trend.vue b/src/renderer/src/views/desktop/container/work-trend.vue index 9d1734c..be3e117 100644 --- a/src/renderer/src/views/desktop/container/work-trend.vue +++ b/src/renderer/src/views/desktop/container/work-trend.vue @@ -37,6 +37,7 @@ import { homeworklist } from '@/api/teaching/classwork' import { getCurrentTime, getTomorrow } from '@/utils/date' import {sessionStore, createWindow} from '@/utils/tool' import { useToolState } from '@/store/modules/tool' +import {throttle,debounce } from '@/utils/comm' const user = useUserStore().user const toolState = useToolState(); @@ -68,19 +69,17 @@ const getHomework = async () => { } } -const openDialogTime = ref(null);//弹窗 + +const debounceOpenWin = debounce(() => { + toolState.isTaskWin=true; // 设置打开批改窗口 + createWindow('open-taskwin',{url:'/teachClassTask'}); // 调用新窗口批改页面 +}, 1000); + // 批改作业 const onClickItem = (item) => { - console.log('开启弹窗') - if(openDialogTime.value) return; - clearTimeout(openDialogTime.value) - openDialogTime.value = setTimeout(() => { - openDialogTime.value = null; - toolState.isTaskWin=true; // 设置打开批改窗口 - sessionStore.set('teachClassWorkItem', item); // 缓存点击的item - // 调用新窗口批改页面 - createWindow('open-taskwin',{url:'/teachClassTask'}) - }, 1000*2) + console.log('防抖开启弹窗') + sessionStore.set('teachClassWorkItem', item); // 缓存点击的item + debounceOpenWin(); } const tagType = (time) => {