Commit 1744cbd4baedef0d9aef24a28cd8e7c7b3aa5ee7
1 parent
efe28dcf
feat: 优化图片库,增加分页; optimize image gallery(add pagination)
Showing
1 changed file
with
39 additions
and
13 deletions
front-end/h5/src/components/core/support/image-gallery/tabs/personal.js
| 1 | +/** | ||
| 2 | + * https://github.com/ly525/luban-h5/issues/138 | ||
| 3 | + */ | ||
| 1 | import axios from 'axios' | 4 | import axios from 'axios' |
| 2 | import ImageItem from '../components/image-item.js' | 5 | import ImageItem from '../components/image-item.js' |
| 3 | import Uploader from '../components/uploader.js' | 6 | import Uploader from '../components/uploader.js' |
| @@ -6,7 +9,10 @@ export default { | @@ -6,7 +9,10 @@ export default { | ||
| 6 | data: () => ({ | 9 | data: () => ({ |
| 7 | items: [], | 10 | items: [], |
| 8 | cachedItems: [], | 11 | cachedItems: [], |
| 9 | - loading: false | 12 | + loading: false, |
| 13 | + total: 30, | ||
| 14 | + page: 1, | ||
| 15 | + pageSize: 30 | ||
| 10 | }), | 16 | }), |
| 11 | methods: { | 17 | methods: { |
| 12 | uploadSuccess ({ file, fileList }) { | 18 | uploadSuccess ({ file, fileList }) { |
| @@ -18,6 +24,20 @@ export default { | @@ -18,6 +24,20 @@ export default { | ||
| 18 | loading: true | 24 | loading: true |
| 19 | }) | 25 | }) |
| 20 | return file | 26 | return file |
| 27 | + }, | ||
| 28 | + searchFiles () { | ||
| 29 | + axios | ||
| 30 | + .get('/upload/files', { | ||
| 31 | + params: { | ||
| 32 | + '_limit': this.pageSize, | ||
| 33 | + '_start': (this.page - 1) * this.pageSize | ||
| 34 | + // mime: 'image/png' | ||
| 35 | + } | ||
| 36 | + }) | ||
| 37 | + .then(res => { | ||
| 38 | + this.items = res.data | ||
| 39 | + this.cachedItems = [] | ||
| 40 | + }) | ||
| 21 | } | 41 | } |
| 22 | }, | 42 | }, |
| 23 | render (h) { | 43 | render (h) { |
| @@ -31,6 +51,20 @@ export default { | @@ -31,6 +51,20 @@ export default { | ||
| 31 | uploadSuccess={info => this.uploadSuccess(info)} | 51 | uploadSuccess={info => this.uploadSuccess(info)} |
| 32 | /> | 52 | /> |
| 33 | <a-list | 53 | <a-list |
| 54 | + pagination={{ | ||
| 55 | + showSizeChanger: true, | ||
| 56 | + total: this.total, | ||
| 57 | + pageSize: this.pageSize, | ||
| 58 | + onChange: (page, pageSize) => { | ||
| 59 | + this.page = page | ||
| 60 | + this.searchFiles() | ||
| 61 | + console.log(page) | ||
| 62 | + }, | ||
| 63 | + onShowSizeChange: (currentPage, pageSize) => { | ||
| 64 | + this.pageSize = pageSize | ||
| 65 | + this.searchFiles() | ||
| 66 | + } | ||
| 67 | + }} | ||
| 34 | style="height: 400px; overflow: auto;" | 68 | style="height: 400px; overflow: auto;" |
| 35 | grid={{ gutter: 12, column: 3 }} | 69 | grid={{ gutter: 12, column: 3 }} |
| 36 | dataSource={this.items} | 70 | dataSource={this.items} |
| @@ -49,18 +83,10 @@ export default { | @@ -49,18 +83,10 @@ export default { | ||
| 49 | ) | 83 | ) |
| 50 | }, | 84 | }, |
| 51 | mounted () { | 85 | mounted () { |
| 86 | + axios.get('/upload/files/count').then(res => { | ||
| 87 | + this.total = res.data.count | ||
| 88 | + }) | ||
| 89 | + this.searchFiles() | ||
| 52 | // demo code | 90 | // demo code |
| 53 | - axios | ||
| 54 | - .get('/upload/files', { | ||
| 55 | - params: { | ||
| 56 | - '_limit': 10, | ||
| 57 | - '_start': 0, | ||
| 58 | - mime: 'image/png' | ||
| 59 | - } | ||
| 60 | - }) | ||
| 61 | - .then(res => { | ||
| 62 | - this.items = res.data | ||
| 63 | - this.cachedItems = [] | ||
| 64 | - }) | ||
| 65 | } | 91 | } |
| 66 | } | 92 | } |