From 9927b97ee7774f64e0bf75edecf2cc8d889aec0a Mon Sep 17 00:00:00 2001 From: “wangming” <“wangming@antissoft.com”> Date: Fri, 20 Mar 2026 20:54:36 +0800 Subject: [PATCH] Improve GP_R3 printing flow and printer onboarding Enhance TCP built-in fallback with port probing and update label/Bluetooth print templates. --- 美国版/Food Labeling Management App UniApp/src/pages/labels/bluetooth.vue | 27 +++++++++++++++++++++++---- 美国版/Food Labeling Management App UniApp/src/pages/labels/labels.vue | 7 ++++--- 美国版/Food Labeling Management App UniApp/src/pages/labels/preview.vue | 25 ++++++++++++++++++------- 美国版/Food Labeling Management App UniApp/src/pages/more/printers.vue | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- 美国版/Food Labeling Management App UniApp/src/utils/deviceInfo.ts | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/bluetoothTool.js | 143 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 美国版/Food Labeling Management App UniApp/src/utils/print/drivers/d320fax.ts | 2 ++ 美国版/Food Labeling Management App UniApp/src/utils/print/drivers/genericTsc.ts | 2 ++ 美国版/Food Labeling Management App UniApp/src/utils/print/drivers/gpR3.ts | 2 ++ 美国版/Food Labeling Management App UniApp/src/utils/print/imageRaster.ts | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/manager/printerManager.ts | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 美国版/Food Labeling Management App UniApp/src/utils/print/printerConnection.ts | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 美国版/Food Labeling Management App UniApp/src/utils/print/protocols/escPosBuilder.ts | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- 美国版/Food Labeling Management App UniApp/src/utils/print/protocols/tscProtocol.ts | 33 ++++++++++++++++++++++++++++++--- 美国版/Food Labeling Management App UniApp/src/utils/print/systemTemplateAdapter.ts | 376 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/templateRenderer.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/templates/previewSystemTemplate.ts | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/templates/test.json | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/templates/testPrintTemplate.ts | 21 +++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/testPrintCanvas.ts | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/tscLabelBuilder.ts | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- 美国版/Food Labeling Management App UniApp/src/utils/print/types/printer.ts | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 22 files changed, 1931 insertions(+), 98 deletions(-) create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/deviceInfo.ts create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/imageRaster.ts create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/systemTemplateAdapter.ts create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/templateRenderer.ts create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/templates/previewSystemTemplate.ts create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/templates/test.json create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/templates/testPrintTemplate.ts create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/testPrintCanvas.ts diff --git a/美国版/Food Labeling Management App UniApp/src/pages/labels/bluetooth.vue b/美国版/Food Labeling Management App UniApp/src/pages/labels/bluetooth.vue index ea39e5d..9812a8c 100644 --- a/美国版/Food Labeling Management App UniApp/src/pages/labels/bluetooth.vue +++ b/美国版/Food Labeling Management App UniApp/src/pages/labels/bluetooth.vue @@ -17,8 +17,9 @@ - + Bluetooth Debug Status Current Mode: {{ debugInfo.currentMode }} + Available Mode: {{ availablePrinterTypesLabel }} + Device Model: {{ deviceIdentity.model || '-' }} + Device Brand: {{ deviceIdentity.brand || '-' }} + Device Product: {{ deviceIdentity.product || '-' }} Classic Module: {{ debugInfo.classicModuleReady ? 'Ready' : 'Not Ready' }} Paired Count: {{ debugInfo.pairedCount }} Virtual BT Printer: {{ debugInfo.foundVirtualPrinter ? 'Found' : 'Not Found' }} @@ -60,7 +66,7 @@ - + {{ connectedDevice.name }} @@ -167,9 +173,11 @@ import AppIcon from '../../components/AppIcon.vue' import SideMenu from '../../components/SideMenu.vue' import LocationPicker from '../../components/LocationPicker.vue' import { getStatusBarHeight } from '../../utils/statusBar' +import { getDeviceIdentity } from '../../utils/deviceInfo' import classicBluetooth from '../../utils/print/bluetoothTool.js' import { getPrinterType, + getAvailablePrinterTypes, clearPrinter, type PrinterType, } from '../../utils/print/printerConnection' @@ -189,7 +197,14 @@ const isScanning = ref(false) const connectingId = ref('') const errorMsg = ref('') const btAdapterReady = ref(false) -const printerType = ref(getPrinterType() || 'bluetooth') +const availablePrinterTypes = getAvailablePrinterTypes() +const availablePrinterTypesLabel = availablePrinterTypes.map(item => item === 'builtin' ? 'Built-in' : 'Bluetooth').join(' / ') +const deviceIdentity = getDeviceIdentity() +const storedPrinterType = getPrinterType() +const preferredPrinterType = (storedPrinterType && availablePrinterTypes.includes(storedPrinterType as PrinterType)) + ? storedPrinterType as PrinterType + : availablePrinterTypes[0] +const printerType = ref(preferredPrinterType || 'bluetooth') const currentPrinter = ref(getCurrentPrinterSummary()) const debugInfo = ref({ currentMode: 'none', @@ -211,6 +226,8 @@ interface BtDevice { const devices = ref([]) const discoveredIds = new Set() +const isBluetoothModeAvailable = availablePrinterTypes.includes('bluetooth') +const isBuiltinModeAvailable = availablePrinterTypes.includes('builtin') function refreshCurrentPrinter () { currentPrinter.value = getCurrentPrinterSummary() @@ -237,6 +254,7 @@ const connectedDevice = computed(() => { }) function switchType (type: 'bluetooth' | 'builtin') { + if (!availablePrinterTypes.includes(type)) return printerType.value = type if (type === 'bluetooth' && getPrinterType() === 'builtin') { clearPrinter() @@ -487,6 +505,7 @@ const handleTestPrint = async () => { if (testPrinting.value) return testPrinting.value = true try { + uni.showLoading({ title: 'Preparing test print...', mask: true }) await testPrintCurrentPrinter((p) => { if (p < 100) uni.showLoading({ title: `Printing ${p}%`, mask: true }) }) @@ -533,7 +552,7 @@ onMounted(() => { errorMsg.value = '' } }) - printerType.value = getPrinterType() || 'bluetooth' + printerType.value = preferredPrinterType || 'bluetooth' refreshCurrentPrinter() }) diff --git a/美国版/Food Labeling Management App UniApp/src/pages/labels/labels.vue b/美国版/Food Labeling Management App UniApp/src/pages/labels/labels.vue index 2fd3241..a430d78 100644 --- a/美国版/Food Labeling Management App UniApp/src/pages/labels/labels.vue +++ b/美国版/Food Labeling Management App UniApp/src/pages/labels/labels.vue @@ -146,6 +146,7 @@ import AppIcon from '../../components/AppIcon.vue' import SideMenu from '../../components/SideMenu.vue' import LocationPicker from '../../components/LocationPicker.vue' import { getStatusBarHeight } from '../../utils/statusBar' +import { getCurrentPrinterSummary } from '../../utils/print/manager/printerManager' const statusBarHeight = getStatusBarHeight() const isMenuOpen = ref(false) @@ -160,9 +161,9 @@ const btConnected = ref(false) const btDeviceName = ref('') onShow(() => { - const name = uni.getStorageSync('btDeviceName') - btConnected.value = !!name - btDeviceName.value = name || '' + const summary = getCurrentPrinterSummary() + btConnected.value = summary.type === 'bluetooth' || summary.type === 'builtin' + btDeviceName.value = summary.displayName || '' }) const labelCategories = [ diff --git a/美国版/Food Labeling Management App UniApp/src/pages/labels/preview.vue b/美国版/Food Labeling Management App UniApp/src/pages/labels/preview.vue index f6b9771..101e955 100644 --- a/美国版/Food Labeling Management App UniApp/src/pages/labels/preview.vue +++ b/美国版/Food Labeling Management App UniApp/src/pages/labels/preview.vue @@ -118,8 +118,11 @@ import SideMenu from '../../components/SideMenu.vue' import LocationPicker from '../../components/LocationPicker.vue' import { getStatusBarHeight } from '../../utils/statusBar' import { generateNextLabelId } from '../../utils/printLog' -import { getCurrentPrinterSummary, printLabelForCurrentPrinter } from '../../utils/print/manager/printerManager' +import { getCurrentPrinterSummary, printSystemTemplateForCurrentPrinter } from '../../utils/print/manager/printerManager' +import { PREVIEW_SYSTEM_TEMPLATE } from '../../utils/print/templates/previewSystemTemplate' import chickenLabelImg from '../../static/chicken-lable.png' +import label1Img from '../../static/lable1.png' +import label2Img from '../../static/lable2.png' const statusBarHeight = getStatusBarHeight() const isPrinting = ref(false) @@ -146,9 +149,9 @@ const labelImage = computed(() => { } const size = templateSize.value if (size.indexOf('2"x6"') >= 0 || size.indexOf('2"x4"') >= 0) { - return '/static/lable2.png' + return label2Img } - return '/static/lable1.png' + return label1Img }) // 按详情规则与产品列表一致:chicken→Chicken,lable2→Cheese Burger Deluxe,lable1→Syrup @@ -159,6 +162,15 @@ const displayProductName = computed(() => { return 'Syrup' }) +const printTemplateData = computed(() => ({ + product: displayProductName.value, + productName: displayProductName.value, + category: productCategory.value, + labelId: labelId.value, + qrCode: labelId.value, + barcode: labelId.value, +})) + onShow(() => { const summary = getCurrentPrinterSummary() btConnected.value = summary.type === 'bluetooth' || summary.type === 'builtin' @@ -237,11 +249,10 @@ const handlePrint = async () => { } isPrinting.value = true try { - await printLabelForCurrentPrinter({ - productName: displayProductName.value, - labelId: labelId.value, + uni.showLoading({ title: 'Preparing print data...', mask: true }) + await new Promise(resolve => setTimeout(resolve, 30)) + await printSystemTemplateForCurrentPrinter(PREVIEW_SYSTEM_TEMPLATE, printTemplateData.value, { printQty: printQty.value, - extraLine: lastEdited.value, }, (percent) => { if (percent >= 100) return uni.showLoading({ title: `Printing ${percent}%`, mask: true }) diff --git a/美国版/Food Labeling Management App UniApp/src/pages/more/printers.vue b/美国版/Food Labeling Management App UniApp/src/pages/more/printers.vue index c8aa460..d83ea4a 100644 --- a/美国版/Food Labeling Management App UniApp/src/pages/more/printers.vue +++ b/美国版/Food Labeling Management App UniApp/src/pages/more/printers.vue @@ -24,6 +24,10 @@ Debug Status Current Mode: {{ debugInfo.currentMode }} + Available Mode: {{ availablePrinterTypesLabel }} + Device Model: {{ deviceIdentity.model || '-' }} + Device Brand: {{ deviceIdentity.brand || '-' }} + Device Product: {{ deviceIdentity.product || '-' }} Classic Module: {{ debugInfo.classicModuleReady ? 'Ready' : 'Not Ready' }} Paired Count: {{ debugInfo.pairedCount }} Virtual BT Printer: {{ debugInfo.foundVirtualPrinter ? 'Found' : 'Not Found' }} @@ -39,7 +43,7 @@ - {{ currentType === 'builtin' ? t('printers.builtin') : (currentBt?.deviceName || 'Bluetooth Printer') }} + {{ currentDisplayName }} {{ currentType === 'builtin' ? '127.0.0.1' : (currentBt?.deviceId || '') }} {{ t('printers.connected') }} @@ -50,7 +54,7 @@ - + {{ t('printers.builtin') }} @@ -60,6 +64,7 @@ + + +