Blame view

泰额版/Food Labeling Management App UniApp/src/utils/print/bluetoothPrinterAllowlist.ts 1.36 KB
5a192b24   杨鑫   最新同步
1
  /** 扫描/配对列表仅展示以下蓝牙名称(大小写不敏感;支持完整匹配或关键字包含) */
540ac0e3   杨鑫   前端修改bug
2
3
4
5
6
7
8
9
10
  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()),
  )
  
5a192b24   杨鑫   最新同步
11
12
13
14
15
16
17
  /** 名称包含以下片段也视为允许(兼容系统配对名略有差异) */
  const ALLOWED_BLUETOOTH_PRINTER_NAME_FRAGMENTS = [
    'virtual bt',
    'gp-d320fx',
    'd320fx',
  ] as const
  
540ac0e3   杨鑫   前端修改bug
18
19
20
21
22
23
24
25
  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
5a192b24   杨鑫   最新同步
26
27
28
    const lower = normalized.toLowerCase()
    if (ALLOWED_BLUETOOTH_PRINTER_NAME_SET.has(lower)) return true
    return ALLOWED_BLUETOOTH_PRINTER_NAME_FRAGMENTS.some((frag) => lower.includes(frag))
540ac0e3   杨鑫   前端修改bug
29
30
31
32
33
34
  }
  
  /** 一体机虚拟蓝牙名(走整页光栅与预览一致,不走 native printTemplate) */
  export function isVirtualBtPrinterDeviceName (name: string | undefined | null): boolean {
    return normalizeBluetoothPrinterName(name).toLowerCase() === 'virtual bt printer'
  }