Skip to content

Commit

Permalink
Merge pull request #189 from Aqr-K/dev-directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp authored Sep 26, 2024
2 parents cf6b6dd + 6301cb2 commit 7350233
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 13 deletions.
84 changes: 77 additions & 7 deletions src/components/cards/DirectoryCard.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<script lang="ts" setup>
import type { TransferDirectoryConf } from '@/api/types'
import { VTextField } from 'vuetify/lib/components/index.mjs'
import { useToast } from 'vue-toast-notification'
import api from "@/api";
import { nextTick } from 'vue'
// 输入参数
const props = defineProps({
Expand Down Expand Up @@ -46,12 +49,66 @@ const transferSourceItems = [
]
// 整理方式下拉字典
const transferTypeItems = [
{ title: '复制', value: 'copy' },
{ title: '移动', value: 'move' },
{ title: '硬链接', value: 'link' },
{ title: '软链接', value: 'softlink' },
]
const transferTypeItems = ref<{ title: string; value: string }[]>([])
// 调用API查询支持的整理方式
async function loadTransferTypeItems() {
// 参数不全时不查询
if (!props.directory.library_storage || !props.directory.storage) return
try {
// 下载器储存整理方法
const storage_res = await api.get(`storage/transtype/${props.directory.storage}`)
const storage_transtype = (storage_res as any).transtype;
// 媒体库储存整理方法
const library_storage_res = await api.get(`storage/transtype/${props.directory.library_storage}`)
const library_storage_transtype = (library_storage_res as any).transtype;
// 为空终止
if (!library_storage_transtype || !storage_transtype) return
// 取并集
const transtype: { [key: string]: string } = {};
Object.keys(storage_transtype).forEach(key => {
if (key in library_storage_transtype) {
transtype[key] = storage_transtype[key];
}
})
// 非空时设置整理方式下拉字典
if (transtype && Object.keys(transtype).length > 0) {
transferTypeItems.value = Object.keys(transtype).map(key => ({
title: transtype[key],
value: key,
}))
// 如果整理方式下拉字典不为空,且当前值不在新的transferTypeItems里,则设置整理方式为第一个
if (transferTypeItems.value.length > 0 && !transferTypeItems.value.find(item => item.value === props.directory.transfer_type)) {
nextTick(() => {
props.directory.transfer_type = transferTypeItems.value[0].value
})
}
// 如果整理方式下拉字典为空,清空整理方式
if (transferTypeItems.value.length === 0) {
props.directory.transfer_type = ''
}
} else {
// 无可用整理方式,清除已选值
transferTypeItems.value = []
props.directory.transfer_type = ''
}
} catch (e) {
console.log(e)
}
}
// 整理方式无数据提示
const computedNoDataText = computed(() => {
if (!props.directory.library_storage && !props.directory.storage) {
return '无可用整理方式!请先选择下载器储存与媒体库储存!'
} else if (!props.directory.library_storage) {
return '无可用整理方式!请先选择媒体库储存!'
} else if (!props.directory.storage) {
return '无可用整理方式!请先选择下载器储存!'
} else {
return '选择的存储没有支持的整理方法!'
}
})
// 覆盖模式下拉字典
const overwriteModeItems = [
Expand Down Expand Up @@ -93,6 +150,15 @@ const getCategories = computed(() => {
if (!props.categories || !props.categories[props.directory?.media_type ?? '']) return default_value
return default_value.concat(props.categories[props.directory.media_type ?? ''])
})
// 监听 下载储存与媒体库储存 变化,重新加载整理方式下拉字典
watch([() => props.directory.library_storage, () => props.directory.storage],
([newLibraryStorage, newStorage], [oldLibraryStorage, oldStorage]) => {
if (newLibraryStorage !== oldLibraryStorage || newStorage !== oldStorage) {
loadTransferTypeItems();
}
}, { immediate: true });
</script>

<template>
Expand Down Expand Up @@ -132,7 +198,10 @@ const getCategories = computed(() => {
/>
</VCol>
<VCol cols="4">
<VSelect v-model="props.directory.storage" variant="underlined" :items="storageItems" label="下载存储" />
<VSelect v-model="props.directory.storage"
variant="underlined"
:items="storageItems"
label="下载存储" />
</VCol>
<VCol cols="8">
<VPathField @update:modelValue="updateDownloadPath">
Expand Down Expand Up @@ -171,6 +240,7 @@ const getCategories = computed(() => {
variant="underlined"
:items="transferTypeItems"
label="整理方式"
:no-data-text="computedNoDataText"
/>
</VCol>
<VCol cols="8">
Expand Down
11 changes: 10 additions & 1 deletion src/views/setting/AccountSettingDirectory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ async function loadDirectories() {
async function saveDirectories() {
orderDirectoryCards()
try {
const names = directories.value.map(item => item.name)
if (new Set(names).size !== names.length) {
$toast.error('存在重复目录名称!无法保存,请修改!')
return
}
const result: { [key: string]: any } = await api.post('system/setting/Directories', directories.value)
if (result.success) {
$toast.success('目录设置保存成功')
Expand All @@ -93,8 +98,12 @@ async function saveDirectories() {
// 添加媒体库目录
function addDirectory() {
let name = `目录${directories.value.length + 1}`;
while (directories.value.some(item => item.name === name)) {
name = `目录${parseInt(name.split('目录')[1]) + 1}`;
}
directories.value.push({
name: `目录${directories.value.length + 1}`,
name: name,
storage: 'local',
download_path: '',
priority: -1,
Expand Down
18 changes: 15 additions & 3 deletions src/views/setting/AccountSettingRule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@ async function saveCustomRules() {
// 添加自定义规则
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}`;
}
let name = `规则${customRules.value.length + 1}`;
while (customRules.value.some(item => item.name === name)) {
name = `规则${parseInt(name.split('规则')[1]) + 1}`;
}
customRules.value.push({
id: `RULE${customRules.value.length + 1}`,
name: `规则${customRules.value.length + 1}`,
id: id,
name: name,
include: '',
exclude: '',
})
Expand Down Expand Up @@ -89,8 +97,12 @@ async function saveFilterRuleGroups() {
// 添加规则组
function addFilterRuleGroup() {
let name = `规则组${filterRuleGroups.value.length + 1}`;
while (filterRuleGroups.value.some(item => item.name === name)) {
name = `规则组${parseInt(name.split('规则组')[1]) + 1}`;
}
filterRuleGroups.value.push({
name: `规则组${filterRuleGroups.value.length + 1}`,
name: name,
rule_string: '',
media_type: '',
category: '',
Expand Down
12 changes: 10 additions & 2 deletions src/views/setting/AccountSettingSystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ async function saveSystemSetting() {
// 添加下载器
function addDownloader(downloader: string) {
let name = `下载器${downloaders.value.length + 1}`;
while (downloaders.value.some(item => item.name === name)) {
name = `下载器${parseInt(name.split('下载器')[1]) + 1}`;
}
downloaders.value.push({
name: `下载器${downloaders.value.length + 1}`,
name: name,
type: downloader,
default: false,
enabled: false,
Expand All @@ -136,8 +140,12 @@ function onDownloaderChange(downloader: DownloaderConf) {
// 添加媒体服务器
function addMediaServer(mediaserver: string) {
let name = `服务器${mediaServers.value.length + 1}`;
while (mediaServers.value.some(item => item.name === name)) {
name = `服务器${parseInt(name.split('服务器')[1]) + 1}`;
}
mediaServers.value.push({
name: `服务器${mediaServers.value.length + 1}`,
name: name,
type: mediaserver,
enabled: false,
config: {},
Expand Down

0 comments on commit 7350233

Please sign in to comment.