Blame view

泰额版/Food Labeling Management App UniApp/src/utils/print/drivers/genericTsc.ts 1.18 KB
59e51671   “wangming”   1
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
  import { buildTscLabelData, buildTscTestPrintData } from '../protocols/tscProtocol'
  import type { PrinterCandidate, PrinterDriver } from '../types/printer'
  
  const GENERIC_TSC_KEYWORDS = [
    'printer', 'print', 'label', 'tsc', 'zebra', 'brother', 'epson', 'godex',
    'citizen', 'ql-', 'zd', 'zt', 'ttp', 'tdp', 'bt printer', 'virtual bt printer',
  ]
  
  function scoreByKeywords (device: PrinterCandidate, keywords: string[]): number {
    const text = `${device.name || ''} ${device.deviceId || ''}`.toLowerCase()
    let score = 0
    keywords.forEach((keyword) => {
      if (text.includes(keyword)) score += 10
    })
    return score
  }
  
  export const genericTscDriver: PrinterDriver = {
    key: 'generic-tsc',
    brand: 'Generic',
    model: 'TSC',
    displayName: 'Generic TSC Printer',
    protocol: 'tsc',
    preferredBleMtu: 20,
    imageMaxWidthDots: 800,
    imageDpi: 203,
    keywords: GENERIC_TSC_KEYWORDS,
    matches (device) {
      return scoreByKeywords(device, GENERIC_TSC_KEYWORDS)
    },
    resolveConnectionType (device) {
      return device.type === 'ble' ? 'ble' : 'classic'
    },
    buildTestPrintData () {
      return buildTscTestPrintData()
    },
    buildLabelData (payload) {
      return buildTscLabelData(payload)
    },
  }