当前位置:网站首页>基于ArkUI eTS开发的坚果食谱(NutRecipes)
基于ArkUI eTS开发的坚果食谱(NutRecipes)
2022-08-01 10:52:00 【InfoQ】
基于ArkUI eTS开发的坚果食谱(NutRecipes)
实现的功能:
- 获取接口数据
- 菜谱列表
- 菜谱详情页
你能学到的有:
- 网络请求
- 可滚动组件
- 容器组件
- 路由跳转
- 基础组件
文件结构
.
├── 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
效果预览:

获取新闻接口a
- 接口地址:
- https://way.jd.com/jisuapi/search
- 请求方式:
- HTTPS GET POST
- 请求示例:
请求参数说明:

返回参数说明:


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"
}
]
}
]
}
}}


网络请求的步骤
1、声明网络请求权限
"reqPermissions": [
{
"name": "ohos.permission.INTERNET"
}
]
2、支持http明文请求
"deviceConfig": {"default": {
"network": {
"cleartextTraffic": true
}
}},
3、创建HttpRequest
// 导入模块
import http from '@ohos.net.http';
// 创建HttpRequest对象
let httpRequest = http.createHttp();
4、发起请求
// 请求方式: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、解析数据(简单示例)
/*
* 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"
}
]
}
}
/*
* 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<MaterialData>
process: Array<ProcessData>
}
参考文档
- Text
- 尺寸设置
- 边框设置
- RichText
- Web
项目地址
边栏推荐
- C#/VB.NET 将PPT或PPTX转换为图像
- redis6 跟着b站尚硅谷学习
- 如何从完美的智能合约中窃取 1 亿美元
- Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
- MySQL常用语句总结
- gc的意义和触发条件
- Small application project works WeChat gourmet recipes applet graduation design of finished product (1) the development profile
- Solve vscode input! Unable to quickly generate skeletons (three methods for the new version of vscode to quickly generate skeletons)
- 昇思大模型体验平台初体验——以小模型LeNet为例
- CTFshow,命令执行:web31
猜你喜欢
7. SAP ABAP OData 服务如何支持 $orderby (排序)操作
爱可可AI前沿推介(8.1)
Py之yellowbrick:yellowbrick的简介、安装、使用方法之详细攻略
小程序毕设作品之微信美食菜谱小程序毕业设计成品(3)后台功能
Stone Technology builds hard-core brand power and continues to expand the global market
图解MySQL内连接、外连接、左连接、右连接、全连接......太多了
MacOS下postgresql(pgsql)数据库密码为什么不需要填写或可以乱填写
一篇文章,带你详细了解华为认证体系证书(1)
Promise to learn several key questions (3) the Promise - state change, execution sequence and mechanism, multitasking series, abnormal penetration, interrupt the chain of Promise
小程序毕设作品之微信美食菜谱小程序毕业设计成品(4)开题报告
随机推荐
我是如何保护 70000 ETH 并赢得 600 万漏洞赏金的
一文说明白ECDSA spec256k1 spec256r1 EdDSA ed25519千丝万缕的关系
C language implementation!20000 in 4 seconds
利用正则表达式的回溯实现绕过
Android 安全与防护策略
小程序毕设作品之微信美食菜谱小程序毕业设计成品(2)小程序功能
C语言实现!20000用4秒计算
LeakCanary如何监听Service、Root View销毁时机?
分类预测 | MATLAB实现1-DCNN一维卷积神经网络分类预测
复现assert和eval成功连接或失败连接蚁剑的原因
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (2) Mini Program Functions
pve 删除虚拟机「建议收藏」
PDMan-domestic free general database modeling tool (minimalist, beautiful)
STM32 Personal Notes - Embedded C Language Optimization
Online - GCeasy GC log analysis tools
CTFshow,命令执行:web32
世界第4疯狂的科学家,在103岁生日那天去世了
微信公众号授权登录后报redirect_uri参数错误的问题
Mysql index related knowledge review one
深度学习 | MATLAB实现一维卷积神经网络convolution1dLayer参数设定