91欧美超碰AV自拍|国产成年人性爱视频免费看|亚洲 日韩 欧美一厂二区入|人人看人人爽人人操aV|丝袜美腿视频一区二区在线看|人人操人人爽人人爱|婷婷五月天超碰|97色色欧美亚州A√|另类A√无码精品一级av|欧美特级日韩特级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫(xiě)文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

OpenHarmony趣味應(yīng)用 OpenHarmony藏頭詩(shī)應(yīng)用

ArkUI詳解 ? 2022-07-13 09:20 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

今天我們將做一個(gè)OpenHarmony趣味應(yīng)用——OpenHarmony藏頭詩(shī)應(yīng)用,是通過(guò)AI接口來(lái)做。通過(guò)調(diào)用指定的AI接口來(lái)做,接口會(huì)返回藏頭詩(shī)或者繼續(xù)完成詩(shī)的后面幾句。

我要實(shí)現(xiàn)的功能主要有:

生成藏頭詩(shī),

生成整首詩(shī),

你能學(xué)到的有:

網(wǎng)絡(luò)請(qǐng)求

可滾動(dòng)組件

狀態(tài)管理

常用組件

常用屬性

修改應(yīng)用名稱(chēng)和圖標(biāo)

在Config.json添加權(quán)限等

用到的接口:

接口:

https://py.myie9.com/hidepoem/堅(jiān)果

請(qǐng)求方式:

Get

apipost請(qǐng)求測(cè)試

image-20220711081818157

接口:

https://py.myie9.com/xuxietest/汗滴禾下土

apipost請(qǐng)求測(cè)試:

image-20220711082102057

如何創(chuàng)建應(yīng)用在這里不做解釋。

首先預(yù)覽一下應(yīng)用

gif1

注意點(diǎn):

允許https需要添加下面的配置

"deviceConfig": {

"default": {

"network": {

"cleartextTraffic": true

}

}

},

使用網(wǎng)絡(luò)請(qǐng)求在config.json添加權(quán)限:

"reqPermissions": [

{

"name": "ohos.permission.INTERNET"

}

],

完整代碼:

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

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

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

?

?

@Entry

@Component

struct Index {

@State tibetanContent: string = "堅(jiān)果的小跟班";

@State tibetanInput: string = "跟著堅(jiān)果學(xué)鴻蒙";

@State wholeContent: string = "";

@State wholeInput: string = "跟著堅(jiān)果學(xué)鴻蒙";

private scroller: Scroller = new Scroller()

?

?

?

onCancel() {

console.info('關(guān)閉')

}

?

?

?

build() {

Scroll(this.scroller) {

Column({ space: 10 }) {

Text($r("app.string.title"))

.fontSize(26)

.fontWeight(FontWeight.Bold)

.align(Alignment.Start)

.margin({ top: 20 })

?

TextInput({ placeholder: '請(qǐng)輸入要生成的內(nèi)容', })

.fontSize(36)

.enterKeyType(EnterKeyType.Go)

.onChange((value) => {

this.tibetanInput = value;

?

})

.height(80)

.margin({

top: 40,

left: 16,

right: 16

})

?

Button("生成藏頭詩(shī)").backgroundColor(Color.Pink)

.onClick(() => {

this.TibetanRequest();

?

})

Text(this.tibetanContent).fontSize(26).fontColor(Color.Orange)

TextInput({ placeholder: '請(qǐng)輸入要生成的內(nèi)容', })

.fontSize(36)

.enterKeyType(EnterKeyType.Go)

.onChange((value) => {

this.wholeInput = value;

?

})

.height(80)

.margin({

?

left: 16,

right: 16

})

Button("生成整首詩(shī)").backgroundColor(Color.Green)

.onClick(() => {

this.wholePoemRequest();

})

Text(this.wholeContent).fontSize(24).fontColor(Color.Orange)

}

.padding(10)

}

?

}

//藏頭詩(shī)接口

private TibetanRequest() {

let httpRequest = http.createHttp();

httpRequest.request(

"https://py.myie9.com/hidepoem/" + this.tibetanInput,

{

method: RequestMethod.RequestMethod.GET,

readTimeout: 15000,

connectTimeout: 15000,

},

(error, data) => {

if (error) {

console.log("error code: " + error.code + ", msg: " + error.message)

} else {

let code = data.responseCode

if (ResponseCode.ResponseCode.OK == code) {

this.tibetanContent = data.result.toString();

?

let header = JSON.stringify(data.header);

console.log("result: " + this.tibetanContent);

console.log("header: " + header);

} else {

console.log("response code: " + code);

}

?

}

}

?

);

}

?

//整首詩(shī)接口

private wholePoemRequest() {

let httpRequest = http.createHttp();

httpRequest.request(

"https://py.myie9.com/xuxietest/" + this.wholeInput,

{

method: RequestMethod.RequestMethod.GET,

readTimeout: 15000,

connectTimeout: 15000,

},

(error, data) => {

if (error) {

console.log("error code: " + error.code + ", msg: " + error.message)

} else {

let code = data.responseCode

if (ResponseCode.ResponseCode.OK == code) {

this.wholeContent = data.result.toString();

let header = JSON.stringify(data.header);

console.log("result: " + this.wholeContent);

console.log("header: " + header);

} else {

console.log("response code: " + code);

}

}

}

);

}

}

