diff --git a/src/api/index.ts b/src/api/index.ts index 2f30f7a2..4d48d1eb 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -37,3 +37,13 @@ api.interceptors.response.use( ) export default api + +export async function fetchGlobalSettings() { + try { + const result: { [key: string]: any } = await api.get('system/env') + return result.data || {} + } catch (error) { + console.error('Failed to fetch global settings', error) + throw error + } +} diff --git a/src/components/cards/MediaCard.vue b/src/components/cards/MediaCard.vue index 3b1e716c..d90ee898 100644 --- a/src/components/cards/MediaCard.vue +++ b/src/components/cards/MediaCard.vue @@ -19,6 +19,9 @@ const props = defineProps({ height: String, }) +// 从 provide 中获取全局设置 +const globalSettings: any = inject('globalSettings') + const store = useStore() // 提示框 @@ -366,10 +369,11 @@ onBeforeMount(() => { const getImgUrl: Ref = computed(() => { if (imageLoadError.value) return noImage const url = props.media?.poster_path?.replace('original', 'w500') ?? noImage + // 使用图片缓存 + if (globalSettings.GLOBAL_IMAGE_CACHE) return `${import.meta.env.VITE_API_BASE_URL}${url}` // 如果地址中包含douban则使用中转代理 if (url.includes('doubanio.com')) return `${import.meta.env.VITE_API_BASE_URL}douban/img?imgurl=${encodeURIComponent(url)}` - return url }) @@ -405,7 +409,7 @@ function getYear(airDate: string) { 'transition transform-cpu duration-300 scale-105 shadow-lg': hover.isHovering, 'ring-1': isImageLoaded, }" - @click.stop="goMediaDetail(hover.isHovering)" + @click.stop="goMediaDetail(hover.isHovering ?? false)" > ([]) +const libraryDirectories = ref([]) // 目的目录下拉框 const targetDirectories = computed(() => { - const directories = libraryDirectories.value.map(item => item.path) + const directories = libraryDirectories.value.map(item => item.library_path) return [...new Set(directories)] }) // 监听目的路径变化,自动查询目录的刮削配置 watch(transferForm, async () => { if (transferForm.target) { - const directory = libraryDirectories.value.find(item => item.path === transferForm.target) + const directory = libraryDirectories.value.find(item => item.library_path === transferForm.target) if (directory) { - transferForm.scrape = directory.scrape ?? false + transferForm.scrape = directory.scraping ?? false } } }) @@ -186,16 +189,6 @@ async function handleTransferLog(logid: number) { } } -// 调用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) - } -} - // 查询媒体库目录 async function loadLibraryDirectories() { try { @@ -209,7 +202,6 @@ async function loadLibraryDirectories() { } onMounted(() => { - loadSystemSettings() loadLibraryDirectories() }) diff --git a/src/main.ts b/src/main.ts index c75ac4d2..6e08386e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -28,10 +28,19 @@ import '@layouts/styles/index.scss' import '@styles/styles.scss' import 'vue-toast-notification/dist/theme-bootstrap.css' import 'vue3-perfect-scrollbar/style.css' +import { fetchGlobalSettings } from './api' // 创建Vue实例 const app = createApp(App) +try { + const globalSettings = await fetchGlobalSettings() + // 使用 provide 传递全局设置 + app.provide('globalSettings', globalSettings) +} catch (error) { + console.error('Failed to initialize app', error) +} + // 注册全局组件 app .component('VAceEditor', VAceEditor) diff --git a/src/views/discover/MediaDetailView.vue b/src/views/discover/MediaDetailView.vue index c8ba5b13..237b7364 100644 --- a/src/views/discover/MediaDetailView.vue +++ b/src/views/discover/MediaDetailView.vue @@ -17,6 +17,9 @@ const mediaProps = defineProps({ type: String, }) +// 从 provide 中获取全局设置 +const globalSettings: any = inject('globalSettings') + const store = useStore() // 提示框 @@ -316,9 +319,34 @@ function getEpisodeImage(stillPath: string) { // TMDB图片转换为w500大小 function getW500Image(url = '') { if (!url) return '' - return url.replace('original', 'w500') + url = url.replace('original', 'w500') + // 使用图片缓存 + if (globalSettings.GLOBAL_IMAGE_CACHE) return `${import.meta.env.VITE_API_BASE_URL}${encodeURIComponent(url)}` + return url } +// 计算Poster地址 +const getPosterUrl: Ref = computed(() => { + const url = mediaDetail.value.poster_path ?? '' + // 如果地址中包含douban则使用中转代理 + if (url.includes('doubanio.com')) + return `${import.meta.env.VITE_API_BASE_URL}douban/img?imgurl=${encodeURIComponent(url)}` + // 使用图片缓存 + if (globalSettings.GLOBAL_IMAGE_CACHE) return `${import.meta.env.VITE_API_BASE_URL}${url}` + return url +}) + +// 计算backdrop地址 +const getBackdropUrl: Ref = computed(() => { + const url = mediaDetail.value.backdrop_path ?? '' + // 使用图片缓存 + if (globalSettings.GLOBAL_IMAGE_CACHE) return `${import.meta.env.VITE_API_BASE_URL}${url}` + // 如果地址中包含douban则使用中转代理 + if (url.includes('doubanio.com')) + return `${import.meta.env.VITE_API_BASE_URL}douban/img?imgurl=${encodeURIComponent(url)}` + return url +}) + // 获取发行国家名称 const getProductionCountries = computed(() => { return mediaDetail.value.production_countries?.map(country => country.name) @@ -423,9 +451,9 @@ onBeforeMount(() => {