TDesign电商小程序模板解析01-自定义底部导航栏

news2024/10/6 10:40:51

目录

  • 1 电商模板安装
  • 2 创建页面
  • 3 创建底部导航条
  • 总结

我们已经利用了两篇文章解读了一下微信小程序带的TDesign模板
TDesign小程序组件库01
TDesign小程序组件库02

入门一款前端组件库,如果挨个去看每个组件的用法未免比较枯燥,即使看懂了其实离实际开发还是比较远的。为了快速的入门,其实带着一个实际的案例去学习就比较快了。

通常小程序比较常见的场景是电商,一般是作为商家一个私域运营的工具。好在已经提供了一套电商模板,我们来逐步拆解一下。

1 电商模板安装

在我们启动了微信开发者工具后,选择不使用云服务的时候,就可以看到这套电商模板
在这里插入图片描述
安装后就可以看到具体的文件的目录
在这里插入图片描述

2 创建页面

学习一套模板可以阅读代码,也可以创建一个空项目复刻一下。源代码我们在复刻的时候边做边看,这样可以比较好的梳理一下他的思路。

开发小程序第一个步骤是搭建页面,我们可以按照底部导航栏先进行搭建。底部导航栏目前有四个菜单,分别是首页、分类、购物车和个人中心。

那么就先搭建这四个一级页面,选中pages,右键新建文件夹

在这里插入图片描述
输入home
在这里插入图片描述
然后选中home,新建Page
在这里插入图片描述
输入home
在这里插入图片描述
它会自动生成四个页面分别是home.wxml、home.js、home.wxss、home.json
在这里插入图片描述
然后创建分类页面,分类页面是在商品页面下的二级页面,结构如下
在这里插入图片描述
之后建立购物车cart、个人中心usercenter页面
在这里插入图片描述
页面创建好之后,页面的路径会自动的注册到app.json里

{
    "pages": [
        "pages/home/home",
        "pages/goods/category/index",
        "pages/usercenter/index",
        "pages/cart/index"
    ],
    "usingComponents": {},
    "window": {
        "backgroundTextStyle": "light",
        "navigationBarBackgroundColor": "#f6f6f6",
        "backgroundColor": "#f6f6f6",
        "navigationBarTitleText": "TDesign",
        "navigationBarTextStyle": "black"
    },
    "sitemapLocation": "sitemap.json"
}

3 创建底部导航条

我们底部导航条作为一级页面,可以使用微信自带的tabBar组件,配置方法是直接在app.json文件里增加对应的属性。导航条可以使用图标+文字的方案,图标有两种一种是选中状态,一种是未选中状态。

"tabBar": {
    "custom": true,
    "color": "#666666",
    "selectedColor": "#FF5F15",
    "backgroundColor": "#ffffff",
    "borderStyle": "black",
    "list": [
      {
        "pagePath": "pages/home/home",
        "text": "首页"
      },
      {
        "pagePath": "pages/goods/category/index",
        "text": "分类"
      },
      {
        "pagePath": "pages/cart/index",
        "text": "购物车"
      },
      {
        "pagePath": "pages/usercenter/index",
        "text": "我的"
      }
    ]
  }

把这个配置添加到app.json发现底部菜单栏并没有出现,原因是现在我们设置了cutom为true,表示我们要自己定义菜单栏的表现形式,因此需要在根目录创建一个custom-tab-bar文件夹
在这里插入图片描述

在文件夹下建立如下文件
在这里插入图片描述

在index.json里输入如下配置

{
  "component": true,
  "usingComponents": {
    "t-tab-bar": "tdesign-miniprogram/tab-bar/tab-bar",
    "t-tab-bar-item": "tdesign-miniprogram/tab-bar-item/tab-bar-item",
    "t-icon": "tdesign-miniprogram/icon/icon"
  }
}

component为true表示这是一个自定义组件,下边引入了三个框架自带组件

在data.js里输入如下代码

export default [
  {
    icon: 'home',
    text: '首页',
    url: 'pages/home/home',
  },
  {
    icon: 'sort',
    text: '分类',
    url: 'pages/goods/category/index',
  },
  {
    icon: 'cart',
    text: '购物车',
    url: 'pages/cart/index',
  },
  {
    icon: 'person',
    text: '个人中心',
    url: 'pages/usercenter/index',
  },
];

