mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(Steps): use relation mixin (#4387)
This commit is contained in:
parent
42d408dc2c
commit
33652b1e84
@ -1,65 +1,57 @@
|
|||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import { BORDER } from '../utils/constant';
|
import { BORDER } from '../utils/constant';
|
||||||
|
import { ChildrenMixin } from '../mixins/relation';
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('step');
|
const [createComponent, bem] = createNamespace('step');
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
beforeCreate() {
|
mixins: [ChildrenMixin('vanSteps')],
|
||||||
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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
status() {
|
status() {
|
||||||
const index = this.$parent.steps.indexOf(this);
|
if (this.index < this.parent.active) {
|
||||||
const { active } = this.$parent;
|
|
||||||
|
|
||||||
if (index < active) {
|
|
||||||
return 'finish';
|
return 'finish';
|
||||||
}
|
}
|
||||||
if (index === active) {
|
if (this.index === this.parent.active) {
|
||||||
return 'process';
|
return 'process';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
methods: {
|
||||||
const { slots, status } = this;
|
genCircle() {
|
||||||
const { activeIcon, activeColor, inactiveIcon, direction } = this.$parent;
|
const { activeIcon, activeColor, inactiveIcon } = this.parent;
|
||||||
const titleStyle = status === 'process' && { color: activeColor };
|
|
||||||
|
|
||||||
function Circle() {
|
if (this.status === 'process') {
|
||||||
if (status === 'process') {
|
|
||||||
return (
|
return (
|
||||||
slots('active-icon') || (
|
this.slots('active-icon') || (
|
||||||
<Icon class={bem('icon')} name={activeIcon} color={activeColor} />
|
<Icon class={bem('icon')} name={activeIcon} color={activeColor} />
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const inactiveIconSlot = slots('inactive-icon');
|
const inactiveIconSlot = this.slots('inactive-icon');
|
||||||
|
|
||||||
if (inactiveIcon || inactiveIconSlot) {
|
if (inactiveIcon || inactiveIconSlot) {
|
||||||
return inactiveIconSlot || <Icon class={bem('icon')} name={inactiveIcon} />;
|
return inactiveIconSlot || <Icon class={bem('icon')} name={inactiveIcon} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <i class={bem('circle')} />;
|
return <i class={bem('circle')} />;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { status } = this;
|
||||||
|
const { activeColor, direction } = this.parent;
|
||||||
|
const titleStyle = status === 'process' && { color: activeColor };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class={[BORDER, bem([direction, { [status]: status }])]}>
|
<div class={[BORDER, bem([direction, { [status]: status }])]}>
|
||||||
<div class={bem('title')} style={titleStyle}>
|
<div class={bem('title')} style={titleStyle}>
|
||||||
{this.slots()}
|
{this.slots()}
|
||||||
</div>
|
</div>
|
||||||
<div class={bem('circle-container')}>{Circle()}</div>
|
<div class={bem('circle-container')}>{this.genCircle()}</div>
|
||||||
<div class={bem('line')} />
|
<div class={bem('line')} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
import { createNamespace } from '../utils';
|
import { createNamespace } from '../utils';
|
||||||
import { GREEN } from '../utils/constant';
|
import { GREEN } from '../utils/constant';
|
||||||
|
import { ParentMixin } from '../mixins/relation';
|
||||||
|
|
||||||
const [createComponent, bem] = createNamespace('steps');
|
const [createComponent, bem] = createNamespace('steps');
|
||||||
|
|
||||||
export default createComponent({
|
export default createComponent({
|
||||||
|
mixins: [ParentMixin('vanSteps')],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
inactiveIcon: String,
|
inactiveIcon: String,
|
||||||
active: {
|
active: {
|
||||||
@ -24,12 +27,6 @@ export default createComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
steps: []
|
|
||||||
};
|
|
||||||
},
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div class={bem([this.direction])}>
|
<div class={bem([this.direction])}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user