Commit b450b5553e923a852f56f7ff1cdd1d81b855726c

Authored by huixisheng
1 parent bd596e7a

update Steps

src/components/steps/step.vue
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <div :class="[prefixCls + '-tail']"><i></i></div> 3 <div :class="[prefixCls + '-tail']"><i></i></div>
4 <div :class="[prefixCls + '-head']"> 4 <div :class="[prefixCls + '-head']">
5 <div :class="[prefixCls + '-head-inner']"> 5 <div :class="[prefixCls + '-head-inner']">
6 - <span v-if="!icon && status != 'finish' && status != 'error'">{{ stepNumber }}</span> 6 + <span v-if="!icon && currentStatus != 'finish' && currentStatus != 'error'">{{ stepNumber }}</span>
7 <span v-else :class="iconClasses"></span> 7 <span v-else :class="iconClasses"></span>
8 </div> 8 </div>
9 </div> 9 </div>
@@ -21,11 +21,11 @@ @@ -21,11 +21,11 @@
21 21
22 export default { 22 export default {
23 props: { 23 props: {
24 - // status: {  
25 - // validator (value) {  
26 - // return oneOf(value, ['wait', 'process', 'finish', 'error']);  
27 - // }  
28 - // }, 24 + status: {
  25 + validator (value) {
  26 + return oneOf(value, ['wait', 'process', 'finish', 'error']);
  27 + }
  28 + },
29 title: { 29 title: {
30 type: String, 30 type: String,
31 default: '' 31 default: ''
@@ -43,14 +43,17 @@ @@ -43,14 +43,17 @@
43 stepNumber: '', 43 stepNumber: '',
44 nextError: false, 44 nextError: false,
45 total: 1, 45 total: 1,
46 - status: '' 46 + currentStatus: ''
47 }; 47 };
48 }, 48 },
  49 + created () {
  50 + this.currentStatus = this.status;
  51 + },
49 computed: { 52 computed: {
50 wrapClasses () { 53 wrapClasses () {
51 return [ 54 return [
52 `${prefixCls}-item`, 55 `${prefixCls}-item`,
53 - `${prefixCls}-status-${this.status}`, 56 + `${prefixCls}-status-${this.currentStatus}`,
54 { 57 {
55 [`${prefixCls}-custom`]: !!this.icon, 58 [`${prefixCls}-custom`]: !!this.icon,
56 [`${prefixCls}-next-error`]: this.nextError 59 [`${prefixCls}-next-error`]: this.nextError
@@ -63,9 +66,9 @@ @@ -63,9 +66,9 @@
63 if (this.icon) { 66 if (this.icon) {
64 icon = this.icon; 67 icon = this.icon;
65 } else { 68 } else {
66 - if (this.status == 'finish') { 69 + if (this.currentStatus == 'finish') {
67 icon = 'ios-checkmark-empty'; 70 icon = 'ios-checkmark-empty';
68 - } else if (this.status == 'error') { 71 + } else if (this.currentStatus == 'error') {
69 icon = 'ios-close-empty'; 72 icon = 'ios-close-empty';
70 } 73 }
71 } 74 }
@@ -85,8 +88,9 @@ @@ -85,8 +88,9 @@
85 } 88 }
86 }, 89 },
87 watch: { 90 watch: {
88 - status () {  
89 - if (this.status == 'error') { 91 + status (val) {
  92 + this.currentStatus = val;
  93 + if (this.currentStatus == 'error') {
90 this.$parent.setNextError(); 94 this.$parent.setNextError();
91 } 95 }
92 } 96 }
src/components/steps/steps.vue
@@ -60,38 +60,42 @@ @@ -60,38 +60,42 @@
60 60
61 // 如果已存在status,且在初始化时,则略过 61 // 如果已存在status,且在初始化时,则略过
62 // todo 如果当前是error,在current改变时需要处理 62 // todo 如果当前是error,在current改变时需要处理
63 - if (!(isInit && child.status)) { 63 + if (!(isInit && child.currentStatus)) {
64 if (index == this.current) { 64 if (index == this.current) {
65 if (this.status != 'error') { 65 if (this.status != 'error') {
66 - child.status = 'process'; 66 + child.currentStatus = 'process';
67 } 67 }
68 } else if (index < this.current) { 68 } else if (index < this.current) {
69 - child.status = 'finish'; 69 + child.currentStatus = 'finish';
70 } else { 70 } else {
71 - child.status = 'wait'; 71 + child.currentStatus = 'wait';
72 } 72 }
73 } 73 }
74 74
75 - if (child.status != 'error' && index != 0) { 75 + if (child.currentStatus != 'error' && index != 0) {
76 this.$children[index - 1].nextError = false; 76 this.$children[index - 1].nextError = false;
77 } 77 }
78 }); 78 });
79 }, 79 },
80 setNextError () { 80 setNextError () {
81 this.$children.forEach((child, index) => { 81 this.$children.forEach((child, index) => {
82 - if (child.status == 'error' && index != 0) { 82 + if (child.currentStatus == 'error' && index != 0) {
83 this.$children[index - 1].nextError = true; 83 this.$children[index - 1].nextError = true;
84 } 84 }
85 }); 85 });
86 }, 86 },
87 updateCurrent (isInit) { 87 updateCurrent (isInit) {
  88 + // 防止溢出边界
  89 + if (this.current < 0 || this.current >= this.$children.length ) {
  90 + return;
  91 + }
88 if (isInit) { 92 if (isInit) {
89 - const current_status = this.$children[this.current].status; 93 + const current_status = this.$children[this.current].currentStatus;
90 if (!current_status) { 94 if (!current_status) {
91 - this.$children[this.current].status = this.status; 95 + this.$children[this.current].currentStatus = this.status;
92 } 96 }
93 } else { 97 } else {
94 - this.$children[this.current].status = this.status; 98 + this.$children[this.current].currentStatus = this.status;
95 } 99 }
96 } 100 }
97 }, 101 },
test/routers/steps.vue
@@ -31,6 +31,11 @@ @@ -31,6 +31,11 @@
31 <Step title="上传头像" icon="camera" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> 31 <Step title="上传头像" icon="camera" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step>
32 <Step title="验证邮箱" icon="email"></Step> 32 <Step title="验证邮箱" icon="email"></Step>
33 </Steps> 33 </Steps>
  34 + <Steps :current="-1" direction="vertical">
  35 + <Step title="注册" icon="person-add"></Step>
  36 + <Step title="上传头像" icon="camera" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step>
  37 + <Step title="验证邮箱" status="finish" icon="email"></Step>
  38 + </Steps>
34 <br> 39 <br>
35 <p>当前正在进行第 {{ current + 1 }} 步</p> 40 <p>当前正在进行第 {{ current + 1 }} 步</p>
36 <Steps :current="current"> 41 <Steps :current="current">