




















为支持开发者单独获取特定场景的页面和功能,本模板将功能完全自闭环的部分能力抽离出独立的行业组件模块,不依赖公共基础能力包,开发者可以单独集成,开箱即用,降低使用难度。
├─commons/common/src/main
│ ├─ets
│ │ ├─cardManager
│ │ │ CardManager.ets // 卡片管理
│ │ │ EntryContext.ets // 应用上下文
│ │ │ SubscriberClass.ets // 卡片公共事件
│ │ ├─components
│ │ │ NavHeaderBar.ets // navigation页面抬头
│ │ │ CommonConfirmDialog.ets // 确认弹窗
│ │ │ LoadingDialog.ets // 加载中弹窗
│ │ ├─constants
│ │ │ Common.ets // 公共常量
│ │ ├─mapper
│ │ │ Index.ets // 数据映射
│ │ ├─models
│ │ │ RouterModel.ets // 路由参数对象
│ │ │ StorageModel.ets // AppStorage参数对象
│ │ │ TabBarModel.ets // 底部导航栏对象
│ │ └─utils
│ │ AsWebRichText.ets // asweb富文本展示
│ │ Logger.ets // 日志方法
│ │ PermissionUtil.ets // 权限申请方法
│ │ RouterModule.ets // 路由工具方法
│ │ Utils.ets // 公共方法
│ └─resources
├─commons/network/src/main
│ ├─ets
│ │ ├─apis
│ │ │ APIList.ets // 网络请求API
│ │ │ AxiosHttp.ets // 网络请求封装
│ │ │ AxiosModel.ets // 网络请求对象
│ │ │ HttpRequest.ets // 网络请求
│ │ ├─constants
│ │ │ Index.ets // 网络请求常量
│ │ ├─mocks
│ │ │ └─MockData
│ │ │ Order.ets // 点餐mock数据
│ │ │ Store.ets // 店铺mock数据
│ │ │ User.ets // 用户mock数据
│ │ │ AxiosMock.ets // mock请求
│ │ │ RequestMock.ets // mock API
│ │ └─types
│ │ Order.ets // 点餐抽象类
│ │ Request.ets // 请求参数抽象类
│ │ Response.ets // 响应参数抽象类
│ │ Store.ets // 店铺抽象类
│ │ User.ets // 用户抽象类
│ └─resources
│─components/base_ui/src/main
│ ├─ets
│ │ ├─components
│ │ │ BusinessTimeDialog.ets // 店铺休息组件
│ │ │ CallTelSheetBuilder.ets // 拨号组件
│ │ │ CouponCardComp.ets // 优惠券组件
│ │ │ OrderGoodsCard.ets // 订单商品组件
│ │ │ PayTypeDialog.ets // 支付弹窗组件
│ │ │ SheetHeaderComp.ets // 半模态标题组件
│ │ ├─constants
│ │ │ Index.ets // 常量数据
│ │ ├─models
│ │ │ Index.ets // 数据类型
│ │ └─utils
│ │ Index.ets // 工具方法
│─components/goods_detail/src/main
│ ├─ets
│ │ ├─components
│ │ │ GoodsDetail // 商品详情组件
│ │ ├─constants
│ │ │ Index.ets // 常量数据
│ │ └─models
│ │ Index.ets // 数据类型
│─components/my_wallet/src/main
│ ├─ets
│ │ ├─components
│ │ │ MyWallet // 我的钱包组件
│ │ │ RechargeRecordComp // 充值记录组件
│ │ ├─models
│ │ │ Index.ets // 数据类型
│ │ └─utils
│ │ Logger.ets // 日志方法
│─components/select_store/src/main
│ ├─ets
│ │ ├─components
│ │ │ HwMapComp // 华为地图组件
│ │ │ SelectStore // 选择店铺组件
│ │ │ StoreCard // 店铺卡片组件
│ │ └─models
│ │ Index.ets // 数据类型
│─components/snack_sized_deal/src/main
│ ├─ets
│ │ ├─components
│ │ │ SnackSizedDeal // 超值加购组件
│ │ ├─constants
│ │ │ Index.ets // 常量数据
│ │ └─models
│ │ Index.ets // 数据类型
│─features/order/src/main
│ ├─ets
│ │ ├─api
│ │ │ Index.ets // 接口请求封装
│ │ ├─components
│ │ │ CustomSelectDialog.ets // 数据选择半模态弹窗
│ │ │ GoodInfoComp.ets // 商品信息组件
│ │ │ MyCarComp.ets // 购物车组件
│ │ │ MyCarListComp.ets // 购物车列表组件
│ │ │ OrderListComp.ets // 订单内商品列表组件
│ │ │ TitleComp.ets // 点餐标题栏组件
│ │ ├─constants
│ │ │ OrderConstant.ets // 常量数据
│ │ ├─mapper
│ │ │ Index.ets // 数据映射
│ │ ├─models
│ │ │ Index.ets // 数据类型
│ │ │ MustGoodsController.ets // 必选品控制对象
│ │ └─pages
│ │ ConfirmOrderPage.ets // 确认订单页面
│ │ GoodDetailPage.ets // 商品详情页面
│ │ MerchantDetailPage.ets // 店铺详情页面
│ │ OrderPage.ets // 点餐页面
│ │ PreviewImagePage.ets // 图片预览页面
│ │ RemarksPage.ets // 添加备注页面
│ │ SelectCouponPage.ets // 选择优惠券页面
│ │ SelectStorePage.ets // 选择店铺页面
│ │ SnackSizedDealPage.ets // 超值加购页面
│ └─resources
│─features/order_list/src/main
│ ├─ets
│ │ ├─api
│ │ │ Index.ets // 接口请求封装
│ │ ├─components
│ │ │ ButtonListComp.ets // 卡片按钮组件
│ │ │ CommonTab.ets // 订单列表tab组件
│ │ │ OrderCard.ets // 订单卡片组件
│ │ │ OrderTypeComp.ets // 订单详情顶部组件
│ │ │ PaymentDetailsComp.ets // 订单支付详情组件
│ │ │ ReductionCardComp.ets // 订单优惠详情组件
│ │ │ StoreInfoCardComp.ets // 商户卡片组件
│ │ ├─mapper
│ │ │ Index.ets // 数据映射
│ │ ├─models
│ │ │ Index.ets // 订单列表里的数据对象
│ │ └─pages
│ │ HwMapPage.ets // 商户位置页面
│ │ OrderDetailPage.ets // 订单详情页面
│ │ OrderListPage.ets // 订单列表页面
│ └─resources
│─features/personal_center/src/main
│ ├─ets
│ │ ├─api
│ │ │ Index.ets // 接口请求封装
│ │ └─pages
│ │ AnswerPage.ets // 常见问题页面
│ │ FrequentQuestionPage.ets // 问题答复页面
│ │ MyCouponsPage.ets // 我的优惠券页面
│ │ MyWalletPage.ets // 我的页面
│ │ PersonalCenterPage.ets // 我的钱包页面
│ │ RechargeRecordPage.ets // 钱包充值记录页面
│ │ WalletTermsPage.ets // 会员储值协议页面
│ └─resources
│─preload
│ handler.js // 预加载函数
│ package.json // 预加载函数信息
└─products/phone/src/main
├─ets
│ │ ├─api
│ │ │ Index.ets // 接口请求封装
│ ├─components
│ │ CustomTabBar.ets // 自定义底部tab栏组件
│ ├─entryability
│ │ EntryAbility.ets // 应用程序入口
│ ├─entryformability
│ │ EntryFormAbility.ets // 卡片程序入口
│ │ ├─mapper
│ │ │ Index.ets // 数据映射
│ ├─pages
│ │ HomePage.ets // 主页面
│ │ Index.ets // 入口页面
│ └─widget/pages
│ WidgetCard.ets // 卡片页面
└─resources
@Local mapController?: map.MapComponentController;
@Local mapEventManager ?: map.MapEventManager;
private marker: Map<string, map.Marker> = new Map<string, map.Marker>()
private mapOption?: mapCommon.MapOptions;
private callback?: AsyncCallback<map.MapComponentController>;
private style: mapCommon.MyLocationStyle = {
anchorU: 0.5,
anchorV: 0.5,
radiusFillColor: 0xff00FFFFFF,
displayType: mapCommon.MyLocationDisplayType.FOLLOW,
};
aboutToAppear(): void {
this.mapOption = {
position: {
target: {
latitude: this.selectLocation.latitude,
longitude: this.selectLocation.longitude,
},
zoom: 15,
},
};
this.callback = async (err, mapController) => {
if (!err) {
this.mapController = mapController;
this.mapEventManager = this.mapController.getEventManager();
this.mapEventManager?.on(‘markerClick’, (marker: map.Marker) => {
console.info(`on-markerClick marker = ${marker.getTitle()}`);
this.changeStore(marker.getTitle())
});
this.mapController.on(‘mapLoad’, () => {
console.info(‘mapLoad success’);
});
this.abilityEnabled();
mapController.setMyLocationStyle(this.style);
this.updateMakers()
}
};
}
// 地图选择店铺后移动镜头
@Monitor(‘selectStore.id’)
cameraChange(monitor: IMonitor) {
if (monitor.value()?.now) {
this.moveCamera(this.selectLocation)
}
}
// 监听位置变化,更新标记
@Monitor(‘locations’)
infoChange(monitor: IMonitor) {
if (monitor.value()?.now) {
this.updateMakers()
}
}
// 更新地图标记位
updateMakers() {
this.mapController?.clear()
this.marker?.clear()
this.locations.forEach(location => {
this.addMarker(location)
})
if (this.selectLocation) {
this.moveCamera(this.selectLocation)
}
}
// 创建地图标记位
async addMarker(location: MapLocation) {
// Marker初始化参数
let markerOptions: mapCommon.MarkerOptions = {
position: {
latitude: location.latitude,
longitude: location.longitude,
},
rotation: 0,
visible: true,
zIndex: 0,
alpha: 1,
anchorU: 0.5,
anchorV: 1,
clickable: true,
draggable: true,
flat: false,
icon: location.icon || ‘ic_store_location.png’,
};
// 创建Marker
let marker = await this.mapController?.addMarker(markerOptions);
if (marker) {
// 设置信息窗的标题
marker.setTitle(location.title);
this.marker.set(location.id, marker)
}
}
// 移动镜头
moveCamera(location: MapLocation) {
this.mapController?.animateCameraStatus(map.newLatLng({
latitude: location.latitude,
longitude: location.longitude,
}, 15), 200).then(() => {
this.marker?.get(location.id)?.setInfoWindowVisible(true)
});
}
// 加载地图组件
build() {
Stack({ alignContent: Alignment.BottomStart }) {
MapComponent({
mapOptions: this.mapOption,
mapCallback: this.callback,
})
}.height(‘100%’).margin({ bottom: this.mapMarginBottom / 2 }).constraintSize({ maxHeight: ‘100%’ })
}
将commons/lib_common/src/main/ets/httprequest/HttpRequestApi.ets文件中的mock接口替换为真实的服务器接口。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。