Selaa lähdekoodia

toggle添加弹窗确认 第二版

hh 1 viikko sitten
vanhempi
commit
942ee75357
1 muutettua tiedostoa jossa 40 lisäystä ja 38 poistoa
  1. 40 38
      entry/src/main/ets/pages/Index.ets

+ 40 - 38
entry/src/main/ets/pages/Index.ets

@@ -134,7 +134,6 @@ struct WorkshopPage {
   clickStation: StationControl = {}
   // 切换类型(1:电源控制 2:设备控制)
   toggleType: number = 1
-  toggleIsOn: boolean = false
 
   async onPageShow() {
     this.onlineNum = 0;
@@ -296,33 +295,22 @@ struct WorkshopPage {
     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]
-        console.log('hhtest', JSON.stringify(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);
+              this.issueControlCommand(controlStr[0], this.clickStation.controlPowerStatus! === 1 ? 0 : 1);
             } else {
-              this.issueControlCommand(controlStr[0], this.toggleIsOn ? 1 : 0);
+              this.issueControlCommand(controlStr[0], this.clickStation.controlPowerStatus! === 1 ? 0 : 1);
             }
           }
         } else {
           if (controlStr && controlStr.length >= 1) {
-            this.issueControlCommand(controlStr[1], this.toggleIsOn ? 0 : 1);
+            this.issueControlCommand(controlStr[1], this.clickStation.controlPowerStatus! === 1 ? 0 : 1);
           }
         }
       },
@@ -456,18 +444,24 @@ struct WorkshopPage {
                           .fontColor($r('app.color.FFFFFF'))
                           .fontWeight(FontWeight.Regular)
                           .opacity(0.6)
-                        Toggle({ type: ToggleType.Switch, isOn: ((item.stationType! === 1 && item.controlPowerStatus! === 0) || (item.stationType! === 2 && item.controlPowerStatus! === 1)) ? true : false })
-                          .width('67%')
-                          .height('46%')
-                          .selectedColor($r('app.color.30D158'))
-                          .switchPointColor("#CAC8C4")
-                          .onChange((isOn: boolean) => {
-                            this.clickStation = item
-                            this.toggleType = 1
-                            this.toggleIsOn = isOn
-                            this.toggleConfirmController.open()
-                            isOn = this.toggleIsOn
-                          })
+                        Stack() {
+                          Toggle({ type: ToggleType.Switch, isOn: ((item.stationType! === 1 && item.controlPowerStatus! === 0) || (item.stationType! === 2 && item.controlPowerStatus! === 1)) ? true : false })
+                            .width('100%')
+                            .height('70%')
+                            .selectedColor($r('app.color.30D158'))
+                            .switchPointColor("#CAC8C4")
+                          Column()
+                            .width('100%')
+                            .height('100%')
+                            .onClick(()=>{
+                              this.clickStation = item
+                              this.toggleType = 1
+                              this.toggleConfirmController.open()
+                            })
+                        }
+                        .width('100%')
+                        .layoutWeight(1)
+                        .alignContent(Alignment.Top)
                       }
                       .width('50%')
                       .height('100%')
@@ -482,17 +476,24 @@ struct WorkshopPage {
                             .fontColor($r('app.color.FFFFFF'))
                             .fontWeight(FontWeight.Regular)
                             .opacity(0.6)
-                          Toggle({ type: ToggleType.Switch, isOn: item.devicePowerStatus! === 0 ? true : false })
-                            .width('67%')
-                            .height('46%')
-                            .selectedColor($r('app.color.30D158'))
-                            .switchPointColor("#CAC8C4")
-                            .onChange((isOn: boolean) => {
-                              this.clickStation = item
-                              this.toggleType = 2
-                              this.toggleIsOn = isOn
-                              this.toggleConfirmController.open()
-                            })
+                          Stack() {
+                            Toggle({ type: ToggleType.Switch, isOn: item.devicePowerStatus! === 0 ? true : false })
+                              .width('100%')
+                              .height('70%')
+                              .selectedColor($r('app.color.30D158'))
+                              .switchPointColor("#CAC8C4")
+                            Column()
+                              .width('100%')
+                              .height('100%')
+                              .onClick(()=>{
+                                this.clickStation = item
+                                  this.toggleType = 2
+                                  this.toggleConfirmController.open()
+                              })
+                          }
+                          .width('100%')
+                          .layoutWeight(1)
+                          .alignContent(Alignment.Top)
                         }
                       }
                       .width('50%')
@@ -1459,6 +1460,7 @@ struct confirmDialog {
           .fontSize($r('app.float.fontSize_38'))
           .fontColor($r('app.color.FFFFFF'))
           .fontWeight(FontWeight.Medium)
+          .maxLines(1)
       }
       .height('30%')
       .width('100%')