發(fā)起網(wǎng)絡(luò)請(qǐng)求

使用 @ohos.net.http 模塊發(fā)起網(wǎng)絡(luò)請(qǐng)求分為以下步驟:

引入http模塊

import

http

from

'@ohos.net.http'

;

創(chuàng)建一個(gè)httpRequest

let

httpRequest

=

http

.

createHttp

();

發(fā)起http請(qǐng)求

httpRequest 提供了兩種 request() 方法進(jìn)行網(wǎng)絡(luò)請(qǐng)求,分別是無(wú) RequestOptions 參數(shù)的請(qǐng)求和有 RequestOptions 參數(shù)的請(qǐng)求。分別介紹如下:

無(wú) RequestOptions 參數(shù)請(qǐng)求

  1. //藏頭詩(shī)接口
    private TibetanRequest() {
    let httpRequest = http.createHttp();
    httpRequest.request(
    "https://py.myie9.com/hidepoem/" + this.tibetanInput,
    {
    method: RequestMethod.RequestMethod.GET,
    readTimeout: 15000,
    connectTimeout: 15000,
    },
    (error, data) => {
    if (error) {
    console.log("error code: " + error.code + ", msg: " + error.message)
    } else {
    let code = data.responseCode
    if (ResponseCode.ResponseCode.OK == code) {
    this.tibetanContent = data.result.toString();
    ?
    let header = JSON.stringify(data.header);
    console.log("result: " + this.tibetanContent);
    console.log("header: " + header);
    } else {
    console.log("response code: " + code);
    }
    ?
    }
    }
    ?
    );
    }

request() 方法默認(rèn)采用 get 方式請(qǐng)求。

上述代碼,重點(diǎn)是通過(guò)調(diào)用HTTP的AI接口,來(lái)獲取生成接口返回的詩(shī)的內(nèi)容,并顯示在應(yīng)用界面上。

修改應(yīng)用描述信息

默認(rèn)的應(yīng)用描述信息,集中在config.json文件中。

image-20220711111409744

修改string.json內(nèi)容如下:

"srcLanguage": "ets",

"srcPath": "MainAbility",

"icon": "$media:icon", //應(yīng)用圖標(biāo)

"description": "$string:desc",

"label": "$string:title", //應(yīng)用名稱(chēng)

"type": "page",

"visible": true,

"launchType": "standard"

這么有趣的應(yīng)用就這樣完成了,比起js開(kāi)發(fā)方式,eTS是不是更為簡(jiǎn)單呢。

聲明:本文內(nèi)容及配圖由入駐作者撰寫(xiě)或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • HarmonyOS
    +關(guān)注

    關(guān)注

    80

    文章

    2154

    瀏覽量

    36084
  • OpenHarmony
    +關(guān)注

    關(guān)注

    33

    文章

    3955

    瀏覽量

    21130
