From 33652b1e84e565d482c2e43bea8e66624af739e2 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 6 Sep 2019 15:34:11 +0800 Subject: [PATCH] feat(Steps): use relation mixin (#4387) --- src/step/index.js | 44 ++++++++++++++++++-------------------------- src/steps/index.js | 9 +++------ 2 files changed, 21 insertions(+), 32 deletions(-) diff --git a/src/step/index.js b/src/step/index.js index dcb83f8f3..7b0f12b55 100644 --- a/src/step/index.js +++ b/src/step/index.js @@ -1,65 +1,57 @@ import { createNamespace } from '../utils'; import { BORDER } from '../utils/constant'; +import { ChildrenMixin } from '../mixins/relation'; import Icon from '../icon'; const [createComponent, bem] = createNamespace('step'); export default createComponent({ - beforeCreate() { - const { steps } = this.$parent; - const index = this.$parent.slots().indexOf(this.$vnode); - steps.splice(index === -1 ? steps.length : index, 0, this); - }, - - beforeDestroy() { - const index = this.$parent.steps.indexOf(this); - if (index > -1) { - this.$parent.steps.splice(index, 1); - } - }, + mixins: [ChildrenMixin('vanSteps')], computed: { status() { - const index = this.$parent.steps.indexOf(this); - const { active } = this.$parent; - - if (index < active) { + if (this.index < this.parent.active) { return 'finish'; } - if (index === active) { + if (this.index === this.parent.active) { return 'process'; } } }, - render() { - const { slots, status } = this; - const { activeIcon, activeColor, inactiveIcon, direction } = this.$parent; - const titleStyle = status === 'process' && { color: activeColor }; + methods: { + genCircle() { + const { activeIcon, activeColor, inactiveIcon } = this.parent; - function Circle() { - if (status === 'process') { + if (this.status === 'process') { return ( - slots('active-icon') || ( + this.slots('active-icon') || ( ) ); } - const inactiveIconSlot = slots('inactive-icon'); + const inactiveIconSlot = this.slots('inactive-icon'); + if (inactiveIcon || inactiveIconSlot) { return inactiveIconSlot || ; } return ; } + }, + + render() { + const { status } = this; + const { activeColor, direction } = this.parent; + const titleStyle = status === 'process' && { color: activeColor }; return (
{this.slots()}
-
{Circle()}
+
{this.genCircle()}
); diff --git a/src/steps/index.js b/src/steps/index.js index 960bd43e7..3cc572a12 100644 --- a/src/steps/index.js +++ b/src/steps/index.js @@ -1,9 +1,12 @@ import { createNamespace } from '../utils'; import { GREEN } from '../utils/constant'; +import { ParentMixin } from '../mixins/relation'; const [createComponent, bem] = createNamespace('steps'); export default createComponent({ + mixins: [ParentMixin('vanSteps')], + props: { inactiveIcon: String, active: { @@ -24,12 +27,6 @@ export default createComponent({ } }, - data() { - return { - steps: [] - }; - }, - render() { return (