bridge.d.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import type { SimplePulseModel } from './pulse';
  2. interface ScanData {
  3. code: string;
  4. state: number;
  5. type: number;
  6. }
  7. export interface BridgeEventMap {
  8. scan: CustomEvent<{code: number, data?: ScanData, message?: string}>;
  9. }
  10. export class Bridge extends EventTarget {
  11. public static getInstance(): Bridge;
  12. public static pulse(userId: string): Promise<SimplePulseModel & { report: string; time: string; } & {
  13. appId?: string;
  14. userId?: string;
  15. }>;
  16. public static print(): Promise<void>;
  17. public static print(params: { url?: string }): Promise<void>;
  18. /**
  19. * 监听扫码事件
  20. * @param type 事件类型 'scan'
  21. * @param listener 事件回调,参数为 ScanEvent
  22. * @param options
  23. */
  24. addEventListener<T extends keyof BridgeEventMap>(type: T, listener: (event: BridgeEventMap[T]) => void, options?: boolean | AddEventListenerOptions): () => void;
  25. removeEventListener<T extends keyof BridgeEventMap>(type: T, listener: (event: BridgeEventMap[T]) => void, options?: boolean | AddEventListenerOptions): () => void;
  26. postMessage(...args: any[]): Promise<void>;
  27. }
  28. export interface globalAIO {
  29. scan(value: string): number;
  30. print(value: string): void;
  31. }