| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <template>
- <view class="section">
- <view class="section-header">
- <text class="section-title">🛍️ 推荐商品</text>
- <text class="section-more" @click="$emit('moreProducts')">更多 ›</text>
- </view>
- <view class="product-list">
- <!-- 无数据时显示占位卡片 -->
- <template v-if="!displayProducts || displayProducts.length === 0">
- <view class="product-card" v-for="i in 2" :key="'ph-' + i">
- <view class="product-img-placeholder"></view>
- <text class="product-name line-clamp-2">暂无推荐商品</text>
- <text class="product-price">--</text>
- </view>
- </template>
- <!-- 有数据时显示商品卡片 -->
- <template v-else>
- <view class="product-card" v-for="prod in displayProducts" :key="prod.id" @click="$emit('productClick', prod)">
- <image class="product-img" :src="prod.coverImage || '/static/default-product.png'" mode="aspectFill" />
- <text class="product-name line-clamp-2">{{ prod.name }}</text>
- <text class="product-price" v-if="prod.priceLabel">{{ prod.priceLabel }}</text>
- <text class="product-price" v-else-if="prod.price">{{ formatPriceWithSymbol(prod.price) }}</text>
- <text class="product-price" v-else>免费</text>
- </view>
- </template>
- </view>
- </view>
- </template>
- <script>
- export default {
- props: {
- dimensionCode: { type: String, required: true },
- products: { type: Array, default: function() { return [] } },
- isLoggedIn: { type: Boolean, default: false }
- },
- computed: {
- displayProducts: function() {
- return this.products
- }
- },
- methods: {
- formatPriceWithSymbol: function(price) {
- if (price == null) return '免费'
- return '¥' + (Number(price) / 100).toFixed(0)
- }
- }
- }
- </script>
- <style scoped>
- .section {
- margin: 20rpx 20rpx;
- }
- .section-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 20rpx;
- }
- .section-title {
- font-size: 30rpx;
- font-weight: bold;
- color: #333;
- }
- .section-more {
- font-size: 24rpx;
- color: #999;
- }
- .product-list {
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- gap: 16rpx;
- }
- .product-card {
- width: calc(50% - 8rpx);
- background: #fff;
- border-radius: 16rpx;
- padding: 16rpx;
- box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
- box-sizing: border-box;
- }
- .product-card:active {
- opacity: 0.8;
- }
- .product-img {
- width: 100%;
- height: 200rpx;
- border-radius: 12rpx;
- background: #f0f0f0;
- display: block;
- }
- .product-img-placeholder {
- width: 100%;
- height: 200rpx;
- border-radius: 12rpx;
- background: linear-gradient(135deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
- background-size: 200% 100%;
- animation: shimmer 1.5s infinite;
- margin-bottom: 10rpx;
- }
- @keyframes shimmer {
- 0% { background-position: 200% 0; }
- 100% { background-position: -200% 0; }
- }
- .product-name {
- font-size: 26rpx;
- color: #333;
- font-weight: 500;
- display: block;
- margin: 8rpx 0 6rpx;
- min-height: 36rpx;
- }
- .product-price {
- font-size: 24rpx;
- color: #F97316;
- font-weight: 600;
- }
- .line-clamp-2 {
- overflow: hidden;
- text-overflow: ellipsis;
- display: -webkit-box;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- }
- </style>
|