当前位置: 首页 > news >正文

微信小程序:完善购物车功能,购物车主页面展示,详细页面展示效果

一、效果图 

1、主页面

根据物品信息进行菜单分类,点击单项购物车图标添加至购物车,记录总购物车数量

2、购物车详情页

根据主页面选择的项,根据后台查询展示到页面,可进行多选,数量加减等

二、代码

1、主页面

页面展示顶部导航栏,侧边导航栏,以及导航栏执行下的内容,购物车的点击事件,内容单项的点击数量汇总到顶部总购物车总数量

wxml代码

<view class="main"><view class="topinfo"><view class="topinfo_view flex center"><view class="topinfo_model1 flex center"><view class="topinfo_model1_search"><image src="{{search}}"></image><input type="text" placeholder="请输入" placeholder-style="color:#CCCCCC" bindconfirm="search_info" /></view></view><view class="topinfo_model2 flex center" ><view class="topinfo_model2_circle flex center" bind:tap="shoppingClick"><image src="{{ShoppingCarGreen}}" /><view class="red_single1 flex center" wx:if="{{shoppingAllCount > 0}}">{{shoppingAllCount}}</view></view></view></view></view><view class="menu"><view class="top-menu flex between"><block wx:for="{{Menus}}" wx:key="index"><view class="topmenu-item flex center {{currentTopMenu === item.topname ? 'topactive' :''}}" data-menu="{{item.topname}}" bind:tap="onTopMenuClick">{{item.topname}}</view></block></view><view class="top-content flex center" wx:if="{{!linenone}}"><view class="left-menu"><block wx:for="{{LeftMenus}}" wx:key="index"><view class="left-menu-item flex center {{currentLeftMenu === item.name ? 'leftactive' : ''}}" bindtap="onLeftMenuClick" data-menu="{{item.name}}"><view class="left {{currentLeftMenu === item.name ? 'leftactivegreen' : ''}}"></view><text>{{item.name}}</text></view></block></view><view class="right-content"><block wx:for="{{RightInfo}}" wx:key="index"><view class="right-content-view flex"><view class="content-img flex center"><image src="{{item.img}}" mode="aspectFill"/></view><view class="content-info"><view class="cinfo-line flex between"><text>标题1:{{item.info1}}</text><text>标题2:{{item.info2}}</text></view><view class="cinfo-line flex between"><text>标题3:{{item.info3}}</text><text>标题4:{{item.info4}}</text></view><view class="cinfo-line flex between">标题5:{{item.info5}}</view><view class="cinfo-line flex flex-end"><view class="green-btn flex center" data-id="{{item.id}}" bind:tap="singleSel"><image src="{{ShoppingCarWhite}}" mode=""/><view class="red_single flex center" wx:if="{{item.isshopping}}">{{item.shoppingCount}}</view></view></view></view></view></block></view></view><view wx:else class="none">暂无数据</view></view>
</view>

wxss代码

主要采用flex布局进行布局

page {background-color: #f5f5f5;font-size:95%;
}.flex {display: flex;
}.center {justify-content: center;align-items: center;
}
.left{position: absolute;left:0;
}
.flex-end{justify-content: flex-end;
}
.between {justify-content: space-between;
}.none {text-align: center;margin-top: 50rpx;color: #969292;
}
/* 顶行搜索栏+购物车 */
/* 搜索框 */
.topinfo_view {padding: 4% 0 4% 0;
}.topinfo_model1 {height: 60rpx;width: 85%;
}.topinfo_model1_search {display: flex;align-items: center;height: 100%;width: 90%;border-radius: 10px;padding: 0 20rpx;background-color: #fff;
}.topinfo_model1 image {height: 40rpx;width: 45rpx;margin-right: 10px;
}.topinfo_view input {width: 100%;
}/* 购物车 */
.topinfo_model2 {width: 12%;height: 60rpx;
}.topinfo_model2_circle {width: 60rpx;height: 60rpx;background-color: #fff;border-radius: 50%;position:relative;
}.topinfo_model2_circle image {width: 40rpx;height: 40rpx;
}/* 顶部菜单栏 */
.menu {width: 100%;
}.topmenu-item {width: 100%;padding-bottom: 5px;border-bottom: 3px solid #f5f5f5;
}.topactive {border-bottom: 3px solid #4cc46b;
}/* 主体内容 */
.top-content {height:83vh;padding:10px 0;
}/* 左侧菜单栏 */
.left-menu {width: 25%;height:100%;
}
.leftactivegreen{width:5px;height:80%;background-color: #4cc46b;
}
.leftactive {background-color:#fff;color:#4cc46b;
}
.left-menu-item{height:50px;position:relative
}
.right-content {height:100%;width: 75%;font-size: 90%;background-color: #fff; overflow-y: auto;
}
.right-content-view{border-bottom:3px solid #f6f6f6;width:100%;padding:2% 0;
}
.content-img {width: 30%;margin-right: 2px;/* border:1px solid black; */
}
.content-img image {width: 95%;height: 95%;
}
.content-info{width:65%;
}
.cinfo-line{width:100%;padding:2% 0;
}
.green-btn{background-color:#4cc46b ;width:50rpx;height:50rpx;border-radius: 5px;margin-top:-4%;position:relative;
}
.green-btn image{width:35rpx;height:35rpx;
}
.red_single{border:1px solid #fff;color:#fff;position:absolute;width:25rpx;height:25rpx;top:-15rpx; right:-15rpx;border-radius: 50%;background-color: red;font-size: 10px;
} 
.red_single1{border:1px solid #fff;color:#fff;position:absolute;width:25rpx;height:25rpx;top:-12rpx; right:-12rpx;border-radius: 50%;background-color: red;font-size: 10px;
} 

