Bläddra i källkod

feat: 我的收藏列表及收藏商品接口联调

liangan 2 dagar sedan
förälder
incheckning
77d2f50e4f

+ 24 - 0
src/api/mine.ts

@@ -72,3 +72,27 @@ export function memberConfigs() {
 export function myUsers(data: any) {
   return http.post<any>(`${pre1}/api/user/myUsers`, data)
 }
+
+/**
+ * 我的收藏-商品列表
+ * @returns
+ */
+export function myFavoriteProducts(data: any) {
+  return http.post<any>(`${pre}/app/mid/favorite/list`, data)
+}
+
+/**
+ * 我的收藏-新增 {productIdList:[1]}
+ * @returns
+ */
+export function myFavoriteAdd(data: any) {
+  return http.post<any>(`${pre}/app/mid/favorite/add`, data)
+}
+
+/**
+ * 我的收藏-删除  {id:1}
+ * @returns
+ */
+export function myFavoriteDel(data: any) {
+  return http.delete<any>(`${pre}/app/mid/favorite/delete`, data)
+}

+ 1 - 1
src/api/product.ts

@@ -6,7 +6,7 @@ const pre = import.meta.env.VITE_SERVER_BASEURL_PREFIX
  * @returns data.list[]
  */
 export function getList(data: any) {
-  return http.post<any>(`${pre}/app/combination/app/list`, data)
+  return http.post<any>(`${pre}/app/combination/app/list`, { ...data, isShow: 1 })
 }
 /**
  * 获取商品排名列表

+ 4 - 1
src/locale/bn.json

@@ -251,7 +251,7 @@
   "referEarn.howToShare": "- কীভাবে শেয়ার করে অর্থ উপার্জন করবেন -",
   "referEarn.step1": "বন্ধুদের আমন্ত্রণ শেয়ার করুন",
   "referEarn.step2": "আপনার বন্ধু গ্রুপে যোগ দিন",
-  "referEarn.step3": "আপনি ৳৫০ পুরস্কার পান",
+  "referEarn.step3": "আপনি ৳{0} পুরস্কার পান",
   "referEarn.invitedFriends": "আমন্ত্রিত বন্ধুরা",
   "checkout.title": "চেকআউট",
   "checkout.selected": "নির্বাচিত",
@@ -288,6 +288,9 @@
   "productDetail.details": "বিবরণ",
   "productDetail.home": "হোম",
   "productDetail.favorite": "পছন্দের",
+  "productDetail.favoriteSuccess": "পছন্দের তালিকায় যোগ করা হয়েছে",
+  "productDetail.unfavoriteSuccess": "পছন্দের তালিকা থেকে সরানো হয়েছে",
+  "productDetail.favoriteError": "অপারেশন ব্যর্থ, আবার চেষ্টা করুন",
   "productDetail.openGroup": "গ্রুপ খুলুন",
   "productDetail.quantity": "পরিমাণ",
   "topChampions.title": "শীর্ষ চ্যাম্পিয়ন",

+ 4 - 1
src/locale/en.json

@@ -252,7 +252,7 @@
   "referEarn.howToShare": "- How to Share and Earn Money -",
   "referEarn.step1": "Share Invite Friends",
   "referEarn.step2": "Your Friend Join Group",
-  "referEarn.step3": "You Get ৳50 Reward",
+  "referEarn.step3": "You Get ৳{0} Reward",
   "referEarn.invitedFriends": "Invited Friends",
   "checkout.title": "Checkout",
   "checkout.selected": "Selected",
@@ -289,6 +289,9 @@
   "productDetail.details": "Details",
   "productDetail.home": "Home",
   "productDetail.favorite": "Favorite",
+  "productDetail.favoriteSuccess": "Added to favorites",
+  "productDetail.unfavoriteSuccess": "Removed from favorites",
+  "productDetail.favoriteError": "Operation failed, please try again",
   "productDetail.openGroup": "Open Group",
   "productDetail.quantity": "Quantity",
   "topChampions.title": "Top Champions",

+ 4 - 1
src/locale/zh-Hans.json

@@ -251,7 +251,7 @@
   "referEarn.howToShare": "- 如何分享赚钱 -",
   "referEarn.step1": "分享邀请朋友",
   "referEarn.step2": "朋友加入群组",
-  "referEarn.step3": "您获得 ৳50 奖励",
+  "referEarn.step3": "您获得 ৳{0} 奖励",
   "referEarn.invitedFriends": "邀请的朋友",
   "checkout.title": "结账",
   "checkout.selected": "已选择",
@@ -288,6 +288,9 @@
   "productDetail.details": "详情",
   "productDetail.home": "首页",
   "productDetail.favorite": "收藏",
+  "productDetail.favoriteSuccess": "收藏成功",
+  "productDetail.unfavoriteSuccess": "已取消收藏",
+  "productDetail.favoriteError": "操作失败,请重试",
   "productDetail.openGroup": "开团",
   "productDetail.quantity": "数量",
   "topChampions.title": "冠军榜",

+ 4 - 10
src/pages/mine/myFavorite.vue

@@ -13,7 +13,8 @@
 // eslint-disable-next-line unused-imports/no-unused-imports
 import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
 import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
-import { getList } from '@/api/product'
+import { myFavoriteProducts } from '@/api/mine'
+import { toPage } from '@/utils/page'
 
 defineOptions({
   name: 'MyFavorite', // 我的收藏
@@ -32,7 +33,7 @@ async function queryList(pageNo: number, pageSize: number) {
       page: pageNo,
       size: pageSize,
     }
-    const res = await getList(params)
+    const res = await myFavoriteProducts(params)
     paging.value.complete(res.data.list)
   }
   catch {
@@ -46,17 +47,10 @@ async function queryList(pageNo: number, pageSize: number) {
     <template v-if="dataList.length">
       <view class="px-24rpx py-24rpx">
         <view class="grid grid-cols-2 gap-22rpx">
-          <product v-for="(item, index) in dataList" :key="index" :height="340" :item="item" />
+          <product v-for="(item, index) in dataList" :key="index" :height="340" :item="item" @item-click="toPage('/pages/productDetail/productDetail', { productId: item.productId, id: item.id })" />
         </view>
       </view>
     </template>
-    <template v-else>
-      <view class="h-[50vh] flex items-center justify-center">
-        <text class="text-28rpx text-#999">
-          {{ $t('mine.pages.myFavorite.empty') }}
-        </text>
-      </view>
-    </template>
   </z-paging>
 </template>
 

+ 4 - 6
src/pages/productDetail/components/CustomTooltip.vue

@@ -15,8 +15,7 @@ const props = withDefaults(defineProps<Props>(), {
   visible: false,
   autoHide: true,
   autoHideDelay: 10000,
-  icon: 'shop',
-  iconSize: '32rpx',
+  icon: '/static/icons/gift.png',
   message: 'Full refund for unsuccessful group purchase $99.99 Receive red envelope rewards $1.8',
   highlightText1: '$99.99',
   highlightText2: '$1.8',
@@ -133,11 +132,10 @@ defineExpose({
     :style="{ width }"
   >
     <view class="flex items-center">
-      <wd-icon
+      <image
         v-if="icon"
-        :name="icon"
-        :size="iconSize"
-        class="mr-12rpx flex-shrink-0"
+        :src="icon"
+        class="mr-12rpx h-35rpx w-32rpx flex-shrink-0"
       />
       <view class="text-center">
         <text>Full refund for unsuccessful group purchase </text>

+ 54 - 4
src/pages/productDetail/productDetail.vue

@@ -12,10 +12,14 @@
 // eslint-disable-next-line unused-imports/no-unused-imports
 import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
 import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
+import { myFavoriteAdd, myFavoriteDel } from '@/api/mine'
 import { preOrder as _preOrder } from '@/api/order'
 import { getDetail, pinkList } from '@/api/product'
+import { getUserInfoHook, requireLogin } from '@/hooks/usePageAuth'
+import { t } from '@/locale'
 import { formatNumber } from '@/utils/index'
 import { getPageParams, goBack, toPage } from '@/utils/page'
+import { toast } from '@/utils/toast'
 import CustomTooltip from './components/CustomTooltip.vue'
 import NotificationCarousel from './components/NotificationCarousel.vue'
 
@@ -33,7 +37,11 @@ const safeAreaInsets = systemInfo.safeAreaInsets
 const paging = ref(null)
 // 类似mixins,如果是页面滚动务必要写这一行,并传入当前ref绑定的paging,注意此处是paging,而非paging.value
 useZPaging(paging)
-
+function goHome() {
+  uni.switchTab({
+    url: '/pages/index/index',
+  })
+}
 // 添加导航栏背景色变量
 const navBgColor = ref('transparent')
 const changeNavbarThreshold = 300 // 滚动到这个高度时改变导航栏颜色
@@ -241,6 +249,35 @@ function setDefaultSpecs() {
   }
 }
 
+// 收藏/取消收藏
+async function toggleFavorite() {
+  if (!requireLogin()) {
+    return
+  }
+
+  try {
+    if (detail.value.isFavorite) {
+      // 取消收藏
+      const res = await myFavoriteDel({ id: productId.value })
+      if (res.code === '200') {
+        detail.value.isFavorite = false
+        toast.success(t('productDetail.unfavoriteSuccess'))
+      }
+    }
+    else {
+      // 添加收藏
+      const res = await myFavoriteAdd({ productIdList: [productId.value] })
+      if (res.code === '200') {
+        detail.value.isFavorite = true
+        toast.success(t('productDetail.favoriteSuccess'))
+      }
+    }
+  }
+  catch (error) {
+    console.error('收藏操作失败:', error)
+  }
+}
+
 // 预下单
 async function preOrder() {
   if (!requireLogin()) {
@@ -428,13 +465,26 @@ onShow(() => {
       <view class="flex gap-32rpx bg-white/60 px-28rpx py-30rpx backdrop-blur-20">
         <view class="flex items-center justify-between gap-20rpx">
           <view class="flex flex-col items-center justify-center">
-            <wd-icon color="#BDBDBD" name="home" size="40rpx" />
+            <image
+              src="/static/icons/go-home.png"
+              class="h-40rpx w-40rpx"
+              @click="goHome"
+            />
             <text class="text-18rpx text-#757575">
               {{ $t('productDetail.home') }}
             </text>
           </view>
-          <view class="flex flex-col items-center justify-center">
-            <wd-icon color="#BDBDBD" name="heart-filled" size="40rpx" />
+          <view class="flex flex-col items-center justify-center" @click="toggleFavorite">
+            <image
+              v-if="detail.isFavorite"
+              src="/static/icons/favorite-active.png"
+              class="h-40rpx w-40rpx"
+            />
+            <image
+              v-else
+              src="/static/icons/favorite.png"
+              class="h-40rpx w-40rpx"
+            />
             <text class="text-18rpx text-#757575">
               {{ $t('productDetail.favorite') }}
             </text>

BIN
src/static/icons/favorite-active.png


BIN
src/static/icons/favorite.png


BIN
src/static/icons/gift.png


BIN
src/static/icons/go-home.png