From b978dd5bb778023e30ff246b29df52ba5bf759f6 Mon Sep 17 00:00:00 2001 From: laptoy Date: Fri, 12 Jul 2024 21:47:27 +0800 Subject: [PATCH 1/2] hot --- src/jjt/Search.jsx | 4 ++-- src/jjt/scss/Search.scss | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/jjt/Search.jsx b/src/jjt/Search.jsx index d828445..bf082d1 100644 --- a/src/jjt/Search.jsx +++ b/src/jjt/Search.jsx @@ -98,7 +98,7 @@ export default function Searchs() {

搜索历史

-
+
{searhistory.map((item,index) => (
{ setValue(item.name); @@ -109,7 +109,7 @@ export default function Searchs() {

热门搜索

-
+
{hotsearchs.map((item, index) => (
Date: Sat, 13 Jul 2024 08:54:14 +0800 Subject: [PATCH 2/2] jjt4.0 --- src/components/Shopcar.jsx | 2 +- src/jjt/Classfy.jsx | 24 ++++++++++++++++++++---- src/jjt/Home.jsx | 27 ++++++++++++++++++++++----- src/jjt/Search.jsx | 22 +++++++++++++++++++--- src/jjt/untils/BottomFouter.jsx | 4 +++- 5 files changed, 65 insertions(+), 14 deletions(-) diff --git a/src/components/Shopcar.jsx b/src/components/Shopcar.jsx index 372710a..4aeadc0 100644 --- a/src/components/Shopcar.jsx +++ b/src/components/Shopcar.jsx @@ -62,7 +62,7 @@ export default function Shopcar() {

{item.name}

{item.location} 支持自提

-

¥{item.price*item.discount}  ¥{item.price}  xxx人想要

+

¥{item.price*(item.discount/10)}  ¥{item.price}  xxx人想要

diff --git a/src/jjt/Classfy.jsx b/src/jjt/Classfy.jsx index 955c646..9dd4ff6 100644 --- a/src/jjt/Classfy.jsx +++ b/src/jjt/Classfy.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from "react"; import { NavBar } from "react-vant"; //导航栏 import { useNavigate } from "react-router-dom"; -import { Search } from "react-vant"; //搜索 +import { Search,Toast } from "react-vant"; //搜索 import "./scss/Classfy.scss"; import axios from "./untils/Axios"; import { InfiniteScroll } from "antd-mobile"; @@ -60,6 +60,22 @@ export default function Classfy() { setBookData(copy) setTypeTwoId("") } + //加入购物车 + let tocar = async(item) => { + console.log(item,555555555) + let {data} = await axios.post("/jjt/caradd", item); + console.log(data,6666) + if(data.code===200){ + Toast({ + message: '加入购物车成功', + // icon: , + }) + }else{ + Toast({ + message: '加入购物车失败', + }) + } + } //接受分类路由参数 useEffect(() => { getdata(); @@ -184,8 +200,8 @@ export default function Classfy() { )}
{bookData.map((item) => ( -
{nav(`/detail?id=${item._id}`)}}> -
+
+
{nav(`/detail?id=${item._id}`)}}>
@@ -195,7 +211,7 @@ export default function Classfy() {
¥{item.price} - + {tocar(item)}} />
diff --git a/src/jjt/Home.jsx b/src/jjt/Home.jsx index 6cee358..2562d24 100644 --- a/src/jjt/Home.jsx +++ b/src/jjt/Home.jsx @@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react"; import "./scss/Home.scss"; import { Search } from "react-vant"; import { Badge } from "react-vant"; +import { Toast } from 'react-vant'; import { ChatO } from "@react-vant/icons"; import { Swiper } from "react-vant"; import IconFont from "../jjt/untils/Icon"; //icon图标 @@ -30,7 +31,7 @@ export default function Home() { }; const hotsearch = ["Vue", "Python", "React", "布局"]; //热搜 const [value, setValue] = useState(""); //热搜 - let Toast = (i) => { + let Toast2 = (i) => { // console.log(i); setValue(hotsearch[i]); }; @@ -65,6 +66,22 @@ export default function Home() { console.log(item._id, 2223); nav("/jjtclassfy", { state: { _id: item._id } }); }; + //加入购物车 + let tocar = async(item) => { + console.log(item,555555555) + let {data} = await axios.post("/jjt/caradd", item); + console.log(data,6666) + if(data.code===200){ + Toast({ + message: '加入购物车成功', + // icon: , + }) + }else{ + Toast({ + message: '加入购物车失败', + }) + } + } useEffect(() => { getdata(); }, []); @@ -191,8 +208,8 @@ export default function Home() { .filter((ele) => ele.typeTwoId._id == item._id) .slice(0, 2) .map((i) => ( -
{nav(`/detail?id=${i._id}`)}}> -
+
+
{nav(`/detail?id=${i._id}`)}}>
@@ -206,7 +223,7 @@ export default function Home() { ¥{(i.price * i.discount) / 10} ¥{i.price} - + {tocar(i)}} />
@@ -270,7 +287,7 @@ export default function Home() { Toast(i)} + onChange={(i) => Toast2(i)} > {hotsearch.map((image) => ( { + console.log(item,555555555) + let {data} = await axios.post("/jjt/caradd", item); + console.log(data,6666) + if(data.code===200){ + Toast({ + message: '加入购物车成功', + // icon: , + }) + }else{ + Toast({ + message: '加入购物车失败', + }) + } + } useEffect(() => { getdata(); mapsea() @@ -129,8 +145,8 @@ export default function Searchs() {

精选课程

{bookData.slice(0,9).map((item) => ( -
{nav(`/detail?id=${item._id}`)}}> -
+
+
{nav(`/detail?id=${item._id}`)}}>
@@ -147,7 +163,7 @@ export default function Searchs() { }} >

¥{item.price}

-

+

{tocar(item)}} />

diff --git a/src/jjt/untils/BottomFouter.jsx b/src/jjt/untils/BottomFouter.jsx index b9f147b..a11ba5c 100644 --- a/src/jjt/untils/BottomFouter.jsx +++ b/src/jjt/untils/BottomFouter.jsx @@ -1,13 +1,15 @@ import React from 'react' import { Tabbar } from 'react-vant'; import { ShoppingCartO , HomeO, CouponO , ManagerO } from '@react-vant/icons' +import { useNavigate } from 'react-router-dom'; export default function BottomFouter() { + let nav = useNavigate() return (
}>主页 }>卖书 - }>购物车 + } onClick={()=>(nav('/shopcar'))}>购物车 }>我的
-- Gitee