index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { VantComponent } from '../common/component';
  2. import { BLUE } from '../common/color';
  3. VantComponent({
  4. props: {
  5. inactive: Boolean,
  6. percentage: Number,
  7. pivotText: String,
  8. pivotColor: String,
  9. showPivot: {
  10. type: Boolean,
  11. value: true
  12. },
  13. color: {
  14. type: String,
  15. value: BLUE
  16. },
  17. textColor: {
  18. type: String,
  19. value: '#fff'
  20. }
  21. },
  22. data: {
  23. pivotWidth: 0,
  24. progressWidth: 0
  25. },
  26. watch: {
  27. pivotText: 'getWidth',
  28. showPivot: 'getWidth'
  29. },
  30. computed: {
  31. portionStyle: function portionStyle() {
  32. var width = (this.data.progressWidth - this.data.pivotWidth) * this.data.percentage / 100 + 'px';
  33. var background = this.getCurrentColor();
  34. return "width: " + width + "; background: " + background + "; ";
  35. },
  36. pivotStyle: function pivotStyle() {
  37. var color = this.data.textColor;
  38. var background = this.data.pivotColor || this.getCurrentColor();
  39. return "color: " + color + "; background: " + background;
  40. },
  41. text: function text() {
  42. return this.data.pivotText || this.data.percentage + '%';
  43. }
  44. },
  45. mounted: function mounted() {
  46. this.getWidth();
  47. },
  48. methods: {
  49. getCurrentColor: function getCurrentColor() {
  50. return this.data.inactive ? '#cacaca' : this.data.color;
  51. },
  52. getWidth: function getWidth() {
  53. var _this = this;
  54. this.getRect('.van-progress').then(function (rect) {
  55. _this.set({
  56. progressWidth: rect.width
  57. });
  58. });
  59. this.getRect('.van-progress__pivot').then(function (rect) {
  60. _this.set({
  61. pivotWidth: rect.width || 0
  62. });
  63. });
  64. }
  65. }
  66. });