成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

用鴻蒙開發AI應用(六)UI篇

開發
文章由鴻蒙社區產出,想要了解更多內容請前往:51CTO和華為官方戰略合作共建的鴻蒙技術社區https://harmonyos.51cto.com/#zz

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com/#zz

前言
 上一篇,我們在鴻蒙上寫了一個HDF驅動并操作了一下LED硬件,這一篇我們來嘗試一下構建一個有簡單界面的App,體驗一下鴻蒙的前端開發流程。

環境準備

1. 安裝DevEco Studio

解壓相應的壓縮包(文末附下載鏈接),這里以win10為例,雙擊`deveco-studio-2.0.12.201.exe`

 
指定安裝目錄
 
設置可選快捷方式和環境變量
 
一路下一步即可。
 

同意用戶協議后,就能正常啟動了。

 
2. 更新sdk
 
在菜單 `Setting->HarmonyOS SDK->SDK Platforms`中,選擇`Js`和`Java`,安裝新版的`SDK`。
 

同樣在`SDK Tools`中,選中新版的`Previewer`。

 

點擊Apply更新

 

新建項目

點擊菜單`File->New Project...`,選擇智慧屏`Smart Vision`,創建一個空模板應用。

填入項目名稱`MyUiAPP`,點擊完成就能創建一個工程了。
 
遇到 `gradle`下載太慢或版本差異的,可以直接在以下網址用工具下載。
 
  1. https://services.gradle.org/distributions/ 

目錄結構

我們先分析一下目錄結構,做`Android`開發的會倍感親切。

1. APP

`HarmonyOS`的應用軟件包以`APP Pack(Application Package)`形式發布,它是由一個或多個`HAP(HarmonyOS Ability Package)`以及描述每個`HAP`屬性的`pack.info`組成。`HAP`是`Ability`的部署包,`HarmonyOS`應用代碼圍繞`Ability`組件展開。

一個`HAP`是由代碼、資源、第三方庫及應用配置文件組成的模塊包,可分為`entry`和`feature`兩種模塊類型。

- **entry**:應用的主模塊。一個APP中,對于同一設備類型必須有且只有一個`entry`類型的`HAP`,可獨立安裝運行。

- **feature**:應用的動態特性模塊。一個`APP`可以包含一個或多個`feature`類型的`HAP`,也可以不含。只有包含`Ability`的`HAP`才能夠獨立運行。

 

2. Ability

Ability是應用所具備的能力的抽象,一個應用可以包含一個或多個`Ability`。`Ability`分為兩種類型:`FA(Feature Ability)`和`PA(Particle Ability)`。`FA/PA`是應用的基本組成單元,能夠實現特定的業務功能。`FA`有`UI`界面,而`PA`無`UI`界面。

3. 資源文件

應用的資源文件(字符串、圖片、音頻等)統一存放于`resources`目錄下,便于開發者使用和維護。`resources`目錄包括兩大類目錄,一類為`base`目錄與限定詞目錄,另一類為`rawfile`目錄。

4. 配置文件

配置文件` (config.json) `是應用的`Ability`信息,用于聲明應用的`Ability`,以及應用所需權限等信息。

- 應用的全局配置信息,包含應用的包名、生產廠商、版本號等基本信息。

- 應用在具體設備上的配置信息,包含應用的備份恢復、網絡安全等能力。

- `HAP`包的配置信息,包含每個`Ability`必須定義的基本屬性(如包名、類名、類型以及`Ability`提供的能力),以及應用訪問系統或其他應用受保護部分所需的權限等。

5. JS UI 框架

`JS UI`框架是一種跨設備的高性能`UI`開發框架,支持聲明式編程和跨設備多態`UI`。

- 聲明式編程

`JS UI`框架采用類`HTML`和`CSS`聲明式編程語言作為頁面布局和頁面樣式的開發語言,頁面業務邏輯則支持`ECMAScript`規范的`JavaScript`語言。`JS UI`框架提供

的聲明式編程,可以讓開發者避免編寫`UI`狀態切換的代碼,視圖配置信息更加直觀。

- 跨設備

開發框架架構上支持`UI`跨設備顯示能力,運行時自動映射到不同設備類型,開發者無感知,降低開發者多設備適配成本。

- 高性能

開發框架包含了許多核心的控件,如列表、圖片和各類容器組件等,針對聲明式語法進行了渲染流程的優化。

