typings.d.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. // 扩展 @uni-helper/vite-plugin-uni-pages 的 definePage 参数类型
  29. declare module '@uni-helper/vite-plugin-uni-pages' {
  30. interface UserPageMeta {
  31. /**
  32. * 使用 type: "home" 属性设置首页,其他页面不需要设置,默认为page
  33. *
  34. * 尽量保证一个项目 只有一个 这个配置,如果有多个,会按照字母顺序来排列,最终可能不是您想要的效果。
  35. */
  36. type?: 'home'
  37. /**
  38. * 页面布局类型, 模板默认只有 default, 如果在 src/layouts 下新增了 layout, 可以扩展当前属性
  39. * @default 'default'
  40. *
  41. * 当前属性供 https://github.com/uni-helper/vite-plugin-uni-layouts 插件使用
  42. */
  43. layout?: 'default'
  44. /**
  45. * 是否从需要登录的路径中排除
  46. *
  47. * 登录授权(可选):跟以前的 needLogin 类似功能,但是同时支持黑白名单,详情请见 src/router 文件夹
  48. */
  49. excludeLoginPath?: boolean
  50. }
  51. }
  52. // patch uni 类型
  53. // 1. 补全 uni.hideToast() 的 options 类型
  54. // 2. 补全 uni.hideLoading() 的 options 类型
  55. // 3. 使用方式见:https://github.com/unibest-tech/unibest/pull/241
  56. declare global {
  57. declare namespace UniNamespace {
  58. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  59. type HideLoadingCompleteCallback = (res: GeneralCallbackResult) => void
  60. /** 接口调用失败的回调函数 */
  61. type HideLoadingFailCallback = (res: GeneralCallbackResult) => void
  62. /** 接口调用成功的回调函数 */
  63. type HideLoadingSuccessCallback = (res: GeneralCallbackResult) => void
  64. interface HideLoadingOption {
  65. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  66. complete?: HideLoadingCompleteCallback
  67. /** 接口调用失败的回调函数 */
  68. fail?: HideLoadingFailCallback
  69. test: UniNamespace.GeneralCallbackResult
  70. /**
  71. * 微信小程序:需要基础库: `2.22.1`
  72. *
  73. * 微信小程序:目前 toast 和 loading 相关接口可以相互混用,此参数可用于取消混用特性
  74. */
  75. noConflict?: boolean
  76. /** 接口调用成功的回调函数 */
  77. success?: HideLoadingSuccessCallback
  78. }
  79. // ----------------------------------------------------------
  80. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  81. type HideToastCompleteCallback = (res: GeneralCallbackResult) => void
  82. /** 接口调用失败的回调函数 */
  83. type HideToastFailCallback = (res: GeneralCallbackResult) => void
  84. /** 接口调用成功的回调函数 */
  85. type HideToastSuccessCallback = (res: GeneralCallbackResult) => void
  86. interface HideToastOption {
  87. /** 接口调用结束的回调函数(调用成功、失败都会执行) */
  88. complete?: HideToastCompleteCallback
  89. /** 接口调用失败的回调函数 */
  90. fail?: HideToastFailCallback
  91. /**
  92. * 微信小程序:需要基础库: `2.22.1`
  93. *
  94. * 微信小程序:目前 toast 和 loading 相关接口可以相互混用,此参数可用于取消混用特性
  95. */
  96. noConflict?: boolean
  97. /** 接口调用成功的回调函数 */
  98. success?: HideToastSuccessCallback
  99. }
  100. }
  101. interface Uni {
  102. /**
  103. * 隐藏 loading 提示框
  104. *
  105. * 文档: [http://uniapp.dcloud.io/api/ui/prompt?id=hideloading](http://uniapp.dcloud.io/api/ui/prompt?id=hideloading)
  106. * @example ```typescript
  107. * uni.showLoading({
  108. * title: '加载中'
  109. * });
  110. *
  111. * setTimeout(function () {
  112. * uni.hideLoading();
  113. * }, 2000);
  114. *
  115. * ```
  116. * @tutorial [](https://uniapp.dcloud.net.cn/api/ui/prompt.html#hideloading)
  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. hideLoading<T extends UniNamespace.HideToastOption = UniNamespace.HideToastOption>(options?: T): void
  134. /**
  135. * 隐藏消息提示框
  136. *
  137. * 文档: [http://uniapp.dcloud.io/api/ui/prompt?id=hidetoast](http://uniapp.dcloud.io/api/ui/prompt?id=hidetoast)
  138. * @example ```typescript
  139. * uni.hideToast();
  140. * ```
  141. * @tutorial [](https://uniapp.dcloud.net.cn/api/ui/prompt.html#hidetoast)
  142. * @uniPlatform {
  143. * "app": {
  144. * "android": {
  145. * "osVer": "4.4.4",
  146. * "uniVer": "√",
  147. * "unixVer": "3.9.0"
  148. * },
  149. * "ios": {
  150. * "osVer": "9.0",
  151. * "uniVer": "√",
  152. * "unixVer": "3.9.0"
  153. * }
  154. * }
  155. * }
  156. */
  157. // eslint-disable-next-line ts/method-signature-style
  158. hideToast<T extends UniNamespace.HideLoadingOption = UniNamespace.HideLoadingOption>(options?: T): void
  159. }
  160. }
  161. export {} // 防止模块污染