typings.d.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. declare global {
  32. declare namespace UniNamespace {
  33. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  34. type HideLoadingCompleteCallback = (res: GeneralCallbackResult) => void
  35. /** 接口调用失败的回调函数 */
  36. type HideLoadingFailCallback = (res: GeneralCallbackResult) => void
  37. /** 接口调用成功的回调函数 */
  38. type HideLoadingSuccessCallback = (res: GeneralCallbackResult) => void
  39. interface HideLoadingOption {
  40. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  41. complete?: HideLoadingCompleteCallback
  42. /** 接口调用失败的回调函数 */
  43. fail?: HideLoadingFailCallback
  44. test: UniNamespace.GeneralCallbackResult
  45. /**
  46. * 微信小程序:需要基础库: `2.22.1`
  47. *
  48. * 微信小程序:目前 toast 和 loading 相关接口可以相互混用,此参数可用于取消混用特性
  49. */
  50. noConflict?: boolean
  51. /** 接口调用成功的回调函数 */
  52. success?: HideLoadingSuccessCallback
  53. }
  54. // ----------------------------------------------------------
  55. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  56. type HideToastCompleteCallback = (res: GeneralCallbackResult) => void
  57. /** 接口调用失败的回调函数 */
  58. type HideToastFailCallback = (res: GeneralCallbackResult) => void
  59. /** 接口调用成功的回调函数 */
  60. type HideToastSuccessCallback = (res: GeneralCallbackResult) => void
  61. interface HideToastOption {
  62. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  63. complete?: HideToastCompleteCallback
  64. /** 接口调用失败的回调函数 */
  65. fail?: HideToastFailCallback
  66. /**
  67. * 微信小程序:需要基础库: `2.22.1`
  68. *
  69. * 微信小程序:目前 toast 和 loading 相关接口可以相互混用,此参数可用于取消混用特性
  70. */
  71. noConflict?: boolean
  72. /** 接口调用成功的回调函数 */
  73. success?: HideToastSuccessCallback
  74. }
  75. }
  76. interface Uni {
  77. /**
  78. * 隐藏 loading 提示框
  79. *
  80. * 文档: [http://uniapp.dcloud.io/api/ui/prompt?id=hideloading](http://uniapp.dcloud.io/api/ui/prompt?id=hideloading)
  81. * @example ```typescript
  82. * uni.showLoading({
  83. * title: '加载中'
  84. * });
  85. *
  86. * setTimeout(function () {
  87. * uni.hideLoading();
  88. * }, 2000);
  89. *
  90. * ```
  91. * @tutorial [](https://uniapp.dcloud.net.cn/api/ui/prompt.html#hideloading)
  92. * @uniPlatform {
  93. * "app": {
  94. * "android": {
  95. * "osVer": "4.4.4",
  96. * "uniVer": "√",
  97. * "unixVer": "3.9.0"
  98. * },
  99. * "ios": {
  100. * "osVer": "9.0",
  101. * "uniVer": "√",
  102. * "unixVer": "3.9.0"
  103. * }
  104. * }
  105. * }
  106. */
  107. // eslint-disable-next-line ts/method-signature-style
  108. hideLoading<T extends UniNamespace.HideToastOption = UniNamespace.HideToastOption>(options?: T): void
  109. /**
  110. * 隐藏消息提示框
  111. *
  112. * 文档: [http://uniapp.dcloud.io/api/ui/prompt?id=hidetoast](http://uniapp.dcloud.io/api/ui/prompt?id=hidetoast)
  113. * @example ```typescript
  114. * uni.hideToast();
  115. * ```
  116. * @tutorial [](https://uniapp.dcloud.net.cn/api/ui/prompt.html#hidetoast)
  117. * @uniPlatform {
  118. * "app": {
  119. * "android": {
  120. * "osVer": "4.4.4",
  121. * "uniVer": "√",
  122. * "unixVer": "3.9.0"
  123. * },
  124. * "ios": {
  125. * "osVer": "9.0",
  126. * "uniVer": "√",
  127. * "unixVer": "3.9.0"
  128. * }
  129. * }
  130. * }
  131. */
  132. // eslint-disable-next-line ts/method-signature-style
  133. hideToast<T extends UniNamespace.HideLoadingOption = UniNamespace.HideLoadingOption>(options?: T): void
  134. }
  135. }
  136. export {} // 防止模块污染