Blame view

泰额版/Food Labeling Management App UniApp/src/utils/print/drivers/gpD320fx.ts 1.04 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
41
42
  import { buildTscLabelData, buildTscTestPrintData } from '../protocols/tscProtocol'
  import type { PrinterCandidate, PrinterDriver } from '../types/printer'
  
  const KEYWORDS = [
    'd320fx',
    'gp-d320fx',
  ]
  
  function score (device: PrinterCandidate): number {
    const text = `${device.name || ''} ${device.deviceId || ''}`.toLowerCase()
    let total = 0
    KEYWORDS.forEach((keyword) => {
      if (text.includes(keyword)) total += 80
    })
    if (text.includes('gprinter')) total += 10
    return total
  }
  
  export const gpD320fxDriver: PrinterDriver = {
    key: 'gp-d320fx',
    brand: 'Gprinter',
    model: 'GP-D320FX',
    displayName: 'Gprinter GP-D320FX',
    protocol: 'tsc',
    preferredConnection: 'ble',
    preferredBleMtu: 512,
    imageMaxWidthDots: 800,
    imageDpi: 203,
    keywords: KEYWORDS,
    matches (device) {
      return score(device)
    },
    resolveConnectionType (device) {
      return device.type === 'classic' ? 'classic' : 'ble'
    },
    buildTestPrintData () {
      return buildTscTestPrintData()
    },
    buildLabelData (payload) {
      return buildTscLabelData(payload)
    },
  }