Skip to content

Commit deeb45d

Browse files
feat: ✨ 支持Button在支付宝小程序平台opentype设为getAuthorize用于获取手机号和用户信息
1 parent db32ef9 commit deeb45d

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

docs/component/button.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@
120120
| show-message-card | 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,open-type="contact"时有效 | boolean | - | false | - |
121121
| classPrefix | 类名前缀,用于使用自定义图标,参见[icon](/component/icon#自定义图标) | string | - | 'wd-icon' | 0.1.27 |
122122
| button-id | 按钮的唯一标识,可用于设置隐私同意授权按钮的id | string | - | - | 1.3.6 |
123+
| scope | 支付宝小程序使用,当 open-type 为 getAuthorize 时有效。 | ButtonScope | `phoneNumber` / `userInfo` | - | $LOWEST_VERSION$ |
124+
125+
### ButtonOpenType 开放能力
126+
127+
| 属性 | 说明 |
128+
| ------------------------- | ------------------------------------------------------------------------------------------ |
129+
| feedback | 打开“意见反馈”页面,用户可提交反馈内容并上传日志。 |
130+
| share | 触发用户转发 |
131+
| getUserInfo | 获取用户信息,可以从@getuserinfo 回调中获取到用户信息 |
132+
| contact | 打开客服会话,如果用户在会话中点击消息卡片后返回应用,可以从 @contact 回调中获得具体信息 |
133+
| getPhoneNumber | 获取用户手机号,可以从@getphonenumber 回调中获取到用户信息 |
134+
| launchApp | 小程序中打开 APP,可以通过 app-parameter 属性设定向 APP 传的参数 |
135+
| openSetting | 打开授权设置页 |
136+
| chooseAvatar | 获取用户头像,可以从@chooseavatar 回调中获取到头像信息 |
137+
| getAuthorize | 支持小程序授权,支付宝小程序配合`scope`使用,可以实现`getPhoneNumber``getUserInfo`功能。 |
138+
| lifestyle | 关注生活号,支付宝小程序 |
139+
| contactShare | 分享到通讯录好友,支付宝小程序 |
140+
| agreePrivacyAuthorization | 用户同意隐私协议按钮。可通过 @agreeprivacyauthorization 监听用户同意隐私协议事件。 |
123141

124142
## Events
125143

src/pages/button/Index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<page-wraper>
33
<view>
44
<demo-block title="基本用法">
5-
<wd-button open-type="getUserInfo" @getuserinfo="handleGetuserinfo">主要按钮</wd-button>
5+
<wd-button>主要按钮</wd-button>
66
<wd-button type="success">成功按钮</wd-button>
77
<wd-button type="info">信息按钮</wd-button>
88
<wd-button type="warning">警告按钮</wd-button>

src/uni_modules/wot-design-uni/components/wd-button/types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* @Author: weisheng
33
* @Date: 2024-03-15 11:36:12
4-
* @LastEditTime: 2024-07-23 11:38:09
4+
* @LastEditTime: 2024-11-04 21:33:52
55
* @LastEditors: weisheng
66
* @Description:
77
* @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-button\types.ts
@@ -43,6 +43,8 @@ export type ButtonOpenType =
4343
| 'openProfile'
4444
| 'agreePrivacyAuthorization'
4545

46+
export type ButtonScope = 'phoneNumber' | 'userInfo'
47+
4648
export const buttonProps = {
4749
...baseProps,
4850
/**
@@ -128,7 +130,12 @@ export const buttonProps = {
128130
/**
129131
* 按钮的唯一标识,可用于设置隐私同意授权按钮的id
130132
*/
131-
buttonId: String
133+
buttonId: String,
134+
/**
135+
* 支付宝小程序,当 open-type 为 getAuthorize 时有效。
136+
* 可选值:'phoneNumber' | 'userInfo'
137+
*/
138+
scope: String as PropType<ButtonScope>
132139
}
133140

134141
export type ButtonProps = ExtractPropTypes<typeof buttonProps>

src/uni_modules/wot-design-uni/components/wd-button/wd-button.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
:session-from="sessionFrom"
2727
:lang="lang"
2828
:hover-stop-propagation="hoverStopPropagation"
29+
:scope="scope"
2930
@click="handleClick"
31+
@getAuthorize="handleGetAuthorize"
3032
@getuserinfo="handleGetuserinfo"
3133
@contact="handleConcat"
3234
@getphonenumber="handleGetphonenumber"
@@ -106,6 +108,18 @@ function handleClick(event: any) {
106108
}
107109
}
108110
111+
/**
112+
* 支付宝小程序授权
113+
* @param event
114+
*/
115+
function handleGetAuthorize(event: any) {
116+
if (props.scope === 'phoneNumber') {
117+
handleGetphonenumber(event)
118+
} else if (props.scope === 'userInfo') {
119+
handleGetuserinfo(event)
120+
}
121+
}
122+
109123
function handleGetuserinfo(event: any) {
110124
emit('getuserinfo', event.detail)
111125
}

src/uni_modules/wot-design-uni/components/wd-tabbar/types.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/*
2-
* @Author: weisheng
3-
* @Date: 2024-03-15 20:40:34
4-
* @LastEditTime: 2024-03-18 15:38:37
5-
* @LastEditors: weisheng
6-
* @Description:
7-
* @FilePath: \wot-design-uni\src\uni_modules\wot-design-uni\components\wd-tabbar\types.ts
8-
* 记得注释
9-
*/
101
import { type ExtractPropTypes, type InjectionKey } from 'vue'
112
import { baseProps, makeBooleanProp, makeNumberProp, makeNumericProp, makeStringProp } from '../common/props'
123
import type { TabbarItem } from '../wd-tabbar-item/types'
@@ -54,7 +45,7 @@ export const tabbarProps = {
5445
*/
5546
bordered: makeBooleanProp(true),
5647
/**
57-
* 是否设置底部安全距禿(iPhone X 类型的机型)
48+
* 是否设置底部安全距离(iPhone X 类型的机型)
5849
*/
5950
safeAreaInsetBottom: makeBooleanProp(false),
6051
/**

0 commit comments

Comments
 (0)