1 Star 2 Fork 2

坚果派 / 坚果笑话大全

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

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

都说笑一笑十年少,确实,在生活中,我们也是很久没有笑了,那么今天,我就做一个鸿蒙eTS版的坚果笑话App,

实现的功能:

  • 获取接口数据
  • 笑话列表
  • 笑话详情页

你能学到的有:

  • 网络请求

  • 可滚动组件

  • 容器组件

  • 路由跳转

  • 基础组件

文件结构

.
├── config.json
├── ets
│   └── MainAbility
│       ├── app.ets
│       ├── common
│       │   └── RealtimeWeather.ets
│       ├── data
│       │   └── get_test.ets
│       ├── model
│       │   ├── jokeDetailModel.ets
│       │   └── jokeModel.ets
│       └── pages
│           ├── Main.ets
│           └── jokeDetails.ets
└── resources
    ├── base
    │   ├── element
    │   │   ├── color.json
    │   │   └── string.json
    │   └── media
    │       └── icon.png
    └── rawfile

效果预览:

gif11

gif10

image-20220722101712051

笑话大全接口

我们用到的接口:

聚合数据的笑话大全

**接口地址:**http://v.juhe.cn/joke/content/list.php

**返回格式:**json

**请求方式:**http get

**请求示例:**http://v.juhe.cn/joke/content/list.php?key=您申请的KEY&page=2&pagesize=10&sort=asc&time=1418745237

**接口备注:**根据时间戳返回该时间点前或后的笑话列表

请求参数说明:

名称 必填 类型 说明
sort string 类型,desc:指定时间之前发布的,asc:指定时间之后发布的
page int 当前页数,默认1,最大20
pagesize int 每次返回条数,默认1,最大20
time string 时间戳(10位),如:1418816972
key string 在个人中心->我的数据,接口名称上方查看

返回参数说明:

名称 类型 说明
error_code int 返回码
reason string

JSON返回示例

{
    "error_code": 0,
    "reason": "Success",
    "result": {
        "data": [
            {
                "content": "有一天晚上我俩一起吃西瓜,老大把西瓜籽很整洁的吐在了一张纸上,\r\n过了几天,我从教室回但宿舍看到老大在磕瓜子,\r\n我就问他:老大,你什么时候买的瓜子?\r\n老大说:刚晒好,说着抓了一把要递给我……",
                "hashId": "bcc5fdc2fb6efc6db33fa242474f108a",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": ""我女朋友气跑了"\r\n"怎么回事?严重吗?你怎么着她了?"\r\n"不严重,我只是很久没用了"",
                "hashId": "03a6095c18e1d6fe7e2c19b2a20d03d1",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": "还说神马来一场说走就走的旅行,\r\n工作后就连一场说走就走的下班都不行。",
                "hashId": "10edf75c1e7d0933c91f0f39a28a2c84",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": "高速路上堵车,路边葡萄地里有一哥们竟然在偷葡萄,心想太没素质了吧!\r\n不管了我也去,刚溜进葡萄地,那哥们竟问我干嘛,\r\n我撇了一眼反问道你干嘛呢?\r\n那哥们答道摘葡萄呢!\r\n我答道:我也摘葡萄呢!\r\n哥们郁闷了说我摘我家的你呢?\r\n我顿时脸红,哥你家葡萄咋卖呢?",
                "hashId": "bb572bb5b4844badb31012983f7324f5",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": "和老婆在街边散步,我手上捏着一张已揉成一团的传单,\r\n走了好一会终于看到个垃圾桶,我赶紧跑过去想扔掉,\r\n没想到老婆从后边一把拉住我说:老公,那个肯定吃不得了,别捡。\r\n我一愣,发现垃圾桶顶盖上放着半个西瓜。",
                "hashId": "7ebccd3bbfaf24e010f9eb3ee68234bd",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": "某考生考了个倒数第一,回到家被他爸一顿暴揍,\r\n来到学校老师让他谈谈落后的体会,\r\n学生:“我终于明白了“落后就要挨打”的道理。”",
                "hashId": "4aee2aa6a79c67682f605c4146a8eca4",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": "很多人不喜欢朝九晚五的生活,然后开始创业。\r\n最终,他的生活变成了朝五晚九。",
                "hashId": "7b358c4b96cf4a8d82b85545ea8f9603",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": "钱这个东西,真是害人精。\r\n小到人与人之间的矛盾,大到国家之间的战争,无不是为了钱。\r\n钱可以把人推上万众瞩目之颠,也可以使人瞬间变成阶下囚。\r\n可是,富人们却没认识到,当钱几辈子花不完时,\r\n挣再多已经没有意义,还不如早日尽点社会责任,\r\n捐助给需要的人,求得个平安幸福。\r\n看到这个的有钱人们呐,你们什么时侯能捐我点啊!",
                "hashId": "94e18075f8c9c8211dfed5f8d6a62983",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": "看到一句很好的名言:我们无法拉伸生命的长度,但是我们可以拓展生命的宽度。\r\n我觉得这句话太有道理了!\r\n意思就是:虽然我们无法再长高了,但是我们还可以继续长胖。",
                "hashId": "fd8e364a4c70d46e77c1610879748a9a",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            },
            {
                "content": "女生口中所说的“理工男好萌好棒好想嫁!”,\r\n其实理工男是指“会修电脑、会设置手机、会安家用电器、\r\n会帮做PPT打EXCEL表PS修图、话少、高冷、专一、不和乱七八糟的女生来往、\r\n不爱打扮却又干净清爽、高高瘦瘦、手指纤长、戴黑框眼镜超好看的帅哥”。\r\n其实找个帅哥让他学电脑,再戴个眼镜就OK了。",
                "hashId": "5001c08a3cc8a281b15c467bc15a4911",
                "unixtime": 1418814837,
                "updatetime": "2014-12-17 19:13:57"
            }
        ]
    }
}

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

