This commit is contained in:
jxxghp
2024-05-05 11:22:10 +08:00
parent f817b20545
commit 37e5e57d5b
2 changed files with 72 additions and 28 deletions
+47 -6
View File
@@ -1,6 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useToast } from 'vue-toast-notification' import { useToast } from 'vue-toast-notification'
import TmdbSelector from '../misc/TmdbSelector.vue' import MediaIdSelector from '../misc/MediaIdSelector.vue'
import store from '@/store' import store from '@/store'
import api from '@/api' import api from '@/api'
import { numberValidator } from '@/@validators' import { numberValidator } from '@/@validators'
@@ -28,11 +28,14 @@ const seasonItems = ref(
})), })),
) )
// 当前识别类型
const mediaSource = ref('themoviedb')
// 提示框 // 提示框
const $toast = useToast() const $toast = useToast()
// TMDB选择对话框 // TMDB选择对话框
const tmdbSelectorDialog = ref(false) const mediaSelectorDialog = ref(false)
// 加载进度SSE // 加载进度SSE
const progressEventSource = ref<EventSource>() const progressEventSource = ref<EventSource>()
@@ -52,6 +55,7 @@ const transferForm = reactive({
path: '', path: '',
target: props.target ?? '', target: props.target ?? '',
tmdbid: null, tmdbid: null,
doubanid: null,
season: null, season: null,
type_name: '', type_name: '',
transfer_type: '', transfer_type: '',
@@ -142,6 +146,20 @@ async function transfer() {
// 重新加载 // 重新加载
emit('done') emit('done')
} }
// 调用API,加载当前系统环境设置
async function loadSystemSettings() {
try {
const result: { [key: string]: any } = await api.get('system/env')
if (result) mediaSource.value = result.data?.RECOGNIZE_SOURCE || 'themoviedb'
} catch (e) {
console.error(e)
}
}
onMounted(() => {
loadSystemSettings()
})
</script> </script>
<template> <template>
@@ -192,14 +210,26 @@ async function transfer() {
</VCol> </VCol>
<VCol cols="12" md="4"> <VCol cols="12" md="4">
<VTextField <VTextField
v-if="mediaSource === 'themoviedb'"
v-model="transferForm.tmdbid" v-model="transferForm.tmdbid"
:disabled="transferForm.type_name === ''" :disabled="transferForm.type_name === ''"
label="TMDBID" label="TheMovieDb编号"
placeholder="留空自动识别" placeholder="留空自动识别"
:rules="[numberValidator]" :rules="[numberValidator]"
append-inner-icon="mdi-magnify" append-inner-icon="mdi-magnify"
hint="点击图标按名称搜索,留空将自动重新识别" hint="点击图标按名称搜索,留空将自动重新识别"
@click:append-inner="tmdbSelectorDialog = true" @click:append-inner="mediaSelectorDialog = true"
/>
<VTextField
v-else
v-model="transferForm.doubanid"
:disabled="transferForm.type_name === ''"
label="豆瓣编号"
placeholder="留空自动识别"
:rules="[numberValidator]"
append-inner-icon="mdi-magnify"
hint="点击图标按名称搜索,留空将自动重新识别"
@click:append-inner="mediaSelectorDialog = true"
/> />
</VCol> </VCol>
<VCol cols="12" md="4"> <VCol cols="12" md="4">
@@ -265,8 +295,19 @@ async function transfer() {
<!-- 手动整理进度框 --> <!-- 手动整理进度框 -->
<ProgressDialog v-if="progressDialog" v-model="progressDialog" :text="progressText" :value="progressValue" /> <ProgressDialog v-if="progressDialog" v-model="progressDialog" :text="progressText" :value="progressValue" />
<!-- TMDB ID搜索框 --> <!-- TMDB ID搜索框 -->
<VDialog v-model="tmdbSelectorDialog" width="40rem" scrollable max-height="85vh"> <VDialog v-model="mediaSelectorDialog" width="40rem" scrollable max-height="85vh">
<TmdbSelector v-model="transferForm.tmdbid" @close="tmdbSelectorDialog = false" /> <MediaIdSelector
v-if="mediaSource === 'themoviedb'"
v-model="transferForm.tmdbid"
@close="mediaSelectorDialog = false"
:type="mediaSource"
/>
<MediaIdSelector
v-else
v-model="transferForm.doubanid"
@close="mediaSelectorDialog = false"
:type="mediaSource"
/>
</VDialog> </VDialog>
</VDialog> </VDialog>
</template> </template>
@@ -2,10 +2,16 @@
import api from '@/api' import api from '@/api'
import type { MediaInfo } from '@/api/types' import type { MediaInfo } from '@/api/types'
//
const props = defineProps({
type: String, // themoviedb | douban
})
interface TmdbItem { interface TmdbItem {
title: string title: string
overview: string overview: string
tmdbid: number tmdbid: number
doubanid: string
poster: string poster: string
} }
@@ -21,25 +27,23 @@ const keyword = ref('')
const loading = ref(false) const loading = ref(false)
// ref // ref
const tmdbKeyword = ref<HTMLElement | null>(null) const inputKeyword = ref<HTMLElement | null>(null)
// //
function selectMedia(item: TmdbItem) { function selectMedia(item: TmdbItem) {
emit('update:modelValue', item.tmdbid) emit('update:modelValue', item.tmdbid || item.doubanid)
emit('close') emit('close')
} }
// TMDBw500 // TMDBw500
function getW500Image(url = '') { function getW500Image(url = '') {
if (!url) if (!url) return ''
return ''
return url.replace('original', 'w500') return url.replace('original', 'w500')
} }
// //
async function searchMedias() { async function searchMedias() {
if (!keyword) if (!keyword) return
return
// API // API
try { try {
@@ -57,16 +61,17 @@ async function searchMedias() {
// //
for (const item of result) { for (const item of result) {
if (props.type && props.type !== item.source) continue
items.value.push({ items.value.push({
tmdbid: item.tmdb_id || 0, tmdbid: item.tmdb_id || 0,
doubanid: item.douban_id || '',
poster: getW500Image(item.poster_path), poster: getW500Image(item.poster_path),
title: `${item.title}${item.year}`, title: `${item.title}${item.year}`,
overview: `<span class="text-primary">${item.type}</span> ${item.overview}`, overview: `<span class="text-primary">${item.type}</span> ${item.overview}`,
}) })
} }
loading.value = false loading.value = false
} } catch (e) {
catch (e) {
console.error(e) console.error(e)
} }
} }
@@ -75,19 +80,16 @@ async function searchMedias() {
onMounted(() => { onMounted(() => {
// 500ms // 500ms
setTimeout(() => { setTimeout(() => {
tmdbKeyword.value?.focus() inputKeyword.value?.focus()
}, 500) }, 500)
}) })
</script> </script>
<template> <template>
<VCard <VCard class="mx-auto" width="100%">
class="mx-auto"
width="100%"
>
<VToolbar flat class="p-0"> <VToolbar flat class="p-0">
<VTextField <VTextField
ref="tmdbKeyword" ref="inputKeyword"
v-model="keyword" v-model="keyword"
label="输入名称搜索" label="输入名称搜索"
single-line single-line
@@ -101,15 +103,16 @@ onMounted(() => {
@keydown.enter="searchMedias" @keydown.enter="searchMedias"
/> />
</VToolbar> </VToolbar>
<DialogCloseBtn @click="() => { emit('close') }" /> <DialogCloseBtn
<VList @click="
v-if="items.length > 0" () => {
lines="three" emit('close')
> }
"
/>
<VList v-if="items.length > 0" lines="three">
<template v-for="(item, i) in items" :key="i"> <template v-for="(item, i) in items" :key="i">
<VListItem <VListItem @click="selectMedia(item)">
@click="selectMedia(item)"
>
<template #prepend> <template #prepend>
<VImg <VImg
height="75" height="75"