refactor(setting): 移除防抖时间

This commit is contained in:
jxxghp
2024-11-04 12:43:52 +08:00
parent e3ce4196fe
commit 6327649501
10 changed files with 112 additions and 169 deletions

View File

@@ -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({

View File

@@ -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<TransferDirectoryConf[]>([])
@@ -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() {

View File

@@ -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<NotificationConf[]>([])
// 防抖时间
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(() => {

View File

@@ -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<CustomRule[]>([])
@@ -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(() => {

View File

@@ -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<number[]>([])
// 系统设置
const SystemSettings = ref<any>({
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() {

View File

@@ -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<any>({
@@ -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个小时',
]"
/>
</VCol>

View File

@@ -1,10 +1,6 @@
<script lang="ts" setup>
import { useToast } from 'vue-toast-notification'
import api from '@/api'
import debounce from 'lodash/debounce'
// 防抖时间
const debounceTime = 500
// 提示框
const $toast = useToast()
@@ -31,9 +27,9 @@ const siteSetting = ref<any>({
COOKIECLOUD_ENABLE_LOCAL: false,
COOKIECLOUD_BLACKLIST: '',
},
Site:{
Site: {
SITEDATA_REFRESH_INTERVAL: 0,
}
},
})
// 同步间隔下拉框
@@ -58,7 +54,7 @@ const SiteDataRefreshIntervalItems = [
]
// 重置站点
const resetSites = debounce(async () => {
async function resetSites() {
try {
resetSitesDisabled.value = true
resetSitesText.value = '正在重置...'
@@ -72,7 +68,7 @@ const resetSites = debounce(async () => {
} catch (error) {
console.log(error)
}
}, debounceTime)
}
// 加载站点设置
async function loadSiteSettings() {
@@ -86,8 +82,10 @@ async function loadSiteSettings() {
if (result.data.hasOwnProperty(key)) {
v = result.data[key]
// 空字符串转为null避免空字符串导致前端显示问题
if (v === '') { v = null }
(siteSetting.value[sectionKey] as any)[key] = v
if (v === '') {
v = null
}
;(siteSetting.value[sectionKey] as any)[key] = v
}
})
}
@@ -98,7 +96,7 @@ async function loadSiteSettings() {
}
// 调用API保存设置
const saveSiteSetting = debounce(async (value: { [key: string]: any }) => {
async function saveSiteSetting(value: { [key: string]: any }) {
console.log(`正在保存设置:${JSON.stringify(value)}`)
try {
const result: { [key: string]: any } = await api.post('system/env', value)
@@ -109,7 +107,7 @@ const saveSiteSetting = debounce(async (value: { [key: string]: any }) => {
console.log(error)
$toast.error('保存设置失败!')
}
}, debounceTime)
}
// 加载数据
onMounted(() => {
@@ -197,7 +195,7 @@ onMounted(() => {
</VForm>
</VCardText>
<VCardText>
<VForm @submit.prevent="() => {}">
<VForm @submit.prevent="() => {}">
<div class="d-flex flex-wrap gap-4 mt-4">
<VBtn type="submit" @click="saveSiteSetting(siteSetting.CookieCloud)"> 保存 </VBtn>
</div>

View File

@@ -44,9 +44,6 @@ const SystemSettings = ref<any>({
},
})
// 防抖时间
const debounceTime = 500
// 高级设置弹窗
const isAdvancedSystemSettingsDialogOpen = ref(false)
const isAdvancedNetworkSettingsDialogOpen = ref(false)
@@ -110,18 +107,18 @@ async function saveSystemSetting(value: { [key: string]: any }) {
}
// 保存系统设置
const saveSystemSettings = debounce(async () => {
async function saveSystemSettings() {
const Settings = { ...SystemSettings.value.Basis, ...SystemSettings.value.Advanced }
await saveSystemSetting(Settings)
}, debounceTime)
}
// 保存网络设置
const saveNetworkSettings = debounce(async () => {
async function saveNetworkSettings() {
const Settings = { ...SystemSettings.value.Network, ...SystemSettings.value.AdvancedNetwork }
// 查找PROXY_HOST并删除避免意外覆盖
if (Settings.PROXY_HOST) delete Settings.PROXY_HOST
await saveSystemSetting(Settings)
}, debounceTime)
}
// 高级设置变化,等待保存
function saveAdvancedSettings(Settings: any, key: string) {

View File

@@ -1,10 +1,6 @@
<script lang="ts" setup>
import {useToast} from 'vue-toast-notification'
import api from "@/api"
import debounce from 'lodash/debounce'
// 防抖时间
const debounceTime = 500
import { useToast } from 'vue-toast-notification'
import api from '@/api'
// 提示框
const $toast = useToast()
@@ -36,7 +32,7 @@ async function loadSystemSettings() {
if (v === '') {
v = null
}
(SystemSettings.value[sectionKey] as any)[key] = v
;(SystemSettings.value[sectionKey] as any)[key] = v
}
})
}
@@ -47,7 +43,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) {
@@ -58,7 +54,7 @@ const saveSystemSettings = debounce(async (value: any) => {
} catch (error) {
console.log(error)
}
}, debounceTime)
}
// 重载系统生效配置
async function reloadSystem() {
@@ -74,19 +70,21 @@ async function reloadSystem() {
}
// 恢复电影设置默认值
const loadDefaultMovieSetting = debounce(async () => {
SystemSettings.value.Basis.MOVIE_RENAME_FORMAT = '{{title}}{% if year %} ({{year}}){% endif %}/{{title}}{% if year %} ({{year}}){% endif %}{% if part %}-{{part}}{% endif %}{% if videoFormat %} - {{videoFormat}}{% endif %}{{fileExt}}'
}, debounceTime)
async function loadDefaultMovieSetting() {
SystemSettings.value.Basis.MOVIE_RENAME_FORMAT =
'{{title}}{% if year %} ({{year}}){% endif %}/{{title}}{% if year %} ({{year}}){% endif %}{% if part %}-{{part}}{% endif %}{% if videoFormat %} - {{videoFormat}}{% endif %}{{fileExt}}'
}
// 恢复电视剧设置默认值
const loadDefaultTVSetting = debounce(async () => {
SystemSettings.value.Basis.TV_RENAME_FORMAT = '{{title}}{% if year %} ({{year}}){% endif %}/Season {{season}}/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}{{fileExt}}'
}, debounceTime)
async function loadDefaultTVSetting() {
SystemSettings.value.Basis.TV_RENAME_FORMAT =
'{{title}}{% if year %} ({{year}}){% endif %}/Season {{season}}/{{title}} - {{season_episode}}{% if part %}-{{part}}{% endif %}{% if episode %} - 第 {{episode}} 集{% endif %}{{fileExt}}'
}
// 数据源
const sourceItems = [
{ "title": "TheMovieDb", "value": "themoviedb"},
{ "title": "豆瓣", "value": "douban" }
{ 'title': 'TheMovieDb', 'value': 'themoviedb' },
{ 'title': '豆瓣', 'value': 'douban' },
]
// 加载数据
@@ -140,10 +138,7 @@ onMounted(() => {
min="0"
type="number"
suffix="小时"
:rules="[
v => v === 0 || !!v || '请输入元数据缓存时间',
v => v >= 0 || '元数据缓存时间必须大于等于0'
]"
:rules="[(v: any) => v === 0 || !!v || '请输入元数据缓存时间', (v: any) => v >= 0 || '元数据缓存时间必须大于等于0']"
/>
</VCol>
<VCol cols="12">
@@ -191,4 +186,3 @@ onMounted(() => {
</VCol>
</VRow>
</template>

View File

@@ -7,7 +7,6 @@ import type { User } from '@/api/types'
import avatar1 from '@images/avatars/avatar-1.png'
import { useDisplay } from 'vuetify'
import store from '@/store'
import { debounce } from 'lodash'
// 显示器宽度
const display = useDisplay()
@@ -22,9 +21,6 @@ const $toast = useToast()
const refInputEl = ref<HTMLElement>()
// 防抖时间
const debounceTime = 500
// 正在保存
const isSaving = ref(false)
@@ -79,8 +75,8 @@ function changeAvatar(file: Event) {
const maxSize = 800 * 1024
// 检查文件是否为图片
if (!allowedTypes.includes(selectedFile.type)) {
$toast.error('上传的文件不符合要求,请重新选择头像');
return;
$toast.error('上传的文件不符合要求,请重新选择头像')
return
}
// 检查文件大小
if (selectedFile.size > maxSize) {
@@ -118,15 +114,15 @@ async function loadAccountInfo() {
if (!accountInfo.value.avatar) {
accountInfo.value.avatar = avatar1
}
currentAvatar.value = accountInfo.value.avatar
currentUserName.value = accountInfo.value.name
currentAvatar.value = accountInfo.value.avatar
currentUserName.value = accountInfo.value.name
} catch (error) {
console.log(error)
}
}
// 保存用户信息
const saveAccountInfo = debounce(async () => {
async function saveAccountInfo() {
if (isSaving.value) {
$toast.error('正在保存中,请稍后...')
return
@@ -177,7 +173,7 @@ const saveAccountInfo = debounce(async () => {
console.log(error)
}
isSaving.value = false
}, debounceTime)
}
// 为当前用户获取Otp Uri
async function getOtpUri() {
@@ -245,7 +241,7 @@ watch(
() => store.state.auth.avatar,
() => {
currentAvatar.value = store.state.auth.avatar
}
},
)
</script>
@@ -306,21 +302,10 @@ watch(
<VForm class="mt-6">
<VRow>
<VCol md="6" cols="12">
<VTextField
v-model="currentUserName"
density="comfortable"
readonly
label="用户名"
/>
<VTextField v-model="currentUserName" density="comfortable" readonly label="用户名" />
</VCol>
<VCol cols="12" md="6">
<VTextField
v-model="accountInfo.email"
density="comfortable"
clearable
label="邮箱"
type="email"
/>
<VTextField v-model="accountInfo.email" density="comfortable" clearable label="邮箱" type="email" />
</VCol>
<VCol cols="12" md="6">
<VTextField
@@ -397,10 +382,7 @@ watch(
<VRow>
<!-- 👉 Form Actions -->
<VCol cols="12" class="d-flex flex-wrap gap-4">
<VBtn
@click="saveAccountInfo"
:disabled="isSaving"
>
<VBtn @click="saveAccountInfo" :disabled="isSaving">
<span v-if="isSaving">保存中...</span>
<span v-else>保存</span>
</VBtn>