Skip to content

Commit

Permalink
perf(roll-tools-api): use random girl api
Browse files Browse the repository at this point in the history
  • Loading branch information
Aysnine committed Feb 1, 2020
1 parent 3f22855 commit 231c5f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/api/roll-tools-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export const client = () => {

const apis = {
image: {
girl: (page = 1) => instance.get('/image/girl/list', { params: { page } })
girl: (page = 1) =>
instance.get('/image/girl/list', { params: { page } }),
girl_random: () => instance.get('/image/girl/list/random')
},
ip: {
self: () => instance.get('/ip/self'),
Expand Down
27 changes: 16 additions & 11 deletions src/views/admin/roll-tools-api/fuli-images/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
class="infinite-list"
v-infinite-scroll="loadNext"
infinite-scroll-distance="100"
:infinite-scroll-disabled="lock"
:infinite-scroll-disabled="!!lock"
>
<template v-for="pageNumber in page">
<async
:key="pageNumber"
:api="$rta.apis.image.girl"
:args="[pageNumber]"
:api="$rta.apis.image.girl_random"
:transform="transform"
@success="lock = false"
@success="success"
static
>
<template v-slot:default="{ pending, error, data }">
Expand All @@ -37,10 +36,11 @@
<div v-else>
<el-image
v-for="item in data"
lazy
class="infinite-list-item"
:key="item.imageUrl"
:src="item.imageUrl"
:preview-src-list="[item.imageUrl]"
:preview-src-list="urls"
></el-image>
</div>
</template>
Expand All @@ -51,23 +51,28 @@
</template>

<script>
import { get } from 'lodash'
import { get, map } from 'lodash'
export default {
inject: ['@adminContainer'],
data() {
return {
page: 1,
lock: true
lock: 1,
urls: []
}
},
methods: {
transform(response) {
return get(response, 'data.data.list', [])
return get(response, 'data.data', [])
},
loadNext() {
this.lock = true
this.page++
this.lock += 1
this.page += 1
},
success(list) {
this.urls = [...this.urls, ...map(list, 'imageUrl')]
this.lock -= 1
}
}
}
Expand All @@ -78,7 +83,7 @@ export default {
overflow auto
flex 1
.infinite-list-item
width 25%
width 20%
min-height 100px
</style>

Expand Down

0 comments on commit 231c5f6

Please sign in to comment.