瀏覽代碼

toggle添加弹窗确认

hh 1 周之前
父節點
當前提交
935697c874
共有 1 個文件被更改,包括 60 次插入13 次删除
  1. 60 13
      entry/src/main/ets/pages/Index.ets

+ 60 - 13
entry/src/main/ets/pages/Index.ets

@@ -130,6 +130,11 @@ struct WorkshopPage {
       }
       }
     ]
     ]
   })
   })
+  // 切换按钮点击的工位控制
+  clickStation: StationControl = {}
+  // 切换类型(1:电源控制 2:设备控制)
+  toggleType: number = 1
+  toggleIsOn: boolean = false
 
 
   async onPageShow() {
   async onPageShow() {
     this.onlineNum = 0;
     this.onlineNum = 0;
@@ -286,6 +291,48 @@ struct WorkshopPage {
     customStyle: true,
     customStyle: true,
   })
   })
 
 
+  // 切换按钮确认弹窗控制器
+  toggleConfirmController: CustomDialogController = new CustomDialogController({
+    builder: confirmDialog({
+      title: this.clickStation.stationName! + (this.toggleType === 1 ?   '控制电源' : '设备电源'),
+      cancel: ()=> {
+        console.log('hhtest', JSON.stringify(this.toggleIsOn))
+        this.toggleIsOn = !this.toggleIsOn
+        console.log('hhtest', JSON.stringify(this.toggleIsOn))
+        this.stationArray =[...this.stationArray]
+        // for (let i = 0; i < this.stationArray.length; i++) {
+        //   if (this.stationArray[i].stationName! === this.clickStation.stationName) {
+        //     this.stationArray[i] = ...this.clickStation
+        //   }
+        // }
+      },
+      confirm: ()=> {
+        console.log('hhtest', JSON.stringify(this.clickStation))
+        console.log('hhtest', JSON.stringify(this.toggleType))
+        console.log('hhtest', JSON.stringify(this.toggleIsOn))
+        let controlStr = BusinessConstant.stationLightMap.get(this.clickStation.stationName!);
+        if (this.toggleType === 1) {
+          if (controlStr && controlStr.length > 0) {
+            if (this.clickStation.stationType! === 1) {
+              this.issueControlCommand(controlStr[0], this.toggleIsOn ? 0 : 1);
+            } else {
+              this.issueControlCommand(controlStr[0], this.toggleIsOn ? 1 : 0);
+            }
+          }
+        } else {
+          if (controlStr && controlStr.length >= 1) {
+            this.issueControlCommand(controlStr[1], this.toggleIsOn ? 0 : 1);
+          }
+        }
+      },
+    }),
+    autoCancel: true,
+    alignment: DialogAlignment.Center,
+    // gridCount: 3,
+    customStyle: true,
+  })
+
+
   build() {
   build() {
     Column() {
     Column() {
       // 顶部状态栏
       // 顶部状态栏
@@ -408,20 +455,17 @@ struct WorkshopPage {
                           .fontColor($r('app.color.FFFFFF'))
                           .fontColor($r('app.color.FFFFFF'))
                           .fontWeight(FontWeight.Regular)
                           .fontWeight(FontWeight.Regular)
                           .opacity(0.6)
                           .opacity(0.6)
-                        Toggle({ type: ToggleType.Switch, isOn: item.controlPowerStatus! === 0 ? true : false })
+                        Toggle({ type: ToggleType.Switch, isOn: (this.clickStation.stationType! === 1 && item.controlPowerStatus! === 0) || (this.clickStation.stationType! === 2 && item.controlPowerStatus! === 1) ? true : false })
                           .width('67%')
                           .width('67%')
                           .height('46%')
                           .height('46%')
                           .selectedColor($r('app.color.30D158'))
                           .selectedColor($r('app.color.30D158'))
                           .switchPointColor("#CAC8C4")
                           .switchPointColor("#CAC8C4")
                           .onChange((isOn: boolean) => {
                           .onChange((isOn: boolean) => {
-                            let controlStr = BusinessConstant.stationLightMap.get(item.stationName);
-                            if (controlStr && controlStr.length > 0) {
-                              if (item.stationType! === 1) {
-                                this.issueControlCommand(controlStr[0], isOn ? 0 : 1);
-                              } else {
-                                this.issueControlCommand(controlStr[0], isOn ? 1 : 0);
-                              }
-                            }
+                            this.clickStation = item
+                            this.toggleType = 1
+                            this.toggleIsOn = isOn
+                            this.toggleConfirmController.open()
+                            isOn = this.toggleIsOn
                           })
                           })
                       }
                       }
                       .width('50%')
                       .width('50%')
@@ -443,10 +487,10 @@ struct WorkshopPage {
                             .selectedColor($r('app.color.30D158'))
                             .selectedColor($r('app.color.30D158'))
                             .switchPointColor("#CAC8C4")
                             .switchPointColor("#CAC8C4")
                             .onChange((isOn: boolean) => {
                             .onChange((isOn: boolean) => {
-                              let controlStr = BusinessConstant.stationLightMap.get(item.stationName);
-                              if (controlStr && controlStr.length >= 1) {
-                                this.issueControlCommand(controlStr[1], isOn ? 0 : 1);
-                              }
+                              this.clickStation = item
+                              this.toggleType = 2
+                              this.toggleIsOn = isOn
+                              this.toggleConfirmController.open()
                             })
                             })
                         }
                         }
                       }
                       }
@@ -1436,6 +1480,9 @@ struct confirmDialog {
         .height('100%')
         .height('100%')
         .justifyContent(FlexAlign.Center)
         .justifyContent(FlexAlign.Center)
         .onClick(()=>{
         .onClick(()=>{
+          if (this.cancel() != undefined) {
+            this.cancel
+          }
           if (this.controller != undefined) {
           if (this.controller != undefined) {
             this.controller.close()
             this.controller.close()
           }
           }