商城首頁(yè)主要包含以下幾個(gè)部分
- 1.使用ion-slide實(shí)現(xiàn)首頁(yè)幻燈片颗祝;
- 2.使用ion-grid實(shí)現(xiàn)商品分類蓄愁;
- 3.使用ion-list實(shí)現(xiàn)商品列表嘱朽;
說(shuō)一下實(shí)現(xiàn)思路
- 1.先獲取網(wǎng)絡(luò)請(qǐng)求的數(shù)據(jù)轨帜,查看數(shù)據(jù)結(jié)構(gòu)转锈;
- 2.根據(jù)數(shù)據(jù)結(jié)構(gòu)來(lái)判斷需要展示的數(shù)據(jù),編寫(xiě)html;
- 3.調(diào)整界面樣式衔憨,編寫(xiě)scss叶圃;
準(zhǔn)備工作
開(kāi)始之前請(qǐng)到阿里開(kāi)源圖標(biāo)庫(kù)準(zhǔn)備首頁(yè)需要的小圖標(biāo),不想自己找的同學(xué)践图,在文章最后的交流群的群文件里有導(dǎo)出好的資源小圖標(biāo)掺冠,下載后直接放到項(xiàng)目的src/assets/icon/目錄中即可。
并在index.html的header節(jié)點(diǎn)中導(dǎo)入資源圖標(biāo)庫(kù)码党;
index.html
<link href="assets/icon/iconfont.css" rel="stylesheet">
詳細(xì)代碼如下:
home.ts
import { AppService, AppGlobal } from './../../app/app.service';
import { Component } from '@angular/core';
import { NavController, IonicPage } from 'ionic-angular';
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
slides: Array<any> = [];
categories: Array<any> = [];
products: Array<any> = [];
spinner1: boolean = true;
params = {
favoritesId: 2054400,
pageNo: 1,
pageSize: 20
}
constructor(public appService: AppService, public navCtrl: NavController) {
this.getSlides();
this.getCategories();
this.getProducts();
}
//獲取幻燈片
getSlides() {
var params = {
favoritesId: 2056439,
pageNo: 1,
pageSize: 5
}
this.appService.httpGet(AppGlobal.API.getProducts, params, rs => {
console.debug(rs);
this.slides = rs.data;
this.spinner1 = false;
})
}
//獲取分類
getCategories() {
this.appService.httpGet(AppGlobal.API.getCategories, { appTag: 'dress' }, rs => {
console.debug(rs);
this.categories = rs.data;
})
}
//獲取首頁(yè)推薦列表
getProducts() {
this.appService.httpGet(AppGlobal.API.getProducts, this.params, rs => {
console.debug(rs);
this.products = rs.data;
})
}
//商品詳情
goDetails(item) {
console.debug('go details...')
}
}
home.html
<ion-header>
<ion-navbar color="primary">
<ion-title>首頁(yè)</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-row *ngIf="spinner1">
<ion-col text-center>
<ion-spinner></ion-spinner>
</ion-col>
</ion-row>
<ion-slides>
<ion-slide *ngFor="let item of slides" (click)="goDetails(item)">
< img src="{{item.PictUrl}}" alt="">
<div class="cover"></div>
<span class="title">{{item.Title}}</span>
</ion-slide>
</ion-slides>
<div class="categories">
<ion-grid>
<ion-row wrap>
<ion-col text-center tappable col-3 *ngFor="let c of categories" (click)="goProductList(c)">
<i class="iconfont {{c.Icon}} icon"></i>
<span class="title">{{c.FavoritesTitle}}</span>
</ion-col>
</ion-row>
</ion-grid>
</div>
<ion-item-divider class="t-header" color="light"> 年會(huì)禮服2017年新款 </ion-item-divider>
<div class="product">
<ion-row wrap>
<ion-col tappable col-6 *ngFor="let p of products" (click)="goDetails(p)">
<img src="{{p.PictUrl}}" alt=""/>
<p>{{p.Title}}</p>
<div class="list-price buy">
<span class="price-new"><i>¥</i>{{p.ZkFinalPrice}}</span>
<i class="del">¥<span>{{p.ReservePrice}}</span></i>
</div>
</ion-col>
</ion-row>
</div>
</ion-content>
html.scss
page-home {
ion-slides {
height: 30%;
.cover {
position: absolute;
bottom: 0px;
width: 100%;
height: 20px;
background: linear-gradient(to right, #673743, #f9537d);
opacity: 0.6;
}
.title {
position: absolute;
bottom: 0px;
width: 90%;
height: 20px;
line-height: 20px;
font-size: 60%;
left: 5px;
text-align: center;
color: white;
}
}
.categories {
.title {
font-family: "黑體-簡(jiǎn)";
font-weight: 300;
color: #808080;
font-size: 80%;
display: block;
margin-top: 5px;
}
ion-row {
background-color: #efefef;
padding: 0px;
}
ion-col {
background-color: white;
/*border: 1px solid #efefef;*/
}
}
.icon {
border-radius: 100px;
color: white;
background-color: #f8285c;
font-size: 36px !important;
padding: 5px;
}
.c1 {
background-color: orangered;
}
.c2 {
background-color: blueviolet;
}
.c3 {
background-color: sandybrown;
}
.c4 {
background-color: slateblue;
}
.c5 {
background-color: orange;
}
.c6 {
background-color: dimgray;
}
.t-header {
font-family: "黑體-簡(jiǎn)";
font-weight: 300;
color: #f8285c;
border-left: 2px solid #f8285c;
border-top: 5px solid #efefef;
background: white;
}
.stores {
.title {
font-family: "黑體-簡(jiǎn)";
font-weight: 300;
color: #808080;
font-size: 80%;
display: block;
margin-top: 5px;
}
ion-row {
background-color: #efefef;
padding: 0px;
}
ion-col {
background-color: white;
border: 1px solid #efefef;
}
}
.product {
ion-row {
background-color: #efefef;
font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif;
padding-top: 3px;
ion-col {
position: relative;
background-color: white;
border: 2px solid #efefef;
border-radius: 2px;
padding: 0px;
p {
margin: 0px;
padding: 0px;
width: 100%;
font-size: 12px;
font-family: "黑體-簡(jiǎn)";
font-weight: 300;
color: #808080;
height: 26px;
line-height: 26px;
background: rgba(255, 255, 255, 0.8);
overflow: hidden;
text-indent: 5px;
}
}
}
.list-price {
width: 98%;
height: 26px;
line-height: 18px;
position: relative;
bottom: 0;
margin: 0 2%;
}
.price-new {
font-size: 18px;
color: #f8285c;
}
.list-price i {
font-style: normal;
font-size: 12px;
}
.del {
color: rgba(171, 171, 171, 1);
text-decoration: line-through;
margin-left: 2px;
}
.good-btn {
display: block;
position: absolute;
height: 16px;
line-height: 12px;
color: #f8285c;
font-size: 13px;
font-family: "黑體-簡(jiǎn)";
text-align: right;
top: 5px;
right: 2px;
}
.quan_img {
position: absolute;
width: 61px;
height: 55px;
z-index: 5;
right: 0;
top: 0;
cursor: pointer;
background: url(/assets/img/quan.png) no-repeat;
background-size: contain;
color: #fff;
}
.quan_img .num_money {
font-family: Arial;
font-size: 18px;
height: 40px;
left: 9px;
position: absolute;
text-align: center;
top: 14px;
width: 40px;
}
}
}
效果圖
4-1.png
下一講將講解?在ionic3中如何設(shè)計(jì)透明導(dǎo)航欄德崭。
完!