From 6327649501e6c3280981a5f32e5e924b7833fb46 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Mon, 4 Nov 2024 12:43:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor(setting):=20=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E9=98=B2=E6=8A=96=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/dialog/UserAddEditDialog.vue | 16 ++--- src/views/setting/AccountSettingDirectory.vue | 20 +++--- .../setting/AccountSettingNotification.vue | 20 +++--- src/views/setting/AccountSettingRule.vue | 28 ++++---- src/views/setting/AccountSettingSearch.vue | 22 +++---- src/views/setting/AccountSettingService.vue | 64 +++++++++---------- src/views/setting/AccountSettingSite.vue | 24 ++++--- src/views/setting/AccountSettingSystem.vue | 11 ++-- src/views/setting/AccountSettingTransfer.vue | 38 +++++------ src/views/user/UserProfileView.vue | 38 +++-------- 10 files changed, 112 insertions(+), 169 deletions(-) diff --git a/src/components/dialog/UserAddEditDialog.vue b/src/components/dialog/UserAddEditDialog.vue index cf42e778..03bfff9f 100644 --- a/src/components/dialog/UserAddEditDialog.vue +++ b/src/components/dialog/UserAddEditDialog.vue @@ -6,7 +6,6 @@ import api from '@/api' import { useDisplay } from 'vuetify' import avatar1 from '@images/avatars/avatar-1.png' import store from '@/store' -import { debounce } from 'lodash' // 显示器宽度 const display = useDisplay() @@ -24,9 +23,6 @@ const props = defineProps({ oper: String, }) -// 防抖时间 -const debounceTime = 500 - // 当前登录用户名称 const currentLoginUser = store.state.auth.userName @@ -87,8 +83,8 @@ function changeAvatar(file: Event) { const maxSize = 800 * 1024 // 检查文件是否为图片 if (!allowedTypes.includes(selectedFile.type)) { - $toast.error('上传的文件不符合要求,请重新选择头像'); - return; + $toast.error('上传的文件不符合要求,请重新选择头像') + return } // 检查文件大小 if (selectedFile.size > maxSize) { @@ -133,7 +129,7 @@ async function fetchUserInfo() { } // 调用API 新增用户 -const addUser = debounce(async () => { +async function addUser() { if (isAdding.value) { $toast.error(`正在创建【${userForm.value.name}】用户,请稍后`) return @@ -172,10 +168,10 @@ const addUser = debounce(async () => { } doneNProgress() isAdding.value = false -}, debounceTime) +} // 调用API更新用户信息 -const updateUser = debounce(async () => { +async function updateUser() { if (isUpdating.value) { $toast.error(`正在更新【${userForm.value.name}】用户,请稍后`) return @@ -232,7 +228,7 @@ const updateUser = debounce(async () => { } doneNProgress() isUpdating.value = false -}, debounceTime) +} // 用户状态转换,true/false转换为1/0 const userStatus = computed({ diff --git a/src/views/setting/AccountSettingDirectory.vue b/src/views/setting/AccountSettingDirectory.vue index 381b973d..8ea9cc8f 100644 --- a/src/views/setting/AccountSettingDirectory.vue +++ b/src/views/setting/AccountSettingDirectory.vue @@ -7,10 +7,6 @@ import api from '@/api' import { TransferDirectoryConf, StorageConf } from '@/api/types' import DirectoryCard from '@/components/cards/DirectoryCard.vue' import StorageCard from '@/components/cards/StorageCard.vue' -import debounce from 'lodash/debounce' - -// 防抖时间 -const debounceTime = 500 // 所有下载目录 const directories = ref([]) @@ -55,7 +51,7 @@ async function loadStorages() { } // 保存存储 -const saveStorages = debounce(async () => { +async function saveStorages() { try { const result: { [key: string]: any } = await api.post('system/setting/Storages', storages.value) if (result.success) $toast.success('存储设置保存成功') @@ -63,7 +59,7 @@ const saveStorages = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 修改后生效 async function updatedStorage() { @@ -81,7 +77,7 @@ async function loadDirectories() { } // 保存目录 -const saveDirectories = debounce(async () => { +async function saveDirectories() { orderDirectoryCards() try { const names = directories.value.map(item => item.name) @@ -97,10 +93,10 @@ const saveDirectories = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 添加媒体库目录 -const addDirectory = debounce(() => { +function addDirectory() { let name = `目录${directories.value.length + 1}` while (directories.value.some(item => item.name === name)) { name = `目录${parseInt(name.split('目录')[1]) + 1}` @@ -115,15 +111,15 @@ const addDirectory = debounce(() => { media_category: '', }) orderDirectoryCards() -}, debounceTime) +} // 移除媒体库目录 -const removeDirectory = debounce((directory: TransferDirectoryConf) => { +function removeDirectory(directory: TransferDirectoryConf) { const index = directories.value.indexOf(directory) if (index > -1) { directories.value.splice(index, 1) } -}, debounceTime) +} // 调用API查询自动分类配置 async function loadMediaCategories() { diff --git a/src/views/setting/AccountSettingNotification.vue b/src/views/setting/AccountSettingNotification.vue index e3ad3df2..684b3b7d 100644 --- a/src/views/setting/AccountSettingNotification.vue +++ b/src/views/setting/AccountSettingNotification.vue @@ -4,14 +4,10 @@ import api from '@/api' import draggable from 'vuedraggable' import type { NotificationConf, NotificationSwitchConf } from '@/api/types' import NotificationChannelCard from '@/components/cards/NotificationChannelCard.vue' -import debounce from 'lodash/debounce' // 所有消息渠道 const notifications = ref([]) -// 防抖时间 -const debounceTime = 500 - // 提示框 const $toast = useToast() @@ -63,10 +59,10 @@ async function reloadSystem() { } // 添加通知渠道 -const addNotification = debounce((notification: string) => { - let name = `通知${notifications.value.length + 1}`; +function addNotification(notification: string) { + let name = `通知${notifications.value.length + 1}` while (notifications.value.some(item => item.name === name)) { - name = `通知${parseInt(name.split('通知')[1]) + 1}`; + name = `通知${parseInt(name.split('通知')[1]) + 1}` } notifications.value.push({ name: name, @@ -74,7 +70,7 @@ const addNotification = debounce((notification: string) => { enabled: false, config: {}, }) -}, debounceTime) +} // 移除通知渠道 function removeNotification(notification: NotificationConf) { @@ -93,7 +89,7 @@ async function loadNotificationSetting() { } // 调用API保存通知设置 -const saveNotificationSetting = debounce(async () => { +async function saveNotificationSetting() { try { const result: { [key: string]: any } = await api.post('system/setting/Notifications', notifications.value) if (result.success) { @@ -103,7 +99,7 @@ const saveNotificationSetting = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 通知渠道设置变化时赋值 function changNotificationSetting(notification: NotificationConf, name: string) { @@ -122,7 +118,7 @@ async function loadNotificationSwitchs() { } // 保存消息类型开关 -const saveNotificationSwitchs = debounce(async () => { +async function saveNotificationSwitchs() { try { const result: { [key: string]: any } = await api.post( 'system/setting/NotificationSwitchs', @@ -133,7 +129,7 @@ const saveNotificationSwitchs = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 加载数据 onMounted(() => { diff --git a/src/views/setting/AccountSettingRule.vue b/src/views/setting/AccountSettingRule.vue index 317ace9f..54f5adfd 100644 --- a/src/views/setting/AccountSettingRule.vue +++ b/src/views/setting/AccountSettingRule.vue @@ -9,10 +9,6 @@ import { CustomRule, FilterRuleGroup } from '@/api/types' import CustomerRuleCard from '@/components/cards/CustomRuleCard.vue' import FilterRuleGroupCard from '@/components/cards/FilterRuleGroupCard.vue' import ImportCodeDialog from '@/components/dialog/ImportCodeDialog.vue' -import debounce from 'lodash/debounce' - -// 防抖时间 -const debounceTime = 1 // 自定义规则列表 const customRules = ref([]) @@ -56,7 +52,7 @@ async function loadMediaCategories() { } // 保存自定义规则 -const saveCustomRules = debounce(async () => { +async function saveCustomRules() { // 检查是否存在空id规则 if (customRules.value.some(item => !item.id)) { $toast.error('存在空ID的规则,无法保存,请修改!') @@ -87,10 +83,10 @@ const saveCustomRules = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 添加自定义规则 -const addCustomRule = debounce(async () => { +async function addCustomRule() { let id = `RULE${customRules.value.length + 1}` while (customRules.value.some(item => item.id === id)) { id = `RULE${parseInt(id.split('RULE')[1]) + 1}` @@ -105,7 +101,7 @@ const addCustomRule = debounce(async () => { include: '', exclude: '', }) -}, debounceTime) +} // 移除自定义规则 function removeCustomRule(rule: CustomRule) { @@ -124,7 +120,7 @@ async function queryFilterRuleGroups() { } // 保存规则组 -const saveFilterRuleGroups = debounce(async () => { +async function saveFilterRuleGroups() { // 检查是否存在空的规则组名称 if (filterRuleGroups.value.some(item => !item.name)) { $toast.error('存在空名字的规则组!无法保存,请修改!') @@ -143,10 +139,10 @@ const saveFilterRuleGroups = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 添加规则组 -const addFilterRuleGroup = debounce(() => { +function addFilterRuleGroup() { let name = `规则组${filterRuleGroups.value.length + 1}` while (filterRuleGroups.value.some(item => item.name === name)) { name = `规则组${parseInt(name.split('规则组')[1]) + 1}` @@ -157,10 +153,10 @@ const addFilterRuleGroup = debounce(() => { media_type: '', category: '', }) -}, debounceTime) +} // 分享规则 -const shareRules = debounce((rules: CustomRule[] | FilterRuleGroup[]) => { +function shareRules(rules: CustomRule[] | FilterRuleGroup[]) { if (!rules || rules.length === 0) return // 将卡片规则接装为字符串 @@ -173,7 +169,7 @@ const shareRules = debounce((rules: CustomRule[] | FilterRuleGroup[]) => { } catch (error) { $toast.error('优先级规则复制失败!') } -}, debounceTime) +} // 导入规则 async function importRules(ruleType: string) { @@ -256,7 +252,7 @@ async function queryCustomRules() { } // 保存种子优先规则 -const saveTorrentPriority = debounce(async () => { +async function saveTorrentPriority() { try { const result: { [key: string]: any } = await api.post( 'system/setting/TorrentsPriority', @@ -267,7 +263,7 @@ const saveTorrentPriority = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 加载数据 onMounted(() => { diff --git a/src/views/setting/AccountSettingSearch.vue b/src/views/setting/AccountSettingSearch.vue index 5fd0f713..6745d50c 100644 --- a/src/views/setting/AccountSettingSearch.vue +++ b/src/views/setting/AccountSettingSearch.vue @@ -2,10 +2,6 @@ import { useToast } from 'vue-toast-notification' import api from '@/api' import type { FilterRuleGroup, Site } from '@/api/types' -import debounce from 'lodash/debounce' - -// 防抖时间 -const debounceTime = 500 // 提示框 const $toast = useToast() @@ -18,9 +14,7 @@ const selectedSites = ref([]) // 系统设置 const SystemSettings = ref({ - Basis: { - - }, + Basis: {}, Advanced: { SEARCH_MULTIPLE_NAME: false, DOWNLOAD_SUBTITLE: false, @@ -95,7 +89,7 @@ async function querySelectedSites() { } // 保存用户选中的站点 -const saveSelectedSites = debounce(async () => { +async function saveSelectedSites() { try { // 用户名密码 const result: { [key: string]: any } = await api.post('system/setting/IndexerSites', selectedSites.value) @@ -105,7 +99,7 @@ const saveSelectedSites = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 调用API查询设置 async function loadSearchSetting() { @@ -120,7 +114,7 @@ async function loadSearchSetting() { } // 调用API保存设置 -const saveSearchSetting = debounce(async () => { +async function saveSearchSetting() { try { const result1: { [key: string]: any } = await api.post( 'system/setting/SEARCH_SOURCE', @@ -141,7 +135,7 @@ const saveSearchSetting = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 加载系统设置 async function loadSystemSettings() { @@ -158,7 +152,7 @@ async function loadSystemSettings() { if (v === '') { v = null } - (SystemSettings.value[sectionKey] as any)[key] = v + ;(SystemSettings.value[sectionKey] as any)[key] = v } }) } @@ -169,7 +163,7 @@ async function loadSystemSettings() { } // 保存设置 -const saveSystemSettings = debounce(async (value: any) => { +async function saveSystemSettings(value: any) { try { const result: { [key: string]: any } = await api.post('system/env', value) if (result.success) { @@ -182,7 +176,7 @@ const saveSystemSettings = debounce(async (value: any) => { } catch (error) { console.log(error) } -}, debounceTime) +} // 重载系统生效配置 async function reloadSystem() { diff --git a/src/views/setting/AccountSettingService.vue b/src/views/setting/AccountSettingService.vue index dd4391c2..2b3d154e 100644 --- a/src/views/setting/AccountSettingService.vue +++ b/src/views/setting/AccountSettingService.vue @@ -7,10 +7,6 @@ import api from '@/api' import { DownloaderConf, MediaServerConf } from '@/api/types' import DownloaderCard from '@/components/cards/DownloaderCard.vue' import MediaServerCard from '@/components/cards/MediaServerCard.vue' -import debounce from 'lodash/debounce' - -// 防抖时间 -const debounceTime = 500 // 系统设置项 const SystemSettings = ref({ @@ -51,13 +47,13 @@ async function reloadSystem() { } // 调用API保存下载器设置 -const saveDownloaderSetting = debounce(async () => { +async function saveDownloaderSetting() { try { // 提取启用的下载器 - const enabledDownloaders = downloaders.value.filter(item => item.enabled); + const enabledDownloaders = downloaders.value.filter(item => item.enabled) // 有启动的下载器时 if (enabledDownloaders.length > 0) { - downloaders.value = handleDefaultDownloaders(enabledDownloaders, downloaders.value); + downloaders.value = handleDefaultDownloaders(enabledDownloaders, downloaders.value) } const result: { [key: string]: any } = await api.post('system/setting/Downloaders', downloaders.value) if (result.success) $toast.success('下载器设置保存成功') @@ -68,22 +64,22 @@ const saveDownloaderSetting = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 处理默认下载器状态 function handleDefaultDownloaders(enabledDownloaders: any[], downloaders: any[]) { - const enabledDefaultDownloader = enabledDownloaders.find(item => item.default); + 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 }; + $toast.info(`未设置默认下载器,已将【${item.name}】作为默认下载器`) + return { ...item, default: true } } // 清除其他下载器的默认下载器状态 - return {...item, default: false }; - }); + return { ...item, default: false } + }) } - return downloaders; + return downloaders } // 调用API查询媒体服务器设置 @@ -97,7 +93,7 @@ async function loadMediaServerSetting() { } // 调用API保存媒体服务器设置 -const saveMediaServerSetting = debounce(async () => { +async function saveMediaServerSetting() { try { const result: { [key: string]: any } = await api.post('system/setting/MediaServers', mediaServers.value) if (result.success) $toast.success('媒体服务器设置保存成功') @@ -108,16 +104,14 @@ const saveMediaServerSetting = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 加载系统设置 async function loadSystemSettings() { try { const result: { [key: string]: any } = await api.get('system/env') if (result.success) { - const { - MEDIASERVER_SYNC_INTERVAL, - } = result.data + const { MEDIASERVER_SYNC_INTERVAL } = result.data SystemSettings.value = { MEDIASERVER_SYNC_INTERVAL, } @@ -128,7 +122,7 @@ async function loadSystemSettings() { } // 调用API保存系统设置 -const saveSystemSetting = debounce(async () => { +async function saveSystemSetting() { try { const result: { [key: string]: any } = await api.post('system/env', SystemSettings.value) @@ -137,13 +131,13 @@ const saveSystemSetting = debounce(async () => { } catch (error) { console.log(error) } -}, debounceTime) +} // 添加下载器 function addDownloader(downloader: string) { - let name = `下载器${downloaders.value.length + 1}`; + let name = `下载器${downloaders.value.length + 1}` while (downloaders.value.some(item => item.name === name)) { - name = `下载器${parseInt(name.split('下载器')[1]) + 1}`; + name = `下载器${parseInt(name.split('下载器')[1]) + 1}` } downloaders.value.push({ name: name, @@ -155,10 +149,10 @@ function addDownloader(downloader: string) { } // 删除下载器 -const removeDownloader = debounce((ele: DownloaderConf) => { +function removeDownloader(ele: DownloaderConf) { const index = downloaders.value.indexOf(ele) downloaders.value.splice(index, 1) -}, debounceTime) +} // 下载器变化 function onDownloaderChange(downloader: DownloaderConf, name: string) { @@ -167,10 +161,10 @@ function onDownloaderChange(downloader: DownloaderConf, name: string) { } // 添加媒体服务器 -const addMediaServer = debounce( (mediaserver: string) => { - let name = `服务器${mediaServers.value.length + 1}`; +function addMediaServer(mediaserver: string) { + let name = `服务器${mediaServers.value.length + 1}` while (mediaServers.value.some(item => item.name === name)) { - name = `服务器${parseInt(name.split('服务器')[1]) + 1}`; + name = `服务器${parseInt(name.split('服务器')[1]) + 1}` } mediaServers.value.push({ name: name, @@ -178,13 +172,13 @@ const addMediaServer = debounce( (mediaserver: string) => { enabled: false, config: {}, }) -}, debounceTime) +} // 删除媒体服务器 -const removeMediaServer = debounce((ele: MediaServerConf) => { +function removeMediaServer(ele: MediaServerConf) { const index = mediaServers.value.indexOf(ele) if (index !== -1) mediaServers.value.splice(index, 1) -}, debounceTime) +} // 变更媒体服务器 function onMediaServerChange(mediaserver: MediaServerConf, name: string) { @@ -229,11 +223,11 @@ onDeactivated(() => { suffix="小时" type="number" min="1" - style="width: fit-content" + style="inline-size: fit-content" :rules="[ - v => !!v || '必选项,请勿留空', - v => !isNaN(v) || '仅支持输入数字,请勿输入其他字符', - v => v >= 1 || '间隔不能小于1个小时', + (v: any) => !!v || '必选项,请勿留空', + (v: any) => !isNaN(v) || '仅支持输入数字,请勿输入其他字符', + (v: any) => v >= 1 || '间隔不能小于1个小时', ]" /> diff --git a/src/views/setting/AccountSettingSite.vue b/src/views/setting/AccountSettingSite.vue index f6243b94..91547220 100644 --- a/src/views/setting/AccountSettingSite.vue +++ b/src/views/setting/AccountSettingSite.vue @@ -1,10 +1,6 @@ @@ -306,21 +302,10 @@ watch( - + - + - + 保存中... 保存