fix(webui): 整型开关字段与布尔值桥接

md-switch 发出布尔值,而表单里 0/1 字段存的是字符串,导致:
- 「显示 HDR 内容时休眠」打开后阈值输入不展开(=== '1' 判定失效)
- 保存时 parseInt(true) 得 0,会把已开启的开关写成关闭

新增 autoBriSleep / displayHdrSleep / compatibilityMode / debugMode 四个桥接 computed
This commit is contained in:
YuleBest committed 2026-09-10 10:28:01 +08:00
1 parent 78807937bd
commit 949e50916f
2 files changed
+24 -5

No files matched your search

+19
View File
@@ -89,6 +89,21 @@ export function useConfig() {
return patch
}
/** 整型开关字段(0/1)与布尔值之间的桥接:md-switch 给出的是布尔值 */
function intBool(key) {
return computed({
get: () => Number(form[key]) === 1,
set: (on) => {
form[key] = on ? '1' : '0'
},
})
}
const autoBriSleep = intBool('auto_bri_sleep')
const displayHdrSleep = intBool('display_hdr_sleep')
const compatibilityMode = intBool('compatibility_mode')
const debugMode = intBool('debug_mode')
const diffMain = computed(() => changedKeys(MAIN_KEYS))
const diffAdvanced = computed(() => changedKeys(ADVANCED_KEYS))
const dirtyMain = computed(() => Object.keys(diffMain.value).length > 0)
@@ -157,6 +172,10 @@ export function useConfig() {
error,
dirtyMain,
dirtyAdvanced,
autoBriSleep,
displayHdrSleep,
compatibilityMode,
debugMode,
load,
saveMain,
saveAdvanced,
+5 -5
View File
@@ -127,13 +127,13 @@ async function confirmReset() {
/>
</div>
</div>
<AppSwitch v-model="form.auto_bri_sleep" name="自动亮度时休眠" support="系统自动亮度开启时不提升" />
<AppSwitch v-model="config.autoBriSleep.value" name="自动亮度时休眠" support="系统自动亮度开启时不提升" />
<AppSwitch
v-model="form.display_hdr_sleep"
v-model="config.displayHdrSleep.value"
name="显示 HDR 内容时休眠"
support="比率 ≥ 进入阈值休眠,≤ 退出阈值恢复"
/>
<div class="collapse collapse--gap" :class="{ open: form.display_hdr_sleep === '1' }">
<div class="collapse collapse--gap" :class="{ open: config.displayHdrSleep.value }">
<div class="sleep-row">
<AppTextField
v-model="form.hdr_enter_ratio"
@@ -156,7 +156,7 @@ async function confirmReset() {
</div>
</div>
<AppSwitch
v-model="form.compatibility_mode"
v-model="config.compatibilityMode.value"
name="兼容模式(轮询驱动)"
support="不使用事件监听,改为 2 秒一次轮询"
warning="仅在事件驱动失效时开启,会略微增加耗电"
@@ -191,7 +191,7 @@ async function confirmReset() {
<Wrench :size="16" aria-hidden="true" /> 运行环境
</div>
<AppSwitch
v-model="form.debug_mode"
v-model="config.debugMode.value"
name="调试模式"
support="记录详细事件到日志"
warning="需重启模块生效,用完请关闭"