人民医院前端

sdkLib.d.ts 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. export interface IErrorMessage {
  2. /** the error code */
  3. errorCode?: string;
  4. /** the error message */
  5. errorMessage?: string;
  6. }
  7. export interface ICallbackOption<S> {
  8. onSuccess?(data: S): void;
  9. onFail?(err: IErrorMessage): void;
  10. onCancel?(err: IErrorMessage): void;
  11. }
  12. export declare type IJSBridge = (method: string, params: any) => Promise<any>;
  13. export declare type ICommonAPI<S, T> = (params: S & ICallbackOption<T>) => Promise<T>;
  14. export interface IInvokeAPIConfigMap {
  15. [platform: string]: IAPIConfig | undefined;
  16. }
  17. export interface IAPIConfig {
  18. /** the minSupport version about the API */
  19. vs: string | {
  20. [platformSub: string]: string;
  21. };
  22. invokeName?: string;
  23. /**
  24. * 应返回新的转换后的参数,不应直接修改传入的变量
  25. */
  26. paramsDeal?: (params: any) => any | Promise<any>;
  27. /**
  28. * 应返回新的转换后的参数,不应直接修改传入的变量
  29. */
  30. resultDeal?: (res: any) => any;
  31. }
  32. export interface IJSBridgeMap {
  33. [platform: string]: IJSBridge | undefined;
  34. }
  35. export interface IInvokeAPIConfigMapByMethod {
  36. [method: string]: IInvokeAPIConfigMap | undefined;
  37. }
  38. export declare function isFunction(param: any): boolean;
  39. /**
  40. * when origin >= target ,return true
  41. * 关于为什么没有跟otherApi保持一致,主要是当初因为otherApi里的方法是复制旧版jsapi的,有一定缺陷
  42. * 但是担心线上环境利用了缺陷来做逻辑,所以没有保持一致使用同一个方法
  43. * TODO: 但其实另起方法太冗余,以及丑陋,后续还是需要整个统一掉
  44. * @param origin
  45. * @param target
  46. */
  47. export declare function compareVersion(origin: string, target: string): boolean;
  48. /**
  49. * 客户端错误码
  50. */
  51. export declare enum ERROR_CODE {
  52. cancel = "-1",
  53. not_exist = "1",
  54. no_permission = "7"
  55. }
  56. export declare enum ENV_ENUM {
  57. pc = "pc",
  58. android = "android",
  59. ios = "ios",
  60. gdtPc = "gdtPc",
  61. /**
  62. * gdt Android mpaas 容器
  63. */
  64. gdtAndroid = "gdtAndroid",
  65. /**
  66. * gdt Ios mpaas 容器
  67. */
  68. gdtIos = "gdtIos",
  69. /**
  70. * gdt Android 标准 容器
  71. */
  72. gdtStandardAndroid = "gdtStandardAndroid",
  73. /**
  74. * gdt Ios 标准 容器
  75. */
  76. gdtStandardIos = "gdtStandardIos",
  77. notInDingTalk = "notInDingTalk",
  78. windows = "windows",
  79. mac = "mac"
  80. }
  81. export declare enum ENV_ENUM_SUB {
  82. mac = "mac",
  83. win = "win",
  84. noSub = "noSub"
  85. }
  86. export declare enum APP_TYPE {
  87. WEB = "WEB",
  88. MINI_APP = "MINI_APP",
  89. WEEX = "WEEX",
  90. WEBVIEW_IN_MINIAPP = "WEBVIEW_IN_MINIAPP",
  91. WEEX_WIDGET = "WEEX_WIDGET"
  92. }
  93. export interface IENV {
  94. /** current platform (iOS or Android or PC or NotInDingTalk) */
  95. platform: ENV_ENUM;
  96. /** current sub platform (support mac & win) */
  97. platformSub?: ENV_ENUM_SUB;
  98. /** current client version */
  99. version?: string;
  100. /** @deprecated recommend use navigator.language to get current language */
  101. language?: string;
  102. /** current appType (web or eapp or weex) */
  103. appType: APP_TYPE;
  104. [key: string]: any;
  105. }
  106. export interface IConfigParams {
  107. jsApiList?: string[];
  108. [key: string]: any;
  109. }
  110. export interface IDevConfigParams {
  111. /** 是否开启调试模式 */
  112. debug?: boolean;
  113. /** 是否校验Api是否支持等 */
  114. isAuthApi?: boolean;
  115. /** 废除兼容性处理 */
  116. isDisableDeal?: boolean;
  117. /** 部分接口废除兼容性处理 */
  118. disbaleDealApiWhiteList?: string[];
  119. /** 接口层面开启兼容性处理,优先级大于废除逻辑 */
  120. forceEnableDealApiFnMap?: {
  121. [apiName: string]: (params: any) => boolean;
  122. };
  123. onBeforeInvokeAPI?: (data: {
  124. invokeId: string;
  125. method: string;
  126. startTime: number;
  127. params: any;
  128. }) => void;
  129. onAfterInvokeAPI?: (data: {
  130. invokeId: string;
  131. method: string;
  132. params: any;
  133. payload: any;
  134. duration: number;
  135. startTime: number;
  136. isSuccess: boolean;
  137. }) => void;
  138. extraPlatform?: IPlatformConfig;
  139. }
  140. export interface IEvent {
  141. preventDefault: () => void;
  142. }
  143. export declare enum LogLevel {
  144. INFO = 1,
  145. WARNING = 2,
  146. ERROR = 3
  147. }
  148. export interface ILog {
  149. level: LogLevel;
  150. text: any[];
  151. time: Date;
  152. }
  153. export declare type ILogFn = (option: ILog) => void;
  154. export interface IPlatformConfig {
  155. platform: string;
  156. authMethod: string;
  157. authParamsDeal?: (params: object) => object;
  158. bridgeInit: () => Promise<IJSBridge>;
  159. event?: {
  160. on: (type: string, handler: (e: IEvent) => void) => void;
  161. off: (type: string, handler: (e: IEvent) => void) => void;
  162. };
  163. }
  164. export interface ICheckJsApiParams {
  165. jsApiList?: string[];
  166. }
  167. export interface ICheckJsApiResult {
  168. [jsApi: string]: boolean;
  169. }
  170. export declare type ICheckJsApiFn = (params: ICheckJsApiParams) => Promise<ICheckJsApiResult>;
  171. export interface IUNCore {
  172. /** 当config权限校验成功时触发readyCallback */
  173. ready: (readyCallback: () => void) => void;
  174. /** 当config权限校验成功时触发readyCallback */
  175. error: (callback: (err: any) => void) => void;
  176. /** 配置权限校验参数, 即可启动校验,启动校验成功后可以让本没有权限的接口获取权限,如果你的域名是白名单或者调用的接口不需要校验,可不用调用此接口 */
  177. config: (configParams: IConfigParams) => void;
  178. /** 配置开发选项 */
  179. devConfig: (devConfigParams: IDevConfigParams) => void;
  180. /** 推荐使用on绑定方法, 替代原本document的方式 */
  181. on: (methodName: string, listener: (e: IEvent | any) => void) => void;
  182. /** 推荐使用off解绑方法,替代document的方式 */
  183. off: (methodName: string, listener: (e: IEvent | any) => void) => void;
  184. /** 当前运行时的环境变量 */
  185. env: IENV;
  186. /**
  187. * 提供检测jsapi能力的接口
  188. * @description 本接口原理依赖于 JSAPI 的静态支持版本数据,故存在一定的误差
  189. * @deprecated 移动端上推荐使用 plugin/checkJsApi.ts 来检测真实环境下的支持情况
  190. */
  191. checkJsApi: ICheckJsApiFn;
  192. /** 直接通过method名调用jsapi,新的接口基本不存在多端不一致的问题,可以使用此接口代替。注意:但如果直接调用旧的jsapi接口,且没有引入对应接口库,将不会对入参出参进行兼容操作 */
  193. _invoke: (method: string, params?: any) => Promise<any>;
  194. }
  195. export interface IConfigCoreMap {
  196. [platform: string]: IPlatformConfig | undefined;
  197. }
  198. export interface IApiMiddlewareContext {
  199. method: string;
  200. params: any;
  201. isAuthApi: boolean;
  202. invokeName?: string;
  203. callParams?: any;
  204. JSBridge?: IJSBridge;
  205. apiConfig?: IAPIConfig;
  206. }
  207. export declare type IApiMiddlewareNextFn = () => Promise<any>;
  208. export declare type IApiMiddlewareFn = (context: IApiMiddlewareContext, next: IApiMiddlewareNextFn) => Promise<any>;