uniapp实现简单瀑布流

uniapp实现简单瀑布流

DansRoh Lv4

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<template>
<view class="productList">
<view @click="handleClick(item.id)" class="productItem" v-for="(item,index) in list" :key="item.id">
<image class="productImage" :src="item.pic" lazy-load="true" mode="widthFix"></image>
<view class="container">
<view class="productName">{{ item.name }}</view>
<view class="priceBox">
<view>
<text class="priceIcon">¥</text>
{{ item.price }}
<text class="unit" v-if="item.tag">/箱</text>
</view>
<view class="iconBox">
<uni-icons color="#fff" type="cart" size="32rpx"></uni-icons>
</view>
</view>
<view v-if="item.tag" class="tag">
<view class="iconBoxTag">
<image class="medalsIcon" :src="getStatic('/index/medals.png')" mode="scaleToFill"></image>
</view>
<view class="tagText">{{item.tag}}</view>
<view class="tagOrder">TOP 1</view>
</view>
</view>
</view>
</view>
</template>

<script>
import {getStatic} from "@/utils/global";

export default {
props: {
listData: {
type: Array,
default: []
}
},
data() {
return {
};
},
computed: {
list() {
return this.reorderArrayForColumns(this.listData).map(item=>{
let price = item.price
if(item.promotionType === 1 && item.promotionStartTime && item.promotionEndTime){
const now = Date.now()
if(now >= new Date(item.promotionStartTime).valueOf() && now <= new Date(item.promotionEndTime).valueOf()){
//在促销时间内
price = item.promotionPrice
}
}
return {...item, price}
})
}
},
methods: {
getStatic,
handleClick(id) {
uni.navigateTo({
url: `/pages/product/product?id=${id}&type=normal`
})
},
// 处理数据渲染的排序问题
reorderArrayForColumns(arr) {
let arr1 = [];
let arr2 = [];
arr1 = arr.filter((item, index) => ((index+1) % 2 !== 0))
arr2 = arr.filter((item, index) => ((index+1) % 2 === 0))
return [...arr1, ...arr2];
},
}
}
</script>

<style lang="scss" scoped>

.productList {
margin-top: 20rpx;
column-count: 2;
column-gap: 20rpx;
}

.productItem {
box-sizing: border-box;
width: 344rpx;
border-radius: 15rpx;
overflow: hidden;
background-color: #fff;
break-inside: avoid;
margin-bottom: 20rpx;
box-shadow: 0 0 28rpx 1rpx rgba(78, 101, 153, 0.14);
}

.productItem .productImage {
width: 344rpx;
}

.container {
padding: 0 22rpx 30rpx 22rpx;
font-size: 24rpx;

.productName {
color: #212121;
font-size: 28rpx;
font-weight: 500;
}

.priceBox {
color: #ff0000;
font-size: 40rpx;
line-height: 32rpx;
font-weight: bold;
padding-top: 22rpx;
display: flex;
justify-content: space-between;
align-items: center;

.priceIcon {
font-size: 26rpx;
}
.unit {
font-size: 28rpx;
color: #CFCFCF;
}
.iconBox {
width: 52rpx;
height: 52rpx;
border-radius: 50%;
overflow: hidden;
background: linear-gradient( 180deg, #FA2C19 0%, #FE5617 100%);
display: flex;
justify-content: center;
align-items: center;
}
}
.tag {
margin-top: 20rpx;
width: 304rpx;
height: 48rpx;
background: #FAF5EC;
border-radius: 8rpx;
display: flex;
align-items: center;
.iconBoxTag {
width: 52rpx;
height: 48rpx;
overflow: hidden;
background: linear-gradient( 166deg, #E3CB8B 0%, #D5A443 100%);
border-radius: 8rpx 0rpx 8rpx 8rpx;
display: flex;
align-items: center;
justify-content: center;
.medalsIcon {
width: 36rpx;
height: 36rpx;
}
}
.tagText{
margin-left: 16rpx;
font-weight: 500;
font-size: 26rpx;
color: #C89839;
}
.tagOrder {
margin-left: 8rpx;
font-size: 26rpx;
color: #C89839;
font-weight: 500;
}
}
}
</style>

  • 标题: uniapp实现简单瀑布流
  • 作者: DansRoh
  • 创建于 : 2024-09-05 00:00:00
  • 更新于 : 2024-09-05 10:00:58
  • 链接: https://blog.shinri.me/2024/09/05/40_uniapp实现简单瀑布流/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
此页目录
uniapp实现简单瀑布流