收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    【原創(chuàng)】OpenHarmony系統(tǒng)投屏工具軟件 - OpenHarmony_OHScrcpy使用推薦

    OpenHarmony_OHScrcpy - OpenHarmony投屏工具軟件 OpenHarmony_OHScrcpy是一款為OpenHarmony系統(tǒng)設(shè)計(jì)的投屏工具軟件,功能類(lèi)似
    發(fā)表于 01-22 18:34

    #OpenHarmony HDC調(diào)試

    OpenHarmony
    視美泰
    發(fā)布于 :2026年01月16日 09:46:28

    #OpenHarmony 開(kāi)發(fā)環(huán)境準(zhǔn)備

    OpenHarmony
    視美泰
    發(fā)布于 :2026年01月16日 09:44:31

    #OpenHarmony 鏡像燒錄

    OpenHarmony
    視美泰
    發(fā)布于 :2026年01月16日 09:42:36

    #OpenHarmony 系統(tǒng)概述

    OpenHarmony
    視美泰
    發(fā)布于 :2026年01月16日 09:39:20

    #OpenHarmony Hello World應(yīng)用以及部署

    OpenHarmony
    視美泰
    發(fā)布于 :2026年01月16日 09:32:52

    OpenHarmony系統(tǒng)】本期視頻將為您介紹怎樣將鏡像燒錄到板卡中。

    OpenHarmony
    視美泰
    發(fā)布于 :2026年01月15日 14:29:55

    OpenHarmony年度課題管理辦法

    OpenHarmony年度課題管理辦法V1.0 第一章 總則 第一條 宗旨 圍繞終端操作系統(tǒng)所面臨的技術(shù)挑戰(zhàn),OpenHarmony項(xiàng)目群技術(shù)指導(dǎo)委員會(huì)(TSC)聯(lián)合產(chǎn)學(xué)研各界,以
    的頭像 發(fā)表于 11-12 16:55 ?664次閱讀

    2025 OpenHarmony TSC年中技術(shù)與生態(tài)研討會(huì)圓滿舉辦

    2025 OpenHarmony TSC 年中技術(shù)與生態(tài)研討會(huì) 圓滿舉辦 8月1日,2025 OpenHarmony TSC年中技術(shù)與生態(tài)研討會(huì)于中國(guó)上海順利召開(kāi)。 本次會(huì)議由OpenHarmony
    的頭像 發(fā)表于 08-07 12:24 ?2111次閱讀
    2025 <b class='flag-5'>OpenHarmony</b> TSC年中技術(shù)與生態(tài)研討會(huì)圓滿舉辦

    OpenHarmony2025年度競(jìng)賽訓(xùn)練營(yíng)重磅開(kāi)啟

    ? OpenHarmony2025年度競(jìng)賽訓(xùn)練營(yíng) ? ? ? 活動(dòng)介紹 OpenHarmony競(jìng)賽訓(xùn)練營(yíng) 旨在引導(dǎo)高校學(xué)生進(jìn)行OpenHarmony產(chǎn)學(xué)研用,培養(yǎng)更多應(yīng)用型人才和產(chǎn)業(yè)需求有效鏈接
    的頭像 發(fā)表于 07-16 11:51 ?930次閱讀

    桃芯科技獲得OpenHarmony生態(tài)產(chǎn)品兼容性證書(shū)

    近日,由INGCHIPS自主研發(fā)的模組/開(kāi)發(fā)板DB870CC1A順利通過(guò)OpenHarmony 5.0.2 Release版本兼容性測(cè)評(píng),并獲得OpenHarmony生態(tài)產(chǎn)品兼容性證書(shū)!
    的頭像 發(fā)表于 06-25 14:30 ?1148次閱讀

    請(qǐng)問(wèn)下,openharmony支持哪一款龍芯的開(kāi)發(fā)板?有沒(méi)有開(kāi)源的龍芯的openharmony源碼?

    想買(mǎi)個(gè)2k0300的開(kāi)發(fā)板學(xué)習(xí)龍芯和openharmony,愣是沒(méi)有看到提供openharmony源碼的,也沒(méi)與看到開(kāi)源的代碼。gitee上,openharmony的龍芯sig倉(cāng)庫(kù)也是關(guān)閉的,有沒(méi)有人知道現(xiàn)在是什么情況?
    發(fā)表于 04-26 13:06

    2024年OpenHarmony社區(qū)年度激勵(lì)公示

    在過(guò)去一年里,OpenHarmony項(xiàng)目群技術(shù)指導(dǎo)委員會(huì)(TSC)向所有參與者致以最誠(chéng)摯的感謝!大家的積極參與和鼎力支持推動(dòng)了OpenHarmony社區(qū)的持續(xù)繁榮與高質(zhì)量發(fā)展。OpenHarmony
    的頭像 發(fā)表于 04-21 18:17 ?1164次閱讀