index.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _utils = require("../utils");
  5. var _color = require("../utils/color");
  6. var _use = (0, _utils.use)('progress'),
  7. sfc = _use[0],
  8. bem = _use[1];
  9. var _default = sfc({
  10. props: {
  11. inactive: Boolean,
  12. pivotText: String,
  13. pivotColor: String,
  14. percentage: {
  15. type: Number,
  16. required: true,
  17. validator: function validator(value) {
  18. return value >= 0 && value <= 100;
  19. }
  20. },
  21. showPivot: {
  22. type: Boolean,
  23. "default": true
  24. },
  25. color: {
  26. type: String,
  27. "default": _color.BLUE
  28. },
  29. textColor: {
  30. type: String,
  31. "default": _color.WHITE
  32. }
  33. },
  34. data: function data() {
  35. return {
  36. pivotWidth: 0,
  37. progressWidth: 0
  38. };
  39. },
  40. mounted: function mounted() {
  41. this.getWidth();
  42. },
  43. watch: {
  44. showPivot: function showPivot() {
  45. this.getWidth();
  46. },
  47. pivotText: function pivotText() {
  48. this.getWidth();
  49. }
  50. },
  51. methods: {
  52. getWidth: function getWidth() {
  53. var _this = this;
  54. this.$nextTick(function () {
  55. _this.progressWidth = _this.$el.offsetWidth;
  56. _this.pivotWidth = _this.$refs.pivot ? _this.$refs.pivot.offsetWidth : 0;
  57. });
  58. }
  59. },
  60. render: function render(h) {
  61. var pivotText = this.pivotText,
  62. percentage = this.percentage;
  63. var text = (0, _utils.isDef)(pivotText) ? pivotText : percentage + '%';
  64. var showPivot = this.showPivot && text;
  65. var background = this.inactive ? '#cacaca' : this.color;
  66. var pivotStyle = {
  67. color: this.textColor,
  68. background: this.pivotColor || background
  69. };
  70. var portionStyle = {
  71. background: background,
  72. width: (this.progressWidth - this.pivotWidth) * percentage / 100 + 'px'
  73. };
  74. return h("div", {
  75. "class": bem()
  76. }, [h("span", {
  77. "class": bem('portion', {
  78. 'with-pivot': showPivot
  79. }),
  80. "style": portionStyle
  81. }, [showPivot && h("span", {
  82. "ref": "pivot",
  83. "style": pivotStyle,
  84. "class": bem('pivot')
  85. }, [text])])]);
  86. }
  87. });
  88. exports["default"] = _default;