index.js 3.6 KB

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