这里导出了一个数组,数组里的元素是菜单的具体配置,包括图标、文字名称和路径,但这里icon并没有指名路径,是使用框架自带的图标

剩下的配置我们就不解读了,官方已经编写好了,我们只需要复用他的代码就可以

index.js

import TabMenu from './data';
Component({
  data: {
    active: 0,
    list: TabMenu,
  },

  methods: {
    onChange(event) {
      this.setData({ active: event.detail.value });
      wx.switchTab({
        url: this.data.list[event.detail.value].url.startsWith('/')
          ? this.data.list[event.detail.value].url
          : `/${this.data.list[event.detail.value].url}`,
      });
    },

    init() {
      const page = getCurrentPages().pop();
      const route = page ? page.route.split('?')[0] : '';
      const active = this.data.list.findIndex(
        (item) =>
          (item.url.startsWith('/') ? item.url.substr(1) : item.url) ===
          `${route}`,
      );
      this.setData({ active });
    },
  },
});

index.wxml

<t-tab-bar
 value="{{active}}"
 bindchange="onChange"
 split="{{false}}"
>
	<t-tab-bar-item
	 wx:for="{{list}}"
	 wx:for-item="item"
	 wx:for-index="index"
	 wx:key="index"
	>
		<view class="custom-tab-bar-wrapper">
			<t-icon prefix="wr" name="{{item.icon}}" size="48rpx" />
			<view class="text">{{ item.text }}</view>
		</view>
	</t-tab-bar-item>
</t-tab-bar>


index.wxss

.custom-tab-bar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.custom-tab-bar-wrapper .text {
  font-size: 20rpx;
}

实际我们自己做的时候就是把这些代码依次的复制到对应的文件里,复制过去发现图标显示不了,需要再引入一个样式文件,在根目录建一个style文件夹,创建一个iconfont的wxss文件
在这里插入图片描述
样式文件的内容

