| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import { use, isDef } from '../utils';
- import { BLUE, WHITE } from '../utils/color';
- var _use = use('progress'),
- sfc = _use[0],
- bem = _use[1];
- export default sfc({
- props: {
- inactive: Boolean,
- pivotText: String,
- pivotColor: String,
- percentage: {
- type: Number,
- required: true,
- validator: function validator(value) {
- return value >= 0 && value <= 100;
- }
- },
- showPivot: {
- type: Boolean,
- "default": true
- },
- color: {
- type: String,
- "default": BLUE
- },
- textColor: {
- type: String,
- "default": WHITE
- }
- },
- data: function data() {
- return {
- pivotWidth: 0,
- progressWidth: 0
- };
- },
- mounted: function mounted() {
- this.getWidth();
- },
- watch: {
- showPivot: function showPivot() {
- this.getWidth();
- },
- pivotText: function pivotText() {
- this.getWidth();
- }
- },
- methods: {
- getWidth: function getWidth() {
- var _this = this;
- this.$nextTick(function () {
- _this.progressWidth = _this.$el.offsetWidth;
- _this.pivotWidth = _this.$refs.pivot ? _this.$refs.pivot.offsetWidth : 0;
- });
- }
- },
- render: function render(h) {
- var pivotText = this.pivotText,
- percentage = this.percentage;
- var text = isDef(pivotText) ? pivotText : percentage + '%';
- var showPivot = this.showPivot && text;
- var background = this.inactive ? '#cacaca' : this.color;
- var pivotStyle = {
- color: this.textColor,
- background: this.pivotColor || background
- };
- var portionStyle = {
- background: background,
- width: (this.progressWidth - this.pivotWidth) * percentage / 100 + 'px'
- };
- return h("div", {
- "class": bem()
- }, [h("span", {
- "class": bem('portion', {
- 'with-pivot': showPivot
- }),
- "style": portionStyle
- }, [showPivot && h("span", {
- "ref": "pivot",
- "style": pivotStyle,
- "class": bem('pivot')
- }, [text])])]);
- }
- });
|