1 | import { ComponentType } from 'react'
|
2 | import { StandardProps, CommonEventFunction } from './common'
|
3 | import { StyleProp, ViewStyle } from 'react-native'
|
4 |
|
5 | interface ButtonProps extends StandardProps {
|
6 | /** 按钮的大小
|
7 | * @supported weapp, h5, rn, alipay, tt
|
8 | * @default default
|
9 | */
|
10 | size?: keyof ButtonProps.Size
|
11 |
|
12 | /** 按钮的样式类型
|
13 | * @supported weapp, h5, rn, alipay, tt
|
14 | * @default default
|
15 | */
|
16 | type?: keyof ButtonProps.Type
|
17 |
|
18 | /** 按钮是否镂空,背景色透明
|
19 | * @supported weapp, h5, rn, alipay
|
20 | * @default false
|
21 | */
|
22 | plain?: boolean
|
23 |
|
24 | /** 是否禁用
|
25 | * @supported weapp, h5, rn, alipay, tt
|
26 | * @default false
|
27 | */
|
28 | disabled?: boolean
|
29 |
|
30 | /** 名称前是否带 loading 图标
|
31 | * @supported weapp, h5, rn, alipay, tt
|
32 | * @default false
|
33 | */
|
34 | loading?: boolean
|
35 |
|
36 | /** 用于 `<form/>` 组件,点击分别会触发 `<form/>` 组件的 submit/reset 事件
|
37 | * @supported weapp, alipay, tt
|
38 | */
|
39 | formType?: keyof ButtonProps.FormType
|
40 |
|
41 | /** 微信开放能力
|
42 | * @supported weapp, alipay, qq, tt
|
43 | */
|
44 | openType?: ButtonProps.OpenType
|
45 |
|
46 | /** 指定按下去的样式类。当 `hover-class="none"` 时,没有点击态效果
|
47 | * @default button-hover
|
48 | * @supported weapp, alipay, h5, tt
|
49 | * @rn 支持 hoverStyle 属性,但框架未支持 hoverClass
|
50 | */
|
51 | hoverClass?: string
|
52 |
|
53 | /** 由于 RN 不支持 Class,故 RN 端的 Button 组件实现了 `hoverStyle`属性,写法和 style 类似,只不过 `hoverStyle` 的样式是指定按下去的样式。
|
54 | * @default none
|
55 | * @supported rn
|
56 | */
|
57 | hoverStyle?: StyleProp<ViewStyle>
|
58 |
|
59 | /** 指定是否阻止本节点的祖先节点出现点击态
|
60 | * @default false
|
61 | * @supported weapp, alipay, tt
|
62 | */
|
63 | hoverStopPropagation?: boolean
|
64 |
|
65 | /** 按住后多久出现点击态,单位毫秒
|
66 | * @default 20
|
67 | * @supported weapp, alipay, h5, rn, tt
|
68 | */
|
69 | hoverStartTime?: number
|
70 |
|
71 | /** 手指松开后点击态保留时间,单位毫秒
|
72 | * @default 70
|
73 | * @supported weapp, alipay, h5, rn, tt
|
74 | */
|
75 | hoverStayTime?: number
|
76 |
|
77 | /** 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。
|
78 | *
|
79 | * 生效时机: `open-type="getUserInfo"`
|
80 | * @supported weapp
|
81 | */
|
82 | lang?: keyof ButtonProps.Lang
|
83 |
|
84 | /** 会话来源
|
85 | *
|
86 | * 生效时机:`open-type="contact"`
|
87 | * @supported weapp
|
88 | */
|
89 | sessionFrom?: string
|
90 |
|
91 | /** 会话内消息卡片标题
|
92 | *
|
93 | * 生效时机:`open-type="contact"`
|
94 | * @default 当前标题
|
95 | * @supported weapp
|
96 | */
|
97 | sendMessageTitle?: string
|
98 |
|
99 | /** 会话内消息卡片点击跳转小程序路径
|
100 | *
|
101 | * 生效时机:`open-type="contact"`
|
102 | * @default 当前标题
|
103 | * @supported weapp
|
104 | */
|
105 | sendMessagePath?: string
|
106 |
|
107 | /** 会话内消息卡片图片
|
108 | *
|
109 | * 生效时机:`open-type="contact"`
|
110 | * @default 截图
|
111 | * @supported weapp
|
112 | */
|
113 | sendMessageImg?: string
|
114 |
|
115 | /** 打开 APP 时,向 APP 传递的参数
|
116 | *
|
117 | * 生效时机:`open-type="launchApp"`
|
118 | * @supported weapp, qq
|
119 | */
|
120 | appParameter?: string
|
121 |
|
122 | /** 微信小程序子商户能力中,添加 business-id 字段指向子商户
|
123 | *
|
124 | * 生效时机:`open-type="contact"`
|
125 | * @supported weapp
|
126 | */
|
127 | businessId?: string
|
128 |
|
129 | /** 支付宝小程序 scope
|
130 | *
|
131 | * 生效时机:`open-type="getAuthorize"`
|
132 | * @supported weapp
|
133 | */
|
134 | scope?: 'userInfo' | 'phoneNumber'
|
135 |
|
136 | /** 显示会话内消息卡片
|
137 | *
|
138 | * 生效时机:`open-type="contact"`
|
139 | * @default false
|
140 | */
|
141 | showMessageCard?: boolean
|
142 |
|
143 | /** 用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与 Taro.getUserInfo 返回的一致
|
144 | *
|
145 | * 生效时机: `open-type="getUserInfo"`
|
146 | * @supported weapp
|
147 | */
|
148 | onGetUserInfo?: CommonEventFunction<ButtonProps.onGetUserInfoEventDetail>
|
149 |
|
150 | /** 支付宝获取会员基础信息授权回调
|
151 | *
|
152 | * 生效时机:`open-type="getAuthorize"`
|
153 | * @supported alipay
|
154 | */
|
155 | onGetAuthorize?: CommonEventFunction
|
156 |
|
157 | /** 客服消息回调
|
158 | *
|
159 | * 生效时机:`open-type="contact"`
|
160 | * @supported weapp
|
161 | */
|
162 | onContact?: CommonEventFunction<ButtonProps.onContactEventDetail>
|
163 |
|
164 | /** 获取用户手机号回调
|
165 | *
|
166 | * 生效时机:`open-type="getphonenumber"`
|
167 | * @supported weapp, tt
|
168 | */
|
169 | onGetPhoneNumber?: CommonEventFunction<ButtonProps.onGetPhoneNumberEventDetail>
|
170 |
|
171 | /** 获取用户实名
|
172 | *
|
173 | * 生效时机:`open-type="getRealnameAuthInfo"`
|
174 | * @deprecated
|
175 | * @supported weapp
|
176 | */
|
177 | onGetRealNameAuthInfo?: CommonEventFunction
|
178 |
|
179 | /** 当使用开放能力时,发生错误的回调
|
180 | *
|
181 | * 生效时机:`open-type="launchApp"`
|
182 | * @supported weapp
|
183 | */
|
184 | onError?: CommonEventFunction
|
185 |
|
186 | /** 在打开授权设置页后回调
|
187 | *
|
188 | * 生效时机:`open-type="openSetting"`
|
189 | * @supported weapp
|
190 | */
|
191 | onOpenSetting?: CommonEventFunction<ButtonProps.onOpenSettingEventDetail>
|
192 |
|
193 | /** 打开 APP 成功的回调
|
194 | *
|
195 | * 生效时机:`open-type="launchApp"`
|
196 | * @supported weapp
|
197 | */
|
198 | onLaunchApp?: CommonEventFunction
|
199 |
|
200 | /** 获取用户头像回调
|
201 | *
|
202 | * 生效时机:`open-type="chooseAvatar"`
|
203 | * @supported weapp
|
204 | */
|
205 | onChooseAvatar?: CommonEventFunction
|
206 | }
|
207 |
|
208 | declare namespace ButtonProps {
|
209 | /** size 的合法值 */
|
210 | interface Size {
|
211 | /** 默认大小 */
|
212 | default
|
213 | /** 小尺寸 */
|
214 | mini
|
215 | }
|
216 | /** type 的合法值 */
|
217 | interface Type {
|
218 | /** 绿色 */
|
219 | primary
|
220 | /** 白色 */
|
221 | default
|
222 | /** 红色 */
|
223 | warn
|
224 | }
|
225 | /** form-type 的合法值 */
|
226 | interface FormType {
|
227 | /** 提交表单 */
|
228 | submit
|
229 | /** 重置表单 */
|
230 | reset
|
231 | }
|
232 | /** open-type 的合法值 */
|
233 | type OpenType = keyof openTypeKeys["weapp"] | keyof openTypeKeys["alipay"] | keyof openTypeKeys["qq"]
|
234 | /** open-type 的合法值 */
|
235 | interface openTypeKeys {
|
236 | weapp: {
|
237 | /** 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从回调中获得具体信息
|
238 | * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/customer-message.html
|
239 | */
|
240 | contact
|
241 | /** 触发用户转发,使用前建议先阅读使用指引
|
242 | * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%BC%95
|
243 | */
|
244 | share
|
245 | /** 获取用户手机号,可以从回调中获取到用户信息
|
246 | * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
|
247 | */
|
248 | getPhoneNumber
|
249 | /** 获取用户信息,可以从回调中获取到用户信息 */
|
250 | getUserInfo
|
251 | /** 用户实名信息授权
|
252 | * @deprecated
|
253 | */
|
254 | getRealNameAuthInfo
|
255 | /** 打开APP,可以通过 app-parameter 属性设定向APP传的参数
|
256 | * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/launchApp.html
|
257 | */
|
258 | launchApp
|
259 | /** 打开授权设置页 */
|
260 | openSetting
|
261 | /** 打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容 */
|
262 | feedback
|
263 | /** 获取用户头像,可以从回调中获得具体信息 */
|
264 | chooseAvatar
|
265 | }
|
266 | /** 支付宝小程序专属的 open-type 合法值
|
267 | * @see https://opendocs.alipay.com/mini/component/button
|
268 | */
|
269 | alipay: {
|
270 | /** 触发 自定义分享 */
|
271 | share
|
272 | /** 支持小程序授权 */
|
273 | getAuthorize
|
274 | /** 分享到通讯录好友 */
|
275 | contactShare
|
276 | /** 关注生活号 */
|
277 | lifestyle
|
278 | }
|
279 | /** QQ 小程序专属的 open-type 合法值
|
280 | * @see https://q.qq.com/wiki/develop/miniprogram/component/form/button.html
|
281 | */
|
282 | qq: {
|
283 | /** 触发用户转发,使用前建议先阅读使用指引
|
284 | * @see https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_share.html#%E8%BD%AC%E5%8F%91-2
|
285 | */
|
286 | share
|
287 | /** 获取用户信息,可以从 onGetUserInfo 回调中获取到用户信息 */
|
288 | getUserInfo
|
289 | /** 打开APP,可以通过 app-parameter 属性设定向APP传的参数
|
290 | * @see https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_app.html
|
291 | */
|
292 | launchApp
|
293 | /** 打开授权设置页 */
|
294 | openSetting
|
295 | /** 呼起吐个槽反馈页面,开发者可以到官网查看反馈 */
|
296 | feedback
|
297 | /** 呼起群资料卡页面,可以通过 group-id 属性设定需要打开的群资料卡的群号,同时 app.json 中必须配置 groupIdList(数量不超过 10 个),表明可以打开群资料卡的群号 */
|
298 | openGroupProfile
|
299 | /** 添加好友,对方需要通过该小程序进行授权,允许被加好友后才能调用成功[用户授权](https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_userinfo.html#%E6%8E%88%E6%9D%83) */
|
300 | addFriend
|
301 | /** 添加彩签,点击后添加状态有用户提示,无回调 */
|
302 | addColorSign
|
303 | /** 打开公众号资料卡,可以通过 public-id 属性设定需要打开的公众号资料卡的号码,同时 app.json 中必须配置 publicIdList(目前只能配置 1 个),表明可以打开的公众号资料卡的号码 */
|
304 | openPublicProfile
|
305 | /** 添加群应用(只有管理员或群主有权操作,建议先调用 qq.getGroupInfo 获取当前用户是否为管理员,如果是管理员才显示该按钮),添加后给button绑定 onAddGroupApp 事件接收回调数据。 */
|
306 | addGroupApp
|
307 | /** 在自定义开放数据域组件中,向指定好友发起分享据 */
|
308 | shareMessageToFriend
|
309 | }
|
310 | }
|
311 | /** lang 的合法值 */
|
312 | interface Lang {
|
313 | /** 英文 */
|
314 | en
|
315 | /** 简体中文 */
|
316 | zh_CN
|
317 | /** 繁体中文 */
|
318 | zh_TW
|
319 | }
|
320 |
|
321 | interface onGetUserInfoEventDetail {
|
322 | userInfo: {
|
323 | /** 昵称 */
|
324 | nickName: string
|
325 | /** 头像 */
|
326 | avatarUrl: string
|
327 | /** 性别 */
|
328 | gender: keyof Gender
|
329 | /** 省份,如:`Yunnan` */
|
330 | province: string
|
331 | /** 城市,如:`Dalian` */
|
332 | city: string
|
333 | /** 国家,如:`China` */
|
334 | country: string
|
335 | }
|
336 | /** 不包括敏感信息的原始数据 `JSON` 字符串,用于计算签名 */
|
337 | rawData: string
|
338 | /** 使用 `sha1(rawData + sessionkey)` 得到字符串,用于校验用户信息 */
|
339 | signature: string
|
340 | /** 包括敏感数据在内的完整用户信息的加密数据 */
|
341 | encryptedData: string
|
342 | /** 加密算法的初始向量 */
|
343 | iv: string
|
344 | /* 用户信息的调用状态 */
|
345 | errMsg: string
|
346 | /** 敏感数据对应的云 ID,开通[云开发](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)的小程序才会返回,可通过云调用直接获取开放数据,详细见[云调用直接获取开放数据](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html#method-cloud) */
|
347 | cloudID?: string
|
348 | }
|
349 |
|
350 | /** 性别的合法值 */
|
351 | interface Gender {
|
352 | /** 未知 */
|
353 | 0
|
354 | /** 男 */
|
355 | 1
|
356 | /** 女 */
|
357 | 2
|
358 | }
|
359 |
|
360 | interface onContactEventDetail {
|
361 | /* 小程序消息的调用状态 */
|
362 | errMsg: string
|
363 | /** 小程序消息指定的路径 */
|
364 | path: string
|
365 | /** 小程序消息指定的查询参数 */
|
366 | query: Record<string, any>
|
367 | }
|
368 |
|
369 | interface onGetPhoneNumberEventDetail {
|
370 | /* 获取用户手机号的调用状态 */
|
371 | errMsg: string
|
372 | /** 包括敏感数据在内的完整用户信息的加密数据 */
|
373 | encryptedData: string
|
374 | /** 加密算法的初始向量 */
|
375 | iv: string
|
376 | /** 动态令牌。可通过动态令牌换取用户手机号。
|
377 | * @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html#%E4%BD%BF%E7%94%A8%E6%8C%87%E5%BC%95
|
378 | */
|
379 | code?: string
|
380 | }
|
381 |
|
382 | interface onOpenSettingEventDetail {
|
383 | /* 打开授权设置页的调用状态 */
|
384 | errMsg: string
|
385 | /* 用户授权结果 */
|
386 | authSetting: Record<string, boolean>
|
387 | }
|
388 | }
|
389 |
|
390 | /** 按钮
|
391 | * @classification forms
|
392 | * @supported weapp, h5, rn, tt
|
393 | * @example_react
|
394 | * ```tsx
|
395 | * export default class PageButton extends Component {
|
396 | * state = {
|
397 | * btn: [
|
398 | * {
|
399 | * text: '页面主操作 Normal',
|
400 | * size: 'default',
|
401 | * type: 'primary'
|
402 | * },
|
403 | * {
|
404 | * text: '页面主操作 Loading',
|
405 | * size: 'default',
|
406 | * type: 'primary',
|
407 | * loading: true,
|
408 | * },
|
409 | * {
|
410 | * text: '页面主操作 Disabled',
|
411 | * size: 'default',
|
412 | * type: 'primary',
|
413 | * disabled: true,
|
414 | * },
|
415 | * {
|
416 | * text: '页面次要操作 Normal',
|
417 | * size: 'default',
|
418 | * type: 'default'
|
419 | * },
|
420 | * {
|
421 | * text: '页面次要操作 Disabled',
|
422 | * size: 'default',
|
423 | * type: 'default',
|
424 | * disabled: true,
|
425 | * },
|
426 | * {
|
427 | * text: '警告类操作 Normal',
|
428 | * size: 'default',
|
429 | * type: 'warn'
|
430 | * },
|
431 | * {
|
432 | * text: '警告类操作 Disabled',
|
433 | * size: 'default',
|
434 | * type: 'warn',
|
435 | * disabled: true,
|
436 | * }
|
437 | * ]
|
438 | * }
|
439 | * render () {
|
440 | * return (
|
441 | * <View className='container'>
|
442 | * {this.state.btn.map(item => {
|
443 | * return (
|
444 | * <Button
|
445 | * size={item.size ? item.size : ''}
|
446 | * type={item.type ? item.type : ''}
|
447 | * loading={item.loading ? item.loading : false}
|
448 | * disabled={item.disabled ? item.disabled : false}
|
449 | * >
|
450 | * {item.text}
|
451 | * </Button>
|
452 | * )
|
453 | * })}
|
454 | * <Button className='btn-max-w' plain type='primary'>按钮</Button>
|
455 | * <Button className='btn-max-w' plain type='primary' disabled>不可点击的按钮</Button>
|
456 | * <Button className='btn-max-w' plain >按钮</Button>
|
457 | * <Button className='btn-max-w' plain disabled >按钮</Button>
|
458 | * <Button size='mini' type='primary'>按钮</Button>
|
459 | * <Button size='mini' >按钮</Button>
|
460 | * <Button size='mini' type='warn'>按钮</Button>
|
461 | * </View>
|
462 | * )
|
463 | * }
|
464 | * }
|
465 | * ```
|
466 | * @example_vue
|
467 | * ```html
|
468 | * <template>
|
469 | * <view class="container">
|
470 | * <button
|
471 | * v-for="item in btn"
|
472 | * :size="item.size ? item.size : ''"
|
473 | * :type="item.type ? item.type : ''"
|
474 | * :loading="item.loading ? item.loading : false"
|
475 | * :disabled="item.disabled ? item.disabled : false"
|
476 | * >
|
477 | * {{ item.text }}
|
478 | * </button>
|
479 | * <button class="btn-max-w" :plain="true" type="primary">按钮</button>
|
480 | * <button class="btn-max-w" :plain="true" type="primary" :disabled="true">不可点击的按钮</button>
|
481 | * <button class="btn-max-w" :plain="true">按钮</button>
|
482 | * <button class="btn-max-w" :plain="true" :disabled="true">按钮</button>
|
483 | * <button size="mini" type="primary">按钮</button>
|
484 | * <button size="mini" >按钮</button>
|
485 | * <button size="mini" type="warn">按钮</button>
|
486 | * </view>
|
487 | * </template>
|
488 | *
|
489 | * <script>
|
490 | * export default {
|
491 | * data() {
|
492 | * return {
|
493 | * btn: [
|
494 | * {
|
495 | * text: '页面主操作 Normal',
|
496 | * size: 'default',
|
497 | * type: 'primary'
|
498 | * },
|
499 | * {
|
500 | * text: '页面主操作 Loading',
|
501 | * size: 'default',
|
502 | * type: 'primary',
|
503 | * loading: true,
|
504 | * },
|
505 | * {
|
506 | * text: '页面主操作 Disabled',
|
507 | * size: 'default',
|
508 | * type: 'primary',
|
509 | * disabled: true,
|
510 | * },
|
511 | * {
|
512 | * text: '页面次要操作 Normal',
|
513 | * size: 'default',
|
514 | * type: 'default'
|
515 | * },
|
516 | * {
|
517 | * text: '页面次要操作 Disabled',
|
518 | * size: 'default',
|
519 | * type: 'default',
|
520 | * disabled: true,
|
521 | * },
|
522 | * {
|
523 | * text: '警告类操作 Normal',
|
524 | * size: 'default',
|
525 | * type: 'warn'
|
526 | * },
|
527 | * {
|
528 | * text: '警告类操作 Disabled',
|
529 | * size: 'default',
|
530 | * type: 'warn',
|
531 | * disabled: true,
|
532 | * }
|
533 | * ]
|
534 | * }
|
535 | * }
|
536 | * }
|
537 | * </script>
|
538 | * ```
|
539 | * @see https://developers.weixin.qq.com/miniprogram/dev/component/button.html
|
540 | */
|
541 | declare const Button: ComponentType<ButtonProps>
|
542 |
|
543 | export { Button, ButtonProps }
|