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], () => {