From 30222b08ab6539552f3679f4cb9442f477f4df55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E5=B8=86?= <201379873@qq.com> Date: Fri, 17 May 2024 14:27:40 +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/components/GiCell/GiCellTag.vue | 9 +++++++-- src/hooks/app/useDict.ts | 22 +++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/components/GiCell/GiCellTag.vue b/src/components/GiCell/GiCellTag.vue index 2059b02..1df157c 100644 --- a/src/components/GiCell/GiCellTag.vue +++ b/src/components/GiCell/GiCellTag.vue @@ -25,8 +25,13 @@ const props = defineProps({ } }) -const dictItem = computed(() => - props.dict.find((d) => d.value === String(props.value) || d.value === Number(props.value)) +const dictItem = computed(() => { + try { + return props.dict.find((d) => d.value === String(props.value) || d.value === Number(props.value)) + } catch (error) { + return [] + } +} ) diff --git a/src/hooks/app/useDict.ts b/src/hooks/app/useDict.ts index d4ad90b..99e2912 100644 --- a/src/hooks/app/useDict.ts +++ b/src/hooks/app/useDict.ts @@ -2,20 +2,32 @@ import { ref, toRefs } from 'vue' import { listCommonDict } from '@/apis' import { useDictStore } from '@/stores' +const dictStore = useDictStore() +const tmpCodeZone: string[] = [] export function useDict(...codes: Array) { const res = ref({}) return (() => { - const dictStore = useDictStore() codes.forEach((code) => { res.value[code] = [] const dict = dictStore.getDict(code) 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) + }) + } else { + res.value[code] = computed(() => { + return dictStore.getDict(code) + }) + } } }) return toRefs(res.value)