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