mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-05-21 05:50:47 +08:00
parent
3ecd69bc14
commit
6e1d9408ec
@ -1,36 +1,31 @@
|
|||||||
@import '../common/style/var.less';
|
@import '../common/style/var.less';
|
||||||
|
|
||||||
.van-progress {
|
.van-progress {
|
||||||
height: 4px;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
border-radius: 4px;
|
height: 4px;
|
||||||
background: @gray-light;
|
background: @gray-light;
|
||||||
|
border-radius: 4px;
|
||||||
|
|
||||||
&__portion {
|
&__portion {
|
||||||
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
position: absolute;
|
|
||||||
border-radius: inherit;
|
border-radius: inherit;
|
||||||
|
|
||||||
&--with-pivot {
|
|
||||||
border-top-right-radius: 0;
|
|
||||||
border-bottom-right-radius: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&__pivot {
|
&__pivot {
|
||||||
|
position: absolute;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
right: 0;
|
right: 0;
|
||||||
min-width: 2em;
|
min-width: 2em;
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
position: absolute;
|
|
||||||
line-height: 1.6;
|
line-height: 1.6;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
border-radius: 1em;
|
|
||||||
word-break: keep-all;
|
word-break: keep-all;
|
||||||
box-sizing: border-box;
|
|
||||||
background-color: @gray-light;
|
background-color: @gray-light;
|
||||||
transform: translate(100%, -50%);
|
border-radius: 1em;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,57 +19,5 @@ VantComponent({
|
|||||||
type: String,
|
type: String,
|
||||||
value: '#fff'
|
value: '#fff'
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
data: {
|
|
||||||
pivotWidth: 0,
|
|
||||||
progressWidth: 0
|
|
||||||
},
|
|
||||||
|
|
||||||
watch: {
|
|
||||||
pivotText: 'getWidth',
|
|
||||||
showPivot: 'getWidth'
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
|
||||||
portionStyle() {
|
|
||||||
const width = (this.data.progressWidth - this.data.pivotWidth) * this.data.percentage / 100 + 'px';
|
|
||||||
const background = this.getCurrentColor();
|
|
||||||
return `width: ${width}; background: ${background}; `;
|
|
||||||
},
|
|
||||||
|
|
||||||
pivotStyle() {
|
|
||||||
const color = this.data.textColor;
|
|
||||||
const background = this.data.pivotColor || this.getCurrentColor();
|
|
||||||
return `color: ${color}; background: ${background}`
|
|
||||||
},
|
|
||||||
|
|
||||||
text() {
|
|
||||||
return this.data.pivotText || this.data.percentage + '%';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
mounted() {
|
|
||||||
this.getWidth();
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
|
||||||
getCurrentColor() {
|
|
||||||
return this.data.inactive ? '#cacaca' : this.data.color;
|
|
||||||
},
|
|
||||||
|
|
||||||
getWidth() {
|
|
||||||
this.getRect('.van-progress').then(rect => {
|
|
||||||
this.set({
|
|
||||||
progressWidth: rect.width
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
this.getRect('.van-progress__pivot').then(rect => {
|
|
||||||
this.set({
|
|
||||||
pivotWidth: rect.width || 0
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
|
<wxs src="./index.wxs" module="getters" />
|
||||||
|
|
||||||
<view class="van-progress custom-class">
|
<view class="van-progress custom-class">
|
||||||
<view
|
<view
|
||||||
class="van-progress__portion {{ showPivot && text ? 'van-progress__portion--with-pivot' : '' }}"
|
class="van-progress__portion"
|
||||||
style="{{ portionStyle }}"
|
style="width: {{ percentage }}%; background: {{ inactive ? '#cacaca' : color }}"
|
||||||
>
|
>
|
||||||
<view
|
<view
|
||||||
wx:if="{{ showPivot && text }}"
|
wx:if="{{ showPivot && getters.text(pivotText, percentage) }}"
|
||||||
style="{{ pivotStyle }}"
|
style="color: {{ textColor }}; background: {{ pivotColor ? pivotColor : inactive ? '#cacaca' : color }}"
|
||||||
class="van-progress__pivot"
|
class="van-progress__pivot"
|
||||||
>
|
>
|
||||||
{{ text }}
|
{{ getters.text(pivotText, percentage) }}
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
5
packages/progress/index.wxs
Normal file
5
packages/progress/index.wxs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
text: function(pivotText, percentage) {
|
||||||
|
return pivotText || percentage + '%';
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user