style: Update globalSettings injection in multiple components

This commit is contained in:
jxxghp
2024-08-29 08:36:29 +08:00
parent 9d55f8ab24
commit 6ec1bbe1ae
10 changed files with 107 additions and 55 deletions

View File

@@ -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<string> = 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)"
>
<VImg
aspect-ratio="2/3"

View File

@@ -9,6 +9,9 @@ const personProps = defineProps({
height: String,
})
// 从 provide 中获取全局设置
const globalSettings: any = inject('globalSettings')
// 当前人物
const personInfo = ref(personProps.person)
@@ -17,22 +20,26 @@ const isImageLoaded = ref(false)
// 人物图片地址
function getPersonImage() {
let url = ''
if (personProps.person?.source === 'themoviedb') {
if (!personInfo.value?.profile_path) return personIcon
return `https://image.tmdb.org/t/p/w600_and_h900_bestv2${personInfo.value?.profile_path}`
url = `https://image.tmdb.org/t/p/w600_and_h900_bestv2${personInfo.value?.profile_path}`
} else if (personProps.person?.source === 'douban') {
if (!personInfo.value?.avatar) return personIcon
if (typeof personInfo.value?.avatar === 'object') {
return personInfo.value?.avatar?.normal
url = personInfo.value?.avatar?.normal
} else {
return personInfo.value?.avatar
url = personInfo.value?.avatar
}
} else if (personProps.person?.source === 'bangumi') {
if (!personInfo.value?.images) return personIcon
return personInfo.value?.images?.medium
url = personInfo.value?.images?.medium
} else {
return personIcon
}
if (globalSettings.GLOBAL_IMAGE_CACHE && url)
return `${import.meta.env.VITE_API_BASE_URL}system/cache/image?url=${encodeURIComponent(url)}`
return url
}
// 人物姓名

View File

@@ -6,7 +6,7 @@ import api from '@/api'
import { numberValidator } from '@/@validators'
import { useDisplay } from 'vuetify'
import ProgressDialog from './ProgressDialog.vue'
import { FileItem, MediaDirectory } from '@/api/types'
import { FileItem, TransferDirectoryConf } from '@/api/types'
// 显示器宽度
const display = useDisplay()
@@ -22,6 +22,12 @@ const props = defineProps({
target: String,
})
// 从 provide 中获取全局设置
const globalSettings: any = inject('globalSettings')
// 当前识别类型
const mediaSource = ref(globalSettings.data?.RECOGNIZE_SOURCE || 'themoviedb')
// 定义事件
const emit = defineEmits(['done', 'close'])
@@ -33,9 +39,6 @@ const seasonItems = ref(
})),
)
// 当前识别类型
const mediaSource = ref('themoviedb')
// 提示框
const $toast = useToast()
@@ -88,20 +91,20 @@ const transferForm = reactive({
})
// 所有媒体库目录
const libraryDirectories = ref<MediaDirectory[]>([])
const libraryDirectories = ref<TransferDirectoryConf[]>([])
// 目的目录下拉框
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()
})
</script>