From 86d38911e98711b1df540dfc0404997173f70816 Mon Sep 17 00:00:00 2001 From: hayden Date: Tue, 29 Oct 2024 18:02:49 +0800 Subject: [PATCH] fix: Too many models may cause performance issues --- src/components/DialogCreateTask.vue | 9 ++++----- src/hooks/download.ts | 12 ++++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/components/DialogCreateTask.vue b/src/components/DialogCreateTask.vue index 20b0da2..b56a2dd 100644 --- a/src/components/DialogCreateTask.vue +++ b/src/components/DialogCreateTask.vue @@ -29,10 +29,9 @@
@@ -78,7 +77,7 @@ const dialog = useDialog() const modelUrl = ref() -const { current, data, search } = useModelSearch() +const { current, currentModel, data, search } = useModelSearch() const searchModelsByUrl = async () => { if (modelUrl.value) { diff --git a/src/hooks/download.ts b/src/hooks/download.ts index 10c1dcc..fb1f865 100644 --- a/src/hooks/download.ts +++ b/src/hooks/download.ts @@ -4,7 +4,7 @@ import { socket } from 'hooks/socket' import { defineStore } from 'hooks/store' import { useToast } from 'hooks/toast' import { bytesToSize } from 'utils/common' -import { onBeforeMount, onMounted, ref } from 'vue' +import { onBeforeMount, onMounted, ref, watch } from 'vue' import { useI18n } from 'vue-i18n' export const useDownload = defineStore('download', (store) => { @@ -375,6 +375,7 @@ export const useModelSearch = () => { const { toast } = useToast() const data = ref<(SelectOptions & { item: VersionModel })[]>([]) const current = ref() + const currentModel = ref() const handleSearchByUrl = async (url: string) => { if (!url) { @@ -406,6 +407,7 @@ export const useModelSearch = () => { }, })) current.value = data.value[0]?.value + currentModel.value = data.value[0]?.item if (resData.length === 0) { toast.add({ @@ -430,5 +432,11 @@ export const useModelSearch = () => { .finally(() => loading.hide()) } - return { data, current, search: handleSearchByUrl } + watch(current, () => { + currentModel.value = data.value.find( + (option) => option.value === current.value, + )?.item + }) + + return { data, current, currentModel, search: handleSearchByUrl } }