Blame view

泰额版/Food Labeling Management App UniApp/src/utils/print/bluetoothPrinterAllowlist.ts 1.04 KB
540ac0e3   杨鑫   前端修改bug
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
  /** 扫描/配对列表仅展示以下蓝牙名称(大小写不敏感,须完整匹配) */
  export const ALLOWED_BLUETOOTH_PRINTER_NAMES = [
    'GP-D320FX-spp_A7FO',
    'Virtual BT Printer',
  ] as const
  
  const ALLOWED_BLUETOOTH_PRINTER_NAME_SET = new Set(
    ALLOWED_BLUETOOTH_PRINTER_NAMES.map((name) => name.toLowerCase()),
  )
  
  export function normalizeBluetoothPrinterName (name: string | undefined | null): string {
    return String(name ?? '').trim()
  }
  
  /** 仅允许白名单内的蓝牙打印机名称出现在连接列表 */
  export function isAllowedBluetoothPrinterName (name: string | undefined | null): boolean {
    const normalized = normalizeBluetoothPrinterName(name)
    if (!normalized) return false
    return ALLOWED_BLUETOOTH_PRINTER_NAME_SET.has(normalized.toLowerCase())
  }
  
  /** 一体机虚拟蓝牙名(走整页光栅与预览一致,不走 native printTemplate) */
  export function isVirtualBtPrinterDeviceName (name: string | undefined | null): boolean {
    return normalizeBluetoothPrinterName(name).toLowerCase() === 'virtual bt printer'
  }