EnvironmentCustomDialog.ets 2.85 KB
import { SPHelper } from 'wdKit/Index';
import { HostEnum, HostManager, HttpUrlUtils } from 'wdNetwork/Index';

@CustomDialog
export struct EnvironmentCustomDialog {
  @State currentEnvironment: string = HostManager.getHost();
  controller: CustomDialogController
  cancel: () => void = () => {
  }
  confirm: () => void = () => {
  }

  build() {
    Column() {
      Text("请选择环境")
        .fontColor("#222222")
        .fontSize(18)
        .width("100%")
        .fontWeight(FontWeight.Bold)
        .textAlign(TextAlign.Center)
        .margin({ top: 20 })
      Row() {
        Radio({ value: 'Radio1', group: 'radioGroup' })
          .checked(this.currentEnvironment == HostEnum.HOST_SIT)
          .height(20)
          .width(20)
          .onChange((isChecked: boolean) => {
            if (isChecked) {
              this.currentEnvironment = HostEnum.HOST_SIT;
            }
          })
        Text('切换到SIT(测试)环境,重启应用生效')
          .fontSize(14)
      }
      .justifyContent(FlexAlign.Start)
      .width('90%')

      Row() {
        Radio({ value: 'Radio1', group: 'radioGroup' })
          .checked(this.currentEnvironment == HostEnum.HOST_UAT)
          .height(20)
          .width(20)
          .onChange((isChecked: boolean) => {
            if (isChecked) {
              this.currentEnvironment = HostEnum.HOST_UAT;
            }
          })
        Text('切换到UAT(预发布)环境,重启应用生效')
          .fontSize(14)
      }
      .width('90%')
      .justifyContent(FlexAlign.Start)

      Row() {
        Radio({ value: 'Radio1', group: 'radioGroup' })
          .checked(this.currentEnvironment == HostEnum.HOST_PRODUCT)
          .height(20)
          .width(20)
          .onChange((isChecked: boolean) => {
            if (isChecked) {
              this.currentEnvironment = HostEnum.HOST_PRODUCT;
            }
          })
        Text('切换到PROD(现网)环境,重启应用生效')
          .fontSize(14)
      }
      .width('90%')
      .justifyContent(FlexAlign.Start)

      Row() {
        Radio({ value: 'Radio1', group: 'radioGroup' })
          .checked(this.currentEnvironment == HostEnum.HOST_DEV)
          .height(20)
          .width(20)
          .onChange((isChecked: boolean) => {
            if (isChecked) {
              this.currentEnvironment = HostEnum.HOST_DEV;
            }
          })
        Text('切换到DEV(开发)环境,重启应用生效')
          .fontSize(14)
      }
      .width('90%')
      .justifyContent(FlexAlign.Start)

      Button('确认')
        .margin({ top: 20 })
        .onClick(() => {
          // HttpUrlUtils.hostUrl = this.currentEnvironment
          SPHelper.default.saveSync('hostUrl', this.currentEnvironment);
          this.controller.close()
          this.confirm()
        })
    }.height(261).backgroundColor(Color.White).borderRadius(6).width('74%')

  }
}