|
|
@@ -193,7 +193,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="uts">
|
|
|
-import { ref, computed, onMounted } from 'vue'
|
|
|
+import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
|
|
|
import { listOrderHours, getOrderHourStatistics } from '@/api/worktime/index'
|
|
|
import { getDictDataByType } from '@/api/dict/index'
|
|
|
import type { SysDictData } from '@/types/dict'
|
|
|
@@ -213,6 +213,12 @@ const repairHours = ref<number>(0)
|
|
|
const rank = ref<number | null>(null)
|
|
|
const totalRankingUsers = ref<number | null>(null)
|
|
|
|
|
|
+// 防止重复请求的标志位
|
|
|
+const isSearching = ref<boolean>(false)
|
|
|
+
|
|
|
+// 添加防抖定时器
|
|
|
+let searchTimer: number | null = null
|
|
|
+
|
|
|
// 弹窗显示状态
|
|
|
const showDatePickerPopup = ref<boolean>(false)
|
|
|
const showStartDatePicker = ref<boolean>(false)
|
|
|
@@ -491,26 +497,98 @@ function loadData(isRefresh: boolean) {
|
|
|
}
|
|
|
|
|
|
function handleSearch() {
|
|
|
- loadData(true)
|
|
|
- //getStatistics()
|
|
|
+ // 添加防抖和防止重复请求
|
|
|
+ if (isSearching.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const timer = searchTimer
|
|
|
+ if (timer != null) {
|
|
|
+ clearTimeout(timer)
|
|
|
+ searchTimer = null
|
|
|
+ }
|
|
|
+
|
|
|
+ searchTimer = setTimeout(() => {
|
|
|
+ isSearching.value = true
|
|
|
+ loadData(true)
|
|
|
+ getStatistics()
|
|
|
+ // 延迟重置标志位,确保请求发送后才允许下一次搜索
|
|
|
+ setTimeout(() => {
|
|
|
+ isSearching.value = false
|
|
|
+ }, 100)
|
|
|
+ }, 300)
|
|
|
}
|
|
|
|
|
|
function clearSearch() {
|
|
|
+ // 添加防抖和防止重复请求
|
|
|
+ if (isSearching.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const timer = searchTimer
|
|
|
+ if (timer != null) {
|
|
|
+ clearTimeout(timer)
|
|
|
+ searchTimer = null
|
|
|
+ }
|
|
|
+
|
|
|
searchKeyword.value = ""
|
|
|
- loadData(true)
|
|
|
- //getStatistics()
|
|
|
+ searchTimer = setTimeout(() => {
|
|
|
+ isSearching.value = true
|
|
|
+ loadData(true)
|
|
|
+ getStatistics()
|
|
|
+ // 延迟重置标志位,确保请求发送后才允许下一次搜索
|
|
|
+ setTimeout(() => {
|
|
|
+ isSearching.value = false
|
|
|
+ }, 100)
|
|
|
+ }, 300)
|
|
|
}
|
|
|
|
|
|
function filterByOrderType(type: string) {
|
|
|
+ // 添加防止重复请求
|
|
|
+ if (isSearching.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const timer = searchTimer
|
|
|
+ if (timer != null) {
|
|
|
+ clearTimeout(timer)
|
|
|
+ searchTimer = null
|
|
|
+ }
|
|
|
+
|
|
|
orderTypeFilter.value = type
|
|
|
- loadData(true)
|
|
|
- getStatistics()
|
|
|
+ searchTimer = setTimeout(() => {
|
|
|
+ isSearching.value = true
|
|
|
+ loadData(true)
|
|
|
+ getStatistics()
|
|
|
+ // 延迟重置标志位,确保请求发送后才允许下一次搜索
|
|
|
+ setTimeout(() => {
|
|
|
+ isSearching.value = false
|
|
|
+ }, 100)
|
|
|
+ }, 300)
|
|
|
}
|
|
|
|
|
|
function changeTimeRange(range: string) {
|
|
|
+ // 添加防止重复请求
|
|
|
+ if (isSearching.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const timer = searchTimer
|
|
|
+ if (timer != null) {
|
|
|
+ clearTimeout(timer)
|
|
|
+ searchTimer = null
|
|
|
+ }
|
|
|
+
|
|
|
timeRange.value = range
|
|
|
- loadData(true)
|
|
|
- getStatistics()
|
|
|
+ searchTimer = setTimeout(() => {
|
|
|
+ isSearching.value = true
|
|
|
+ loadData(true)
|
|
|
+ getStatistics()
|
|
|
+ // 延迟重置标志位,确保请求发送后才允许下一次搜索
|
|
|
+ setTimeout(() => {
|
|
|
+ isSearching.value = false
|
|
|
+ }, 100)
|
|
|
+ }, 300)
|
|
|
}
|
|
|
|
|
|
function loadMore() {
|
|
|
@@ -563,8 +641,27 @@ function confirmCustomDate() {
|
|
|
|
|
|
closeDatePicker()
|
|
|
timeRange.value = 'custom'
|
|
|
- loadData(true)
|
|
|
- getStatistics()
|
|
|
+
|
|
|
+ // 添加防止重复请求
|
|
|
+ if (isSearching.value) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const timer = searchTimer
|
|
|
+ if (timer != null) {
|
|
|
+ clearTimeout(timer)
|
|
|
+ searchTimer = null
|
|
|
+ }
|
|
|
+
|
|
|
+ searchTimer = setTimeout(() => {
|
|
|
+ isSearching.value = true
|
|
|
+ loadData(true)
|
|
|
+ getStatistics()
|
|
|
+ // 延迟重置标志位,确保请求发送后才允许下一次搜索
|
|
|
+ setTimeout(() => {
|
|
|
+ isSearching.value = false
|
|
|
+ }, 100)
|
|
|
+ }, 300)
|
|
|
}
|
|
|
|
|
|
// 打开开始日期选择器
|
|
|
@@ -687,6 +784,16 @@ onMounted(() => {
|
|
|
loadMaintenanceTypeDictList()
|
|
|
loadData(false)
|
|
|
getStatistics()
|
|
|
+ dictLoaded.value = true
|
|
|
+})
|
|
|
+
|
|
|
+// 组件销毁时清除定时器
|
|
|
+onBeforeUnmount(() => {
|
|
|
+ const timer = searchTimer
|
|
|
+ if (timer != null) {
|
|
|
+ clearTimeout(timer)
|
|
|
+ searchTimer = null
|
|
|
+ }
|
|
|
})
|
|
|
</script>
|
|
|
|