chenjun3_wd

环境切换

1 import { Params } from 'wdBean'; 1 import { Params } from 'wdBean';
2 import { WDRouterPage, WDRouterRule } from 'wdRouter'; 2 import { WDRouterPage, WDRouterRule } from 'wdRouter';
3 -import featureAbility from '@ohos.ability.featureAbility'; 3 +import { EnvironmentCustomDialog } from './EnvironmentCustomDialog';
4 4
5 const TAG = 'AboutPageUI'; 5 const TAG = 'AboutPageUI';
6 6
@@ -9,7 +9,18 @@ export struct AboutPageUI { @@ -9,7 +9,18 @@ export struct AboutPageUI {
9 @State listData: Array<string | Array<string>> = ['隐私授权协议', '软件许可及用户协议']; 9 @State listData: Array<string | Array<string>> = ['隐私授权协议', '软件许可及用户协议'];
10 @State message: string = '京ICP备16066560号-6A Copyright © 人民日报客户端\nall rights reserved.' 10 @State message: string = '京ICP备16066560号-6A Copyright © 人民日报客户端\nall rights reserved.'
11 @State version: string = '版本号:v' 11 @State version: string = '版本号:v'
  12 + clickTimes: number = 0
  13 + dialogController: CustomDialogController = new CustomDialogController({
  14 + builder: EnvironmentCustomDialog({
  15 + cancel: () => {
12 16
  17 + },
  18 + confirm: () => {
  19 + }
  20 + }),
  21 + customStyle: true,
  22 + alignment: DialogAlignment.Center
  23 + })
13 24
14 build() { 25 build() {
15 Navigation() { 26 Navigation() {
@@ -19,18 +30,24 @@ export struct AboutPageUI { @@ -19,18 +30,24 @@ export struct AboutPageUI {
19 .title('关于') 30 .title('关于')
20 } 31 }
21 32
22 - aboutToAppear(){ 33 + aboutToAppear() {
23 let context = getContext(); 34 let context = getContext();
24 context.getApplicationContext(); 35 context.getApplicationContext();
25 } 36 }
26 37
27 - @Builder aboutUi() { 38 + @Builder
  39 + aboutUi() {
28 Column() { 40 Column() {
29 Image($r('app.media.setting_about_logo')) 41 Image($r('app.media.setting_about_logo'))
30 .width('278lpx') 42 .width('278lpx')
31 .height('154lpx') 43 .height('154lpx')
32 - .margin({top:'173lpx',bottom:'154lpx'})  
33 - 44 + .margin({ top: '173lpx', bottom: '154lpx' })
  45 + .onClick(() => {
  46 + this.clickTimes++
  47 + if (this.clickTimes > 2) {
  48 + this.dialogController.open()
  49 + }
  50 + })
34 // Row(){ 51 // Row(){
35 // 52 //
36 // }.backgroundColor(Color.Yellow) 53 // }.backgroundColor(Color.Yellow)
@@ -44,19 +61,17 @@ export struct AboutPageUI { @@ -44,19 +61,17 @@ export struct AboutPageUI {
44 // .height('97lpx') 61 // .height('97lpx')
45 62
46 63
47 -  
48 -  
49 - List(){  
50 - ForEach(this.listData, (item:string, index : number) =>{ 64 + List() {
  65 + ForEach(this.listData, (item: string, index: number) => {
51 ListItem() { 66 ListItem() {
52 this.getArrowCell(item, index) 67 this.getArrowCell(item, index)
53 - }.onClick(() =>{ 68 + }.onClick(() => {
54 if (index == 0) { 69 if (index == 0) {
55 - let bean={contentId:"1",pageID:""} as Params  
56 - WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage,bean)  
57 - }else{  
58 - let bean={contentId:"2",pageID:""} as Params  
59 - WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage,bean) 70 + let bean = { contentId: "1", pageID: "" } as Params
  71 + WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage, bean)
  72 + } else {
  73 + let bean = { contentId: "2", pageID: "" } as Params
  74 + WDRouterRule.jumpWithPage(WDRouterPage.loginProtocolPage, bean)
60 } 75 }
61 }) 76 })
62 }) 77 })
@@ -77,22 +92,21 @@ export struct AboutPageUI { @@ -77,22 +92,21 @@ export struct AboutPageUI {
77 .fontSize('25lpx') 92 .fontSize('25lpx')
78 .textAlign(TextAlign.Center) 93 .textAlign(TextAlign.Center)
79 .fontColor($r("app.color.color_666666")) 94 .fontColor($r("app.color.color_666666"))
80 - .margin({bottom:'31lpx'}) 95 + .margin({ bottom: '31lpx' })
81 96
82 Text(this.message) 97 Text(this.message)
83 .fontSize('19lpx') 98 .fontSize('19lpx')
84 .textAlign(TextAlign.Center) 99 .textAlign(TextAlign.Center)
85 .fontColor($r("app.color.color_999999")) 100 .fontColor($r("app.color.color_999999"))
86 - .margin({bottom:'35lpx'}) 101 + .margin({ bottom: '35lpx' })
87 } 102 }
88 .width('100%') 103 .width('100%')
89 .height('100%') 104 .height('100%')
90 } 105 }
91 106
92 -  
93 -  
94 // 右文字+箭头cell 107 // 右文字+箭头cell
95 - @Builder getArrowCell(item:string, index:number) { 108 + @Builder
  109 + getArrowCell(item: string, index: number) {
96 110
97 Row() { 111 Row() {
98 // 左侧标题 112 // 左侧标题
@@ -109,10 +123,8 @@ export struct AboutPageUI { @@ -109,10 +123,8 @@ export struct AboutPageUI {
109 .justifyContent(FlexAlign.SpaceBetween) 123 .justifyContent(FlexAlign.SpaceBetween)
110 .height('97lpx') 124 .height('97lpx')
111 .width('100%') 125 .width('100%')
112 - .padding({left:'29lpx',right:'29lpx'}) 126 + .padding({ left: '29lpx', right: '29lpx' })
113 } 127 }
114 -  
115 -  
116 } 128 }
117 129
118 130
  1 +import { SPHelper } from 'wdKit/Index';
  2 +import { HttpUrlUtils } from 'wdNetwork/Index';
  3 +
  4 +@CustomDialog
  5 +export struct EnvironmentCustomDialog {
  6 + currentEnvironment: string = HttpUrlUtils.HOST_PRODUCT;
  7 + controller: CustomDialogController
  8 + cancel: () => void = () => {
  9 + }
  10 + confirm: () => void = () => {
  11 + }
  12 +
  13 + build() {
  14 + Column() {
  15 + Text("请选择环境")
  16 + .fontColor("#222222")
  17 + .fontSize(18)
  18 + .width("100%")
  19 + .fontWeight(FontWeight.Bold)
  20 + .textAlign(TextAlign.Center)
  21 + .margin({ top: 20 })
  22 + Row() {
  23 + Radio({ value: 'Radio1', group: 'radioGroup' })
  24 + .checked(true)
  25 + .height(20)
  26 + .width(20)
  27 + .onChange((isChecked: boolean) => {
  28 + if (isChecked) {
  29 + this.currentEnvironment = HttpUrlUtils.HOST_SIT;
  30 + }
  31 + })
  32 + Text('切换到SIT(测试)环境,重启应用生效')
  33 + .fontSize(14)
  34 + }
  35 + .justifyContent(FlexAlign.Start)
  36 + .width('90%')
  37 +
  38 + Row() {
  39 + Radio({ value: 'Radio1', group: 'radioGroup' })
  40 + .checked(true)
  41 + .height(20)
  42 + .width(20)
  43 + .onChange((isChecked: boolean) => {
  44 + if (isChecked) {
  45 + this.currentEnvironment = HttpUrlUtils.HOST_UAT;
  46 + }
  47 + })
  48 + Text('切换到UAT(预发布)环境,重启应用生效')
  49 + .fontSize(14)
  50 + }
  51 + .width('90%')
  52 + .justifyContent(FlexAlign.Start)
  53 +
  54 + Row() {
  55 + Radio({ value: 'Radio1', group: 'radioGroup' })
  56 + .checked(true)
  57 + .height(20)
  58 + .width(20)
  59 + .onChange((isChecked: boolean) => {
  60 + if (isChecked) {
  61 + this.currentEnvironment = HttpUrlUtils.HOST_PRODUCT;
  62 + }
  63 + })
  64 + Text('切换到PROD(现网)环境,重启应用生效')
  65 + .fontSize(14)
  66 + }
  67 + .width('90%')
  68 + .justifyContent(FlexAlign.Start)
  69 +
  70 + Row() {
  71 + Radio({ value: 'Radio1', group: 'radioGroup' })
  72 + .checked(true)
  73 + .height(20)
  74 + .width(20)
  75 + .onChange((isChecked: boolean) => {
  76 + if (isChecked) {
  77 + this.currentEnvironment = HttpUrlUtils.HOST_DEV;
  78 + }
  79 + })
  80 + Text('切换到DEV(开发)环境,重启应用生效')
  81 + .fontSize(14)
  82 + }
  83 + .width('90%')
  84 + .justifyContent(FlexAlign.Start)
  85 +
  86 + Button('确认')
  87 + .margin({ top: 20 })
  88 + .onClick(() => {
  89 + // HttpUrlUtils.hostUrl = this.currentEnvironment
  90 + SPHelper.default.saveSync('hostUrl', this.currentEnvironment);
  91 + this.controller.close()
  92 + this.confirm()
  93 + })
  94 + }.height(261).backgroundColor(Color.White).borderRadius(6).width('74%')
  95 +
  96 + }
  97 +}
@@ -4,8 +4,8 @@ import UIAbility from '@ohos.app.ability.UIAbility'; @@ -4,8 +4,8 @@ import UIAbility from '@ohos.app.ability.UIAbility';
4 import Want from '@ohos.app.ability.Want'; 4 import Want from '@ohos.app.ability.Want';
5 import window from '@ohos.window'; 5 import window from '@ohos.window';
6 import { registerRouter } from 'wdRouter'; 6 import { registerRouter } from 'wdRouter';
7 -import { SPHelper, WindowModel } from 'wdKit';  
8 -import { WDHttp } from 'wdNetwork' 7 +import { SPHelper, StringUtils, WindowModel } from 'wdKit';
  8 +import { HttpUrlUtils, WDHttp } from 'wdNetwork';
9 9
10 export default class EntryAbility extends UIAbility { 10 export default class EntryAbility extends UIAbility {
11 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 11 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
@@ -13,6 +13,10 @@ export default class EntryAbility extends UIAbility { @@ -13,6 +13,10 @@ export default class EntryAbility extends UIAbility {
13 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); 13 hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
14 registerRouter(); 14 registerRouter();
15 WDHttp.initHttpHeader() 15 WDHttp.initHttpHeader()
  16 + const spHostUrl = SPHelper.default.getSync('hostUrl', '') as string
  17 + if (StringUtils.isNotEmpty(spHostUrl)) {
  18 + HttpUrlUtils.hostUrl = spHostUrl
  19 + }
16 } 20 }
17 21
18 onDestroy(): void { 22 onDestroy(): void {