fix: 修复拨码开关数字孪生无法正常工作的问题
This commit is contained in:
parent
b6720d867d
commit
97b86acfa8
|
@ -114,7 +114,7 @@ public class SwitchController : ControllerBase
|
||||||
|
|
||||||
for (int i = 0; i < keyStatus.Length; i++)
|
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)
|
if (!result.IsSuccessful)
|
||||||
{
|
{
|
||||||
logger.Error(result.Error, $"SetSwitchOnOff({i}, {keyStatus[i]}) failed");
|
logger.Error(result.Error, $"SetSwitchOnOff({i}, {keyStatus[i]}) failed");
|
||||||
|
|
|
@ -127,6 +127,10 @@ const switchCount = computed(() => {
|
||||||
else return props.switchCount;
|
else return props.switchCount;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function getClient() {
|
||||||
|
return AuthManager.createClient(SwitchClient);
|
||||||
|
}
|
||||||
|
|
||||||
// 解析初始值
|
// 解析初始值
|
||||||
function parseInitialValues(): boolean[] {
|
function parseInitialValues(): boolean[] {
|
||||||
if (Array.isArray(props.initialValues)) {
|
if (Array.isArray(props.initialValues)) {
|
||||||
|
@ -162,7 +166,7 @@ function updateStatus(newStates: boolean[], index?: number) {
|
||||||
btnStatus.value = newStates.slice(0, switchCount.value);
|
btnStatus.value = newStates.slice(0, switchCount.value);
|
||||||
if (props.enableDigitalTwin) {
|
if (props.enableDigitalTwin) {
|
||||||
try {
|
try {
|
||||||
const client = AuthManager.createClient(SwitchClient);
|
const client = getClient();
|
||||||
if (!isUndefined(index)) client.setSwitchOnOff(index, newStates[index]);
|
if (!isUndefined(index)) client.setSwitchOnOff(index, newStates[index]);
|
||||||
else client.setMultiSwitchsOnOff(btnStatus.value);
|
else client.setMultiSwitchsOnOff(btnStatus.value);
|
||||||
} catch (error: any) {}
|
} catch (error: any) {}
|
||||||
|
@ -186,6 +190,15 @@ function setBtnStatus(idx: number, isOn: boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 监听 props 变化只同步一次
|
// 监听 props 变化只同步一次
|
||||||
|
watch(
|
||||||
|
() => props.enableDigitalTwin,
|
||||||
|
(newVal) => {
|
||||||
|
const client = getClient();
|
||||||
|
client.setEnable(newVal);
|
||||||
|
},
|
||||||
|
{ immediate: true },
|
||||||
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => [switchCount.value, props.initialValues],
|
() => [switchCount.value, props.initialValues],
|
||||||
() => {
|
() => {
|
||||||
|
|
Loading…
Reference in New Issue