服务直达 - 比特日记
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
服务直达
EntryAbility
 复制成功
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
 1export default class EntryAbility extends UIAbility {
 2  /**
 3   * 初始化时执行
 4   *
 5   * @param want
 6   * @param launchParam
 7   */
 8  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
 9    console.log('onCreate')
10    this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
11    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
12  }
13
14  /**
15   * 唤起
16   * @param want
17   * @param launchParam
18   */
19  onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
20
21  }
22....
export default class EntryAbility extends UIAbility {
  /**
   * 初始化时执行
   *
   * @param want
   * @param launchParam
   */
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    console.log('onCreate')
    this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
  }
  /**
   * 唤起
   * @param want
   * @param launchParam
   */
  onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
  }
....
跳转
 复制成功
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
  1import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
  2import { hilog } from '@kit.PerformanceAnalysisKit';
  3import { window } from '@kit.ArkUI';
  4import { cardDBUtils } from '../utils/CardDBUtils';
  5import preferencesUtil from '../utils/PreferencesUtils';
  6import kvStore from '../utils/KVStore';
  7
  8const DOMAIN = 0x0000;
  9
 10export default class EntryAbility extends UIAbility {
 11  // 跳转的路径地址
 12  private selectPage: string = ''
 13  // 指定的窗口地址
 14  private currentWindowStage: window.WindowStage | null = null
 15
 16  /**
 17   * 初始化时执行
 18   *
 19   * @param want
 20   * @param launchParam
 21   */
 22  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
 23    console.log('onCreate')
 24    console.log(`onNewWant-${JSON.stringify(want.parameters?.params)}`)
 25    this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
 26    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
 27    if (want.parameters) {
 28      let params: Record<string, string> = JSON.parse(JSON.stringify(want.parameters))
 29      this.selectPage = params.targetPage
 30    }
 31  }
 32
 33  /**
 34   * 唤起
 35   * @param want
 36   * @param launchParam
 37   */
 38  onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
 39    console.log(`onNewWant-${JSON.stringify(want.parameters?.params)}`)
 40    if (want.parameters) {
 41      let params: Record<string, string> = JSON.parse(JSON.stringify(want.parameters))
 42      this.selectPage = params.targetPage
 43    }
 44    if (this.currentWindowStage) {
 45      this.onWindowStageCreate(this.currentWindowStage)
 46    }
 47  }
 48
 49  onDestroy(): void {
 50    console.log('onDestroy')
 51    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
 52  }
 53
 54  onWindowStageCreate(windowStage: window.WindowStage): void {
 55    console.log('onWindowStageCreate')
 56    // 加载数据库
 57    cardDBUtils.initCardDB(this.context, 'goodcard')
 58    preferencesUtil.init(this.context, 'goodMail')
 59    preferencesUtil.insertData('theme', 'pink')
 60
 61    kvStore.init(this.context)
 62    kvStore.createStore('myStore')
 63
 64    let targetPage: string = ''
 65    switch (this.selectPage) {
 66      case 'Index':
 67        targetPage = 'pages/Index'
 68        break
 69      case 'DataPage':
 70        targetPage = 'pages/DataPage'
 71        break
 72      default:
 73        targetPage = 'pages/Index'
 74    }
 75
 76    if (this.currentWindowStage === null) {
 77      this.currentWindowStage = windowStage
 78    }
 79
 80    // Main window is created, set main page for this ability
 81    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
 82
 83    windowStage.loadContent(targetPage, (err) => {
 84      if (err.code) {
 85        hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
 86        return;
 87      }
 88      hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
 89    });
 90  }
 91
 92  onWindowStageDestroy(): void {
 93    console.log('onWindowStageDestroy')
 94    // Main window is destroyed, release UI related resources
 95    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
 96  }
 97
 98  onForeground(): void {
 99    console.log('onForeground')
100    // Ability has brought to foreground
101    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
102  }
103
104  onBackground(): void {
105    console.log('onBackground')
106    // Ability has back to background
107    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
108  }
109}
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { window } from '@kit.ArkUI';
import { cardDBUtils } from '../utils/CardDBUtils';
import preferencesUtil from '../utils/PreferencesUtils';
import kvStore from '../utils/KVStore';
const DOMAIN = 0x0000;
export default class EntryAbility extends UIAbility {
  // 跳转的路径地址
  private selectPage: string = ''
  // 指定的窗口地址
  private currentWindowStage: window.WindowStage | null = null
  /**
   * 初始化时执行
   *
   * @param want
   * @param launchParam
   */
  onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    console.log('onCreate')
    console.log(`onNewWant-${JSON.stringify(want.parameters?.params)}`)
    this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
    if (want.parameters) {
      let params: Record<string, string> = JSON.parse(JSON.stringify(want.parameters))
      this.selectPage = params.targetPage
    }
  }
  /**
   * 唤起
   * @param want
   * @param launchParam
   */
  onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void {
    console.log(`onNewWant-${JSON.stringify(want.parameters?.params)}`)
    if (want.parameters) {
      let params: Record<string, string> = JSON.parse(JSON.stringify(want.parameters))
      this.selectPage = params.targetPage
    }
    if (this.currentWindowStage) {
      this.onWindowStageCreate(this.currentWindowStage)
    }
  }
  onDestroy(): void {
    console.log('onDestroy')
    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
  }
  onWindowStageCreate(windowStage: window.WindowStage): void {
    console.log('onWindowStageCreate')
    // 加载数据库
    cardDBUtils.initCardDB(this.context, 'goodcard')
    preferencesUtil.init(this.context, 'goodMail')
    preferencesUtil.insertData('theme', 'pink')
    kvStore.init(this.context)
    kvStore.createStore('myStore')
    let targetPage: string = ''
    switch (this.selectPage) {
      case 'Index':
        targetPage = 'pages/Index'
        break
      case 'DataPage':
        targetPage = 'pages/DataPage'
        break
      default:
        targetPage = 'pages/Index'
    }
    if (this.currentWindowStage === null) {
      this.currentWindowStage = windowStage
    }
    // Main window is created, set main page for this ability
    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
    windowStage.loadContent(targetPage, (err) => {
      if (err.code) {
        hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
        return;
      }
      hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
    });
  }
  onWindowStageDestroy(): void {
    console.log('onWindowStageDestroy')
    // Main window is destroyed, release UI related resources
    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
  }
  onForeground(): void {
    console.log('onForeground')
    // Ability has brought to foreground
    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
  }
  onBackground(): void {
    console.log('onBackground')
    // Ability has back to background
    hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
  }
}
服务直达
 复制成功
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 1@Entry
 2@Component
 3struct Widget02Card {
 4  /*
 5   * The title.
 6   */
 7  readonly title: string = '运动卡片2222';
 8  /*
 9   * The action type.
10   */
11  readonly actionType: string = 'router';
12  /*
13   * The ability name.
14   */
15  readonly abilityName: string = 'EntryAbility';
16  /*
17   * The message.
18   */
19  readonly message: string = 'add detail';
20  /*
21   * The width percentage setting.
22   */
23  readonly fullWidthPercent: string = '100%';
24  /*
25   * The height percentage setting.
26   */
27  readonly fullHeightPercent: string = '100%';
28
29  build() {
30    Column() {
31      Column() {
32        Text(this.title)
33          .fontSize($r('app.float.font_size'))
34          .fontWeight(FontWeight.Medium)
35          .fontColor($r('sys.color.font_primary'))
36      }
37      .width(this.fullWidthPercent)
38
39      Flex({
40        direction: FlexDirection.Row,
41        justifyContent: FlexAlign.SpaceBetween
42      }) {
43        Button('主页').onClick((event: ClickEvent) => {
44          postCardAction(this, {
45            action: this.actionType,
46            abilityName: this.abilityName,
47            params: {
48              targetPage: 'Index'
49            }
50          })
51        })
52        Button('数据').onClick((event: ClickEvent) => {
53          postCardAction(this, {
54            action: this.actionType,
55            abilityName: this.abilityName,
56            params: {
57              targetPage: 'DataPage'
58            }
59          })
60        })
61      }
62      .width('100%')
63    }
64    .height(this.fullHeightPercent)
65    .backgroundColor(Color.Brown)
66
67  }
68}
@Entry
@Component
struct Widget02Card {
  /*
   * The title.
   */
  readonly title: string = '运动卡片2222';
  /*
   * The action type.
   */
  readonly actionType: string = 'router';
  /*
   * The ability name.
   */
  readonly abilityName: string = 'EntryAbility';
  /*
   * The message.
   */
  readonly message: string = 'add detail';
  /*
   * The width percentage setting.
   */
  readonly fullWidthPercent: string = '100%';
  /*
   * The height percentage setting.
   */
  readonly fullHeightPercent: string = '100%';
  build() {
    Column() {
      Column() {
        Text(this.title)
          .fontSize($r('app.float.font_size'))
          .fontWeight(FontWeight.Medium)
          .fontColor($r('sys.color.font_primary'))
      }
      .width(this.fullWidthPercent)
      Flex({
        direction: FlexDirection.Row,
        justifyContent: FlexAlign.SpaceBetween
      }) {
        Button('主页').onClick((event: ClickEvent) => {
          postCardAction(this, {
            action: this.actionType,
            abilityName: this.abilityName,
            params: {
              targetPage: 'Index'
            }
          })
        })
        Button('数据').onClick((event: ClickEvent) => {
          postCardAction(this, {
            action: this.actionType,
            abilityName: this.abilityName,
            params: {
              targetPage: 'DataPage'
            }
          })
        })
      }
      .width('100%')
    }
    .height(this.fullHeightPercent)
    .backgroundColor(Color.Brown)
  }
}
1
2
1onCreate-"{\"targetPage\":\"DataPage\"}"
2onNewWant-"{\"targetPage\":\"DataPage\"}"
onCreate-"{\"targetPage\":\"DataPage\"}"
onNewWant-"{\"targetPage\":\"DataPage\"}"

Copyright ©2010-2022 比特日记 All Rights Reserved.
Powered By 可尔物语
浙ICP备11005866号-12