From 6705027273e098cde57792743c3a0bdacb559449 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E5=B8=86?= <201379873@qq.com> Date: Thu, 16 May 2024 20:15:42 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E8=AF=B7=E6=B1=82=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/app/useDict.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/hooks/app/useDict.ts b/src/hooks/app/useDict.ts index d4ad90b..9a7a815 100644 --- a/src/hooks/app/useDict.ts +++ b/src/hooks/app/useDict.ts @@ -2,6 +2,7 @@ import { ref, toRefs } from 'vue' import { listCommonDict } from '@/apis' import { useDictStore } from '@/stores' +const tmpCodeZone: string[] = [] export function useDict(...codes: Array) { const res = ref({}) return (() => { @@ -12,10 +13,19 @@ export function useDict(...codes: Array) { if (dict) { res.value[code] = dict } else { - listCommonDict(code).then((resp) => { - res.value[code] = resp.data - dictStore.setDict(code, res.value[code]) - }) + 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) + }) + } } }) return toRefs(res.value)