微信小程序实战(电商项目)

简介: 微信小程序实战(电商项目)

上一篇简单的写了微信小程序实现图书查询功能,这一篇开始实战做一个电商项目实战。

小程序端业务功能代码实现

1.项目整体搭建

1.1 创建小程序项目miniprogram-mall

网络异常,图片无法展示
|

1.2 导入矢量图标

1.在阿里云矢量库选择项目中需要的图标进行导入

网络异常,图片无法展示
|

2.创建styles/iconfont.wxss文件,粘贴复制的图标文件代码

@font-face {
  font-family: "iconfont"; /* Project id 2848128 */
  src: url('//at.alicdn.com/t/font_2848128_mchidofoxgo.woff2?t=1643706746390') format('woff2'),
       url('//at.alicdn.com/t/font_2848128_mchidofoxgo.woff?t=1643706746390') format('woff'),
       url('//at.alicdn.com/t/font_2848128_mchidofoxgo.ttf?t=1643706746390') format('truetype');
}
.iconfont {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.icon-search:before {
  content: "\e648";
}
.icon-quanbudingdan:before {
  content: "\e600";
}
.icon-daifukuan:before {
  content: "\e601";
}
.icon-tuikuan:before {
  content: "\e8ab";
}
.icon-daishouhuo:before {
  content: "\e640";
}
.icon-home:before {
  content: "\e69b";
}
.icon-shoucang:before {
  content: "\e666";
}
.icon-kefufenxiermaikefu:before {
  content: "\e889";
}
.icon-chakantiezifenxiang:before {
  content: "\e660";
}
.icon-weibiaoti2fuzhi08:before {
  content: "\e625";
}
.icon-dingdan:before {
  content: "\e897";
}
.icon-gouwuche:before {
  content: "\e899";
}
.icon-fukuantongzhi:before {
  content: "\e60c";
}
.icon-icon-:before {
  content: "\e701";
}
.icon-shoucang1:before {
  content: "\e8c6";
}

3.全局导入

/**app.wxss**/
/* 全局引入iconfont */
@import "./styles/iconfont.wxss"

4.index页面测试

<!--index.wxml-->
<View>
  <View class="iconfont icon-daifukuan">全局图标引入</View>
  <View class="iconfont icon-search">全局图标引入</View>
  <View class="iconfont icon-daifukuan">全局图标引入</View>
</View>

5.效果

网络异常,图片无法展示
|

1.3 底部菜单tabbar实现

设置底部菜单

{
  "pages":[
    "pages/index/index",
    "pages/category/index",
    "pages/cart/index",
    "pages/my/index",
    "pages/logs/logs"
  ],
  "tabBar": {
    "color": "#999",
    "selectedColor": "#FF5700",
    "backgroundColor": "#fafafa",
    "list": [{
      "pagePath": "pages/index/index",
      "text": "首页",
      "iconPath": "icons/_home.png",
      "selectedIconPath": "icons/home.png"
    },{
      "pagePath": "pages/category/index",
      "text": "分类",
      "iconPath": "icons/_category.png",
      "selectedIconPath": "icons/category.png"
    },{
      "pagePath": "pages/cart/index",
      "text": "购物车",
      "iconPath": "icons/_cart.png",
      "selectedIconPath": "icons/cart.png"
    },{
      "pagePath": "pages/my/index",
      "text": "我的",
      "iconPath": "icons/_my.png",
      "selectedIconPath": "icons/my.png"
    }]
  },
  "window":{
    "backgroundTextStyle":"light",
    "navigationBarBackgroundColor": "#FF5700",
    "navigationBarTitleText": "微信小程序电商实例",
    "navigationBarTextStyle":"white"
  },
  "style": "v2",
  "sitemapLocation": "sitemap.json"
}

测试:

网络异常,图片无法展示
|

1.4初始化全局样式设置

/* 初始化全局样式 */
page,view,text,swiper,swiper-item,image,navigator{
  padding:0;
  margin: 0;
  box-sizing: border-box;
}

全局变量定义 设置主题颜色,字体大小等

/* 全局变量定义 设置主题颜色,字体大小等 */
page{
  /* 主题颜色 */
  --themeColor:#FF5700;
  /* 字体大小 rpx自适应大小 */
  font-size:28rpx;
}

使用变量var

view{
  color:var(--themeColor);
}

导航栏背景颜色和文字颜色设置

"window": {
    "backgroundTextStyle": "light",
    "navigationBarBackgroundColor": "#FF5700",
    "navigationBarTitleText": "java1234商城",
    "navigationBarTextStyle": "white"
 }

1.5搜索框自定义组件实现

因为后面多个页面会用到搜索框,考虑到搜索框的重用性因此做成自定义组件,其他页面需要使用时直接引入即可。

1.创建components/SearchBar 页面

网络异常,图片无法展示
|

<!--components/SearchBar/SearchBar.wxml-->
<view>搜索框</view>

2.index引入SearchBar

"usingComponents": {
    "SearchBar":"/components/SearchBar/SearchBar"
}
<!--index.wxml  使用SearchBar-->
<View>
  <View class="iconfont icon-daifukuan">全局图标引入</View>
  <View class="iconfont icon-search">全局图标引入</View>
  <View class="iconfont icon-daifukuan">全局图标引入</View>
</View>
<SearchBar></SearchBar>

3.测试:

网络异常,图片无法展示
|

1.6完善SearchBar.wxml搜索框组件

1.搜索页面SearchBar.wxml

<view class="search_bar">
  <navigator url="/pages/search/index" open-type="navigate">
    <icon type="search" size="16"></icon>搜索
  </navigator>
</view>

2.搜索组件样式设置

/* components/SearchBar/SearchBar.wxss */
.search_bar{
  height: 90rpx;
  padding: 10rpx;
  background-color: var(--themeColor);
}
.search_bar navigator{
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #fff;
  border-radius: 15rpx;
  color: #666;
}
.search_bar navigator icon{
  padding-right: 5rpx;
}

修改index.wxml

<!--index.wxml-->
<view>
  <SearchBar></SearchBar>
</view>

测试:

网络异常,图片无法展示
|

下一篇 springboot后端项目搭建

相关文章
|
2月前
|
小程序 前端开发
微信小程序商城,微信小程序微店 【毕业设计参考项目】
文章推荐了一个微信小程序商城项目作为毕业设计参考,该项目在Github上获得18.2k星,提供了详细的使用教程和前端页面实现,适合学习微信小程序开发和作为毕业设计项目。
微信小程序商城,微信小程序微店 【毕业设计参考项目】
|
2月前
|
小程序
关于我花了一个星期学习微信小程序开发、并且成功开发出一个商城项目系统的心得体会
这篇文章是作者关于学习微信小程序开发并在一周内成功开发出一个商城项目系统的心得体会,分享了学习基础知识、实战项目开发的过程,以及小程序开发的易上手性和开发周期的简短。
关于我花了一个星期学习微信小程序开发、并且成功开发出一个商城项目系统的心得体会
|
3月前
|
监控 小程序 安全
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(2)
小程序提供便捷的鲜花选购和配送服务,汇聚全球优质鲜花品种,确保新鲜送达。用户可轻松挑选花束,享受个性化配送,并通过地图功能查看配送位置。此外,物流功能实时更新,保证鲜花安全快速到达。代码示例展示了地图和物流信息的页面布局与交互实现。 ### 配送与物流功能亮点 1. **地图功能**:使用`map.wxml`, `map.wxss`, 和 `map.js` 实现定位与导航,确保精准配送。 2. **物流追踪**:通过`logistics.wxml`, `logistics.wxss`, 和 `logistics.js` 显示详细物流状态,提供流畅的用户体验。
66 1
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(2)
|
2月前
|
人工智能 搜索推荐 安全
从零到一:微信机器人开发的实战心得
从零到一:微信机器人开发的实战心得
162 2
|
3月前
|
小程序 安全 搜索推荐
【微信小程序开发实战项目】——个人中心页面的制作
本文介绍了如何设计和实现一个网上花店的微信小程序,包括个人中心、我的订单和我的地址等功能模块。个人中心让用户能够查看订单历史、管理地址和与客服互动。代码示例展示了`own.wxml`、`own.wxss`和`own.js`文件,用于构建个人中心界面,包括用户信息、订单链接、收藏、地址、客服和版本信息。我的订单部分展示了订单详情,包括商品图片、名称、销量、价格和订单状态,用户可以查看和管理订单。我的地址功能允许用户输入和编辑收货信息,包括联系人、性别、电话、城市和详细地址。每个功能模块都附有相应的WXML和WXSS代码,以及简洁的样式设计。
145 0
【微信小程序开发实战项目】——个人中心页面的制作
|
3月前
|
小程序 安全 搜索推荐
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(3)
这是一篇关于微信小程序开发的文章摘要,作者介绍了如何创建一个网上花店小程序,旨在提供便捷的购花体验。小程序包含鲜花分类功能,允许用户按品种、颜色和用途筛选,确保快速找到合适的鲜花。它还提供了配送服务,保证鲜花的新鲜度。文章展示了`cash.wxml`、`cash.wxss`和`cash.js`的部分代码,用于实现分类和商品展示,以及`qin.wxml`、`qin.wxss`和`qin.js`,涉及商品详情和购买付款流程。代码示例展示了商品列表渲染和交互逻辑,包括页面跳转、数据传递和点击事件处理。文章最后提到了购买付款界面,强调了安全和便捷的支付体验。
96 0
【微信小程序开发实战项目】——如何制作一个属于自己的花店微信小程序(3)
|
3月前
|
小程序 开发者
uniapp实战 —— 开发微信小程序的调试技巧
uniapp实战 —— 开发微信小程序的调试技巧
310 1
|
3月前
|
前端开发 小程序
【微信小程序-原生开发】实用教程20 - 生成海报(实战范例为生成活动海报,内含生成指定页面的小程序二维码,保存图片到手机,canvas 系列教程)
【微信小程序-原生开发】实用教程20 - 生成海报(实战范例为生成活动海报,内含生成指定页面的小程序二维码,保存图片到手机,canvas 系列教程)
368 0
|
3月前
|
小程序
【微信小程序】实战案例 -- 向订阅用户发送消息(范例:报名提醒)
【微信小程序】实战案例 -- 向订阅用户发送消息(范例:报名提醒)
199 0
|
3月前
|
小程序 前端开发
【微信小程序-原生开发】TDesign 实战模板——聊天气泡
【微信小程序-原生开发】TDesign 实战模板——聊天气泡
64 0

热门文章

最新文章