[new feature] Pagination code review (#328)

* fix: Tabbar icon line-height

* [new feature] progress add showPivot prop

* [new feature] TabItem support vue-router

* [new feature] update document header style

* [Doc] add toast english ducoment

* [bugfix] Search box-sizing wrong

* [Doc] update vant-demo respo

* [Doc] translate theme & demo pages

* [Doc] add Internationalization document

* [bugfix] remove unnecessary props

* [fix] optimize clickoutside

* [new feature] optimize find-parent

* [new feature]: change document title accordinng to language

* [new feature] Pagination code review
This commit is contained in:
neverland
2017-11-17 01:12:49 -06:00
committed by GitHub
parent d17f161772
commit 80e3c6dd65
9 changed files with 176 additions and 273 deletions

View File

@@ -2,38 +2,34 @@
<demo-section>
<demo-block :title="$t('basicUsage')">
<van-pagination
:totalItems="totalItems"
:itemsPerPage="itemsPerPage"
:showPageSize="showPageSize2"
v-model="currentPage1"
:totalItems="24"
:itemsPerPage="5"
:previousText= "$t('prevText')"
:nextText= "$t('nextText')"
v-model="pagination1"
@change="pageChanged()"
></van-pagination>
<pre>Page: {{pagination1.currentPage}} / {{pagination1.numPages}}</pre>
/>
</demo-block>
<demo-block :title="$t('simpleMode')">
<demo-block :title="$t('title2')">
<van-pagination
:totalItems="bigTotalItems"
v-model="pagination2"
v-model="currentPage2"
:pageCount="12"
:previousText= "$t('prevText')"
:nextText= "$t('nextText')"
mode="simple"
size="small"
></van-pagination>
<pre>Page: {{pagination2.currentPage}} / {{pagination2.numPages}}</pre>
/>
</demo-block>
<demo-block :title="$t('advancedUsage')">
<demo-block :title="$t('title3')">
<van-pagination
:totalItems="bigTotalItems"
v-model="pagination3"
:showPageSize="showPageSize"
:forceEllipses="true"
forceEllipses
v-model="currentPage3"
:totalItems="125"
:showPageSize="3"
:previousText= "$t('prevText')"
:nextText= "$t('nextText')"
></van-pagination>
<pre>Page: {{pagination3.currentPage}} / {{pagination3.numPages}}</pre>
/>
</demo-block>
</demo-section>
</template>
@@ -42,12 +38,14 @@
export default {
i18n: {
'zh-CN': {
simpleMode: '简单模式',
title2: '简单模式',
title3: '',
prevText: '上一页',
nextText: '下一页'
},
'en-US': {
simpleMode: 'Simple Mode',
title2: 'Simple Mode',
title3: 'Show ellipses',
prevText: 'Prev',
nextText: 'Next'
}
@@ -55,26 +53,9 @@ export default {
data() {
return {
totalItems: 24,
pagination1: {
currentPage: 2
},
pagination2: {
currentPage: 1
},
pagination3: {
currentPage: 1
},
setPage(pageNo) {
this.pagination1.currentPage = pageNo;
},
pageChanged() {
console.log('Page changed to: ' + this.pagination1.currentPage);
},
showPageSize: 3,
showPageSize2: 5,
bigTotalItems: 125,
itemsPerPage: 5
currentPage1: 1,
currentPage2: 1,
currentPage3: 1,
};
}
};
@@ -90,5 +71,9 @@ export default {
.van-doc-demo-block {
padding: 0 15px;
}
.van-doc-demo-block__title {
padding-left: 0;
}
}
</style>

View File

@@ -1,104 +1,69 @@
## Pagination
### Usage
### Install
``` javascript
import { Pagination } from 'vant';
Vue.component(Pagination.name, Pagination);
```
### Demo
### Usage
#### Basic Usage
```html
<van-pagination
:totalItems="totalItems"
:itemsPerPage="itemsPerPage"
:showPageSize="showPageSize2"
previousText= "Prev"
nextText= "Next"
v-model="pagination1"
@change="pageChanged"
></van-pagination>
<pre>Page: {{pagination1.currentPage}} / {{pagination1.numPages}}</pre>
v-model="currentPage"
:totalItems="24"
:itemsPerPage="5"
/>
```
```javascript
export default {
data() {
return {
totalItems: 24,
pagination1: {
currentPage: 2
},
pagination2: {
currentPage: 1
},
pagination3: {
currentPage: 1
},
setPage (pageNo) {
this.pagination1.currentPage = pageNo;
},
pageChanged () {
console.log('Page changed to: ' + this.pagination1.currentPage);
},
showPageSize: 3,
showPageSize2: 5
bigTotalItems: 125,
itemsPerPage: 5
currentPage: 1
}
}
}
```
Set `mode=simple` use Simple Mode
#### Simple mode
```html
<van-pagination
:totalItems="bigTotalItems"
v-model="pagination2"
:previousText="'Prev'"
:nextText="'Next'"
v-model="currentPage"
:pageCount="12"
mode="simple"
></van-pagination>
<pre>Page: {{pagination2.currentPage}} / {{pagination2.numPages}}</pre>
/>
```
#### Advanced Usage
Set `forceEllipses: true`, show ellipses
#### Show ellipses
```html
<van-pagination
:totalItems="bigTotalItems"
v-model="pagination3"
:showPageSize="showPageSize"
v-model="currentPage"
:totalItems="125"
:showPageSize="3"
:forceEllipses="true"
previousText= "Prev"
nextText= "Next"
></van-pagination>
<pre>Page: {{pagination3.currentPage}} / {{pagination3.numPages}}</pre>
/>
```
### API
| Attribute | Description | Type | Default | Accepted Values |
|-----------|-----------|-----------|-------------|-------------|
| v-model | pageModel | Object | - | - |
| mode | mode | String | multi | multi : simple |
| itemsPerPage | itemsPerPage | Number | 10 | - |
| previousText | previousText | String | Previous | - |
| nextText | nextText | String | Next | - |
| showPageSize | showPageSize | Number | 5 | - |
| forceEllipses | ellipses | Boolean | false | - |
| v-model | pageModel | `Object` | - | - |
| mode | mode | `String` | `multi` | `simple` |
| itemsPerPage | itemsPerPage | `Number` | `10` | - |
| prevText | previousText | `String` | `Previous` | - |
| nextText | nextText | `String` | `Next` | - |
| showPageSize | showPageSize | `Number` | `5` | - |
| forceEllipses | ellipses | `Boolean` | `false` | - |
### Event
| Event | Description | Attribute |
|-----------|-----------|-----------|
| change | triggered on page change | - |
| change | Triggered on page change | - |

View File

@@ -12,90 +12,57 @@ Vue.component(Pagination.name, Pagination);
#### 基础用法
```html
<van-pagination
:totalItems="totalItems"
:itemsPerPage="itemsPerPage"
:showPageSize="showPageSize2"
previousText= "上一页"
nextText= "下一页"
v-model="pagination1"
@change="pageChanged"
></van-pagination>
<pre>Page: {{pagination1.currentPage}} / {{pagination1.numPages}}</pre>
v-model="currentPage"
:totalItems="24"
:itemsPerPage="5"
/>
```
```javascript
export default {
data() {
return {
totalItems: 24,
pagination1: {
currentPage: 2
},
pagination2: {
currentPage: 1
},
pagination3: {
currentPage: 1
},
setPage (pageNo) {
this.pagination1.currentPage = pageNo;
},
pageChanged () {
console.log('Page changed to: ' + this.pagination1.currentPage);
},
showPageSize: 3,
showPageSize2: 5,
bigTotalItems: 125,
itemsPerPage: 5
currentPage: 1
}
}
}
```
设置`mode=simple`,使用简单模式
#### 简单模式
```html
<van-pagination
:totalItems="bigTotalItems"
v-model="pagination2"
previousText="上一页"
nextText="下一页"
v-model="currentPage"
:pageCount="12"
mode="simple"
></van-pagination>
<pre>Page: {{pagination2.currentPage}} / {{pagination2.numPages}}</pre>
/>
```
#### 高级用法
设置 `forceEllipses: true`,显示省略号
#### 显示省略号
```html
<van-pagination
:totalItems="bigTotalItems"
v-model="pagination3"
:showPageSize="showPageSize"
v-model="currentPage"
:totalItems="125"
:showPageSize="3"
:forceEllipses="true"
previousText= "上一页"
nextText= "下一页"
></van-pagination>
<pre>Page: {{pagination3.currentPage}} / {{pagination3.numPages}}</pre>
/>
```
### API
| 参数 | 说明 | 类型 | 默认值 | 可选值 |
|-----------|-----------|-----------|-------------|-------------|
| v-model | 当前页码 | Object | - | - |
| mode | 显示模式 | String | multi | multi : simple |
| itemsPerPage | 每页记录数 | Number | 10 | - |
| previousText | 上一页 | String | Previous | - |
| nextText | 下一页 | String | Next | - |
| showPageSize | 显示的页码个数 | Number | 5 | - |
| forceEllipses | 显示省略号 | Boolean | false | - |
| v-model | 当前页码 | `Object` | - | - |
| mode | 显示模式 | `String` | `multi` | `simple` |
| itemsPerPage | 每页记录数 | `Number` | `10` | - |
| previousText | 上一页 | `String` | `上一页` | - |
| nextText | 下一页 | `String` | `下一页` | - |
| showPageSize | 显示的页码个数 | `Number` | `5` | - |
| forceEllipses | 显示省略号 | `Boolean` | `false` | - |
### Event

View File

@@ -386,6 +386,10 @@ module.exports = {
path: '/notice-bar',
title: 'NoticeBar'
},
{
path: '/pagination',
title: 'Pagination'
},
{
path: '/panel',
title: 'Panel'

View File

@@ -7,6 +7,11 @@ const langMap = {
'zh-CN': zhCN
};
const titleMap = {
'en-US': 'Vant - A Vue.js 2.0 Mobile UI at YouZan',
'zh-CN': 'Vant - 有赞移动端 Vue 组件库'
};
const userLang = window.localStorage.getItem('VANT_LANGUAGE') || window.navigator.language || 'en-US';
let defaultLang = 'en-US';
if (userLang.indexOf('zh-') !== -1) {
@@ -17,4 +22,5 @@ setLang(defaultLang);
export function setLang(lang) {
window.localStorage.setItem('VANT_LANGUAGE', lang);
Locale.use(lang, langMap[lang]);
document.title = titleMap[lang];
}