Skip to content

Commit

Permalink
Helly w feature/button agreeprivacyauthorization (#2330)
Browse files Browse the repository at this point in the history
* feat(button): add props buttonId & add event  bindagreeprivacyauthorization

* fix: 命名规范,修改button为tId

* update button readme

* test: update snapshot

---------

Co-authored-by: HellyW <w@hellyw.com>
Co-authored-by: HellyW <wuhaohao1993@outlook.com>
  • Loading branch information
3 people authored Aug 29, 2023
1 parent 56b5517 commit 71084c9
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/button/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

name | type | default | description | required
-- | -- | -- | -- | --
t-id | String | - | button tag id | N
block | Boolean | false | make button to be a block-level element | N
content | String / Slot | - | button's children elements | N
custom-dataset | Object | - | Typescript:`any` | N
Expand All @@ -20,7 +21,7 @@ suffix | Slot | - | \- | N
theme | String | default | button theme。options:default/primary/danger | N
type | String | - | type of button element, same as formType of Miniprogram。options:submit/reset | N
variant | String | base | button variant。options:base/outline/text | N
open-type | String | - | options:contact/share/getPhoneNumber/getUserInfo/launchApp/openSetting/feedback/chooseAvatar | N
open-type | String | - | options:contact/share/getPhoneNumber/getUserInfo/launchApp/openSetting/feedback/chooseAvatar/agreePrivacyAuthorization | N
hover-stop-propagation | Boolean | false | \- | N
hover-start-time | Number | 20 | \- | N
hover-stay-time | Number | 70 | \- | N
Expand All @@ -38,6 +39,7 @@ binderror | Eventhandle | - | \- | N
bindopensetting | Eventhandle | - | \- | N
bindlaunchapp | Eventhandle | - | \- | N
bindchooseavatar | Eventhandle | - | \- | N
bindagreeprivacyauthorization | Eventhandle | - | \-| N

### Button Events

Expand Down
4 changes: 3 additions & 1 deletion src/button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ isComponent: true

名称 | 类型 | 默认值 | 说明 | 必传
-- | -- | -- | -- | --
t-id | String | - | 按钮标签id | N
block | Boolean | false | 是否为块级元素 | N
content | String / Slot | - | 按钮内容 | N
custom-dataset | Object | - | 自定义 dataset,可通过 event.currentTarget.dataset.custom 获取。TS 类型:`any` | N
Expand All @@ -79,7 +80,7 @@ suffix | Slot | - | 右侧内容,可用于定义右侧图标 | N
theme | String | default | 组件风格,依次为品牌色、危险色。可选项:default/primary/danger/light | N
type | String | - | 同小程序的 formType。可选项:submit/reset | N
variant | String | base | 按钮形式,基础、线框、文字。可选项:base/outline/dashed/text | N
open-type | String | - | 微信开放能力。<br />具体释义:<br />`contact` 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息,<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/customer-message.html">具体说明</a> (*小程序插件中不能使用*);<br />`share` 触发用户转发,使用前建议先阅读<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html#使用指引">使用指引</a>;<br />`getPhoneNumber` 获取用户手机号,可以从 bindgetphonenumber 回调中获取到用户信息,<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html">具体说明</a> (*小程序插件中不能使用*);<br />`getUserInfo` 获取用户信息,可以从 bindgetuserinfo 回调中获取到用户信息 (*小程序插件中不能使用*);<br />`launchApp` 打开APP,可以通过 app-parameter 属性设定向 APP 传的参数<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/launchApp.html">具体说明</a>;<br />`openSetting` 打开授权设置页;<br />`feedback` 打开“意见反馈”页面,用户可提交反馈内容并上传<a href="https://developers.weixin.qq.com/miniprogram/dev/api/base/debug/wx.getLogManager.html">日志</a>,开发者可以登录<a href="https://mp.weixin.qq.com/">小程序管理后台</a>后进入左侧菜单“客服反馈”页面获取到反馈内容;<br />`chooseAvatar` 获取用户头像,可以从 bindchooseavatar 回调中获取到头像信息。<br />[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/button.html)。可选项:contact/share/getPhoneNumber/getUserInfo/launchApp/openSetting/feedback/chooseAvatar | N
open-type | String | - | 微信开放能力。<br />具体释义:<br />`contact` 打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息,<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/customer-message/customer-message.html">具体说明</a> (*小程序插件中不能使用*);<br />`share` 触发用户转发,使用前建议先阅读<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share.html#使用指引">使用指引</a>;<br />`getPhoneNumber` 获取用户手机号,可以从 bindgetphonenumber 回调中获取到用户信息,<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html">具体说明</a> (*小程序插件中不能使用*);<br />`getUserInfo` 获取用户信息,可以从 bindgetuserinfo 回调中获取到用户信息 (*小程序插件中不能使用*);<br />`launchApp` 打开APP,可以通过 app-parameter 属性设定向 APP 传的参数<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/launchApp.html">具体说明</a>;<br />`openSetting` 打开授权设置页;<br />`feedback` 打开“意见反馈”页面,用户可提交反馈内容并上传<a href="https://developers.weixin.qq.com/miniprogram/dev/api/base/debug/wx.getLogManager.html">日志</a>,开发者可以登录<a href="https://mp.weixin.qq.com/">小程序管理后台</a>后进入左侧菜单“客服反馈”页面获取到反馈内容;<br />`chooseAvatar` 获取用户头像,可以从 bindchooseavatar 回调中获取到头像信息;<br />`agreePrivacyAuthorization`用户同意隐私协议按钮。用户点击一次此按钮后,所有隐私接口可以正常调用。可通过`bindagreeprivacyauthorization`监听用户同意隐私协议事件。隐私合规开发指南详情可见《<a href="https://developers.weixin.qq.com/miniprogram/dev/framework/user-privacy/PrivacyAuthorize.html">小程序隐私协议开发指南</a>》。<br />[小程序官方文档](https://developers.weixin.qq.com/miniprogram/dev/component/button.html)。可选项:contact/share/getPhoneNumber/getUserInfo/launchApp/openSetting/feedback/chooseAvatar/agreePrivacyAuthorization | N
hover-class | String | '' | 指定按钮按下去的样式类,按钮不为加载或禁用状态时有效。当 `hover-class="none"` 时,没有点击态效果 | N
hover-stop-propagation | Boolean | false | 指定是否阻止本节点的祖先节点出现点击态 | N
hover-start-time | Number | 20 | 按住后多久出现点击态,单位毫秒 | N
Expand All @@ -98,6 +99,7 @@ binderror | Eventhandle | - | 当使用开放能力时,发生错误的回调
bindopensetting | Eventhandle | - | 在打开授权设置页后回调,open-type=openSetting时有效 | N
bindlaunchapp | Eventhandle | - | 打开 APP 成功的回调,open-type=launchApp时有效 | N
bindchooseavatar | Eventhandle | - | 获取用户头像回调,open-type=chooseAvatar时有效 | N
bindagreeprivacyauthorization | Eventhandle | - | 用户同意隐私协议事件回调,open-type=agreePrivacyAuthorization时有效 | N

### Button Events

Expand Down
6 changes: 6 additions & 0 deletions src/button/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('button', () => {
const handler = jest.fn();
const id = simulate.load({
template: `<t-button
tId="test"
class="btn"
openType="{{openType}}"
bind:getuserinfo="handler"
Expand All @@ -66,6 +67,7 @@ describe('button', () => {
bind:opensetting="handler"
bind:launchapp="handler"
bind:chooseavatar="handler"
bind:agreeprivacyauthorization="handler"
></t-button>`,
data: {
openType: 'getUserInfo',
Expand Down Expand Up @@ -109,5 +111,9 @@ describe('button', () => {
$btn.dispatchEvent('chooseavatar');
await simulate.sleep(10);
expect(handler).toHaveBeenCalledTimes(14);

$btn.dispatchEvent('agreeprivacyauthorization');
await simulate.sleep(10);
expect(handler).toHaveBeenCalledTimes(16);
});
});
3 changes: 3 additions & 0 deletions src/button/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export default class Button extends SuperComponent {
chooseavatar(e) {
this.triggerEvent('chooseavatar', e.detail);
},
agreeprivacyauthorization(e) {
this.triggerEvent('agreeprivacyauthorization', e.detail);
},
handleTap(e) {
if (this.data.disabled || this.data.loading) return;

Expand Down
2 changes: 2 additions & 0 deletions src/button/button.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<wxs src="../common/utils.wxs" module="_" />

<button
id="{{tId}}"
style="{{_._style([style, customStyle])}}"
data-custom="{{ customDataset }}"
class="class {{className}}"
Expand All @@ -26,6 +27,7 @@
bind:opensetting="opensetting"
bind:launchapp="launchapp"
bind:chooseavatar="chooseavatar"
bind:agreeprivacyauthorization="agreeprivacyauthorization"
aria-label="{{ariaLabel}}"
>
<template
Expand Down
6 changes: 5 additions & 1 deletion src/button/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* */

import { TdButtonProps } from './type';
const props: TdButtonProps = {
const props: TdButtonProps = {
/**按钮id */
tId: {
type: String,
},
/** 是否为块级元素 */
block: {
type: Boolean,
Expand Down
8 changes: 7 additions & 1 deletion src/button/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { LoadingProps } from '../loading/index';
import { SizeEnum } from '../common/common';

export interface TdButtonProps {
/**按钮id */
tId?: {
type: StringConstructor;
value?: string;
};
/**
* 是否为块级元素
* @default false
Expand Down Expand Up @@ -127,7 +132,8 @@ export interface TdButtonProps {
| 'launchApp'
| 'openSetting'
| 'feedback'
| 'chooseAvatar';
| 'chooseAvatar'
| 'agreePrivacyAuthorization';
};
/**
* 指定按钮按下去的样式类,按钮不为加载或禁用状态时有效。当 `hover-class="none"` 时,没有点击态效果
Expand Down
2 changes: 2 additions & 0 deletions src/calendar/__test__/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ exports[`calendar :base 1`] = `
hoverStartTime="{{20}}"
hoverStayTime="{{70}}"
hoverStopPropagation="{{false}}"
id=""
lang="en"
openType=""
sendMessageImg=""
Expand All @@ -765,6 +766,7 @@ exports[`calendar :base 1`] = `
sessionFrom=""
showMessageCard="{{false}}"
style=""
bind:agreeprivacyauthorization="agreeprivacyauthorization"
bind:chooseavatar="chooseavatar"
bind:contact="contact"
bind:error="error"
Expand Down
1 change: 1 addition & 0 deletions src/common/template/button.wxml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template name="button">
<t-button
t-id="{{tId}}"
block="{{block || false}}"
class="{{class || ''}}"
t-class="{{externalClass}}"
Expand Down

0 comments on commit 71084c9

Please sign in to comment.