antd-mini
Version:
antd-mini 是支付宝小程序 UI 组件库,遵循 Ant Design 规范。
398 lines (371 loc) • 12.7 kB
Markdown
---
nav:
path: /components
group:
title: Bizness Components
order: 15
toc: 'content'
---
Used in scenarios such as product activation and agreement signing
In `index.json` Introducing Components in
```json
"usingComponents": {
"ant-terms": "antd-mini/es/Terms/index"
"ant-terms": "antd-mini/Terms/index"
}
```
```xml
<ant-terms
termPrefix="请阅读并同意"
terms="{{terms}}"
buttons="{{buttons}}"
onButtonTap="handleButtonTap"
onTermTap="handleTermTap"
bindbuttontap="handleButtonTap"
bindtermtap="handleTermTap"
/>
```
```js
Page({
data: {
buttons: [
{ text: '同意协议 + 行动点描述', type: 'primary' }
{ text: '取消', aide: true, type: 'default' }
],
terms: [
{ name: '《用户协议》', key: 'user' }
],
},
handleButtonTap(item, index, checked, event) {
my.showToast({ content: `点击了第 ${index + 1} 个按钮` });
wx.showToast({ title: `点击了第 ${item.detail[1] + 1} 个按钮` });
},
handleTermTap(item, index, event) {
my.showToast({ content: `点击了第 ${index + 1} 个协议` });
wx.showToast({ title: `点击了第 ${item.detail[1] + 1} 个协议` });
},
});
```
```xml
<ant-terms
type="check"
termPrefix="我已阅读并同意"
terms="{{terms}}"
buttons="{{buttons}}"
checkboxTipsText="请阅读后勾选服务协议"
checkboxTipsVisible="{{checkboxTipsVisible}}"
onButtonTap="handleButtonTap"
onTermTap="handleTermTap"
onCheckChange="handleCheckChange"
onTermPrefixTap="handleTermPrefixTap"
bindbuttontap="handleButtonTap"
bindtermtap="handleTermTap"
bindcheckchange="handleCheckChange"
bindtermprefixtap="handleTermPrefixTap"
/>
```
```js
Page({
data: {
buttons: [
{ text: '行动点描述', type: 'primary' }
],
terms: [
{ name: '《用户协议》', key: 'user' }
],
checkboxTipsVisible: false,
},
handleButtonTap(item, checked) {
this.setData({ checkboxTipsVisible: !checked });
this.setData({ checkboxTipsVisible: !item.detail[2] });
},
handleTermTap(item, index) {
my.showToast({ content: `点击了第 ${index + 1} 个协议` });
wx.showToast({ title: `点击了第 ${item.detail[1] + 1} 个协议` });
},
handleCheckChange(checked) {
this.setData({ checkboxTipsVisible: !checked });
if (checked) {
this.setData({ checkboxTipsVisible: false });
}
this.setData({ checkboxTipsVisible: !checked.detail });
if (checked.detail) {
this.setData({ checkboxTipsVisible: false });
}
},
handleTermPrefixTap(checked) {
this.setData({ checkboxTipsVisible: !checked });
if (checked) {
this.setData({ checkboxTipsVisible: false });
}
this.setData({ checkboxTipsVisible: !checked.detail });
if (checked.detail) {
this.setData({ checkboxTipsVisible: false });
}
},
});
```
```xml
<ant-terms
type="read"
termPrefix="当前正In读"
terms="{{terms}}"
buttons="{{buttons}}"
readCurrent="{{readCurrent}}"
onButtonTap="handleButtonTap"
onTermTap="handleTermTap"
onCountdownFinish="handleCountdownFinish"
onReadChange="handleReadChange"
bindbuttontap="handleButtonTap"
bindtermtap="handleTermTap"
bindcountdownfinish="handleCountdownFinish"
bindreadchange="handleReadChange"
>
<scroll-view
enhanced
slot="read-content"
style="height:300px;"
id="scroll-view"
scrollTop="{{scrollTop}}"
scrollY="{{true}}"
scrollWithAnimation="{{true}}"
scrollAnimationDuration="{{300}}"
lowerThreshold="{{100}}"
onScroll="onScroll"
onTouchStart="onTouchStart"
onScrollToLower="onScrollToLower"
bindscroll="onScroll"
binddragstart="onTouchStart"
bindscrolltolower="onScrollToLower"
>
<image
class="term-content"
id="term-content-0"
src="https://mdn.alipayobjects.com/huamei_bsws4g/afts/img/966PR7FNh8cAAAAAAAAAAAAADoEQAQFr/original"
mode="widthFix"
onLoad="onImageLoad"
/>
<image
class="term-content"
id="term-content-1"
src="https://mdn.alipayobjects.com/huamei_bsws4g/afts/img/966PR7FNh8cAAAAAAAAAAAAADoEQAQFr/original"
mode="widthFix"
onLoad="onImageLoad"
/>
<image
class="term-content"
id="term-content-2"
src="https://mdn.alipayobjects.com/huamei_bsws4g/afts/img/966PR7FNh8cAAAAAAAAAAAAADoEQAQFr/original"
mode="widthFix"
onLoad="onImageLoad"
/>
</scroll-view>
<view slot="read-total">
Total {{terms3.length}} agreements
</view>
</ant-terms>
```
```js
Page({
data: {
buttons: [
{ text: '请阅读全部协议', disabled: true, type: 'primary', countdownTime: 30 }
],
terms: [
{ name: '《用户协议》', key: 'user' },
{ name: '《隐私协议》', key: 'private' },
{ name: '《网络协议》', key: 'internet' }
],
readCurrent: 1,
},
handleButtonTap(item, index, checked, event) {
my.showToast({ content: `点击了第 ${index + 1} 个按钮` });
wx.showToast({ title: `点击了第 ${item.detail[1] + 1} 个按钮` });
},
handleTermTap(item, index, event) {
my.showToast({ content: `点击了第 ${index + 1} 个协议` });
wx.showToast({ title: `点击了第 ${item.detail[1] + 1} 个协议` });
},
handleCountdownFinish(item, index) {
this.setData({
buttons3: this.data.buttons3.map((button, idx) =>
idx === index
? { ...button, text: '同意协议 + 行动点描述', disabled: false }
: button
),
});
},
handleReadChange(current) {
current = current.detail;
this.tap = true;
this.setData({
scrollTop:
this.itemRectList[current].top -
this.scrollViewRect.top +
Math.random(),
});
},
async onReady() {
await this.updateRect();
},
async onImageLoad() {
await this.updateRect();
},
async updateRect() {
this.itemRectList = await Promise.all(
this.data.terms3.map((item, index) =>
this.getBoundingClientRect(`
)
);
this.scrollViewRect = await this.getBoundingClientRect('#scroll-view');
},
onTouchStart() {
this.tap = false;
},
onScroll(e) {
if (this.tap) {
return;
}
this.scrollTop = e.detail.scrollTop;
const scrollTop = this.scrollTop + this.itemRectList[0].top;
for (let i = 0; i < this.itemRectList.length; i++) {
const item = this.itemRectList[i];
if (
scrollTop > item.top &&
(!this.itemRectList[i + 1] ||
scrollTop < this.itemRectList[i + 1].top) &&
i !== this.data.readCurrent
) {
this.setData({
readCurrent: i,
});
return;
}
}
},
onScrollToLower() {
console.log('触底');
},
getBoundingClientRect(id) {
if (typeof my === 'undefined') {
return this.getInstanceBoundingClientRect(this, id);
}
return this.getInstanceBoundingClientRect(my, id);
},
getInstanceBoundingClientRect(instance, selector) {
return new Promise((resolve) => {
instance
.createSelectorQuery()
.select(selector)
.boundingClientRect()
.exec((ret) => {
if (ret && ret[0]) {
resolve(ret[0]);
}
});
});
},
});
```
<code src='../../demo/pages/Terms/Fixed/index'></code>
<code src='../../demo/pages/Terms/index'></code>
| Property | Description | Type | Default Value |
| ------------------------------- | -------------------- | ----------------------------------------------------------------- | ------------ |
| type | Protocol Presentation Type | `""` \| `"check"` \| `"read"` | `""` |
| terms | Protocol List | [Term](
| buttons | Button List | [Button](
| buttonsFixed | Whether the button area sucks the bottom | `boolean` | `false` |
| buttonsDirection | Split line direction, default portrait | `"horizontal"` \| `"vertical"` | `"vertical"` |
| termPrefix | Protocol Prefix | `string` | `""` |
| termSuffix | Protocol Suffix | `string` | `""` |
| checkboxTipsText | Check the box to guide the copy | `string` | `""` |
| checkboxTipsVisible | Check box to guide display status | `boolean` | `false` |
| readCurrent | Current sequence number read | `number` | `-` |
| defaultReadCurrent | Current sequence number of default reading | `number` | `-` |
|
|
|
|
|
|
|
|
|
|
|
|
| Property | Description | Type | Default Value |
| ---- | -------- | -------- | ------ |
| key | Unique identification | `string` | `-` |
| name | Agreement Name | `string` | `-` |
| Property | Description | Type | Default Value |
| ----------------------------------------------------- | ------------------ | -------- | ------ |
| key | Unique identification | `string` | `-` |
| text | Button Copy | `string` | `-` |
| countdownTime | Number of seconds, in seconds | `number` | `-` |
| Transparent transmission [ant-button](/components/button