refactor: extract useDebounce composable from 4 duplicate copies
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
export function useDebounce<T extends (...args: any[]) => any>(fn: T, delay: number) {
|
||||||
|
let timer: ReturnType<typeof setTimeout> | null = null
|
||||||
|
const debounced = (...args: Parameters<T>) => {
|
||||||
|
if (timer) clearTimeout(timer)
|
||||||
|
timer = setTimeout(() => fn(...args), delay)
|
||||||
|
}
|
||||||
|
const cancel = () => { if (timer) clearTimeout(timer) }
|
||||||
|
return { debounced, cancel }
|
||||||
|
}
|
||||||
@@ -185,17 +185,7 @@ import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
|
|||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { Search, Refresh, Plus, Connection, Right, Setting } from '@element-plus/icons-vue'
|
import { Search, Refresh, Plus, Connection, Right, Setting } from '@element-plus/icons-vue'
|
||||||
import api from '../api'
|
import api from '../api'
|
||||||
|
import { useDebounce } from '../composables/useDebounce'
|
||||||
// Debounce helper
|
|
||||||
function useDebounce<T extends (...args: any[]) => any>(fn: T, delay: number) {
|
|
||||||
let timer: ReturnType<typeof setTimeout> | null = null
|
|
||||||
const debounced = (...args: Parameters<T>) => {
|
|
||||||
if (timer) clearTimeout(timer)
|
|
||||||
timer = setTimeout(() => fn(...args), delay)
|
|
||||||
}
|
|
||||||
const cancel = () => { if (timer) clearTimeout(timer) }
|
|
||||||
return { debounced, cancel }
|
|
||||||
}
|
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const search = ref('')
|
const search = ref('')
|
||||||
|
|||||||
@@ -103,16 +103,7 @@ import { ref, reactive, onMounted, onUnmounted } from 'vue'
|
|||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { Notebook, Warning, Timer, Search, Refresh } from '@element-plus/icons-vue'
|
import { Notebook, Warning, Timer, Search, Refresh } from '@element-plus/icons-vue'
|
||||||
import api from '../api'
|
import api from '../api'
|
||||||
|
import { useDebounce } from '../composables/useDebounce'
|
||||||
function useDebounce<T extends (...args: any[]) => any>(fn: T, delay: number) {
|
|
||||||
let timer: ReturnType<typeof setTimeout> | null = null
|
|
||||||
const debounced = (...args: Parameters<T>) => {
|
|
||||||
if (timer) clearTimeout(timer)
|
|
||||||
timer = setTimeout(() => fn(...args), delay)
|
|
||||||
}
|
|
||||||
const cancel = () => { if (timer) clearTimeout(timer) }
|
|
||||||
return { debounced, cancel }
|
|
||||||
}
|
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const searchPath = ref('')
|
const searchPath = ref('')
|
||||||
|
|||||||
@@ -161,17 +161,7 @@ import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
|
|||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
import { Search, Refresh, Memo, CircleCheck, Warning } from '@element-plus/icons-vue'
|
import { Search, Refresh, Memo, CircleCheck, Warning } from '@element-plus/icons-vue'
|
||||||
import api from '../api'
|
import api from '../api'
|
||||||
|
import { useDebounce } from '../composables/useDebounce'
|
||||||
// Debounce utility
|
|
||||||
function useDebounce<T extends (...args: any[]) => any>(fn: T, delay: number) {
|
|
||||||
let timer: ReturnType<typeof setTimeout> | null = null
|
|
||||||
const debounced = (...args: Parameters<T>) => {
|
|
||||||
if (timer) clearTimeout(timer)
|
|
||||||
timer = setTimeout(() => fn(...args), delay)
|
|
||||||
}
|
|
||||||
const cancel = () => { if (timer) clearTimeout(timer) }
|
|
||||||
return { debounced, cancel }
|
|
||||||
}
|
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const search = ref('')
|
const search = ref('')
|
||||||
|
|||||||
@@ -140,16 +140,7 @@ import { ref, reactive, onMounted, onUnmounted } from 'vue'
|
|||||||
import { ElMessage } from 'element-plus'
|
import { ElMessage } from 'element-plus'
|
||||||
import { Timer, CircleCheck, CircleClose, Loading, Search, Refresh } from '@element-plus/icons-vue'
|
import { Timer, CircleCheck, CircleClose, Loading, Search, Refresh } from '@element-plus/icons-vue'
|
||||||
import api from '../api'
|
import api from '../api'
|
||||||
|
import { useDebounce } from '../composables/useDebounce'
|
||||||
function useDebounce<T extends (...args: any[]) => any>(fn: T, delay: number) {
|
|
||||||
let timer: ReturnType<typeof setTimeout> | null = null
|
|
||||||
const debounced = (...args: Parameters<T>) => {
|
|
||||||
if (timer) clearTimeout(timer)
|
|
||||||
timer = setTimeout(() => fn(...args), delay)
|
|
||||||
}
|
|
||||||
const cancel = () => { if (timer) clearTimeout(timer) }
|
|
||||||
return { debounced, cancel }
|
|
||||||
}
|
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const search = ref('')
|
const search = ref('')
|
||||||
|
|||||||
Reference in New Issue
Block a user