mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-06 08:06:43 +08:00
refactor(ReorganizeDialog): 重构目标路径输入组件,移除不必要的目录加载逻辑
This commit is contained in:
@@ -6,7 +6,7 @@ import { storageOptions } from '@/api/constants'
|
|||||||
import { numberValidator } from '@/@validators'
|
import { numberValidator } from '@/@validators'
|
||||||
import { useDisplay } from 'vuetify'
|
import { useDisplay } from 'vuetify'
|
||||||
import ProgressDialog from './ProgressDialog.vue'
|
import ProgressDialog from './ProgressDialog.vue'
|
||||||
import { FileItem, TransferDirectoryConf } from '@/api/types'
|
import { FileItem } from '@/api/types'
|
||||||
|
|
||||||
// 显示器宽度
|
// 显示器宽度
|
||||||
const display = useDisplay()
|
const display = useDisplay()
|
||||||
@@ -85,39 +85,13 @@ const transferForm = reactive({
|
|||||||
from_history: false,
|
from_history: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 所有媒体库目录
|
// 下载路径更新
|
||||||
const directories = ref<TransferDirectoryConf[]>([])
|
function updateTargetPath(value: string) {
|
||||||
|
if (value !== transferForm.target_path) {
|
||||||
// 查询目录
|
transferForm.target_path = value // 仅在值真正改变时更新
|
||||||
async function loadDirectories() {
|
|
||||||
try {
|
|
||||||
const result: { [key: string]: any } = await api.get('system/setting/Directories')
|
|
||||||
directories.value = result.data?.value ?? []
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 目的目录下拉框
|
|
||||||
const targetDirectories = computed(() => {
|
|
||||||
return directories.value.map(item => item.library_path)
|
|
||||||
})
|
|
||||||
|
|
||||||
// 监听目的路径变化,配置默认值
|
|
||||||
watch(
|
|
||||||
() => transferForm.target_path,
|
|
||||||
async newPath => {
|
|
||||||
if (newPath) {
|
|
||||||
const directory = directories.value.find(item => item.library_path === newPath)
|
|
||||||
if (directory) {
|
|
||||||
transferForm.target_storage = directory.storage ?? 'local'
|
|
||||||
transferForm.transfer_type = directory.transfer_type ?? ''
|
|
||||||
transferForm.scrape = directory.scraping ?? false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
// 使用SSE监听加载进度
|
// 使用SSE监听加载进度
|
||||||
function startLoadingProgress() {
|
function startLoadingProgress() {
|
||||||
progressText.value = '请稍候 ...'
|
progressText.value = '请稍候 ...'
|
||||||
@@ -190,10 +164,6 @@ async function handleTransferLog(logid: number) {
|
|||||||
console.log(e)
|
console.log(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
loadDirectories()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -229,15 +199,20 @@ onMounted(() => {
|
|||||||
persistent-hint
|
persistent-hint
|
||||||
/>
|
/>
|
||||||
</VCol>
|
</VCol>
|
||||||
<VCol cols="12" md="12">
|
<VCol cols="12">
|
||||||
<VCombobox
|
<VPathField @update:modelValue="updateTargetPath" :storage="transferForm.target_storage">
|
||||||
v-model="transferForm.target_path"
|
<template #activator="{ menuprops }">
|
||||||
:items="targetDirectories"
|
<VTextField
|
||||||
label="目的路径"
|
v-model="transferForm.target_path"
|
||||||
placeholder="留空自动"
|
v-bind="menuprops"
|
||||||
hint="整理目的路径,留空将自动匹配"
|
label="目的路径"
|
||||||
persistent-hint
|
placeholder="留空自动"
|
||||||
/>
|
hint="整理目的路径,留空将自动匹配"
|
||||||
|
persistent-hint
|
||||||
|
clearable
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</VPathField>
|
||||||
</VCol>
|
</VCol>
|
||||||
</VRow>
|
</VRow>
|
||||||
<VRow>
|
<VRow>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import api from '@/api'
|
|||||||
import { FileItem } from '@/api/types'
|
import { FileItem } from '@/api/types'
|
||||||
import { VTreeview } from 'vuetify/labs/VTreeview'
|
import { VTreeview } from 'vuetify/labs/VTreeview'
|
||||||
|
|
||||||
// 输入变量为默认路径
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
root: {
|
root: {
|
||||||
type: String,
|
type: String,
|
||||||
@@ -16,16 +15,12 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
// update:modelValue 事件
|
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue'])
|
||||||
|
|
||||||
// 激活的目录
|
|
||||||
const activedDirs = ref<string[]>([])
|
const activedDirs = ref<string[]>([])
|
||||||
|
|
||||||
// 打开的目录
|
|
||||||
const openedDirs = ref<string[]>([])
|
const openedDirs = ref<string[]>([])
|
||||||
|
const isUserAction = ref(false) // 标志:是否为用户主动操作
|
||||||
|
|
||||||
// 目录列表
|
|
||||||
const treeItems = ref<FileItem[]>([
|
const treeItems = ref<FileItem[]>([
|
||||||
{
|
{
|
||||||
name: '/',
|
name: '/',
|
||||||
@@ -37,19 +32,16 @@ const treeItems = ref<FileItem[]>([
|
|||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|
||||||
// 拉取子目录
|
|
||||||
async function fetchDirs(item: any) {
|
async function fetchDirs(item: any) {
|
||||||
return api
|
return api
|
||||||
.post('/storage/list', item)
|
.post('/storage/list', item)
|
||||||
.then((data: any) => {
|
.then((data: any) => {
|
||||||
// 只添加目录到子目录
|
|
||||||
data = data.filter((i: any) => i.type === 'dir')
|
data = data.filter((i: any) => i.type === 'dir')
|
||||||
item.children.push(...data)
|
item.children.push(...data)
|
||||||
})
|
})
|
||||||
.catch(err => console.warn(err))
|
.catch(err => console.warn(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取选择的目录路径
|
|
||||||
const selectedPath = computed(() => {
|
const selectedPath = computed(() => {
|
||||||
if (activedDirs.value.length > 0) {
|
if (activedDirs.value.length > 0) {
|
||||||
return activedDirs.value[0]
|
return activedDirs.value[0]
|
||||||
@@ -57,13 +49,12 @@ const selectedPath = computed(() => {
|
|||||||
return ''
|
return ''
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听目录变化
|
|
||||||
watch(activedDirs, newVal => {
|
watch(activedDirs, newVal => {
|
||||||
if (!newVal.length) return
|
if (!newVal.length || !isUserAction.value) return
|
||||||
emit('update:modelValue', selectedPath)
|
emit('update:modelValue', selectedPath.value)
|
||||||
|
isUserAction.value = false
|
||||||
})
|
})
|
||||||
|
|
||||||
// 监听存储变化
|
|
||||||
watch(
|
watch(
|
||||||
() => props.storage,
|
() => props.storage,
|
||||||
async newVal => {
|
async newVal => {
|
||||||
@@ -81,6 +72,10 @@ watch(
|
|||||||
activedDirs.value = []
|
activedDirs.value = []
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
function handleUserSelect() {
|
||||||
|
isUserAction.value = true
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -102,7 +97,7 @@ watch(
|
|||||||
max-height="20rem"
|
max-height="20rem"
|
||||||
expand-icon="mdi-folder"
|
expand-icon="mdi-folder"
|
||||||
collapse-icon="mdi-folder-open"
|
collapse-icon="mdi-folder-open"
|
||||||
>
|
@update:activated="handleUserSelect"
|
||||||
</VTreeview>
|
/>
|
||||||
</VMenu>
|
</VMenu>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user