Skip to content

Commit

Permalink
revert: 回退优化字典重复请求问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 16, 2024
1 parent a015d9f commit 1e83e7b
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/hooks/app/useDict.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (() => {
Expand All @@ -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)
Expand Down

0 comments on commit 1e83e7b

Please sign in to comment.