Commit 112ed1fae82856bacfa38ac7fe6bb7a05c4a5d0f

Authored by Aresn
Committed by GitHub
2 parents a804d608 b450b555

Merge pull request #325 from huixisheng/feature-steps

support Steps
build/webpack.dev.config.js
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 4
5 var path = require('path'); 5 var path = require('path');
6 var webpack = require('webpack'); 6 var webpack = require('webpack');
7 -var ExtractTextPlugin = require('extract-text-webpack-plugin'); 7 +// var ExtractTextPlugin = require('extract-text-webpack-plugin');
8 var HtmlWebpackPlugin = require('html-webpack-plugin'); 8 var HtmlWebpackPlugin = require('html-webpack-plugin');
9 9
10 module.exports = { 10 module.exports = {
@@ -76,6 +76,7 @@ @@ -76,6 +76,7 @@
76 "vue-loader": "^11.0.0", 76 "vue-loader": "^11.0.0",
77 "vue-router": "^2.2.1", 77 "vue-router": "^2.2.1",
78 "vue-style-loader": "^1.0.0", 78 "vue-style-loader": "^1.0.0",
  79 + "vue-template-compiler": "^2.2.1",
79 "webpack": "^2.2.1", 80 "webpack": "^2.2.1",
80 "webpack-dev-server": "^2.4.1" 81 "webpack-dev-server": "^2.4.1"
81 } 82 }
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>
@@ -42,14 +42,18 @@ @@ -42,14 +42,18 @@
42 prefixCls: prefixCls, 42 prefixCls: prefixCls,
43 stepNumber: '', 43 stepNumber: '',
44 nextError: false, 44 nextError: false,
45 - total: 1 45 + total: 1,
  46 + currentStatus: ''
46 }; 47 };
47 }, 48 },
  49 + created () {
  50 + this.currentStatus = this.status;
  51 + },
