Compare commits

...

36 Commits

Author SHA1 Message Date
fdzcxy212206240 f76806135b qgh
6 months ago
ccl 2277ab8ae8 添加功能:购物车可以计算总价格并进行商品结算 修改:删除search页面样式的注释防止报错
6 months ago
李庚 82eb5e4342 fivth commit
7 months ago
郑诗鹏 dc94cb930a zsp
7 months ago
蔡军仁 43a6c57ece 搜索和数据展示
7 months ago
蔡军仁 6fa0d7a33f Merge remote-tracking branch 'origin/master'
7 months ago
蔡军仁 2ae2f77691 搜索和数据展示
7 months ago
fjc b057396406 Merge remote-tracking branch 'origin/master'
7 months ago
fjc cbb34a5085 商品详情1
7 months ago
ccl d1ae2c4c5f 购物车
7 months ago
dengzeyu d929230e03 Merge remote-tracking branch 'origin/master'
7 months ago
dengzeyu 43415cccdf 删除
7 months ago
李庚 f45ace8d4f fourth commit
7 months ago
蔡军仁 4401295f0a 搜索和数据展示
7 months ago
蔡军仁 d83972c616 搜索和数据展示
7 months ago
蔡军仁 92c33f360e 搜索和数据展示
7 months ago
dengzeyu 01112011d9 Merge remote-tracking branch 'origin/master'
7 months ago
dengzeyu fc918a3114 货物列表1
7 months ago
dengzeyu 8e15040714 Merge remote-tracking branch 'origin/master'
7 months ago
蔡军仁 d3db7cbbc2 Merge remote-tracking branch 'origin/master'
7 months ago
蔡军仁 b93050f966 搜索和数据展示
7 months ago
dengzeyu 3c1fbf22c1 212206213邓泽玉
7 months ago
李庚 0594e390c7 second commit
7 months ago
李庚 7f13e1c48d second commit
7 months ago
李庚 d3c073aeb9 first commit
7 months ago
dengzeyu 42bbe65049 Merge remote-tracking branch 'origin/master'
7 months ago
dengzeyu 78a328ead7 try
7 months ago
蔡军仁 afe5d5dbbf Merge remote-tracking branch 'origin/master'
7 months ago
蔡军仁 9e1f9891fb 111
7 months ago
郑诗鹏 75991f3560 源码
7 months ago
蔡军仁 166115169b Merge remote-tracking branch 'origin/master'
7 months ago
蔡军仁 0bb767b01a 111
7 months ago
蔡军仁 7da4a3e653 333
7 months ago
dengzeyu 127e54895f 123456
7 months ago
fjc 5f902c23ec 222
7 months ago
fjc 9d2f91b5bd 111
7 months ago