@font-face {
    font-family: 'wr';
    src: url('https://cdn3.codesign.qq.com/icons/gqxWyZ1yMJZmVXk/Yyg5Zp2LG8292lK/iconfont.woff?t=cfc62dd36011e60805f5c3ad1a20b642')
      format('woff2');
  }
  
  .wr {
    font-family: 'wr' !important;
    font-size: 32rpx;
    font-style: normal;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  .wr-deliver:before {
    content: '\e033';
  }
  .wr-indent_close:before {
    content: '\e041';
  }
  .wr-edit:before {
    content: '\e002';
  }
  .wr-succeed:before {
    content: '\e00d';
  }
  .wr-goods_return:before {
    content: '\e03c';
  }
  .wr-wallet:before {
    content: '\e051';
  }
  .wr-package:before {
    content: '\e047';
  }
  .wr-comment:before {
    content: '\e037';
  }
  .wr-exchang:before {
    content: '\e03e';
  }
  .wr-credit_card:before {
    content: '\e035';
  }
  .wr-service:before {
    content: '\e04a';
  }
  .wr-shop_bag:before {
    content: '\e02a';
  }
  .wr-goods_refund:before {
    content: '\e03d';
  }
  .wr-check:before {
    content: '\e053';
  }
  .wr-wechat:before {
    content: '\e065';
  }
  .wr-cartAdd:before {
    content: '\e05d';
  }
  .wr-home:before {
    content: '\e020';
  }
  .wr-person:before {
    content: '\e02c';
  }
  .wr-cart:before {
    content: '\e023';
  }
  .wr-location:before {
    content: '\e016';
  }
  .wr-arrow_forward:before {
    content: '\e012';
  }
  .wr-close:before {
    content: '\e021';
  }
  .wr-search:before {
    content: '\e011';
  }
  .wr-clear_filled:before {
    content: '\e027';
  }
  .wr-arrow_drop_up:before {
    content: '\e071';
  }
  .wr-arrow_drop_down:before {
    content: '\e070';
  }
  .wr-filter:before {
    content: '\e038';
  }
  .wr-copy:before {
    content: '\e001';
  }
  .wr-arrow_back:before {
    content: '\e003';
  }
  .wr-add_circle:before {
    content: '\e004';
  }
  .wr-Download:before {
    content: '\e006';
  }
  .wr-map:before {
    content: '\e007';
  }
  .wr-store:before {
    content: '\e008';
  }
  .wr-movie:before {
    content: '\e00a';
  }
  .wr-done:before {
    content: '\e00b';
  }
  .wr-minus:before {
    content: '\e00c';
  }
  .wr-list:before {
    content: '\e00e';
  }
  .wr-expand_less:before {
    content: '\e00f';
  }
  .wr-person_add:before {
    content: '\e010';
  }
  .wr-Photo:before {
    content: '\e013';
  }
  .wr-preview:before {
    content: '\e014';
  }
  .wr-remind:before {
    content: '\e015';
  }
  
  .wr-info:before {
    content: '\e017';
  }
  .wr-expand_less_s:before {
    content: '\e018';
  }
  .wr-arrow_forward_s:before {
    content: '\e019';
  }
  .wr-expand_more_s:before {
    content: '\e01a';
  }
  .wr-share:before {
    content: '\e01d';
  }
  .wr-notify:before {
    content: '\e01e';
  }
  .wr-add:before {
    content: '\e01f';
  }
  .wr-Home:before {
    content: '\e020';
  }
  .wr-delete:before {
    content: '\e022';
  }
  .wr-error:before {
    content: '\e025';
  }
  .wr-sort:before {
    content: '\e028';
  }
  .wr-sort_filled:before {
    content: '\e029';
  }
  .wr-shop_bag_filled:before {
    content: '\e02b';
  }
  
  .wr-person_filled:before {
    content: '\e02d';
  }
  .wr-cart_filled:before {
    content: '\e02e';
  }
  .wr-home_filled:before {
    content: '\e02f';
  }
  .wr-add_outline:before {
    content: '\e030';
  }
  
  .wr-compass:before {
    content: '\e034';
  }
  .wr-goods_exchange:before {
    content: '\e03a';
  }
  .wr-group_buy:before {
    content: '\e03b';
  }
  .wr-group:before {
    content: '\e03f';
  }
  .wr-indent_goods:before {
    content: '\e040';
  }
  .wr-help:before {
    content: '\e042';
  }
  .wr-group_takeout:before {
    content: '\e043';
  }
  .wr-label:before {
    content: '\e044';
  }
  .wr-indent_wating:before {
    content: '\e045';
  }
  .wr-member:before {
    content: '\e046';
  }
  
  .wr-scanning:before {
    content: '\e04b';
  }
  .wr-tv:before {
    content: '\e04d';
  }
  .wr-to_top:before {
    content: '\e04f';
  }
  .wr-visibility_off:before {
    content: '\e050';
  }
  .wr-error-1:before {
    content: '\e052';
  }
  
  .wr-arrow_right:before {
    content: '\e054';
  }
  .wr-arrow_left:before {
    content: '\e056';
  }
  .wr-picture_filled:before {
    content: '\e057';
  }
  .wr-navigation:before {
    content: '\e058';
  }
  .wr-telephone:before {
    content: '\e059';
  }
  .wr-indent_time:before {
    content: '\e05c';
  }
  .wr-cart_add:before {
    content: '\e05d';
  }
  .wr-classify:before {
    content: '\e060';
  }
  .wr-place:before {
    content: '\e063';
  }
  .wr-wechat_pay:before {
    content: '\e064';
  }
  .wr-security:before {
    content: '\e066';
  }
  .wr-alarm:before {
    content: '\e067';
  }
  .wr-person-1:before {
    content: '\e068';
  }
  .wr-open_in_new:before {
    content: '\e069';
  }
  .wr-uncheck:before {
    content: '\e06b';
  }
  .wr-thumb_up:before {
    content: '\e06c';
  }
  .wr-thumb_up_filled:before {
    content: '\e06d';
  }
  .wr-star:before {
    content: '\e06e';
  }
  .wr-star_filled:before {
    content: '\e06f';
  }
  .wr-cards:before {
    content: '\e072';
  }
  .wr-picture_error_filled:before {
    content: '\e076';
  }
  .wr-discount:before {
    content: '\e077';
  }
  

然后需要在app.wxss里引入

@import 'style/iconfont.wxss';

一切配置好之后我们就把底部导航栏制作好了

总结

我们本篇带着大家搭建了一下TDesign电商模板的底部导航条功能,模板是使用自定义组件进行了搭建,还引入了自定义样式文件,稍稍有一点复杂,可以照着教程自己实验一下。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/663502.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

从零开始 Spring Boot 44:Test

从零开始 Spring Boot 44&#xff1a;Test 图源&#xff1a;简书 (jianshu.com) 本篇文章我们讨论如何在 Spring 项目中编写测试用例。 当前使用的是 Spring 6.0&#xff0c;默认集成 JUnit 5。 依赖 Spring Boot 的测试功能需要以下依赖&#xff1a; <dependency><…

数据中心机柜PDU应该怎么选?

数据中心是国家确定的“新基建”七大领域之一。数据中心在国民经济和社会发展中所起的作用越来越重要&#xff0c;数据中心已经成为了各行各业的关键基础设施&#xff0c;为经济转型升级提供了重要支撑。在庞杂的数据中心&#xff0c;服务器和交换器担负着传输数据的重要责任&a…

【论文阅读-人机交互】通过用户参与来缓解人工智能决策中的知识失衡问题

Title: Mitigating knowledge imbalance in AI-advised decision-making through collaborative user involvement From: International Journal of Human - Computer Studies Link: https://doi.org/10.1016/j.ijhcs.2022.102977 目录 1 绪论2 方法2.1 假设2.2. 实验任务及研究…

【单片机】STM32F103C8T6 最小系统板原理图

STM32F103C8T6是一款基于ARM Cortex-M3内核的32位微控制器&#xff0c;由STMicroelectronics&#xff08;ST&#xff09;公司生产。它是STMicroelectronics的STM32系列微控制器中的一员&#xff0c;被广泛应用于嵌入式系统和电子设备中。 STM32F103C8T6单片机的主要特点和资源…

点云深度学习系列博客(七): 针对点云的数据增强技术

好长时间不更新博客了&#xff0c;入职以后突然就变忙了&#xff0c;确实有心无力。最近做一个点云数据增强的项目&#xff0c;搞了一个简单的前期调研&#xff0c;趁着最近几天不太忙&#xff0c;凑一篇博客出来&#xff0c;保一下博客专家资格... 一. 简介 我们在利用深度学…

TDesign电商小程序模板解析02-首页功能

目录 1 home.json2 goods-list组件3 goods-card组件总结 上一篇我们搭建了底部的导航条&#xff0c;这一篇来拆解一下首页的功能。首页有如下功能 可以进行搜索显示轮播图横向可拖动的页签图文卡片列表 1 home.json 因为是要使用组件库的组件搭建页面&#xff0c;自然是先需要…

Git第二章、多人协作

一、多人协作一 目前&#xff0c;我们所完成的工作如下&#xff1a; • 基本完成 Git 的所有本地库的相关操作&#xff0c;git基本操作&#xff0c;分支理解&#xff0c;版本回退&#xff0c;冲突解决等等 • 申请码云账号&#xff0c;将远端信息clone到本地&#xff0c;以及推…

简单认识Nginx网络服务

文章目录 一、简介1、概括2、Nginx和Apache的差异3、Nginx优于Apache的优点 二、编译安装nginx 服务1、在线安装nginx2、 nginx编译安装&#xff08;1&#xff09;、关闭防火墙&#xff0c;将安装nginx所需软件包传到/opt目录下&#xff08;2&#xff09;、#nginx的配置及运行需…

基于分时电价和蓄电池控制策略用电优化研究(matlab代码)

目录 1 主要内容 温控负荷模型 蓄电池模型 2 部分代码 3 程序结果 4 下载链接 点击直达&#xff01; 1 主要内容 该程序复现《基于需求侧家庭能量管理系统用电优化研究》中第三章模型&#xff0c;题目是《基于分时电价和蓄电池控制策略用电优化研究》&#xff0c;该部…

Spring Boot初阶篇笔记

SpringBoot笔记 SpringBoot官方文档 一、SpringBoot的常用注解 ConfigurationProperties、PropertySource、ImportResource的区别 1.ConfigurationProperties: ConfigurationProperties:告诉SpringBoot将本类中的所有属性与配置文件中的相关属性进行绑定; 如&#xff1a;C…

Linux权限维持方法论

Linux权限维持方法论 1.创建超级用户2.SUID后门权限维持3.Strace监听后门4.rookit后门 1.创建超级用户 例如&#xff1a; 创建一个用户名guest&#xff0c;密码123456的root用户 useradd -p openssl passwd -1 -salt salt 123456 guest -o -u 0 -g root -G root -s /bin/bas…

【C语言初阶】带你玩转C语言中的数组,并逐步实现冒泡排序,三子棋,扫雷

君兮_的个人主页 勤时当勉励 岁月不待人 C/C 游戏开发 数组的使用 前言一维数组1.一维数组的定义数组的分类 2.数组的初始化第一种越界情况 3.数组的使用数组的下标&#xff1a;第二种越界情况 4.数组在内存中的存储 二维数组1.二维数组的创建2.二维数组的初始化3.二维数组的…

vue3新特性与vue2的不同点对比

前端必备工具推荐网站(免费图床、API和ChatAI等实用工具): http://luckycola.com.cn/ 一、vue3是什么? Vue 是一款用于构建用户界面的 JavaScript 框架。它基于标准 HTML、CSS 和 JavaScript 构建&#xff0c; 并提供了一套声明式的、组件化的编程模型&#xff0c;帮助你高效…

计算机网络管理-实验4(三) 使用Wireshark 抓取MIB-2中sysUpTime对象的SNMP报文管理信息结构

⬜⬜⬜ &#x1f430;&#x1f7e7;&#x1f7e8;&#x1f7e9;&#x1f7e6;&#x1f7ea;(*^▽^*)欢迎光临 &#x1f7e7;&#x1f7e8;&#x1f7e9;&#x1f7e6;&#x1f7ea;&#x1f430;⬜⬜⬜ ✏️write in front✏️ &#x1f4dd;个人主页&#xff1a;陈丹宇jmu &am…

【win11+Visual Studio 2019 配置 PCL 1.12.1 的经验总结分享】

点云pc库的下载与安装参考另外一篇文章&#xff0c;链接&#xff1a; https://blog.csdn.net/weixin_47869094/article/details/131270772?spm1001.2014.3001.5501 各种教程里面这都很好&#xff0c;就不赘述了&#xff0c;当然&#xff0c;这里也给出一个个人认为不错的安装…

移动互联网行业就业率除车载外,还有“该”的岗位在暴涨!

从2013年进入到移动互联网时代&#xff0c;在Android系统广泛应用在手机厂商中&#xff0c;App承载了我们生活工作的方方面面&#xff0c;原来需要在PC或者线下才能做的事情&#xff0c;现在点一点手指就可以做到了。这类方便也带来更多的系统安全危害。正所谓魔高一尺道高一丈…

一.《UE4奥丁》人物最大属性

​寻找突破口 1.续上节课,此时看到标题,有基础的同学第一反应就是,老师用CE搜索血量,通过改变就能找到&#xff01; 2.额,有这么简单吗&#xff01; 3.既然写了这个帖子,肯定是有原因的 4.为了方便学习,我们就先按照同学们的思路来试一试,能不能找到最大属性,比如最大血&am…

mysql索引方面的知识

1. 查看表的索引 show index from 表名 ex: 重点看Key_name这一列的值, 可以看到只有一个主键, 目前该表还没有创建索引, 接下来进行索引的创建 2.给表添加索引 create index idx_time_classtype_sip_sport on event_20230508(time,classtype,sip,sport) 说明: 上面index后…

【论文精读】DELS-MVS

今天读的是发表在WACV2023上的文章&#xff0c;第一作者来自于格拉茨技术大学。 文章链接&#xff1a;DELS-MVS: Deep Epipolar Line Search for Multi-View Stereo 文章目录 Abstract1. Introduction2. Related Work3. Algorithm3.1 Depth estimation via epipolar residual3.…

【换脸详细教程】手把手教你进行AI换脸:换脸流程及源码详解

目录 1. 换脸基本原理2 人脸检测及可视化3. 人脸轮廓点检测及可视化4. 人脸图像变换--仿射变换5. 生成遮罩并直接替换人脸6. 人脸颜色校正 最近AI换脸貌似比较火爆&#xff0c;就稍微研究了一下相关了内容。AI换脸是一个娱乐性比较强的应用&#xff0c;这种错位感让人觉得非常有…