js代码

这里主要展示核心数据部分,详细可参考资源

Menus: [{topname: '顶部菜单1',leftMenus: [{name: '侧边菜单1',items: [{id: 1,info1: '11',info2: '22',info3: '33',info4: '44',info5: '55',img: '../img/process_2.png'},{id: 2,info1: '22',info2: '22',info3: '22',info4: '22',info5: '22',img: '../img/process_1.png'},],},{name: '侧边菜单2',items: [{id: 3,info1: '33',info2: '33',info3: '33',info4: '33',info5: '33',img: '../img/process_3.png'}],},]},{topname: '顶部菜单2',leftMenus: []},{topname: '顶部菜单3',leftMenus: [{name: '侧边菜单3',items: [{id: 4,info1: '44',info2: '44',info3: '44',info4: '44',info5: '44',img: '../img/process_2.png'}],}],},{topname: '顶部菜单4',leftMenus: [{name: '侧边菜单4',items: [{id: 5,info1: '55',info2: '55',info3: '55',info4: '55',info5: '55',img: '../img/process_1.png'}],}],},
],

2、购物车界面

主要完成页面的选中项的展示,根据主页页面传递的id参数可进行数据库的查询,这里没连接后端,所以直接展示的实例数据,循环出数据项后,可对数据项进行多选,数据加减等功能

wxml代码

实现页面

<view class="main"><view class="itemallinfo"><view class="item_info flex center" wx:for="{{allinfo}}" wx:key="index" data-id="{{item.id}}"><view class="item flex center"><view class="sel_checkbox flex center"><checkbox value="{{item.id}}" checked="{{item.checked}}" bindtap="handleSelectItem" data-id="{{item.id}}" /></view><view class="info_image flex center"><image src="{{item.img}}" mode="aspectFill" /></view><view class="info_content"><view class="info_line1">配件名称:{{item.name}}</view><view class="info_line1">库存数量:{{item.stockQty}}{{item.uom}}</view><view class="info_line1 flex flex-end numbtn"><view class="btn_minus flex center" bindtap="handleMinus" data-id="{{item.id}}">-</view><input class="input_count" type="number" value="{{item.count}}" bindinput="handleInputChange" data-id="{{item.id}}" /><view class="btn_plus flex center" bindtap="handlePlus" data-id="{{item.id}}">+</view></view></view></view></view></view><view class="footer flex between"><view class="select_all flex center"><checkbox bindtap="handleSelectAll" checked="{{isAllSelected}}" /> 全选</view><view class="bottom2 flex center"><view class="delete_btn surebtn flex center" bindtap="handleDelete">删除</view></view><view class="bottom3 flex center"><view class="submit_btn surebtn flex center" bindtap="handleSubmit">提交</view></view></view>
</view>

wxss代码

