[new feature] Picker: add loading prop (#619)

This commit is contained in:
neverland 2018-02-07 17:09:09 +08:00 committed by GitHub
parent 866aff9c45
commit e53f543639
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 59 additions and 9 deletions

View File

@ -21,6 +21,10 @@
<demo-block :title="$t('title4')"> <demo-block :title="$t('title4')">
<van-picker :columns="columns" @change="onChange2" /> <van-picker :columns="columns" @change="onChange2" />
</demo-block> </demo-block>
<demo-block :title="$t('loading')">
<van-picker :columns="columns" loading />
</demo-block>
</demo-section> </demo-section>
</template> </template>

View File

@ -45,6 +45,7 @@ Set `columns-num` with 2, you'll have a 2 level picker.
| area-list | an object contains these properties: `province_list`, `city_list` and `county_list` | `Object` | - | - | | area-list | an object contains these properties: `province_list`, `city_list` and `county_list` | `Object` | - | - |
| columns-num | level of picker | `String`,`Number` | 3 | - | | columns-num | level of picker | `String`,`Number` | 3 | - |
| item-height | Option height | `Number` | `44` | - | | item-height | Option height | `Number` | `44` | - |
| loading | Whether to show loading prompt | `Boolean` | `false` | - |
| visible-item-count | Count of visible columns | `Number` | `5` | - | | visible-item-count | Count of visible columns | `Number` | `5` | - |
### Event ### Event

View File

@ -114,6 +114,13 @@ export default {
}; };
``` ```
#### Loading
When Picker columns data is acquired asynchronously, use `loading` prop to show loading prompt
```html
<van-picker :columns="columns" loading />
```
### API ### API
| Attribute | Description | Type | Default | Accepted Values | | Attribute | Description | Type | Default | Accepted Values |
@ -121,6 +128,7 @@ export default {
| columns | Columns data | `Array` | `[]` | - | | columns | Columns data | `Array` | `[]` | - |
| show-toolbar | Whether to show toolbar | `Boolean` | `false` | - | | show-toolbar | Whether to show toolbar | `Boolean` | `false` | - |
| title | Toolbar title | `String` | `''` | - | | title | Toolbar title | `String` | `''` | - |
| loading | Whether to show loading prompt | `Boolean` | `false` | - |
| confirm-button-text | Text of confirm button | `String` | `Confirm` | - | | confirm-button-text | Text of confirm button | `String` | `Confirm` | - |
| cancel-button-text | Text of cancel button | `String` | `Cancel` | - | | cancel-button-text | Text of cancel button | `String` | `Cancel` | - |
| item-height | Option height | `Number` | `44` | - | | item-height | Option height | `Number` | `44` | - |

View File

@ -42,6 +42,7 @@ Vue.use(Area);
| title | 顶部栏标题 | `String` | `''` | - | | title | 顶部栏标题 | `String` | `''` | - |
| area-list | 省市县数据,格式见下方 | `Object` | - | - | | area-list | 省市县数据,格式见下方 | `Object` | - | - |
| columns-num | 省市县显示列数3-省市县2-省市1-省 | `String`,`Number` | `3` | - | | columns-num | 省市县显示列数3-省市县2-省市1-省 | `String`,`Number` | `3` | - |
| loading | 是否显示加载状态 | `Boolean` | `false` | - |
| item-height | 选项高度 | `Number` | `44` | - | | item-height | 选项高度 | `Number` | `44` | - |
| visible-item-count | 可见的选项个数 | `Number` | `5` | - | | visible-item-count | 可见的选项个数 | `Number` | `5` | - |

View File

@ -116,6 +116,13 @@ export default {
}; };
``` ```
#### 加载状态
当 Picker 数据是通过异步获取时,可以通过 `loading` 属性显示加载提示
```html
<van-picker :columns="columns" loading />
```
### API ### API
| 参数 | 说明 | 类型 | 默认值 | 可选值 | | 参数 | 说明 | 类型 | 默认值 | 可选值 |
@ -123,6 +130,7 @@ export default {
| columns | 对象数组,配置每一列显示的数据 | `Array` | `[]` | - | | columns | 对象数组,配置每一列显示的数据 | `Array` | `[]` | - |
| show-toolbar | 是否显示顶部栏 | `Boolean` | `false` | - | | show-toolbar | 是否显示顶部栏 | `Boolean` | `false` | - |
| title | 顶部栏标题 | `String` | `''` | - | | title | 顶部栏标题 | `String` | `''` | - |
| loading | 是否显示加载状态 | `Boolean` | `false` | - |
| confirm-button-text | 确认按钮文字 | `String` | `完成` | - | | confirm-button-text | 确认按钮文字 | `String` | `完成` | - |
| cancel-button-text | 取消按钮文字 | `String` | `取消` | - | | cancel-button-text | 取消按钮文字 | `String` | `取消` | - |
| item-height | 选项高度 | `Number` | `44` | - | | item-height | 选项高度 | `Number` | `44` | - |

View File

@ -5,6 +5,7 @@
show-toolbar show-toolbar
value-key="name" value-key="name"
:title="title" :title="title"
:loading="loading"
:columns="columns" :columns="columns"
:item-height="itemHeight" :item-height="itemHeight"
:visible-item-count="visibleItemCount" :visible-item-count="visibleItemCount"
@ -28,6 +29,7 @@ export default create({
props: { props: {
value: {}, value: {},
title: String, title: String,
loading: Boolean,
areaList: Object, areaList: Object,
itemHeight: Number, itemHeight: Number,
visibleItemCount: Number, visibleItemCount: Number,

View File

@ -37,14 +37,11 @@ export default create({
valueKey: String, valueKey: String,
className: String, className: String,
itemHeight: Number, itemHeight: Number,
visibleItemCount: Number,
options: { options: {
type: Array, type: Array,
default: () => [] default: () => []
}, },
visibleItemCount: {
type: Number,
default: 5
},
defaultIndex: { defaultIndex: {
type: Number, type: Number,
default: 0 default: 0

View File

@ -7,7 +7,10 @@
<div class="van-picker__confirm" @click="emit('confirm')">{{ confirmButtonText || $t('confirm') }}</div> <div class="van-picker__confirm" @click="emit('confirm')">{{ confirmButtonText || $t('confirm') }}</div>
</slot> </slot>
</div> </div>
<div class="van-picker__columns" @touchmove.prevent> <div v-if="loading" class="van-picker__loading">
<loading type="circular" />
</div>
<div class="van-picker__columns" :style="columnsStyle" @touchmove.prevent>
<picker-column <picker-column
v-for="(item, index) in currentColumns" v-for="(item, index) in currentColumns"
:key="index" :key="index"
@ -38,10 +41,14 @@ export default create({
props: { props: {
title: String, title: String,
loading: Boolean,
showToolbar: Boolean, showToolbar: Boolean,
confirmButtonText: String, confirmButtonText: String,
cancelButtonText: String, cancelButtonText: String,
visibleItemCount: Number, visibleItemCount: {
type: Number,
default: 5
},
valueKey: { valueKey: {
type: String, type: String,
default: 'text' default: 'text'
@ -78,6 +85,12 @@ export default create({
return { return {
height: this.itemHeight + 'px' height: this.itemHeight + 'px'
}; };
},
columnsStyle() {
return {
height: this.itemHeight * this.visibleItemCount + 'px'
};
} }
}, },

View File

@ -84,7 +84,7 @@
color: $gray; color: $gray;
} }
.van-loading__circular circle { circle {
stroke: $gray; stroke: $gray;
} }
} }
@ -103,7 +103,7 @@
color: #fff; color: #fff;
} }
.van-loading__circular circle { circle {
stroke: $white; stroke: $white;
} }
} }

View File

@ -3,6 +3,7 @@
.van-picker { .van-picker {
overflow: hidden; overflow: hidden;
user-select: none; user-select: none;
position: relative;
background-color: $white; background-color: $white;
&__toolbar { &__toolbar {
@ -32,6 +33,21 @@
position: relative; position: relative;
} }
&__loading {
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 2;
position: absolute;
background-color: rgba(255,255,255,.9);
circle {
stroke: $blue;
}
}
&__loading .van-loading,
&__frame { &__frame {
top: 50%; top: 50%;
left: 0; left: 0;