Quellcode durchsuchen

feat: 添加搜索历史清空与推荐功能并优化推荐展示

- 新增搜索历史清空接口调用,清空后显示提示
- 新增搜索推荐接口,用于购物车页面推荐列表
- 优化搜索推荐展示,使用动态分类名称替换硬编码文本
- 移除购物车页面硬编码的推荐数据,改为接口获取
ylong vor 2 Tagen
Ursprung
Commit
30ecf12519

+ 6 - 0
api/modules/mall.js

@@ -189,5 +189,11 @@ export const useMallApi = (Vue, vm) => {
 
         // 订单支付
         payShopOrderAjax: (data) => vm.$u.post('/token/shop/order/orderPay', data),
+
+        // 清空搜索历史
+        clearSearchHistoryAjax: () => vm.$u.post('/token/shop/user/clearSearchLog'),
+
+        // 搜索推荐
+        getSearchRecommendAjax: () => vm.$u.get('/token/shop/user/searchRecommend'),
 	}
 }

+ 10 - 12
pages-car/pages/index.vue

@@ -18,7 +18,7 @@
         </view>
 
         <!-- 为你推荐 -->
-        <view class="recommend-section">
+        <view class="recommend-section" v-if="recommendList.length>0">
             <view class="section-title">
                 <text class="line"></text>
                 <text class="text">为你推荐</text>
@@ -98,14 +98,7 @@
                         }
                     }
                 ],
-                recommendList: [
-                    { title: '工程数学线性代数第六版', cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' },
-                    { title: '工程数学线性代数第六版', cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' },
-                    { title: '工程数学线性代数第六版', cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' },
-                    { title: '工程数学线性代数第六版', cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' },
-                    { title: '工程数学线性代数第六版', cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' },
-                    { title: '工程数学线性代数第六版', cover: 'https://k.sinaimg.cn/n/sinakd20116/234/w1000h1634/20251003/b66b-587c9ff400fcf01be52c6693594b6a6d.jpg/w700d1q75cms.jpg' }
-                ]
+                recommendList: []
             };
         },
         onShow() {
@@ -156,13 +149,11 @@
             },
             loadData() {
                 this.loading = true;
+                // 获取购物车列表
                 this.$u.api.getShopCartListAjax({}).then(res => {
                     this.loading = false;
                     // 本地添加选中状态属性
                     const list = res.rows || [];
-                    // 如果可能,与现有的选中状态合并,或者重置?
-                    // 为简单起见,如果 id 匹配,则重置或保持选中状态。
-                    // 或者直接初始化 checked=false。
                     this.cartList = list.map(item => {
                         return {
                             ...item,
@@ -173,6 +164,13 @@
                 }).catch(() => {
                     this.loading = false;
                 });
+
+                // 获取推荐列表
+                this.$u.api.getSearchRecommendAjax().then(res => {
+                    if (res.code == 200) {
+                        this.recommendList = res.data || [];
+                    }
+                });
             },
             handleCheck({ id, checked }) {
                 const item = this.cartList.find(i => i.id === id);

+ 1 - 1
pages-sell/components/sell-container/index.vue

@@ -107,7 +107,7 @@
 			<!-- 书嗨推荐 -->
 			<view class="recommend-section" @click="navigateTo(item.jumpUrl)" v-for="(item, index) in topicList" :key="index">
 				<view class="section-header">
-					<text class="section-title">书嗨推荐</text>
+					<text class="section-title">{{item.showCateName}}</text>
 					<view class="view-more">
 						<text>查看全部</text>
 						<image src="/pages-sell/static/right-arrow.png" class="arrow-icon" mode="widthFix"></image>

+ 9 - 1
pages-sell/pages/search.vue

@@ -127,7 +127,15 @@
                     content: '确定清空搜索历史吗?',
                     success: (res) => {
                         if (res.confirm) {
-                            this.historyList = [];
+                            this.$u.api.clearSearchHistoryAjax().then(res => {
+                                if (res.code == 200) {
+                                    this.historyList = [];
+                                    uni.showToast({
+                                        title: '已清空',
+                                        icon: 'none'
+                                    });
+                                }
+                            });
                         }
                     }
                 });