1 line
12 KiB
Plaintext
1 line
12 KiB
Plaintext
{"version":3,"sources":["pages/mall/consumer/favorites.uvue","pages/user/change-password.uvue","pages/user/login.uvue","pages/user/center.uvue","uni_modules/ak-req/ak-req.uts"],"sourcesContent":["<template>\r\n <scroll-view class=\"favorites-page\" direction=\"vertical\">\r\n <view class=\"product-grid\">\r\n <view v-if=\"favorites.length === 0\" class=\"empty-state\">\r\n <text class=\"empty-icon\">❤️</text>\r\n <text class=\"empty-text\">暂无收藏商品</text>\r\n <button class=\"go-shopping-btn\" @click=\"goShopping\">去逛逛</button>\r\n </view>\r\n \r\n <view v-else v-for=\"(product, index) in favorites\" :key=\"index\" class=\"product-item\" @click=\"goToDetail(product.id)\">\r\n <image :src=\"product.image\" class=\"product-image\" mode=\"aspectFill\" />\r\n <view class=\"product-info\">\r\n <text class=\"product-name\">{{ product.name }}</text>\r\n <text class=\"product-price\">¥{{ product.price }}</text>\r\n <view class=\"product-footer\">\r\n <text class=\"product-sales\">已售 {{ product.sales }}</text>\r\n <view class=\"action-btns\">\r\n <view class=\"cart-btn\" @click.stop=\"addToCart(product)\">\r\n <text class=\"cart-icon\">🛒</text>\r\n </view>\r\n <view class=\"remove-btn\" @click.stop=\"removeFavorite(product.id)\">\r\n <text class=\"remove-icon\">🗑️</text>\r\n </view>\r\n </view>\r\n </view>\r\n </view>\r\n </view>\r\n </view>\r\n </scroll-view>\r\n</template>\r\n\r\n<script setup lang=\"uts\">\r\nimport { ref, onMounted } from 'vue'\r\nimport { supabaseService } from '@/utils/supabaseService.uts'\r\n\r\ntype Product = {\r\n id: string\r\n name: string\r\n price: number\r\n image: string\r\n sales: number\r\n shopId?: string\r\n shopName?: string\r\n}\r\n\r\nconst favorites = ref<Product[]>([])\r\n\r\nconst addToCart = async (product: Product) => {\r\n uni.showLoading({ title: '添加中' })\r\n const success = await supabaseService.addToCart(product.id, 1, '')\r\n uni.hideLoading()\r\n if (success) {\r\n uni.showToast({ title: '已添加到购物车', icon: 'success' })\r\n } else {\r\n uni.showToast({ title: '添加失败', icon: 'none' })\r\n }\r\n}\r\n\r\nconst loadFavorites = async () => {\r\n const res = await supabaseService.getFavorites()\r\n \r\n favorites.value = res.map((item: any): Product => {\r\n let prod: any | null = null\r\n let itemObj: UTSJSONObject | null = null\r\n \r\n if (item instanceof UTSJSONObject) {\r\n itemObj = item as UTSJSONObject\r\n prod = itemObj.get('ml_products')\r\n } else {\r\n itemObj = JSON.parse(JSON.stringify(item)) as UTSJSONObject\r\n prod = itemObj.get('ml_products')\r\n }\r\n \r\n let image = '/static/default-product.png'\r\n let id = ''\r\n let name = '未知商品'\r\n let price = 0\r\n let sales = 0\r\n \r\n if (prod != null) {\r\n let prodObj: UTSJSONObject\r\n if (prod instanceof UTSJSONObject) {\r\n prodObj = prod as UTSJSONObject\r\n } else {\r\n prodObj = JSON.parse(JSON.stringify(prod)) as UTSJSONObject\r\n }\r\n \r\n id = prodObj.getString('id') ?? ''\r\n name = prodObj.getString('name') ?? '未知商品'\r\n price = prodObj.getNumber('base_price') ?? 0\r\n image = prodObj.getString('main_image_url') ?? image\r\n sales = prodObj.getNumber('sale_count') ?? 0\r\n \r\n if (image === '/static/default-product.png') {\r\n const imgUrls = prodObj.getString('image_urls')\r\n if (imgUrls != null) {\r\n try {\r\n const arr = JSON.parse(imgUrls)\r\n if (Array.isArray(arr) && arr.length > 0) {\r\n image = arr[0] as string\r\n }\r\n } catch(e) {}\r\n }\r\n }\r\n } else {\r\n if (itemObj != null) {\r\n id = itemObj.getString('target_id') ?? ''\r\n }\r\n }\r\n\r\n return {\r\n id: id,\r\n name: name,\r\n price: price,\r\n image: image,\r\n sales: sales,\r\n shopId: '', \r\n shopName: ''\r\n } as Product\r\n })\r\n}\r\n\r\nconst goShopping = () => {\r\n uni.switchTab({\r\n url: '/pages/mall/consumer/index'\r\n })\r\n}\r\n\r\nconst goToDetail = (id: string) => {\r\n uni.navigateTo({\r\n url: `/pages/mall/consumer/product-detail?productId=${id}`\r\n })\r\n}\r\n\r\nconst removeFavorite = (id: string) => {\r\n uni.showModal({\r\n title: '取消收藏',\r\n content: '确定要取消收藏该商品吗?',\r\n success: (res) => {\r\n if (res.confirm) {\r\n supabaseService.toggleFavorite(id).then((isStillFavorite) => {\r\n if (!isStillFavorite) {\r\n const index = favorites.value.findIndex((item): Boolean => {\r\n return item.id === id\r\n })\r\n if (index !== -1) {\r\n favorites.value.splice(index, 1)\r\n }\r\n uni.showToast({\r\n title: '已取消收藏',\r\n icon: 'none'\r\n })\r\n } else {\r\n uni.showToast({\r\n title: '取消失败',\r\n icon: 'none'\r\n })\r\n }\r\n })\r\n }\r\n }\r\n })\r\n}\r\n\r\nonMounted(() => {\r\n loadFavorites()\r\n})\r\n</script>\r\n\r\n<style>\r\n.favorites-page {\r\n padding: 15px;\r\n background-color: #f5f5f5;\r\n flex: 1;\r\n}\r\n\r\n.product-grid {\r\n display: flex;\r\n flex-direction: row;\r\n flex-wrap: wrap;\r\n justify-content: space-between;\r\n width: 100%;\r\n}\r\n\r\n.empty-state {\r\n width: 100%;\r\n display: flex;\r\n flex-direction: column;\r\n align-items: center;\r\n justify-content: center;\r\n padding-top: 100px;\r\n}\r\n\r\n.empty-icon {\r\n font-size: 60px;\r\n margin-bottom: 20px;\r\n color: #ddd;\r\n}\r\n\r\n.empty-text {\r\n font-size: 16px;\r\n color: #999;\r\n margin-bottom: 20px;\r\n}\r\n\r\n.go-shopping-btn {\r\n background-color: #ff5000;\r\n color: white;\r\n padding: 8px 24px;\r\n border-radius: 20px;\r\n font-size: 14px;\r\n border: none;\r\n}\r\n\r\n.product-item {\r\n width: 48%; /* Default Mobile: 2 items per row */\r\n background-color: white;\r\n border-radius: 8px;\r\n overflow: hidden;\r\n display: flex;\r\n flex-direction: column;\r\n box-sizing: border-box; /* Important for grid */\r\n}\r\n\r\n/* PC/Tablet Responsive */\r\n@media (min-width: 768px) {\r\n .product-item {\r\n width: 31% !important; /* Tablet: 3 items (gap 15px roughly distributed) */\r\n }\r\n}\r\n\r\n@media (min-width: 1024px) {\r\n .product-item {\r\n width: 15% !important; /* PC: 6 items */\r\n }\r\n \r\n /* Center content on large screens */\r\n .product-grid, .header {\r\n max-width: 1200px;\r\n margin: 0 auto;\r\n }\r\n}\r\n\r\n.product-image {\r\n width: 100%;\r\n height: 170px;\r\n background-color: #f5f5f5;\r\n}\r\n\r\n.product-info {\r\n padding: 10px;\r\n display: flex;\r\n flex-direction: column;\r\n flex: 1;\r\n}\r\n\r\n.product-name {\r\n font-size: 14px;\r\n color: #333;\r\n margin-bottom: 6px;\r\n text-overflow: ellipsis;\r\n lines: 2;\r\n overflow: hidden;\r\n height: 40px;\r\n line-height: 20px;\r\n}\r\n\r\n.product-price {\r\n font-size: 16px;\r\n color: #ff5000;\r\n font-weight: bold;\r\n margin-bottom: 6px;\r\n}\r\n\r\n.product-footer {\r\n display: flex;\r\n justify-content: space-between;\r\n align-items: center;\r\n margin-top: auto;\r\n}\r\n\r\n.product-sales {\r\n font-size: 12px;\r\n color: #999;\r\n}\r\n\r\n.action-btns {\r\n display: flex;\r\n flex-direction: row;\r\n align-items: center;\r\n}\r\n\r\n.cart-btn, .remove-btn {\r\n width: 28px;\r\n height: 28px;\r\n border-radius: 14px;\r\n display: flex;\r\n align-items: center;\r\n justify-content: center;\r\n margin-left: 8px; /* Replacement for gap */\r\n}\r\n\r\n.cart-btn {\r\n background-color: #ff5000;\r\n}\r\n\r\n.cart-icon {\r\n font-size: 14px;\r\n color: white;\r\n}\r\n\r\n.remove-btn {\r\n background-color: #f0f0f0;\r\n}\r\n\r\n.remove-icon {\r\n font-size: 14px;\r\n}\r\n</style>\r\n",null,null,null,null],"names":[],"mappings":";;;;;;;;;;;;;;;;+BAqDG,eAAA;;;+BAwBkB,aAAA;;;;;;;;;YAhCrB,IAAM,YAAY,QAAI;YAEtB,IAAM,YAAY,IAAO,SAAS,aAAO,WAAA,IAAA,EAAI;gBAAA,OAAA,eAAA;wBAM1C,mCALiB,QAAO;wBACzB,IAAM,UAAU,MA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