当前位置:   article > 正文

HarmonyOS学习,灵活运用工程结构及应用程序结构

HarmonyOS学习,灵活运用工程结构及应用程序结构

HarmonyOS学习,灵活运用工程结构及应用程序结构

工程结构及应用程序结构
一、自定义工程框架
在这里插入图片描述

1、在工程目录下的build-profile.json5文件中定义app参数和多模块数组参数(并设置phone模块为主模块)。一个模块配置一个子目录。
应用的主模块。一个APP中,对于同一设备类型必须有且只有一个入口Entry类型的模块。
{
“app”: {
“signingConfigs”: [],
“compileSdkVersion”: 9,
“compatibleSdkVersion”: 9,
“products”: [
{
“name”: “default”,
“signingConfig”: “default”,
}
]
},
“modules”: [
{
“name”: “phone”,
“srcPath”: “./product/phone”,
“targets”: [
{
“name”: “default”,
“applyToProducts”: [
“default”
]
}
]
},
{
“name”: “common”,
“srcPath”: “./common”
},
{
“name”: “home”,
“srcPath”: “./features/home”
},
{
“name”: “newproduct”,
“srcPath”: “./features/newproduct”
},
{
“name”: “shopcart”,
“srcPath”: “./features/shopcart”
},
{
“name”: “personal”,
“srcPath”: “./features/personal”
},
{
“name”: “commoditydetail”,
“srcPath”: “./features/commoditydetail”
},
{
“name”: “orderdetail”,
“srcPath”: “./features/orderdetail”
}
]
}

2、在主模块目录下oh-package.json5文件中配置dependencies,将模块关联关键字
{
“license”: “ISC”,
“devDependencies”: {},
“name”: “phone”,
“description”: “example description”,
“repository”: {},
“version”: “1.0.0”,
“dependencies”: {
“@ohos/orderdetail”: “file:…/…/features/orderdetail”,
“@ohos/commoditydetail”: “…/…/features/commoditydetail”,
“@ohos/newproduct”: “…/…/features/newproduct”,
“@ohos/home”: “…/…/features/home”,
“@ohos/common”: “file:…/…/common”,
“@ohos/personal”: “…/…/features/personal”,
“@ohos/shopcart”: “…/…/features/shopcart”
}
}

3、在主模块的子目录src/main下的文件module.json5配置EntryAbility的相关参数

{
“module”: {
“name”: “phone”,
“type”: “entry”,
“description”: “ s t r i n g : m o d u l e d e s c " , " m a i n E l e m e n t " : " E n t r y A b i l i t y " , " d e v i c e T y p e s " : [ " p h o n e " , " t a b l e t " ] , " d e l i v e r y W i t h I n s t a l l " : t r u e , " i n s t a l l a t i o n F r e e " : f a l s e , " p a g e s " : " string:module_desc", "mainElement": "EntryAbility", "deviceTypes": [ "phone", "tablet" ], "deliveryWithInstall": true, "installationFree": false, "pages": " string:moduledesc","mainElement":"EntryAbility","deviceTypes":["phone","tablet"],"deliveryWithInstall":true,"installationFree":false,"pages":"profile:main_pages”,
“abilities”: [
{
“name”: “EntryAbility”,
“srcEntry”: “./ets/entryability/EntryAbility.ets”,
“description”: “ s t r i n g : E n t r y A b i l i t y d e s c " , " i c o n " : " string:EntryAbility_desc", "icon": " string:EntryAbilitydesc","icon":"media:icon”,
“label”: “ s t r i n g : E n t r y A b i l i t y l a b e l " , " s t a r t W i n d o w I c o n " : " string:EntryAbility_label", "startWindowIcon": " string:EntryAbilitylabel","startWindowIcon":"media:icon”,
“startWindowBackground”: “$color:start_window_background”,
“exported”: true,
“skills”: [
{
“entities”: [
“entity.system.home”
],
“actions”: [
“action.system.home”
]
}
]
}
]
}
}

在这里插入图片描述
在这里插入图片描述

设置主页"pages": “$profile:main_pages”,main_pages.json设置主页参数,并且各主页参数对应的控件都需要用@Entry装饰器装饰
{
“src”: [
“pages/SplashPage”,
“pages/MainPage”,
“pages/CommodityDetailPage”,
“pages/ConfirmOrderPage”,
“pages/PayOrderPage”,
“pages/OrderDetailListPage”
]
}

4、选择其中一个子模块,例如common子模块,配置oh-package.json5文件设置主页面为index.ets.

Index.ets的内容,是将本模块控件export
在这里插入图片描述
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/317278
推荐阅读
相关标签
  

闽ICP备14008679号