Commit 112ed1fae82856bacfa38ac7fe6bb7a05c4a5d0f
Committed by
GitHub
Merge pull request #325 from huixisheng/feature-steps
support Steps
Showing
8 changed files
with
55 additions
and
50 deletions
Show diff stats
build/webpack.dev.config.js
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | |
| 5 | 5 | var path = require('path'); |
| 6 | 6 | var webpack = require('webpack'); |
| 7 | -var ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
| 7 | +// var ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
| 8 | 8 | var HtmlWebpackPlugin = require('html-webpack-plugin'); |
| 9 | 9 | |
| 10 | 10 | module.exports = { | ... | ... |
package.json
src/components/steps/step.vue
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | <div :class="[prefixCls + '-tail']"><i></i></div> |
| 4 | 4 | <div :class="[prefixCls + '-head']"> |
| 5 | 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 | 7 | <span v-else :class="iconClasses"></span> |
| 8 | 8 | </div> |
| 9 | 9 | </div> |
| ... | ... | @@ -42,14 +42,18 @@ |
| 42 | 42 | prefixCls: prefixCls, |
| 43 | 43 | stepNumber: '', |
| 44 | 44 | nextError: false, |
| 45 | - total: 1 | |
| 45 | + total: 1, | |
| 46 | + currentStatus: '' | |
| 46 | 47 | }; |
| 47 | 48 | }, |
| 49 | + created () { | |
| 50 | + this.currentStatus = this.status; | |
| 51 | + }, | |
| 48 | 52 | computed: { |
| 49 | 53 | wrapClasses () { |
| 50 | 54 | return [ |
| 51 | 55 | `${prefixCls}-item`, |
| 52 | - `${prefixCls}-status-${this.status}`, | |
| 56 | + `${prefixCls}-status-${this.currentStatus}`, | |
| 53 | 57 | { |
| 54 | 58 | [`${prefixCls}-custom`]: !!this.icon, |
| 55 | 59 | [`${prefixCls}-next-error`]: this.nextError |
| ... | ... | @@ -62,9 +66,9 @@ |
| 62 | 66 | if (this.icon) { |
| 63 | 67 | icon = this.icon; |
| 64 | 68 | } else { |
| 65 | - if (this.status == 'finish') { | |
| 69 | + if (this.currentStatus == 'finish') { | |
| 66 | 70 | icon = 'ios-checkmark-empty'; |
| 67 | - } else if (this.status == 'error') { | |
| 71 | + } else if (this.currentStatus == 'error') { | |
| 68 | 72 | icon = 'ios-close-empty'; |
| 69 | 73 | } |
| 70 | 74 | } |
| ... | ... | @@ -84,8 +88,9 @@ |
| 84 | 88 | } |
| 85 | 89 | }, |
| 86 | 90 | watch: { |
| 87 | - status () { | |
| 88 | - if (this.status == 'error') { | |
| 91 | + status (val) { | |
| 92 | + this.currentStatus = val; | |
| 93 | + if (this.currentStatus == 'error') { | |
| 89 | 94 | this.$parent.setNextError(); |
| 90 | 95 | } |
| 91 | 96 | } | ... | ... |
src/components/steps/steps.vue
| ... | ... | @@ -43,7 +43,7 @@ |
| 43 | 43 | ]; |
| 44 | 44 | } |
| 45 | 45 | }, |
| 46 | - ready () { | |
| 46 | + mounted () { | |
| 47 | 47 | this.updateChildProps(true); |
| 48 | 48 | this.setNextError(); |
| 49 | 49 | this.updateCurrent(true); |
| ... | ... | @@ -60,38 +60,42 @@ |
| 60 | 60 | |
| 61 | 61 | // 如果已存在status,且在初始化时,则略过 |
| 62 | 62 | // todo 如果当前是error,在current改变时需要处理 |
| 63 | - if (!(isInit && child.status)) { | |
| 63 | + if (!(isInit && child.currentStatus)) { | |
| 64 | 64 | if (index == this.current) { |
| 65 | 65 | if (this.status != 'error') { |
| 66 | - child.status = 'process'; | |
| 66 | + child.currentStatus = 'process'; | |
| 67 | 67 | } |
| 68 | 68 | } else if (index < this.current) { |
| 69 | - child.status = 'finish'; | |
| 69 | + child.currentStatus = 'finish'; | |
| 70 | 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 | 76 | this.$children[index - 1].nextError = false; |
| 77 | 77 | } |
| 78 | 78 | }); |
| 79 | 79 | }, |
| 80 | 80 | setNextError () { |
| 81 | 81 | this.$children.forEach((child, index) => { |
| 82 | - if (child.status == 'error' && index != 0) { | |
| 82 | + if (child.currentStatus == 'error' && index != 0) { | |
| 83 | 83 | this.$children[index - 1].nextError = true; |
| 84 | 84 | } |
| 85 | 85 | }); |
| 86 | 86 | }, |
| 87 | 87 | updateCurrent (isInit) { |
| 88 | + // 防止溢出边界 | |
| 89 | + if (this.current < 0 || this.current >= this.$children.length ) { | |
| 90 | + return; | |
| 91 | + } | |
| 88 | 92 | if (isInit) { |
| 89 | - const current_status = this.$children[this.current].status; | |
| 93 | + const current_status = this.$children[this.current].currentStatus; | |
| 90 | 94 | if (!current_status) { |
| 91 | - this.$children[this.current].status = this.status; | |
| 95 | + this.$children[this.current].currentStatus = this.status; | |
| 92 | 96 | } |
| 93 | 97 | } else { |
| 94 | - this.$children[this.current].status = this.status; | |
| 98 | + this.$children[this.current].currentStatus = this.status; | |
| 95 | 99 | } |
| 96 | 100 | } |
| 97 | 101 | }, | ... | ... |
src/index.js
| ... | ... | @@ -31,7 +31,7 @@ import Radio from './components/radio'; |
| 31 | 31 | // import Rate from './components/rate'; |
| 32 | 32 | // import Slider from './components/slider'; |
| 33 | 33 | // import Spin from './components/spin'; |
| 34 | -// import Steps from './components/steps'; | |
| 34 | +import Steps from './components/steps'; | |
| 35 | 35 | // import Switch from './components/switch'; |
| 36 | 36 | // import Table from './components/table'; |
| 37 | 37 | // import Tabs from './components/tabs'; |
| ... | ... | @@ -96,8 +96,8 @@ const iview = { |
| 96 | 96 | // iSelect: Select, |
| 97 | 97 | // Slider, |
| 98 | 98 | // Spin, |
| 99 | - // Step: Steps.Step, | |
| 100 | - // Steps, | |
| 99 | + Step: Steps.Step, | |
| 100 | + Steps, | |
| 101 | 101 | // Switch, |
| 102 | 102 | // iTable: Table, |
| 103 | 103 | // Tabs: Tabs, | ... | ... |
test/app.vue
| ... | ... | @@ -2,26 +2,15 @@ |
| 2 | 2 | @import "../src/styles/index.less"; |
| 3 | 3 | </style> |
| 4 | 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 | 11 | </style> |
| 23 | 12 | <template> |
| 24 | - <div> | |
| 13 | + <div class="container"> | |
| 25 | 14 | <nav> |
| 26 | 15 | <ul> |
| 27 | 16 | <li><router-link to="/affix">Affix</router-link></li> |
| ... | ... | @@ -30,6 +19,7 @@ li + li { |
| 30 | 19 | <li><router-link to="/input">Input</router-link></li> |
| 31 | 20 | <li><router-link to="/radio">Radio</router-link></li> |
| 32 | 21 | <li><router-link to="/checkbox">Checkbox</router-link></li> |
| 22 | + <li><router-link to="/steps">Steps</router-link></li> | |
| 33 | 23 | </ul> |
| 34 | 24 | </nav> |
| 35 | 25 | <router-view></router-view> | ... | ... |
test/main.js
test/routers/step.vue renamed to test/routers/steps.vue
| 1 | -<style> | |
| 2 | - | |
| 3 | -</style> | |
| 4 | 1 | <template> |
| 2 | +<div> | |
| 5 | 3 | <Steps :current="1" size="small"> |
| 6 | 4 | <Step title="已完成" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> |
| 7 | 5 | <Step title="进行中" content="这里是该步骤的描述信息"></Step> |
| ... | ... | @@ -33,6 +31,11 @@ |
| 33 | 31 | <Step title="上传头像" icon="camera" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> |
| 34 | 32 | <Step title="验证邮箱" icon="email"></Step> |
| 35 | 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 | 39 | <br> |
| 37 | 40 | <p>当前正在进行第 {{ current + 1 }} 步</p> |
| 38 | 41 | <Steps :current="current"> |
| ... | ... | @@ -41,8 +44,9 @@ |
| 41 | 44 | <Step title="步骤3"></Step> |
| 42 | 45 | <Step title="步骤4"></Step> |
| 43 | 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 | 50 | <Steps :current="1" direction="vertical" size="small"> |
| 47 | 51 | <Step title="已完成" content="这里是该步骤的描述信息这里是该步骤的描述信息这里是该步骤的描述信息"></Step> |
| 48 | 52 | <Step title="进行中" content="这里是该步骤的描述信息"></Step> |
| ... | ... | @@ -56,18 +60,18 @@ |
| 56 | 60 | <Step title="待进行" content="这里是该步骤的描述信息"></Step> |
| 57 | 61 | <Step title="待进行" content="这里是该步骤的描述信息"></Step> |
| 58 | 62 | </Steps> |
| 63 | +</div> | |
| 59 | 64 | </template> |
| 60 | 65 | <script> |
| 61 | - import { Page, Steps, iButton } from 'iview'; | |
| 66 | + import { Steps, Button } from 'iview'; | |
| 62 | 67 | |
| 63 | 68 | const Step = Steps.Step; |
| 64 | 69 | |
| 65 | 70 | export default { |
| 66 | 71 | components: { |
| 67 | - Page, | |
| 68 | 72 | Steps, |
| 69 | 73 | Step, |
| 70 | - iButton | |
| 74 | + Button | |
| 71 | 75 | }, |
| 72 | 76 | props: { |
| 73 | 77 | |
| ... | ... | @@ -82,9 +86,6 @@ |
| 82 | 86 | |
| 83 | 87 | }, |
| 84 | 88 | methods: { |
| 85 | - setPage (page) { | |
| 86 | - console.log(page) | |
| 87 | - }, | |
| 88 | 89 | next () { |
| 89 | 90 | if (this.current == 3) { |
| 90 | 91 | this.current = 0; | ... | ... |