From 97b86acfa84bc4aaa426b77af0dc3341a2018fc0 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Sun, 17 Aug 2025 12:29:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8B=A8=E7=A0=81?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E6=95=B0=E5=AD=97=E5=AD=AA=E7=94=9F=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E5=B7=A5=E4=BD=9C=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/Controllers/SwitchController.cs | 2 +- src/components/equipments/Switch.vue | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/src/Controllers/SwitchController.cs b/server/src/Controllers/SwitchController.cs index 76b98ef..b29498e 100644 --- a/server/src/Controllers/SwitchController.cs +++ b/server/src/Controllers/SwitchController.cs @@ -114,7 +114,7 @@ public class SwitchController : ControllerBase for (int i = 0; i < keyStatus.Length; i++) { - var result = await switchCtrl.SetSwitchOnOff(i, keyStatus[i]); + var result = await switchCtrl.SetSwitchOnOff(i + 1, keyStatus[i]); if (!result.IsSuccessful) { logger.Error(result.Error, $"SetSwitchOnOff({i}, {keyStatus[i]}) failed"); diff --git a/src/components/equipments/Switch.vue b/src/components/equipments/Switch.vue index d8108f4..f136adc 100644 --- a/src/components/equipments/Switch.vue +++ b/src/components/equipments/Switch.vue @@ -127,6 +127,10 @@ const switchCount = computed(() => { else return props.switchCount; }); +function getClient() { + return AuthManager.createClient(SwitchClient); +} + // 解析初始值 function parseInitialValues(): boolean[] { if (Array.isArray(props.initialValues)) { @@ -162,7 +166,7 @@ function updateStatus(newStates: boolean[], index?: number) { btnStatus.value = newStates.slice(0, switchCount.value); if (props.enableDigitalTwin) { try { - const client = AuthManager.createClient(SwitchClient); + const client = getClient(); if (!isUndefined(index)) client.setSwitchOnOff(index, newStates[index]); else client.setMultiSwitchsOnOff(btnStatus.value); } catch (error: any) {} @@ -186,6 +190,15 @@ function setBtnStatus(idx: number, isOn: boolean) { } // 监听 props 变化只同步一次 +watch( + () => props.enableDigitalTwin, + (newVal) => { + const client = getClient(); + client.setEnable(newVal); + }, + { immediate: true }, +); + watch( () => [switchCount.value, props.initialValues], () => {