From 0e116ad1b94ad4fbeaf0a9833fcb5c924313b609 Mon Sep 17 00:00:00 2001 From: Aqr-K <95741669+Aqr-K@users.noreply.github.com> Date: Wed, 2 Oct 2024 02:36:02 +0800 Subject: [PATCH] feat(downloader): Default downloader automatic selection and checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 增加保存时的默认下载器不存在的自动选择与去重 --- src/views/setting/AccountSettingSystem.vue | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/views/setting/AccountSettingSystem.vue b/src/views/setting/AccountSettingSystem.vue index a7279ef9..332bd704 100644 --- a/src/views/setting/AccountSettingSystem.vue +++ b/src/views/setting/AccountSettingSystem.vue @@ -49,6 +49,12 @@ async function reloadSystem() { // 调用API保存下载器设置 async function saveDownloaderSetting() { try { + // 提取启用的下载器 + const enabledDownloaders = downloaders.value.filter(item => item.enabled); + // 有启动的下载器时 + if (enabledDownloaders.length > 0) { + downloaders.value = handleDefaultDownloaders(enabledDownloaders, downloaders.value); + } const result: { [key: string]: any } = await api.post('system/setting/Downloaders', downloaders.value) if (result.success) $toast.success('下载器设置保存成功') else $toast.error('下载器设置保存失败!') @@ -60,6 +66,22 @@ async function saveDownloaderSetting() { } } +// 处理默认下载器状态 +function handleDefaultDownloaders(enabledDownloaders: any[], downloaders: any[]) { + const enabledDefaultDownloader = enabledDownloaders.find(item => item.default); + if (enabledDownloaders.length > 0 && !enabledDefaultDownloader) { + downloaders = downloaders.map(item => { + if (item === enabledDownloaders[0]) { + $toast.info(`未设置默认下载器,已将【${item.name}】作为默认下载器`); + return {...item, default: true }; + } + // 清除其他下载器的默认下载器状态 + return {...item, default: false }; + }); + } + return downloaders; +} + // 调用API查询媒体服务器设置 async function loadMediaServerSetting() { try {