forked from verdnatura/salix-front
fix: hasMoreData
This commit is contained in:
parent
c638209f0e
commit
ae2737673d
|
@ -1,5 +1,5 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
import { onMounted, ref, watch, computed } from 'vue';
|
import { onMounted, ref, watch } from 'vue';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useArrayData } from 'composables/useArrayData';
|
import { useArrayData } from 'composables/useArrayData';
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ const arrayData = useArrayData(props.dataKey, {
|
||||||
userParams: props.userParams,
|
userParams: props.userParams,
|
||||||
exprBuilder: props.exprBuilder,
|
exprBuilder: props.exprBuilder,
|
||||||
});
|
});
|
||||||
const hasMoreData = computed(() => arrayData.hasMoreData);
|
|
||||||
const store = arrayData.store;
|
const store = arrayData.store;
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
@ -97,7 +96,7 @@ const addFilter = async (filter, params) => {
|
||||||
|
|
||||||
async function fetch() {
|
async function fetch() {
|
||||||
await arrayData.fetch({ append: false });
|
await arrayData.fetch({ append: false });
|
||||||
if (!hasMoreData.value) {
|
if (!arrayData.hasMoreData.value) {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
emit('onFetch', store.data);
|
emit('onFetch', store.data);
|
||||||
|
@ -110,8 +109,8 @@ async function paginate() {
|
||||||
|
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
await arrayData.loadMore();
|
await arrayData.loadMore();
|
||||||
if (!hasMoreData.value) {
|
if (!arrayData.hasMoreData.value) {
|
||||||
if (store.userParamsChanged) hasMoreData.value = true;
|
if (store.userParamsChanged) arrayData.hasMoreData.value = true;
|
||||||
store.userParamsChanged = false;
|
store.userParamsChanged = false;
|
||||||
endPagination();
|
endPagination();
|
||||||
return;
|
return;
|
||||||
|
@ -142,7 +141,7 @@ async function onLoad(index, done) {
|
||||||
|
|
||||||
await paginate();
|
await paginate();
|
||||||
let isDone = false;
|
let isDone = false;
|
||||||
if (store.userParamsChanged) isDone = !hasMoreData.value;
|
if (store.userParamsChanged) isDone = !arrayData.hasMoreData.value;
|
||||||
done(isDone);
|
done(isDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +186,7 @@ defineExpose({ fetch, addFilter });
|
||||||
v-if="store.data"
|
v-if="store.data"
|
||||||
@load="onLoad"
|
@load="onLoad"
|
||||||
:offset="offset"
|
:offset="offset"
|
||||||
:disable="disableInfiniteScroll || !hasMoreData.value"
|
:disable="disableInfiniteScroll || !arrayData.hasMoreData.value"
|
||||||
class="full-width"
|
class="full-width"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
>
|
>
|
||||||
|
@ -197,7 +196,7 @@ defineExpose({ fetch, addFilter });
|
||||||
</div>
|
</div>
|
||||||
</QInfiniteScroll>
|
</QInfiniteScroll>
|
||||||
<div
|
<div
|
||||||
v-if="!isLoading && hasMoreData.value"
|
v-if="!isLoading && arrayData.hasMoreData.value"
|
||||||
class="w-full flex justify-center q-mt-md"
|
class="w-full flex justify-center q-mt-md"
|
||||||
>
|
>
|
||||||
<QBtn color="primary" :label="t('Load more data')" @click="paginate()" />
|
<QBtn color="primary" :label="t('Load more data')" @click="paginate()" />
|
||||||
|
|
Loading…
Reference in New Issue