调整存储添加逻辑

This commit is contained in:
jxxghp
2025-07-02 08:58:16 +08:00
parent 7070eb8a7d
commit 8328e51ae0
2 changed files with 44 additions and 6 deletions

View File

@@ -15,7 +15,6 @@ import AlistConfigDialog from '../dialog/AlistConfigDialog.vue'
import { useToast } from 'vue-toastification'
import { isNullOrEmptyObject } from '@/@core/utils'
import { useI18n } from 'vue-i18n'
import { storageIconDict } from '@/api/constants'
import { useDisplay } from 'vuetify'
// 显示器宽度
@@ -163,7 +162,7 @@ function onClose() {
<template>
<div>
<VCard variant="tonal" @click="openStorageDialog">
<VDialogCloseBtn v-if="!storageIconDict[storage.type]" @click="onClose" />
<VDialogCloseBtn @click="onClose" class="absolute top-0 right-0" />
<VCardText class="flex justify-space-between align-center gap-3">
<div class="align-self-start flex-1">
<h5 class="text-h6 mb-1">{{ storage.name }}</h5>

View File

@@ -9,6 +9,7 @@ import DirectoryCard from '@/components/cards/DirectoryCard.vue'
import StorageCard from '@/components/cards/StorageCard.vue'
import ProgressDialog from '@/components/dialog/ProgressDialog.vue'
import { useI18n } from 'vue-i18n'
import { storageAttributes } from '@/api/constants'
const { t } = useI18n()
@@ -33,6 +34,17 @@ const sourceItems = [
{ 'title': '豆瓣', 'value': 'douban' },
]
// 存储选项(排除已添加的)
const storageOptions = computed(() => {
const existingTypes = storages.value.map(storage => storage.type)
return storageAttributes
.filter(item => !existingTypes.includes(item.type))
.map(item => ({
title: t(`storage.${item.type}`),
value: item.type,
}))
})
// 系统设置
const SystemSettings = ref<any>({
Basic: {
@@ -156,10 +168,27 @@ async function loadMediaCategories() {
}
// 添加存储
function addStorage() {
function addStorage(storageType = 'custom') {
let name: string
let type: string
if (storageType === 'custom') {
// 自定义存储需要数字序号
name = `${t(`storage.${storageType}`)} ${storages.value.length + 1}`
while (storages.value.some(item => item.name === name)) {
const num = parseInt(name.match(/\d+$/)?.[0] || '1') + 1
name = `${t(`storage.${storageType}`)} ${num}`
}
type = `custom${storages.value.length + 1}`
} else {
// 预定义存储类型直接使用类型名称
name = t(`storage.${storageType}`)
type = storageType
}
storages.value.push({
name: `${t('storage.custom')} ${storages.value.length + 1}`,
type: `custom${storages.value.length + 1}`,
name: name,
type: type,
config: {},
})
}
@@ -228,8 +257,18 @@ onMounted(() => {
<VBtn type="submit" class="me-2" @click="saveStorages" prepend-icon="mdi-content-save">
{{ t('common.save') }}
</VBtn>
<VBtn color="success" variant="tonal" @click="addStorage">
<VBtn color="success" variant="tonal">
<VIcon icon="mdi-plus" />
<VMenu activator="parent" close-on-content-click>
<VList>
<VListItem v-for="item in storageOptions" :key="item.value" @click="addStorage(item.value)">
<VListItemTitle>{{ item.title }}</VListItemTitle>
</VListItem>
<VListItem @click="addStorage('custom')">
<VListItemTitle>{{ t('storage.custom') }}</VListItemTitle>
</VListItem>
</VList>
</VMenu>
</VBtn>
</div>
</VForm>