当前位置: 首页 > 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应用程序提供强大的音视…...

python打卡day49

知识点回顾&#xff1a; 通道注意力模块复习空间注意力模块CBAM的定义 作业&#xff1a;尝试对今天的模型检查参数数目&#xff0c;并用tensorboard查看训练过程 import torch import torch.nn as nn# 定义通道注意力 class ChannelAttention(nn.Module):def __init__(self,…...

深入浅出:JavaScript 中的 `window.crypto.getRandomValues()` 方法

深入浅出&#xff1a;JavaScript 中的 window.crypto.getRandomValues() 方法 在现代 Web 开发中&#xff0c;随机数的生成看似简单&#xff0c;却隐藏着许多玄机。无论是生成密码、加密密钥&#xff0c;还是创建安全令牌&#xff0c;随机数的质量直接关系到系统的安全性。Jav…...

基于数字孪生的水厂可视化平台建设:架构与实践

分享大纲&#xff1a; 1、数字孪生水厂可视化平台建设背景 2、数字孪生水厂可视化平台建设架构 3、数字孪生水厂可视化平台建设成效 近几年&#xff0c;数字孪生水厂的建设开展的如火如荼。作为提升水厂管理效率、优化资源的调度手段&#xff0c;基于数字孪生的水厂可视化平台的…...

css的定位(position)详解:相对定位 绝对定位 固定定位

在 CSS 中&#xff0c;元素的定位通过 position 属性控制&#xff0c;共有 5 种定位模式&#xff1a;static&#xff08;静态定位&#xff09;、relative&#xff08;相对定位&#xff09;、absolute&#xff08;绝对定位&#xff09;、fixed&#xff08;固定定位&#xff09;和…...

GitHub 趋势日报 (2025年06月08日)

&#x1f4ca; 由 TrendForge 系统生成 | &#x1f310; https://trendforge.devlive.org/ &#x1f310; 本日报中的项目描述已自动翻译为中文 &#x1f4c8; 今日获星趋势图 今日获星趋势图 884 cognee 566 dify 414 HumanSystemOptimization 414 omni-tools 321 note-gen …...

uniapp 小程序 学习(一)

利用Hbuilder 创建项目 运行到内置浏览器看效果 下载微信小程序 安装到Hbuilder 下载地址 &#xff1a;开发者工具默认安装 设置服务端口号 在Hbuilder中设置微信小程序 配置 找到运行设置&#xff0c;将微信开发者工具放入到Hbuilder中&#xff0c; 打开后出现 如下 bug 解…...

es6+和css3新增的特性有哪些

一&#xff1a;ECMAScript 新特性&#xff08;ES6&#xff09; ES6 (2015) - 革命性更新 1&#xff0c;记住的方法&#xff0c;从一个方法里面用到了哪些技术 1&#xff0c;let /const块级作用域声明2&#xff0c;**默认参数**&#xff1a;函数参数可以设置默认值。3&#x…...

论文阅读:Matting by Generation

今天介绍一篇关于 matting 抠图的文章&#xff0c;抠图也算是计算机视觉里面非常经典的一个任务了。从早期的经典算法到如今的深度学习算法&#xff0c;已经有很多的工作和这个任务相关。这两年 diffusion 模型很火&#xff0c;大家又开始用 diffusion 模型做各种 CV 任务了&am…...

Linux安全加固:从攻防视角构建系统免疫

Linux安全加固:从攻防视角构建系统免疫 构建坚不可摧的数字堡垒 引言:攻防对抗的新纪元 在日益复杂的网络威胁环境中,Linux系统安全已从被动防御转向主动免疫。2023年全球网络安全报告显示,高级持续性威胁(APT)攻击同比增长65%,平均入侵停留时间缩短至48小时。本章将从…...

如何做好一份技术文档?从规划到实践的完整指南

如何做好一份技术文档&#xff1f;从规划到实践的完整指南 &#x1f31f; 嗨&#xff0c;我是IRpickstars&#xff01; &#x1f30c; 总有一行代码&#xff0c;能点亮万千星辰。 &#x1f50d; 在技术的宇宙中&#xff0c;我愿做永不停歇的探索者。 ✨ 用代码丈量世界&…...