开发项目流程介绍 Headline | uniapp - 黑马优购
视频地址 01.项目介绍与项目文档_哔哩哔哩_bilibili P95-P192
视频中是用uni-app做的,我是用原生的小程序开发平台做的
目录
1 准备工作
1.1 头部信息
1.2 主页面
logs是自带的,后面没有进行开发,也可以删去logs这个页面
1.3 tabbar
需要用到这些图
然后在app.json中做如下配置
1.4 定义请求根路径
在app.js中定义全局变量base_url
2 首页
首页分为四个区域,自上而下依次是 搜索区域,轮播图区域,导航区域,楼层区域
导航区域以下全是楼层区域
2.1 轮播图接口
发get请求 https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata 不携带任何参数
图像的内容是image_src。点击相应的轮播图会跳转到指定的小程序位置(navigator_url)。其中提到的goods_detail是小程序的一个子页面
2.2 导航部分接口
发get请求 https://api-hmugo-web.itheima.net/api/public/v1/home/catitems 不携带任何参数
只有第一个导航点击后会跳到分类的主页面,其余点击后无效。如果你想让其他导航有效,那么修改后端端口就可以了
2.3 楼层区域接口
发get请求 https://api-hmugo-web.itheima.net/api/public/v1/home/floordata 不携带任何参数 请求结果如下
{
"message": [
{
"floor_title": {
"name": "时尚女装",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_title.png"
},
"product_list": [
{
"name": "优质服饰",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_1@2x.png",
"image_width": "232",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=服饰"
},
{
"name": "春季热门",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_2@2x.png",
"image_width": "233",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=热"
},
{
"name": "爆款清仓",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_3@2x.png",
"image_width": "233",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=爆款"
},
{
"name": "倒春寒",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_4@2x.png",
"image_width": "233",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=春季"
},
{
"name": "怦然心动",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_5@2x.png",
"image_width": "233",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=心动"
}
]
},
{
"floor_title": {
"name": "户外活动",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_title.png"
},
"product_list": [
{
"name": "勇往直前",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_1@2x.png",
"image_width": "232",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=户外"
},
{
"name": "户外登山包",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_2@2x.png",
"image_width": "273",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=登山包"
},
{
"name": "超强手套",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_3@2x.png",
"image_width": "193",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=手套"
},
{
"name": "户外运动鞋",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_4@2x.png",
"image_width": "193",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=运动鞋"
},
{
"name": "冲锋衣系列",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_5@2x.png",
"image_width": "273",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=冲锋衣"
}
]
},
{
"floor_title": {
"name": "箱包配饰",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_title.png"
},
"product_list": [
{
"name": "清新气质",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_1@2x.png",
"image_width": "232",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=饰品"
},
{
"name": "复古胸针",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_2@2x.png",
"image_width": "263",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=胸针"
},
{
"name": "韩版手链",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_3@2x.png",
"image_width": "203",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=手链"
},
{
"name": "水晶项链",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_4@2x.png",
"image_width": "193",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=水晶项链"
},
{
"name": "情侣表",
"image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_5@2x.png",
"image_width": "273",
"open_type": "navigate",
"navigator_url": "/pages/goods_list?query=情侣表"
}
]
}
],
"meta": {
"msg": "获取成功",
"status": 200
}
}
楼层区域点击后会跳转到子页面goods_list
2.4 首页源码
wxml
<!--pages/home/home.wxml-->
<!-- 搜索区域 -->
<view style="position: sticky;top:0;z-index: 999;">
<black_horse_search></black_horse_search>
</view>
<!-- 轮播图 -->
<swiper indicator-dots="true" autoplay="true" interval="3000" duration="1000" circular="true">
<swiper-item wx:for="{{ swiperList }}" wx:key="goods_id">
<navigator class="swiper_item_view" url="{{'/subpackage_goods_detail/goods_detail?goods_id=' + item.goods_id}}">
<image src="{{item.image_src}}" />
</navigator>
</swiper-item>
</swiper>
<!-- 导航区域 -->
<view class="nav-list">
<view class="nav-item" wx:for="{{ navList }}" wx:key="index">
<image src="{{item.image_src}}" class="nav-img" bindtap="nav_click_method" data-nav_name="{{item.name}}"/>
</view>
</view>
<!-- 楼层区域 -->
<view class="floor-list">
<view class="floor-item" wx:for="{{ floorList }}" wx:key="index" >
<!-- 楼层标题 -->
<image src="{{item.floor_title.image_src}}" class="floor-title" />
<view class="floor-img-box">
<!-- 楼层大图片盒子 -->
<view class="left-img-box">
<image src="{{ item.product_list[0].image_src }}" style="{{'width:' + item.product_list[0].image_width + 'rpx;'}}" mode="widthFix" bindtap="floor_click_method" data-url="{{ item.product_list[0].navigator_url }}"/>
</view>
<!-- 楼层小图片盒子 -->
<view class="right-img-box">
<image wx:for="{{ item.product_list }}" wx:for-item="item1" wx:for-index="index1" wx:key="index1" wx:if="{{index1 != 0}}" src="{{ item1.image_src }}" mode="widthFix" style="{{'width:' + item1.image_width + 'rpx;'}}" bindtap="floor_click_method" data-url="{{ item1.navigator_url }}"/>
</view>
</view>
</view>
</view>
wxss
/* pages/home/home.wxss */
/* 轮播图部分 */
swiper {
height:330rpx;
}
swiper .swiper_item_view,image {
width:100%;
height:100%
}
/* 导航部分 */
.nav-list {
display:flex;
justify-content: space-around;
margin:15px 0;
}
.nav-list .nav-img {
width: 128rpx;
height:140rpx;
}
/* 楼层部分 */
.floor-title {
height:60rpx;
width:100%;
display:flex;
}
.right-img-box {
display:flex;
flex-wrap:wrap;
justify-content:space-around;
padding:0px;
}
.floor-img-box {
display:flex;
padding-left:10rpx;
}
js
// pages/home/home.js
import {createStoreBindings} from 'mobx-miniprogram-bindings'
import {store} from '../../store/store.js'
const App = getApp()
Page({
// 楼层部分点击
floor_click_method(e) {
wx.navigateTo({url:'/subpackage_goods_list/goods_list?' + e.target.dataset.url.split('?')[1]})
},
// 获取楼层区域信息
get_floorList() {
wx.request({
url:App.base_url + '/api/public/v1/home/floordata',
method:'GET',
success:(val) => {
this.setData({floorList:val.data.message})
},
fail:() => {
console.log('获取楼层失败')
wx.showToast({
title:'获取楼层失败',
icon:'error',
duration:2000
})
}
})
},
// 导航部分点击
nav_click_method(e) {
if (e.target.dataset.nav_name == "分类") {
wx.switchTab({url:'/pages/category/category'})
}
},
// 获取导航部分数据
get_navList() {
wx.request({
url:App.base_url + '/api/public/v1/home/catitems',
method:'GET',
success:(val) => {
this.setData({navList:val.data.message})
},
fail:() => {
console.log('获取主页导航数据失败')
wx.showToast({
title:'获取主页导航数据失败',
icon:'error',
duration:2000
})
}
})
},
// 获取轮播图数据
get_swiperList() {
wx.request({
url:App.base_url + '/api/public/v1/home/swiperdata',
// url:'http://127.0.0.1:8000/api/public/v1/home/swiperdata/',
method:'GET',
success:(val) => {
this.setData({swiperList:val.data.message})
},
fail:() => {
console.log('获取轮播图失败')
wx.showToast({
title:'获取轮播图失败',
icon:'error',
duration:2000
})
}
})
},
/**
* 页面的初始数据
*/
data: {
swiperList:[],
navList:[],
floorList:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.storeBindings = createStoreBindings(this,{
store,
actions:['set_cart_tabBar_badge']
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
// 获取轮播图数据
this.get_swiperList()
// 获取主页导航部分数据
this.get_navList()
// 获取主页楼层部分数据
this.get_floorList()
// 设置购物车tabBar上的徽标
this.set_cart_tabBar_badge()
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})