page {background-color: #f6f6f6;font-size: 90%;
}.flex {display: flex;
}checkbox {transform: scale(0.8);
}.center {justify-content: center;align-items: center;
}.flex-end {justify-content: flex-end;align-items: center;
}
.between{justify-content: space-between;
}/* 列表内容 */
.item_info {width: 100%;padding: 5px 0;
}
.itemallinfo{padding:15px 0 100px 0;
}
.item {width: 95%;background-color: #fff;padding: 2% 0;border-radius: 5px;box-shadow: 3px 3px 3px rgb(0, 0, 0, 0.1);
}.sel_radio {width: 12%;
}radio {transform: scale(0.8);
}.info_image {width: 20%;
}.info_image image {width: 60px;height: 60px;
}.info_content {width: 68%;
}.info_line1 {margin: 2% 0;
}.numbtn {height: 25px;align-items: stretch;padding-right:2%;
}.btn_minus,
.btn_plus {border: 1px solid #c0c0c0;width: 30px;/* 设置按钮宽度 */height: 100%;cursor: pointer;/* 可选:设置鼠标指针样式 */
}.input_count {border: 1px solid #c0c0c0;width: 50px;/* 设置输入框宽度 */text-align: center;margin: 0 -1px;height: 100%;border-right:0;border-left:0;
}.footer {align-items: center;background-color: #fff;border-top: 1px solid #eee;position:fixed;width:100%;bottom:0;height:70px;
}
.select_all{height:100%;width:30%;
}
.bottom3,.bottom2{height:100%;width:35%;
}
.delete_btn {background-color: #bebebe;color: #fff;
}
.submit_btn {background-color: #f3454e;color: #fff;
}
.surebtn{border-radius: 5px;width:80%;height:30px;
}

js代码

这里主要展示核心数据部分,详细可参考资源

