Skip to content

Commit e48932b

Browse files
feat(progress): 新增 Progress 组件 (#789)
* feat(Progress): 新增 Progress 组件 * refactor(Example): 增加示例小程序中的组件 Icon 1. 新增 LoadMore 组件 Icon 2. 新增 Skeleton 组件 Icon 3. 新增 Steps 组件 Icon 4. 新增 Sticky 组件 Icon Co-authored-by: 桔子 <[email protected]>
1 parent 97a9762 commit e48932b

File tree

27 files changed

+549
-7
lines changed

27 files changed

+549
-7
lines changed

config/styles/_base.less

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,5 @@
8989
@transition-time : .2s;
9090
@ease-in-out : ease-in-out;
9191

92+
// Progress
93+
@progress-active-color : @theme-color;

dist/progress/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/progress/index.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"component":true,"usingComponents":{}}

dist/progress/index.wxml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
<view class="container l-class">
3+
<view class="text l-text-class" wx:if="{{showInfo && textPosition==='left'}}" style="color:{{textColor?textColor:''}};margin-right:{{interval}}rpx">
4+
{{percent}}%
5+
</view>
6+
<view class="progress short" style="height:{{strokeWidth}}rpx;">
7+
<view class="slot" style="margin-left:{{marginLeft}}rpx;margin-top:{{marginTop}}rpx;">
8+
<slot name="header"></slot>
9+
</view>
10+
<view class="percent {{activeColor?'':'active'}} l-active-class" style="width:{{percent}}%;height:{{strokeWidth}}rpx;border-radius:{{borderRadius}}rpx;{{activeColor?'background-color:'+activeColor+';':''}}"></view>
11+
<view class="background l-background-class" style="height:{{strokeWidth}}rpx;border-radius:{{borderRadius}}rpx;background-color:{{backgroundColor}};"></view>
12+
</view>
13+
<view class="text l-text-class" wx:if="{{showInfo && textPosition==='right'}}" style="color:{{textColor?textColor:''}};margin-left:{{interval}}rpx">
14+
{{percent}}%
15+
</view>
16+
</view>

dist/progress/index.wxss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.container{display:flex;flex-direction:row;align-items:center}.progress{position:relative;width:100%;transition:all .25s ease-in-out}.percent{position:absolute;z-index:1}.active{background-color:#3963bc}.text{color:#3963bc;font-size:30rpx}.background{position:absolute;width:100%}.header{position:absolute!important;z-index:2}.slot{position:absolute;z-index:2}

examples/app.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
"pages/loadmore/index",
6666
"pages/loadmore/case/index",
6767
"pages/steps/index",
68-
"pages/skeleton/index"
68+
"pages/skeleton/index",
69+
"pages/progress/index"
6970
]
7071
},
7172
{
@@ -140,4 +141,4 @@
140141
"content-card": "/components/content-card/index"
141142
},
142143
"sitemapLocation": "sitemap.json"
143-
}
144+
}

