lib.router.d.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. type libRouterHandlesKeys = '$live' | '$map';
  2. type libRouterHandles = {
  3. [key in libRouterHandlesKeys]:(this:LibRouterApi,data:LibRouter)=>LibRouter
  4. }
  5. interface LibRouter extends WechatMiniprogram.NavigateToOption{
  6. url?:string,
  7. // 名称
  8. name?:libRouterHandlesKeys | string,
  9. // 路径
  10. path?:string,
  11. // 参数
  12. params?: Record<string, any> | string,
  13. // 内存数据
  14. memoryParams?:Record<string, any>,
  15. // 分包名称
  16. subcontract?:string,
  17. // 房间id
  18. roomId?:number | string
  19. }
  20. type LibRouterFunctionKeys = 'navigateTo' | 'switchTab' | 'navigateBack' | 'reLaunch' | 'redirectTo';
  21. type LibRouterParamsApi = {
  22. [key in Exclude<LibRouterFunctionKeys, 'navigateBack'>]:(data:LibRouter | string) => Promise<any>
  23. }
  24. interface LibRouterOtherParams {
  25. // 返回上一页
  26. navigateBack:(data?:number) => Promise<any>,
  27. // 获取 直播路径
  28. getLivePath:(roomId:number | string,params:Record<string, any> | string)=> string,
  29. getMapPath:(params:Record<string, any> | string) => string,
  30. // 执行跳转辅助
  31. router:(name:string,data:LibRouter | string | libRouterHandlesKeys,params?:boolean) => Promise<any>
  32. // 将params 转为 string
  33. getParamsString: (params:Record<string, any> | string) => string;
  34. // 内存缓存数据
  35. memoryData: Record<string, Record<string, any>>;
  36. // 向内存数据获取
  37. memoryGet:(name:string) => Record<string, any> | undefined;
  38. // 向内存数据写入
  39. memorySet:(name:string,params:Record<string, any>) => void;
  40. // 获取路由名称
  41. getRouterName:(path:string) => string;
  42. // 推断分包
  43. inferSubPages:(url:string)=>string | undefined,
  44. autoRouter:(data:LibRouter | string,defaultMode?:LibRouterFunctionKeys)=> Promise<any>
  45. // 辅助对象
  46. routerParams:{
  47. // 是否可以继续执行
  48. next:boolean,
  49. // 延迟执行时间
  50. delay:number
  51. }
  52. }
  53. type LibRouterApi = LibRouterOtherParams & LibRouterParamsApi;