1e41f4b71Sopenharmony_ci# Building the Home Page<a name="EN-US_TOPIC_0000001054927705"></a> 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciThe application home page displays air quality information of different cities. The home page provides two screens \(for two information bars\), which can be added as required. Each screen displays the air quality information of one city, including the Air Quality Index \(AQI\), city name, pollution level, update time, and data source. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciThe home page of [AirQuality](device-camera-visual-overview.md) consists of three parts: 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci- Title bar: displays the page title and provides an exit button. The title bar is fixed at the top of the page. 8e41f4b71Sopenharmony_ci- Information bar: displays air quality information. Multiple information bars can be added based on user requirements and support looping scroll. 9e41f4b71Sopenharmony_ci- Indicator bar: shows the position of the current screen among all screens. The indicator bar is fixed at the bottom of the page. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciThe following steps describe how to build the home page with a flexible layout that has three rows vertically arranged. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci1. Add a root **<div\>** to the **.hml** file. Note that each **.hml** file can contain only one root component. The sample code is as follows: 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci ``` 16e41f4b71Sopenharmony_ci <div class="container"> 17e41f4b71Sopenharmony_ci </div> 18e41f4b71Sopenharmony_ci ``` 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci **class="container"** indicates the style used by the component. The **container** is a style class defined in the **index.css** file. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci ``` 23e41f4b71Sopenharmony_ci .container { 24e41f4b71Sopenharmony_ci flex-direction: column; 25e41f4b71Sopenharmony_ci height: 480px; 26e41f4b71Sopenharmony_ci width: 960px; 27e41f4b71Sopenharmony_ci } 28e41f4b71Sopenharmony_ci ``` 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci The height and width of the root component **<div\>** are set in the style class. Note that the height and width must be explicitly specified \(except for some components, such as **<text\>**\). Otherwise, the component may fail to display. In the **container** style class, the **flex-direction** attribute is set to **column**, which means that child components of **<div\>** are vertically arranged from top to bottom for implementing the flexible page layout. 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci2. Add the title bar. The title bar consists of an exit button and title text that are horizontally arranged. Add a **<div\>** to hold the title bar and set the **flex-direction** attribute to **row** to arrange the child components from left to right. Add an **<image\>** and a **<text\>** component in sequence. The sample code is as follows: 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci ``` 35e41f4b71Sopenharmony_ci <div class="container"> 36e41f4b71Sopenharmony_ci <div class="header" onclick="exitApp"> 37e41f4b71Sopenharmony_ci <image class="back" src="common/ic_back.png"></image> 38e41f4b71Sopenharmony_ci <text class="title"> 39e41f4b71Sopenharmony_ci Air quality 40e41f4b71Sopenharmony_ci </text> 41e41f4b71Sopenharmony_ci </div> 42e41f4b71Sopenharmony_ci </div> 43e41f4b71Sopenharmony_ci ``` 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci Set component attributes, including the height, width, margin, and color. 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci ``` 48e41f4b71Sopenharmony_ci .header { 49e41f4b71Sopenharmony_ci width: 960px; 50e41f4b71Sopenharmony_ci height: 72px; 51e41f4b71Sopenharmony_ci } 52e41f4b71Sopenharmony_ci .back { 53e41f4b71Sopenharmony_ci width: 36px; 54e41f4b71Sopenharmony_ci height: 36px; 55e41f4b71Sopenharmony_ci margin-left: 39px; 56e41f4b71Sopenharmony_ci margin-top: 23px; 57e41f4b71Sopenharmony_ci } 58e41f4b71Sopenharmony_ci .title { 59e41f4b71Sopenharmony_ci width: 296px; 60e41f4b71Sopenharmony_ci height: 40px; 61e41f4b71Sopenharmony_ci margin-top: 20px; 62e41f4b71Sopenharmony_ci margin-left: 21px; 63e41f4b71Sopenharmony_ci color: #e6e6e6; 64e41f4b71Sopenharmony_ci } 65e41f4b71Sopenharmony_ci ``` 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci In the **.hml** file, **onclick="exitApp"** sets the click event for the **<div\>** component. When the click event is triggered, the **exitApp\(\)** function is executed. The example definition of **exitApp\(\)** in **index.js** is as follows: 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci ``` 70e41f4b71Sopenharmony_ci exitApp() { 71e41f4b71Sopenharmony_ci console.log('start exit'); 72e41f4b71Sopenharmony_ci app.terminate(); 73e41f4b71Sopenharmony_ci console.log('end exit'); 74e41f4b71Sopenharmony_ci } 75e41f4b71Sopenharmony_ci ``` 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci The **app.terminate\(\)** function is used to exit the program. Before using this function, you must import the **app** module by adding the following code at the beginning of **index.js**: 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci ``` 80e41f4b71Sopenharmony_ci import app from '@system.app' 81e41f4b71Sopenharmony_ci ``` 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci After the code is compiled, run the project on the simulator. The following figure shows the display effect. 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci **Figure 1** Title bar<a name="fig14273162465317"></a> 86e41f4b71Sopenharmony_ci  87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci3. The **<swiper\>** component is required to implement the switching between screens. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci Add a **<swiper\>** to the root node. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci ``` 93e41f4b71Sopenharmony_ci <div class="container"> 94e41f4b71Sopenharmony_ci <div class="header" onclick="exitApp"> 95e41f4b71Sopenharmony_ci <image class="back" src="common/ic_back.png"></image> 96e41f4b71Sopenharmony_ci <text class="title"> 97e41f4b71Sopenharmony_ci Air quality 98e41f4b71Sopenharmony_ci </text> 99e41f4b71Sopenharmony_ci </div> 100e41f4b71Sopenharmony_ci <swiper class="swiper" index="{{swiperPage}}" duration="500" onchange="swiperChange"> 101e41f4b71Sopenharmony_ci </swiper> 102e41f4b71Sopenharmony_ci </div> 103e41f4b71Sopenharmony_ci ``` 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci - Use **class="**swiper**"** to set the height and width of the component. The sample code is as follows: 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci ``` 108e41f4b71Sopenharmony_ci .swiper { 109e41f4b71Sopenharmony_ci height: 385px; 110e41f4b71Sopenharmony_ci width: 960px; 111e41f4b71Sopenharmony_ci } 112e41f4b71Sopenharmony_ci ``` 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci - **index="\{\{swiperPage\}\}" duration="500" onchange="swiperChange"** sets the component attribute and event. **duration="500"** indicates that the duration of the swiping animation is 500 ms. 115e41f4b71Sopenharmony_ci - **index="\{\{swiperPage\}\}"** specifies the index of the child component of **<swiper\>**. **\{\{swiperPage\}\}** indicates that the index value is dynamically bound to the **swiperPage** variable in the JavaScript code. The index value changes with the **swiperPage** value. 116e41f4b71Sopenharmony_ci - **onchange="swiperChange"** binds the change event of the **<swiper\>** component to the **swiperChange** function. The JavaScript code is as follows: 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci ``` 119e41f4b71Sopenharmony_ci // Import the router module for page switching. 120e41f4b71Sopenharmony_ci import router from'@system.router' 121e41f4b71Sopenharmony_ci import app from '@system.app' 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci export default { 124e41f4b71Sopenharmony_ci // Define parameters. 125e41f4b71Sopenharmony_ci data: { 126e41f4b71Sopenharmony_ci // By default, the first page is displayed. 127e41f4b71Sopenharmony_ci swiperPage: 0 128e41f4b71Sopenharmony_ci }, 129e41f4b71Sopenharmony_ci onInit () { 130e41f4b71Sopenharmony_ci }, 131e41f4b71Sopenharmony_ci exitApp(){ 132e41f4b71Sopenharmony_ci console.log('start exit'); 133e41f4b71Sopenharmony_ci app.terminate(); 134e41f4b71Sopenharmony_ci console.log('end exit'); 135e41f4b71Sopenharmony_ci }, 136e41f4b71Sopenharmony_ci // Swiping event, which saves the index value of the current <swiper>. The index value is saved to the swiperPage variable each time a swiping occurs. 137e41f4b71Sopenharmony_ci swiperChange (e) { 138e41f4b71Sopenharmony_ci this.swiperPage = e.index; 139e41f4b71Sopenharmony_ci } 140e41f4b71Sopenharmony_ci } 141e41f4b71Sopenharmony_ci ``` 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci4. Set the information about a city to be displayed on a screen. On each screen, information of different types is displayed using different components. 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci Add two **<stack\>** as child components \(directional layout\) to **<swiper\>**. Add **<text\>**, **<image\>**, **<progress\>**, and other components to each **<stack\>** to display the information. The following example shows the page structure: 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci ``` 148e41f4b71Sopenharmony_ci <swiper class="swiper" index="{{swiperPage}}" duration="500" onchange="swiperChange"> 149e41f4b71Sopenharmony_ci <!-- The first screen --> 150e41f4b71Sopenharmony_ci <stack class="swiper"> 151e41f4b71Sopenharmony_ci <text></text>------Air quality 152e41f4b71Sopenharmony_ci <text></text>------City name 153e41f4b71Sopenharmony_ci <progress></progress>-----Progress bar 154e41f4b71Sopenharmony_ci <image></image>-------A cloud image 155e41f4b71Sopenharmony_ci <text></text>--------AQI value 156e41f4b71Sopenharmony_ci <text>AQI</text>------AQI 157e41f4b71Sopenharmony_ci <div>--------AQI details 158e41f4b71Sopenharmony_ci </div> 159e41f4b71Sopenharmony_ci <div>--------Update time, website, and other information 160e41f4b71Sopenharmony_ci </div> 161e41f4b71Sopenharmony_ci </stack> 162e41f4b71Sopenharmony_ci <!-- The second screen --> 163e41f4b71Sopenharmony_ci <stack class="container"> 164e41f4b71Sopenharmony_ci <text></text> 165e41f4b71Sopenharmony_ci <text></text> 166e41f4b71Sopenharmony_ci <progress></progress> 167e41f4b71Sopenharmony_ci <image></image> 168e41f4b71Sopenharmony_ci <text></text> 169e41f4b71Sopenharmony_ci <text></text> 170e41f4b71Sopenharmony_ci <div></div> 171e41f4b71Sopenharmony_ci </stack> 172e41f4b71Sopenharmony_ci </swiper> 173e41f4b71Sopenharmony_ci ``` 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci After the code is compiled, the display effect on the simulator is as follows. 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci **Figure 2** Title bar and information bar<a name="fig177003454238"></a> 178e41f4b71Sopenharmony_ci  179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci5. Add the indicator bar. Currently, the **<swiper\>** component does not support indicator settings. You need to implement a dots indicator by adding **<div\>** components and setting the style. Add a **<div\>** as a child component to the root node and set the style. Add two **<div\>** to the parent **<div\>**, set **border-radius** for the two child **<div\>**, and dynamically change the background colors of the **<div\>** components in the swiping event. 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci ``` 183e41f4b71Sopenharmony_ci <div class="images"> 184e41f4b71Sopenharmony_ci <div class="circle-div" style="background-color: {{iconcheckedColor}};"></div> 185e41f4b71Sopenharmony_ci <div class="circle-div" style="background-color: {{iconUncheckedColor}};margin-left: 36px;"></div> 186e41f4b71Sopenharmony_ci </div> 187e41f4b71Sopenharmony_ci ``` 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci **Figure 3** Indicator bar<a name="fig767374119496"></a> 190e41f4b71Sopenharmony_ci  191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci6. Set the style, animation effect, and dynamic data binding for all components. The complete sample code is as follows: 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci - **index.hml** 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci ``` 197e41f4b71Sopenharmony_ci <div class="container"> 198e41f4b71Sopenharmony_ci <div class="header" onclick="exitApp"> 199e41f4b71Sopenharmony_ci <image class="back" src="common/ic_back.png"></image> 200e41f4b71Sopenharmony_ci <text class="title"> 201e41f4b71Sopenharmony_ci AirQuality 202e41f4b71Sopenharmony_ci </text> 203e41f4b71Sopenharmony_ci </div> 204e41f4b71Sopenharmony_ci <swiper class="swiper" index="{{swiperPage}}" duration="500" onchange="swiperChange"> 205e41f4b71Sopenharmony_ci <stack class="swiper"> 206e41f4b71Sopenharmony_ci <text class="airquality" style="color:{{textColor1}};">{{airData[0].airQuality}} 207e41f4b71Sopenharmony_ci </text> 208e41f4b71Sopenharmony_ci <text class="location-text">{{airData[0].location}} 209e41f4b71Sopenharmony_ci </text> 210e41f4b71Sopenharmony_ci <progress class="circle-progress" style="color: {{textColor1}};background-Color: {{bgColor1}};" type="arc" 211e41f4b71Sopenharmony_ci percent="{{percent1}}"></progress> 212e41f4b71Sopenharmony_ci <image class="image" src="{{src1}}"></image> 213e41f4b71Sopenharmony_ci <text class="aqi-value">{{airData[0].detailData}} 214e41f4b71Sopenharmony_ci </text> 215e41f4b71Sopenharmony_ci <text class="aqi"> 216e41f4b71Sopenharmony_ci AQI 217e41f4b71Sopenharmony_ci </text> 218e41f4b71Sopenharmony_ci <div class="detail"> 219e41f4b71Sopenharmony_ci <div class="text-wrapper"> 220e41f4b71Sopenharmony_ci <text class="gas-name"> 221e41f4b71Sopenharmony_ci CO 222e41f4b71Sopenharmony_ci </text> 223e41f4b71Sopenharmony_ci <text class="gas-value"> 224e41f4b71Sopenharmony_ci 100 225e41f4b71Sopenharmony_ci </text> 226e41f4b71Sopenharmony_ci </div> 227e41f4b71Sopenharmony_ci <div class="text-wrapper"> 228e41f4b71Sopenharmony_ci <text class="gas-name"> 229e41f4b71Sopenharmony_ci NO2 230e41f4b71Sopenharmony_ci </text> 231e41f4b71Sopenharmony_ci <text class="gas-value"> 232e41f4b71Sopenharmony_ci 90 233e41f4b71Sopenharmony_ci </text> 234e41f4b71Sopenharmony_ci </div> 235e41f4b71Sopenharmony_ci <div class="text-wrapper"> 236e41f4b71Sopenharmony_ci <text class="gas-name"> 237e41f4b71Sopenharmony_ci PM10 238e41f4b71Sopenharmony_ci </text> 239e41f4b71Sopenharmony_ci <text class="gas-value"> 240e41f4b71Sopenharmony_ci 120 241e41f4b71Sopenharmony_ci </text> 242e41f4b71Sopenharmony_ci </div> 243e41f4b71Sopenharmony_ci <div class="text-wrapper"> 244e41f4b71Sopenharmony_ci <text class="gas-name"> 245e41f4b71Sopenharmony_ci PM2.5 246e41f4b71Sopenharmony_ci </text> 247e41f4b71Sopenharmony_ci <text class="gas-value"> 248e41f4b71Sopenharmony_ci 40 249e41f4b71Sopenharmony_ci </text> 250e41f4b71Sopenharmony_ci </div> 251e41f4b71Sopenharmony_ci <div class="text-wrapper"> 252e41f4b71Sopenharmony_ci <text class="gas-name"> 253e41f4b71Sopenharmony_ci SO2 254e41f4b71Sopenharmony_ci </text> 255e41f4b71Sopenharmony_ci <text class="gas-value"> 256e41f4b71Sopenharmony_ci 150 257e41f4b71Sopenharmony_ci </text> 258e41f4b71Sopenharmony_ci </div> 259e41f4b71Sopenharmony_ci <input class="btn" type="button" onclick="openDetail" value=" History"></input> 260e41f4b71Sopenharmony_ci </div> 261e41f4b71Sopenharmony_ci <div class="footer"> 262e41f4b71Sopenharmony_ci <text class="update-time"> 263e41f4b71Sopenharmony_ci Update Time: 10:38 264e41f4b71Sopenharmony_ci </text> 265e41f4b71Sopenharmony_ci <text class="info-source"> 266e41f4b71Sopenharmony_ci From: tianqi.com 267e41f4b71Sopenharmony_ci </text> 268e41f4b71Sopenharmony_ci </div> 269e41f4b71Sopenharmony_ci </stack> 270e41f4b71Sopenharmony_ci <stack class="swiper"> 271e41f4b71Sopenharmony_ci <text class="airquality" style="color: {{textColor2}};">{{airData[1].airQuality}} 272e41f4b71Sopenharmony_ci </text> 273e41f4b71Sopenharmony_ci <text class="location-text">{{airData[1].location}} 274e41f4b71Sopenharmony_ci </text> 275e41f4b71Sopenharmony_ci <progress class="circle-progress" style="color: {{textColor2}};background-Color: {{bgColor2}};" type="arc" 276e41f4b71Sopenharmony_ci percent="{{percent2}}"></progress> 277e41f4b71Sopenharmony_ci <image class="image" src="{{src2}}"></image> 278e41f4b71Sopenharmony_ci <text class="aqi-value">{{airData[1].detailData}} 279e41f4b71Sopenharmony_ci </text> 280e41f4b71Sopenharmony_ci <text class="aqi"> 281e41f4b71Sopenharmony_ci AQI 282e41f4b71Sopenharmony_ci </text> 283e41f4b71Sopenharmony_ci <div class="detail"> 284e41f4b71Sopenharmony_ci <div class="text-wrapper"> 285e41f4b71Sopenharmony_ci <text class="gas-name"> 286e41f4b71Sopenharmony_ci CO 287e41f4b71Sopenharmony_ci </text> 288e41f4b71Sopenharmony_ci <text class="gas-value"> 289e41f4b71Sopenharmony_ci 10 290e41f4b71Sopenharmony_ci </text> 291e41f4b71Sopenharmony_ci </div> 292e41f4b71Sopenharmony_ci <div class="text-wrapper"> 293e41f4b71Sopenharmony_ci <text class="gas-name"> 294e41f4b71Sopenharmony_ci NO2 295e41f4b71Sopenharmony_ci </text> 296e41f4b71Sopenharmony_ci <text class="gas-value"> 297e41f4b71Sopenharmony_ci 50 298e41f4b71Sopenharmony_ci </text> 299e41f4b71Sopenharmony_ci </div> 300e41f4b71Sopenharmony_ci <div class="text-wrapper"> 301e41f4b71Sopenharmony_ci <text class="gas-name"> 302e41f4b71Sopenharmony_ci PM10 303e41f4b71Sopenharmony_ci </text> 304e41f4b71Sopenharmony_ci <text class="gas-value"> 305e41f4b71Sopenharmony_ci 60 306e41f4b71Sopenharmony_ci </text> 307e41f4b71Sopenharmony_ci </div> 308e41f4b71Sopenharmony_ci <div class="text-wrapper"> 309e41f4b71Sopenharmony_ci <text class="gas-name"> 310e41f4b71Sopenharmony_ci PM2.5 311e41f4b71Sopenharmony_ci </text> 312e41f4b71Sopenharmony_ci <text class="gas-value"> 313e41f4b71Sopenharmony_ci 40 314e41f4b71Sopenharmony_ci </text> 315e41f4b71Sopenharmony_ci </div> 316e41f4b71Sopenharmony_ci <div class="text-wrapper"> 317e41f4b71Sopenharmony_ci <text class="gas-name"> 318e41f4b71Sopenharmony_ci SO2 319e41f4b71Sopenharmony_ci </text> 320e41f4b71Sopenharmony_ci <text class="gas-value"> 321e41f4b71Sopenharmony_ci 150 322e41f4b71Sopenharmony_ci </text> 323e41f4b71Sopenharmony_ci </div> 324e41f4b71Sopenharmony_ci <input class="btn" type="button" onclick="openDetail" value=" History"></input> 325e41f4b71Sopenharmony_ci </div> 326e41f4b71Sopenharmony_ci <div class="footer"> 327e41f4b71Sopenharmony_ci <text class="update-time"> 328e41f4b71Sopenharmony_ci Update Time: 10:38 329e41f4b71Sopenharmony_ci </text> 330e41f4b71Sopenharmony_ci <text class="info-source"> 331e41f4b71Sopenharmony_ci From: tianqi.com 332e41f4b71Sopenharmony_ci </text> 333e41f4b71Sopenharmony_ci </div> 334e41f4b71Sopenharmony_ci </stack> 335e41f4b71Sopenharmony_ci </swiper> 336e41f4b71Sopenharmony_ci <div class="images"> 337e41f4b71Sopenharmony_ci <div class="circle-div" style="background-color: {{iconcheckedColor}};"></div> 338e41f4b71Sopenharmony_ci <div class="circle-div" style="background-color: {{iconUncheckedColor}};margin-left: 36px;"></div> 339e41f4b71Sopenharmony_ci </div> 340e41f4b71Sopenharmony_ci </div> 341e41f4b71Sopenharmony_ci ``` 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci - **index.css** 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci A **.css** file contains many classes. Each class defines the position, size, font, color, and background color of a component. Each child component is added to its parent component, and the style file of the parent component affects how the child component will be displayed. 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci ``` 348e41f4b71Sopenharmony_ci .aqi-value { 349e41f4b71Sopenharmony_ci text-align: center; 350e41f4b71Sopenharmony_ci font-size: 65px; 351e41f4b71Sopenharmony_ci color: #f0ffff; 352e41f4b71Sopenharmony_ci width: 156px; 353e41f4b71Sopenharmony_ci height: 92px; 354e41f4b71Sopenharmony_ci top: 134px; 355e41f4b71Sopenharmony_ci left: 210px; 356e41f4b71Sopenharmony_ci } 357e41f4b71Sopenharmony_ci .aqi { 358e41f4b71Sopenharmony_ci text-align: center; 359e41f4b71Sopenharmony_ci color: #a2c4a2; 360e41f4b71Sopenharmony_ci width: 156px; 361e41f4b71Sopenharmony_ci height: 45px; 362e41f4b71Sopenharmony_ci top: 90px; 363e41f4b71Sopenharmony_ci left: 210px; 364e41f4b71Sopenharmony_ci } 365e41f4b71Sopenharmony_ci .airquality { 366e41f4b71Sopenharmony_ci top: 222px; 367e41f4b71Sopenharmony_ci text-align: center; 368e41f4b71Sopenharmony_ci width: 156px; 369e41f4b71Sopenharmony_ci height: 45px; 370e41f4b71Sopenharmony_ci left: 210px; 371e41f4b71Sopenharmony_ci } 372e41f4b71Sopenharmony_ci .image { 373e41f4b71Sopenharmony_ci top: 285px; 374e41f4b71Sopenharmony_ci left: 274px; 375e41f4b71Sopenharmony_ci width: 32px; 376e41f4b71Sopenharmony_ci height: 32px; 377e41f4b71Sopenharmony_ci } 378e41f4b71Sopenharmony_ci .location-text { 379e41f4b71Sopenharmony_ci text-align: center; 380e41f4b71Sopenharmony_ci color: #ffffff; 381e41f4b71Sopenharmony_ci width: 200px; 382e41f4b71Sopenharmony_ci height: 52px; 383e41f4b71Sopenharmony_ci font-size: 40px; 384e41f4b71Sopenharmony_ci left: 380px; 385e41f4b71Sopenharmony_ci top: 16px; 386e41f4b71Sopenharmony_ci } 387e41f4b71Sopenharmony_ci .container { 388e41f4b71Sopenharmony_ci flex-direction: column; 389e41f4b71Sopenharmony_ci height: 480px; 390e41f4b71Sopenharmony_ci width: 960px; 391e41f4b71Sopenharmony_ci } 392e41f4b71Sopenharmony_ci .circle-progress { 393e41f4b71Sopenharmony_ci center-x: 128px; 394e41f4b71Sopenharmony_ci center-y: 128px; 395e41f4b71Sopenharmony_ci radius: 128px; 396e41f4b71Sopenharmony_ci startAngle: 198; 397e41f4b71Sopenharmony_ci totalAngle: 320; 398e41f4b71Sopenharmony_ci strokeWidth: 24px; 399e41f4b71Sopenharmony_ci width: 256px; 400e41f4b71Sopenharmony_ci height: 256px; 401e41f4b71Sopenharmony_ci left: 160px; 402e41f4b71Sopenharmony_ci top: 58px; 403e41f4b71Sopenharmony_ci } 404e41f4b71Sopenharmony_ci .detail { 405e41f4b71Sopenharmony_ci width: 256px; 406e41f4b71Sopenharmony_ci height: 265px; 407e41f4b71Sopenharmony_ci left: 544px; 408e41f4b71Sopenharmony_ci top: 58px; 409e41f4b71Sopenharmony_ci flex-direction: column; 410e41f4b71Sopenharmony_ci } 411e41f4b71Sopenharmony_ci .text-wrapper { 412e41f4b71Sopenharmony_ci width: 256px; 413e41f4b71Sopenharmony_ci height: 35px; 414e41f4b71Sopenharmony_ci margin-top: 6px; 415e41f4b71Sopenharmony_ci } 416e41f4b71Sopenharmony_ci .gas-name { 417e41f4b71Sopenharmony_ci width: 128px; 418e41f4b71Sopenharmony_ci height: 35px; 419e41f4b71Sopenharmony_ci text-align: left; 420e41f4b71Sopenharmony_ci } 421e41f4b71Sopenharmony_ci .gas-value { 422e41f4b71Sopenharmony_ci width: 128px; 423e41f4b71Sopenharmony_ci height: 35px; 424e41f4b71Sopenharmony_ci text-align: right; 425e41f4b71Sopenharmony_ci } 426e41f4b71Sopenharmony_ci .btn { 427e41f4b71Sopenharmony_ci width: 180px; 428e41f4b71Sopenharmony_ci height: 50px; 429e41f4b71Sopenharmony_ci margin-top: 6px; 430e41f4b71Sopenharmony_ci margin-left: 38px; 431e41f4b71Sopenharmony_ci background-color: #1a1a1a; 432e41f4b71Sopenharmony_ci color: #1085CE; 433e41f4b71Sopenharmony_ci } 434e41f4b71Sopenharmony_ci .footer { 435e41f4b71Sopenharmony_ci top: 326px; 436e41f4b71Sopenharmony_ci width: 960px; 437e41f4b71Sopenharmony_ci height: 28px; 438e41f4b71Sopenharmony_ci } 439e41f4b71Sopenharmony_ci .header { 440e41f4b71Sopenharmony_ci width: 960px; 441e41f4b71Sopenharmony_ci height: 72px; 442e41f4b71Sopenharmony_ci } 443e41f4b71Sopenharmony_ci .back { 444e41f4b71Sopenharmony_ci width: 36px; 445e41f4b71Sopenharmony_ci height: 36px; 446e41f4b71Sopenharmony_ci margin-left: 39px; 447e41f4b71Sopenharmony_ci margin-top: 23px; 448e41f4b71Sopenharmony_ci } 449e41f4b71Sopenharmony_ci .title { 450e41f4b71Sopenharmony_ci width: 296px; 451e41f4b71Sopenharmony_ci height: 40px; 452e41f4b71Sopenharmony_ci margin-top: 20px; 453e41f4b71Sopenharmony_ci margin-left: 21px; 454e41f4b71Sopenharmony_ci color: #e6e6e6; 455e41f4b71Sopenharmony_ci } 456e41f4b71Sopenharmony_ci .swiper { 457e41f4b71Sopenharmony_ci height: 385px; 458e41f4b71Sopenharmony_ci width: 960px; 459e41f4b71Sopenharmony_ci } 460e41f4b71Sopenharmony_ci .images { 461e41f4b71Sopenharmony_ci width: 60px; 462e41f4b71Sopenharmony_ci height: 15px; 463e41f4b71Sopenharmony_ci margin-left: 450px; 464e41f4b71Sopenharmony_ci } 465e41f4b71Sopenharmony_ci .update-time { 466e41f4b71Sopenharmony_ci width: 480px; 467e41f4b71Sopenharmony_ci height: 28px; 468e41f4b71Sopenharmony_ci font-size: 20px; 469e41f4b71Sopenharmony_ci color: #A9A9A9; 470e41f4b71Sopenharmony_ci text-align: right; 471e41f4b71Sopenharmony_ci } 472e41f4b71Sopenharmony_ci .info-source { 473e41f4b71Sopenharmony_ci width: 450px; 474e41f4b71Sopenharmony_ci height: 28px; 475e41f4b71Sopenharmony_ci font-size: 20px; 476e41f4b71Sopenharmony_ci color: #A9A9A9; 477e41f4b71Sopenharmony_ci text-align: left; 478e41f4b71Sopenharmony_ci margin-left: 24px; 479e41f4b71Sopenharmony_ci } 480e41f4b71Sopenharmony_ci .circle-div { 481e41f4b71Sopenharmony_ci width: 12px; 482e41f4b71Sopenharmony_ci height: 12px; 483e41f4b71Sopenharmony_ci border-radius: 6px; 484e41f4b71Sopenharmony_ci } 485e41f4b71Sopenharmony_ci ``` 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ci - **index.js** 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci A **.js** file is used to implement interaction logic of your application. In the **.js** file of the home page, implement page switching and enable text content and progress bar color to change dynamically according to AQI values. 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci ``` 492e41f4b71Sopenharmony_ci // Import router and app modules. 493e41f4b71Sopenharmony_ci import router from '@system.router' 494e41f4b71Sopenharmony_ci import app from '@system.app' 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ci export default { 497e41f4b71Sopenharmony_ci data: { 498e41f4b71Sopenharmony_ci // Bind data. 499e41f4b71Sopenharmony_ci textColor1: '#00ff00', 500e41f4b71Sopenharmony_ci textColor2: '#00ff00', 501e41f4b71Sopenharmony_ci bgColor1: '#669966', 502e41f4b71Sopenharmony_ci bgColor2: '#669966', 503e41f4b71Sopenharmony_ci swiperPage: 0, 504e41f4b71Sopenharmony_ci percent1: 40, 505e41f4b71Sopenharmony_ci percent2: 90, 506e41f4b71Sopenharmony_ci iconUncheckedColor: '#262626', 507e41f4b71Sopenharmony_ci iconcheckedColor: '#ffffff', 508e41f4b71Sopenharmony_ci iconcheckedBR: '6px', 509e41f4b71Sopenharmony_ci src1: 'common/cloud_green.png', 510e41f4b71Sopenharmony_ci src2: 'common/cloud_green.png', 511e41f4b71Sopenharmony_ci airData: [{ 512e41f4b71Sopenharmony_ci location: 'Dongguan', 513e41f4b71Sopenharmony_ci airQuality: 'Good', 514e41f4b71Sopenharmony_ci detailData: 40 515e41f4b71Sopenharmony_ci }, { 516e41f4b71Sopenharmony_ci location: 'Shenzhen', 517e41f4b71Sopenharmony_ci airQuality: 'Polluted', 518e41f4b71Sopenharmony_ci detailData: 90 519e41f4b71Sopenharmony_ci }] 520e41f4b71Sopenharmony_ci }, 521e41f4b71Sopenharmony_ci onInit () { 522e41f4b71Sopenharmony_ci // Set the font, background color, and background image for different value ranges. 523e41f4b71Sopenharmony_ci if(this.airData[0].detailData > 100){ 524e41f4b71Sopenharmony_ci this.src1 = 'common/cloud_red.png'; 525e41f4b71Sopenharmony_ci this.textColor1 = '#ff0000'; 526e41f4b71Sopenharmony_ci this.bgColor1 = '#9d7462'; 527e41f4b71Sopenharmony_ci } else if(50 < this.airData[0].detailData && this.airData[0].detailData <= 100){ 528e41f4b71Sopenharmony_ci this.src1 = 'common/cloud_yellow.png'; 529e41f4b71Sopenharmony_ci this.textColor1 = '#ecf19a'; 530e41f4b71Sopenharmony_ci this.bgColor1 = '#9d9d62'; 531e41f4b71Sopenharmony_ci } 532e41f4b71Sopenharmony_ci if(this.airData[1].detailData > 100){ 533e41f4b71Sopenharmony_ci this.src2 = 'common/cloud_red.png'; 534e41f4b71Sopenharmony_ci this.textColor2 = '#ff0000'; 535e41f4b71Sopenharmony_ci this.bgColor2 = '#9d7462'; 536e41f4b71Sopenharmony_ci } else if(50 < this.airData[1].detailData && this.airData[1].detailData <= 100){ 537e41f4b71Sopenharmony_ci this.src2 = 'common/cloud_yellow.png'; 538e41f4b71Sopenharmony_ci this.textColor2 = '#ecf19a'; 539e41f4b71Sopenharmony_ci this.bgColor2 = '#9d9d62'; 540e41f4b71Sopenharmony_ci } 541e41f4b71Sopenharmony_ci if(this.selectedCityIndex){ 542e41f4b71Sopenharmony_ci this.swiperPage = this.selectedCityIndex; 543e41f4b71Sopenharmony_ci if(this.swiperPage == 0){ 544e41f4b71Sopenharmony_ci this.iconcheckedColor = '#ffffff'; 545e41f4b71Sopenharmony_ci this.iconUncheckedColor = '#262626'; 546e41f4b71Sopenharmony_ci }else{ 547e41f4b71Sopenharmony_ci this.iconcheckedColor = '#262626'; 548e41f4b71Sopenharmony_ci this.iconUncheckedColor = '#ffffff'; 549e41f4b71Sopenharmony_ci } 550e41f4b71Sopenharmony_ci } 551e41f4b71Sopenharmony_ci }, 552e41f4b71Sopenharmony_ci // Switch to the details page. 553e41f4b71Sopenharmony_ci openDetail () { 554e41f4b71Sopenharmony_ci router.replace({ 555e41f4b71Sopenharmony_ci uri: 'pages/detail/detail', 556e41f4b71Sopenharmony_ci params: {selectedCityIndex:this.swiperPage} 557e41f4b71Sopenharmony_ci }); 558e41f4b71Sopenharmony_ci }, 559e41f4b71Sopenharmony_ci // Exit the application. 560e41f4b71Sopenharmony_ci exitApp(){ 561e41f4b71Sopenharmony_ci console.log('start exit'); 562e41f4b71Sopenharmony_ci app.terminate(); 563e41f4b71Sopenharmony_ci console.log('end exit'); 564e41f4b71Sopenharmony_ci }, 565e41f4b71Sopenharmony_ci // Define the swiping event. Change the indicator dots when the user swipes the screen. 566e41f4b71Sopenharmony_ci swiperChange (e) { 567e41f4b71Sopenharmony_ci this.swiperPage = e.index; 568e41f4b71Sopenharmony_ci if(e.index == 0){ 569e41f4b71Sopenharmony_ci this.iconcheckedColor = '#ffffff'; 570e41f4b71Sopenharmony_ci this.iconUncheckedColor = '#262626'; 571e41f4b71Sopenharmony_ci }else{ 572e41f4b71Sopenharmony_ci this.iconcheckedColor = '#262626'; 573e41f4b71Sopenharmony_ci this.iconUncheckedColor = '#ffffff'; 574e41f4b71Sopenharmony_ci } 575e41f4b71Sopenharmony_ci } 576e41f4b71Sopenharmony_ci } 577e41f4b71Sopenharmony_ci ``` 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci 580