index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { createNamespace } from '../utils';
  2. import { BORDER } from '../utils/constant';
  3. import { ChildrenMixin } from '../mixins/relation';
  4. import Icon from '../icon';
  5. var _createNamespace = createNamespace('step'),
  6. createComponent = _createNamespace[0],
  7. bem = _createNamespace[1];
  8. export default createComponent({
  9. mixins: [ChildrenMixin('vanSteps')],
  10. computed: {
  11. status: function status() {
  12. if (this.index < this.parent.active) {
  13. return 'finish';
  14. }
  15. if (this.index === +this.parent.active) {
  16. return 'process';
  17. }
  18. },
  19. active: function active() {
  20. return this.status === 'process';
  21. },
  22. lineStyle: function lineStyle() {
  23. var _this$parent = this.parent,
  24. activeColor = _this$parent.activeColor,
  25. inactiveColor = _this$parent.inactiveColor,
  26. center = _this$parent.center,
  27. direction = _this$parent.direction;
  28. var style = {
  29. background: this.status === 'finish' ? activeColor : inactiveColor
  30. };
  31. if (center && direction === 'vertical') {
  32. style.top = '50%';
  33. }
  34. return style;
  35. },
  36. circleContainerStyle: function circleContainerStyle() {
  37. if (this.parent.center && this.parent.direction === 'vertical') {
  38. return {
  39. top: '50%'
  40. };
  41. }
  42. },
  43. titleStyle: function titleStyle() {
  44. if (this.active) {
  45. return {
  46. color: this.parent.activeColor
  47. };
  48. }
  49. if (!this.status) {
  50. return {
  51. color: this.parent.inactiveColor
  52. };
  53. }
  54. }
  55. },
  56. methods: {
  57. genCircle: function genCircle() {
  58. var h = this.$createElement;
  59. var _this$parent2 = this.parent,
  60. activeIcon = _this$parent2.activeIcon,
  61. iconPrefix = _this$parent2.iconPrefix,
  62. activeColor = _this$parent2.activeColor,
  63. finishIcon = _this$parent2.finishIcon,
  64. inactiveIcon = _this$parent2.inactiveIcon;
  65. if (this.active) {
  66. return this.slots('active-icon') || h(Icon, {
  67. "class": bem('icon', 'active'),
  68. "attrs": {
  69. "name": activeIcon,
  70. "color": activeColor,
  71. "classPrefix": iconPrefix
  72. }
  73. });
  74. }
  75. var finishIconSlot = this.slots('finish-icon');
  76. if (this.status === 'finish' && (finishIcon || finishIconSlot)) {
  77. return finishIconSlot || h(Icon, {
  78. "class": bem('icon', 'finish'),
  79. "attrs": {
  80. "name": finishIcon,
  81. "color": activeColor,
  82. "classPrefix": iconPrefix
  83. }
  84. });
  85. }
  86. var inactiveIconSlot = this.slots('inactive-icon');
  87. if (inactiveIcon || inactiveIconSlot) {
  88. return inactiveIconSlot || h(Icon, {
  89. "class": bem('icon'),
  90. "attrs": {
  91. "name": inactiveIcon,
  92. "classPrefix": iconPrefix
  93. }
  94. });
  95. }
  96. return h("i", {
  97. "class": bem('circle'),
  98. "style": this.lineStyle
  99. });
  100. },
  101. onClickStep: function onClickStep() {
  102. this.parent.$emit('click-step', this.index);
  103. }
  104. },
  105. render: function render() {
  106. var _ref;
  107. var h = arguments[0];
  108. var status = this.status,
  109. active = this.active;
  110. var direction = this.parent.direction;
  111. return h("div", {
  112. "class": [BORDER, bem([direction, (_ref = {}, _ref[status] = status, _ref)])]
  113. }, [h("div", {
  114. "class": bem('title', {
  115. active: active
  116. }),
  117. "style": this.titleStyle,
  118. "on": {
  119. "click": this.onClickStep
  120. }
  121. }, [this.slots()]), h("div", {
  122. "class": bem('circle-container'),
  123. "on": {
  124. "click": this.onClickStep
  125. },
  126. "style": this.circleContainerStyle
  127. }, [this.genCircle()]), h("div", {
  128. "class": bem('line'),
  129. "style": this.lineStyle
  130. })]);
  131. }
  132. });