0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

基于ArkUI eTS开发的坚果食谱(NutRecipes)

ArkUI详解 来源:鸿蒙实验室 作者:鸿蒙实验室 2022-08-18 08:23 次阅读

今天为大家做一款坚果食谱,有大量的食谱数据,覆盖了很多种类的食谱。

请求urlUrl:https://way.jd.com/jisuapi/search?keyword=白菜&num=10&start=0&appkey=7c913be32b690701cd994d804a6d4294

实现的功能:

获取接口数据

菜谱列表

菜谱详情页

你能学到的有:

网络请求

可滚动组件

容器组件

路由跳转

基础组件

文件结构

.

├── config.json

├── ets

│ └── MainAbility

│ ├── app.ets

│ ├── data

│ │ ├── get_cook_data.ets

│ │ └── get_test.ets

│ ├── model

│ │ ├── cookDetailModel.ets

│ │ ├── cookModel.ets

│ │ ├── materialModel.ets

│ │ └── processModel.ets

│ └── pages

│ ├── Main.ets

│ ├── cookbookDetails.ets

│ └── index.ets

└── resources

├── base

│ ├── element

│ │ ├── color.json

│ │ └── string.json

│ └── media

│ └── icon.png

└── rawfile

效果预览:

image-20220724104951823

获取新闻接口a

标识:get

接口地址:

https://way.jd.com/jisuapi/search

请求方式:

HTTPS GET POST

请求示例:

Url:https://way.jd.com/jisuapi/search?keyword=白菜&num=10&start=0&appkey=7c913be32b690701cd994d804a6d4294

请求参数说明:

image-20220724105047682

返回参数说明:

image-20220724105034435image-20220724105104455

JSON返回示例

{"code":"10000","charge":false,"msg":"查询成功","result":{

"status": "0",

"msg": "ok",

"result": {

"num": "10",

"list": [

{

"id": "8",

"classid": "2",

"name": "醋溜白菜",

"peoplenum": "1-2人",

"preparetime": "10-20分钟",

"cookingtime": "10-20分钟",

"content": "醋溜白菜,是北方人经常吃的一道菜,尤其是在多年前的冬天。那时,没有大棚菜,冬天,家家每天佐餐的基本上都是冬储大白菜,聪明的家庭主妇总是想方设法将这单调的菜变成多种菜式,于是,醋溜白菜被频繁的端上餐桌。

美食不分贵贱,用最平凡的原料、最简单的调料和最普通的手法做出美味的菜肴来才是美食的真谛。

这次,我做的醋溜白菜,近似鲁菜的做法,使个这道菜酸甜浓郁、开胃下饭、老少咸宜。",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/115138_46688.jpg",

"tag": "减肥,家常菜,排毒,补钙",

"material": [

{

"mname": "油",

"type": "0",

"amount": "适量"

},

{

"mname": "盐",

"type": "0",

"amount": "适量"

},

{

"mname": "花椒",

"type": "0",

"amount": "适量"

},

{

"mname": "干红椒",

"type": "0",

"amount": "适量"

},

{

"mname": "葱",

"type": "0",

"amount": "适量"

},

{

"mname": "姜",

"type": "0",

"amount": "适量"

},

{

"mname": "蒜",

"type": "0",

"amount": "适量"

},

{

"mname": "醋",

"type": "0",

"amount": "适量"

},

{

"mname": "酱油",

"type": "0",

"amount": "适量"

},

{

"mname": "糖",

"type": "0",

"amount": "适量"

},

{

"mname": "淀粉",

"type": "0",

"amount": "适量"

},

{

"mname": "白菜",

"type": "1",

"amount": "380g"

}

],

"process": [

{

"pcontent": "准备食材。",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162550_84583.jpg"

},

{

"pcontent": "将白菜斜刀片成薄片。",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162551_90620.jpg"

},

{

"pcontent": "片切好的白菜帮与菜叶分别入好。",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162551_20925.jpg"

},

{

"pcontent": "盐、糖、生抽、醋淀粉加少许水调匀备用。",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162552_23125.jpg"

},

{

"pcontent": "锅中油烧热,先入花椒炒香后捞出。再加入干红椒段略炒。",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162552_57046.jpg"

},

{

"pcontent": "加入葱姜蒜煸炒香,然后入白菜帮翻炒。",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162553_89090.jpg"

},

{

"pcontent": "炒至菜帮变软时,加入白菜叶。",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162553_40445.jpg"

},

{

"pcontent": "快速翻炒至菜软,勾入碗汁",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162554_92210.jpg"

},

{

"pcontent": "使汤汁均匀的包裹在菜帮上即可",

"pic": "http://api.jisuapi.com/recipe/upload/20160719/162554_29522.jpg"

}

]

}

]

}

}}

