interface.uts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. export type GetBatteryInfoSuccess = {
  2. errMsg: string,
  3. /**
  4. * 设备电量,范围1 - 100
  5. */
  6. level: number,
  7. /**
  8. * 是否正在充电中
  9. */
  10. isCharging: boolean
  11. }
  12. export type GetBatteryInfoOptions = {
  13. /**
  14. * 接口调用结束的回调函数(调用成功、失败都会执行)
  15. */
  16. success?: (res: GetBatteryInfoSuccess) => void
  17. /**
  18. * 接口调用失败的回调函数
  19. */
  20. fail?: (res: UniError) => void
  21. /**
  22. * 接口调用成功的回调
  23. */
  24. complete?: (res: any) => void
  25. }
  26. export type GetBatteryInfoResult = {
  27. /**
  28. * 设备电量,范围1 - 100
  29. */
  30. level: number,
  31. /**
  32. * 是否正在充电中
  33. */
  34. isCharging: boolean
  35. }
  36. /**
  37. * 错误码
  38. * - 1001 getAppContext is null
  39. */
  40. export type GetBatteryInfoErrorCode = 1001 | 1002;
  41. /**
  42. * GetBatteryInfo 的错误回调参数
  43. */
  44. export interface GetBatteryInfoFail extends IUniError {
  45. errCode: GetBatteryInfoErrorCode
  46. };
  47. /**
  48. * 获取电量信息
  49. * @param {GetBatteryInfoOptions} options
  50. *
  51. *
  52. * @tutorial https://uniapp.dcloud.net.cn/api/system/batteryInfo.html
  53. * @platforms APP-IOS = ^9.0,APP-ANDROID = ^22
  54. * @since 3.6.11
  55. *
  56. * @assert () => success({errCode: 0, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:ok", level: 60, isCharging: false })
  57. * @assert () => fail({errCode: 1001, errSubject: "uni-getBatteryInfo", errMsg: "getBatteryInfo:fail getAppContext is null" })
  58. */
  59. export type GetBatteryInfo = (options: GetBatteryInfoOptions) => void
  60. export type GetBatteryInfoSync = () => GetBatteryInfoResult
  61. interface Uni {
  62. /**
  63. * 获取电池电量信息
  64. *
  65. * @example
  66. * ```typescript
  67. * uni.getBatteryInfo({
  68. * success(res) {
  69. * console.log(res);
  70. * }
  71. * })
  72. * ```
  73. * @remark
  74. * - 该接口需要同步调用
  75. * @uniPlatform {
  76. * "app": {
  77. * "android": {
  78. * "osVer": "4.4.4",
  79. * "uniVer": "3.6.11",
  80. * "unixVer": "3.9.0"
  81. * },
  82. * "ios": {
  83. * "osVer": "12.0",
  84. * "uniVer": "3.6.11",
  85. * "unixVer": "4.11"
  86. * },
  87. * "harmony": {
  88. * "osVer": "3.0",
  89. * "uniVer": "4.23",
  90. * "unixVer": "x"
  91. * }
  92. * },
  93. * "web": {
  94. * "uniVer": "3.6.11",
  95. * "unixVer": "4.0"
  96. * }
  97. * }
  98. * @uniVueVersion 2,3 //支持的vue版本
  99. *
  100. */
  101. getBatteryInfo(options: GetBatteryInfoOptions): void,
  102. /**
  103. * 同步获取电池电量信息
  104. *
  105. * @example
  106. * ```typescript
  107. * uni.getBatteryInfo()
  108. * ```
  109. * @remark
  110. * - 该接口需要同步调用
  111. * @uniPlatform {
  112. * "app": {
  113. * "android": {
  114. * "osVer": "4.4.4",
  115. * "uniVer": "3.6.11",
  116. * "unixVer": "3.9.0"
  117. * },
  118. * "ios": {
  119. * "osVer": "12.0",
  120. * "uniVer": "3.6.11",
  121. * "unixVer": "4.11"
  122. * },
  123. * "harmony": {
  124. * "osVer": "3.0",
  125. * "uniVer": "4.23",
  126. * "unixVer": "x"
  127. * }
  128. * },
  129. * "web": {
  130. * "uniVer": "3.6.11",
  131. * "unixVer": "4.0"
  132. * }
  133. * }
  134. * @uniVueVersion 2,3 //支持的vue版本
  135. *
  136. */
  137. getBatteryInfoSync(): GetBatteryInfoResult
  138. }