forked from verdnatura/salix-front
fix: hasMoreData
This commit is contained in:
parent
9a3f714290
commit
80844e7869
|
@ -78,6 +78,7 @@ const arrayData = useArrayData(props.dataKey, {
|
||||||
exprBuilder: props.exprBuilder,
|
exprBuilder: props.exprBuilder,
|
||||||
});
|
});
|
||||||
const store = arrayData.store;
|
const store = arrayData.store;
|
||||||
|
const hasMoreData = arrayData.hasMoreData;
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (props.autoLoad) fetch();
|
if (props.autoLoad) fetch();
|
||||||
|
@ -96,7 +97,7 @@ const addFilter = async (filter, params) => {
|
||||||
|
|
||||||
async function fetch() {
|
async function fetch() {
|
||||||
await arrayData.fetch({ append: false });
|
await arrayData.fetch({ append: false });
|
||||||
if (!arrayData.hasMoreData.value) {
|
if (!hasMoreData.value) {
|
||||||
isLoading.value = false;
|
isLoading.value = false;
|
||||||
}
|
}
|
||||||
emit('onFetch', store.data);
|
emit('onFetch', store.data);
|
||||||
|
@ -109,8 +110,8 @@ async function paginate() {
|
||||||
|
|
||||||
isLoading.value = true;
|
isLoading.value = true;
|
||||||
await arrayData.loadMore();
|
await arrayData.loadMore();
|
||||||
if (!arrayData.hasMoreData.value) {
|
if (!hasMoreData.value) {
|
||||||
if (store.userParamsChanged) arrayData.hasMoreData.value = true;
|
if (store.userParamsChanged) hasMoreData.value = true;
|
||||||
store.userParamsChanged = false;
|
store.userParamsChanged = false;
|
||||||
endPagination();
|
endPagination();
|
||||||
return;
|
return;
|
||||||
|
@ -131,9 +132,7 @@ function endPagination() {
|
||||||
emit('onPaginate');
|
emit('onPaginate');
|
||||||
}
|
}
|
||||||
async function onLoad(index, done) {
|
async function onLoad(index, done) {
|
||||||
if (!store.data) {
|
if (!store.data) return done();
|
||||||
return done();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (store.data.length === 0 || !props.url) return done(false);
|
if (store.data.length === 0 || !props.url) return done(false);
|
||||||
|
|
||||||
|
@ -141,7 +140,7 @@ async function onLoad(index, done) {
|
||||||
|
|
||||||
await paginate();
|
await paginate();
|
||||||
let isDone = false;
|
let isDone = false;
|
||||||
if (store.userParamsChanged) isDone = !arrayData.hasMoreData.value;
|
if (store.userParamsChanged) isDone = !hasMoreData.value;
|
||||||
done(isDone);
|
done(isDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,13 +180,12 @@ defineExpose({ fetch, addFilter });
|
||||||
</QCard>
|
</QCard>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<QInfiniteScroll
|
<QInfiniteScroll
|
||||||
v-if="store.data"
|
v-if="store.data"
|
||||||
@load="onLoad"
|
@load="onLoad"
|
||||||
:offset="offset"
|
:offset="offset"
|
||||||
:disable="disableInfiniteScroll || !arrayData.hasMoreData.value"
|
|
||||||
class="full-width"
|
class="full-width"
|
||||||
|
:disable="disableInfiniteScroll || !hasMoreData"
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
>
|
>
|
||||||
<slot name="body" :rows="store.data"></slot>
|
<slot name="body" :rows="store.data"></slot>
|
||||||
|
@ -195,10 +193,7 @@ defineExpose({ fetch, addFilter });
|
||||||
<QSpinner color="orange" size="md" />
|
<QSpinner color="orange" size="md" />
|
||||||
</div>
|
</div>
|
||||||
</QInfiniteScroll>
|
</QInfiniteScroll>
|
||||||
<div
|
<div v-if="!isLoading && hasMoreData" class="w-full flex justify-center q-mt-md">
|
||||||
v-if="!isLoading && arrayData.hasMoreData.value"
|
|
||||||
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()" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -14,7 +14,7 @@ export function useArrayData(key, userOptions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const store = arrayDataStore.get(key);
|
const store = arrayDataStore.get(key);
|
||||||
const hasMoreData = ref(false);
|
const hasMoreData = computed(() => arrayDataStore.hasMoreData);
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
let canceller = null;
|
let canceller = null;
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ export function useArrayData(key, userOptions) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const { limit } = filter;
|
const { limit } = filter;
|
||||||
hasMoreData.value = limit && response.data.length >= limit;
|
arrayDataStore.hasMoreData = limit && response.data.length >= limit;
|
||||||
|
|
||||||
if (append) {
|
if (append) {
|
||||||
if (!store.data) store.data = [];
|
if (!store.data) store.data = [];
|
||||||
|
|
Loading…
Reference in New Issue