当前位置:网站首页>[small program practice series] e-commerce platform source code and function implementation
[small program practice series] e-commerce platform source code and function implementation
2022-06-28 04:10:00 【Half body wind and snow】
author : Half body wind and snow
Previous section : What is wechat applet
Retail mall template
One 、 Business Introduction
The retail industry template applet is a classic single store version e-commerce applet , It covers the golden link process of e-commerce , From Commodities -> The shopping cart -> Settlement -> Orders, etc . The applet contains a total of 28 A full page , Cover the first page , Product details page , Personal center , After sales process and other basic pages . use mock Data display , Provides a complete display of retail products 、 Transaction and after-sales process . Page details :

The screenshot of the main page is as follows :








Two 、 Project composition
The retail industry template applet uses the basic JavaScript + WXSS + ESLint Build , Lower the threshold of use .
The project directory structure is as follows :

|-- mall-starter
|-- README.md
|-- app.js //JavaScrip file
|-- app.json // Project profile , Responsible for window color, etc
|-- app.wxss // similar CSS file
|-- components // Common component library
|-- config // Basic configuration
|-- custom-tab-bar // Customize tabbar
|-- model // mock data
|-- pages
| |-- cart // Shopping cart related pages
| |-- coupon // Coupon related pages
| |-- goods // Product related pages
| |-- home // home page
| |-- order // Order after sales related pages
| |-- promotion-detail // Campaign page
| |-- usercenter // Relevant pages of personal center and receiving address
|-- services // Request interface
|-- style // Common styles and iconfont
|-- utils // Tool library
3、 ... and 、 The data simulation
Retail applets use real interface data , Simulate back-end return logic , Show the complete shopping scene and shopping experience logic in the applet .
Four 、 The source code of the project
4.1、 Page routing and tabBar
{
"pages": [
"pages/home/home",
"pages/usercenter/index",
"pages/usercenter/person-info/index",
"pages/usercenter/address/list/index",
"pages/usercenter/address/edit/index",
"pages/goods/list/index",
"pages/goods/details/index",
"pages/goods/category/index",
"pages/goods/search/index",
"pages/goods/result/index",
"pages/cart/index",
"pages/order/order-confirm/index",
"pages/order/receipt/index",
"pages/order/pay-result/index",
"pages/order/order-list/index",
"pages/order/order-detail/index",
"pages/goods/comments/index",
"pages/order/apply-service/index",
"pages/order/after-service-list/index",
"pages/order/after-service-detail/index",
"pages/goods/comments/create/index",
"pages/coupon/coupon-list/index",
"pages/coupon/coupon-detail/index",
"pages/coupon/coupon-activity-goods/index",
"pages/promotion-detail/index",
"pages/order/fill-tracking-no/index",
"pages/order/delivery-detail/index",
"pages/order/invoice/index",
"pages/usercenter/name-edit/index"
],
"tabBar": {
"custom": true,
"color": "#666666",
"selectedColor": "#FF5F15",
"backgroundColor": "#ffffff",
"borderStyle": "black",
"list": [
{
"pagePath": "pages/home/home",
"text": " home page "
},
{
"pagePath": "pages/goods/category/index",
"text": " classification "
},
{
"pagePath": "pages/cart/index",
"text": " The shopping cart "
},
{
"pagePath": "pages/usercenter/index",
"text": " my "
}
]
},
"lazyCodeLoading": "requiredComponents",
"usingComponents": {
},
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "Weixin",
"navigationBarTextStyle": "black"
},
"sitemapLocation": "sitemap.json",
"permission": {
"scope.userLocation": {
"desc": " Your location information will be used to show the effect of the applet location interface "
}
}
}
4.2、home home page
// 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: ' Click Add to cart ',
});
},
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": " home page ",
"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.wxml -->
<view style="text-align: center" wx:if="{
{pageLoading}}">
<t-loading
theme="circular"
size="40rpx"
loading
t-class-indicator="t-class-indicator"
>
<span slot="text" class="loading-text"> Loading ...</span>
</t-loading>
</view>
<view class="home-page-header">
<view class="search" bind:tap="navToSearchPage">
<t-search
t-class-input="t-search__input"
t-class-input-container="t-search__input-container"
placeholder="iphone 13 Hot sale "
leftIcon=""
disabled
>
<t-icon
slot="left-icon"
prefix="wr"
name="search"
size="40rpx"
color="#bbb"
/>
</t-search>
</view>
<view class="swiper-wrap">
<t-swiper
wx:if="{
{imgSrcs.length > 0}}"
current="{
{current}}"
autoplay="{
{autoplay}}"
duration="{
{duration}}"
interval="{
{interval}}"
navigation="{
{navigation}}"
>
<t-swiper-item wx:for="{
{imgSrcs}}" wx:key="index">
<t-image src="{
{item.img}}" t-class="t-image__swiper" bind:tap="navToActivityDetail" />
</t-swiper-item>
</t-swiper>
</view>
</view>
<view class="home-page-container">
<t-tabs
t-class="t-tabs"
t-class-active="t-class-item"
t-class-track="t-class-track"
defaultValue="{
{0}}"
bind:change="tabChangeHandle"
>
<t-tab-panel
wx:for="{
{tabList}}"
wx:for-index="index"
wx:key="index"
label="{
{item.text}}"
value="{
{item.key}}"
/>
</t-tabs>
<goods-list
wr-class="goods-list-container"
goodsList="{
{goodsList}}"
bind:click="goodListClickHandle"
bind:addcart="goodListAddCartHandle"
/>
<load-more list-is-empty="{
{!goodsList.length}}" status="{
{goodsListLoadStatus}}" bind:retry="onReTry" />
<t-toast id="t-toast" />
</view>
/* 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;
}
/* Half a word */
.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;
}
.home-page-container .tab .bottom-line {
border-radius: 4rpx;
}
.home-page-container .tab .order-nav-item.active .bottom-line {
background-color: #fa550f !important;
}
.home-page-container .t-class-item {
color: #333333 !important;
font-size: 32rpx;
}
.home-page-container .t-class-track {
background-color: #fa4126 !important;
height: 6rpx !important;
border-radius: 4rpx !important;
width: 48rpx !important;
}
.t-tabs.t-tabs--top .t-tabs__item,
.t-tabs.t-tabs--bottom .t-tabs__item {
height: 86rpx !important;
}
.home-page-container .goods-list-container {
background: #f5f5f5 !important;
margin-top: 24rpx;
}
.t-class-indicator,
.loading-text {
color: #b9b9b9 !important;
}
Forget it , direct Source download
边栏推荐
- Building a server monitoring platform with telegraf influxdb grafana
- 僅用遞歸函數和棧操作逆序一個棧
- MSc 307 (88) (2010 FTPC code) Part 9 bedding test
- What are the password requirements for waiting insurance 2.0? What are the legal bases?
- Introversion, lying flat and midlife crisis
- ambari SSLError: Failed to connect. Please check openssl library versions.
- Introduction notes to machine learning
- How to write a software test report? Here comes the third party performance report template
- 利用 telegraf influxdb grafana 搭建服务器监控平台
- 数字电路学习笔记(二)
猜你喜欢
随机推荐
基于arm5718的Shell脚本参数传递的2种方法
English语法_形容词/副词3级 - 比较级
利用ELK 搭建日志分析系统(三)—— 安全认证
Understanding and learning of parental delegation mechanism
Using elk to build a log analysis system (I) -- component introduction
applicationContext. Getbeansoftype obtains the execution methods of all implementation classes under an interface or obtains the operation application scenarios such as implementation class objects. L
[MySQL] multi table connection query
使用tensorboard进行loss可视化
简单工厂模式
欧洲家具EN 597-1 跟EN 597-2两个阻燃标准一样吗?
Detailed explanation of iptables firewall rules and firewalld firewall rules
Building log analysis system with elk (II) -- deployment and installation
English语法_形容词/副词3级-比较级_常用短语
关于 SY8120I 的DC-DC的降压芯片的学习(12V降至3.3V)
A preliminary study of blackbody radiation
Several important physical concepts
C语言十进制与BCD码的相互转换
From zero to one, I will teach you to build a "search by text and map" search service (I)
Does the applet input box flash?
How to write a software test report? Here comes the third party performance report template









