mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-05-25 18:29:44 +08:00
Refactor data refresh mechanism with conditional timer support
Co-authored-by: jxxghp <jxxghp@163.com>
This commit is contained in:
@@ -18,7 +18,7 @@ const display = useDisplay()
|
||||
|
||||
// 获取i18n实例
|
||||
const { t } = useI18n()
|
||||
const { useDataRefresh } = useBackgroundOptimization()
|
||||
const { useConditionalDataRefresh } = useBackgroundOptimization()
|
||||
|
||||
// 定义输入
|
||||
const props = defineProps({
|
||||
@@ -63,9 +63,15 @@ const downloaderInfo = ref<DownloaderConf>({
|
||||
config: {},
|
||||
})
|
||||
|
||||
// 下载器是否应该刷新数据的计算属性
|
||||
const shouldRefresh = computed(() => props.allowRefresh && props.downloader.enabled)
|
||||
|
||||
// 调用API查询下载器数据
|
||||
async function loadDownloaderInfo() {
|
||||
if (!props.allowRefresh) {
|
||||
if (!shouldRefresh.value) {
|
||||
// 当下载器被禁用时,重置速率数据
|
||||
upload_rate.value = 0
|
||||
download_rate.value = 0
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -135,12 +141,13 @@ function onClose() {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
// 使用优化的数据刷新定时器(只在下载器启用时激活)
|
||||
const { stop: stopRefresh } = useDataRefresh(
|
||||
// 使用条件性数据刷新定时器(只在下载器启用时运行)
|
||||
const { stop: stopRefresh } = useConditionalDataRefresh(
|
||||
`downloader-${props.downloader.name}`,
|
||||
loadDownloaderInfo,
|
||||
shouldRefresh, // 响应式条件:只有当allowRefresh为true且downloader启用时才运行
|
||||
3000, // 3秒间隔
|
||||
props.downloader.enabled // 只在启用时执行
|
||||
true // 立即执行一次
|
||||
)
|
||||
|
||||
onUnmounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user