#
zhou zhou
2026-04-08 2812a2504ec3d0a98fa7e6204e6048584723adab
rsf-design/src/hooks/core/useTable.js
@@ -1,5 +1,6 @@
import { ref, reactive, computed, onMounted, onUnmounted, nextTick, readonly } from 'vue'
import { useWindowSize } from '@vueuse/core'
import { hash } from 'ohash'
import { useTableColumns } from './useTableColumns'
import { TableCache, CacheInvalidationStrategy } from '../../utils/table/tableCache'
import {
@@ -59,12 +60,14 @@
  const error = ref(null)
  const data = ref([])
  let abortController = null
  let inflightRequest = null
  let inflightRequestKey = ''
  let cacheCleanupTimer = null
  const searchParams = reactive(
    Object.assign(
      {
        [pageKey]: 1,
        [sizeKey]: 10
        [sizeKey]: 20
      },
      apiParams || {}
    )
@@ -113,14 +116,6 @@
    cacheUpdateTrigger.value++
  }
  const fetchData = async (params, useCache = enableCache) => {
    if (abortController) {
      abortController.abort()
    }
    const currentController = new AbortController()
    abortController = currentController
    loadingState.value = 'loading'
    error.value = null
    try {
      let requestParams = Object.assign(
        {},
        searchParams,
@@ -137,6 +132,20 @@
        })
        requestParams = filteredParams
      }
    const requestKey = hash(requestParams)
    if (inflightRequest && inflightRequestKey === requestKey) {
      logger.log('复用进行中的请求')
      return inflightRequest
    }
    if (abortController) {
      abortController.abort()
    }
    const currentController = new AbortController()
    abortController = currentController
    loadingState.value = 'loading'
    error.value = null
    const currentRequest = (async () => {
      try {
      if (useCache && cache) {
        const cachedItem = cache.get(requestParams)
        if (cachedItem) {
@@ -201,8 +210,16 @@
      if (abortController === currentController) {
        abortController = null
      }
        if (inflightRequest === currentRequest) {
          inflightRequest = null
          inflightRequestKey = ''
    }
  }
    })()
    inflightRequest = currentRequest
    inflightRequestKey = requestKey
    return currentRequest
  }
  const getData = async (params) => {
    try {
      return await fetchData(params)