var allinfo = [{id: 1,info1: '11',info2: '22',info3: '33',info4: '44',info5: '55',img: '../img/process_2.png',count: 1,checked: false, // 默认未选中},{id: 3,info1: '33',info2: '33',info3: '33',info4: '33',info5: '33',img: '../img/process_3.png',count: 2,checked: false, // 默认未选中},{id: 5,info1: '55',info2: '55',info3: '55',info4: '55',info5: '55',img: '../img/process_1.png',count: 1,checked: false, // 默认未选中},
];

相关文章:

微信小程序:完善购物车功能,购物车主页面展示,详细页面展示效果

一、效果图 1、主页面 根据物品信息进行菜单分类&#xff0c;点击单项购物车图标添加至购物车&#xff0c;记录总购物车数量 2、购物车详情页 根据主页面选择的项&#xff0c;根据后台查询展示到页面&#xff0c;可进行多选&#xff0c;数量加减等 二、代码 1、主页面 页…...

javaweb将上传的图片保存在项目文件webapp下的upload文件夹下

前端HTML表单 (upload.html) 首先&#xff0c;创建一个HTML页面&#xff0c;允许用户选择并上传图片。 <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><title>图片上传</title> </head> <…...

LabVIEW 无法播放 AVI 视频的编解码器解决方案

用户在 LabVIEW 中使用示例程序 Read AVI File.vi&#xff08;路径&#xff1a; &#x1f4cc; C:\Program Files (x86)\National Instruments\LabVIEW 2019\examples\Vision\Files\Read AVI File.vi&#xff09;时发现&#xff1a; ✅ LabVIEW 自带的 AVI 视频可正常播放 这是…...

composer 错误汇总

文章目录 1: 安装EasyWeChat 报错2: composer install 报错, laravel/framework[v11.9.0, ..., v11.44.0] require fruitcake/php-cors ^1.33: 卸载Pulse 报错, Class "Laravel\Pulse\Pulse" not found4: 卸载Telescope报错 1: 安装EasyWeChat 报错 解决: composer …...

MySQL锁分类

一、按锁的粒度划分 全局锁 定义&#xff1a;锁定整个数据库实例&#xff0c;阻止所有写操作&#xff0c;确保数据备份一致性。加锁方式&#xff1a;通过FLUSH TABLES WITH READ LOCK实现&#xff0c;释放需执行UNLOCK TABLES。应用场景&#xff1a;适用于全库逻辑备份&#xf…...

DeepSeek 助力 Vue3 开发:打造丝滑的悬浮按钮(Floating Action Button)

前言&#xff1a;哈喽&#xff0c;大家好&#xff0c;今天给大家分享一篇文章&#xff01;并提供具体代码帮助大家深入理解&#xff0c;彻底掌握&#xff01;创作不易&#xff0c;如果能帮助到大家或者给大家一些灵感和启发&#xff0c;欢迎收藏关注哦 &#x1f495; 目录 Deep…...

认知动力学视角下的生命优化系统:多模态机器学习框架的哲学重构

认知动力学视角下的生命优化系统&#xff1a;多模态机器学习框架的哲学重构 一、信息熵与生命系统的耗散结构 在热力学第二定律框架下&#xff0c;生命系统可视为负熵流的耗散结构&#xff1a; d S d i S d e S dS d_iS d_eS dSdi​Sde​S 其中 d i S d_iS di​S为内部熵…...

Metal 学习笔记五:3D变换

在上一章中&#xff0c;您通过在 vertex 函数中计算position&#xff0c;来平移顶点和在屏幕上移动对象。但是&#xff0c;在 3D 空间中&#xff0c;您还想执行更多操作&#xff0c;例如旋转和缩放对象。您还需要一个场景内摄像机&#xff0c;以便您可以在场景中移动。 要移动…...

unity学习56:旧版legacy和新版TMP文本输入框 InputField学习

目录 1 旧版文本输入框 legacy InputField 1.1 新建一个文本输入框 1.2 InputField 的子物体构成 1.3 input field的的component 1.4 input Field的属性 2 过渡 transition 3 控件导航 navigation 4 占位文本 placeholder 5 文本 text 5.1 文本内容&#xff0c;用户…...

32位,算Cache地址

32位&#xff0c;算Cache地址...

C++蓝桥杯基础篇(六)

片头 嗨~小伙伴们&#xff0c;大家好&#xff01;今天我们来一起学习蓝桥杯基础篇&#xff08;六&#xff09;&#xff0c;练习相关的数组习题&#xff0c;准备好了吗&#xff1f;咱们开始咯&#xff01; 第1题 数组的左方区域 这道题&#xff0c;实质上是找规律&#xff0c;…...

React 常见面试题及答案

记录面试过程 常见问题&#xff0c;如有错误&#xff0c;欢迎批评指正 1. 什么是虚拟DOM&#xff1f;为什么它提高了性能&#xff1f; 虚拟DOM是React创建的一个轻量级JavaScript对象&#xff0c;表示真实DOM的结构。当状态变化时&#xff0c;React会生成新的虚拟DOM&#xf…...

和鲸科技推出人工智能通识课程解决方案,助力AI人才培养

2025年2月&#xff0c;教育部副部长吴岩应港澳特区政府邀请&#xff0c;率团赴港澳宣讲《教育强国建设规划纲要 (2024—2035 年)》。在港澳期间&#xff0c;吴岩阐释了教育强国目标的任务&#xff0c;并与特区政府官员交流推进人工智能人才培养的办法。这一系列行动体现出人工智…...

免费使用 DeepSeek API 教程及资源汇总

免费使用 DeepSeek API 教程及资源汇总 一、DeepSeek API 资源汇总1.1 火山引擎1.2 百度千帆1.3 阿里百炼1.4 腾讯云 二、其他平台2.1 华为云2.2 硅基流动 三、总结 DeepSeek-R1 作为 2025 年初发布的推理大模型&#xff0c;凭借其卓越的逻辑推理能力和成本优势&#xff0c;迅速…...

网络安全-使用DeepSeek来获取sqlmap的攻击payload

文章目录 概述DeepSeek使用创建示例数据库创建API测试sqlmap部分日志参考 概述 今天来使用DeepSeek做安全测试&#xff0c;看看在有思路的情况下实现的快不快。 DeepSeek使用 我有一个思路&#xff0c;想要测试sqlmap工具如何dump数据库的&#xff1a; 连接mysql数据库&#…...

网络原理--TCP/IP(2)

我们在之前已经介绍到TCP协议的核心机制二,接下来我们将继续介绍其他的核心机制。 核心机制三:连接管理 即建立连接,断开连接,在正常情况下,TCP要经过三次握⼿建⽴连接,四次挥⼿断开连接。 建立连接:TCP是通过“三次握手” 在生活中的握手就是打招呼,,但握手操作没有…...

Ragflow与Dify之我见:AI应用开发领域的开源框架对比分析

本文详细介绍了两个在AI应用开发领域备受关注的开源框架&#xff1a;Ragflow和Dify。Ragflow专注于构建基于检索增强生成&#xff08;RAG&#xff09;的工作流&#xff0c;强调模块化和轻量化&#xff0c;适合处理复杂文档格式和需要高精度检索的场景。Dify则旨在降低大型语言模…...

文件上传漏洞绕过WAF

文件上传漏洞绕过WAF学习笔记 1. WAF检测原理 WAF&#xff08;Web应用防火墙&#xff09;通过以下方式拦截文件上传攻击&#xff1a; 关键字匹配&#xff1a;检测文件名、内容中的敏感词&#xff08;如<?php、eval&#xff09;。 扩展名黑名单&#xff1a;拦截.php、.jsp…...

[含文档+PPT+源码等]精品基于Python实现的vue3+Django计算机课程资源平台

基于Python实现的Vue3Django计算机课程资源平台的背景&#xff0c;可以从以下几个方面进行阐述&#xff1a; 一、教育行业发展背景 1. 教育资源数字化趋势 随着信息技术的快速发展&#xff0c;教育资源的数字化已成为不可逆转的趋势。计算机课程资源作为教育领域的重要组成部…...

Qt 开源音视频框架模块之QtAV播放器实践

Qt 开源音视频框架模块QtAV播放器实践 1 摘要 QtAV是一个基于Qt的多媒体框架&#xff0c;旨在简化音视频播放和处理。它是一个跨平台的库&#xff0c;支持多种音视频格式&#xff0c;并提供了一个简单易用的API来集成音视频功能。QtAV的设计目标是为Qt应用程序提供强大的音视…...

【kafka】Golang实现分布式Masscan任务调度系统

要求&#xff1a; 输出两个程序&#xff0c;一个命令行程序&#xff08;命令行参数用flag&#xff09;和一个服务端程序。 命令行程序支持通过命令行参数配置下发IP或IP段、端口、扫描带宽&#xff0c;然后将消息推送到kafka里面。 服务端程序&#xff1a; 从kafka消费者接收…...

springboot 百货中心供应链管理系统小程序

一、前言 随着我国经济迅速发展&#xff0c;人们对手机的需求越来越大&#xff0c;各种手机软件也都在被广泛应用&#xff0c;但是对于手机进行数据信息管理&#xff0c;对于手机的各种软件也是备受用户的喜爱&#xff0c;百货中心供应链管理系统被用户普遍使用&#xff0c;为方…...

蓝牙 BLE 扫描面试题大全(2):进阶面试题与实战演练

前文覆盖了 BLE 扫描的基础概念与经典问题蓝牙 BLE 扫描面试题大全(1)&#xff1a;从基础到实战的深度解析-CSDN博客&#xff0c;但实际面试中&#xff0c;企业更关注候选人对复杂场景的应对能力&#xff08;如多设备并发扫描、低功耗与高发现率的平衡&#xff09;和前沿技术的…...

如何为服务器生成TLS证书

TLS&#xff08;Transport Layer Security&#xff09;证书是确保网络通信安全的重要手段&#xff0c;它通过加密技术保护传输的数据不被窃听和篡改。在服务器上配置TLS证书&#xff0c;可以使用户通过HTTPS协议安全地访问您的网站。本文将详细介绍如何在服务器上生成一个TLS证…...

零基础设计模式——行为型模式 - 责任链模式

第四部分&#xff1a;行为型模式 - 责任链模式 (Chain of Responsibility Pattern) 欢迎来到行为型模式的学习&#xff01;行为型模式关注对象之间的职责分配、算法封装和对象间的交互。我们将学习的第一个行为型模式是责任链模式。 核心思想&#xff1a;使多个对象都有机会处…...

LLMs 系列实操科普(1)

写在前面&#xff1a; 本期内容我们继续 Andrej Karpathy 的《How I use LLMs》讲座内容&#xff0c;原视频时长 ~130 分钟&#xff0c;以实操演示主流的一些 LLMs 的使用&#xff0c;由于涉及到实操&#xff0c;实际上并不适合以文字整理&#xff0c;但还是决定尽量整理一份笔…...

MySQL 部分重点知识篇

一、数据库对象 1. 主键 定义 &#xff1a;主键是用于唯一标识表中每一行记录的字段或字段组合。它具有唯一性和非空性特点。 作用 &#xff1a;确保数据的完整性&#xff0c;便于数据的查询和管理。 示例 &#xff1a;在学生信息表中&#xff0c;学号可以作为主键&#xff…...

PHP 8.5 即将发布:管道操作符、强力调试

前不久&#xff0c;PHP宣布了即将在 2025 年 11 月 20 日 正式发布的 PHP 8.5&#xff01;作为 PHP 语言的又一次重要迭代&#xff0c;PHP 8.5 承诺带来一系列旨在提升代码可读性、健壮性以及开发者效率的改进。而更令人兴奋的是&#xff0c;借助强大的本地开发环境 ServBay&am…...

Ubuntu系统多网卡多相机IP设置方法

目录 1、硬件情况 2、如何设置网卡和相机IP 2.1 万兆网卡连接交换机&#xff0c;交换机再连相机 2.1.1 网卡设置 2.1.2 相机设置 2.3 万兆网卡直连相机 1、硬件情况 2个网卡n个相机 电脑系统信息&#xff0c;系统版本&#xff1a;Ubuntu22.04.5 LTS&#xff1b;内核版本…...

Python网页自动化Selenium中文文档

1. 安装 1.1. 安装 Selenium Python bindings 提供了一个简单的API&#xff0c;让你使用Selenium WebDriver来编写功能/校验测试。 通过Selenium Python的API&#xff0c;你可以非常直观的使用Selenium WebDriver的所有功能。 Selenium Python bindings 使用非常简洁方便的A…...