index.js 2.2 KB

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