HarmonyOS NEXT 實戰之元服務:靜態案例效果---查看國內航班服務

背景:

前幾篇學習了元服務,后面幾期就讓我們開發簡單的元服務吧,里面豐富的內容大家自己加,本期案例 僅供參考

先上本期效果圖 ,里面圖片自行替換

在這里插入圖片描述

效果圖1完整代碼案例如下:

  • Index代碼
import { authentication } from '@kit.AccountKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { AddressExchangeViewComponent } from './AddressExchangeViewComponent';export const DATA_CONFIG: Record<string, number> = {'NUMBER_LEN': 7,'DURATION_TIME': 200,'MILLENNIAL_LEN': 3
}export const STYLE_CONFIG: Record<string, number> = {'ITEM_GUTTER': 12,'ITEM_HEIGHT': 26,'TEXT_MARGIN': 2,'PADDING_TOP': 32
}@Entry
@Component
struct Index {build() {Column({ space: STYLE_CONFIG.ITEM_GUTTER }) {Text($r('app.string.EntryAbility_label')).fontColor(Color.White).fontSize($r('sys.float.ohos_id_text_size_headline8')).width($r('app.string.digital_scroll_animation_max_size')).textAlign(TextAlign.Center)AddressExchangeViewComponent()}.padding({top: STYLE_CONFIG.PADDING_TOP}).margin({ top: 60 }).width($r('app.string.digital_scroll_animation_max_size')).height($r('app.string.digital_scroll_animation_max_size')).linearGradient({colors: [[$r('app.color.digital_scroll_animation_background_color'), 0.0],[$r('sys.color.ohos_id_color_background'), 0.3]]})}aboutToAppear() {hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');this.loginWithHuaweiID();}/*** Sample code for using HUAWEI ID to log in to atomic service.* According to the Atomic Service Review Guide, when a atomic service has an account system,* the option to log in with a HUAWEI ID must be provided.* The following presets the atomic service to use the HUAWEI ID silent login function.* To enable the atomic service to log in successfully using the HUAWEI ID, please refer* to the HarmonyOS HUAWEI ID Access Guide to configure the client ID and fingerprint certificate.*/private loginWithHuaweiID() {// Create a login request and set parameterslet loginRequest = new authentication.HuaweiIDProvider().createLoginWithHuaweiIDRequest();// Whether to forcibly launch the HUAWEI ID login page when the user is not logged in with the HUAWEI IDloginRequest.forceLogin = false;// Execute login requestlet controller = new authentication.AuthenticationController();controller.executeRequest(loginRequest).then((data) => {let loginWithHuaweiIDResponse = data as authentication.LoginWithHuaweiIDResponse;let authCode = loginWithHuaweiIDResponse.data?.authorizationCode;// Send authCode to the backend in exchange for unionID, session}).catch((error: BusinessError) => {hilog.error(0x0000, 'testTag', 'error: %{public}s', JSON.stringify(error));if (error.code == authentication.AuthenticationErrorCode.ACCOUNT_NOT_LOGGED_IN) {// HUAWEI ID is not logged in, it is recommended to jump to the login guide page}});}
}
  • AddressExchangeViewComponent 代碼
import curves from '@ohos.curves';
import { promptAction } from '@kit.ArkUI';@Preview
@Component
export struct AddressExchangeViewComponent {@State rotateAngle: number = 0;@State translateX: number = 0;@State swap: boolean = false;private JWidth: number = 300;build() {Column({ space: 15 }) {Row() {Text($r('app.string.address_exchange_address_left')).translate({ x: this.translateX }).width("40%").textAlign(this.swap ? TextAlign.End : TextAlign.Start).onClick(() => {promptAction.showToast({message: '北京',});})Stack() {Image($r('app.media.address_exchange_airplane')).size({height: 16,width: 16})Image($r('app.media.address_exchange_recycle')).size({height: 38,width: 38}).rotate({ angle: this.rotateAngle }).animation({curve: Curve.EaseOut,playMode: PlayMode.Normal,})}.width("20%").onClick(() => {this.swap = !this.swapanimateTo({ curve: curves.springMotion() }, () => {if (this.swap) {this.translateX = this.JWidth * 0.5;} else {this.translateX = 0}})this.rotateAngle += 180;})Text('深圳').translate({ x: -this.translateX }).width("40%").textAlign(this.swap ? TextAlign.Start : TextAlign.End).onClick(() => {promptAction.showToast({message: '點了'});})}.width(this.JWidth).borderWidth(1).borderRadius(8).padding(8).height(60)Row({ space: 15 }) {Text(this.getDate()).fontSize($r('app.string.ohos_id_text_size_headline')).fontWeight(FontWeight.Medium).height(30)Text($r('app.string.address_exchange_week')).height(30)}.width(this.JWidth).onClick(() => {promptAction.showToast({message: '點了'});})Button($r('app.string.address_exchange_search_ticket')).fontColor(Color.White).height(40).backgroundColor('#6486FF').width(this.JWidth).onClick(() => {promptAction.showToast({message: '今日機器出現故障,請找工作室人員解決'});})Row({ space: 10 }) {Row() {Text('出差 返現').fontSize(13).fontColor('#222222')Toggle({ type: ToggleType.Checkbox, isOn: false })}Row() {Row() {Text('帶兒童/嬰兒').fontSize(13).fontColor('#222222')Toggle({ type: ToggleType.Checkbox, isOn: true })}Row() {Text('學生票').fontSize(13).fontColor('#222222')Toggle({ type: ToggleType.Checkbox, isOn: false })}}}.width('100%').justifyContent(FlexAlign.SpaceBetween)Row() {Text('每周特價機票').fontSize(18).fontColor(Color.Black)Text('查看更多>').fontSize(15).fontColor(Color.Black)}.justifyContent(FlexAlign.SpaceBetween).width('100%').padding(10).onClick(() => {})Row({ space: 20 }) {Column({ space: 10 }) {Text('上海   ->   深圳').fontWeight(FontWeight.Bold).fontSize(13).fontColor('#5A5A5A')Row() {Text('12月3日 | 周一').fontSize(10).fontColor('#CAC8C9')Text('¥600').fontSize(15).fontColor(Color.Red).fontWeight(FontWeight.Bold).margin({ left: 8 })}.width('100%').justifyContent(FlexAlign.SpaceBetween)Text() {Span('原價  ').fontColor('#222222').fontSize(15)Span('¥1000').fontColor(Color.Red).fontSize(15)}.fontWeight(FontWeight.Bold).margin({ left: 8 })}.width('100%').borderRadius(4).backgroundColor('#F5F9F8').padding(8).alignItems(HorizontalAlign.Start)}Row({ space: 20 }) {Column({ space: 10 }) {Text('北京   ->   天津').fontWeight(FontWeight.Bold).fontSize(13).fontColor('#5A5A5A')Row() {Text('12月5日 | 周四').fontSize(10).fontColor('#CAC8C9')Text('¥300').fontSize(15).fontColor(Color.Red).fontWeight(FontWeight.Bold).margin({ left: 8 })}.width('100%').justifyContent(FlexAlign.SpaceBetween)Text() {Span('原價  ').fontColor('#222222').fontSize(15)Span('¥400').fontColor(Color.Red).fontSize(15)}.fontWeight(FontWeight.Bold).margin({ left: 8 })}.width('100%').borderRadius(4).backgroundColor('#F5F9F8').padding(8).alignItems(HorizontalAlign.Start)}}.width($r('app.string.address_exchange_content_size')).height(178).margin($r('app.string.ohos_id_card_margin_start'))}private getDate() {const now = new Date();const year = now.getFullYear();const month = now.getMonth() + 1; // 注意:月份是從0開始計數的const day = now.getDate();const hours = now.getHours();const minutes = now.getMinutes();const seconds = now.getSeconds();return `${year} 年 ${month} 月 ${day} 日`}
}

最近文章>>>>>>>>>>>

HarmonyOS NEXT實戰:元服務與應用 APP 發布應用市場的詳細步驟與流程

若本文對您稍有幫助,誠望您不吝點贊,多謝。

有興趣的同學可以點擊查看源碼

