| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <template>
- <div class="nut-steps" :class="{horizontal: direction === 'horizontal'}">
- <slot></slot>
- </div>
- </template>
- <script>
- export default {
- name: 'nut-steps',
- props: {
- current: {
- type: Number,
- default: 0
- },
- timeForward: {
- type: Boolean,
- default: false
- },
- direction: {
- type: String,
- default: 'vertical'
- },
- type: {
- type: String
- },
- source: {
- type: Array,
- default() {
- return [];
- }
- },
- },
- data() {
- return {
- steps: []
- };
- },
- methods: {
- updateChildProps(isInit) {
- const total = this.steps.length;
- this.steps.forEach((child, index) => {
- // 如果已存在status,且在初始化时,则略过
- // todo 如果当前是error,在current改变时需要处理
- if (!(isInit && child.currentStatus)) {
- if (this.current === index) {
- child.currentStatus = 'nut-step-status-process';
- }
- if (this.type === 'process') {
- if (index < this.current) {
- child.currentStatus = 'nut-step-status-finish';
- }
- if (index > this.current) {
- child.currentStatus = 'nut-step-status-wait';
- }
- }
- if (this.type === 'mini') {
- child.type = 'mini'
- }
- }
-
- if (index + 1 === total) {
- child.currentStatus += ' nut-step-last';
- }
- if (this.timeForward) {
- child.timeForward = true;
- }
- });
- },
- init() {
- if (this.$slots.default) {
- this.steps = this.$slots.default.filter(vnode => !!vnode.componentInstance).map(node => node.componentInstance);
- this.updateChildProps(true);
- }
- }
- },
- mounted() {
- this.init();
- },
- watch: {
- current() {
- this.updateChildProps();
- },
- source() {
- this.$nextTick(() => {
- this.init();
- });
- }
- }
- };
- </script>
|