UNPKG

8.21 kBTypeScriptView Raw
1import Taro from '../../index'
2
3declare module '../../index' {
4 namespace openSetting {
5 interface Option {
6 /**
7 * 是否同时获取用户订阅消息的订阅状态,默认不获取。注意:withSubscriptions 只返回用户勾选过订阅面板中的“总是保持以上选择,不再询问”的订阅消息。
8 */
9 withSubscriptions?: boolean
10 /** 接口调用结束的回调函数(调用成功、失败都会执行) */
11 complete?: (res: TaroGeneral.CallbackResult) => void
12 /** 接口调用失败的回调函数 */
13 fail?: (res: TaroGeneral.CallbackResult) => void
14 /** 接口调用成功的回调函数 */
15 success?: (result: SuccessCallbackResult) => void
16 }
17
18 interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
19 /** 用户授权结果 */
20 authSetting: AuthSetting
21 /** 用户订阅消息设置,接口参数 withSubscriptions 值为 true 时才会返回。 */
22 subscriptionsSetting: SubscriptionsSetting
23 /** 调用结果 */
24 errMsg: string
25 }
26 }
27
28 namespace getSetting {
29 interface Option {
30 /**
31 * 是否同时获取用户订阅消息的订阅状态,默认不获取。注意:withSubscriptions 只返回用户勾选过订阅面板中的“总是保持以上选择,不再询问”的订阅消息。
32 */
33 withSubscriptions?: boolean
34 /** 接口调用结束的回调函数(调用成功、失败都会执行) */
35 complete?: (res: TaroGeneral.CallbackResult) => void
36 /** 接口调用失败的回调函数 */
37 fail?: (res: TaroGeneral.CallbackResult) => void
38 /** 接口调用成功的回调函数 */
39 success?: (result: SuccessCallbackResult) => void
40 }
41
42 interface SuccessCallbackResult extends TaroGeneral.CallbackResult {
43 /** 用户授权结果 */
44 authSetting: AuthSetting
45 /** 用户订阅消息设置,接口参数 withSubscriptions 值为 true 时才会返回。 */
46 subscriptionsSetting: SubscriptionsSetting
47 /** 在插件中调用时,当前宿主小程序的用户授权结果 */
48 miniprogramAuthSetting: AuthSetting
49 /** 调用结果 */
50 errMsg: string
51 }
52 }
53
54 /** 用户授权设置信息,详情参考[权限](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html)
55 * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html
56 */
57 interface AuthSetting {
58 /** 是否授权用户信息,对应接口 [Taro.getUserInfo](/docs/apis/open-api/user-info/getUserInfo) */
59 'scope.userInfo'?: boolean
60 /** 是否授权地理位置,对应接口 [Taro.getLocation](/docs/apis/location/getLocation), [Taro.chooseLocation](/docs/apis/location/chooseLocation) */
61 'scope.userLocation'?: boolean
62 /** 是否授权通讯地址,对应接口 [Taro.chooseAddress](/docs/apis/open-api/address/chooseAddress) */
63 'scope.address'?: boolean
64 /** 是否授权发票抬头,对应接口 [Taro.chooseInvoiceTitle](/docs/apis/open-api/invoice/chooseInvoiceTitle) */
65 'scope.invoiceTitle'?: boolean
66 /** 是否授权获取发票,对应接口 [Taro.chooseInvoice](/docs/apis/open-api/invoice/chooseInvoice) */
67 'scope.invoice'?: boolean
68 /** 是否授权微信运动步数,对应接口 [Taro.getWeRunData](/docs/apis/open-api/werun/getWeRunData) */
69 'scope.werun'?: boolean
70 /** 是否授权录音功能,对应接口 [Taro.startRecord](/docs/apis/media/recorder/startRecord) */
71 'scope.record'?: boolean
72 /** 是否授权保存到相册 [Taro.saveImageToPhotosAlbum](/docs/apis/media/image/saveImageToPhotosAlbum), [Taro.saveVideoToPhotosAlbum](/docs/apis/media/video/saveVideoToPhotosAlbum) */
73 'scope.writePhotosAlbum'?: boolean
74 /** 是否授权摄像头,对应 [camera](/docs/components/media/camera) 组件 */
75 'scope.camera'?: boolean
76 /** 是否授权小程序在后台运行蓝牙,对应接口 [Taro.openBluetoothAdapterBackground](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/setting/(wx.openBluetoothAdapterBackground).html) */
77 'scope.bluetoothBackground'?: boolean
78 }
79
80 /** 订阅消息设置
81 *
82 * 注意事项
83 * - itemSettings 只返回用户勾选过订阅面板中的“总是保持以上选择,不再询问”的订阅消息。
84 * @example
85 * ```tsx
86 * Taro.getSetting({
87 * withSubscriptions: true,
88 * success (res) {
89 * console.log(res.authSetting)
90 * // res.authSetting = {
91 * // "scope.userInfo": true,
92 * // "scope.userLocation": true
93 * // }
94 * console.log(res.subscriptionsSetting)
95 * // res.subscriptionsSetting = {
96 * // mainSwitch: true, // 订阅消息总开关
97 * // itemSettings: { // 每一项开关
98 * // SYS_MSG_TYPE_INTERACTIVE: 'accept', // 小游戏系统订阅消息
99 * // SYS_MSG_TYPE_RANK: 'accept'
100 * // zun-LzcQyW-edafCVvzPkK4de2Rllr1fFpw2A_x0oXE: 'reject', // 普通一次性订阅消息
101 * // ke_OZC_66gZxALLcsuI7ilCJSP2OJ2vWo2ooUPpkWrw: 'ban',
102 * // }
103 * // }
104 * }
105 * })
106 * ```
107 * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/setting/SubscriptionsSetting.html
108 */
109 interface SubscriptionsSetting {
110 /** 订阅消息总开关,true 为开启,false 为关闭 */
111 mainSwitch: boolean
112 /** 每一项订阅消息的订阅状态。itemSettings对象的键为一次性订阅消息的模板id或系统订阅消息的类型
113 * - 一次性订阅消息使用方法详见 [Taro.requestSubscribeMessage](/docs/apis/open-api/subscribe-message/requestSubscribeMessage)
114 * - 永久订阅消息(仅小游戏可用)使用方法详见 [Taro.requestSubscribeSystemMessage](https://developers.weixin.qq.com/minigame/dev/api/open-api/subscribe-message/wx.requestSubscribeSystemMessage.html)
115 * @type "accept" | "reject" | "ban"
116 */
117 itemSettings: {
118 [TEMPLATE_ID: string]: keyof SubscriptionsSetting.TemplateReflex | string
119 }
120 }
121
122 namespace SubscriptionsSetting {
123 /** 模版消息订阅类型 */
124 interface TemplateReflex {
125 /** 表示用户同意订阅该条id对应的模板消息 */
126 accept
127 /** 表示用户拒绝订阅该条id对应的模板消息 */
128 reject
129 /** 表示已被后台封禁 */
130 ban
131 }
132 }
133
134 interface TaroStatic {
135 /** 调起客户端小程序设置界面,返回用户设置的操作结果。**设置界面只会出现小程序已经向用户请求过的[权限](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html)**。
136 *
137 * 注意:[2.3.0](https://developers.weixin.qq.com/miniprogram/dev/framework/compatibility.html) 版本开始,用户发生点击行为后,才可以跳转打开设置页,管理授权信息。[详情](https://developers.weixin.qq.com/community/develop/doc/000cea2305cc5047af5733de751008)
138 * @supported weapp
139 * @example
140 * ```tsx
141 * Taro.openSetting({
142 * success: function (res) {
143 * console.log(res.authSetting)
144 * // res.authSetting = {
145 * // "scope.userInfo": true,
146 * // "scope.userLocation": true
147 * // }
148 * }
149 * })
150 * ```
151 * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/setting/wx.openSetting.html
152 */
153 openSetting(option?: openSetting.Option): Promise<openSetting.SuccessCallbackResult>
154
155 /** 获取用户的当前设置。**返回值中只会出现小程序已经向用户请求过的[权限](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html)**。
156 * @supported weapp
157 * @example
158 * ```tsx
159 * Taro.getSetting({
160 * success: function (res) {
161 * console.log(res.authSetting)
162 * // res.authSetting = {
163 * // "scope.userInfo": true,
164 * // "scope.userLocation": true
165 * // }
166 * }
167 * })
168 * ```
169 * @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/setting/wx.getSetting.html
170 */
171 getSetting(option?: getSetting.Option): Promise<getSetting.SuccessCallbackResult>
172 }
173}