index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. if (this.status === 'finish') {
  24. return {
  25. background: this.parent.activeColor
  26. };
  27. }
  28. return {
  29. background: this.parent.inactiveColor
  30. };
  31. },
  32. titleStyle: function titleStyle() {
  33. if (this.active) {
  34. return {
  35. color: this.parent.activeColor
  36. };
  37. }
  38. if (!this.status) {
  39. return {
  40. color: this.parent.inactiveColor
  41. };
  42. }
  43. }
  44. },
  45. methods: {
  46. genCircle: function genCircle() {
  47. var h = this.$createElement;
  48. var _this$parent = this.parent,
  49. activeIcon = _this$parent.activeIcon,
  50. iconPrefix = _this$parent.iconPrefix,
  51. activeColor = _this$parent.activeColor,
  52. finishIcon = _this$parent.finishIcon,
  53. inactiveIcon = _this$parent.inactiveIcon;
  54. if (this.active) {
  55. return this.slots('active-icon') || h(Icon, {
  56. "class": bem('icon', 'active'),
  57. "attrs": {
  58. "name": activeIcon,
  59. "color": activeColor,
  60. "classPrefix": iconPrefix
  61. }
  62. });
  63. }
  64. var finishIconSlot = this.slots('finish-icon');
  65. if (this.status === 'finish' && (finishIcon || finishIconSlot)) {
  66. return finishIconSlot || h(Icon, {
  67. "class": bem('icon', 'finish'),
  68. "attrs": {
  69. "name": finishIcon,
  70. "color": activeColor,
  71. "classPrefix": iconPrefix
  72. }
  73. });
  74. }
  75. var inactiveIconSlot = this.slots('inactive-icon');
  76. if (inactiveIcon || inactiveIconSlot) {
  77. return inactiveIconSlot || h(Icon, {
  78. "class": bem('icon'),
  79. "attrs": {
  80. "name": inactiveIcon,
  81. "classPrefix": iconPrefix
  82. }
  83. });
  84. }
  85. return h("i", {
  86. "class": bem('circle'),
  87. "style": this.lineStyle
  88. });
  89. },
  90. onClickStep: function onClickStep() {
  91. this.parent.$emit('click-step', this.index);
  92. }
  93. },
  94. render: function render() {
  95. var _ref;
  96. var h = arguments[0];
  97. var status = this.status,
  98. active = this.active;
  99. var direction = this.parent.direction;
  100. return h("div", {
  101. "class": [BORDER, bem([direction, (_ref = {}, _ref[status] = status, _ref)])]
  102. }, [h("div", {
  103. "class": bem('title', {
  104. active: active
  105. }),
  106. "style": this.titleStyle,
  107. "on": {
  108. "click": this.onClickStep
  109. }
  110. }, [this.slots()]), h("div", {
  111. "class": bem('circle-container'),
  112. "on": {
  113. "click": this.onClickStep
  114. }
  115. }, [this.genCircle()]), h("div", {
  116. "class": bem('line'),
  117. "style": this.lineStyle
  118. })]);
  119. }
  120. });