lib.wx.app.d.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*! *****************************************************************************
  2. Copyright (c) 2021 Tencent, Inc. All rights reserved.
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of
  4. this software and associated documentation files (the "Software"), to deal in
  5. the Software without restriction, including without limitation the rights to
  6. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  7. of the Software, and to permit persons to whom the Software is furnished to do
  8. so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in all
  10. copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  17. SOFTWARE.
  18. ***************************************************************************** */
  19. declare namespace WechatMiniprogram.App {
  20. interface ReferrerInfo {
  21. /** 来源小程序或公众号或App的 appId
  22. *
  23. * 以下场景支持返回 referrerInfo.appId:
  24. * - 1020(公众号 profile 页相关小程序列表): appId
  25. * - 1035(公众号自定义菜单):来源公众号 appId
  26. * - 1036(App 分享消息卡片):来源应用 appId
  27. * - 1037(小程序打开小程序):来源小程序 appId
  28. * - 1038(从另一个小程序返回):来源小程序 appId
  29. * - 1043(公众号模板消息):来源公众号 appId
  30. */
  31. appId: string
  32. /** 来源小程序传过来的数据,scene=1037或1038时支持 */
  33. extraData?: any
  34. }
  35. type SceneValues =
  36. | 1001
  37. | 1005
  38. | 1006
  39. | 1007
  40. | 1008
  41. | 1011
  42. | 1012
  43. | 1013
  44. | 1014
  45. | 1017
  46. | 1019
  47. | 1020
  48. | 1023
  49. | 1024
  50. | 1025
  51. | 1026
  52. | 1027
  53. | 1028
  54. | 1029
  55. | 1030
  56. | 1031
  57. | 1032
  58. | 1034
  59. | 1035
  60. | 1036
  61. | 1037
  62. | 1038
  63. | 1039
  64. | 1042
  65. | 1043
  66. | 1044
  67. | 1045
  68. | 1046
  69. | 1047
  70. | 1048
  71. | 1049
  72. | 1052
  73. | 1053
  74. | 1056
  75. | 1057
  76. | 1058
  77. | 1059
  78. | 1064
  79. | 1067
  80. | 1069
  81. | 1071
  82. | 1072
  83. | 1073
  84. | 1074
  85. | 1077
  86. | 1078
  87. | 1079
  88. | 1081
  89. | 1082
  90. | 1084
  91. | 1089
  92. | 1090
  93. | 1091
  94. | 1092
  95. | 1095
  96. | 1096
  97. | 1097
  98. | 1099
  99. | 1102
  100. | 1124
  101. | 1125
  102. | 1126
  103. | 1129
  104. interface LaunchShowOption {
  105. /** 打开小程序的路径 */
  106. path: string
  107. /** 打开小程序的query */
  108. query: IAnyObject
  109. /** 打开小程序的场景值
  110. * - 1001:发现栏小程序主入口,「最近使用」列表(基础库2.2.4版本起包含「我的小程序」列表)
  111. * - 1005:微信首页顶部搜索框的搜索结果页
  112. * - 1006:发现栏小程序主入口搜索框的搜索结果页
  113. * - 1007:单人聊天会话中的小程序消息卡片
  114. * - 1008:群聊会话中的小程序消息卡片
  115. * - 1011:扫描二维码
  116. * - 1012:长按图片识别二维码
  117. * - 1013:扫描手机相册中选取的二维码
  118. * - 1014:小程序模板消息
  119. * - 1017:前往小程序体验版的入口页
  120. * - 1019:微信钱包(微信客户端7.0.0版本改为支付入口)
  121. * - 1020:公众号 profile 页相关小程序列表
  122. * - 1023:安卓系统桌面图标
  123. * - 1024:小程序 profile 页
  124. * - 1025:扫描一维码
  125. * - 1026:发现栏小程序主入口,「附近的小程序」列表
  126. * - 1027:微信首页顶部搜索框搜索结果页「使用过的小程序」列表
  127. * - 1028:我的卡包
  128. * - 1029:小程序中的卡券详情页
  129. * - 1030:自动化测试下打开小程序
  130. * - 1031:长按图片识别一维码
  131. * - 1032:扫描手机相册中选取的一维码
  132. * - 1034:微信支付完成页
  133. * - 1035:公众号自定义菜单
  134. * - 1036:App 分享消息卡片
  135. * - 1037:小程序打开小程序
  136. * - 1038:从另一个小程序返回
  137. * - 1039:摇电视
  138. * - 1042:添加好友搜索框的搜索结果页
  139. * - 1043:公众号模板消息
  140. * - 1044:带 shareTicket 的小程序消息卡片 [详情](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html)
  141. * - 1045:朋友圈广告
  142. * - 1046:朋友圈广告详情页
  143. * - 1047:扫描小程序码
  144. * - 1048:长按图片识别小程序码
  145. * - 1049:扫描手机相册中选取的小程序码
  146. * - 1052:卡券的适用门店列表
  147. * - 1053:搜一搜的结果页
  148. * - 1056:聊天顶部音乐播放器右上角菜单
  149. * - 1057:钱包中的银行卡详情页
  150. * - 1058:公众号文章
  151. * - 1059:体验版小程序绑定邀请页
  152. * - 1064:微信首页连Wi-Fi状态栏
  153. * - 1067:公众号文章广告
  154. * - 1069:移动应用
  155. * - 1071:钱包中的银行卡列表页
  156. * - 1072:二维码收款页面
  157. * - 1073:客服消息列表下发的小程序消息卡片
  158. * - 1074:公众号会话下发的小程序消息卡片
  159. * - 1077:摇周边
  160. * - 1078:微信连Wi-Fi成功提示页
  161. * - 1079:微信游戏中心
  162. * - 1081:客服消息下发的文字链
  163. * - 1082:公众号会话下发的文字链
  164. * - 1084:朋友圈广告原生页
  165. * - 1089:微信聊天主界面下拉,「最近使用」栏(基础库2.2.4版本起包含「我的小程序」栏)
  166. * - 1090:长按小程序右上角菜单唤出最近使用历史
  167. * - 1091:公众号文章商品卡片
  168. * - 1092:城市服务入口
  169. * - 1095:小程序广告组件
  170. * - 1096:聊天记录
  171. * - 1097:微信支付签约页
  172. * - 1099:页面内嵌插件
  173. * - 1102:公众号 profile 页服务预览
  174. * - 1124:扫“一物一码”打开小程序
  175. * - 1125:长按图片识别“一物一码”
  176. * - 1126:扫描手机相册中选取的“一物一码”
  177. * - 1129:微信爬虫访问 [详情](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/sitemap.html)
  178. */
  179. scene: SceneValues
  180. /** shareTicket,详见 [获取更多转发信息]((转发#获取更多转发信息)) */
  181. shareTicket: string
  182. /** 当场景为由从另一个小程序或公众号或App打开时,返回此字段 */
  183. referrerInfo?: ReferrerInfo
  184. }
  185. interface PageNotFoundOption {
  186. /** 不存在页面的路径 */
  187. path: string
  188. /** 打开不存在页面的 query */
  189. query: IAnyObject
  190. /** 是否本次启动的首个页面(例如从分享等入口进来,首个页面是开发者配置的分享页面) */
  191. isEntryPage: boolean
  192. }
  193. interface Option {
  194. /** 生命周期回调—监听小程序初始化
  195. *
  196. * 小程序初始化完成时触发,全局只触发一次。
  197. */
  198. onLaunch(options: LaunchShowOption): void
  199. /** 生命周期回调—监听小程序显示
  200. *
  201. * 小程序启动,或从后台进入前台显示时
  202. */
  203. onShow(options: LaunchShowOption): void
  204. /** 生命周期回调—监听小程序隐藏
  205. *
  206. * 小程序从前台进入后台时
  207. */
  208. onHide(): void
  209. /** 错误监听函数
  210. *
  211. * 小程序发生脚本错误,或者 api
  212. */
  213. onError(/** 错误信息,包含堆栈 */ error: string): void
  214. /** 页面不存在监听函数
  215. *
  216. * 小程序要打开的页面不存在时触发,会带上页面信息回调该函数
  217. *
  218. * **注意:**
  219. * 1. 如果开发者没有添加 `onPageNotFound` 监听,当跳转页面不存在时,将推入微信客户端原生的页面不存在提示页面。
  220. * 2. 如果 `onPageNotFound` 回调中又重定向到另一个不存在的页面,将推入微信客户端原生的页面不存在提示页面,并且不再回调 `onPageNotFound`。
  221. *
  222. * 最低基础库: 1.9.90
  223. */
  224. onPageNotFound(options: PageNotFoundOption): void
  225. /**
  226. * 小程序有未处理的 Promise 拒绝时触发。也可以使用 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html) 绑定监听。注意事项请参考 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html)。
  227. * **参数**:与 [wx.onUnhandledRejection](https://developers.weixin.qq.com/miniprogram/dev/api/base/app/app-event/wx.onUnhandledRejection.html) 一致
  228. */
  229. onUnhandledRejection: OnUnhandledRejectionCallback
  230. /**
  231. * 系统切换主题时触发。也可以使用 wx.onThemeChange 绑定监听。
  232. *
  233. * 最低基础库: 2.11.0
  234. */
  235. onThemeChange: OnThemeChangeCallback
  236. }
  237. type Instance<T extends IAnyObject> = Option & T
  238. type Options<T extends IAnyObject> = Partial<Option> &
  239. T &
  240. ThisType<Instance<T>>
  241. type TrivialInstance = Instance<IAnyObject>
  242. interface Constructor {
  243. <T extends IAnyObject>(options: Options<T>): void
  244. }
  245. interface GetAppOption {
  246. /** 在 `App` 未定义时返回默认实现。当App被调用时,默认实现中定义的属性会被覆盖合并到App中。一般用于独立分包
  247. *
  248. * 最低基础库: 2.2.4
  249. */
  250. allowDefault?: boolean
  251. }
  252. interface GetApp {
  253. <T = IAnyObject>(opts?: GetAppOption): Instance<T>
  254. }
  255. }
  256. declare let App: WechatMiniprogram.App.Constructor
  257. declare let getApp: WechatMiniprogram.App.GetApp