【小程序实战系列】电商平台源码及功能实现_import { fetchhome } from ‘(1)

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

"scope.userLocation": {
  "desc": "你的位置信息将用于小程序位置接口的效果展示"
}

}
}


### 4.2、home 首页



// home.js

import { fetchHome } from ‘…/…/services/home/home’;
import { fetchGoodsList } from ‘…/…/services/good/fetchGoods’;
import Toast from ‘tdesign-miniprogram/toast/index’;

Page({
data: {
imgSrcs: [],
tabList: [],
goodsList: [],
goodsListLoadStatus: 0,
pageLoading: false,
current: 1,
autoplay: true,
duration: 500,
interval: 5000,
navigation: { type: ‘dots’ },
},

goodListPagination: {
index: 0,
num: 20,
},

privateData: {
tabIndex: 0,
},

onShow() {
this.getTabBar().init();
},

onLoad() {
this.init();
},

onReachBottom() {
if (this.data.goodsListLoadStatus === 0) {
this.loadGoodsList();
}
},

onPullDownRefresh() {
this.init();
},

init() {
this.loadHomePage();
},

loadHomePage() {
wx.stopPullDownRefresh();

this.setData({
  pageLoading: true,
});
fetchHome().then(({ swiper, tabList }) => {
  this.setData({
    tabList,
    imgSrcs: swiper,
    pageLoading: false,
  });
  this.loadGoodsList(true);
});

},

tabChangeHandle(e) {
this.privateData.tabIndex = e.detail;
this.loadGoodsList(true);
},

onReTry() {
this.loadGoodsList();
},

async loadGoodsList(fresh = false) {
if (fresh) {
wx.pageScrollTo({
scrollTop: 0,
});
}

this.setData({ goodsListLoadStatus: 1 });

const pageSize = this.goodListPagination.num;
let pageIndex =
  this.privateData.tabIndex \* pageSize + this.goodListPagination.index + 1;
if (fresh) {
  pageIndex = 0;
}

try {
  const nextList = await fetchGoodsList(pageIndex, pageSize);
  this.setData({
    goodsList: fresh ? nextList : this.data.goodsList.concat(nextList),
    goodsListLoadStatus: 0,
  });

  this.goodListPagination.index = pageIndex;
  this.goodListPagination.num = pageSize;
} catch (err) {
  this.setData({ goodsListLoadStatus: 3 });
}

},

goodListClickHandle(e) {
const { index } = e.detail;
const { spuId } = this.data.goodsList[index];
wx.navigateTo({
url: /pages/goods/details/index?spuId=${spuId},
});
},

goodListAddCartHandle() {
Toast({
context: this,
selector: ‘#t-toast’,
message: ‘点击加入购物车’,
});
},

navToSearchPage() {
wx.navigateTo({ url: ‘/pages/goods/search/index’ });
},

navToActivityDetail({ detail }) {
const { index: promotionID = 0 } = detail || {};
wx.navigateTo({
url: /pages/promotion-detail/index?promotion_id=${promotionID},
});
},
});



// home.json
{
“navigationBarTitleText”: “首页”,
“onReachBottomDistance”: 10,
“backgroundTextStyle”: “light”,
“enablePullDownRefresh”: true,
“usingComponents”: {
“t-search”: “tdesign-miniprogram/search/search”,
“t-loading”: “tdesign-miniprogram/loading/loading”,
“t-swiper”: “tdesign-miniprogram/swiper/swiper”,
“t-swiper-item”: “tdesign-miniprogram/swiper/swiper-item”,
“t-swiper-nav”: “tdesign-miniprogram/swiper/swiper-nav”,
“t-image”: “/components/webp-image/index”,
“t-icon”: “tdesign-miniprogram/icon/icon”,
“t-toast”: “tdesign-miniprogram/toast/toast”,
“t-tabs”: “tdesign-miniprogram/tabs/tabs”,
“t-tab-panel”: “tdesign-miniprogram/tabs/tab-panel”,
“goods-list”: “/components/goods-list/index”,
“load-more”: “/components/load-more/index”
}
}



加载中...


/* home.wxss */

page {
box-sizing: border-box;
padding-bottom: calc(env(safe-area-inset-bottom) + 96rpx);
}

.t-tabs.t-tabs–top .t-tabs__scroll {
border-bottom: none !important;
}

.home-page-header {
background: linear-gradient(#fff, #f5f5f5);
}

.home-page-container {
background: #f5f5f5;
}

.home-page-container,
.home-page-header {
display: block;
padding: 0 24rpx;
}

.home-page-header .t-search__input-container {
border-radius: 32rpx !important;
height: 64rpx !important;
}

.home-page-header .t-search__input {
font-size: 28rpx !important;
color: rgb(116, 116, 116) !important;
}

.home-page-header .swiper-wrap {
margin-top: 20rpx;
}

.home-page-header .t-image__swiper {
width: 100%;
height: 300rpx;
border-radius: 10rpx;
}

.home-page-container .t-tabs {
background: #f5f5f5;
}

.home-page-container .t-tabs .t-tabs-nav {
background-color: transparent;
line-height: 80rpx;
font-size: 28rpx;
color: #333;
}

.home-page-container .t-tabs .t-tabs-scroll {
border: none !important;
}

/* 半个字 */
.home-page-container .tab.order-nav .order-nav-item.scroll-width {
min-width: 165rpx;
}
.home-page-container .tab .order-nav-item.active {
color: #fa550f !important;
}

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

0f !important;
}

[外链图片转存中…(img-cdVqiNr5-1715712808545)]
[外链图片转存中…(img-EzR8Ntuz-1715712808545)]

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值