lf-pickup-code.vue
5.92 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<template>
<view class="pickup-code-card">
<view class="pickup-code-head">
<view>
<text class="pickup-code-kicker">{{ used ? 'VERIFIED PASS' : 'PICKUP QR PASS' }}</text>
<text class="pickup-code-title">{{ title }}</text>
</view>
<text class="pickup-code-status" :class="{ used }">{{ used ? '已核销' : '待核销' }}</text>
</view>
<view class="pickup-code-panel">
<view class="qr-frame">
<view class="qr-board">
<view v-for="(cell, index) in cells" :key="index" class="qr-cell" :class="{ filled: cell }"></view>
<view class="qr-center-badge">
<text class="qr-center-text">绿纤</text>
</view>
</view>
</view>
</view>
<text class="pickup-code-text">{{ code }}</text>
<text class="pickup-code-desc">{{ desc }}</text>
</view>
</template>
<script>
const SIZE = 29
const FINDER_SIZE = 7
const createMatrix = (size, fill = false) => Array.from({ length: size }, () => Array.from({ length: size }, () => fill))
const setFinder = (matrix, reserved, startRow, startCol) => {
for (let row = 0; row < FINDER_SIZE; row += 1) {
for (let col = 0; col < FINDER_SIZE; col += 1) {
const globalRow = startRow + row
const globalCol = startCol + col
const outer = row === 0 || row === FINDER_SIZE - 1 || col === 0 || col === FINDER_SIZE - 1
const inner = row >= 2 && row <= 4 && col >= 2 && col <= 4
matrix[globalRow][globalCol] = outer || inner
reserved[globalRow][globalCol] = true
}
}
}
const setAlignment = (matrix, reserved, centerRow, centerCol) => {
for (let row = -2; row <= 2; row += 1) {
for (let col = -2; col <= 2; col += 1) {
const globalRow = centerRow + row
const globalCol = centerCol + col
if (globalRow < 0 || globalRow >= SIZE || globalCol < 0 || globalCol >= SIZE) {
continue
}
const outer = Math.abs(row) === 2 || Math.abs(col) === 2
const core = row === 0 && col === 0
matrix[globalRow][globalCol] = outer || core
reserved[globalRow][globalCol] = true
}
}
}
const createSeed = code => String(code || 'LQ-0000').split('').reduce((sum, ch, index) => sum + ch.charCodeAt(0) * (index + 3), 97)
export default {
props: {
code: {
type: String,
default: 'LQ-5001-0101'
},
title: {
type: String,
default: '门店核销二维码'
},
desc: {
type: String,
default: '到店后出示二维码,门店核销后即可自提。'
},
used: {
type: Boolean,
default: false
}
},
computed: {
cells() {
const matrix = createMatrix(SIZE)
const reserved = createMatrix(SIZE)
setFinder(matrix, reserved, 0, 0)
setFinder(matrix, reserved, 0, SIZE - FINDER_SIZE)
setFinder(matrix, reserved, SIZE - FINDER_SIZE, 0)
setAlignment(matrix, reserved, SIZE - 7, SIZE - 7)
for (let index = 0; index < SIZE; index += 1) {
if (!reserved[6][index]) {
matrix[6][index] = index % 2 === 0
reserved[6][index] = true
}
if (!reserved[index][6]) {
matrix[index][6] = index % 2 === 0
reserved[index][6] = true
}
}
let seed = createSeed(this.code)
for (let row = 0; row < SIZE; row += 1) {
for (let col = 0; col < SIZE; col += 1) {
if (reserved[row][col]) {
continue
}
seed = (seed * 1103515245 + 12345 + row * 31 + col * 17) & 0x7fffffff
matrix[row][col] = (seed % 100) < 46
}
}
const centerStart = 11
const centerEnd = 17
for (let row = centerStart; row <= centerEnd; row += 1) {
for (let col = centerStart; col <= centerEnd; col += 1) {
matrix[row][col] = false
}
}
return matrix.flat()
}
}
}
</script>
<style lang="scss" scoped>
@import '@/styles/mixins.scss';
.pickup-code-card {
@include glass-panel(0.92);
padding: 32rpx;
margin-bottom: 24rpx;
}
.pickup-code-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20rpx;
}
.pickup-code-kicker,
.pickup-code-title,
.pickup-code-status,
.pickup-code-text,
.pickup-code-desc {
display: block;
}
.pickup-code-kicker {
font-size: 20rpx;
letter-spacing: 4rpx;
color: rgba(143, 118, 86, 0.82);
}
.pickup-code-title {
margin-top: 12rpx;
font-size: 30rpx;
font-weight: 700;
color: $text-primary;
}
.pickup-code-status {
@include chip-soft;
white-space: nowrap;
}
.pickup-code-status.used {
@include chip-rose;
}
.pickup-code-panel {
display: flex;
justify-content: center;
margin-top: 28rpx;
}
.qr-frame {
padding: 22rpx;
border-radius: 40rpx;
background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 250, 247, 0.98));
box-shadow: inset 0 1rpx 0 rgba(255, 255, 255, 0.92), 0 20rpx 42rpx rgba(54, 77, 64, 0.08);
}
.qr-board {
position: relative;
width: 430rpx;
height: 430rpx;
padding: 18rpx;
display: grid;
grid-template-columns: repeat(29, 1fr);
gap: 2rpx;
border-radius: 28rpx;
background: #ffffff;
}
.qr-cell {
border-radius: 2rpx;
background: rgba(255, 255, 255, 1);
}
.qr-cell.filled {
background: #111111;
}
.qr-center-badge {
position: absolute;
left: 50%;
top: 50%;
width: 86rpx;
height: 86rpx;
margin-left: -43rpx;
margin-top: -43rpx;
border-radius: 26rpx;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(145deg, #ffffff, #f3f6f1);
border: 8rpx solid #ffffff;
box-shadow: 0 10rpx 24rpx rgba(54, 77, 64, 0.08);
}
.qr-center-text {
font-size: 24rpx;
font-weight: 700;
letter-spacing: 4rpx;
color: $brand-primary-deep;
}
.pickup-code-text {
margin-top: 24rpx;
text-align: center;
font-size: 28rpx;
font-weight: 700;
letter-spacing: 4rpx;
color: $brand-primary-deep;
}
.pickup-code-desc {
margin-top: 14rpx;
text-align: center;
font-size: 23rpx;
line-height: 1.8;
color: $text-secondary;
}
</style>