project init & fix ui
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
:: BASE_DOC ::
|
||||
|
||||
## API
|
||||
### PullDownRefresh Props
|
||||
|
||||
name | type | default | description | required
|
||||
-- | -- | -- | -- | --
|
||||
custom-style `v0.25.0` | String | - | \- | N
|
||||
external-classes | Array | - | `['t-class', 't-class-loading','t-class-text', 't-class-indicator']` | N
|
||||
loading-bar-height | String / Number | 50 | \- | N
|
||||
loading-props | Object | - | Typescript:`LoadingProps`,[Loading API Documents](./loading?tab=api)。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/pull-down-refresh/type.ts) | N
|
||||
loading-texts | Array | [] | Typescript:`string[]` | N
|
||||
max-bar-height | String / Number | 80 | \- | N
|
||||
refresh-timeout | Number | 3000 | \- | N
|
||||
value | Boolean | false | \- | N
|
||||
default-value | Boolean | false | uncontrolled property | N
|
||||
|
||||
### PullDownRefresh Events
|
||||
|
||||
name | params | description
|
||||
-- | -- | --
|
||||
change | `(value: boolean)` | \-
|
||||
refresh | \- | \-
|
||||
scrolltolower | \- | \-
|
||||
timeout | \- | \-
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
title: PullDownRefresh 下拉刷新
|
||||
description: 用于快速刷新页面信息,刷新可以是整页刷新也可以是页面的局部刷新。
|
||||
spline: message
|
||||
isComponent: true
|
||||
---
|
||||
|
||||
<span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20lines-96%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20functions-81%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20statements-94%25-blue" /></span><span class="coverages-badge" style="margin-right: 10px"><img src="https://img.shields.io/badge/coverages%3A%20branches-81%25-blue" /></span>
|
||||
## 引入
|
||||
|
||||
全局引入,在 miniprogram 根目录下的`app.json`中配置,局部引入,在需要引入的页面或组件的`index.json`中配置。
|
||||
|
||||
```json
|
||||
"usingComponents": {
|
||||
"t-pull-down-refresh": "tdesign-miniprogram/pull-down-refresh/pull-down-refresh"
|
||||
}
|
||||
```
|
||||
|
||||
## 代码演示
|
||||
|
||||
### 顶部下拉刷新
|
||||
|
||||
由于组件内无法监听页面滚动,需要由页面获取组件实例,并将页面滚动事件传递到组件。
|
||||
|
||||
{{ base }}
|
||||
|
||||
|
||||
|
||||
> 在使用 pull-down-refresh 组件的页面,建议开启 `disableScroll: true`
|
||||
|
||||
## API
|
||||
### PullDownRefresh Props
|
||||
|
||||
名称 | 类型 | 默认值 | 说明 | 必传
|
||||
-- | -- | -- | -- | --
|
||||
custom-style `v0.25.0` | String | - | 自定义组件样式 | N
|
||||
external-classes | Array | - | 加载loading样式。`['t-class', 't-class-loading','t-class-text', 't-class-indicator']` | N
|
||||
loading-bar-height | String / Number | 50 | 加载中下拉高度,如果值为数字则单位是:'px' | N
|
||||
loading-props | Object | - | 加载loading样式。TS 类型:`LoadingProps`,[Loading API Documents](./loading?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/pull-down-refresh/type.ts) | N
|
||||
loading-texts | Array | [] | 提示语,组件内部默认值为 ['下拉刷新', '松手刷新', '正在刷新', '刷新完成']。TS 类型:`string[]` | N
|
||||
max-bar-height | String / Number | 80 | 最大下拉高度,如果值为数字则单位是:'px' | N
|
||||
refresh-timeout | Number | 3000 | 刷新超时时间 | N
|
||||
value | Boolean | false | 组件状态,值为 `true` 表示下拉状态,值为 `false` 表示收起状态 | N
|
||||
default-value | Boolean | false | 组件状态,值为 `true` 表示下拉状态,值为 `false` 表示收起状态。非受控属性 | N
|
||||
|
||||
### PullDownRefresh Events
|
||||
|
||||
名称 | 参数 | 描述
|
||||
-- | -- | --
|
||||
change | `(value: boolean)` | 下拉或收起时触发,用户手势往下滑动触发下拉状态,手势松开触发收起状态
|
||||
refresh | \- | 结束下拉时触发
|
||||
scrolltolower | \- | 滚动到页面底部时触发
|
||||
timeout | \- | 刷新超时触发
|
||||
3
miniprogram_npm/tdesign-miniprogram/pull-down-refresh/props.d.ts
vendored
Normal file
3
miniprogram_npm/tdesign-miniprogram/pull-down-refresh/props.d.ts
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { TdPullDownRefreshProps } from './type';
|
||||
declare const props: TdPullDownRefreshProps;
|
||||
export default props;
|
||||
@@ -0,0 +1,39 @@
|
||||
const props = {
|
||||
customStyle: {
|
||||
type: String,
|
||||
value: '',
|
||||
},
|
||||
externalClasses: {
|
||||
type: Array,
|
||||
},
|
||||
loadingBarHeight: {
|
||||
type: String,
|
||||
optionalTypes: [Number],
|
||||
value: 50,
|
||||
},
|
||||
loadingProps: {
|
||||
type: Object,
|
||||
},
|
||||
loadingTexts: {
|
||||
type: Array,
|
||||
value: [],
|
||||
},
|
||||
maxBarHeight: {
|
||||
type: String,
|
||||
optionalTypes: [Number],
|
||||
value: 80,
|
||||
},
|
||||
refreshTimeout: {
|
||||
type: Number,
|
||||
value: 3000,
|
||||
},
|
||||
value: {
|
||||
type: Boolean,
|
||||
value: null,
|
||||
},
|
||||
defaultValue: {
|
||||
type: Boolean,
|
||||
value: false,
|
||||
},
|
||||
};
|
||||
export default props;
|
||||
50
miniprogram_npm/tdesign-miniprogram/pull-down-refresh/pull-down-refresh.d.ts
vendored
Normal file
50
miniprogram_npm/tdesign-miniprogram/pull-down-refresh/pull-down-refresh.d.ts
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { SuperComponent } from '../common/src/index';
|
||||
export default class PullDownRefresh extends SuperComponent {
|
||||
pixelRatio: number;
|
||||
startPoint: {
|
||||
pageX: number;
|
||||
pageY: number;
|
||||
} | null;
|
||||
isPulling: boolean;
|
||||
maxBarHeight: number;
|
||||
loadingBarHeight: number;
|
||||
maxRefreshAnimateTimeFlag: number;
|
||||
closingAnimateTimeFlag: number;
|
||||
externalClasses: string[];
|
||||
options: {
|
||||
multipleSlots: boolean;
|
||||
};
|
||||
properties: import("./type").TdPullDownRefreshProps;
|
||||
data: {
|
||||
prefix: string;
|
||||
classPrefix: string;
|
||||
barHeight: number;
|
||||
refreshStatus: number;
|
||||
loosing: boolean;
|
||||
enableToRefresh: boolean;
|
||||
scrollTop: number;
|
||||
};
|
||||
lifetimes: {
|
||||
attached(): void;
|
||||
detached(): void;
|
||||
};
|
||||
observers: {
|
||||
value(val: any): void;
|
||||
maxBarHeight(val: any): void;
|
||||
loadingBarHeight(val: any): void;
|
||||
};
|
||||
methods: {
|
||||
onScrollToBottom(): void;
|
||||
onScrollToTop(): void;
|
||||
onScroll(e: any): void;
|
||||
onTouchStart(e: WechatMiniprogram.Component.TrivialInstance): void;
|
||||
onTouchMove(e: WechatMiniprogram.Component.TrivialInstance): void;
|
||||
onTouchEnd(e: WechatMiniprogram.Component.TrivialInstance): void;
|
||||
toRpx(v: number | string): number;
|
||||
toPx(v: number): number;
|
||||
setRefreshBarHeight(barHeight: number): Promise<unknown>;
|
||||
close(): void;
|
||||
setScrollTop(scrollTop: number): void;
|
||||
scrollToTop(): void;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
import { SuperComponent, wxComponent } from '../common/src/index';
|
||||
import config from '../common/config';
|
||||
import props from './props';
|
||||
const { prefix } = config;
|
||||
const name = `${prefix}-pull-down-refresh`;
|
||||
let PullDownRefresh = class PullDownRefresh extends SuperComponent {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.pixelRatio = 1;
|
||||
this.startPoint = null;
|
||||
this.isPulling = false;
|
||||
this.maxBarHeight = 0;
|
||||
this.loadingBarHeight = 200;
|
||||
this.maxRefreshAnimateTimeFlag = 0;
|
||||
this.closingAnimateTimeFlag = 0;
|
||||
this.externalClasses = [`${prefix}-class`, `${prefix}-class-loading`, `${prefix}-class-tex`, `${prefix}-class-indicator`];
|
||||
this.options = {
|
||||
multipleSlots: true,
|
||||
};
|
||||
this.properties = props;
|
||||
this.data = {
|
||||
prefix,
|
||||
classPrefix: name,
|
||||
barHeight: 0,
|
||||
refreshStatus: -1,
|
||||
loosing: false,
|
||||
enableToRefresh: true,
|
||||
scrollTop: 0,
|
||||
};
|
||||
this.lifetimes = {
|
||||
attached() {
|
||||
const { screenWidth } = wx.getSystemInfoSync();
|
||||
const { maxBarHeight, loadingBarHeight } = this.properties;
|
||||
this.pixelRatio = 750 / screenWidth;
|
||||
if (maxBarHeight) {
|
||||
this.maxBarHeight = this.toRpx(maxBarHeight);
|
||||
}
|
||||
if (loadingBarHeight) {
|
||||
this.setData({
|
||||
computedLoadingBarHeight: this.toRpx(loadingBarHeight),
|
||||
});
|
||||
this.loadingBarHeight = this.toRpx(loadingBarHeight);
|
||||
}
|
||||
},
|
||||
detached() {
|
||||
clearTimeout(this.maxRefreshAnimateTimeFlag);
|
||||
clearTimeout(this.closingAnimateTimeFlag);
|
||||
},
|
||||
};
|
||||
this.observers = {
|
||||
value(val) {
|
||||
if (!val) {
|
||||
clearTimeout(this.maxRefreshAnimateTimeFlag);
|
||||
this.setData({ refreshStatus: 3 });
|
||||
this.close();
|
||||
}
|
||||
},
|
||||
maxBarHeight(val) {
|
||||
this.maxBarHeight = this.toRpx(val);
|
||||
},
|
||||
loadingBarHeight(val) {
|
||||
this.setData({
|
||||
computedLoadingBarHeight: this.toRpx(val),
|
||||
});
|
||||
this.loadingBarHeight = this.toRpx(val);
|
||||
},
|
||||
};
|
||||
this.methods = {
|
||||
onScrollToBottom() {
|
||||
this.triggerEvent('scrolltolower');
|
||||
},
|
||||
onScrollToTop() {
|
||||
this.setData({
|
||||
enableToRefresh: true,
|
||||
});
|
||||
},
|
||||
onScroll(e) {
|
||||
this.setData({
|
||||
enableToRefresh: e.detail.scrollTop === 0,
|
||||
});
|
||||
},
|
||||
onTouchStart(e) {
|
||||
if (this.isPulling || !this.data.enableToRefresh)
|
||||
return;
|
||||
const { touches } = e;
|
||||
if (touches.length !== 1)
|
||||
return;
|
||||
const { pageX, pageY } = touches[0];
|
||||
this.setData({ loosing: false });
|
||||
this.startPoint = { pageX, pageY };
|
||||
this.isPulling = true;
|
||||
},
|
||||
onTouchMove(e) {
|
||||
if (!this.startPoint)
|
||||
return;
|
||||
const { touches } = e;
|
||||
if (touches.length !== 1)
|
||||
return;
|
||||
const { pageY } = touches[0];
|
||||
const offset = pageY - this.startPoint.pageY;
|
||||
const barHeight = this.toRpx(offset);
|
||||
if (barHeight > 0) {
|
||||
if (barHeight > this.maxBarHeight) {
|
||||
this.setRefreshBarHeight(this.maxBarHeight);
|
||||
}
|
||||
else {
|
||||
this.setRefreshBarHeight(barHeight);
|
||||
}
|
||||
}
|
||||
},
|
||||
onTouchEnd(e) {
|
||||
if (!this.startPoint)
|
||||
return;
|
||||
const { changedTouches } = e;
|
||||
if (changedTouches.length !== 1)
|
||||
return;
|
||||
const { pageY } = changedTouches[0];
|
||||
const barHeight = this.toRpx(pageY - this.startPoint.pageY);
|
||||
this.startPoint = null;
|
||||
this.setData({ loosing: true });
|
||||
if (barHeight > this.loadingBarHeight) {
|
||||
this.setData({
|
||||
barHeight: this.loadingBarHeight,
|
||||
refreshStatus: 2,
|
||||
});
|
||||
this.triggerEvent('change', { value: true });
|
||||
this.triggerEvent('refresh');
|
||||
this.maxRefreshAnimateTimeFlag = setTimeout(() => {
|
||||
this.maxRefreshAnimateTimeFlag = null;
|
||||
if (this.data.refreshStatus === 2) {
|
||||
this.triggerEvent('timeout');
|
||||
this.close();
|
||||
}
|
||||
}, this.properties.refreshTimeout);
|
||||
}
|
||||
else {
|
||||
this.close();
|
||||
}
|
||||
},
|
||||
toRpx(v) {
|
||||
if (typeof v === 'number')
|
||||
return v * this.pixelRatio;
|
||||
return parseInt(v, 10);
|
||||
},
|
||||
toPx(v) {
|
||||
return v / this.pixelRatio;
|
||||
},
|
||||
setRefreshBarHeight(barHeight) {
|
||||
const data = { barHeight };
|
||||
if (barHeight >= this.loadingBarHeight) {
|
||||
data.refreshStatus = 1;
|
||||
}
|
||||
else {
|
||||
data.refreshStatus = 0;
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
this.setData(data, () => resolve(barHeight));
|
||||
});
|
||||
},
|
||||
close() {
|
||||
const animationDuration = 240;
|
||||
this.setData({ barHeight: 0 });
|
||||
this.triggerEvent('change', { value: false });
|
||||
this.closingAnimateTimeFlag = setTimeout(() => {
|
||||
this.closingAnimateTimeFlag = null;
|
||||
this.setData({ refreshStatus: -1 });
|
||||
this.isPulling = false;
|
||||
}, animationDuration);
|
||||
},
|
||||
setScrollTop(scrollTop) {
|
||||
this.setData({ scrollTop });
|
||||
},
|
||||
scrollToTop() {
|
||||
this.setScrollTop(0);
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
PullDownRefresh = __decorate([
|
||||
wxComponent()
|
||||
], PullDownRefresh);
|
||||
export default PullDownRefresh;
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"t-loading": "../loading/loading"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<scroll-view
|
||||
style="{{ customStyle }}"
|
||||
class="{{classPrefix}} {{prefix}}-class"
|
||||
scroll-top="{{scrollTop}}"
|
||||
bind:touchstart="onTouchStart"
|
||||
bind:touchmove="onTouchMove"
|
||||
bind:touchend="onTouchEnd"
|
||||
bind:scroll="onScroll"
|
||||
bindscrolltoupper="onScrollToTop"
|
||||
bindscrolltolower="onScrollToBottom"
|
||||
scroll-y
|
||||
enable-back-to-top
|
||||
enhanced
|
||||
scroll-with-animation
|
||||
bounces="{{false}}"
|
||||
>
|
||||
<view
|
||||
class="{{classPrefix}}__track {{classPrefix + '__track--' + (loosing ? 'loosing' : '')}}"
|
||||
style="transform: translate3d(0, {{barHeight + 'rpx'}}, 0);"
|
||||
>
|
||||
<view class="{{classPrefix}}__tips" style="height: {{computedLoadingBarHeight}}rpx">
|
||||
<t-loading
|
||||
wx:if="{{refreshStatus === 2}}"
|
||||
delay="{{loadingProps.delay || 0}}"
|
||||
duration="{{loadingProps.duration || 800}}"
|
||||
indicator="{{loadingProps.indicator || true}}"
|
||||
layout="{{loadingProps.layout || 'horizontal'}}"
|
||||
loading="{{loadingProps.loading || true}}"
|
||||
pause="{{loadingProps.pause || false}}"
|
||||
progress="{{loadingProps.progress}}"
|
||||
reverse="{{loadingProps.reverse}}"
|
||||
size="{{loadingProps.size || '50rpx'}}"
|
||||
text="{{loadingProps.text || loadingTexts[refreshStatus]}}"
|
||||
theme="{{loadingProps.theme || 'circular'}}"
|
||||
t-class-indicator="{{prefix}}-class-indicator"
|
||||
/>
|
||||
<view wx:elif="{{refreshStatus >= 0}}" class="{{classPrefix}}__text {{prefix}}-class-text"
|
||||
>{{loadingTexts[refreshStatus]}}</view
|
||||
>
|
||||
</view>
|
||||
<slot />
|
||||
</view>
|
||||
</scroll-view>
|
||||
@@ -0,0 +1,57 @@
|
||||
.t-float-left {
|
||||
float: left;
|
||||
}
|
||||
.t-float-right {
|
||||
float: right;
|
||||
}
|
||||
@keyframes tdesign-fade-out {
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
.hotspot-expanded.relative {
|
||||
position: relative;
|
||||
}
|
||||
.hotspot-expanded::after {
|
||||
content: '';
|
||||
display: block;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
transform: scale(1.5);
|
||||
}
|
||||
.t-pull-down-refresh {
|
||||
overflow: hidden;
|
||||
max-height: 100vh;
|
||||
height: 100%;
|
||||
}
|
||||
.t-pull-down-refresh__track {
|
||||
position: relative;
|
||||
}
|
||||
.t-pull-down-refresh__track--loosing {
|
||||
transition: transform ease 0.24s;
|
||||
}
|
||||
.t-pull-down-refresh__tips {
|
||||
position: absolute;
|
||||
color: var(--td-pull-down-refresh-color, var(--td-font-gray-3, rgba(0, 0, 0, 0.4)));
|
||||
font-size: 24rpx;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
transform: translateY(-100%);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
.t-pull-down-refresh__text {
|
||||
margin: 16rpx 0 0;
|
||||
}
|
||||
.t-pull-down-refresh__wrap {
|
||||
position: relative;
|
||||
}
|
||||
41
miniprogram_npm/tdesign-miniprogram/pull-down-refresh/type.d.ts
vendored
Normal file
41
miniprogram_npm/tdesign-miniprogram/pull-down-refresh/type.d.ts
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import { LoadingProps } from '../loading/index';
|
||||
export interface TdPullDownRefreshProps {
|
||||
customStyle?: {
|
||||
type: StringConstructor;
|
||||
value?: string;
|
||||
};
|
||||
externalClasses?: {
|
||||
type: ArrayConstructor;
|
||||
value?: ['t-class', 't-class-loading', 't-class-text', 't-class-indicator'];
|
||||
};
|
||||
loadingBarHeight?: {
|
||||
type: StringConstructor;
|
||||
optionalTypes: Array<NumberConstructor>;
|
||||
value?: string | number;
|
||||
};
|
||||
loadingProps?: {
|
||||
type: ObjectConstructor;
|
||||
value?: LoadingProps;
|
||||
};
|
||||
loadingTexts?: {
|
||||
type: ArrayConstructor;
|
||||
value?: string[];
|
||||
};
|
||||
maxBarHeight?: {
|
||||
type: StringConstructor;
|
||||
optionalTypes: Array<NumberConstructor>;
|
||||
value?: string | number;
|
||||
};
|
||||
refreshTimeout?: {
|
||||
type: NumberConstructor;
|
||||
value?: number;
|
||||
};
|
||||
value?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
defaultValue?: {
|
||||
type: BooleanConstructor;
|
||||
value?: boolean;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export {};
|
||||
Reference in New Issue
Block a user