  • gitee:https://gitee.com/jiaojiaoone/explore-harmony-next/tree/case%2Fwanandroid/
  • github:https://github.com/JasonYinH/ExploreHarmonyNext.git

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/64037.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/64037.shtml
英文地址,請注明出處:http://en.pswp.cn/web/64037.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Windows11家庭版啟動Hyper-V

Hyper-V 是微軟的硬件虛擬化產品&#xff0c;允許在 Windows 上以虛擬機形式運行多個操作系統。每個虛擬機都在虛擬硬件上運行&#xff0c;可以創建虛擬硬盤驅動器、虛擬交換機等虛擬設備。使用虛擬化可以運行需要較舊版本的 Windows 或非 Windows 操作系統的軟件&#xff0c;以…

為什么深度學習和神經網絡要使用 GPU?

為什么深度學習和神經網絡要使用 GPU&#xff1f; 本篇文章的目標是幫助初學者了解 CUDA 是什么&#xff0c;以及它如何與 PyTorch 配合使用&#xff0c;更重要的是&#xff0c;我們為何在神經網絡編程中使用 GPU。 圖形處理單元 (GPU) 要了解 CUDA&#xff0c;我們需要對圖…

每天五分鐘機器學習:核函數

本文重點 在學習支持向量機算法之前,我們要繼續學習一些數學基礎,本文我們將學習核函數的概念。當數據線性不可分的時候,此時就需要核函數出場了,它可以將低維不可分的數據映射到高維可分數據,此時就可以完成數據分類了。 核函數的定義 核函數K(x, y)定義為兩個數據點x…

MaaS(Model as a Service)

1.MasS是什么&#xff1f; Model as a Service&#xff08;MaaS&#xff09;是一種云計算服務模式&#xff0c;它允許用戶通過互聯網訪問和使用機器學習模型&#xff0c;而不需要自行構建和維護這些模型。MaaS提供了模型的托管、管理和監控&#xff0c;使用戶能夠專注于應用程…

圖像處理-Ch7-快速小波變換和小波包

個人博客&#xff01;無廣告觀看&#xff0c;因為這節內容太多了&#xff0c;有點放不下&#xff0c;分了三節 文章目錄 快速小波變換(The Fast Wavelet Transform)與兩頻段子帶編譯碼系統的關系例&#xff1a;計算一維小波變換 一維快速小波反變換例&#xff1a;計算一維小波…

KAFKA 權威指南筆記(一)究竟應該配置多少個BROKER?

一個KAFKA集群需要多少個BROKER&#xff1f; 一個單獨的Kafka服務器被叫做BROKER&#xff0c;BROKER可以處理數千個分區以及每秒百萬級別的消息量。由BROKER組成了“集群”&#xff08;其中由集群控制器角色的BROKER是從成員中選舉出來的&#xff0c;負責控制管理工作&#xf…

【ES6復習筆記】函數參數的默認值(6)

在ES6中&#xff0c;函數參數默認值是一個非常有用的特性&#xff0c;它允許你在定義函數時為參數指定一個默認值。如果在調用函數時沒有提供相應的參數值&#xff0c;那么函數將使用默認值。 1. 形參初始值 具有默認值的參數&#xff0c;一般位置要靠后。這是一個潛規則&…

WebRtc webrtc-streamer部署

文章目錄 本文檔只是為了留檔方便以后工作運維&#xff0c;或者給同事分享文檔內容比較簡陋命令也不是特別全&#xff0c;不適合小白觀看&#xff0c;如有不懂可以私信&#xff0c;上班期間都是在得 WebRtc webrtc-streamer 部署 docker run -p 8000:8000 -it mpromonet/webrt…

Spring Boot中冪等性的應用

在 Spring Boot 中&#xff0c;冪等性是實現分布式系統設計和接口調用的一個重要概念&#xff0c;尤其在高并發、分布式環境下&#xff0c;確保接口重復調用不會引發系統數據異常至關重要。 冪等性概念 冪等性&#xff08;Idempotence&#xff09;是指一次請求和重復多次請求…

leetcode 7. 整數反轉

class Solution { public: int reverse(int x) { long long n0; if(x0) return 0; while(x%100) { xx/10; } while(x!0) { nn*10x%10; xx/10; } if(n<-2147483648||n>2147483647) return 0; return n; } };

[項目][boost搜索引擎#4] cpp-httplib使用 log.hpp 前端 測試及總結

目錄 編寫http_server模塊 1. 引入cpp-httplib到項目中 2. cpp-httplib的使用介紹 3. 正式編寫http_server 九、添加日志到項目中 十、編寫前端模塊 十一. 詳解傳 gitee 十二、項目總結 項目的擴展 寫在前面 [項目詳解][boost搜索引擎#1] 概述 | 去標簽 | 數據清洗 |…

xxl-job 簡單的入門到實戰

本文是參考官方文檔自己實踐一次&#xff0c;純享版&#xff0c;大致也是作者邊寫博客邊去跟著官方文檔實現 一、前期準備 1、官網地址 GitHub地址&#xff1a; GitHub - xuxueli/xxl-job: A distributed task scheduling framework.&#xff08;分布式任務調度平臺XXL-JOB&…

Centos7, 使用yum工具,出現 Could not resolve host: mirrorlist.centos.org

在 CentOS 7 中使用 yum 工具時&#xff0c;如果出現 "Could not resolve host: mirrorlist.centos.org" 的錯誤&#xff0c;通常是因為默認的鏡像源無法訪問。以下是一些常用的解決方法&#xff1a; 檢查網絡連接&#xff1a;首先使用 ping 命令測試網絡連接是否正常…

【教程】通過Docker運行AnythingLLM

轉載請注明出處&#xff1a;小鋒學長生活大爆炸[xfxuezhagn.cn] 如果本文幫助到了你&#xff0c;歡迎[點贊、收藏、關注]哦~ 官方教程&#xff1a;Local Docker Installation ~ AnythingLLM 1、先創建一個目錄用于保存anythingllm的持久化文件&#xff1a; sudo mkdir /app su…

若依(RuoYi-Vue)+Flowable工作流前后端整合教程

此教程適合若依前后端分離項目&#xff0c;其他項目可以在擴展列表中進行查找。 近期公司里需要對很久以前的RuoYi-Vue前后端分離項目擴展出flowable的功能&#xff0c;當然這個重任也是落在了我的身上&#xff08;不然也不會有這篇文章&#xff09;&#xff0c;然后我在官網看…

ubuntu 網絡管理--NetworkManager

ubuntu 網絡管理--NetworkManager 1 介紹2 NetworkManager 命令2 nmcli 命令顯示可用的wifi AP連接wifi檢查網絡連接 ?? 如何刪除刪除網絡連接查看設備狀態添加一個新的以太網連接設置靜態 IP 地址啟用并測試連接添加新的wifi連接 3 其他命令參考 1 介紹 NetworkManager 是標…

計算機網絡習題(第5章 網絡層 第6章 傳輸層)

第5章 網絡層 一、單選題 1、下列關于 IPv4 地址的說法中&#xff0c;錯誤的是( )。 A、 IP 地址是邏輯地址 B、 IP 地址一般用點分十進制表示 C、 205.106.286.36 是一個合法的 IP 地址 D、 同一個網絡中不能有兩臺計算機的 IP 地址相同 正確答案&#xff1a; C 2、…

水庫大壩三維模型的開發和使用3Dmax篇

成果圖 開發過程 工具插件three.js先加載模型做水體銜接水位測量標尺水位標記斷面標記大壩監測點打點 上代碼&#xff0c;技術交流V: bloxed <template><div class"box w100 h100"><el-row :gutter"20" v-loading"loading"e…

【藍橋杯每日一題】分糖果——DFS

分糖果 藍橋杯每日一題 2024-12-24 分糖果 DFS 題目描述 兩種糖果分別有 9 個和 16 個&#xff0c;要全部分給 7 個小朋友&#xff0c;每個小朋友得到的糖果總數最少為 2 個最多為 5 個&#xff0c;問有多少種不同的分法。糖果必須全部分完。 只要有其中一個小朋友在兩種方案中…

計算機畢設-基于springboot的校園招聘網站的設計與實現(附源碼+lw+ppt+開題報告)

博主介紹&#xff1a;?多個項目實戰經驗、多個大型網購商城開發經驗、在某機構指導學員上千名、專注于本行業領域? 技術范圍&#xff1a;Java實戰項目、Python實戰項目、微信小程序/安卓實戰項目、爬蟲大數據實戰項目、Nodejs實戰項目、PHP實戰項目、.NET實戰項目、Golang實戰…