diff --git a/src/components/steps/step.vue b/src/components/steps/step.vue index 99917224..e8c89fd6 100644 --- a/src/components/steps/step.vue +++ b/src/components/steps/step.vue @@ -3,7 +3,7 @@
- {{ stepNumber }} + {{ stepNumber }}
@@ -21,11 +21,11 @@ export default { props: { - // status: { - // validator (value) { - // return oneOf(value, ['wait', 'process', 'finish', 'error']); - // } - // }, + status: { + validator (value) { + return oneOf(value, ['wait', 'process', 'finish', 'error']); + } + }, title: { type: String, default: '' @@ -43,14 +43,17 @@ stepNumber: '', nextError: false, total: 1, - status: '' + currentStatus: '' }; }, + created () { + this.currentStatus = this.status; + }, computed: { wrapClasses () { return [ `${prefixCls}-item`, - `${prefixCls}-status-${this.status}`, + `${prefixCls}-status-${this.currentStatus}`, { [`${prefixCls}-custom`]: !!this.icon, [`${prefixCls}-next-error`]: this.nextError @@ -63,9 +66,9 @@ if (this.icon) { icon = this.icon; } else { - if (this.status == 'finish') { + if (this.currentStatus == 'finish') { icon = 'ios-checkmark-empty'; - } else if (this.status == 'error') { + } else if (this.currentStatus == 'error') { icon = 'ios-close-empty'; } } @@ -85,8 +88,9 @@ } }, watch: { - status () { - if (this.status == 'error') { + status (val) { + this.currentStatus = val; + if (this.currentStatus == 'error') { this.$parent.setNextError(); } } diff --git a/src/components/steps/steps.vue b/src/components/steps/steps.vue index 906c2fd6..cc68ddc7 100644 --- a/src/components/steps/steps.vue +++ b/src/components/steps/steps.vue @@ -60,38 +60,42 @@ // 如果已存在status,且在初始化时,则略过 // todo 如果当前是error,在current改变时需要处理 - if (!(isInit && child.status)) { + if (!(isInit && child.currentStatus)) { if (index == this.current) { if (this.status != 'error') { - child.status = 'process'; + child.currentStatus = 'process'; } } else if (index < this.current) { - child.status = 'finish'; + child.currentStatus = 'finish'; } else { - child.status = 'wait'; + child.currentStatus = 'wait'; } } - if (child.status != 'error' && index != 0) { + if (child.currentStatus != 'error' && index != 0) { this.$children[index - 1].nextError = false; } }); }, setNextError () { this.$children.forEach((child, index) => { - if (child.status == 'error' && index != 0) { + if (child.currentStatus == 'error' && index != 0) { this.$children[index - 1].nextError = true; } }); }, updateCurrent (isInit) { + // 防止溢出边界 + if (this.current < 0 || this.current >= this.$children.length ) { + return; + } if (isInit) { - const current_status = this.$children[this.current].status; + const current_status = this.$children[this.current].currentStatus; if (!current_status) { - this.$children[this.current].status = this.status; + this.$children[this.current].currentStatus = this.status; } } else { - this.$children[this.current].status = this.status; + this.$children[this.current].currentStatus = this.status; } } }, diff --git a/test/routers/steps.vue b/test/routers/steps.vue index f18a0425..8b63203c 100644 --- a/test/routers/steps.vue +++ b/test/routers/steps.vue @@ -31,6 +31,11 @@ + + + + +

当前正在进行第 {{ current + 1 }} 步