UNPKG

@auraxy/cef-bridge

Version:

cefCore, boundAsync, cefEnviroment, cefPopupEnvironment, cefJsWebBridge

341 lines (336 loc) 12.8 kB
declare type ClientV1 = 'XieChengClient' | 'KaipiaoClient 票易通' | 'KaipiaoConsole'; declare type ClientV2 = 'XieChengClientV2' | 'KaipiaoClientV2' | 'KaipiaoConsoleV2'; declare type ClientV3 = 'XieChengClientV3' | 'KaipiaoClientV3' | 'KaipiaoConsoleV3'; interface IceInfo { /** * 操作系统 * */ OS: string; AppVer: string; /** * 客户端税件类型,*V2 表示是自研税件,XieCheng* 表示是携程相关 * * */ AppName: ClientV1 | ClientV2 | ClientV3; Channel: 'XieCheng' | 'TongYong' | 'YinLian'; TaxSoftVer: string; TaxDiskType: 'BarWang' | 'HangXin'; } interface BoundAsync { /** * example: {"OS": "Windows7", "AppVer": "0.2.3.0", "Channel": "XieCheng", "TaxSoftVer": "2. 0.17. 0", "TaxDiskType": "BaiWang"} * * 最早的老版本没有这个接口 * */ getIce?(): Promise<string>; /** * 发票修复 * */ callInvoiceFix(): void; /** * 强制重新加载 * */ refushHome(): void; /** * 判断是否是自研税件,新版本使用 IceInfo 的 AppName 字段判断 * * 返回值为空,则表示不是自研税件 * * 较早的老版本没有这个接口 * */ getVersionName?(): string | null; login(username: string, pwd: string): Promise<boolean>; logout(): void; /** * 客户端唤起客户端 */ jumpAction?(type: string, url: string): void; } interface InvokeOptions { width?: number; height?: number; /** * 窗口位置 * * 与客户端约定: * 1. rightBottom 为非阻塞窗口 * 2. 非阻塞窗口不能同时存在两个,新的窗口会将旧的非阻塞窗口关闭 * */ position?: 'centerParent' | 'centerScreen' | 'rightBottom'; [key: string]: any; } interface CefPopupEnvironment { /** * data 为 JSON.stringify 之后的字符创串 * */ callback: (data?: string) => any; } interface CefEnvironment { } declare type NonFunction<T = any> = T extends Function ? never : T; /** * T 回调数据类型 * */ interface DialogBtn<T = any> { /** * 回调接收的数据,由于数据只有在 json 字符串化后才能在窗口之间传递,所以不能是哪些 json 字符串化之后会丢失的数据结构,也不能是函数 * */ data?: NonFunction<T>; /** * 文本 * */ innerHTML?: string; style?: Partial<CSSStyleDeclaration>; className?: string; closePopup?: boolean; } interface DialogRenderProps { voice?: string; title?: string; content?: string; btnsWrapStyle?: Partial<CSSStyleDeclaration>; btns?: DialogBtn[]; } declare type InvokeCallback = (data?: any) => any; interface CefJsWebBridge { invoke(type: string, options: InvokeOptions, callback: InvokeCallback): any; getVersion(callback: (v: string) => void): void; /** 监听客户端事件,用于接收从客户端发来的消息 */ addEventListener(eventType: string, handler: (ev: any) => void): void; removeEventListener(eventType: string, handler: (ev: any) => void): void; [key: string]: any; } interface OpenTaxExeResult { code: number; data: boolean; message: string; } declare enum TaxSoftWares { HX = "hx", BW = "bw" } declare enum InvoiceType { Common = "c", Special = "s", Electronic = "ce", BlockChain = "bc" } interface TitleItem { companyName: string; taxNo?: string; buyAddress?: string; buyPhone?: string; bankName?: string; bankNo?: string; invoiceType?: InvoiceType; receiverPhone: string | number; } interface TaxDeviceInfo { /** 名称 */ companyName: string | null; /** 税号 */ companyTax: string | null; /** 机器码 */ machineCode: string | null; /** SN 号 */ diskCode: string | null; diskPassWord: string | null; /** '0' 航信 '1' 百旺 */ diskType: '0' | '1'; /** 可开票种,示例:'c|ce' */ invoiceImpower: string | null; /** '0000' 表示读取成功 */ returnCode: string | null; /** 读取成功/失败消息 */ returnMsg: string | null; isHxV3?: string; } interface CTaxDeviceInfo extends TaxDeviceInfo { status: number; companyName: string; taxNo: string; deviceNo: string; message: string; type: number; } interface CefCore { ShowMainWindow(): void; /** 关闭当前窗口,如果直接从弹出窗口调用,会导致回调丢失 */ CloseWindow(): void; SetWindowMinimized(): void; /** 打开航信进程/百旺,不传入根据税盘自动判断 */ OpenTaxExe(name?: TaxSoftWares): Promise<boolean | string>; /** 查找当前环境,是否是航信还是百旺,不传入根据税盘自动判断 */ IsTaxProcessOpen(name?: TaxSoftWares): Promise<boolean>; /** @return TaxDeviceInfo json 字符串 */ GetNowTaxInfo(): Promise<string>; /** * 轻量版发送抬头信息,json -> TitleItem 数据字符串化 * 如果成功,返回 null | '' * 有异常,则返回提示字符串 * */ DoSendTitle(json: string): Promise<string | null>; /** * 轻量版电票开具,json 数据字符串化 * 如果成功,返回 null | '' * 如果证书密码错误,返回 '99',则弹出提示窗口 * 有异常,则返回提示字符串 * * json 数据示例:https://www.showdoc.cc/363387933772874?page_id=2117156569221380 (页面中的 `入参示例`) * */ MakeoutFromPreview(json: string): Promise<string | null>; /** * 轻量版设置证书密码 * 如果成功,返回 null | '' * 有异常,则返回提示字符串 * */ SetCertPassword(pwd: string): Promise<string | null>; /** * 轻量版 pdf 生成 * 如果成功,返回 null | '' * 如果证书密码错误,返回 '99',则弹出提示窗口 * 其他异常提示,返回提示字符串 * * json 数据来源于服务端 * */ MakePdf(json: string): Promise<string | null>; /** * 打开一个外部浏览器接口 * */ OpenUrlOnSystem(url: string): void; /** 获取 DPI */ GetDpi(): Promise<string>; /** Play audio */ PlaySound(url: string): void; /** Has OFD function */ HasOfd?(): Promise<boolean>; [key: string]: any; } declare type Unsubscribe = () => void; interface JumpActionProps { type: '0' | '1'; url: string; } /** * 只存在于完整版客户端 * */ declare const boundAsync: BoundAsync; /** * 判断是否是 KaiPiao 完整版客户端 * */ declare const IsKaiPiaoClient: boolean; /** 获取完整版客户端信息 */ declare function GetKaiPiaoClientInfo(): Promise<IceInfo | null>; declare function GetKaiPiaoClientVersion(): Promise<string | null>; declare function GetKaiPiaoClientAppName(): Promise<"XieChengClient" | "KaipiaoClient 票易通" | "KaipiaoConsole" | "XieChengClientV2" | "KaipiaoClientV2" | "KaipiaoConsoleV2" | "XieChengClientV3" | "KaipiaoClientV3" | "KaipiaoConsoleV3" | null>; declare function IsKaiPiaoClientV2ByIce(): Promise<boolean>; declare function IsKaiPiaoClientV3ByIce(): Promise<boolean>; /** * 完整版 - * 从选中的税盘判断是V2还是V3版本 * */ declare function IsKaiPiaoClientV2ByTaxDisk(clientInfo: IceInfo): boolean; declare function IsKaiPiaoClientV3ByTaxDisk(clientInfo: IceInfo): boolean; /** 客户端唤起客户端 */ declare function JumpAction(jumpProps: JumpActionProps): void; /** 完整版发票修复 */ declare function InvoiceFix(): Promise<boolean>; /** 强制刷新页面 */ declare function PageReload(): void; /** 完整版客户端登录 */ declare function LoginKaiPiao(username: string, pwd: string): Promise<boolean>; /** 完整版客户端登出 */ declare function LogoutKaiPiao(): void; /** * 存在于新完整版客户端,携程轻量版 * */ declare const cefCore: CefCore; declare const cefEnvironment: CefEnvironment; /** * 只存在于主窗口环境 * */ declare const cefJsWebBridge: CefJsWebBridge; /** * 只存在于弹窗环境 * */ declare const cefPopupEnvironment: CefPopupEnvironment; /** * 是否是有 cefCore, cefEnvironment, cefPopupEnvironment, cefJsWebBridge 的客户端 * */ declare const CefIsFullBridgeClient: boolean; /** 是否是弹窗 */ declare const CefIsPopupClient: boolean; /** * cefJsWebBridge 注册判断,cefJsWebBridge 的相关事件需要在其注册之后调用才能成功 * */ declare const CefJsWebBridgeReady: Promise<unknown>; /** 前置主窗体 */ declare function CefShowMainWindow(): void; /** 关闭窗口 */ declare function CefWindowClose(): void; declare function CefExitApp(): void; /** 窗口最小化 */ declare function CefWindowMinimize(): void; /** 打开一个外部浏览器接口 */ declare function CefOpenUrlInBrowser(url: string): void; /** 监听客户端事件,用于接收从客户端发来的消息 */ declare function CefAddEventListener(type: string, handler: (ev: any) => void): void; declare function CefRemoveEventListener(type: string, handler: (ev: any) => void): void; /** 获取系统当前显示器的 DPI */ declare function CefGetDPI(): Promise<number>; /** 打开弹窗,并接收弹窗传递过来的数据,只能在主窗口调用 */ declare function CefWindowPopup<T = any>(renderProps: DialogRenderProps, options?: InvokeOptions): Promise<T>; /** popup 向主体窗口传递数据,只能在弹窗中调用 */ declare function CefPopupCallback<T = any>(data: T): void; /** 版本,只能在主窗口调用 */ declare function CefVersion(): Promise<string>; /** 获取税盘状态 */ declare function CefGetTaxDeviceInfo(): Promise<CTaxDeviceInfo>; /** 订阅税盘状态 */ declare function CefSubscribeTaxDeviceInfo(callback: (info: CTaxDeviceInfo) => any, duration?: number): Unsubscribe; /** 打开航信进程/百旺,不传入根据税盘自动判断 */ declare function CefOpenTaxSoftware(name?: TaxSoftWares): Promise<any>; /** 轻量版发送抬头信息到客户端 */ declare function CefSendTitleToTaxSoftware(data: TitleItem): Promise<string | null>; /** * 轻量版电票开具,json 数据字符串化 * 如果成功,返回 null | '' * 如果证书密码错误,返回 '99',则弹出提示窗口 * 有异常,则返回提示字符串 * * data 数据示例:https://www.showdoc.cc/363387933772874?page_id=2117156569221380 (页面中的 `入参示例`) * */ declare function CefSendDataForCE(data: any): Promise<string | null>; /** * 轻量版设置证书密码 * 如果成功,返回 null | '' * 有异常,则返回提示字符串 * */ declare function CefSetCertPassword(pwd: string): Promise<string | null>; /** * 轻量版 pdf 生成 * 如果成功,返回 null | '' * 如果证书密码错误,返回 '99',则弹出提示窗口 * 其他异常提示,返回提示字符串 * * data 数据来源于服务端 * */ declare function CefMakePdf(data: any): Promise<string | null>; /** 查找当前环境,是否是航信还是百旺,不传入根据税盘自动判断 */ declare function CefIsTaxSoftWareOpen(name?: TaxSoftWares): Promise<boolean>; /** Play sound */ declare function CefPlayAudio(url: string): void; /** Has OFD function */ declare function CefHasOFD(): Promise<boolean>; /** * 调用没记录的可能存在的接口 * * 一般用于服务端通过 H5 与 .net 客户端交互,这时前端可以做被动调用就行,接口名以及参数都由后端提供 * */ declare function CefCall(apiName: string, ...args: any[]): any; /** 退出客户端 */ declare function SignOutClient(version: string): any; /** * 是否是客户端 * */ declare const IsClient: boolean; export { BoundAsync, CTaxDeviceInfo, CefAddEventListener, CefCall, CefCore, CefEnvironment, CefExitApp, CefGetDPI, CefGetTaxDeviceInfo, CefHasOFD, CefIsFullBridgeClient, CefIsPopupClient, CefIsTaxSoftWareOpen, CefJsWebBridge, CefJsWebBridgeReady, CefMakePdf, CefOpenTaxSoftware, CefOpenUrlInBrowser, CefPlayAudio, CefPopupCallback, CefPopupEnvironment, CefRemoveEventListener, CefSendDataForCE, CefSendTitleToTaxSoftware, CefSetCertPassword, CefShowMainWindow, CefSubscribeTaxDeviceInfo, CefVersion, CefWindowClose, CefWindowMinimize, CefWindowPopup, DialogBtn, DialogRenderProps, GetKaiPiaoClientAppName, GetKaiPiaoClientInfo, GetKaiPiaoClientVersion, IceInfo, InvoiceFix, InvoiceType, InvokeOptions, IsClient, IsKaiPiaoClient, IsKaiPiaoClientV2ByIce, IsKaiPiaoClientV2ByTaxDisk, IsKaiPiaoClientV3ByIce, IsKaiPiaoClientV3ByTaxDisk, JumpAction, JumpActionProps, LoginKaiPiao, LogoutKaiPiao, NonFunction, OpenTaxExeResult, PageReload, SignOutClient, TaxDeviceInfo, TaxSoftWares, TitleItem, Unsubscribe, boundAsync, cefCore, cefEnvironment, cefJsWebBridge, cefPopupEnvironment };