examples/dist/progress/index.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// components/progress/index.js
2+
import {
3+
px2rpx
4+
} from '../utils/util.js';
5+
import validator from '../behaviors/validator';
6+
Component({
7+
/**
8+
* 组件的属性列表
9+
*/
10+
externalClasses: ['l-class', 'l-text-class', 'l-active-class', 'l-background-class'],
11+
behaviors: [validator],
12+
properties: {
13+
percent: {
14+
type: Number,
15+
value: 0,
16+
},
17+
strokeWidth: {
18+
type: Number,
19+
value: 12
20+
},
21+
borderRadius: {
22+
type: Number,
23+
value: 6,
24+
},
25+
activeColor: {
26+
type: String,
27+
},
28+
backgroundColor: {
29+
type: String,
30+
value: '#EBEBEB',
31+
},
32+
showInfo: {
33+
type: Boolean,
34+
value: false
35+
},
36+
textPosition: {
37+
type: String,
38+
value: 'right',
39+
options: ['left', 'right']
40+
},
41+
textColor: {
42+
type: String,
43+
},
44+
interval: {
45+
type: Number,
46+
value: 20,
47+
},
48+
active: {
49+
type: Boolean,
50+
value: false
51+
},
52+
duration: {
53+
type: Number,
54+
value: 30
55+
}
56+
},
57+
58+
options: {
59+
multipleSlots: true,
60+
pureDataPattern: /^_/ // 指定所有 _ 开头的数据字段为纯数据字段
61+
},
62+
63+
/**
64+
* 组件的初始数据
65+
*/
66+
data: {
67+
_slotWidth: 0,
68+
_slotHeight: 0,
69+
_progressWidth: 0,
70+
_progressHeight: 0,
71+
_marginBottom: 0,
72+
marginLeft: 0,
73+
marginTop: 0,
74+
_useSlot: false,
75+
},
76+
77+
observers: {
78+
'_slotWidth, _slotHeight, _progressWidth, _progressHeight, percent,_useSlot': function (_slotWidth, _slotHeight, _progressWidth, _progressHeight, percent, _useSlot) {
79+
if (_useSlot) {
80+
const marginTop = -(_slotHeight - _progressHeight) / 2;
81+
const marginLeft = (_progressWidth - _slotWidth) * percent / 100;
82+
this.setData({
83+
marginTop,
84+
marginLeft
85+
});
86+
}
87+
}
88+
},
89+
90+
lifetimes: {
91+
attached() {
92+
if (this.data.percent > 100) {
93+
this.setData({
94+
percent: 100
95+
});
96+
}
97+
98+
const querySlot = wx.createSelectorQuery().in(this);
99+
querySlot.select('.slot').boundingClientRect(res => {
100+
let _useSlot = this.data._useSlot;
101+
if (res.width) {
102+
_useSlot = true;
103+
}
104+
this.setData({
105+
_useSlot,
106+
_slotWidth: px2rpx(res.width),
107+
_slotHeight: px2rpx(res.height)
108+
});
109+
}).exec();
110+
const queryProgress = wx.createSelectorQuery().in(this);
111+
queryProgress.select('.progress').boundingClientRect(res => {
112+
this.setData({
113+
_progressHeight: px2rpx(res.height),
114+
_progressWidth: px2rpx(res.width)
115+
});
116+
}).exec();
117+
118+
const percent = this.data.percent;
119+
let now = 0;
120+
if (this.data.active) {
121+
setInterval(() => {
122+
if (now < percent) {
123+
now += 1;
124+
this.setData({
125+
percent: now
126+
});
127+
}
128+
}, this.data.duration);
129+
}
130+
},
131+
},
132+
133+
/**
134+
* 组件的方法列表
135+
*/
136+
methods: {}
137+
});

examples/dist/progress/index.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"component": true,
3+
"usingComponents": {}
4+
}

examples/dist/progress/index.wxml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!-- components/progress/index.wxml -->
2+
<view class="container l-class">
3+
<view class="text l-text-class" wx:if="{{showInfo && textPosition==='left'}}" style="color:{{textColor?textColor:''}};margin-right:{{interval}}rpx">
4+
{{percent}}%
5+
</view>
6+
<view class="progress short" style="height:{{strokeWidth}}rpx;">
7+
<view class="slot" style="margin-left:{{marginLeft}}rpx;margin-top:{{marginTop}}rpx;">
8+
<slot name="header"></slot>
9+
</view>
10+
<view class="percent {{activeColor?'':'active'}} l-active-class" style="width:{{percent}}%;height:{{strokeWidth}}rpx;border-radius:{{borderRadius}}rpx;{{activeColor?'background-color:'+activeColor+';':''}}"></view>
11+
<view class="background l-background-class" style="height:{{strokeWidth}}rpx;border-radius:{{borderRadius}}rpx;background-color:{{backgroundColor}};"></view>
12+
</view>
13+
<view class="text l-text-class" wx:if="{{showInfo && textPosition==='right'}}" style="color:{{textColor?textColor:''}};margin-left:{{interval}}rpx">
14+
{{percent}}%
15+
</view>
16+
</view>

examples/dist/progress/index.wxss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.container{display:flex;flex-direction:row;align-items:center}.progress{position:relative;width:100%;transition:all .25s ease-in-out}.percent{position:absolute;z-index:1}.active{background-color:#3963bc}.text{color:#3963bc;font-size:30rpx}.background{position:absolute;width:100%}.header{position:absolute!important;z-index:2}.slot{position:absolute;z-index:2}

0 commit comments

Comments
 (0)