接下来,我们开始今天的实战,首先创建一个项目NutJoke

image-20220722080412586

点击下一步

image-20220724095142561

因为我们要网络请求

所以我们需要在config.json中配置网络请求权限

网络请求的步骤

1、声明网络请求权限

entry下的config.jsonmodule字段下配置权限

"reqPermissions": [

{

"name": "ohos.permission.INTERNET"

}

]

2、支持http明文请求

默认支持https,如果要支持http,在entry下的config.jsondeviceConfig字段下配置

"deviceConfig": {"default": {

"network": {

"cleartextTraffic": true

}

}},

3、创建HttpRequest

// 导入模块

import http from '@ohos.net.http';

// 创建HttpRequest对象

let httpRequest = http.createHttp();

4、发起请求

GET请求(默认为GET请求

// 请求方式:GET

getRequest() {

// 每一个httpRequest对应一个http请求任务,不可复用

let httpRequest = http.createHttp()

let url = "https://way.jd.com/jisuapi/search?keyword=白菜&num=10&start=0&appkey=7c913be32b690701cd994d804a6d4294"

httpRequest.request(url, (err, data) => {

if (!err) {

if (data.responseCode == 200) {

console.info('=====data.result=====' + data.result)

// 解析数据

//this.content= data.result;

// 解析数据

var cookModel: CookModel = JSON.parse(data.result.toString())

// 判断接口返回码,0成功

if (cookModel.code == 1000) {

// 设置数据

this.future = cookModel.result.result.list.material

this.cookdetail = cookModel.result.result.list

this.isRequestSucceed = true;

console.info('=====data.result===this.content==' + cookModel.result.result.list.material)

} else {

// 接口异常,弹出提示

prompt.showToast({ message: "数据请求失败" })

prompt.showToast({ message: jokeModel.error_code })

}

} else {

// 请求失败,弹出提示

prompt.showToast({ message: '网络异常' })

}

} else {

// 请求失败,弹出提示

prompt.showToast({ message: err.message })

}

})

}

5、解析数据(简单示例)

1.网络请求到的json字符串

/*

* Copyright (c) 2021 JianGuo Device Co., Ltd.

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

export

function

getCookTest

() {

return

{

"id"

:

"8"

,

"classid"

:

"2"

,

"name"

:

"醋溜白菜"

,

"peoplenum"

:

"1-2人"

,

"preparetime"

:

"10-20分钟"

,

"cookingtime"

:

"10-20分钟"

,

"content"

:

"醋溜白菜,是北方人经常吃的一道菜,尤其是在多年前的冬天。那时,没有大棚菜,冬天,家家每天佐餐的基本上都是冬储大白菜,聪明的家庭主妇总是想方设法将这单调的菜变成多种菜式,于是,醋溜白菜被频繁的端上餐桌。"

+

" 美食不分贵贱,用最平凡的原料、最简单的调料和最普通的手法做出美味的菜肴来才是美食的真谛。"

+

" 这次,我做的醋溜白菜,近似鲁菜的做法,使个这道菜酸甜浓郁、开胃下饭、老少咸宜。"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/115138_46688.jpg"

,

"tag"

:

"减肥,家常菜,排毒,补钙"

,

"material"

: [

{

"mname"

:

"油"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"盐"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"花椒"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"干红椒"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"葱"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"姜"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"蒜"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"醋"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"酱油"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"糖"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"淀粉"

,

"type"

:

"0"

,

"amount"

:

"适量"

},

{

"mname"

:

"白菜"

,

"type"

:

"1"

,

"amount"

:

"380g"

}

],

"process"

: [

{

"pcontent"

:

"准备食材。"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162550_84583.jpg"

},

{

"pcontent"

:

"将白菜斜刀片成薄片。"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162551_90620.jpg"

},

{

"pcontent"

:

"片切好的白菜帮与菜叶分别入好。"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162551_20925.jpg"

},

{

"pcontent"

:

"盐、糖、生抽、醋淀粉加少许水调匀备用。"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162552_23125.jpg"

},

{

"pcontent"

:

"锅中油烧热,先入花椒炒香后捞出。再加入干红椒段略炒。"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162552_57046.jpg"

},

{

"pcontent"

:

"加入葱姜蒜煸炒香,然后入白菜帮翻炒。"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162553_89090.jpg"

},

{

"pcontent"

:

"炒至菜帮变软时,加入白菜叶。"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162553_40445.jpg"

},

{

"pcontent"

:

"快速翻炒至菜软,勾入碗汁"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162554_92210.jpg"

},

{

"pcontent"

:

"使汤汁均匀的包裹在菜帮上即可"

,

"pic"

:

"http://api.jisuapi.com/recipe/upload/20160719/162554_29522.jpg"

}

]

}

}

2.创建相应的对象

/*

* Copyright (c) 2021 JianGuo Device Co., Ltd.

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

import

{

CookDetailData

}

from

'./cookDetailModel'

;

export

class

CookModel

{

charge

: string

//返回说明

code

: number

//返回码,1000为查询成功

msg

: string

//

result

: {

result

: CookModel7

// 笑话

status

: number

//数量

msg

: string

// ok

}

}

export

class

CookModel7

{

num

: string

//频道

list

: CookDetailData

//

}

/*

* Copyright (c) 2021 JianGuo Device Co., Ltd.

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

import { MaterialData } from './materialModel';

import { ProcessData } from './processModel';

export class CookDetailData {

name: string //

peoplenum: string //

cookingtime: string //

content: string //

pic: string //

tag: string //

material: Array

process: Array

}

参考文档

Text

尺寸设置

边框设置

RichText

Web

项目地址

https://gitee.com/jianguo888/nut-recipes

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • ARK
    ARK
    +关注

    关注

    0

    文章

    10

    浏览量

    13752
  • OpenHarmony
    +关注

    关注

    23

    文章

    3304

    浏览量

    15159
收藏 人收藏

    评论

    相关推荐

    基于eTS的HamronyOS应用开发

    随着HarmonyOS 3.0 Beta版的发布,API Version 8新增了大批JS/eTS API接口,相信很多开发者已经迫不及待想体验基于eTS的HamronyOS应用开发
    的头像 发表于 07-15 09:20 1722次阅读
    基于<b class='flag-5'>eTS</b>的HamronyOS应用<b class='flag-5'>开发</b>

    基于ArkUI eTS开发坚果笑话(NutJoke)

      都说笑一笑十年少,确实,在生活中,我们也是很久没有笑了,那么今天,我就做一个鸿蒙eTS版的坚果笑话App, 实现的功能: 获取接口数据 笑话列表 笑话详情页 你能学到的有: 网络请求 可滚动组件
    的头像 发表于 08-19 09:59 983次阅读

    课程预告丨12月15日官方直播带你领略ArkUI的声明式开发范式之美

    方舟开发框架(ArkUI)的声明式开发范式有什么优势?Java/JS/eTS(extended TypeScript)三种语言,用哪种语言更好?12月15日 19:00-20:30,H
    发表于 12-10 17:52

    entry模块里面的index.ets如何跳转到另外一个xxx.ets页面呢

      ArkUI框架,如何跳转到HarmonyOS Library里面的page呢?  entry模块里面的index.ets,如何跳转到另外一个Module(library)里面实现的xxx.ets
    发表于 03-14 17:06

    100行代码实现HarmonyOS“画图”应用,eTS开发走起!

    式UI框架——方舟开发框架(ArkUI)。ArkUI框架引入了基于TS扩展的声明式开发范式,让开发变得更加简洁、高效! 已经有很多
    发表于 03-30 14:28

    [ArkUI]HarmonyOS新ArkUIets版本抓住神经猫--会算法的神经猫你能抓住吗?

    的知识:ets方式的UI布局,ets组件化开发思想,自定义弹出框,ets语言构造多叉树,广度优先算法,最小路径算法,设置图片动画等等,整体开发
    发表于 04-06 20:19

    全面支持JS/eTS应用开发,DevEco Studio 3.0 Beta4新版本发布

    新版本主要支持在HarmonyOS 3.0 Beta版上开发JS/eTS应用及服务,同时还增强了低代码开发、预览器和编辑器的能力,优化了信息中心体验。升级方式:**建议您从官网下载安装包进行全量升级
    发表于 07-08 14:29

    全面支持JS/eTS应用开发,DevEco Studio 3.0 Beta4新版本发布

    新版本主要支持在HarmonyOS 3.0 Beta版上开发JS/eTS应用及服务,同时还增强了低代码开发、预览器和编辑器的能力,优化了信息中心体验。升级方式:建议您从官网下载安装包进行全量升级
    发表于 07-11 17:37

    OpenHarmony应用开发ArkUI组件集合

    介绍 本示例为ArkUI中组件、通用、动画、全局方法的集合。 工程目录 entry/src/main/ets/ |---component
    发表于 09-22 14:56

    基于ETS开发范式制作Loading组件

    最近刚接触基于 OpenHarmony 开源框架的应用开发,特别是基于 JS/ETS 开发范式。
    的头像 发表于 04-12 08:56 1117次阅读

    OpenHarmony应用开发ETS开发方式Image组件

    今天带大家了解ETS开发方式中的Image组件
    的头像 发表于 07-03 12:06 3068次阅读
    OpenHarmony应用<b class='flag-5'>开发</b>之<b class='flag-5'>ETS</b><b class='flag-5'>开发</b>方式Image组件

    玩嗨OpenHarmony:基于OpenHarmony的ArkUI翻页时钟

    设备,用电脑动画的方式实现翻页时钟,也是一种特别的复古UI交互体验。 本项目岂在通过OpenHarmony的ArkUI框架,用TS扩展的声明式开发范式eTS,来实现翻页时钟的体验。 本项目的
    的头像 发表于 12-05 20:15 899次阅读

    ArkUI新能力,助力应用开发更便捷

    作者:niulihua,华为ArkUI技术专家;wanglei,华为ArkUI技术专家 ArkUI是一套构建分布式应用的声明式UI开发框架。它具备简洁自然的UI信息语法、丰富的UI组件
    的头像 发表于 02-15 16:35 671次阅读

    鸿蒙ArkUI开发-Tabs组件的使用

    鸿蒙ArkUI开发-Tabs组件的使用
    的头像 发表于 01-19 16:01 437次阅读
    鸿蒙<b class='flag-5'>ArkUI</b><b class='flag-5'>开发</b>-Tabs组件的使用

    鸿蒙ArkUI开发实战:eTS版【笑话app】

    制作一款笑话app,使用ArkUI
    的头像 发表于 03-25 16:04 184次阅读
    鸿蒙<b class='flag-5'>ArkUI</b><b class='flag-5'>开发</b>实战:<b class='flag-5'>eTS</b>版【笑话app】