image-20220722080412586

点击下一步

image-20220722080853387

因为我们要网络请求

所以我们需要在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://devapi.qweather.com/v7/weather/now?location=101010100&key=48fbadf80bbc43ce853ab9a92408373e'
    httpRequest.request(url, (err, data) => {
      if (!err) {
        if (data.responseCode == 200) {
          console.info('=====data.result=====' + data.result)
          // 解析数据
          //this.content= data.result;
          // 解析数据
          var weatherModel: WeatherModel = JSON.parse(data.result.toString())
          // 判断接口返回码,0成功
          if (weatherModel.code == 200) {
            // 设置数据

            this.realtime = weatherModel.now


            this.isRequestSucceed = true;

            console.info('=====data.result===this.content==' + weatherModel.now)

          } else {
            // 接口异常,弹出提示
            prompt.showToast({ message: "数据请求失败" })
          }

        } 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 getTest() {
  return [
    {
      "content": "有一天晚上我俩一起吃西瓜,老大把西瓜籽很整洁的吐在了一张纸上,\r\n过了几天,我从教室回但宿舍看到老大在磕瓜子,\r\n我就问他:老大,你什么时候买的瓜子?\r\n老大说:刚晒好,说着抓了一把要递给我……",
      "hashId": "bcc5fdc2fb6efc6db33fa242474f108a",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": ""我女朋友气跑了"\r\n"怎么回事?严重吗?你怎么着她了?"\r\n"不严重,我只是很久没用了"",
      "hashId": "03a6095c18e1d6fe7e2c19b2a20d03d1",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": "还说神马来一场说走就走的旅行,\r\n工作后就连一场说走就走的下班都不行。",
      "hashId": "10edf75c1e7d0933c91f0f39a28a2c84",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": "高速路上堵车,路边葡萄地里有一哥们竟然在偷葡萄,心想太没素质了吧!\r\n不管了我也去,刚溜进葡萄地,那哥们竟问我干嘛,\r\n我撇了一眼反问道你干嘛呢?\r\n那哥们答道摘葡萄呢!\r\n我答道:我也摘葡萄呢!\r\n哥们郁闷了说我摘我家的你呢?\r\n我顿时脸红,哥你家葡萄咋卖呢?",
      "hashId": "bb572bb5b4844badb31012983f7324f5",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": "和老婆在街边散步,我手上捏着一张已揉成一团的传单,\r\n走了好一会终于看到个垃圾桶,我赶紧跑过去想扔掉,\r\n没想到老婆从后边一把拉住我说:老公,那个肯定吃不得了,别捡。\r\n我一愣,发现垃圾桶顶盖上放着半个西瓜。",
      "hashId": "7ebccd3bbfaf24e010f9eb3ee68234bd",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": "某考生考了个倒数第一,回到家被他爸一顿暴揍,\r\n来到学校老师让他谈谈落后的体会,\r\n学生:“我终于明白了“落后就要挨打”的道理。”",
      "hashId": "4aee2aa6a79c67682f605c4146a8eca4",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": "很多人不喜欢朝九晚五的生活,然后开始创业。\r\n最终,他的生活变成了朝五晚九。",
      "hashId": "7b358c4b96cf4a8d82b85545ea8f9603",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": "钱这个东西,真是害人精。\r\n小到人与人之间的矛盾,大到国家之间的战争,无不是为了钱。\r\n钱可以把人推上万众瞩目之颠,也可以使人瞬间变成阶下囚。\r\n可是,富人们却没认识到,当钱几辈子花不完时,\r\n挣再多已经没有意义,还不如早日尽点社会责任,\r\n捐助给需要的人,求得个平安幸福。\r\n看到这个的有钱人们呐,你们什么时侯能捐我点啊!",
      "hashId": "94e18075f8c9c8211dfed5f8d6a62983",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": "看到一句很好的名言:我们无法拉伸生命的长度,但是我们可以拓展生命的宽度。\r\n我觉得这句话太有道理了!\r\n意思就是:虽然我们无法再长高了,但是我们还可以继续长胖。",
      "hashId": "fd8e364a4c70d46e77c1610879748a9a",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    },
    {
      "content": "女生口中所说的“理工男好萌好棒好想嫁!”,\r\n其实理工男是指“会修电脑、会设置手机、会安家用电器、\r\n会帮做PPT打EXCEL表PS修图、话少、高冷、专一、不和乱七八糟的女生来往、\r\n不爱打扮却又干净清爽、高高瘦瘦、手指纤长、戴黑框眼镜超好看的帅哥”。\r\n其实找个帅哥让他学电脑,再戴个眼镜就OK了。",
      "hashId": "5001c08a3cc8a281b15c467bc15a4911",
      "unixtime": 1418814837,
      "updatetime": "2014-12-17 19:13:57"
    }
  ]
}

2.创建相应的对象

export class JokeDetailData {
  content: string // 内容
  hashId: string // 哈希值
  unixtime: number //
  updatetime: string //更新时间


}
import { JokeDetailData } from './jokeDetailModel';

export class JokeModel {
  reason: string //返回说明
  error_code: number //返回码,0为查询成功

  result: {

    data: Array<JokeDetailData> // 笑话
  }
}

参考文档

项目地址

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

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] 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.

简介

鸿蒙eTS版,HarmonyOS 展开 收起
TypeScript 等 2 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/nutsus/nut-jokes.git
git@gitee.com:nutsus/nut-jokes.git
nutsus
nut-jokes
坚果笑话大全
master

搜索帮助

14c37bed 8189591 565d56ea 8189591