|
95 | 95 | <n-card class="set-item"> |
96 | 96 | <div class="label"> |
97 | 97 | <n-text class="name">缓存大小上限</n-text> |
98 | | - <n-text class="tip" :depth="3">达到上限后将清理最旧的缓存</n-text> |
| 98 | + <n-text class="tip" :depth="3">达到上限后将清理最旧的缓存,数值可以是小数,最低 2GB</n-text> |
99 | 99 | </div> |
100 | | - <n-select |
101 | | - v-model:value="cacheLimit" |
102 | | - :options="cacheSizeOptions" |
103 | | - class="set" |
104 | | - @update:value="changeCacheLimit" |
105 | | - /> |
| 100 | + <n-input-group class="set"> |
| 101 | + <n-input-number |
| 102 | + :value="cacheLimit" |
| 103 | + :update-value-on-input="false" |
| 104 | + :min="2" |
| 105 | + :max="9999" |
| 106 | + :style="{ |
| 107 | + width: cacheLimited ? '55%' : '0%', |
| 108 | + transition: isMounted ? 'width 0.3s ease' : 'none', |
| 109 | + }" |
| 110 | + @update:value="(value) => { |
| 111 | + cacheLimit = value ?? 2; |
| 112 | + changeCacheLimit(cacheLimit); |
| 113 | + }" |
| 114 | + /> |
| 115 | + <n-select |
| 116 | + v-model:value="cacheLimited" |
| 117 | + :options="[ |
| 118 | + { label: '不限制', value: 0 }, |
| 119 | + { label: cacheLimited === 0 ? '输入数值 (单位 GB)' : 'GB', value: 1 }, |
| 120 | + ]" |
| 121 | + :style="{ |
| 122 | + width: cacheLimited ? '45%' : '100%', |
| 123 | + transition: isMounted ? 'width 0.3s ease' : 'none', |
| 124 | + }" |
| 125 | + @update:value="(value) => { |
| 126 | + if (value === 0) { |
| 127 | + changeCacheLimit(0); |
| 128 | + } else { |
| 129 | + if (cacheLimit === 0) cacheLimit = 2; |
| 130 | + changeCacheLimit(cacheLimit); |
| 131 | + } |
| 132 | + }" |
| 133 | + /> |
| 134 | + </n-input-group> |
106 | 135 | </n-card> |
107 | 136 | <n-card class="set-item"> |
108 | 137 | <div class="label"> |
@@ -289,9 +318,13 @@ import { isDevBuild } from "@/utils/env"; |
289 | 318 |
|
290 | 319 | const settingStore = useSettingStore(); |
291 | 320 | const cacheManager = useCacheManager(); |
| 321 | +
|
| 322 | +const isMounted = ref<boolean>(false); |
| 323 | +
|
292 | 324 | const cachePath = ref<string>(""); |
293 | 325 | const cacheSizeDisplay = ref<string>("--"); |
294 | 326 | const cacheLimit = ref<number>(10); // 本地状态 |
| 327 | +const cacheLimited = ref<number>(1); // 是否限制缓存 (1 为限制) |
295 | 328 |
|
296 | 329 | // 默认下载音质选项 |
297 | 330 | const downloadQualityOptions = computed(() => { |
@@ -332,41 +365,6 @@ const folderStrategyOptions = [ |
332 | 365 | }, |
333 | 366 | ]; |
334 | 367 |
|
335 | | -const cacheSizeOptions = [ |
336 | | - { |
337 | | - label: "不限制", |
338 | | - value: 0, |
339 | | - }, |
340 | | - { |
341 | | - label: "5G", |
342 | | - value: 5, |
343 | | - }, |
344 | | - { |
345 | | - label: "10G", |
346 | | - value: 10, |
347 | | - }, |
348 | | - { |
349 | | - label: "15G", |
350 | | - value: 15, |
351 | | - }, |
352 | | - { |
353 | | - label: "20G", |
354 | | - value: 20, |
355 | | - }, |
356 | | - { |
357 | | - label: "25G", |
358 | | - value: 25, |
359 | | - }, |
360 | | - { |
361 | | - label: "30G", |
362 | | - value: 30, |
363 | | - }, |
364 | | - { |
365 | | - label: "50G", |
366 | | - value: 50, |
367 | | - }, |
368 | | -]; |
369 | | -
|
370 | 368 | // 选择下载路径 |
371 | 369 | const choosePath = async () => { |
372 | 370 | const path = await window.electron.ipcRenderer.invoke("choose-path"); |
@@ -397,7 +395,6 @@ const confirmChangeCachePath = () => { |
397 | 395 |
|
398 | 396 | // 更改缓存大小限制 |
399 | 397 | const changeCacheLimit = async (value: number) => { |
400 | | - cacheLimit.value = value; |
401 | 398 | await window.api.store.set("cacheLimit", value); |
402 | 399 | }; |
403 | 400 |
|
@@ -465,11 +462,15 @@ onMounted(async () => { |
465 | 462 | const path = await window.api.store.get("cachePath"); |
466 | 463 | cachePath.value = path || ""; |
467 | 464 | const limit = await window.api.store.get("cacheLimit"); |
468 | | - if (typeof limit === "number") cacheLimit.value = limit; |
| 465 | + if (typeof limit === "number") { |
| 466 | + cacheLimit.value = limit; |
| 467 | + if (limit === 0) cacheLimited.value = 0; |
| 468 | + } |
469 | 469 | } catch (error) { |
470 | 470 | console.error("读取缓存路径失败:", error); |
471 | 471 | } |
472 | 472 | await loadCacheSize(); |
| 473 | + isMounted.value = true; |
473 | 474 | }); |
474 | 475 | </script> |
475 | 476 |
|
|
0 commit comments