preview.vue
16.8 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
<template>
<view class="page">
<view class="header-hero" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="top-bar">
<view class="top-left" @click="goBack">
<AppIcon name="chevronLeft" size="sm" color="white" />
</view>
<view class="top-center">
<text class="page-title">Label Preview</text>
<LocationPicker />
</view>
<view class="top-right" @click="isMenuOpen = true">
<AppIcon name="menu" size="sm" color="white" />
</view>
</view>
</view>
<view class="content">
<view class="food-card">
<view class="food-info">
<text class="food-name">{{ displayProductName }}</text>
<text class="food-cat">{{ productCategory }}</text>
<view v-if="labelTypeName" class="food-label-type">
<AppIcon name="tag" size="sm" color="primary" />
<text class="food-label-type-text">{{ labelTypeName }}</text>
</view>
</view>
<view class="food-template">
<text class="template-size">{{ templateSize }}</text>
<text class="template-name">{{ templateName }}</text>
</view>
</view>
<view class="qty-card">
<text class="qty-label">Print Quantity</text>
<view class="qty-control">
<view class="qty-btn" :class="{ disabled: printQty <= 1 }" @click="decrement">
<AppIcon name="minus" size="sm" color="gray" />
</view>
<text class="qty-value">{{ printQty }}</text>
<view class="qty-btn" @click="increment">
<AppIcon name="plus" size="sm" color="gray" />
</view>
</view>
</view>
<text class="section-title">Label Preview</text>
<view class="label-card">
<view class="label-img-wrap">
<image :src="labelImage" class="label-img" mode="widthFix" />
</view>
</view>
<view class="info-row">
<view class="info-item">
<text class="info-label">Last Edited</text>
<text class="info-value">{{ lastEdited }}</text>
</view>
<view class="info-item">
<text class="info-label">Location</text>
<text class="info-value">{{ locationName }}</text>
</view>
</view>
<view class="note-card">
<AppIcon name="alert" size="sm" color="blue" />
<text class="note-text">This is a preview of the label. Actual printed labels may vary slightly in appearance.</text>
</view>
</view>
<view class="bottom-bar">
<view class="bottom-info">
<text class="bottom-qty">{{ printQty }} label{{ printQty > 1 ? 's' : '' }}</text>
<view class="bt-indicator" :class="{ connected: btConnected }">
<text class="bt-dot" />
<text class="bt-name">{{ btConnected ? btDeviceName : 'No printer' }}</text>
</view>
</view>
<view class="bottom-actions">
<view class="btn-preview-sq" @click="showPreviewModal = true">
<AppIcon name="eye" size="md" color="primary" />
</view>
<view class="print-btn" :class="{ disabled: isPrinting }" @click="handlePrint">
<AppIcon name="printer" size="sm" color="white" />
<text class="print-btn-text">{{ isPrinting ? 'Printing...' : 'Print' }}</text>
</view>
</view>
</view>
<view v-if="showPreviewModal" class="modal-mask" @click="showPreviewModal = false">
<view class="modal-body modal-body-label-only" @click.stop>
<view class="modal-label-wrap">
<view class="modal-label-inner">
<image :src="labelImage" class="modal-label-img" mode="widthFix" />
</view>
</view>
</view>
</view>
<SideMenu v-model="isMenuOpen" />
</view>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import AppIcon from '../../components/AppIcon.vue'
import SideMenu from '../../components/SideMenu.vue'
import LocationPicker from '../../components/LocationPicker.vue'
import { getStatusBarHeight } from '../../utils/statusBar'
const statusBarHeight = getStatusBarHeight()
const isPrinting = ref(false)
const isMenuOpen = ref(false)
const printQty = ref(1)
const showPreviewModal = ref(false)
const btConnected = ref(false)
const btDeviceName = ref('')
const productName = ref('Chicken')
const productCategory = ref('Meat')
const labelTypeName = ref('')
const templateSize = ref('2"x2"')
const templateName = ref('Basic')
const lastEdited = ref('2025.12.03 11:45')
const locationName = ref('Location A')
const labelImage = computed(() => {
const size = templateSize.value
if (size.indexOf('2"x6"') >= 0 || size.indexOf('2"x4"') >= 0) {
return '/static/lable2.png'
}
return '/static/lable1.png'
})
// 产品名称按标签模板固定:lable1 → Syrup,lable2 → Cheese Burger Deluxe
const displayProductName = computed(() =>
labelImage.value.includes('lable1') ? 'Syrup' : 'Cheese Burger Deluxe'
)
onShow(() => {
const name = uni.getStorageSync('btDeviceName')
btConnected.value = !!name
btDeviceName.value = name || ''
})
interface ProductData {
name: string
category: string
templateSize: string
templateName: string
lastEdited: string
labelTypes: { id: string; name: string }[]
}
const productMap: Record<string, ProductData> = {
'chicken': { name: 'Chicken', category: 'Meat', templateSize: '2"x2"', templateName: 'Basic', lastEdited: '2025.12.03 11:45', labelTypes: [{ id: 'defrost', name: 'Defrost' }, { id: 'opened', name: 'Opened/Preped' }, { id: 'heated', name: 'Heated' }] },
'beef': { name: 'Beef', category: 'Meat', templateSize: '2"x2"', templateName: 'Basic', lastEdited: '2025.12.04 09:20', labelTypes: [{ id: 'defrost', name: 'Defrost' }, { id: 'opened', name: 'Opened/Preped' }, { id: 'heated', name: 'Heated' }] },
'bacon': { name: 'Bacon', category: 'Meat', templateSize: '2"x2"', templateName: 'Basic', lastEdited: '2025.12.03 14:30', labelTypes: [{ id: 'raw', name: 'Raw Bacon' }, { id: 'cooked', name: 'Cooked Bacon' }] },
'chicken-sandwich': { name: 'Chicken Sandwich', category: 'Sandwich', templateSize: '2"x6"', templateName: "G'n'G", lastEdited: '2025.12.03 11:45', labelTypes: [] },
'turkey-club': { name: 'Turkey Club', category: 'Sandwich', templateSize: '2"x6"', templateName: "G'n'G", lastEdited: '2025.12.04 09:30', labelTypes: [] },
'cheese-burger': { name: 'Cheese Burger', category: 'Sandwich', templateSize: '2"x6"', templateName: "G'n'G", lastEdited: '2025.12.03 15:20', labelTypes: [] },
'caesar-salad': { name: 'Caesar Salad', category: 'Salads', templateSize: '2"x4"', templateName: "G'n'G", lastEdited: '2025.12.04 09:00', labelTypes: [] },
'greek-salad': { name: 'Greek Salad', category: 'Salads', templateSize: '2"x4"', templateName: "G'n'G", lastEdited: '2025.12.03 12:30', labelTypes: [] },
'fresh-juice': { name: 'Fresh Juice', category: 'Beverages', templateSize: '2"x2"', templateName: "G'n'G", lastEdited: '2025.12.04 07:45', labelTypes: [] },
'smoothie': { name: 'Smoothie', category: 'Beverages', templateSize: '2"x2"', templateName: "G'n'G", lastEdited: '2025.12.03 11:00', labelTypes: [] },
'milk': { name: 'Milk', category: 'Dairy', templateSize: '2"x2"', templateName: 'Basic', lastEdited: '2025.12.04 08:30', labelTypes: [] },
'cheese': { name: 'Cheese', category: 'Dairy', templateSize: '2"x2"', templateName: 'Basic', lastEdited: '2025.12.03 11:15', labelTypes: [] },
'sliced-ham': { name: 'Sliced Ham', category: 'Deli', templateSize: '2"x2"', templateName: 'Basic', lastEdited: '2025.12.04 10:00', labelTypes: [] },
'turkey-deli': { name: 'Turkey Deli', category: 'Deli', templateSize: '2"x2"', templateName: 'Basic', lastEdited: '2025.12.03 14:20', labelTypes: [] },
}
onLoad((opts: any) => {
const pid = (opts && opts.productId) || 'chicken'
const subType = (opts && opts.subType) || ''
const product = productMap[pid]
if (product) {
productName.value = product.name
productCategory.value = product.category
templateSize.value = product.templateSize
templateName.value = product.templateName
lastEdited.value = product.lastEdited
if (subType) {
const found = product.labelTypes.filter(function (lt) { return lt.id === subType })
if (found.length > 0) {
labelTypeName.value = found[0].name
}
}
}
const storeId = uni.getStorageSync('storeId') || '001'
locationName.value = 'Location A'
})
const increment = () => { if (printQty.value < 99) printQty.value++ }
const decrement = () => { if (printQty.value > 1) printQty.value-- }
const goBack = () => uni.navigateBack()
const handlePrint = () => {
if (isPrinting.value) return
if (!btConnected.value) {
uni.showModal({
title: 'No Printer Connected',
content: 'Please connect a Bluetooth printer first.',
confirmText: 'Connect',
cancelText: 'Cancel',
success: (res) => {
if (res.confirm) uni.navigateTo({ url: '/pages/labels/bluetooth' })
},
})
return
}
isPrinting.value = true
setTimeout(() => {
isPrinting.value = false
uni.showToast({ title: printQty.value + ' label' + (printQty.value > 1 ? 's' : '') + ' printed!', icon: 'success' })
}, 2000)
}
</script>
<style scoped>
.page {
min-height: 100vh;
background: #f9fafb;
overflow-x: hidden;
overflow-x: clip;
width: 100%;
max-width: 100vw;
box-sizing: border-box;
}
.header-hero {
background: linear-gradient(135deg, var(--theme-primary), var(--theme-primary-dark));
padding: 16rpx 32rpx 24rpx;
}
.top-bar {
height: 96rpx;
display: flex;
align-items: center;
justify-content: space-between;
}
.top-left,
.top-right {
width: 64rpx;
height: 64rpx;
border-radius: 999rpx;
background: rgba(255, 255, 255, 0.15);
display: flex;
align-items: center;
justify-content: center;
}
.top-center {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
}
.page-title {
font-size: 34rpx;
font-weight: 600;
color: #fff;
display: block;
}
.content {
padding: 32rpx;
padding-bottom: 300rpx;
box-sizing: border-box;
overflow-x: hidden;
overflow-x: clip;
width: 100%;
max-width: 100%;
min-width: 0;
}
.food-card {
background: #fff;
padding: 28rpx;
border-radius: 20rpx;
margin-bottom: 24rpx;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}
.food-info {
flex: 1;
min-width: 0;
}
.food-name {
font-size: 32rpx;
font-weight: 600;
color: #111827;
display: block;
margin-bottom: 4rpx;
}
.food-cat {
font-size: 26rpx;
color: #6b7280;
display: block;
}
.food-label-type {
display: flex;
align-items: center;
gap: 8rpx;
margin-top: 12rpx;
}
.food-label-type-text {
font-size: 24rpx;
color: var(--theme-primary);
font-weight: 500;
}
.food-template {
flex-shrink: 0;
text-align: center;
background: #f3f4f6;
padding: 16rpx 20rpx;
border-radius: 14rpx;
}
.template-size {
font-size: 28rpx;
font-weight: 700;
color: #111827;
display: block;
}
.template-name {
font-size: 22rpx;
color: #6b7280;
display: block;
margin-top: 4rpx;
}
.qty-card {
display: flex;
align-items: center;
justify-content: space-between;
background: #fff;
padding: 24rpx 28rpx;
border-radius: 20rpx;
margin-bottom: 32rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}
.qty-label {
font-size: 30rpx;
font-weight: 600;
color: #111827;
}
.qty-control {
display: flex;
align-items: center;
}
.qty-btn {
width: 64rpx;
height: 64rpx;
border-radius: 14rpx;
background: #f3f4f6;
display: flex;
align-items: center;
justify-content: center;
}
.qty-btn:active {
background: #e5e7eb;
}
.qty-btn.disabled {
opacity: 0.35;
}
.qty-value {
width: 88rpx;
text-align: center;
font-size: 36rpx;
font-weight: 700;
color: #111827;
}
.section-title {
font-size: 30rpx;
font-weight: 600;
color: #111827;
display: block;
margin-bottom: 20rpx;
}
/* 使用 block 布局避免移动端 Safari flex+图片溢出问题 */
.label-card {
background: #fff;
border-radius: 20rpx;
overflow: hidden;
overflow-x: clip;
margin-bottom: 24rpx;
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.06);
padding: 24rpx 0;
display: block;
width: 100%;
max-width: 100%;
position: relative;
contain: layout;
}
.label-img-wrap {
width: 100%;
max-width: 100%;
overflow: hidden;
overflow-x: clip;
box-sizing: border-box;
position: relative;
}
/* 移动端:width:auto + max-width:100% 比 width:100% 更可靠 */
.label-img {
width: 100%;
max-width: 100%;
height: auto;
display: block;
vertical-align: top;
object-fit: contain;
border-radius: 12rpx;
box-sizing: border-box;
}
.info-row {
display: flex;
gap: 16rpx;
margin-bottom: 24rpx;
}
.info-item {
flex: 1;
background: #fff;
padding: 20rpx 24rpx;
border-radius: 16rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}
.info-label {
font-size: 22rpx;
color: #9ca3af;
display: block;
margin-bottom: 6rpx;
}
.info-value {
font-size: 26rpx;
font-weight: 600;
color: #111827;
display: block;
}
.note-card {
display: flex;
align-items: flex-start;
gap: 16rpx;
padding: 24rpx 28rpx;
background: #eff6ff;
border: 1rpx solid #bfdbfe;
border-radius: 16rpx;
}
.note-text {
flex: 1;
font-size: 26rpx;
color: #1e40af;
line-height: 1.5;
}
.bottom-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding: 20rpx 32rpx;
/* 兼容浏览器:env(safe-area-inset-bottom) + 最小 36px,避免打印按钮偏上/遮挡 */
padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 36px);
background: #fff;
border-top: 1rpx solid #e5e7eb;
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.04);
}
.bottom-info {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16rpx;
}
.bottom-qty {
font-size: 26rpx;
font-weight: 600;
color: #111827;
}
.bt-indicator {
display: flex;
align-items: center;
gap: 8rpx;
}
.bt-dot {
width: 12rpx;
height: 12rpx;
border-radius: 50%;
background: #d1d5db;
}
.bt-indicator.connected .bt-dot {
background: #4ade80;
}
.bt-name {
font-size: 24rpx;
color: #9ca3af;
}
.bt-indicator.connected .bt-name {
color: #16a34a;
}
.bottom-actions {
display: flex;
align-items: stretch;
gap: 24rpx;
}
.btn-preview-sq {
width: 100rpx;
height: 100rpx;
flex-shrink: 0;
background: #fff;
border: 2rpx solid #d1d5db;
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
}
.btn-preview-sq:active {
background: #f3f4f6;
}
.print-btn {
flex: 1;
min-width: 0;
height: 100rpx;
background: var(--theme-primary);
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
}
.print-btn.disabled {
opacity: 0.6;
}
.print-btn-text {
font-size: 30rpx;
font-weight: 600;
color: #fff;
line-height: 1;
}
.modal-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
z-index: 999;
padding: 24rpx;
}
.modal-body {
width: 100%;
max-width: 700rpx;
max-height: 85vh;
background: #fff;
border-radius: 24rpx;
overflow-x: hidden;
overflow-y: hidden;
display: flex;
flex-direction: column;
min-width: 0;
}
.modal-body-label-only .modal-label-wrap {
margin-bottom: 0;
padding: 24rpx;
}
.modal-top {
display: flex;
justify-content: space-between;
align-items: center;
padding: 28rpx 32rpx;
border-bottom: 1rpx solid #e5e7eb;
flex-shrink: 0;
}
.modal-title {
font-size: 30rpx;
font-weight: 600;
color: #111827;
}
.modal-close {
width: 52rpx;
height: 52rpx;
display: flex;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #f3f4f6;
transform: rotate(45deg);
}
.modal-scroll {
flex: 1;
min-width: 0;
padding: 28rpx 40rpx;
overflow-y: auto;
overflow-x: hidden;
overflow-x: clip;
box-sizing: border-box;
}
.modal-label-wrap {
width: 100%;
max-width: 100%;
margin-bottom: 24rpx;
padding: 0;
box-sizing: border-box;
overflow: hidden;
overflow-x: clip;
}
.modal-label-inner {
width: 100%;
max-width: 100%;
min-width: 0;
overflow: hidden;
overflow-x: clip;
box-sizing: border-box;
}
.modal-label-img {
width: 100%;
max-width: 100%;
height: auto;
display: block;
vertical-align: top;
object-fit: contain;
border-radius: 12rpx;
box-sizing: border-box;
}
.modal-info {
text-align: center;
}
.modal-info-text {
font-size: 30rpx;
font-weight: 600;
color: #111827;
display: block;
margin-bottom: 8rpx;
}
.modal-info-sub {
font-size: 24rpx;
color: #6b7280;
display: block;
margin-bottom: 4rpx;
}
/* 移动端额外约束,防止部分浏览器仍出现溢出 */
@media screen and (max-width: 768px) {
.page,
.content,
.label-card,
.label-img-wrap {
max-width: 100vw;
}
.label-img,
.modal-label-img {
max-width: 100% !important;
}
}
</style>