typings.d.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // 全局要用的类型放到这里
  2. declare global {
  3. interface IResData<T> {
  4. code: number
  5. msg: string
  6. data: T
  7. }
  8. // uni.uploadFile文件上传参数
  9. interface IUniUploadFileOptions {
  10. file?: File
  11. files?: UniApp.UploadFileOptionFiles[]
  12. filePath?: string
  13. name?: string
  14. formData?: any
  15. }
  16. interface IUserInfo {
  17. nickname?: string
  18. avatar?: string
  19. /** 微信的 openid,非微信没有这个字段 */
  20. openid?: string
  21. }
  22. interface IUserToken {
  23. token: string
  24. refreshToken?: string
  25. refreshExpire?: number
  26. }
  27. }
  28. // patch uni 类型
  29. // 1. 补全 uni.hideToast() 的 options 类型
  30. // 2. 补全 uni.hideLoading() 的 options 类型
  31. // 3. 使用方式见:https://github.com/unibest-tech/unibest/pull/241
  32. declare global {
  33. declare namespace UniNamespace {
  34. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  35. type HideLoadingCompleteCallback = (res: GeneralCallbackResult) => void
  36. /** 接口调用失败的回调函数 */
  37. type HideLoadingFailCallback = (res: GeneralCallbackResult) => void
  38. /** 接口调用成功的回调函数 */
  39. type HideLoadingSuccessCallback = (res: GeneralCallbackResult) => void
  40. interface HideLoadingOption {
  41. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  42. complete?: HideLoadingCompleteCallback
  43. /** 接口调用失败的回调函数 */
  44. fail?: HideLoadingFailCallback
  45. test: UniNamespace.GeneralCallbackResult
  46. /**
  47. * 微信小程序:需要基础库: `2.22.1`
  48. *
  49. * 微信小程序:目前 toast 和 loading 相关接口可以相互混用,此参数可用于取消混用特性
  50. */
  51. noConflict?: boolean
  52. /** 接口调用成功的回调函数 */
  53. success?: HideLoadingSuccessCallback
  54. }
  55. // ----------------------------------------------------------
  56. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  57. type HideToastCompleteCallback = (res: GeneralCallbackResult) => void
  58. /** 接口调用失败的回调函数 */
  59. type HideToastFailCallback = (res: GeneralCallbackResult) => void
  60. /** 接口调用成功的回调函数 */
  61. type HideToastSuccessCallback = (res: GeneralCallbackResult) => void
  62. interface HideToastOption {
  63. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  64. complete?: HideToastCompleteCallback
  65. /** 接口调用失败的回调函数 */
  66. fail?: HideToastFailCallback
  67. /**
  68. * 微信小程序:需要基础库: `2.22.1`
  69. *
  70. * 微信小程序:目前 toast 和 loading 相关接口可以相互混用,此参数可用于取消混用特性
  71. */
  72. noConflict?: boolean
  73. /** 接口调用成功的回调函数 */
  74. success?: HideToastSuccessCallback
  75. }
  76. }
  77. interface Uni {
  78. /**
  79. * 隐藏 loading 提示框
  80. *
  81. * 文档: [http://uniapp.dcloud.io/api/ui/prompt?id=hideloading](http://uniapp.dcloud.io/api/ui/prompt?id=hideloading)
  82. * @example ```typescript
  83. * uni.showLoading({
  84. * title: '加载中'
  85. * });
  86. *
  87. * setTimeout(function () {
  88. * uni.hideLoading();
  89. * }, 2000);
  90. *
  91. * ```
  92. * @tutorial [](https://uniapp.dcloud.net.cn/api/ui/prompt.html#hideloading)
  93. * @uniPlatform {
  94. * "app": {
  95. * "android": {
  96. * "osVer": "4.4.4",
  97. * "uniVer": "√",
  98. * "unixVer": "3.9.0"
  99. * },
  100. * "ios": {
  101. * "osVer": "9.0",
  102. * "uniVer": "√",
  103. * "unixVer": "3.9.0"
  104. * }
  105. * }
  106. * }
  107. */
  108. // eslint-disable-next-line ts/method-signature-style
  109. hideLoading<T extends UniNamespace.HideToastOption = UniNamespace.HideToastOption>(options?: T): void
  110. /**
  111. * 隐藏消息提示框
  112. *
  113. * 文档: [http://uniapp.dcloud.io/api/ui/prompt?id=hidetoast](http://uniapp.dcloud.io/api/ui/prompt?id=hidetoast)
  114. * @example ```typescript
  115. * uni.hideToast();
  116. * ```
  117. * @tutorial [](https://uniapp.dcloud.net.cn/api/ui/prompt.html#hidetoast)
  118. * @uniPlatform {
  119. * "app": {
  120. * "android": {
  121. * "osVer": "4.4.4",
  122. * "uniVer": "√",
  123. * "unixVer": "3.9.0"
  124. * },
  125. * "ios": {
  126. * "osVer": "9.0",
  127. * "uniVer": "√",
  128. * "unixVer": "3.9.0"
  129. * }
  130. * }
  131. * }
  132. */
  133. // eslint-disable-next-line ts/method-signature-style
  134. hideToast<T extends UniNamespace.HideLoadingOption = UniNamespace.HideLoadingOption>(options?: T): void
  135. }
  136. }
  137. export {} // 防止模块污染