1e41f4b71Sopenharmony_ci# postCardAction
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci用于卡片内部和提供方应用间的交互,当前支持router、message和call三种类型的事件,仅在卡片中可以调用。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:** 
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本接口从API version 9开始支持。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## postCardAction
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_cipostCardAction(component: Object, action: Object): void
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci执行函数内部的交互,处理component和action对象的相关操作,不返回任何内容.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci**元服务API:** 从API version 11开始,该接口支持在元服务中使用。
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci**参数:**
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci| **参数名** | **类型** | **必填** | **说明** |
23e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
24e41f4b71Sopenharmony_ci| component | Object | 是 | 当前自定义组件的实例,通常传入this。 |
25e41f4b71Sopenharmony_ci| action | Object | 是 | action的具体描述,详情见下表。 |
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ciaction参数说明:
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci| **参数名** | **类型** |  **必填** | **取值说明** |
32e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
33e41f4b71Sopenharmony_ci| action | string | 是 |action的类型,支持三种预定义的类型:<br/>-&nbsp;router:跳转到提供方应用的指定UIAbility。<br/>-&nbsp;message:自定义消息,触发后会调用提供方FormExtensionAbility的[onFormEvent()](../apis-form-kit/js-apis-app-form-formExtensionAbility.md#onformevent)生命周期回调。<br/>-&nbsp;call:后台启动提供方应用。触发后会拉起提供方应用的指定UIAbility(仅支持launchType为singleton的[UIAbility](../../application-models/uiability-launch-type.md),即启动模式为单实例的UIAbility),但不会调度到前台。提供方应用需要具备后台运行权限([ohos.permission.KEEP_BACKGROUND_RUNNING](../../security/AccessToken/permissions-for-all.md#ohospermissionkeep_background_running))。 |
34e41f4b71Sopenharmony_ci| bundleName | string | 否 | action为router&nbsp;/&nbsp;call&nbsp;类型时跳转的包名。 |
35e41f4b71Sopenharmony_ci| moduleName | string | 否 | action为router&nbsp;/&nbsp;call&nbsp;类型时跳转的模块名。 |
36e41f4b71Sopenharmony_ci| abilityName | string | 否 | action为router&nbsp;/&nbsp;call&nbsp;类型时跳转的UIAbility名。 |
37e41f4b71Sopenharmony_ci| uri<sup>11+</sup> | string   | 否   | action为router&nbsp;类型时跳转的UIAbility的统一资源标识符。uri和abilityName同时存在时,abilityName优先。 |
38e41f4b71Sopenharmony_ci| params | Object | 否 | 当前action携带的额外参数,内容使用JSON格式的键值对形式。 |
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci>**说明:**
41e41f4b71Sopenharmony_ci>
42e41f4b71Sopenharmony_ci>"action"为"call"&nbsp;类型时,"params"需填入参数'method',且类型需为string类型,用于触发UIAbility中对应的方法。
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**示例:** 
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci<!--code_no_check-->
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ci```ts
49e41f4b71Sopenharmony_ciButton('跳转')
50e41f4b71Sopenharmony_ci  .width('40%')
51e41f4b71Sopenharmony_ci  .height('20%')
52e41f4b71Sopenharmony_ci  .onClick(() => {
53e41f4b71Sopenharmony_ci    postCardAction(this, {
54e41f4b71Sopenharmony_ci      action: 'router',
55e41f4b71Sopenharmony_ci      bundleName: 'com.example.myapplication',
56e41f4b71Sopenharmony_ci      abilityName: 'EntryAbility',
57e41f4b71Sopenharmony_ci      params: {
58e41f4b71Sopenharmony_ci        message: 'testForRouter' // 自定义要发送的message
59e41f4b71Sopenharmony_ci      }
60e41f4b71Sopenharmony_ci    });
61e41f4b71Sopenharmony_ci  })
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ciButton('拉至后台')
64e41f4b71Sopenharmony_ci  .width('40%')
65e41f4b71Sopenharmony_ci  .height('20%')
66e41f4b71Sopenharmony_ci  .onClick(() => {
67e41f4b71Sopenharmony_ci    postCardAction(this, {
68e41f4b71Sopenharmony_ci      action: 'call',
69e41f4b71Sopenharmony_ci      bundleName: 'com.example.myapplication',
70e41f4b71Sopenharmony_ci      abilityName: 'EntryAbility',
71e41f4b71Sopenharmony_ci      params: {
72e41f4b71Sopenharmony_ci        method: 'fun', // 自定义调用的方法名,必填
73e41f4b71Sopenharmony_ci        message: 'testForCall' // 自定义要发送的message
74e41f4b71Sopenharmony_ci      }
75e41f4b71Sopenharmony_ci    });
76e41f4b71Sopenharmony_ci  })
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ciButton('URI跳转')
79e41f4b71Sopenharmony_ci  .width('40%')
80e41f4b71Sopenharmony_ci  .height('20%')
81e41f4b71Sopenharmony_ci  .onClick(() => {
82e41f4b71Sopenharmony_ci    postCardAction(this, {
83e41f4b71Sopenharmony_ci      action: 'router',
84e41f4b71Sopenharmony_ci      uri: 'example://uri.ohos.com/link_page',
85e41f4b71Sopenharmony_ci      params: {
86e41f4b71Sopenharmony_ci        message: 'router msg for dynamic uri deeplink' // 自定义要发送的message
87e41f4b71Sopenharmony_ci      }
88e41f4b71Sopenharmony_ci    });
89e41f4b71Sopenharmony_ci  })
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci```
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**待跳转应用 [module.json5](../../quick-start/module-configuration-file.md#skills标签) uris 配置示例:**
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci```json
96e41f4b71Sopenharmony_ci"abilities": [
97e41f4b71Sopenharmony_ci  {
98e41f4b71Sopenharmony_ci    "skills": [
99e41f4b71Sopenharmony_ci      {
100e41f4b71Sopenharmony_ci        "uris": [
101e41f4b71Sopenharmony_ci          {
102e41f4b71Sopenharmony_ci            "scheme": "example",
103e41f4b71Sopenharmony_ci            "host": "uri.ohos.com",
104e41f4b71Sopenharmony_ci            "path": "link_page"
105e41f4b71Sopenharmony_ci          },
106e41f4b71Sopenharmony_ci        ]
107e41f4b71Sopenharmony_ci      }
108e41f4b71Sopenharmony_ci    ],
109e41f4b71Sopenharmony_ci  }
110e41f4b71Sopenharmony_ci]
111e41f4b71Sopenharmony_ci```
112