iview/src/components/steps/step.vue

106 lines
3.1 KiB
Vue
Raw Normal View History

2019-08-27 09:42:40 +08:00
<template>
2019-09-17 15:37:05 +08:00
<div :class="wrapClasses">
2019-08-27 09:42:40 +08:00
<div :class="[prefixCls + '-tail']"><i></i></div>
<div :class="[prefixCls + '-head']">
<div :class="[prefixCls + '-head-inner']">
2019-09-17 15:37:05 +08:00
<span v-if="!icon && currentStatus !== 'finish' && currentStatus !== 'error'">{{ stepNumber }}</span>
2019-08-27 09:42:40 +08:00
<span v-else :class="iconClasses"></span>
</div>
</div>
<div :class="[prefixCls + '-main']">
<div :class="[prefixCls + '-title']">{{ title }}</div>
<slot>
<div v-if="content" :class="[prefixCls + '-content']">{{ content }}</div>
</slot>
</div>
</div>
</template>
<script>
import Emitter from '../../mixins/emitter';
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-steps';
const iconPrefixCls = 'ivu-icon';
export default {
name: 'Step',
mixins: [ Emitter ],
props: {
status: {
validator (value) {
return oneOf(value, ['wait', 'process', 'finish', 'error']);
}
},
title: {
type: String,
default: ''
},
content: {
type: String
},
icon: {
type: String
}
},
data () {
return {
prefixCls: prefixCls,
stepNumber: '',
nextError: false,
total: 1,
currentStatus: ''
};
},
computed: {
wrapClasses () {
return [
`${prefixCls}-item`,
`${prefixCls}-status-${this.currentStatus}`,
{
[`${prefixCls}-custom`]: !!this.icon,
[`${prefixCls}-next-error`]: this.nextError
}
];
},
iconClasses () {
let icon = '';
if (this.icon) {
icon = this.icon;
} else {
2019-09-17 15:37:05 +08:00
if (this.currentStatus === 'finish') {
2019-08-27 09:42:40 +08:00
icon = 'ios-checkmark';
2019-09-17 15:37:05 +08:00
} else if (this.currentStatus === 'error') {
2019-08-27 09:42:40 +08:00
icon = 'ios-close';
}
}
return [
`${prefixCls}-icon`,
`${iconPrefixCls}`,
{
2019-09-17 15:37:05 +08:00
[`${iconPrefixCls}-${icon}`]: icon !== ''
2019-08-27 09:42:40 +08:00
}
];
}
},
watch: {
status (val) {
this.currentStatus = val;
2019-09-17 15:37:05 +08:00
if (this.currentStatus === 'error') {
2019-08-27 09:42:40 +08:00
this.$parent.setNextError();
}
}
},
created () {
this.currentStatus = this.status;
},
mounted () {
this.dispatch('Steps', 'append');
},
beforeDestroy () {
this.dispatch('Steps', 'remove');
}
};
</script>