@ -11,7 +11,7 @@
Target Server Version : 50560 Target Server Version : 50560
File Encoding : 65001 File Encoding : 65001
Date: 08/08/2022 15:36:53 Date: 10/30/2024 10:33:35
*/ */
SET NAMES utf8mb4; SET NAMES utf8mb4;
@ -27,7 +27,7 @@ CREATE TABLE `banner` (
`descs` text NOT NULL, `descs` text NOT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4;
-- 指定自增列从 5 开始。默认字符编码方式为utf-8字符集
-- ---------------------------- -- ----------------------------
-- Records of banner -- Records of banner
-- ---------------------------- -- ----------------------------
@ -49,7 +49,7 @@ CREATE TABLE `cart` (
`price` text, `price` text,
`currentID` int(11) DEFAULT NULL, `currentID` int(11) DEFAULT NULL,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COMMENT='newTable'; ) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8 COMMENT='cart';
-- ---------------------------- -- ----------------------------
-- Records of cart -- Records of cart
@ -70,7 +70,7 @@ CREATE TABLE `category` (
`image` text, `image` text,
`cate` text, `cate` text,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='newTable'; ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='category';
-- ---------------------------- -- ----------------------------
-- Records of category -- Records of category
@ -130,7 +130,7 @@ CREATE TABLE `goodsdetails` (
`price` text, `price` text,
`topimage` text, `topimage` text,
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='newTable'; ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='goodsdetails';
-- ---------------------------- -- ----------------------------
-- Records of goodsdetails -- Records of goodsdetails
@ -160,7 +160,7 @@ CREATE TABLE `keywords` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key', `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`content` varchar(255) DEFAULT NULL COMMENT 'content', `content` varchar(255) DEFAULT NULL COMMENT 'content',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='newTable'; ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='keywords';
-- ---------------------------- -- ----------------------------
-- Records of keywords -- Records of keywords
@ -182,10 +182,11 @@ COMMIT;
DROP TABLE IF EXISTS `user`; DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` ( CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key', `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
`openid` text, `openid` text,
`session_key` text, `session_key` text,
--openid session_key
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COMMENT='newTable'; ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COMMENT='user';
-- ---------------------------- -- ----------------------------
-- Records of user -- Records of user

@ -15,4 +15,4 @@ app.use("/api",router);
app.listen(3001,() =>{ app.listen(3001,() =>{
console.log("服务器运行在3001端口上"); console.log("服务器运行在3001端口上");
}) })//123

@ -1,5 +1,5 @@
/** /**
* 存储接口地址 * 定义存储接口地址
*/ */
module.exports = { module.exports = {
baseUrl:"http://iwenwiki.com:3001", // 公共地址 baseUrl:"http://iwenwiki.com:3001", // 公共地址
@ -12,6 +12,6 @@ module.exports = {
addCart:"/api/cart/add", // 添加购物车 addCart:"/api/cart/add", // 添加购物车
delCart:"/api/cart/del", // 删除购物车 delCart:"/api/cart/del", // 删除购物车
category:"/api/category", // 分类 category:"/api/category", // 分类
buy:"/api/buy", // 购买 buy:"/api/buy", // 购买商品
login:"/api/login", // 登录 login:"/api/login", // 登录
} }

@ -5,14 +5,14 @@ const { login,baseUrl,banner,goods,hotSearch,search,goodsDetails,cart,addCart,de
*/ */
/** /**
* get banner data *轮播图
*/ */
function getBanner(data){ function getBanner(data){
return request(baseUrl + banner,"GET",data) return request(baseUrl + banner,"GET",data)
} }
/** /**
* get goods list data * 轮播图
*/ */
function getGoods(data){ function getGoods(data){
@ -20,63 +20,63 @@ function getGoods(data){
} }
/** /**
* hot search keywords * 热门搜索
*/ */
function getHotSearch(data){ function getHotSearch(data){
return request(baseUrl + hotSearch,"GET",data) return request(baseUrl + hotSearch,"GET",data)
} }
/** /**
* search * 搜索
*/ */
function getSearch(data){ function getSearch(data){
return request(baseUrl + search,"GET",data) return request(baseUrl + search,"GET",data)
} }
/** /**
* goods details * 商品详情
*/ */
function getGoodsDetails(data){ function getGoodsDetails(data){
return request(baseUrl + goodsDetails,"GET",data) return request(baseUrl + goodsDetails,"GET",data)
} }
/** /**
* cart select * 购物车查询
*/ */
function getCart(data){ function getCart(data){
return request(baseUrl + cart,"GET",data) return request(baseUrl + cart,"GET",data)
} }
/** /**
* cart add * 添加购物车
*/ */
function addGoodsCart(data){ function addGoodsCart(data){
return request(baseUrl + addCart,"GET",data) return request(baseUrl + addCart,"GET",data)
} }
/** /**
* cart del * 删除购物车
*/ */
function delGoodsCart(data){ function delGoodsCart(data){
return request(baseUrl + delCart,"GET",data) return request(baseUrl + delCart,"GET",data)
} }
/** /**
* category * 分类
*/ */
function getCategory(data){ function getCategory(data){
return request(baseUrl + category,"GET",data) return request(baseUrl + category,"GET",data)
} }
/** /**
* buy * 购买
*/ */
function getBuy(data){ function getBuy(data){
return request(baseUrl + buy,"GET",data) return request(baseUrl + buy,"GET",data)
} }
function getLogin(data){ function getLogin(data){
return request(baseUrl + login,"POST",data) return request(baseUrl + login,"POST",data)
} }
module.exports = { module.exports = {

@ -1,12 +1,12 @@
// app.js // app.js
App({ App({
onLaunch() { onLaunch() {
// 展示本地存储能力 6 // 展示本地存储能力
const logs = wx.getStorageSync('logs') || [] const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now()) logs.unshift(Date.now())
wx.setStorageSync('logs', logs) wx.setStorageSync('logs', logs)
// 登录 // 定义登录
wx.login({ wx.login({
success: res => { success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId // 发送 res.code 到后台换取 openId, sessionKey, unionId

@ -1,7 +1,7 @@
// components/goods-list/goods-list.js // components/goods-list/goods-list.js
Component({ Component({
/** /**
* 组件的属性列表 * 212206213邓泽玉组件的属性列表
*/ */
properties: { properties: {
goodsData:{ goodsData:{
@ -11,15 +11,17 @@ Component({
}, },
/** /**
* 组件的初始数据 * 组件的初始数据212206213邓泽玉
*/ *
data: {
21212313/
data: {
}, },
/** /**
* 组件的方法列表 * 组件的方法列表212206213邓泽玉
*/ 132131*/
methods: { methods: {
} }

@ -3,6 +3,9 @@
padding: 5px; padding: 5px;
box-sizing: border-box; box-sizing: border-box;
} }
/**
* 列表的样式212206213邓泽玉
*/
.list .item { .list .item {
width: 48%; width: 48%;
@ -12,11 +15,11 @@
background: #fff; background: #fff;
margin: 2px 1%; margin: 2px 1%;
} }
/**列表项目的样式**/
.list .item .goods_img image { .list .item .goods_img image {
width: 100%; width: 100%;
} }
/**货物信息名字**/
.list .item .goods_info .goods_name { .list .item .goods_info .goods_name {
font-size: 14px; font-size: 14px;
text-align: left; text-align: left;
@ -29,7 +32,7 @@
display: -webkit-box; display: -webkit-box;
word-break: break-all; word-break: break-all;
} }
/**货物价格**/
.list .item .goods_info .goods_price { .list .item .goods_info .goods_price {
font-style: normal; font-style: normal;
font-family: JDZH-Regular, sans-serif; font-family: JDZH-Regular, sans-serif;
@ -38,7 +41,7 @@
line-height: 1.5rem; line-height: 1.5rem;
color: #ff4142; color: #ff4142;
} }
/**新货物的信息**/
.list .item .goods_info .goods_price text{ .list .item .goods_info .goods_price text{
font-size: 1rem; font-size: 1rem;
} }

@ -1,41 +1,50 @@
// 定义一个自定义组件
Component({ Component({
/** /**
* 组件的属性列表 * 组件的属性列表
* 这些属性可以在父组件中传递给子组件用于配置子组件的行为和显示
*/ */
properties: { properties: {
indicatorDots:{ // 是否显示面板指示点
type:Boolean, indicatorDots: {
value:false type: Boolean, // 属性类型为布尔值
value: false // 默认值为false即不显示指示点
}, },
autoplay:{ // 是否自动切换
type:Boolean, autoplay: {
value:false type: Boolean, // 属性类型为布尔值
value: false // 默认值为false即不自动切换
}, },
interval:{ // 自动切换时间间隔,单位为毫秒
type:Number, interval: {
value:5000 type: Number, // 属性类型为数字
value: 5000 // 默认值为5000毫秒即5秒
}, },
duration:{ // 滑动动画时长,单位为毫秒
type:Number, duration: {
value:500 type: Number, // 属性类型为数字
value: 500 // 默认值为500毫秒
}, },
swiperData:{ // 轮播图的数据源,数组形式
type:Array, swiperData: {
value:[] type: Array, // 属性类型为数组
value: [] // 默认值为空数组
} }
}, },
/** /**
* 组件的初始数据 * 组件的初始数据
* 这些数据是组件内部使用的不会从外部传递
*/ */
data: { data: {
// 可以在这里定义组件内部的数据,例如当前激活的滑块索引等
}, },
/** /**
* 组件的方法列表 * 组件的方法列表
* 这些方法可以被组件内部调用也可以暴露给父组件调用
*/ */
methods: { methods: {
// 可以在这里定义组件的各种方法,例如处理滑动事件、更新数据等
} }
}) })

@ -1,4 +1,4 @@
{ {
"component": true, "component": true,
"usingComponents": {} "usingComponents": {}
} }

@ -1,9 +1,22 @@
<!-- 外层视图容器类名为swiper -->
<view class="swiper"> <view class="swiper">
<swiper class="myswiper" indicator-dots="{{ indicatorDots }}" autoplay="{{ autoplay }}" interval="{{ interval }}" duration="{{ duration }}" indicator-color="#fff" indicator-active-color="#fa2c19"> <!-- 使用swiper组件设置相关属性 -->
<swiper
class="myswiper" <!-- 设置swiper组件的类名为myswiper -->
indicator-dots="{{ indicatorDots }}" <!-- 是否显示面板指示点绑定到组件属性indicatorDots -->
autoplay="{{ autoplay }}" <!-- 是否自动切换绑定到组件属性autoplay -->
interval="{{ interval }}" <!-- 自动切换时间间隔绑定到组件属性interval -->
duration="{{ duration }}" <!-- 滑动动画时长绑定到组件属性duration -->
indicator-color="#fff" <!-- 指示点颜色 -->
indicator-active-color="#fa2c19"> <!-- 当前选中的指示点颜色 -->
<!-- 使用block组件循环渲染swiper-item -->
<block wx:for="{{ swiperData }}" wx:key="index"> <block wx:for="{{ swiperData }}" wx:key="index">
<!-- 每个swiper-item组件 -->
<swiper-item> <swiper-item>
<!-- 图片组件mode设置为宽度自适应src绑定到当前项的url -->
<image mode="widthFix" src="{{ item.url }}"></image> <image mode="widthFix" src="{{ item.url }}"></image>
</swiper-item> </swiper-item>
</block> </block>
</swiper> </swiper>
</view> </view>

@ -1,6 +1,9 @@
.swiper{ /* 定义类名为swiper的样式 */
padding: 0 10px; .swiper {
padding: 0 10px; /* 设置左右内边距为10px顶部和底部内边距为0 */
}
/* 定义image元素的样式 */
image {
width: 100%; /* 设置图片宽度为100%,使其宽度自适应其父容器 */
} }
image{
width: 100%;
}

@ -1,21 +1,30 @@
// 引入一个模块该模块导出了一个名为getBuy的函数
const { getBuy } = require("../../api/index.js") const { getBuy } = require("../../api/index.js")
// 定义一个页面对象,这是微信小程序页面的标准结构
Page({ Page({
data: { data: {
goodsData:{} goodsData:{}// 用于存储商品数据的对象,初始化为空对象
}, },
// 页面的初始数据
onLoad(options) { onLoad(options) {
// 调用getBuy函数传入一个对象作为参数该对象包含一个id属性其值来自页面加载时的选项参数
getBuy({ id:options.id }).then(res =>{ getBuy({ id:options.id }).then(res =>{
// 在Promise的then回调中处理异步请求的响应
console.log(res.data); console.log(res.data);
// 使用setData方法更新页面数据
// 这里将响应数据中的第一个商品数据赋值给goodsData
this.setData({ this.setData({
goodsData:res.data.data[0] goodsData:res.data.data[0]
}) })
}) })
}, },
// 页面上的提交按钮点击时触发的事件处理函数
onSubmit(){ onSubmit(){
wx.showToast({ wx.showToast({
title: '购买完成', // 显示一个提示框,告知用户购买完成
icon:"success" title: '购买完成',// 提示框的标题
icon:"success"// 提示框的图标,这里使用成功图标
}) })
} }
}) })

@ -1,46 +1,125 @@
const { getCart,delGoodsCart } = require("../../api/index.js") // 引入获取购物车和删除购物车商品的API方法
const { getCart, delGoodsCart, submitOrder } = require("../../api/index.js");
// 定义小程序页面对象
Page({ Page({
// 页面数据对象初始时cartData为空数组totalPrice为0
/**
* 页面的初始数据
*/
data: { data: {
cartData:[] cartData: [],
totalPrice: 0 // 初始化 totalPrice 为 0
},
// 页面显示时触发的方法调用http方法获取购物车数据
onShow() {
this.http();
}, },
/**
* 每次打开页面都会执行 // 跳转到商品详情页的方法根据传入的商品ID进行跳转
*/ goDetail(e) {
onShow(){ const id = e.currentTarget.dataset.id; // 获取当前点击元素的数据集中的id值
this.http() wx.navigateTo({
url: `/pages/goodsDetails/goodsDetails?id=${id}` // 跳转到商品详情页并传递商品ID参数
});
}, },
// 根源
delCartHandle(e){ // 删除购物车商品的方法根据传入的商品ID进行删除操作
console.log(e.currentTarget.dataset.id); delCartHandle(e) {
/** console.log("删除按钮被点击"); // 打印日志,表示删除按钮被点击
* 这里有两个ID console.log(e.currentTarget.dataset.id); // 打印当前点击元素的数据集中的id值
* 1. currentID:商品ID同一个商品加入购物车多次的时候会一次性全删除 // 调用删除购物车商品的API方法传入当前商品ID
* 2. id:每条数据的唯一索引(推荐)课程中选择的方式 delGoodsCart({ currentID: e.currentTarget.dataset.id }).then(res => {
*/ if (res.data.status === 200) { // 如果API返回的状态码为200表示删除成功
delGoodsCart({currentID:e.currentTarget.dataset.id}).then(res =>{ wx.showToast({ // 显示成功提示框
if(res.data.status === 200){ title: '删除成功',
wx.showToast({ });
title: '删除成功', this.http(); // 刷新购物车数据
}) } else { // 如果API返回的状态码不是200表示删除失败
this.http() wx.showToast({ // 显示失败提示框
}else{
wx.showToast({
title: '删除失败', title: '删除失败',
}) });
} }
}) });
}, },
http(){
getCart().then(res =>{ // 获取购物车数据的方法
console.log(res.data.data); http() {
this.setData({ getCart().then(res => { // 调用获取购物车数据的API方法
cartData:res.data.data console.log(res.data.data); // 打印API返回的购物车数据
}) const cartData = res.data.data;
}) let totalPrice = 0;
cartData.forEach(item => {
const price = parseFloat(item.price); // 将 price 字段从字符串转换为数字
if (!isNaN(price)) { // 确保 price 是有效的数字
totalPrice += price; // 计算总价格,每个商品默认数量为 1
} else {
console.warn(`Invalid price for item:`, item); // 调试信息:警告无效的 price
}
});
console.log("Calculated Total Price:", totalPrice); // 调试信息:打印计算出的总价格
this.setData({ // 更新页面数据对象中的cartData属性和totalPrice
cartData: cartData,
totalPrice: totalPrice * 100 // van-submit-bar 的 price 单位是分
});
}).catch(err => {
console.error("Error during getCart operation:", err); // 调试信息:捕获并打印错误
wx.showToast({ // 显示失败提示框
title: '获取购物车数据失败',
icon: 'none'
});
});
},
onSubmit(){
wx.showToast({
// 显示一个提示框,告知用户购买完成
title: '购买完成',// 提示框的标题
icon:"success"// 提示框的图标,这里使用成功图标
})
},
//无法实现
// 提交订单的方法
/*
onSubmit() {
// 调用提交订单的API方法
submitOrder().then(res => {
if (res.data.status === 200) { // 如果API返回的状态码为200表示订单提交成功
wx.showToast({ // 显示成功提示框
title: '购买成功',
});
// 清空购物车数据
this.setData({
cartData: [],
totalPrice: 0
});
// 调用删除购物车商品的API方法传入所有商品ID
const cartIDs = this.data.cartData.map(item => item.id);
delGoodsCart({ currentIDs: cartIDs }).then(delRes => {
if (delRes.data.status === 200) { // 如果API返回的状态码为200表示删除成功
console.log('购物车商品删除成功');
} else { // 如果API返回的状态码不是200表示删除失败
console.error('购物车商品删除失败', delRes);
}
}).catch(delErr => {
console.error('删除购物车商品时发生错误', delErr);
});
} else { // 如果API返回的状态码不是200表示订单提交失败
wx.showToast({ // 显示失败提示框
title: '购买失败',
icon: 'none'
});
}
}).catch(err => {
console.error("Error during submitOrder operation:", err); // 调试信息:捕获并打印错误
wx.showToast({ // 显示失败提示框
title: '提交订单失败',
icon: 'none'
});
});
} }
}) */
});

@ -2,6 +2,7 @@
"usingComponents": { "usingComponents": {
"van-swipe-cell": "@vant/weapp/swipe-cell/index", "van-swipe-cell": "@vant/weapp/swipe-cell/index",
"van-cell": "@vant/weapp/cell/index", "van-cell": "@vant/weapp/cell/index",
"van-card": "@vant/weapp/card/index" "van-card": "@vant/weapp/card/index",
"van-submit-bar": "@vant/weapp/submit-bar/index"
} }
} }

@ -5,4 +5,9 @@
<view data-id="{{ item.id }}" bindtap="delCartHandle" slot="right" class="van-swipe-cell-right">删除</view> <view data-id="{{ item.id }}" bindtap="delCartHandle" slot="right" class="van-swipe-cell-right">删除</view>
</van-swipe-cell> </van-swipe-cell>
</view> </view>
</view> <van-submit-bar
price="{{ totalPrice }}"
button-text="提交订单"
bind:submit="onSubmit"
/>
</view>

@ -1,75 +1,92 @@
const { getGoodsDetails,addGoodsCart } = require("../../api/index.js") const { getGoodsDetails, addGoodsCart } = require("../../api/index.js");
Page({ Page({
/** /**
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
goodsDetails:{} goodsDetails: {} // 存储商品详情数据
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
* @param {Object} options - 页面加载时传递的参数
*/ */
onLoad(options) { onLoad(options) {
// 提示用户在获取数据 // 显示加载提示
wx.showLoading({ wx.showLoading({
title: '等待数据加载...', title: '等待数据加载...',
}) });
getGoodsDetails({id:options.id}).then(res =>{
wx.hideLoading() // 获取商品详情数据
if(res.data.status === 200){ getGoodsDetails({ id: options.id }).then(res => {
wx.hideLoading(); // 隐藏加载提示
if (res.data.status === 200) {
// 设置商品详情数据
this.setData({ this.setData({
goodsDetails:res.data.data[0] goodsDetails: res.data.data[0]
}) });
}else{ } else {
// 显示数据获取失败的提示
wx.showToast({ wx.showToast({
title: '数据获取失败', title: '数据获取失败',
icon:"success" icon: "none" // 修改为 "none",因为 "success" 不适合表示错误
}) });
} }
}) });
}, },
/** /**
* 客服 * 客服点击事件
*/ */
onClickKF(){}, onClickKF() {
// 客服功能实现
},
/** /**
* 购物车 * 购物车点击事件
*/ */
onClickCart(){ onClickCart() {
// 跳转到购物车页面
wx.switchTab({ wx.switchTab({
url: '/pages/cart/cart', url: '/pages/cart/cart',
}) });
}, },
/** /**
* 加入购物车 * 加入购物车点击事件
*/ */
onClickAddCart(){ onClickAddCart() {
// 添加商品到购物车
addGoodsCart({ addGoodsCart({
title:this.data.goodsDetails.title, title: this.data.goodsDetails.title, // 商品标题
price:this.data.goodsDetails.price, price: this.data.goodsDetails.price, // 商品价格
image:this.data.goodsDetails.topimage, image: this.data.goodsDetails.topimage, // 商品图片
currentID:this.data.goodsDetails.id currentID: this.data.goodsDetails.id // 商品ID
}).then(res =>{ }).then(res => {
if(res.data.status === 200){ if (res.data.status === 200) {
// 显示添加成功提示
wx.showToast({ wx.showToast({
title: res.data.msg, title: res.data.msg,
}) });
}else{ } else {
// 显示添加失败提示
wx.showToast({ wx.showToast({
title: res.data.msg, title: res.data.msg,
}) });
} }
}) });
}, },
/** /**
* 立即购买 * 立即购买点击事件
* @param {Object} e - 事件对象
*/ */
onClickBuy(e){ onClickBuy(e) {
// 跳转到购买页面并传递商品ID
wx.navigateTo({ wx.navigateTo({
url: '/pages/buy/buy?id='+e.currentTarget.dataset.id, url: '/pages/buy/buy?id=' + e.currentTarget.dataset.id,
}) });
} }
}) });

@ -1,22 +1,41 @@
<!-- 商品详情页面的根容器 -->
<view class="details"> <view class="details">
<!-- 商品顶部图片,使用宽度自适应模式 -->
<image class="topimage" mode="widthFix" src="{{ goodsDetails.topimage }}"></image> <image class="topimage" mode="widthFix" src="{{ goodsDetails.topimage }}"></image>
<!-- 商品基本信息容器 -->
<view class="content"> <view class="content">
<!-- 商品价格显示 -->
<view class="price"> <view class="price">
¥<text>{{ goodsDetails.price }}</text>.00 ¥<text>{{ goodsDetails.price }}</text>.00
</view> </view>
<!-- 商品标题显示 -->
<view class="title"> <view class="title">
<text>{{ goodsDetails.title }}</text> <text>{{ goodsDetails.title }}</text>
</view> </view>
</view> </view>
<!-- 商品详细介绍图片,使用宽度自适应模式 -->
<view class="introduce"> <view class="introduce">
<image mode="widthFix" src="{{ goodsDetails.details }}"></image> <image mode="widthFix" src="{{ goodsDetails.details }}"></image>
</view> </view>
<!-- 商品操作栏容器 -->
<view class="cart"> <view class="cart">
<!-- Vant 商品操作栏组件 -->
<van-goods-action> <van-goods-action>
<!-- 客服图标按钮,点击时触发 onClickKF 事件 -->
<van-goods-action-icon icon="chat-o" text="客服" bind:click="onClickKF" /> <van-goods-action-icon icon="chat-o" text="客服" bind:click="onClickKF" />
<!-- 购物车图标按钮,点击时触发 onClickCart 事件 -->
<van-goods-action-icon icon="cart-o" text="购物车" bind:click="onClickCart" /> <van-goods-action-icon icon="cart-o" text="购物车" bind:click="onClickCart" />
<!-- 加入购物车按钮,点击时触发 onClickAddCart 事件 -->
<van-goods-action-button text="加入购物车" type="warning" bind:click="onClickAddCart" /> <van-goods-action-button text="加入购物车" type="warning" bind:click="onClickAddCart" />
<!-- 立即购买按钮,点击时触发 onClickBuy 事件,并传递商品 ID -->
<van-goods-action-button data-id="{{ goodsDetails.id }}" text="立即购买" bind:click="onClickBuy" /> <van-goods-action-button data-id="{{ goodsDetails.id }}" text="立即购买" bind:click="onClickBuy" />
</van-goods-action> </van-goods-action>
</view> </view>
</view> </view>

@ -1,32 +1,39 @@
.details{ /* 商品详情页面的整体样式 */
background: #fff; .details {
background: #fff; /* 设置背景颜色为白色 */
} }
.details .topimage{ /* 商品顶部图片的样式 */
width: 100%; .details .topimage {
width: 100%; /* 图片宽度占满父容器 */
} }
.details .content{ /* 商品基本信息容器的样式 */
margin: 10px; .details .content {
margin: 10px; /* 设置外边距为 10px */
} }
/* 商品价格的样式 */
.details .content .price { .details .content .price {
color: #f2270c; color: #f2270c; /* 设置价格文字颜色为红色 */
} }
.details .content .price text{ /* 商品价格中的文本样式 */
color: #f2270c; .details .content .price text {
display: inline-block; color: #f2270c; /* 设置价格文字颜色为红色 */
font-family: JDZH-Regular; display: inline-block; /* 使文本块级显示,方便设置其他样式 */
font-size: 20px; font-family: JDZH-Regular; /* 设置字体为 JDZH-Regular */
line-height: 30px; font-size: 20px; /* 设置字体大小为 20px */
line-height: 30px; /* 设置行高为 30px */
} }
.details .content .title{ /* 商品标题的样式 */
font-size: 15px; .details .content .title {
font-weight: 700; font-size: 15px; /* 设置字体大小为 15px */
font-weight: 700; /* 设置字体加粗 */
} }
.details .introduce image{ /* 商品详细介绍图片的样式 */
width: 100%; .details .introduce image {
} width: 100%; /* 图片宽度占满父容器 */
}

@ -1,102 +1,117 @@
const { getBanner,getGoods } = require("../../api/index.js") // 引入api模块中的getBanner和getGoods函数
const { getBanner, getGoods } = require("../../api/index.js")
// 定义页面对象
Page({ Page({
// 页面数据
data: { data: {
value: "", value: "", // 搜索框的值,初始为空字符串
swiperOptions:{ swiperOptions: {
indicatorDots:true, indicatorDots: true, // 是否显示面板指示点
autoplay:true, autoplay: true, // 是否自动切换
interval:3000, interval: 3000, // 自动切换时间间隔,单位为毫秒
duration:1000, duration: 1000, // 滑动动画时长,单位为毫秒
swiperData:[] swiperData: [] // 轮播图的数据源,初始为空数组
}, },
navData:[ navData: [
// 导航栏数据
{ {
text:"数码", text: "数码", // 文本内容
icon:"like", icon: "like", // 图标名称
color:"#ff0000" color: "#ff0000" // 图标颜色
}, },
{ {
text:"生鲜", text: "生鲜",
icon:"star", icon: "star",
color:"#ff0000" color: "#ff0000"
}, },
{ {
text:"会员", text: "会员",
icon:"fire", icon: "fire",
color:"#ff0000" color: "#ff0000"
}, },
{ {
text:"优惠", text: "优惠",
icon:"gift", icon: "gift",
color:"#ff0000" color: "#ff0000"
}, },
{ {
text:"充值", text: "充值",
icon:"phone", icon: "phone",
color:"#ff0000" color: "#ff0000"
}, },
{ {
text:"领券", text: "领券",
icon:"gem", icon: "gem",
color:"#ff0000" color: "#ff0000"
}, },
{ {
text:"外卖", text: "外卖",
icon:"gift-card", icon: "gift-card",
color:"#ff0000" color: "#ff0000"
}, },
{ {
text:"美食", text: "美食",
icon:"smile", icon: "smile",
color:"#ff0000" color: "#ff0000"
} }
], ],
page:1, page: 1, // 当前页码初始为1
goodsData:[] goodsData: [] // 商品数据,初始为空数组
}, },
// 页面加载时执行的函数
onLoad() { onLoad() {
getBanner().then(res =>{ // 获取轮播图数据
getBanner().then(res => {
this.setData({ this.setData({
indicatorDots:true, indicatorDots: true, // 设置是否显示面板指示点
autoplay:true, autoplay: true, // 设置是否自动切换
interval:3000, interval: 3000, // 设置自动切换时间间隔
duration:1000, duration: 1000, // 设置滑动动画时长
swiperData:res.data.data.result swiperData: res.data.data.result // 设置轮播图数据
}) })
}) })
// 加载第一页商品数据
this.http(this.data.page) this.http(this.data.page)
}, },
http(page){
getGoods({page}).then(res =>{ // 获取商品数据的函数
if(!res.data.msg){ http(page) {
getGoods({ page }).then(res => {
if (!res.data.msg) {
// 如果没有错误消息,合并新数据到现有商品数据中
this.setData({ this.setData({
// 老数据合并新数据,做累加操作 goodsData: this.data.goodsData.concat(res.data.data.result) // 累加新数据
goodsData:this.data.goodsData.concat(res.data.data.result)
}) })
}else{ } else {
// 给出用户提示 // 如果有错误消息,显示提示信息
wx.showToast({ wx.showToast({
title: res.data.msg, title: res.data.msg, // 提示信息内容
icon:"success", icon: "success", // 提示图标类型
duration:2000 duration: 2000 // 提示显示时长,单位为毫秒
}) })
} }
}) })
}, },
onReachBottom(){
// 更改页码 // 页面滚动到底部时触发的函数
onReachBottom() {
// 更新页码
this.setData({ this.setData({
page:this.data.page += 1 page: this.data.page + 1 // 页码加1
}) })
// 加载下一页商品数据
this.http(this.data.page) this.http(this.data.page)
}, },
/** /**
* 点击搜索框获取焦点 * 点击搜索框获取焦点时触发的函数
*/ */
clickSearch(){ clickSearch() {
// 跳转到搜索页面
wx.navigateTo({ wx.navigateTo({
url: '/pages/search/search', url: '/pages/search/search',
}) })
} }
}) })

@ -1,19 +1,31 @@
<view class="index-container"> <view class="index-container"> <!-- 整个页面的容器 -->
<view class="header"> <view class="header"> <!-- 头部区域 -->
<van-search bindtap="clickSearch" disabled bind:focus="clickSearch" value="{{ value }}" shape="round" background="#fa2c19" placeholder="请输入搜索关键词" /> <van-search
bindtap="clickSearch" <!-- 点击搜索框时触发 clickSearch 方法 -->
disabled <!-- 搜索框禁用 -->
bind:focus="clickSearch" <!-- 搜索框获得焦点时触发 clickSearch 方法 -->
value="{{ value }}" <!-- 搜索框的值绑定到 value 变量 -->
shape="round" <!-- 搜索框形状为圆角 -->
background="#fa2c19" <!-- 搜索框背景颜色 -->
placeholder="请输入搜索关键词" /> <!-- 搜索框占位符文本 -->
<!-- 轮播图 --> <!-- 轮播图 -->
<swiper swiperData="{{ swiperData }}" indicatorDots="{{ swiperOptions.indicatorDots }}" autoplay="{{ swiperOptions.autoplay }}" interval="{{ swiperOptions.interval }}" duration="{{ swiperOptions.duration }}"></swiper> <swiper
swiperData="{{ swiperData }}" <!-- 轮播图数据绑定到 swiperData 变量 -->
indicatorDots="{{ swiperOptions.indicatorDots }}" <!-- 是否显示面板指示点 -->
autoplay="{{ swiperOptions.autoplay }}" <!-- 是否自动切换 -->
interval="{{ swiperOptions.interval }}" <!-- 自动切换时间间隔 -->
duration="{{ swiperOptions.duration }}"> <!-- 滑动动画时长 -->
</swiper>
</view> </view>
<view class="nav"> <view class="nav"> <!-- 导航区域 -->
<van-grid column-num="4"> <van-grid column-num="4"> <!-- 4列的网格布局 -->
<van-grid-item <van-grid-item
wx:key="index" wx:key="index" <!-- 每个网格项的唯一标识 -->
icon-color="{{ item.color }}" icon-color="{{ item.color }}" <!-- 图标颜色 -->
icon="{{ item.icon }}" icon="{{ item.icon }}" <!-- 图标名称 -->
text="{{ item.text }}" text="{{ item.text }}" <!-- 文本内容 -->
wx:for="{{ navData }}" /> wx:for="{{ navData }}" /> <!-- 循环渲染 navData 中的数据 -->
</van-grid> </van-grid>
</view> </view>
<goods-list goodsData="{{ goodsData }}"></goods-list> <goods-list goodsData="{{ goodsData }}"></goods-list> <!-- 商品列表组件,数据绑定到 goodsData 变量 -->
</view> <!-- 整个页面的容器结束 -->
</view>

@ -1,13 +1,13 @@
.header{ .header { /* 定义头部区域的样式 */
background-image: -webkit-gradient(linear, left bottom, left top, from(#f1503b), color-stop(50%, #c82519)); background-image: -webkit-gradient(linear, left bottom, left top, from(#f1503b), color-stop(50%, #c82519)); /* 使用 WebKit 渐变从底部到顶部,颜色从 #f1503b 到 #c82519 */
background-image: -webkit-linear-gradient(bottom, #f1503b, #c82519 50%); background-image: -webkit-linear-gradient(bottom, #f1503b, #c82519 50%); /* 使用 WebKit 线性渐变从底部到顶部,颜色从 #f1503b 到 #c82519 */
background-image: linear-gradient(0deg, #f1503b, #c82519 50%); background-image: linear-gradient(0deg, #f1503b, #c82519 50%); /* 使用标准线性渐变从底部到顶部,颜色从 #f1503b 到 #c82519 */
width: 100%; width: 100%; /* 宽度占满父容器 */
height: 190px; height: 190px; /* 高度为 190 像素 */
border-bottom-left-radius: 100%; border-bottom-left-radius: 100%; /* 左下角圆角半径为 100%,形成圆形效果 */
border-bottom-right-radius: 100%; border-bottom-right-radius: 100%; /* 右下角圆角半径为 100%,形成圆形效果 */
} }
.nav{ .nav { /* 定义导航区域的样式 */
margin-top: 10px; margin-top: 10px; /* 上外边距为 10 像素 */
} }

@ -9,21 +9,37 @@ Page({
hotSearch:[], hotSearch:[],
value:"", value:"",
goodsData:[] goodsData:[]
}, },
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*.list-keywords {
*margin: 10px;
*padding: 10px;
*background: #fff;
*}1
*.list-keywords .item{
*display: inline-block;
*padding: 5px 10px;
*background: #f1f1f1;
*margin: 5px;
*font-size: 12px;
*color: #666;
*}
*/ */
onLoad(options) { onLoad(options) {
getHotSearch().then(res =>{ getHotSearch().then(res =>{//获取热点搜索函数
this.setData({ this.setData({
hotSearch:res.data.data.result hotSearch:res.data.data.result//搜索数据结果
}) })
}) })
}, },
// 内容改变 // 内容改变
onChange(e){ onChange(e){//内容展示函数
this.setData({ this.setData({//放置数据
value:e.detail value:e.detail//获取值
}) })
}, },
@ -34,31 +50,37 @@ Page({
*/ */
// 实现搜索 // 实现搜索
onSearch(){ onSearch(){//搜索函数
this.http(this.data.value) this.http(this.data.value)//1
}, },
onSearchCliclk(){ onSearchCliclk(){//搜索点击函数
this.http(this.data.value) this.http(this.data.value)//1
}, },
/** /**
* 获取热门关键字 * 获取热门关键字
*/ */
clickGetKeyWords(e){ clickGetKeyWords(e){
this.http(e.currentTarget.dataset.hotkey) this.http(e.currentTarget.dataset.hotkey)//使用this
}, },
http(search){ http(search){
getSearch({search}).then(res =>{ getSearch({search}).then(res =>{
if(!res.data.msg){ if(!res.data.msg){
// 序列化 // 序列化
let goods = JSON.stringify(res.data.data) let goods = JSON.stringify(res.data.data)//数据
wx.navigateTo({ wx.navigateTo({
url: '/pages/goods/goods?goodsData=' + goods, url: '/pages/goods/goods?goodsData=' + goods,//给出跳转网址0
}) })
}else{ }else{
wx.showToast({ wx.showToast({
title: res.data.msg, title: res.data.msg,//获取记录搜索结果总数0
}) })
} }
}) })
} }
}) }) /**
* 展示搜索数据在goods页面展示
* 1. 在搜索页面通过网络请求获取数据传递到goods页面显示
* 2. 在搜索页面将搜索的关键字传递到goods页面在goods页面做网络请求
*/
// 实现搜索7

@ -3,4 +3,4 @@
"van-search": "@vant/weapp/search/index", "van-search": "@vant/weapp/search/index",
"van-button": "@vant/weapp/button/index" "van-button": "@vant/weapp/button/index"
} }
} }

@ -1,6 +1,6 @@
<view> <view>
<van-search value="{{ value }}" placeholder="请输入搜索关键词" use-action-slot bind:change="onChange" bind:search="onSearch"> <van-search value="{{ value }}" placeholder="请输入搜索关键词" use-action-slot bind:change="onChange" bind:search="onSearch">
<van-button type="primary" size="small" slot="action" bind:tap="onSearchCliclk">搜索</van-button> <van-button type="primary" size="small" slot="action" bind:tap="onSearchCliclk">搜索</van-button>//搜索提示11
</van-search> </van-search>
<view class="list-keywords"> <view class="list-keywords">
<text data-hotkey="{{ item.content }}" bindtap="clickGetKeyWords" class="item" wx:for="{{ hotSearch }}" wx:key="index">{{ item.content }}</text> <text data-hotkey="{{ item.content }}" bindtap="clickGetKeyWords" class="item" wx:for="{{ hotSearch }}" wx:key="index">{{ item.content }}</text>

@ -10,4 +10,4 @@
margin: 5px; margin: 5px;
font-size: 12px; font-size: 12px;
color: #666; color: #666;
} }

@ -1,5 +1,5 @@
const { getLogin } = require("../../api/index.js") const { getLogin } = require("../../api/index.js")
//1231344
Page({ Page({
data: { data: {
userInfo: {}, userInfo: {},

@ -49,8 +49,8 @@
"useCompilerPlugins": false "useCompilerPlugins": false
}, },
"compileType": "miniprogram", "compileType": "miniprogram",
"libVersion": "2.19.4", "libVersion": "2.25.3",
"appid": "wx4ce6ca2eb67b5bf7", "appid": "touristappid",
"projectname": "miniprogram-92", "projectname": "miniprogram-92",
"condition": {}, "condition": {},
"editorSetting": { "editorSetting": {

Loading…
Cancel
Save