• Home
Name Date Size #Lines LOC

..--

AppScope/22-Oct-2025-3633

entry/22-Oct-2025-2,1321,882

hvigor/22-Oct-2025-2422

screenshots/device/22-Oct-2025-

.gitignoreD22-Oct-2025110 1010

README_zh.mdD22-Oct-20253.2 KiB7654

build-profile.json5D22-Oct-20251.1 KiB4443

hvigorfile.tsD22-Oct-2025158 21

hvigorwD22-Oct-20252.1 KiB6428

hvigorw.batD22-Oct-20252 KiB7356

oh-package.json5D22-Oct-2025832 2725

ohosTest.mdD22-Oct-2025873 1310

README_zh.md

1#  多设备自适应服务卡片
2
3### 介绍
4
5本示例展示Js工程中服务卡片的布局和使用,其中卡片内容显示使用了一次开发,多端部署的能力实现多设备自适应。
6用到了卡片扩展模块接口,[@ohos.app.form.FormExtensionAbility](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formExtensionAbility.md)7
8卡片信息和状态等相关类型和枚举接口,[@ohos.app.form.formInfo](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formInfo.md)9
10卡片数据绑定的能力接口[@ohos.app.form.formBindingData](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/reference/apis-form-kit/js-apis-app-form-formBindingData.md)11
12
13
14### 效果预览
15
16|主页|卡片|
17|-------|-------|
18|![](screenshots/device/main.png)|![](screenshots/device/card.png)|
19
20使用说明
21
22长按示例应用,等待出现服务卡片字样,点击后可左右滑动选择需要的卡片尺寸,添加到屏幕。
23
24### 工程目录
25```
26entry/src/main
27|---module.json5                           // 添加卡片拓展能力
28|---/ets/pages
29|   |---index.ets                          // 首页
30|---/ets/entryformability
31|   |---EntryFormAbility.ets               // 定义卡片对象首次被创建时需要做的操作
32|---js/complex/pages/index                 // 定义卡片内容
33|   |---index.hml
34|   |---index.css
35|   |---index.json
36|---resources/base/profile
37|   |---form_config.json                   // 配置卡片(卡片名称,引入js卡片,卡片窗口大小等)
38```
39
40### 具体实现
411、在module.json5文件添加拓展能力,类型为卡片,并设置卡片入口srcEntrance和卡片元数据metadata。[源码参考](entry/src/main/module.json5) 例如:"metadata": [
42{
43"name": "ohos.extension.form",
44"resource": "$profile:form_config"
45}。
462、初始化卡片:通过实现@ohos.app.form.FormExtensionAbility卡片操作类,在卡片对象首次被创建时,初始化卡片绑定数据为空,并将卡片状态设置为就绪状态READY。 例如:onCreate(){
47formBindingData.createFormBindingData({}) onAcquireFormState(want) {
48return formInfo.FormState.READY }。
493、配置卡片:用js编写相应的卡片,将卡片配置到resources/base/profile/form_config, [源码参考](entry/src/main/resources/base/profile/form_config.json) 。
50
51### 相关权限
52
53不涉及。
54
55### 依赖
56
57不涉及。
58
59### 约束与限制
60
611.本示例支持在标准系统上运行。
62
632.本示例需要使用DevEco Studio 版本号(4.0 Release)及以上版本才可编译运行。
64
653.本示例已适配API10版本SDK,SDK版本号(API Version 10 Release),镜像版本号(4.0 Release)。
66
67### 下载
68
69如需单独下载本工程,执行如下命令:
70```
71git init
72git config core.sparsecheckout true
73echo code/SuperFeature/Widget/AdaptiveServiceWidget/ > .git/info/sparse-checkout
74git remote add origin https://gitee.com/openharmony/applications_app_samples.git
75git pull origin master
76```