`JS UI`框架包括應用層`(Application)`、前端框架層`(Framework)`、引擎層`(Engine)`和平臺適配層`(Porting Layer)`。

# 空氣質量監測 UI

## 1. 創建首頁面

空氣質量監測App包含兩個界面`(Page)`,工程創建完成后會生成一個名為`index`的`Page`,可以作為首頁。

## 2. 創建詳情頁

在`pages`目錄按右鍵,彈出的菜單中選擇`New->JS Page`。

輸入頁面名稱`detail`,
 

詳情頁創建完成后應用工程目錄如下圖所示,每個`Page`包括三個文件:布局文件`hml`、樣式文件`css`、業務邏輯代碼`js`。

## 3. 開發首頁

應用首頁主要展示城市的空氣質量概況。首頁總共有兩屏(可以根據需求設置多屏),每屏顯示一個城市的空氣質量信息:主要包括AQI指數、城市名稱、污染物指數、更新時間和信息來源等數據。

### 3.1 創建根節點

修改`entry/src/main/js/default/pages/index/index.hml`,加入根節點`div`:

  1. <div class="container"> 
  2. </div> 

### 3.2 創建樣式

修改`entry/src/main/js/default/pages/index/index.css`

  1. container {     
  2.     flex-direction: column; 
  3.     height: 480px; 
  4.     width: 960px; 
 3.3 添加標題欄

標題欄包括一個退出按鈕和一個標題,兩個控件是橫向排列

  1. <div class="container">     
  2.     <div class="header" onclick="exitApp">         
  3.         <image class="back" src="common/ic_back.png"></image>         
  4.         <text class="title">             
  5.             空氣質量         
  6.          </text>     
  7.     </div> 
  8. </div> 

注意,這里要先導入common/ic_back.png圖標資源。

3.4 添加標題欄樣式

修改entry/src/main/js/default/pages/detail/detail.css,添加以下代碼,設置組件的高度、邊距、顏色等屬性。

  1. .header {     
  2.     width: 960px; 
  3.     height: 72px; 
  4. .back {     
  5.     width: 36px; 
  6.     height: 36px; 
  7.     margin-left: 39px; 
  8.     margin-top: 23px; 
  9. .title {     
  10.     width: 296px; 
  11.     height: 40px; 
  12.     margin-top: 20px; 
  13.     margin-left: 21px; 
  14.     color: #e6e6e6; 

### 3.5 添加退出事件

`onclick="exitApp"` 設置了`div`組件的`click`事件,當在標題欄上觸發點擊事件時,就會執行函數`exitApp`,該函數位于`index.js`文件中,代碼如下:

  1. exitApp() {   
  2.     console.log('start exit');   
  3.     app.terminate();   
  4.     console.log('end exit'); 

`app.terminate()`函數實現了程序退出功能;在使用該函數前,需要引入`app`模塊,在`index.js`文件的最上方寫如下代碼:

  1. import app from '@system.app' 

在 Previewer 窗口中,可以預覽界面效果

 

### 3.6 滑動組件

實現城市空氣質量信息的多屏左右滑動,需要使用`“swiper”`組件。

在根節點中添加一個子節點`swiper`, 修改`index.hml`

  1. <swiper class="swiper" index="{{swiperPage}}" duration="500" onchange="swiperChange"> 
  2.  
  3. </swiper> 
 添加樣式,修改`index.css`
 
  1. .swiper { 
  2.     height: 385px; 
  3.     width: 960px; 
 綁定`swiperPage`變量,`swiperChange`事件,修改`index.js`
 
  1. //引入router模塊,用戶頁面跳轉 
  2. import router from'@system.router' 
  3. import app from '@system.app' 
  4.   
  5. export default { 
  6.     //定義參數 
  7.     data: { 
  8.       //默認是第一頁 
  9.       swiperPage: 0  
  10.     }, 
  11.     onInit () { 
  12.     }, 
  13.     exitApp(){   
  14.         console.log('start exit');   
  15.         app.terminate();   
  16.         console.log('end exit'); 
  17.     }, 
  18.     //swiper滑動回調事件,保存當前swiper的index值,每次滑動都會將index值保存在swiperPage變量中 
  19.     swiperChange (e) { 
  20.         this.swiperPage = e.index; 
  21.     } 

在`swiper`中添加兩個子組件`stack`(絕對布局),每個`stack`組件內分別添加`text、image、progress`等組件來顯示對應的信息。

  1. <div class="container"> 
  2.     <div class="header" onclick="exitApp"> 
  3.         <image class="back" src="common/ic_back.png"></image> 
  4.         <text class="title"> 
  5.             空氣質量 
  6.         </text> 
  7.     </div> 
  8.     <swiper class="swiper" index="{{swiperPage}}" duration="500" onchange="swiperChange"> 
  9.         <!--第一屏--> 
  10.         <stack class="swiper"> 
  11.             <!--空氣質量--> 
  12.             <text class="airquality" style="color:{{textColor1}};">{{airData[0].airQuality}}</text> 
  13.             <!--城市名稱--> 
  14.             <text class="location-text">{{airData[0].location}}</text> 
  15.             <!--進度條--> 
  16.             <progress 
  17.                 class="circleProgress" 
  18.                 style="color:{{textColor1}};background-Color:{{bgColor1}};" 
  19.                 type="arc" 
  20.                 onclick="openDetail" 
  21.                 percent="{{percent1}}"> 
  22.             </progress> 
  23.             <!--云朵圖片--> 
  24.             <image class="image" src="{{src1}}"></image> 
  25.             <!--AQI數值--> 
  26.             <text class="pm25-value">{{ airData[0].detailData }}</text> 
  27.             <text class="pm25-name">AQI</text> 
  28.             <!--空氣指標詳細信息--> 
  29.             <div class="detail"> 
  30.                 <div class="text-wrapper"> 
  31.                     <text class="gas-name"> 
  32.                         CO 
  33.                     </text> 
  34.                     <text class="gas-value"> 
  35.                         100 
  36.                     </text> 
  37.                 </div> 
  38.                 <div class="text-wrapper"> 
  39.                     <text class="gas-name"> 
  40.                         NO2 
  41.                     </text> 
  42.                     <text class="gas-value"> 
  43.                         90 
  44.                     </text> 
  45.                 </div> 
  46.                 <div class="text-wrapper"> 
  47.                     <text class="gas-name"> 
  48.                         PM10 
  49.                     </text> 
  50.                     <text class="gas-value"> 
  51.                         120 
  52.                     </text> 
  53.                 </div> 
  54.                 <div class="text-wrapper"> 
  55.                     <text class="gas-name"> 
  56.                         PM2.5 
  57.                     </text> 
  58.                     <text class="gas-value"> 
  59.                         40 
  60.                     </text> 
  61.                 </div> 
  62.                 <div class="text-wrapper"> 
  63.                     <text class="gas-name"> 
  64.                         SO2 
  65.                     </text> 
  66.                     <text class="gas-value"> 
  67.                         150 
  68.                     </text> 
  69.                 </div> 
  70.                 <input class="btn" type="button" onclick="openDetail" value="歷史記錄"></input> 
  71.             </div> 
  72.             <!--更新時間和網站等信息--> 
  73.             <div class="footer"> 
  74.                 <text class="update-time"> 
  75.                     更新時間: 10:38 
  76.                 </text> 
  77.                 <text class="info-source"> 
  78.                     信息來源: tianqi.com 
  79.                 </text> 
  80.             </div> 
  81.         </stack> 
  82.  
  83.         <!--第二屏--> 
  84.         <stack class="swiper"> 
  85.             <text class="airquality" style="color: {{textColor2}};">{{airData[1].airQuality}}</text> 
  86.             <text class="location-text">{{airData[1].location}}</text> 
  87.             <progress class="circle-progress" style="color: {{textColor2}};background-Color: {{bgColor2}};" type="arc" 
  88.                     percent="{{percent2}}"></progress> 
  89.             <image class="image" src="{{src2}}"></image> 
  90.             <text class="aqi-value">{{airData[1].detailData}}</text> 
  91.             <text class="aqi"> 
  92.                 AQI 
  93.             </text> 
  94.             <div class="detail"> 
  95.                 <div class="text-wrapper"> 
  96.                     <text class="gas-name"> 
  97.                         CO 
  98.                     </text> 
  99.                     <text class="gas-value"> 
  100.                         10 
  101.                     </text> 
  102.                 </div> 
  103.                 <div class="text-wrapper"> 
  104.                     <text class="gas-name"> 
  105.                         NO2 
  106.                     </text> 
  107.                     <text class="gas-value"> 
  108.                         50 
  109.                     </text> 
  110.                 </div> 
  111.                 <div class="text-wrapper"> 
  112.                     <text class="gas-name"> 
  113.                         PM10 
  114.                     </text> 
  115.                     <text class="gas-value"> 
  116.                         60 
  117.                     </text> 
  118.                 </div> 
  119.                 <div class="text-wrapper"> 
  120.                     <text class="gas-name"> 
  121.                         PM2.5 
  122.                     </text> 
  123.                     <text class="gas-value"> 
  124.                         40 
  125.                     </text> 
  126.                 </div> 
  127.                 <div class="text-wrapper"> 
  128.                     <text class="gas-name"> 
  129.                         SO2 
  130.                     </text> 
  131.                     <text class="gas-value"> 
  132.                         150 
  133.                     </text> 
  134.                 </div> 
  135.                 <input class="btn" type="button" onclick="openDetail" value="歷史記錄"></input> 
  136.             </div> 
  137.             <div class="footer"> 
  138.                 <text class="update-time"> 
  139.                     更新時間: 10:38 
  140.                 </text> 
  141.                 <text class="info-source"> 
  142.                     信息來源: tianqi.com 
  143.                 </text> 
  144.             </div> 
  145.         </stack> 
  146.     </swiper> 
  147. </div> 

### 3.7 頁面位置指示器

添加頁面位置指示器:由于當前`swiper`不支持設置`indicator`,需要開發者自己來實現該效果。在根節點中添加一個子組件`div`,并設置相應樣式;然后在該`div`中添

加兩個子組件`div`,設置兩個`div`的`border-radius`,并在`swiper`滑動事件中動態改變對應`div`的背景色來實現該效果。

修改`index.hml`,在`swiper`組件后加入以下代碼:

  1. <div class="images">     
  2.     <div class="circle-div" style="background-color: {{iconcheckedColor}};"></div>     
  3.     <div class="circle-div" style="background-color: {{iconUncheckedColor}};margin-left: 36px;"></div> 
  4. </div> 

### 3.8 新增文字樣式

修改 `index.css`

  1. aqi-value { 
  2.     text-align: center; 
  3.     font-size: 65px; 
  4.     color: #f0ffff; 
  5.     width: 156px; 
  6.     height: 92px; 
  7.     top: 134px; 
  8.     left: 210px; 
  9. .aqi { 
  10.     text-align: center; 
  11.     color: #a2c4a2; 
  12.     width: 156px; 
  13.     height: 45px; 
  14.     top: 90px; 
  15.     left: 210px; 
  16. .airquality { 
  17.     top: 222px; 
  18.     text-align: center; 
  19.     width: 156px; 
  20.     height: 45px; 
  21.     left: 210px; 
  22. .image { 
  23.     top: 285px; 
  24.     left: 274px; 
  25.     width: 32px; 
  26.     height: 32px; 
  27. .location-text { 
  28.     text-align: center; 
  29.     color: #ffffff; 
  30.     width: 250px; 
  31.     height: 52px; 
  32.     font-size: 40px; 
  33.     left: 380px; 
  34.     top: 16px; 
  35. .container { 
  36.     flex-direction: column; 
  37.     height: 480px; 
  38.     width: 960px; 
  39. .circle-progress { 
  40.     center-x: 128px; 
  41.     center-y: 128px; 
  42.     radius: 128px; 
  43.     startAngle: 198; 
  44.     totalAngle: 320; 
  45.     strokeWidth: 24px; 
  46.     width: 256px; 
  47.     height: 256px; 
  48.     left: 160px; 
  49.     top: 58px; 
  50. .detail { 
  51.     width: 256px; 
  52.     height: 265px; 
  53.     left: 544px; 
  54.     top: 58px; 
  55.     flex-direction: column; 
  56. .text-wrapper { 
  57.     width: 256px; 
  58.     height: 35px; 
  59.     margin-top: 6px; 
  60. .gas-name { 
  61.     width: 128px; 
  62.     height: 35px; 
  63.     text-align: left; 
  64. .gas-value { 
  65.     width: 128px; 
  66.     height: 35px; 
  67.     text-align: right; 
  68. .btn { 
  69.     width: 180px; 
  70.     height: 50px; 
  71.     margin-top: 6px; 
  72.     margin-left: 38px; 
  73.     background-color: #1a1a1a; 
  74.     color: #1085CE; 
  75. .footer { 
  76.     top: 326px; 
  77.     width: 960px; 
  78.     height: 28px; 
  79. .header { 
  80.     width: 960px; 
  81.     height: 72px; 
  82. .back { 
  83.     width: 36px; 
  84.     height: 36px; 
  85.     margin-left: 39px; 
  86.     margin-top: 23px; 
  87. .title { 
  88.     width: 296px; 
  89.     height: 40px; 
  90.     margin-top: 20px; 
  91.     margin-left: 21px; 
  92.     color: #e6e6e6; 
  93. .swiper { 
  94.     height: 385px; 
  95.     width: 960px; 
  96. .images { 
  97.     width: 60px; 
  98.     height: 15px; 
  99.     margin-left: 450px; 
  100. .update-time { 
  101.     width: 480px; 
  102.     height: 28px; 
  103.     font-size: 20px; 
  104.     color: #A9A9A9; 
  105.     text-align: right; 
  106. .info-source { 
  107.     width: 450px; 
  108.     height: 28px; 
  109.     font-size: 20px; 
  110.     color: #A9A9A9; 
  111.     text-align: left; 
  112.     margin-left: 24px; 
  113. .circle-div { 
  114.     width: 12px; 
  115.     height: 12px; 
  116.     border-radius: 6px; 
 ### 3.9 實現頁面邏輯

修改`index.js`,綁定頁面數據`data`。初始化時,根據不同的數值顯示不同的字體和圖片`onInit`。實現頁面跳轉`openDetail`,將當前頁面索引傳遞給`detail`頁面。滑動觸發后`swiperChange`改變指示位置。

  1. //引入router模塊,用戶頁面跳轉 
  2. import router from'@system.router' 
  3. import app from '@system.app' 
  4.  
  5. export default { 
  6. //定義參數 
  7.     data: { 
  8.         //頁面綁定數據 
  9.         textColor1: "#00ff00", 
  10.         textColor2: "#00ff00", 
  11.         bgColor1: "#669966", 
  12.         bgColor2: "#669966", 
  13.         //默認是第一頁 
  14.         swiperPage: 0, 
  15.         percent1: 10, 
  16.         percent2: 90, 
  17.         iconUncheckedColor: '#262626', 
  18.         iconcheckedColor: '#ffffff', 
  19.         iconcheckedBR: '6px', 
  20.         src1: "common/cloud_green.png", 
  21.         src2: "common/cloud_green.png", 
  22.         airData: [ 
  23.           { 
  24.             location: "HangZhou", 
  25.             airQuality: "Good", 
  26.             detailData: 10 
  27.           }, 
  28.           { 
  29.             location: "ShangHai", 
  30.             airQuality: "Unhealth", 
  31.             detailData: 90 
  32.           } 
  33.         ] 
  34.     }, 
  35.     onInit () { 
  36.         //根據數值的不同,設置不同的字體、背景顏色和圖片 
  37.         if(this.airData[0].detailData > 100){ 
  38.             this.src1 = 'common/cloud_red.png'; 
  39.             this.textColor1 = '#ff0000'; 
  40.             this.bgColor1 = '#9d7462'; 
  41.         } else if(50 < this.airData[0].detailData && this.airData[0].detailData <= 100){ 
  42.             this.src1 = 'common/cloud_yellow.png'; 
  43.             this.textColor1 = '#ecf19a'; 
  44.             this.bgColor1 = '#9d9d62'; 
  45.         } 
  46.         if(this.airData[1].detailData > 100){ 
  47.             this.src2 = 'common/cloud_red.png'; 
  48.             this.textColor2 = '#ff0000'; 
  49.             this.bgColor2 = '#9d7462'; 
  50.         } else if(50 < this.airData[1].detailData && this.airData[1].detailData <= 100){ 
  51.             this.src2 = 'common/cloud_yellow.png'; 
  52.             this.textColor2 = '#ecf19a'; 
  53.             this.bgColor2 =  '#9d9d62'; 
  54.         } 
  55.         if(this.selectedCityIndex){ 
  56.             this.swiperPage = this.selectedCityIndex; 
  57.             if(this.swiperPage == 0){ 
  58.                 this.iconcheckedColor = '#ffffff'; 
  59.                 this.iconUncheckedColor = '#262626'; 
  60.             }else{ 
  61.                 this.iconcheckedColor = '#262626'; 
  62.                 this.iconUncheckedColor = '#ffffff'; 
  63.             } 
  64.         } 
  65.     }, 
  66.     //跳轉到詳情頁面 
  67.     openDetail () { 
  68.         router.replace({ 
  69.             uri: 'pages/detail/detail', 
  70.             params: {selectedCityIndex:this.swiperPage} 
  71.         }); 
  72.     }, 
  73.     //退出應用 
  74.     exitApp(){ 
  75.         console.log('start exit'); 
  76.         app.terminate(); 
  77.         console.log('end exit'); 
  78.     }, 
  79.     //swiper滑動回調事件,保存當前swiper的index值,每次滑動都會將index值保存在swiperPage變量中 
  80.     swiperChange (e) { 
  81.         this.swiperPage = e.index; 
  82.         if(e.index == 0){ 
  83.             this.iconcheckedColor = '#ffffff'; 
  84.             this.iconUncheckedColor = '#262626'; 
  85.         }else{ 
  86.             this.iconcheckedColor = '#262626'; 
  87.             this.iconUncheckedColor = '#ffffff'; 
  88.         } 
  89.     } 
 預覽效果如下:
 

## 4. 開發詳情頁

詳情頁以圖表的形式展示一周內空氣質量指標值。本頁面由兩部分組成:標題欄和圖表欄;在圖表欄,考慮顯示效果,我們使用多個`div`替代`chart`組件來實現圖表功能。

### 4.1 添加標題欄

修改 `entry/src/main/js/default/pages/detail/detail.hml`

  1. <div class="container"> 
  2.     <div class="header" onclick="backMain"> 
  3.         <image class="back" src="common/ic_back.png"></image> 
  4.         <text class="title"> 
  5.             歷史記錄 
  6.         </text> 
  7.     </div> 
  8.     <list class="chart-list"> 
  9.     </list> 
  10. </div> 

### 4.2 添加圖表欄

添加城市位置到`list-item-title`,圖表到`list-item-chart`

  1. <list class="chart-list"> 
  2.     <list-item class="list-item-title"> 
  3.         <text class="location">{{location}}</text> 
  4.     </list-item> 
  5.     <list-item class="list-item-chart"> 
  6.     </list-item> 
  7. </list> 
 4.3 添加圖表
  1. <div class="chart-wrapper" style="margin-left: 128px;"> 
  2.     <text class="gas-name">CO</text> 
  3.     <div class="chart"> 
  4.         <div class="chart-item" style="height: 78px;background-color: #00ff00;"></div> 
  5.         <div class="chart-item" style="height: 52px;background-color: #00ff00;"></div> 
  6.         <div class="chart-item" style="height: 155px;background-color: #ff0000;"></div> 
  7.         <div class="chart-item" style="height: 134px;background-color: #ff0000;"></div> 
  8.         <div class="chart-item" style="height: 98px;background-color: #FF7500;"></div> 
  9.         <div class="chart-item" style="height: 88px;background-color: #FF7500;"></div> 
  10.         <div class="chart-item" style="height: 144px;background-color: #ff0000;"></div> 
  11.     </div> 
  12.     <div class="white-line"></div> 
  13.     <div class="week"></div> 
  14. </div> 
 4.4 添加樣式
  1. .location { 
  2.     text-align: center; 
  3.     color: #ffffff; 
  4.     width: 960px; 
  5.     height: 52px; 
  6.     font-size: 40px; 
  7. .container { 
  8.     height: 480px; 
  9.     width: 960px; 
  10.     flex-direction: column; 
  11.  
  12. .header { 
  13.     width: 960px; 
  14.     height: 72px; 
  15.  
  16. .back { 
  17.     width: 36px; 
  18.     height: 36px; 
  19.     margin-left: 39px; 
  20.     margin-top: 23px; 
  21.  
  22. .title { 
  23.     width: 296px; 
  24.     height: 40px; 
  25.     margin-top: 20px; 
  26.     margin-left: 21px; 
  27.     color: #e6e6e6; 
  28.  
  29. .chart-list { 
  30.     width: 960px; 
  31.     height: 408px; 
  32.  
  33. .list-item-title { 
  34.     width: 960px; 
  35.     height: 52px; 
  36.  
  37. .list-item-chart { 
  38.     width: 960px; 
  39.     height: 280px; 
  40.  
  41. .chart-wrapper { 
  42.     width: 308px; 
  43.     height: 256px; 
  44.     flex-direction: column; 
  45.  
  46. .gas-name { 
  47.     width: 308px; 
  48.     height: 35px; 
  49.     text-align: left; 
  50.  
  51. .chart { 
  52.     width: 308px; 
  53.     height: 155px; 
  54.     margin-top: 10px; 
  55.     justify-content: flex-start; 
  56.     align-items: flex-end; 
  57.  
  58. .chart-item { 
  59.     width: 24px; 
  60.     margin-left: 18px; 
  61.     border-radius: 3px; 
  62.  
  63. .white-line { 
  64.     width: 308px; 
  65.     height: 2px; 
  66.     background-color: #ffffff; 
  67.     margin-top: 22px; 
  68.  
  69. .week { 
  70.     width: 308px; 
  71.     height: 17px; 
  72.     margin-top: 6px; 
  73.     border-color: #ffffff; 
  74.     border-radius: 2px; 
  75.     margin-top: 6px; 
  76.  
  77. .day { 
  78.     width: 26px; 
  79.     height: 17px; 
  80.     font-size: 10px; 
  81.     margin-left: 16px; 
  82.     text-align: center; 
 ### 4.5 實現頁面跳轉

其中`onclick="backMain"`為返回主頁事件,根據傳遞的頁面索引,顯示不同的位置數據,`detail.js`中的代碼實現如下:

  1. import router from '@system.router' 
  2.  
  3. export default { 
  4.     data: { 
  5.         location: '' 
  6.     }, 
  7.     onInit() { 
  8.         if (this.selectedCityIndex === 0) { 
  9.             this.location = '杭州'; 
  10.         } else { 
  11.             this.location = '上海'; 
  12.         } 
  13.     }, 
  14.     backMain() { 
  15.         router.replace({ 
  16.             uri: 'pages/index/index', 
  17.             params: { 
  18.                 selectedCityIndex: this.selectedCityIndex 
  19.             } 
  20.         }); 
  21.     } 
 

5. 模擬器調試

菜單Tools->HVD Manager,可以打開云端的模擬器

 
注冊華為開發者賬號,授權登錄后
 
 
就能看到模擬器列表了,相比`beta`版只有`Phone`、`TV`和`Wearable`三種,增加了不少的設備。
 
 

可惜還沒有可用于`smartVision`設備的模擬器,現階段我們還只能燒錄到設備中調試,總體上"富鴻蒙"的進度比較快,期待一波更新。

## 6. 編譯打包

若開發手機端的`App`,則需要申請證書,對應用程序進行簽名。這樣才能發布到應用市場,才被允許安裝到真機上運行。

`IPCamera`應用**暫時不支持簽名模式**,所以需要將應用發布為未簽名的應用安裝包。

菜單`Build->Buildo APP(s)/Hap(s)->Build Release Hap(s)`,生成`Hap`文件。

輸出文件為 `build/outputs/hap/release/smartVision/entry-release-smartVision-unsigned.hap`,改名為`MyUiApp.hap`便于安裝。

## 7. 通過sdcard安裝

### 7.1 復制安裝包和工具

將IDE編譯的未簽名應用安裝包和安裝工具(`Z:\openharmony\out\my_hi3516dv300\dev_tools`)放在`sdcard`中,將`sdcard`插入開發板卡槽。

### 7.2 禁用簽名校驗

應用安裝默認要校驗簽名,需要執行以下命令,關閉簽名校驗。

  1. ./sdcard/dev_tools/bin/bm set -s disable 
 

7.3 安裝應用

  1. ./sdcard/dev_tools/bin/bm install -p /sdcard/MyUiApp.hap  
 

## 8. 通過NFS安裝

每次插拔`sdcard`還是蠻不方便的,這里我們安裝一個`NFS`服務器,讓鴻蒙系統能直接訪問`Win10`的目錄,后續安裝調試就會方便很多。

### 8.1 安裝NFS服務器

我們先安裝一個`haneWIN NFS服務器`, 雙擊文末網盤里的`nfs1169.exe`,一路下一步即可。

 

8.2 配置目錄參數

編輯輸出表文件,定義傳輸目錄

 
  1. # exports example 
  2.  
  3. # C:\ftp -range 192.168.1.1 192.168.1.10 
  4. # c:\public -public -readonly 
  5. # c:\tools -readonly 192.168.1.4 
  6.  
  7. D:\PycharmProjects\aiLearn\Harmony\tftp -public -name:nfs 
 ### 8.3 重啟服務

右鍵管理員權限,重啟所有服務,讓配置生效。

 

### 8.4 設置防火墻

防火墻設置`111、1058、2049`這些端口的`TCP`和`UDP`,入站規則放行。

  

### 8.5 鴻蒙上掛載目錄

主電腦的`ip`地址為`192.168.1.57`,`NFS`服務的別名為`nfs`,對應的目錄為`D:\PycharmProjects\aiLearn\Harmony\tftp`

  1. mkdir nfs 
  2. mount 192.168.1.57:/nfs /nfs nfs 
  掛載到鴻蒙的剛新建的 `/nfs`目錄下,我們可以復制安裝包和安裝工具
 
 

8.6 安裝應用

  1. cd nfs 
  2. ./dev_tools/bin/bm set -s disable 
  3. ./dev_tools/bin/bm install -p MyUiApp.hap 

前面做了這么多的鋪墊,后續開發只要復制`hap`安裝包,直接一條命令安裝即可,非常方便。

 

# 運行程序

安裝完成后,點擊桌面上的`MyUiApp`就能看見界面效果了。

`Js UI框架`對開發者還是比較友好的,有小程序或快應用的開發經驗,上手應該都比較順滑。

不過`HarmonyOS Device`的支持庫精簡的非常嚴重,例如網絡訪問的`@system.request`和`@system.fetch`都不可用,這些功能在“富鴻蒙”的設備上開發就會比較方便。

# 資料下載

 

# 下一篇預告

> 本期主要介紹了一下JS框架下的界面開發,

> 下一篇我們將嘗試熟悉更多的設備能力,

> 并打通從框架用戶態到驅動內核態之間的聯系,

> 敬請期待...

 
©著作權歸作者和HarmonyOS技術社區共同所有,如需轉載,請注明出處,否則將追究法律責任

想了解更多內容,請訪問:

51CTO和華為官方合作共建的鴻蒙技術社區

https://harmonyos.51cto.com/#zz

 

責任編輯:jianghua 來源: 鴻蒙社區
相關推薦

2021-01-15 11:36:16

鴻蒙HarmonyOSAI應用

2021-01-15 09:50:06

鴻蒙HarmonyOSAI應用

2021-01-14 12:06:22

鴻蒙HarmonyOSAI應用

2021-01-19 12:46:45

鴻蒙HarmonyOSHelloworld

2024-06-07 13:11:44

2021-02-06 10:40:45

鴻蒙HarmonyOS應用開發

2011-04-14 10:03:32

UI組件BlackBerry

2011-04-14 10:05:16

BlackBerry

2021-01-21 13:27:37

鴻蒙HarmonyOS應用開發

2021-01-05 10:35:04

鴻蒙HarmonyOS應用開發

2021-10-18 10:14:26

鴻蒙HarmonyOS應用

2020-09-28 15:13:04

鴻蒙

2021-11-24 16:02:57

鴻蒙HarmonyOS應用

2025-02-24 02:00:00

AIC#模型

2019-05-05 11:02:07

vscodevue前端

2009-12-09 10:48:50

ibmdwLotus

2024-11-11 16:22:15

2020-11-09 11:56:49

HarmonyOS

2024-11-26 07:33:09

2021-01-18 13:26:06

鴻蒙HarmonyOS應用
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美日韩在线观看一区 | 日韩不卡一区二区 | 欧美日韩高清在线一区 | 国产亚洲精品久久19p | 久久久国产视频 | 国产在线精品一区二区 | 欧美一级做性受免费大片免费 | 午夜精品久久久久久不卡欧美一级 | 91精品国产91久久久久久丝袜 | 亚洲一区二区视频在线观看 | 国产精品久久久久一区二区三区 | 天天夜天天操 | 国产一区二区三区四区五区加勒比 | 99久久精品免费看国产小宝寻花 | 成在线人视频免费视频 | 亚洲在线看 | 亚洲视频欧美视频 | 久久成人人人人精品欧 | 国产高清视频一区二区 | 你懂的在线视频播放 | 亚洲综合色自拍一区 | 中文字幕精品一区 | 国内久久精品 | 欧美一级黄带 | 在线 丝袜 欧美 日韩 制服 | 日韩精品视频在线免费观看 | 亚洲精品字幕 | 久久精品一区 | 久久免费香蕉视频 | 欧美一区二区三区在线观看视频 | 亚洲精品一 | 国产美女视频黄 | 免费黄色网址视频 | 日本一区二区影视 | 色天天综合 | 黄色一级电影免费观看 | 免费a v网站 | 国内精品久久精品 | 一区在线视频 | 精品国产乱码久久久久久蜜柚 | 91高清在线观看 |