mirror of
				https://github.com/continew-org/continew-admin-ui.git
				synced 2025-11-04 08:59:22 +08:00 
			
		
		
		
	revert: 回退优化字典重复请求问题
This commit is contained in:
		@@ -2,7 +2,6 @@ import { ref, toRefs } from 'vue'
 | 
			
		||||
import { listCommonDict } from '@/apis'
 | 
			
		||||
import { useDictStore } from '@/stores'
 | 
			
		||||
 | 
			
		||||
const tmpCodeZone: string[] = []
 | 
			
		||||
export function useDict(...codes: Array<string>) {
 | 
			
		||||
  const res = ref<any>({})
 | 
			
		||||
  return (() => {
 | 
			
		||||
@@ -13,19 +12,10 @@ export function useDict(...codes: Array<string>) {
 | 
			
		||||
      if (dict) {
 | 
			
		||||
        res.value[code] = dict
 | 
			
		||||
      } else {
 | 
			
		||||
        if (!tmpCodeZone.includes(code)) {
 | 
			
		||||
          // 防止重复请求
 | 
			
		||||
          tmpCodeZone.push(code)
 | 
			
		||||
          listCommonDict(code)
 | 
			
		||||
            .then((resp) => {
 | 
			
		||||
              res.value[code] = resp.data
 | 
			
		||||
              dictStore.setDict(code, res.value[code])
 | 
			
		||||
              tmpCodeZone.splice(tmpCodeZone.indexOf(code), 1)
 | 
			
		||||
            })
 | 
			
		||||
            .catch(() => {
 | 
			
		||||
              tmpCodeZone.splice(tmpCodeZone.indexOf(code), 1)
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
        listCommonDict(code).then((resp) => {
 | 
			
		||||
          res.value[code] = resp.data
 | 
			
		||||
          dictStore.setDict(code, res.value[code])
 | 
			
		||||
        })
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    return toRefs(res.value)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user