48 computed: { 52 computed: {
49 wrapClasses () { 53 wrapClasses () {
50 return [ 54 return [
51 `${prefixCls}-item`, 55 `${prefixCls}-item`,
52 - `${prefixCls}-status-${this.status}`, 56 + `${prefixCls}-status-${this.currentStatus}`,
53 { 57 {
54 [`${prefixCls}-custom`]: !!this.icon, 58 [`${prefixCls}-custom`]: !!this.icon,
55 [`${prefixCls}-next-error`]: this.nextError 59 [`${prefixCls}-next-error`]: this.nextError
@@ -62,9 +66,9 @@ @@ -62,9 +66,9 @@
62 if (this.icon) { 66 if (this.icon) {
63 icon = this.icon; 67 icon = this.icon;
64 } else { 68 } else {
65 - if (this.status == 'finish') { 69 + if (this.currentStatus == 'finish') {
66 icon = 'ios-checkmark-empty'; 70 icon = 'ios-checkmark-empty';
67 - } else if (this.status == 'error') { 71 + } else if (this.currentStatus == 'error') {
68 icon = 'ios-close-empty'; 72 icon = 'ios-close-empty';
69 } 73 }
70 } 74 }
@@ -84,8 +88,9 @@ @@ -84,8 +88,9 @@
84 } 88 }
85 }, 89 },
86 watch: { 90 watch: {
87 - status () {  
88 - if (this.status == 'error') { 91 + status (val) {
  92 + this.currentStatus = val;
  93 + if (this.currentStatus == 'error') {
89 this.$parent.setNextError(); 94 this.$parent.setNextError();
90 } 95 }
91 } 96 }
src/components/steps/steps.vue
@@ -43,7 +43,7 @@ @@ -43,7 +43,7 @@
43 ]; 43 ];
44 } 44 }
45 }, 45 },
46 - ready () { 46 + mounted () {
47 this.updateChildProps(true); 47 this.updateChildProps(true);
48 this.setNextError(); 48 this.setNextError();
49 this.updateCurrent(true); 49 this.updateCurrent(true);
@@ -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 },
@@ -31,7 +31,7 @@ import Radio from &#39;./components/radio&#39;; @@ -31,7 +31,7 @@ import Radio from &#39;./components/radio&#39;;
31 // import Rate from './components/rate'; 31 // import Rate from './components/rate';
32 // import Slider from './components/slider'; 32 // import Slider from './components/slider';
33 // import Spin from './components/spin'; 33 // import Spin from './components/spin';
34 -// import Steps from './components/steps'; 34 +import Steps from './components/steps';
35 // import Switch from './components/switch'; 35 // import Switch from './components/switch';
36 // import Table from './components/table'; 36 // import Table from './components/table';
37 // import Tabs from './components/tabs'; 37 // import Tabs from './components/tabs';
@@ -96,8 +96,8 @@ const iview = { @@ -96,8 +96,8 @@ const iview = {
96 // iSelect: Select, 96 // iSelect: Select,
97 // Slider, 97 // Slider,
98 // Spin, 98 // Spin,
99 - // Step: Steps.Step,  
100 - // Steps, 99 + Step: Steps.Step,
  100 + Steps,
101 // Switch, 101 // Switch,
102 // iTable: Table, 102 // iTable: Table,
103 // Tabs: Tabs, 103 // Tabs: Tabs,
@@ -2,26 +2,15 @@ @@ -2,26 +2,15 @@
2 @import "../src/styles/index.less"; 2 @import "../src/styles/index.less";
3 </style> 3 </style>
4 <style scoped> 4 <style scoped>
5 -nav {  
6 - margin-bottom: 40px;  
7 -}  
8 -  
9 -li {  
10 - display: inline-block;  
11 -}  
12 -  
13 -li + li {  
14 - border-left: solid 1px #bbb;  
15 - padding-left: 5px;  
16 - margin-left: 5px;  
17 -}  
18 -  
19 -.v-link-active {  
20 - color: #bbb;  
21 -} 5 +nav { margin-bottom: 40px; }
  6 +ul { display: flex; flex-wrap: wrap; }
  7 +li { display: inline-block; }
  8 +li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
  9 +.container{ padding: 10px 40px; }
  10 +.v-link-active { color: #bbb; }
22 </style> 11 </style>
23 <template> 12 <template>
24 - <div> 13 + <div class="container">
25 <nav> 14 <nav>
26 <ul> 15 <ul>
27 <li><router-link to="/affix">Affix</router-link></li> 16 <li><router-link to="/affix">Affix</router-link></li>
@@ -30,6 +19,7 @@ li + li { @@ -30,6 +19,7 @@ li + li {
30 <li><router-link to="/input">Input</router-link></li> 19 <li><router-link to="/input">Input</router-link></li>
31 <li><router-link to="/radio">Radio</router-link></li> 20 <li><router-link to="/radio">Radio</router-link></li>
32 <li><router-link to="/checkbox">Checkbox</router-link></li> 21 <li><router-link to="/checkbox">Checkbox</router-link></li>
  22 + <li><router-link to="/steps">Steps</router-link></li>
33 </ul> 23 </ul>
34 </nav> 24 </nav>
35 <router-view></router-view> 25 <router-view></router-view>
@@ -40,6 +40,10 @@ const router = new VueRouter({ @@ -40,6 +40,10 @@ const router = new VueRouter({
40 { 40 {
41 path: '/checkbox', 41 path: '/checkbox',
42 component: require('./routers/checkbox.vue') 42 component: require('./routers/checkbox.vue')
  43 + },
  44 + {
  45 + path: '/steps',
  46 + component: require('./routers/steps.vue')
43 } 47 }
44 ] 48 ]
45 }); 49 });
test/routers/step.vue renamed to test/routers/steps.vue
1 -<style>  
2 -  
3 -</style>  
4 <template> 1 <template>
  2 +<div>
5 <Steps :current="1" size="small"> 3 <Steps :current="1" size="small">
6 <Step title="已完成" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> 4 <Step title="已完成" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step>
7 <Step title="进行中" content="这里是该步骤的描述信息"></Step> 5 <Step title="进行中" content="这里是该步骤的描述信息"></Step>
@@ -33,6 +31,11 @@ @@ -33,6 +31,11 @@
33 <Step title="上传头像" icon="camera" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> 31 <Step title="上传头像" icon="camera" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step>
34 <Step title="验证邮箱" icon="email"></Step> 32 <Step title="验证邮箱" icon="email"></Step>
35 </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>
36 <br> 39 <br>
37 <p>当前正在进行第 {{ current + 1 }} 步</p> 40 <p>当前正在进行第 {{ current + 1 }} 步</p>
38 <Steps :current="current"> 41 <Steps :current="current">
@@ -41,8 +44,9 @@ @@ -41,8 +44,9 @@
41 <Step title="步骤3"></Step> 44 <Step title="步骤3"></Step>
42 <Step title="步骤4"></Step> 45 <Step title="步骤4"></Step>
43 </Steps> 46 </Steps>
44 - <i-button type="primary" @click="next">下一步</i-button>  
45 - <br><br> 47 + <br>
  48 + <Button type="primary" @click.native="next">下一步</Button>
  49 + <br><br><br>
46 <Steps :current="1" direction="vertical" size="small"> 50 <Steps :current="1" direction="vertical" size="small">
47 <Step title="已完成" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> 51 <Step title="已完成" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step>
48 <Step title="进行中" content="这里是该步骤的描述信息"></Step> 52 <Step title="进行中" content="这里是该步骤的描述信息"></Step>
@@ -56,18 +60,18 @@ @@ -56,18 +60,18 @@
56 <Step title="待进行" content="这里是该步骤的描述信息"></Step> 60 <Step title="待进行" content="这里是该步骤的描述信息"></Step>
57 <Step title="待进行" content="这里是该步骤的描述信息"></Step> 61 <Step title="待进行" content="这里是该步骤的描述信息"></Step>
58 </Steps> 62 </Steps>
  63 +</div>
59 </template> 64 </template>
60 <script> 65 <script>
61 - import { Page, Steps, iButton } from 'iview'; 66 + import { Steps, Button } from 'iview';
62 67
63 const Step = Steps.Step; 68 const Step = Steps.Step;
64 69
65 export default { 70 export default {
66 components: { 71 components: {
67 - Page,  
68 Steps, 72 Steps,
69 Step, 73 Step,
70 - iButton 74 + Button
71 }, 75 },
72 props: { 76 props: {
73 77
@@ -82,9 +86,6 @@ @@ -82,9 +86,6 @@
82 86
83 }, 87 },
84 methods: { 88 methods: {
85 - setPage (page) {  
86 - console.log(page)  
87 - },  
88 next () { 89 next () {
89 if (this.current == 3) { 90 if (this.current == 3) {
90 this.current = 0; 91 this.current = 0;