mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-07-03 21:41:32 +08:00
fix(subscribe): refine season mode defaults (#503)
This commit is contained in:
@@ -34,6 +34,7 @@ const props = defineProps({
|
||||
selectedSeason: Number,
|
||||
subscribedSeasons: Array as PropType<number[]>,
|
||||
subscribedSeasonModes: Object as PropType<SeasonSubscribeModes>,
|
||||
defaultSubscribeMode: String as PropType<SubscribeMode>,
|
||||
})
|
||||
|
||||
// 从 provide 中获取全局设置
|
||||
@@ -50,6 +51,9 @@ const seasonsSelected = ref<number[]>([])
|
||||
// 各季订阅方式
|
||||
const seasonModes = ref<Record<number, SubscribeMode>>({})
|
||||
|
||||
// 用户已手动选择过模式的季号,入库状态异步刷新时不再覆盖。
|
||||
const manuallySelectedModeSeasons = ref(new Set<number>())
|
||||
|
||||
// 各季缺失状态:0-已入库 1-部分缺失 2-全部缺失,没有数据也是已入库
|
||||
const seasonsNotExisted = ref<{ [key: number]: number }>({})
|
||||
|
||||
@@ -294,11 +298,25 @@ function setSeasonMode(season: number, mode: SubscribeMode) {
|
||||
|
||||
function updateSeasonMode(season: number, mode: unknown) {
|
||||
if (!isSubscribeMode(mode)) return
|
||||
manuallySelectedModeSeasons.value.add(season)
|
||||
setSeasonMode(season, mode)
|
||||
}
|
||||
|
||||
function getDefaultSeasonMode(season: number) {
|
||||
if (!seasonsNotExisted.value[season]) return 'best_version_full'
|
||||
|
||||
return props.defaultSubscribeMode ?? 'normal'
|
||||
}
|
||||
|
||||
function ensureSeasonMode(season: number) {
|
||||
if (!seasonModes.value[season]) setSeasonMode(season, props.subscribedSeasonModes?.[season] ?? 'normal')
|
||||
if (!seasonModes.value[season]) setSeasonMode(season, props.subscribedSeasonModes?.[season] ?? getDefaultSeasonMode(season))
|
||||
}
|
||||
|
||||
function syncDefaultSeasonModes() {
|
||||
seasonsSelected.value.forEach(season => {
|
||||
if (subscribedSeasonSet.value.has(season) || manuallySelectedModeSeasons.value.has(season)) return
|
||||
setSeasonMode(season, getDefaultSeasonMode(season))
|
||||
})
|
||||
}
|
||||
|
||||
function isSeasonSubscribed(season: number) {
|
||||
@@ -354,6 +372,8 @@ watchEffect(() => {
|
||||
|
||||
watch(seasonInfos, syncSelectedSeason)
|
||||
|
||||
watch(seasonsNotExisted, syncDefaultSeasonModes, { deep: true })
|
||||
|
||||
watch(() => props.selectedSeason, syncSelectedSeason)
|
||||
|
||||
watch(() => props.subscribedSeasons, syncSelectedSeason)
|
||||
@@ -624,7 +644,7 @@ onMounted(async () => {
|
||||
|
||||
.subscribe-season-mode-toggle {
|
||||
block-size: 2rem;
|
||||
max-inline-size: 16rem;
|
||||
max-inline-size: 18rem;
|
||||
}
|
||||
|
||||
.subscribe-season-mode-button {
|
||||
|
||||
@@ -16,6 +16,12 @@ interface SubscribePayload {
|
||||
best_version_full?: number
|
||||
}
|
||||
|
||||
interface SubscribeConfig {
|
||||
show_edit_dialog?: boolean
|
||||
best_version?: unknown
|
||||
best_version_full?: unknown
|
||||
}
|
||||
|
||||
interface AddSubscribeOptions {
|
||||
openEditDialog?: boolean
|
||||
}
|
||||
@@ -67,6 +73,13 @@ export function getSubscribeMode(subscribe: { best_version?: unknown; best_versi
|
||||
return isEnabledFlag(subscribe.best_version_full) ? 'best_version_full' : 'best_version'
|
||||
}
|
||||
|
||||
function getSubscribeConfigMode(config?: SubscribeConfig): SubscribeMode {
|
||||
return getSubscribeMode({
|
||||
best_version: config?.best_version,
|
||||
best_version_full: config?.best_version_full,
|
||||
})
|
||||
}
|
||||
|
||||
function getModeName(t: ReturnType<typeof useI18n>['t'], mode: SubscribeMode) {
|
||||
if (mode === 'normal') return t('dialog.subscribeMode.normal')
|
||||
if (mode === 'best_version') return t('dialog.subscribeMode.bestVersionEpisode')
|
||||
@@ -161,9 +174,10 @@ export function useMediaSubscribe(options: UseMediaSubscribeOptions) {
|
||||
)
|
||||
}
|
||||
|
||||
function openSubscribeSeasonDialog(selectedSeason?: number | null) {
|
||||
async function openSubscribeSeasonDialog(selectedSeason?: number | null) {
|
||||
const media = currentMedia()
|
||||
if (!media) return
|
||||
const defaultSubscribeConfig = await queryDefaultSubscribeConfig()
|
||||
|
||||
openSharedDialog(
|
||||
SubscribeSeasonDialog,
|
||||
@@ -172,6 +186,7 @@ export function useMediaSubscribe(options: UseMediaSubscribeOptions) {
|
||||
selectedSeason,
|
||||
subscribedSeasons: options.subscribedSeasons?.value ?? [],
|
||||
subscribedSeasonModes: options.subscribedSeasonModes?.value ?? {},
|
||||
defaultSubscribeMode: getSubscribeConfigMode(defaultSubscribeConfig),
|
||||
},
|
||||
{
|
||||
subscribe: subscribeSeasons,
|
||||
@@ -180,8 +195,8 @@ export function useMediaSubscribe(options: UseMediaSubscribeOptions) {
|
||||
)
|
||||
}
|
||||
|
||||
async function queryDefaultSubscribeConfig() {
|
||||
if (!options.canSubscribe()) return false
|
||||
async function queryDefaultSubscribeConfig(): Promise<SubscribeConfig | undefined> {
|
||||
if (!options.canSubscribe()) return undefined
|
||||
|
||||
try {
|
||||
const media = currentMedia()
|
||||
@@ -191,12 +206,12 @@ export function useMediaSubscribe(options: UseMediaSubscribeOptions) {
|
||||
: 'system/setting/public/DefaultTvSubscribeConfig'
|
||||
const result: { [key: string]: any } = await api.get(subscribeConfigUrl)
|
||||
|
||||
if (result.data?.value) return result.data.value.show_edit_dialog
|
||||
return result.data?.value
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
}
|
||||
|
||||
return false
|
||||
return undefined
|
||||
}
|
||||
|
||||
function showSubscribeAddToast(
|
||||
@@ -242,8 +257,8 @@ export function useMediaSubscribe(options: UseMediaSubscribeOptions) {
|
||||
showSubscribeAddToast(result.success, media.title ?? '', season, result.message, payload.best_version ?? 0)
|
||||
|
||||
if (result.success && (addOptions.openEditDialog ?? true)) {
|
||||
const showEditDialog = await queryDefaultSubscribeConfig()
|
||||
if (showEditDialog) openSubscribeEditDialog(result.data.id)
|
||||
const subscribeConfig = await queryDefaultSubscribeConfig()
|
||||
if (subscribeConfig?.show_edit_dialog) openSubscribeEditDialog(result.data.id)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
|
||||
@@ -2824,10 +2824,10 @@ export default {
|
||||
},
|
||||
subscribeMode: {
|
||||
title: 'Choose Subscription Type',
|
||||
normal: 'Subscribe',
|
||||
normal: 'Normal',
|
||||
bestVersion: 'Version Upgrade',
|
||||
bestVersionEpisode: 'Episode Upgrade',
|
||||
bestVersionFull: 'Full Season Upgrade',
|
||||
bestVersionEpisode: 'Episode',
|
||||
bestVersionFull: 'Full',
|
||||
},
|
||||
subscribeEdit: {
|
||||
titleDefault: 'Default Subscription Rules',
|
||||
|
||||
Reference in New Issue
Block a user