iview/src/components/steps/step.vue

111 lines
3.2 KiB
Vue
Raw Normal View History

2016-09-09 14:29:19 +08:00
<template>
2016-09-23 15:22:37 +08:00
<div :class="wrapClasses" :style="styles">
2016-10-28 17:24:52 +08:00
<div :class="[prefixCls + '-tail']"><i></i></div>
<div :class="[prefixCls + '-head']">
<div :class="[prefixCls + '-head-inner']">
2017-03-01 23:24:23 +08:00
<span v-if="!icon && currentStatus != 'finish' && currentStatus != 'error'">{{ stepNumber }}</span>
2016-09-09 14:29:19 +08:00
<span v-else :class="iconClasses"></span>
</div>
</div>
2016-10-28 17:24:52 +08:00
<div :class="[prefixCls + '-main']">
<div :class="[prefixCls + '-title']">{{ title }}</div>
2017-04-07 18:44:14 +08:00
<slot>
<div v-if="content" :class="[prefixCls + '-content']">{{ content }}</div>
</slot>
2016-09-09 14:29:19 +08:00
</div>
</div>
</template>
<script>
2017-09-19 21:47:53 +08:00
import Emitter from '../../mixins/emitter';
2016-09-09 14:29:19 +08:00
import { oneOf } from '../../utils/assist';
const prefixCls = 'ivu-steps';
const iconPrefixCls = 'ivu-icon';
export default {
name: 'Step',
2017-09-19 21:47:53 +08:00
mixins: [ Emitter ],
2016-09-09 14:29:19 +08:00
props: {
2017-03-01 23:24:23 +08:00
status: {
validator (value) {
return oneOf(value, ['wait', 'process', 'finish', 'error']);
}
},
2016-09-09 14:29:19 +08:00
title: {
type: String,
default: ''
},
content: {
type: String
},
icon: {
type: String
}
},
data () {
return {
prefixCls: prefixCls,
stepNumber: '',
2016-09-23 15:22:37 +08:00
nextError: false,
total: 1,
2017-03-01 23:24:23 +08:00
currentStatus: ''
2016-12-25 22:49:42 +08:00
};
2016-09-09 14:29:19 +08:00
},
computed: {
wrapClasses () {
return [
`${prefixCls}-item`,
2017-03-01 23:24:23 +08:00
`${prefixCls}-status-${this.currentStatus}`,
2016-09-09 14:29:19 +08:00
{
[`${prefixCls}-custom`]: !!this.icon,
[`${prefixCls}-next-error`]: this.nextError
}
2016-12-25 22:49:42 +08:00
];
2016-09-09 14:29:19 +08:00
},
iconClasses () {
let icon = '';
2016-12-25 22:49:42 +08:00
if (this.icon) {
2016-09-09 14:29:19 +08:00
icon = this.icon;
} else {
2017-03-01 23:24:23 +08:00
if (this.currentStatus == 'finish') {
2016-09-09 14:29:19 +08:00
icon = 'ios-checkmark-empty';
2017-03-01 23:24:23 +08:00
} else if (this.currentStatus == 'error') {
2016-09-09 14:29:19 +08:00
icon = 'ios-close-empty';
}
}
return [
`${prefixCls}-icon`,
`${iconPrefixCls}`,
{
[`${iconPrefixCls}-${icon}`]: icon != ''
}
2016-12-25 22:49:42 +08:00
];
2016-09-23 15:22:37 +08:00
},
styles () {
return {
width: `${1/this.total*100}%`
2016-12-25 22:49:42 +08:00
};
2016-09-09 14:29:19 +08:00
}
},
watch: {
2017-03-01 23:24:23 +08:00
status (val) {
this.currentStatus = val;
if (this.currentStatus == 'error') {
2016-09-09 14:29:19 +08:00
this.$parent.setNextError();
}
}
2017-09-19 21:47:53 +08:00
},
created () {
this.currentStatus = this.status;
},
mounted () {
this.dispatch('Steps', 'append');
},
beforeDestroy () {
this.dispatch('Steps', 'remove');
2016-09-09 14:29:19 +08:00
}
2016-12-25 22:49:42 +08:00
};
2016-10-28 17:24:52 +08:00
</script>